devlink: Add boot-time eswitch mode defaults
Subsystems (7)
Tariq Toukan
maintainercover devlink: Add boot-time eswitch mode defaults
Hi,
See detailed feature description by Mark below.
Regards,
Tariq
This series adds a devlink_eswitch_mode= kernel command line parameter for applying a default devlink eswitch mode during device initialization.
Following the discussion with Jakub[1] and the feedback on the RFC postings, this version implements the direction that was agreed on: keep the scope limited to a boot-time devlink eswitch mode default only.
The implementation is intended to support the following properties:
- A system may have multiple devlink devices that usually need the same configuration. For a configuration such as eswitch mode switchdev, a user can specify either all devlink devices or an explicit list of devices to which that mode applies.
- Deployments can set the devlink eswitch mode before normal userspace orchestration runs, while still using devlink concepts and driver callbacks rather than adding driver-specific module parameters.
A default is scoped to either all devlink handles or to a comma-separated list of devlink handles, for example:
devlink_eswitch_mode=[*]:switchdev devlink_eswitch_mode=[pci/0000:08:00.0,pci/0000:09:00.1]:switchdev_inactive
The supported modes are legacy, switchdev and switchdev_inactive.
mlx5 wires this into device initialization after the devlink instance is registered and after mlx5 devlink operations are available, so eswitch mode defaults can be applied to matching PCI devlink devices.
Patch 1 clears the mlx5 FW reset-in-progress bit before reloading after a firmware reset.
Patch 2 adds the devlink eswitch mode boot-default parser, storage, devl_apply_default_esw_mode() API and documentation for the devlink_eswitch_mode= syntax.
Patch 3 calls devl_apply_default_esw_mode() from mlx5 device initialization.
Changelog:
Since RFC v2:
- Replaced the generic devlink=[...]:esw:mode:<mode> command line API with devlink_eswitch_mode=[...]:<mode>.
- Simplified the parser to handle one eswitch mode parameter instead of a generic command/attribute grammar.
- Renamed devl_apply_defaults() to devl_apply_default_esw_mode().
- Added the mlx5 firmware reset cleanup as the first patch after the cover letter.
[1] https://lore.kernel.org/all/[email protected]/
RFC V1:
https://lore.kernel.org/all/[email protected]/
RFC V2:
https://lore.kernel.org/all/[email protected]/
Mark Bloch (3):
net/mlx5: Clear FW reset-in-progress bit before reload
devlink: Add eswitch mode boot defaults net/mlx5: Apply devlink default eswitch mode during init
.../admin-guide/kernel-parameters.txt | 25 ++ .../networking/devlink/devlink-defaults.rst | 80 ++++++ Documentation/networking/devlink/index.rst | 1 + .../ethernet/mellanox/mlx5/core/fw_reset.c | 28 +- .../net/ethernet/mellanox/mlx5/core/main.c | 17 ++ include/net/devlink.h | 1 + net/devlink/core.c | 255 ++++++++++++++++++ 7 files changed, 396 insertions(+), 11 deletions(-) create mode 100644 Documentation/networking/devlink/devlink-defaults.rst
base-commit: 9bf93cb2e180a58d5984ba13daee95903ff4fc14
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 1/3 net/mlx5: Clear FW reset-in-progress bit before reload
From: Mark Bloch <[email protected]>
mlx5 sets MLX5_FW_RESET_FLAGS_RESET_IN_PROGRESS when acknowledging a sync reset request. This bit blocks devlink reload and other devlink operations while the firmware reset is running, but it was kept set until after the driver reload finished.
Clear the reset-in-progress bit once the reset unload flow is done and PCI access is back, before reloading the device. For a reset initiated through devlink, clear it before completing the reload waiter. For a reset reported through an asynchronous firmware event, keep the unload flow outside devl_lock, then take devl_lock before clearing the bit and reloading through the devl-locked load helper.
--- .../ethernet/mellanox/mlx5/core/fw_reset.c | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/fw_reset.c +17 -11
@@ -238,24 +238,30 @@ static void mlx5_fw_reset_complete_reload(struct mlx5_core_dev *dev) {struct mlx5_fw_reset *fw_reset = dev->priv.fw_reset;struct devlink *devlink =priv_to_devlink (dev); +int err;/* if this is the driver that initiated the fw reset, devlink completed the reload */ if (test_bit (MLX5_FW_RESET_FLAGS_PENDING_COMP , &fw_reset->reset_flags)) { +clear_bit (MLX5_FW_RESET_FLAGS_RESET_IN_PROGRESS , + &fw_reset->reset_flags);complete (&fw_reset->done); - }else { -mlx5_sync_reset_unload_flow (dev, false); -if (mlx5_health_wait_pci_up (dev)) -mlx5_core_err (dev,"reset reload flow aborted, PCI reads still not working\n" ); -else -mlx5_load_one (dev, true); -devl_lock (devlink); -devlink_remote_reload_actions_performed (devlink,0 , -BIT (DEVLINK_RELOAD_ACTION_DRIVER_REINIT ) | -BIT (DEVLINK_RELOAD_ACTION_FW_ACTIVATE )); -devl_unlock (devlink); +return ; } +mlx5_sync_reset_unload_flow (dev, false); + err =mlx5_health_wait_pci_up (dev); + +devl_lock (devlink);clear_bit (MLX5_FW_RESET_FLAGS_RESET_IN_PROGRESS , &fw_reset->reset_flags); +if (err) +mlx5_core_err (dev,"reset reload flow aborted, PCI reads still not working\n" ); +else +mlx5_load_one_devl_locked (dev, true); + +devlink_remote_reload_actions_performed (devlink,0 , +BIT (DEVLINK_RELOAD_ACTION_DRIVER_REINIT ) | +BIT (DEVLINK_RELOAD_ACTION_FW_ACTIVATE )); +devl_unlock (devlink); }static void mlx5_stop_sync_reset_poll (struct mlx5_core_dev *dev)
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 2/3 devlink: Add eswitch mode boot defaults
In reply to Tariq ToukanFrom: Mark Bloch <[email protected]>
Add devlink_eswitch_mode= command line support for setting an eswitch mode during device initialization.
The supported syntax selects either all devlink handles or one explicit comma-separated handle list:
devlink_eswitch_mode=[*]:<mode> devlink_eswitch_mode=[<handle>[,<handle>...]]:<mode>
where <mode> is one of legacy, switchdev or switchdev_inactive. All selected handles receive the same mode. Assigning different modes to different handle lists in the same parameter value is not supported.
The default is applied through the existing eswitch_mode_set() devlink operation, matching the userspace devlink eswitch set command.
Expose devl_apply_default_esw_mode() so drivers can apply the default at the point where their devlink instance and eswitch operations are ready.
Document the devlink_eswitch_mode= syntax and duplicate handle handling.
--- .../admin-guide/kernel-parameters.txt | 25 ++ .../networking/devlink/devlink-defaults.rst | 80 ++++++ Documentation/networking/devlink/index.rst | 1 + include/net/devlink.h | 1 + net/devlink/core.c | 255 ++++++++++++++++++ 5 files changed, 362 insertions(+) create mode 100644 Documentation/networking/devlink/devlink-defaults.rst
Documentation/admin-guide/kernel-parameters.txt +25 -0
@@ -1278,6 +1278,31 @@ Kernel parameters dell_smm_hwmon.fan_max= [HW] Maximum configurable fan speed. + devlink_eswitch_mode= + [NET] + Format: + [<selector>]:<mode> + + <selector>: + * | <handle>[,<handle>...] + + <handle>: + <bus-name>/<dev-name> + + Configure default devlink eswitch mode for matching + devlink instances during device initialization. + + <mode>: + legacy | switchdev | switchdev_inactive + + Examples: + devlink_eswitch_mode=[*]:switchdev + devlink_eswitch_mode=[pci/0000:08:00.0]:switchdev + devlink_eswitch_mode=[pci/0000:08:00.0,pci/0000:09:00.1]:legacy + + See Documentation/networking/devlink/devlink-defaults.rst + for the full syntax. + dfltcc= [HW,S390] Format: { on | off | def_only | inf_only | always } on: s390 zlib hardware support for compression on
Documentation/networking/devlink/devlink-defaults.rst new file +80 -0
80 lines not on this page · raw message
Documentation/networking/devlink/index.rst +1 -0
@@ -56,6 +56,7 @@ general. :maxdepth: 1 devlink-dpipe + devlink-defaults devlink-eswitch-attr devlink-flash devlink-health
include/net/devlink.h +1 -0
@@ -1622,6 +1622,7 @@ int devl_trylock(struct devlink *devlink);void devl_unlock (struct devlink *devlink);void devl_assert_locked (struct devlink *devlink);bool devl_lock_is_held (struct devlink *devlink); +int devl_apply_default_esw_mode (struct devlink *devlink); DEFINE_GUARD(devl, struct devlink *, devl_lock(_T), devl_unlock(_T));struct ib_device ;
net/devlink/core.c +255 -0
280 lines not on this page · raw message
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH 3/3 net/mlx5: Apply devlink default eswitch mode during init
In reply to Tariq ToukanFrom: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/main.c +17 -0
@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);
@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ; err_register:
@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ; err_attach:
Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 52 lines · Tariq Toukan
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +16
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ; err_register:
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) · line 1560
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ; err_attach:
NIPA flagged this patch with a build_allmodconfig_warn failure:
https://netdev-ctrl.bots.linux.dev/logs/build/1098506/14585935/build_allmodconfig_warn/
I do not see how this mlx5 patch is related to the reported issue, but I looked into it anyway.
After the kernel has been built once, the issue can be reproduced by rerunning sparse only on version.o, which filters out the unrelated noise. I had an older sparse installed, so I used a local copy:
rm -f arch/x86/boot/version.o
make V=1 C=1 CHECK=/labhome/mbloch/bin/sparse arch/x86/boot/version.o
This gives the same error reported by NIPA:
...
...
make -f ./scripts/Makefile.vmlinux
make -f ./scripts/Makefile.build obj=arch/x86/boot arch/x86/boot/bzImage
make -f ./scripts/Makefile.build obj=arch/x86/boot/compressed arch/x86/boot/compressed/vmlinux
# CC arch/x86/boot/version.o
gcc -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version -c -o arch/x86/boot/version.o arch/x86/boot/version.c
# CHECK arch/x86/boot/version.c
/labhome/mbloch/bin/sparse -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise -Wno-return-void -Wno-unknown-attribute -D__x86_64__ --arch=x86 -mlittle-endian -m64 -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version arch/x86/boot/version.carch/x86/boot/version.c: note: in included file (through arch/x86/include/uapi/asm/bitsperlong.h, include/uapi/asm-generic/int-ll64.h, include/asm-generic/int-ll64.h, include/uapi/asm-generic/types.h, ...):./include/asm-generic/bitsperlong.h:23:2: error: Inconsistent word size. Check asm/bitsperlong.h./include/asm-generic/bitsperlong.h:27:33: error: static assertion failed: "Inconsistent word size. Check asm/bitsperlong.h"
# cmd_gen_symversions_c arch/x86/boot/version.o if nm arch/x86/boot/version.o 2>/dev/null | grep -q ' __export_symbol_'; then gcc -E -D__GENKSYMS__ -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version arch/x86/boot/version.c | ./scripts/genksyms/genksyms >> arch/x86/boot/.version.o.cmd; fi # LD arch/x86/boot/setup.elf ld -m elf_x86_64 -z noexecstack -m elf_i386 -z noexecstack -T arch/x86/boot/setup.ld arch/x86/boot/a20.o arch/x86/boot/bioscall.o arch/x86/boot/cmdline.o arch/x86/boot/copy.o arch/x86/boot/cpu.o arch/x86/boot/cpuflags.o arch/x86/boot/cpucheck.o arch/x86/boot/early_serial_console.o arch/x86/boot/edd.o arch/x86/boot/header.o arch/x86/boot/main.o arch/x86/boot/memory.o arch/x86/boot/pm.o arch/x86/boot/pmjump.o arch/x86/boot/printf.o arch/x86/boot/regs.o arch/x86/boot/string.o arch/x86/boot/tty.o arch/x86/boot/video.o arch/x86/boot/video-mode.o arch/x86/boot/version.o arch/x86/boot/video-vga.o arch/x86/boot/video-vesa.o arch/x86/boot/video-bios.o -o arch/x86/boot/setup.elf # OBJCOPY arch/x86/boot/setup.bin objcopy -O binary arch/x86/boot/setup.elf arch/x86/boot/setup.bin # BUILD arch/x86/boot/bzImage (dd if=arch/x86/boot/setup.bin bs=4k conv=sync status=none; cat arch/x86/boot/vmlinux.bin) >arch/x86/boot/bzImage mkdir -p ./arch/x86_64/boot ln -fsn ../../x86/boot/bzImage ./arch/x86_64/boot/bzImage
To me this looks like sparse is getting a conflicting set of flags. The command line contains both "-D__x86_64__ -m64" and "-m16 -march=i386 -D_SETUP".
I confirmed that the following patch "fixes" the issue, but I do not know whether this is the right fix. This area is outside my comfort zone, so it would be helpful if someone more familiar with the x86 build/sparse flow could take a look:
arch/x86/boot/Makefile +4 -0
@@ -71,6 +71,10 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(SETUP_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) + sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|_e\?sbat\|z_.*\)$$/\#define ZO_\2 0x\1/p' quiet_cmd_zoffset = ZOFFSET $@
arch/x86/realmode/rm/Makefile +4 -0
@@ -29,6 +29,10 @@ targets += $(realmode-y) REALMODE_OBJS = $(addprefix $(obj)/,$(realmode-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(REALMODE_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) + sed-pasyms := -n -r -e 's/^([0-9a-fA-F]+) [ABCDGRSTVW] (.+)$$/pa_\2 = \2;/p' quiet_cmd_pasyms = PASYMS $@
Re: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
On Thu, May 21, 2026 at 04:16:28PM +0300, Mark Bloch wrote:
(...)
Quoted 66 lines
NIPA flagged this patch with a
build_allmodconfig_warnfailure:
https://netdev-ctrl.bots.linux.dev/logs/build/1098506/14585935/build_allmodconfig_warn/I do not see how this mlx5 patch is related to the reported issue, but I looked into it anyway.
After the kernel has been built once, the issue can be reproduced by rerunning sparse only on version.o, which filters out the unrelated noise. I had an older sparse installed, so I used a local copy:
rm -f
arch/x86/boot/version.o
make V=1 C=1 CHECK=/labhome/mbloch/bin/sparsearch/x86/boot/version.oThis gives the same error reported by NIPA:
...
...
make -f./scripts/Makefile.vmlinux
make -f./scripts/Makefile.buildobj=arch/x86/bootarch/x86/boot/bzImage
make -f./scripts/Makefile.buildobj=arch/x86/boot/compressedarch/x86/boot/compressed/vmlinux
# CCarch/x86/boot/version.o
gcc -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version -c -oarch/x86/boot/version.oarch/x86/boot/version.c
# CHECKarch/x86/boot/version.c
/labhome/mbloch/bin/sparse -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise -Wno-return-void -Wno-unknown-attribute -D__x86_64__ --arch=x86 -mlittle-endian -m64 -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=versionarch/x86/boot/version.carch/x86/boot/version.c: note: in included file (througharch/x86/include/uapi/asm/bitsperlong.h,include/uapi/asm-generic/int-ll64.h,include/asm-generic/int-ll64.h,include/uapi/asm-generic/types.h, ...):./include/asm-generic/bitsperlong.h:23:2: error: Inconsistent word size. Checkasm/bitsperlong.h./include/asm-generic/bitsperlong.h:27:33: error: static assertion failed: "Inconsistent word size. Checkasm/bitsperlong.h"# cmd_gen_symversions_c arch/x86/boot/version.o if nm arch/x86/boot/version.o 2>/dev/null | grep -q ' __export_symbol_'; then gcc -E -D__GENKSYMS__ -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version arch/x86/boot/version.c | ./scripts/genksyms/genksyms >> arch/x86/boot/.version.o.cmd; fi # LD arch/x86/boot/setup.elf ld -m elf_x86_64 -z noexecstack -m elf_i386 -z noexecstack -T arch/x86/boot/setup.ld arch/x86/boot/a20.o arch/x86/boot/bioscall.o arch/x86/boot/cmdline.o arch/x86/boot/copy.o arch/x86/boot/cpu.o arch/x86/boot/cpuflags.o arch/x86/boot/cpucheck.o arch/x86/boot/early_serial_console.o arch/x86/boot/edd.o arch/x86/boot/header.o arch/x86/boot/main.o arch/x86/boot/memory.o arch/x86/boot/pm.o arch/x86/boot/pmjump.o arch/x86/boot/printf.o arch/x86/boot/regs.o arch/x86/boot/string.o arch/x86/boot/tty.o arch/x86/boot/video.o arch/x86/boot/video-mode.o arch/x86/boot/version.o arch/x86/boot/video-vga.o arch/x86/boot/video-vesa.o arch/x86/boot/video-bios.o -o arch/x86/boot/setup.elf # OBJCOPY arch/x86/boot/setup.bin objcopy -O binary arch/x86/boot/setup.elf arch/x86/boot/setup.bin # BUILD arch/x86/boot/bzImage (dd if=arch/x86/boot/setup.bin bs=4k conv=sync status=none; cat arch/x86/boot/vmlinux.bin) >arch/x86/boot/bzImage mkdir -p ./arch/x86_64/boot ln -fsn ../../x86/boot/bzImage ./arch/x86_64/boot/bzImageTo me this looks like sparse is getting a conflicting set of flags. The command line contains both "-D__x86_64__ -m64" and "-m16 -march=i386 -D_SETUP".
I confirmed that the following patch "fixes" the issue, but I do not know whether this is the right fix. This area is outside my comfort zone, so it would be helpful if someone more familiar with the x86 build/sparse flow could take a look:
arch/x86/boot/Makefile +4
-0@@ -71,6 +71,10 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(SETUP_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) + sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|_e\?sbat\|z_.*\)$$/\#define ZO_\2 0x\1/p' quiet_cmd_zoffset = ZOFFSET $@arch/x86/realmode/rm/Makefile +0
-0
arch/x86/realmode/rm/Makefile targets += $(realmode-y) · line 35
Quoted 7 lines
arch/x86/realmode/rm/Makefile +4
-0@@ -29,6 +29,10 @@ targets += $(realmode-y) REALMODE_OBJS = $(addprefix $(obj)/,$(realmode-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(REALMODE_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) +
The idea looks good, we do something similar for the 32-bit vDSO:
arch/x86/entry/vdso/vdso32/Makefile
CHECKFLAGS := $(subst -m64,-m32,$(CHECKFLAGS)) CHECKFLAGS := $(subst -D__x86_64__,-D__i386__,$(CHECKFLAGS))
It seems the same kind of substitution would work here. We can add a helper function to arch/x86/Makefile and use that also for the compat vDSO.
I am wondering why this didn't show up before. Are you going to send a patch or should I?
Thomas
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 84 lines · Thomas Weißschuh
On Thu, May 21, 2026 at 04:16:28PM +0300, Mark Bloch wrote:
(...)Quoted 66 lines
NIPA flagged this patch with a
build_allmodconfig_warnfailure:
https://netdev-ctrl.bots.linux.dev/logs/build/1098506/14585935/build_allmodconfig_warn/I do not see how this mlx5 patch is related to the reported issue, but I looked into it anyway.
After the kernel has been built once, the issue can be reproduced by rerunning sparse only on version.o, which filters out the unrelated noise. I had an older sparse installed, so I used a local copy:
rm -f
arch/x86/boot/version.o
make V=1 C=1 CHECK=/labhome/mbloch/bin/sparsearch/x86/boot/version.oThis gives the same error reported by NIPA:
...
...
make -f./scripts/Makefile.vmlinux
make -f./scripts/Makefile.buildobj=arch/x86/bootarch/x86/boot/bzImage
make -f./scripts/Makefile.buildobj=arch/x86/boot/compressedarch/x86/boot/compressed/vmlinux
# CCarch/x86/boot/version.o
gcc -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version -c -oarch/x86/boot/version.oarch/x86/boot/version.c
# CHECKarch/x86/boot/version.c
/labhome/mbloch/bin/sparse -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise -Wno-return-void -Wno-unknown-attribute -D__x86_64__ --arch=x86 -mlittle-endian -m64 -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=versionarch/x86/boot/version.carch/x86/boot/version.c: note: in included file (througharch/x86/include/uapi/asm/bitsperlong.h,include/uapi/asm-generic/int-ll64.h,include/asm-generic/int-ll64.h,include/uapi/asm-generic/types.h, ...):./include/asm-generic/bitsperlong.h:23:2: error: Inconsistent word size. Checkasm/bitsperlong.h./include/asm-generic/bitsperlong.h:27:33: error: static assertion failed: "Inconsistent word size. Checkasm/bitsperlong.h"# cmd_gen_symversions_c arch/x86/boot/version.o if nm arch/x86/boot/version.o 2>/dev/null | grep -q ' __export_symbol_'; then gcc -E -D__GENKSYMS__ -Wp,-MMD,arch/x86/boot/.version.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -std=gnu11 -fms-extensions -m16 -g -Os -DDISABLE_BRANCH_PROFILING -D__DISABLE_EXPORTS -Wall -Wstrict-prototypes -march=i386 -mregparm=3 -fno-strict-aliasing -fomit-frame-pointer -fno-pic -mno-mmx -mno-sse -fcf-protection=none -ffreestanding -fno-stack-protector -Wno-address-of-packed-member -mpreferred-stack-boundary=2 -D_SETUP -fno-asynchronous-unwind-tables -Wimplicit-fallthrough=5 -DKBUILD_MODFILE='"arch/x86/boot/version"' -DKBUILD_BASENAME='"version"' -DKBUILD_MODNAME='"version"' -D__KBUILD_MODNAME=version arch/x86/boot/version.c | ./scripts/genksyms/genksyms >> arch/x86/boot/.version.o.cmd; fi # LD arch/x86/boot/setup.elf ld -m elf_x86_64 -z noexecstack -m elf_i386 -z noexecstack -T arch/x86/boot/setup.ld arch/x86/boot/a20.o arch/x86/boot/bioscall.o arch/x86/boot/cmdline.o arch/x86/boot/copy.o arch/x86/boot/cpu.o arch/x86/boot/cpuflags.o arch/x86/boot/cpucheck.o arch/x86/boot/early_serial_console.o arch/x86/boot/edd.o arch/x86/boot/header.o arch/x86/boot/main.o arch/x86/boot/memory.o arch/x86/boot/pm.o arch/x86/boot/pmjump.o arch/x86/boot/printf.o arch/x86/boot/regs.o arch/x86/boot/string.o arch/x86/boot/tty.o arch/x86/boot/video.o arch/x86/boot/video-mode.o arch/x86/boot/version.o arch/x86/boot/video-vga.o arch/x86/boot/video-vesa.o arch/x86/boot/video-bios.o -o arch/x86/boot/setup.elf # OBJCOPY arch/x86/boot/setup.bin objcopy -O binary arch/x86/boot/setup.elf arch/x86/boot/setup.bin # BUILD arch/x86/boot/bzImage (dd if=arch/x86/boot/setup.bin bs=4k conv=sync status=none; cat arch/x86/boot/vmlinux.bin) >arch/x86/boot/bzImage mkdir -p ./arch/x86_64/boot ln -fsn ../../x86/boot/bzImage ./arch/x86_64/boot/bzImageTo me this looks like sparse is getting a conflicting set of flags. The command line contains both "-D__x86_64__ -m64" and "-m16 -march=i386 -D_SETUP".
I confirmed that the following patch "fixes" the issue, but I do not know whether this is the right fix. This area is outside my comfort zone, so it would be helpful if someone more familiar with the x86 build/sparse flow could take a look:
arch/x86/boot/Makefile +4
-0@@ -71,6 +71,10 @@ $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(SETUP_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) + sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|efi.._stub_entry\|efi\(32\)\?_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|_e\?data\|_e\?sbat\|z_.*\)$$/\#define ZO_\2 0x\1/p' quiet_cmd_zoffset = ZOFFSET $@arch/x86/realmode/rm/Makefile +0
-0arch/x86/realmode/rm/Makefile targets += $(realmode-y) · line 35
Quoted 7 lines
arch/x86/realmode/rm/Makefile +4
-0@@ -29,6 +29,10 @@ targets += $(realmode-y) REALMODE_OBJS = $(addprefix $(obj)/,$(realmode-y)) +realmode-checkflags-$(CONFIG_X86_64) := -m32 -U__x86_64__ -D__i386__ +REALMODE_CHECKFLAGS := $(filter-out -m64 -D__x86_64__,$(CHECKFLAGS)) $(realmode-checkflags-y) +$(REALMODE_OBJS): CHECKFLAGS := $(REALMODE_CHECKFLAGS) +The idea looks good, we do something similar for the 32-bit vDSO:
arch/x86/entry/vdso/vdso32/MakefileCHECKFLAGS := $(subst -m64,-m32,$(CHECKFLAGS)) CHECKFLAGS := $(subst -D__x86_64__,-D__i386__,$(CHECKFLAGS))
Quoted 7 lines
It seems the same kind of substitution would work here. We can add a helper function to
arch/x86/Makefileand use that also for the compat vDSO.I am wondering why this didn't show up before. Are you going to send a patch or should I?
Yes, please take it if you don't mind.
Mark
Quoted 2 lines
Thomas
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
In reply to Tariq ToukanQuoted 44 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);
I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
Quoted 14 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836 net: Apply devlink esw mode defaults ab4f54102ba9 bnxt_en: Apply devlink default eswitch mode during init b48cce1607bb liquidio: Apply devlink default eswitch mode during init 4ea54b0fe04a ice: Apply devlink default eswitch mode during init b7faddaa1c90 octeontx2-af: Apply devlink default eswitch mode during init 74b0c22c47b9 octeontx2-pf: Apply devlink default eswitch mode during init 5000e4c3d768 nfp: Apply devlink default eswitch mode during init 97a218e95e41 netdevsim: Apply devlink default eswitch mode during init
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement eswitch_mode_set() would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.
Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during init
Quoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call ops->eswitch_mode_set at the end of register. Multiple reasons:
1) end of devl_register is exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implement eswitch_mode_set. User should get a feedback like this, not silent ignore.
The only loose end is see it the void return of devl_register(). Multiple ways to handle the possibly failed eswitch_mode_set(). I would probably just go for pr_warn, seems to be the most correct.
Make sense?
Quoted 24 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.
Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think devl_register() (at least not the only place) is the right place.
There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling eswitch_mode_set() from inside the register flow.
Some drivers call devlink_register() while holding the device lock. liquidio is one example. If devlink core calls ops->eswitch_mode_set() from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.
For mlx5, the placement after intf_state_mutex is also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);
We can't call it while holding intf_state_mutex because the mode set path takes it internally, and switchdev mode may also create IB representors.
Also, devl_register() only covers the first registration. The mlx5 call in mlx5_load_one_devl_locked() is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, so devl_register() is not called again, but the driver state was rebuilt and we may need to apply the default again.
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in devl_register().
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.
I believe your AI may untagle liquidio locking :)
Quoted 6 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);
Quoted 8 lines
We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.
Call it from reload too, right?
Quoted 11 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Idk, perhaps do it from devlink_post_register_work of some kind? That would allow you to have the same locking ordering as a userspace call.
Quoted 30 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.
Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.
Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from devl_register() for the first registration and from devlink_reload() after a successful DRIVER_REINIT.
That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace cal
l.
I thought about a workqueue too, it was actually my first idea.
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 165 lines · Tue, May 26, 2026 at 07:13:46PM +0200, [email protected] wrote:
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from
devl_register()for the first registration and fromdevlink_reload()after a successfulDRIVER_REINIT.That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace call.
Quoted 7 lines
I thought about a workqueue too, it was actually my first idea.
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Figure that out and expose to user by setting xa_mark only after the work is done? This is doable.
Quoted 5 lines
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
If you don't obey current configuration for example in pci resume, it is bug and you should fix it. All these flows should obey current eswitch mode configuration.
Quoted 43 lines
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 168 lines · Jiri Pirko
Quoted 167 lines · Tue, May 26, 2026 at 07:13:46PM +0200, [email protected] wrote:
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from
devl_register()for the first registration and fromdevlink_reload()after a successfulDRIVER_REINIT.That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace call.
I thought about a workqueue too, it was actually my first idea.
Quoted 8 lines
Quoted 5 lines
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Figure that out and expose to user by setting
xa_markonly after the work is done? This is doable.
I agree that if devlink can keep the instance hidden/unavailable until the post register work is done, that solves the initial userspace race.
The other part is the reinit/recovery case. For that I think devlink core needs some explicit indication from the driver that the device is now in reinit. Something like (at least that's the code I had initially, but something along those lines):
void devl_dev_reinit_begin(struct devlink *devlink); void devl_dev_reinit_end(struct devlink *devlink); void devl_dev_reinit_abort(struct devlink *devlink);
The core can then mark the instance as temporarily unavailable/in reinit between begin/end, and the relevant lookup/dump paths, for example devlink_get_from_attrs_lock() and devlink_nl_inst_iter_dumpit(), can reject or skip it while reinit is in progress. devlink_reload() can probably mark this state by itself around DRIVER_REINIT.
Then mlx5 would look more or less like:
devl_lock(devlink); devl_dev_reinit_begin(devlink); ret = mlx5_load_one_devl_locked(dev, recovery); if (!ret) devl_dev_reinit_end(devlink); else devl_dev_reinit_abort(devlink); devl_unlock(devlink);
This gives devlink core a way to know that the devlink instance is registered, but should not be used by userspace at the moment. It also allows keeping the default/config apply logic in devlink instead of adding driver specific calls to apply it in each init path.
But this still means the generic solution needs some driver help. Drivers need to register devlink at a point where the post-register default apply is safe, and full reinit paths need to be marked with this begin/end API.
Quoted 12 lines
Quoted 7 lines
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
If you don't obey current configuration for example in pci resume, it is bug and you should fix it. All these flows should obey current eswitch mode configuration.
I agree that the device should come back according
to the intended high level policy. But I don't think full reinit can be treated as restoring the whole previous runtime state. There may be user created steering rules and other objects which the driver cannot keep or replay. Today full reinit brings the device back to a clean initialized state, and that is intentional.
So the split I have in mind is:
- full runtime state is not preserved across full reinit;
- high level devlink policy/configuration should be applied when the device is initialized again;
- the command line default should not blindly override a later explicit userspace eswitch mode selection.
I am not against moving this into devlink core, and I am willing to work on it.
But before I rework the series, I want to make sure we agree on the direction. As I see it, doing this cleanly needs a devlink state like "registered but unavailable/in reinit", plus driver annotations for the reinit paths.
If this is not the direction you want, I prefer to know now rather than spend time on a version that will be rejected anyway.
Mark
Quoted 44 lines
Quoted 44 lines
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 192 lines · Wed, May 27, 2026 at 09:03:26AM +0200, [email protected] wrote:
Quoted 168 lines · Jiri Pirko
Quoted 167 lines · Tue, May 26, 2026 at 07:13:46PM +0200, [email protected] wrote:
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from
devl_register()for the first registration and fromdevlink_reload()after a successfulDRIVER_REINIT.That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace call.
I thought about a workqueue too, it was actually my first idea.
Quoted 8 lines
Quoted 5 lines
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Figure that out and expose to user by setting
xa_markonly after the work is done? This is doable.I agree that if devlink can keep the instance hidden/unavailable until the post register work is done, that solves the initial userspace race.
The other part is the reinit/recovery case. For that I think devlink core needs some explicit indication from the driver that the device is now in reinit. Something like (at least that's the code I had initially, but something along those lines):
void
devl_dev_reinit_begin(struct devlink *devlink); voiddevl_dev_reinit_end(struct devlink *devlink); voiddevl_dev_reinit_abort(struct devlink *devlink);
Quoted 5 lines
The core can then mark the instance as temporarily unavailable/in reinit between begin/end, and the relevant lookup/dump paths, for example
devlink_get_from_attrs_lock()anddevlink_nl_inst_iter_dumpit(), can reject or skip it while reinit is in progress.devlink_reload()can probably mark this state by itself aroundDRIVER_REINIT.
I believe this is orthogonal to the problem you are trying to solve in this patchset. Not sure why you bring it in to the conversation...
Quoted 104 lines
Then mlx5 would look more or less like:
devl_lock(devlink); devl_dev_reinit_begin(devlink); ret = mlx5_load_one_devl_locked(dev, recovery); if (!ret) devl_dev_reinit_end(devlink); else devl_dev_reinit_abort(devlink); devl_unlock(devlink);This gives devlink core a way to know that the devlink instance is registered, but should not be used by userspace at the moment. It also allows keeping the default/config apply logic in devlink instead of adding driver specific calls to apply it in each init path.
But this still means the generic solution needs some driver help. Drivers need to register devlink at a point where the post-register default apply is safe, and full reinit paths need to be marked with this begin/end API.
Quoted 12 lines
Quoted 7 lines
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
If you don't obey current configuration for example in pci resume, it is bug and you should fix it. All these flows should obey current eswitch mode configuration.
I agree that the device should come back according
to the intended high level policy. But I don't think full reinit can be treated as restoring the whole previous runtime state. There may be user created steering rules and other objects which the driver cannot keep or replay. Today full reinit brings the device back to a clean initialized state, and that is intentional.So the split I have in mind is:
- full runtime state is not preserved across full reinit;
- high level devlink policy/configuration should be applied when the device is initialized again;
- the command line default should not blindly override a later explicit userspace eswitch mode selection.I am not against moving this into devlink core, and I am willing to work on it.
But before I rework the series, I want to make sure we agree on the direction. As I see it, doing this cleanly needs a devlink state like "registered but unavailable/in reinit", plus driver annotations for the reinit paths.
If this is not the direction you want, I prefer to know now rather than spend time on a version that will be rejected anyway.
Mark
Quoted 44 lines
Quoted 44 lines
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Mark Bloch
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 193 lines · Jiri Pirko
Quoted 192 lines · Wed, May 27, 2026 at 09:03:26AM +0200, [email protected] wrote:
Quoted 168 lines · Jiri Pirko
Quoted 167 lines · Tue, May 26, 2026 at 07:13:46PM +0200, [email protected] wrote:
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from
devl_register()for the first registration and fromdevlink_reload()after a successfulDRIVER_REINIT.That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace call.
I thought about a workqueue too, it was actually my first idea.
Quoted 8 lines
Quoted 5 lines
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Figure that out and expose to user by setting
xa_markonly after the work is done? This is doable.I agree that if devlink can keep the instance hidden/unavailable until the post register work is done, that solves the initial userspace race.
The other part is the reinit/recovery case. For that I think devlink core needs some explicit indication from the driver that the device is now in reinit. Something like (at least that's the code I had initially, but something along those lines):
void
devl_dev_reinit_begin(struct devlink *devlink); voiddevl_dev_reinit_end(struct devlink *devlink); voiddevl_dev_reinit_abort(struct devlink *devlink);
Quoted 9 lines
Quoted 5 lines
The core can then mark the instance as temporarily unavailable/in reinit between begin/end, and the relevant lookup/dump paths, for example
devlink_get_from_attrs_lock()anddevlink_nl_inst_iter_dumpit(), can reject or skip it while reinit is in progress.devlink_reload()can probably mark this state by itself aroundDRIVER_REINIT.I believe this is orthogonal to the problem you are trying to solve in this patchset. Not sure why you bring it in to the conversation...
I brought it up because I was also thinking about reinit/recovery flows, but I guess I can tackle that later.
For now I can focus on the generic devlink path, move drivers to register devlink only after the device is ready. Then devlink core can apply the default before exposing the instance to userspace.
I think it is better to fix the ordering for all devlink drivers, not only the ones that support eswitch mode set. That gives us a consistent model and makes future defaults easier.
Reload can be handled from devlink after successful DRIVER_REINIT.
Does this sound ok?
Mark
Quoted 105 lines
Quoted 105 lines
Then mlx5 would look more or less like:
devl_lock(devlink); devl_dev_reinit_begin(devlink); ret = mlx5_load_one_devl_locked(dev, recovery); if (!ret) devl_dev_reinit_end(devlink); else devl_dev_reinit_abort(devlink); devl_unlock(devlink);This gives devlink core a way to know that the devlink instance is registered, but should not be used by userspace at the moment. It also allows keeping the default/config apply logic in devlink instead of adding driver specific calls to apply it in each init path.
But this still means the generic solution needs some driver help. Drivers need to register devlink at a point where the post-register default apply is safe, and full reinit paths need to be marked with this begin/end API.
Quoted 12 lines
Quoted 7 lines
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
If you don't obey current configuration for example in pci resume, it is bug and you should fix it. All these flows should obey current eswitch mode configuration.
I agree that the device should come back according
to the intended high level policy. But I don't think full reinit can be treated as restoring the whole previous runtime state. There may be user created steering rules and other objects which the driver cannot keep or replay. Today full reinit brings the device back to a clean initialized state, and that is intentional.So the split I have in mind is:
- full runtime state is not preserved across full reinit;
- high level devlink policy/configuration should be applied when the device is initialized again;
- the command line default should not blindly override a later explicit userspace eswitch mode selection.I am not against moving this into devlink core, and I am willing to work on it.
But before I rework the series, I want to make sure we agree on the direction. As I see it, doing this cleanly needs a devlink state like "registered but unavailable/in reinit", plus driver annotations for the reinit paths.
If this is not the direction you want, I prefer to know now rather than spend time on a version that will be rejected anyway.
Mark
Quoted 44 lines
Quoted 44 lines
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jiri Pirko
maintainerRe: [PATCH net-next 3/3] net/mlx5: Apply devlink default eswitch mode during init
Quoted 213 lines · Thu, May 28, 2026 at 10:15:44AM +0200, [email protected] wrote:
Quoted 193 lines · Jiri Pirko
Quoted 192 lines · Wed, May 27, 2026 at 09:03:26AM +0200, [email protected] wrote:
Quoted 168 lines · Jiri Pirko
Quoted 167 lines · Tue, May 26, 2026 at 07:13:46PM +0200, [email protected] wrote:
Quoted 108 lines · Jiri Pirko
Quoted 107 lines · Tue, May 26, 2026 at 05:03:57PM +0200, [email protected] wrote:
Quoted 91 lines · Jiri Pirko
Quoted 72 lines · Tue, May 26, 2026 at 11:44:46AM +0200, [email protected] wrote:
Quoted 47 lines · Jiri Pirko
Quoted 46 lines · Thu, May 21, 2026 at 09:24:34AM +0200, [email protected] wrote:
From: Mark Bloch <[email protected]>
Apply devlink default eswitch mode for mlx5 devices after successful device initialization while holding the devlink instance lock.
At this point the devlink instance is registered and the mlx5 devlink operations are available, so the default eswitch mode can be applied to the matching PCI devlink handle.
Signed-off-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Moshe Shemesh <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
drivers/net/ethernet/mellanox/mlx5/core/main.c| 17 +++++++++++++++++1 file changed, 17 insertions(+)drivers/net/ethernet/mellanox/mlx5/core/main.c +15
-0@@ -1391,6 +1391,21 @@ static void mlx5_unload(struct mlx5_core_dev *dev)mlx5_free_bfreg (dev, &dev->priv.bfreg); } +static void mlx5_devl_apply_default_esw_mode (struct mlx5_core_dev *dev) +{ +struct devlink *devlink =priv_to_devlink (dev); +int err; + +if (!MLX5_ESWITCH_MANAGER (dev)) +return ; + +devl_assert_locked (devlink); + err =devl_apply_default_esw_mode (devlink); +if (err) +mlx5_core_warn (dev,"Couldn't apply default eswitch mode, err %d\n" , + err); +} +int mlx5_init_one_devl_locked (struct mlx5_core_dev *dev) {bool light_probe =mlx5_dev_is_lightweight (dev);@@ -1437,6 +1452,7 @@ int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev)mlx5_core_err (dev,"mlx5_hwmon_dev_register failed with error code %d\n" , err);Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) · line 1455
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);I wonder how we can make this work for all. I mean, other driver would silently ignore this command like arg, right? Any idea how to make all drivers follow the arg from very beginning?
I have a follow-up series that adds the call to all drivers which support setting eswitch mode. When going over the other drivers, what I found is that the right point to apply the default is driver specific, drivers I have patch for:
46e16c6d9836net: Apply devlink esw mode defaultsab4f54102ba9bnxt_en: Apply devlink default eswitch mode during initb48cce1607bbliquidio: Apply devlink default eswitch mode during init4ea54b0fe04aice: Apply devlink default eswitch mode during initb7faddaa1c90octeontx2-af: Apply devlink default eswitch mode during init74b0c22c47b9octeontx2-pf: Apply devlink default eswitch mode during init5000e4c3d768nfp: Apply devlink default eswitch mode during init97a218e95e41netdevsim: Apply devlink default eswitch mode during initQuoted 4 lines
I don't think doing this generically from devlink is realistic. devlink doesn't really know when a given driver is ready to change eswitch mode. Some drivers need SR-IOV state, representor setup, or other init pieces to be ready first, and the locking is not identical across drivers either.
Low hanging fruit would be just to call
ops->eswitch_mode_setat the end of register. Multiple reasons:1) end of
devl_registeris exactly the point userspace is free to issue the eswitch mode set. Driver should be ready to handle it.
2) all drivers would transparently get this functionality, without actually knowing this kernel command line arg ever existed, without odd wiring call of related exported function. I prefer that stongly.
3) you should add a there warning for the case this arg is passed yet the driver does not implementeswitch_mode_set. User should get a feedback like this, not silent ignore.Quoted 5 lines
The only loose end is see it the void return of
devl_register(). Multiple ways to handle the possibly failedeswitch_mode_set(). I would probably just go forpr_warn, seems to be the most correct.Make sense?
I see the point, but I don't think
devl_register()(at least not the only place) is the right place.There is a small but important difference between userspace doing "devlink eswitch set" after register is done, and devlink core calling
eswitch_mode_set()from inside the register flow.Quoted 8 lines
Quoted 6 lines
Some drivers call
devlink_register()while holding the device lock. liquidio is one example. If devlink core callsops->eswitch_mode_set()from there, we may start the full eswitch mode change while holding that lock. That mode change can create representors, register netdevs, take rtnl, allocate resources, etc. I don't think we want this to become an implicit side effect of devlink registration.I believe your AI may untagle liquidio locking :)
I didn't try to solve that one with ai. Most drivers were fairly simple so I didn't use ai at all. bnxt was the one where I needed a bit of help :)
Quoted 11 lines
Quoted 11 lines
For mlx5, the placement after
intf_state_mutexis also intentional:
mutex_unlock(&dev->intf_state_mutex);mlx5_devl_apply_default_esw_mode(dev);We can't call it while holding
intf_state_mutexbecause the mode set path takes it internally, and switchdev mode may also create IB representors.Quoted 7 lines
Quoted 5 lines
Also,
devl_register()only covers the first registration. The mlx5 call inmlx5_load_one_devl_locked()is for reload/fw reset recovery kind of flows. In those flows devlink is already registered, sodevl_register()is not called again, but the driver state was rebuilt and we may need to apply the default again.Call it from reload too, right?
Yes, that was my first thought: apply it from
devl_register()for the first registration and fromdevlink_reload()after a successfulDRIVER_REINIT.That covers the clean devlink reload path but....(see bellow)
Quoted 14 lines
Quoted 7 lines
Same for reload, fw reset and pci recovery in general. If the driver tears down and rebuilds eswitch related state, the place to apply the default is in that driver's reinit flow, not in
devl_register().Quoted 6 lines
When I went over the other drivers, the right place was not always the same as devlink registration. I'm not an expert in any of them, so I hope I got the details right, but for example octeontx2 AF needs sr-iov and the representor switch state to be initialized first. nfp can do it after app/vNIC init while the devlink lock is already held. liquidio should do it only after dropping the PCI device lock.
Quoted 2 lines
Idk, perhaps do it from
devlink_post_register_workof some kind? That would allow you to have the same locking ordering as a userspace call.
I thought about a workqueue too, it was actually my first idea.
Quoted 8 lines
Quoted 5 lines
The problem is that then we race with userspace. In the mlx5 version here the default is applied while the devlink lock is still held, before userspace can come in and issue its own eswitch set. If we defer it to post-register work, the devlink instance is already visible and userspace can get there first and then we might change the user configuration.
Figure that out and expose to user by setting
xa_markonly after the work is done? This is doable.I agree that if devlink can keep the instance hidden/unavailable until the post register work is done, that solves the initial userspace race.
The other part is the reinit/recovery case. For that I think devlink core needs some explicit indication from the driver that the device is now in reinit. Something like (at least that's the code I had initially, but something along those lines):
void
devl_dev_reinit_begin(struct devlink *devlink); voiddevl_dev_reinit_end(struct devlink *devlink); voiddevl_dev_reinit_abort(struct devlink *devlink);Quoted 9 lines
Quoted 5 lines
The core can then mark the instance as temporarily unavailable/in reinit between begin/end, and the relevant lookup/dump paths, for example
devlink_get_from_attrs_lock()anddevlink_nl_inst_iter_dumpit(), can reject or skip it while reinit is in progress.devlink_reload()can probably mark this state by itself aroundDRIVER_REINIT.I believe this is orthogonal to the problem you are trying to solve in this patchset. Not sure why you bring it in to the conversation...
I brought it up because I was also thinking about reinit/recovery flows, but I guess I can tackle that later.
For now I can focus on the generic devlink path, move drivers to register devlink only after the device is ready. Then devlink core can apply the default before exposing the instance to userspace.
Quoted 7 lines
I think it is better to fix the ordering for all devlink drivers, not only the ones that support eswitch mode set. That gives us a consistent model and makes future defaults easier.
Reload can be handled from devlink after successful
DRIVER_REINIT.Does this sound ok?
Yes. Thanks!
Quoted 109 lines
Mark
Quoted 105 lines
Quoted 105 lines
Then mlx5 would look more or less like:
devl_lock(devlink); devl_dev_reinit_begin(devlink); ret = mlx5_load_one_devl_locked(dev, recovery); if (!ret) devl_dev_reinit_end(devlink); else devl_dev_reinit_abort(devlink); devl_unlock(devlink);This gives devlink core a way to know that the devlink instance is registered, but should not be used by userspace at the moment. It also allows keeping the default/config apply logic in devlink instead of adding driver specific calls to apply it in each init path.
But this still means the generic solution needs some driver help. Drivers need to register devlink at a point where the post-register default apply is safe, and full reinit paths need to be marked with this begin/end API.
Quoted 12 lines
Quoted 7 lines
Also, the bigger issue for mlx5 is not only initial registration or devlink reload. Some recovery paths, pci resume, and fw reset flows rebuild the driver state without going through devlink at all. I did not find a clean way for devlink core to infer all those points by itself.
If you don't obey current configuration for example in pci resume, it is bug and you should fix it. All these flows should obey current eswitch mode configuration.
I agree that the device should come back according
to the intended high level policy. But I don't think full reinit can be treated as restoring the whole previous runtime state. There may be user created steering rules and other objects which the driver cannot keep or replay. Today full reinit brings the device back to a clean initialized state, and that is intentional.So the split I have in mind is:
- full runtime state is not preserved across full reinit;
- high level devlink policy/configuration should be applied when the device is initialized again;
- the command line default should not blindly override a later explicit userspace eswitch mode selection.I am not against moving this into devlink core, and I am willing to work on it.
But before I rework the series, I want to make sure we agree on the direction. As I see it, doing this cleanly needs a devlink state like "registered but unavailable/in reinit", plus driver annotations for the reinit paths.
If this is not the direction you want, I prefer to know now rather than spend time on a version that will be rejected anyway.
Mark
Quoted 44 lines
Quoted 44 lines
To handle that from devlink I would still need to add some api for the driver to tell devlink "I just reinitialized, apply the default now". but nce I had that driver call , it felt simpler and clearer to let the driver call the helper directly at the points where it knows eswitch mode is safe.
I agree that handling all of this inside devlink would be the better option. I just couldn't make it work in a clean way.
Mark
Quoted 31 lines
Quoted 31 lines
Mark
Quoted 26 lines
Quoted 26 lines
Also, since this knob is only about eswitch mode, I don't think we need to touch every devlink driver. Drivers that don't implement
eswitch_mode_set()would just ignore it anyway. The follow-up only wires the default into drivers that actually support changing eswitch mode.Mark
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-0return 0 ;
err_register:drivers/net/ethernet/mellanox/mlx5/core/main.c +1
-0@@ -1538,6 +1554,7 @@ int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) goto err_attach;mutex_unlock (&dev->intf_state_mutex); +mlx5_devl_apply_default_esw_mode (dev);return 0 ;
err_attach:Signature · 1 line
2.44.0
Jakub Kicinski
maintainerQuoted 3 lines · On Thu, 21 May 2026 10:24:31 +0300 Tariq Toukan wrote:
This series adds a devlink_eswitch_mode= kernel command line parameter for applying a default devlink eswitch mode during device initialization.
Jiri? Are you okay with this?
Jiri Pirko
maintainerQuoted 6 lines · Mon, May 25, 2026 at 09:42:56PM +0200, [email protected] wrote:
Quoted 3 lines · On Thu, 21 May 2026 10:24:31 +0300 Tariq Toukan wrote:
This series adds a devlink_eswitch_mode= kernel command line parameter for applying a default devlink eswitch mode during device initialization.
Jiri? Are you okay with this?
In general, yes. Couple of details perhaps. Let me check it more deep.