Re: [PATCH net-next V4 4/6] devlink: Apply eswitch mode boot defaults
From: Mark Bloch <mbloch@nvidia.com>
Date: 2026-07-03 18:32:20
Also in:
linux-doc, linux-rdma
On 02/07/2026 10:41, Paolo Abeni wrote:
On 6/29/26 8:20 PM, Mark Bloch wrote:quoted
Apply parsed devlink_eswitch_mode= defaults after devlink registration and after successful reload. devl_register() may still be called before the device is ready for an eswitch mode change, so keep a per-devlink delayed work item and pending flag for the registration path. Registration queues the work, and the worker tries to take the devlink instance lock. If the lock is busy, the worker requeues itself with a delay. For successful reloads that performed DRIVER_REINIT, devlink_reload() already holds the devlink instance lock and the driver has completed reload_up(). Clear pending work and apply the default directly from the reload path instead of queueing work. If a user sets eswitch mode through netlink before the pending registration work runs, clear the pending flag so the queued default does not override that user request. Cancel pending default apply work when freeing the devlink instance. Signed-off-by: Mark Bloch <mbloch@nvidia.com> --- net/devlink/core.c | 198 +++++++++++++++++++++++++++++++----- net/devlink/dev.c | 6 ++ net/devlink/devl_internal.h | 5 + 3 files changed, 182 insertions(+), 27 deletions(-)diff --git a/net/devlink/core.c b/net/devlink/core.c index 5126509a9c4e..998e4ffd5dce 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c@@ -5,6 +5,7 @@ */ #include <linux/init.h> +#include <linux/jiffies.h> #include <linux/list.h> #include <linux/slab.h> #include <linux/string.h>@@ -22,8 +23,12 @@ DEFINE_XARRAY_FLAGS(devlinks, XA_FLAGS_ALLOC); static char *devlink_default_esw_mode_param; static bool devlink_default_esw_mode_match_all; +static bool devlink_default_esw_mode_enabled; static enum devlink_eswitch_mode devlink_default_esw_mode; static LIST_HEAD(devlink_default_esw_mode_nodes); +static struct workqueue_struct *devlink_default_esw_mode_wq; + +#define DEVLINK_DEFAULT_ESW_MODE_APPLY_DELAY msecs_to_jiffies(100) struct devlink_default_esw_mode_node { struct list_head list;@@ -166,6 +171,7 @@ static void __init devlink_default_esw_mode_nodes_clear(void) } devlink_default_esw_mode_match_all = false; + devlink_default_esw_mode_enabled = false; } static int __init devlink_default_esw_mode_parse(char *str)@@ -192,14 +198,113 @@ static int __init devlink_default_esw_mode_parse(char *str) return err; err = devlink_default_esw_mode_handles_parse(handles); - if (err) + if (err) { devlink_default_esw_mode_nodes_clear(); - else + } else { devlink_default_esw_mode = esw_mode; + devlink_default_esw_mode_enabled = true; + } return err; } +static bool devlink_default_esw_mode_match(struct devlink *devlink) +{ + const char *bus_name = devlink_bus_name(devlink); + const char *dev_name = devlink_dev_name(devlink); + struct devlink_default_esw_mode_node *node; + + if (devlink_default_esw_mode_match_all) + return true; + + node = devlink_default_esw_mode_node_find(bus_name, dev_name); + return !!node; +} + +void devlink_default_esw_mode_apply(struct devlink *devlink) +{ + const struct devlink_ops *ops = devlink->ops; + int err; + + devl_assert_locked(devlink); + + if (!devlink_default_esw_mode_match(devlink)) + return; + + if (!ops->eswitch_mode_set) { + if (!devlink_default_esw_mode_match_all) + devl_warn(devlink, + "devlink_eswitch_mode= selected this device but eswitch mode setting is not supported\n");Not a very strong opinion on my side, but I *think* it would be more consistent to emit this warning even for devlink_default_esw_mode_match_all
I kept it only for the explicit handle case intentionally. With "*" most devlink instances are not expected to support eswitch mode. In the current tree I see 9 drivers that do, and many more devlink users without it. So warning for every unsupported instance in the "*" case would be noisy and would look like errors for devices this knob was never meant for. Mark
/P