[PATCH net-next V3 2/7] net/mlx5: E-Switch, let esw work callers choose GFP flags

From: Tariq Toukan

Date: Sun May 03 2026 - 16:29:56 EST


From: Mark Bloch <mbloch@xxxxxxxxxx>

mlx5_esw_add_work() always allocates the queued work item with
GFP_ATOMIC. That is required for the E-Switch functions-change notifier,
but not every caller of this helper will run from atomic context.

Pass an allocation flag to mlx5_esw_add_work() and keep the notifier
caller using GFP_ATOMIC. This allows sleepable callers to use GFP_KERNEL
instead of unnecessarily relying on atomic reserves.

Signed-off-by: Mark Bloch <mbloch@xxxxxxxxxx>
Signed-off-by: Tariq Toukan <tariqt@xxxxxxxxxx>
---
.../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 69ddf56e2fc9..69134ce2a908 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -3736,11 +3736,12 @@ static void esw_wq_handler(struct work_struct *work)
}

static int mlx5_esw_add_work(struct mlx5_eswitch *esw,
- void (*func)(struct mlx5_eswitch *esw))
+ void (*func)(struct mlx5_eswitch *esw),
+ gfp_t gfp)
{
struct mlx5_host_work *host_work;

- host_work = kzalloc_obj(*host_work, GFP_ATOMIC);
+ host_work = kzalloc_obj(*host_work, gfp);
if (!host_work)
return -ENOMEM;

@@ -3764,7 +3765,8 @@ int mlx5_esw_funcs_changed_handler(struct notifier_block *nb,
esw_funcs = mlx5_nb_cof(nb, struct mlx5_esw_functions, nb);
esw = container_of(esw_funcs, struct mlx5_eswitch, esw_funcs);

- ret = mlx5_esw_add_work(esw, esw_vfs_changed_event_handler);
+ ret = mlx5_esw_add_work(esw, esw_vfs_changed_event_handler,
+ GFP_ATOMIC);
if (ret)
return NOTIFY_DONE;

--
2.44.0