* [PATCH net v2] netdevsim: fix rate node leak during reload and removal
@ 2026-11-21 11:08 xietangxin
2026-11-23 8:09 ` Xuanqiang Luo
2026-11-25 11:22 ` netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: xietangxin @ 2026-11-21 11:08 UTC (permalink / raw)
To: Jakub Kicinski, Andrew Lunn, David S . Miller, Eric Dumazet, Paolo Abeni
Cc: Dmytro Linkin, Vlad Buslov, Jiri Pirko, netdev, linux-kernel,
stable, syzbot+bbd81e1e2276c534dea1, gaoxingwang1, huyizhen2,
Xuanqiang Luo
netdevsim allows switching the eswitch mode to switchdev with zero VFs
and creating rate nodes on such a device. However during device teardown
nsim_dev_reload_destroy() only drops the eswitch back to legacy when VFs
were configured, so the rate nodes are never destroyed and trigger the
WARN_ON(devlink_rates_check()) in devlink_free():
WARNING: net/devlink/core.c:544 at devlink_free+0x18c/0x26c, CPU#2: bash/5032
Modules linked in: netdevsim ...
CPU: 2 UID: 0 PID: 5032 Comm: bash Not tainted 7.4.0-rc3+ #77 PREEMPTLAZY
Call trace:
devlink_free+0x18c/0x26c (P)
nsim_drv_remove+0x9c/0xb4 [netdevsim]
nsim_bus_remove+0x10/0x1c [netdevsim]
del_device_store+0x110/0x190 [netdevsim]
...
The rate nodes are also left behind on the devlink reload path, where
they trigger the WARN in devlink_reload_reinit_sanity_check() instead:
WARNING: net/devlink/dev.c:437 at devlink_reload_reinit_sanity_check+0x110/0x148, CPU#3: devlink/5205
Modules linked in: netdevsim ...
CPU: 3 UID: 0 PID: 5205 Comm: devlink Not tainted 7.4.0-rc3+ #77 PREEMPTLAZY
Call trace:
devlink_reload_reinit_sanity_check+0x110/0x148 (P)
devlink_reload+0x218/0x228
devlink_nl_reload_doit+0x3dc/0x5b4
...
Evaluate the eswitch mode check unconditionally, so rate nodes are
destroyed whether or not any VF was ever configured. Note this also
resets a zero-VF switchdev device back to legacy mode on reload, like
the existing VF case.
Reproduce by:
$ echo "10 1" > /sys/bus/netdevsim/new_device
$ devlink dev eswitch set netdevsim/netdevsim10 mode switchdev
$ devlink port function rate add netdevsim/netdevsim10/n1
$ echo 10 > /sys/bus/netdevsim/del_device
Replacing the last step with "devlink dev reload netdevsim/netdevsim10"
hits the devlink_reload_reinit_sanity_check() WARN instead.
Fixes: 885226f5680e ("netdevsim: Implement support for devlink rate nodes")
Cc: stable@vger.kernel.org
Reported-by: syzbot+bbd81e1e2276c534dea1@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/6af9824c.920b2b3a.148c65.0009.GAE@google.com/
Reported-by: Xuanqiang Luo <xuanqiang.luo@linux.dev>
Link: https://lore.kernel.org/all/17cc4251-04ae-41a7-a872-fc5cf525b58f@linux.dev/
Signed-off-by: xietangxin <xietangxin@h-partners.com>
---
v2: add reload path description
---
drivers/net/netdevsim/dev.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index c6b17b387327..b483c25dfecd 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -1700,11 +1700,10 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
return;
debugfs_remove(nsim_dev->take_snapshot);
- if (nsim_dev_get_vfs(nsim_dev)) {
+ if (nsim_dev_get_vfs(nsim_dev))
nsim_bus_dev_set_vfs(nsim_dev->nsim_bus_dev, 0);
- if (nsim_esw_mode_is_switchdev(nsim_dev))
- nsim_esw_legacy_enable(nsim_dev, NULL);
- }
+ if (nsim_esw_mode_is_switchdev(nsim_dev))
+ nsim_esw_legacy_enable(nsim_dev, NULL);
nsim_dev_port_del_all(nsim_dev);
nsim_dev_hwstats_exit(nsim_dev);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] netdevsim: fix rate node leak during reload and removal 2026-11-21 11:08 [PATCH net v2] netdevsim: fix rate node leak during reload and removal xietangxin @ 2026-11-23 8:09 ` Xuanqiang Luo 2026-11-25 11:22 ` netdev-bot+sashiko 1 sibling, 0 replies; 4+ messages in thread From: Xuanqiang Luo @ 2026-11-23 8:09 UTC (permalink / raw) To: xietangxin Cc: Dmytro Linkin, Vlad Buslov, Jiri Pirko, netdev, linux-kernel, stable, syzbot+bbd81e1e2276c534dea1, gaoxingwang1, huyizhen2, Jakub Kicinski, Andrew Lunn, David S . Miller, Eric Dumazet, Paolo Abeni On 2026/11/21 at 20:08 xietangxin wrote: > netdevsim allows switching the eswitch mode to switchdev with zero VFs > and creating rate nodes on such a device. However during device teardown > nsim_dev_reload_destroy() only drops the eswitch back to legacy when VFs > were configured, so the rate nodes are never destroyed and trigger the > WARN_ON(devlink_rates_check()) in devlink_free(): > > WARNING: net/devlink/core.c:544 at devlink_free+0x18c/0x26c, CPU#2: bash/5032 > Modules linked in: netdevsim ... > CPU: 2 UID: 0 PID: 5032 Comm: bash Not tainted 7.4.0-rc3+ #77 PREEMPTLAZY > Call trace: > devlink_free+0x18c/0x26c (P) > nsim_drv_remove+0x9c/0xb4 [netdevsim] > nsim_bus_remove+0x10/0x1c [netdevsim] > del_device_store+0x110/0x190 [netdevsim] > ... > > The rate nodes are also left behind on the devlink reload path, where > they trigger the WARN in devlink_reload_reinit_sanity_check() instead: > > WARNING: net/devlink/dev.c:437 at devlink_reload_reinit_sanity_check+0x110/0x148, CPU#3: devlink/5205 > Modules linked in: netdevsim ... > CPU: 3 UID: 0 PID: 5205 Comm: devlink Not tainted 7.4.0-rc3+ #77 PREEMPTLAZY > Call trace: > devlink_reload_reinit_sanity_check+0x110/0x148 (P) > devlink_reload+0x218/0x228 > devlink_nl_reload_doit+0x3dc/0x5b4 > ... > > Evaluate the eswitch mode check unconditionally, so rate nodes are > destroyed whether or not any VF was ever configured. Note this also > resets a zero-VF switchdev device back to legacy mode on reload, like > the existing VF case. > > Reproduce by: > $ echo "10 1" > /sys/bus/netdevsim/new_device > $ devlink dev eswitch set netdevsim/netdevsim10 mode switchdev > $ devlink port function rate add netdevsim/netdevsim10/n1 > $ echo 10 > /sys/bus/netdevsim/del_device > > Replacing the last step with "devlink dev reload netdevsim/netdevsim10" > hits the devlink_reload_reinit_sanity_check() WARN instead. > > Fixes: 885226f5680e ("netdevsim: Implement support for devlink rate nodes") > Cc: stable@vger.kernel.org > Reported-by: syzbot+bbd81e1e2276c534dea1@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/netdev/6af9824c.920b2b3a.148c65.0009.GAE@google.com/ > Reported-by: Xuanqiang Luo <xuanqiang.luo@linux.dev> > Link: https://lore.kernel.org/all/17cc4251-04ae-41a7-a872-fc5cf525b58f@linux.dev/ > Signed-off-by: xietangxin <xietangxin@h-partners.com> > --- Reviewed-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn> Thanks, Xuanqiang ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] netdevsim: fix rate node leak during reload and removal 2026-11-21 11:08 [PATCH net v2] netdevsim: fix rate node leak during reload and removal xietangxin 2026-11-23 8:09 ` Xuanqiang Luo @ 2026-11-25 11:22 ` netdev-bot+sashiko 2026-11-28 10:16 ` xietangxin 1 sibling, 1 reply; 4+ messages in thread From: netdev-bot+sashiko @ 2026-11-25 11:22 UTC (permalink / raw) To: xietangxin Cc: kuba, andrew+netdev, davem, edumazet, pabeni, dlinkin, vladbu, jiri, netdev, linux-kernel, stable, syzbot+bbd81e1e2276c534dea1, gaoxingwang1, huyizhen2, xuanqiang.luo Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The fix is incomplete: rate nodes still leak, and the same WARNs still fire, when the device has been left in the devlink… -- netdevsim: fix rate node leak during reload and removal nsim_dev_reload_destroy() now checks the eswitch mode unconditionally. Rate nodes created on a zero-VF switchdev device are then destroyed via nsim_esw_legacy_enable() -> devl_rate_nodes_destroy() on both reload and removal, which avoids the devlink_free() and devlink_reload_reinit_sanity_check() WARNs. Link: https://lore.kernel.org/all/17cc4251-04ae-41a7-a872-fc5cf525b58f@linux.dev/ > diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c > index c6b17b3873271..b483c25dfecdd 100644 > --- a/drivers/net/netdevsim/dev.c > +++ b/drivers/net/netdevsim/dev.c > @@ -1700,11 +1700,10 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) > return; > debugfs_remove(nsim_dev->take_snapshot); > > - if (nsim_dev_get_vfs(nsim_dev)) { > + if (nsim_dev_get_vfs(nsim_dev)) > nsim_bus_dev_set_vfs(nsim_dev->nsim_bus_dev, 0); > - if (nsim_esw_mode_is_switchdev(nsim_dev)) > - nsim_esw_legacy_enable(nsim_dev, NULL); > - } > + if (nsim_esw_mode_is_switchdev(nsim_dev)) > + nsim_esw_legacy_enable(nsim_dev, NULL); [Severity: Medium] Can rate nodes still leak when the device is in the reload_failed state? The new unconditional check sits after the early return at the top of nsim_dev_reload_destroy(): drivers/net/netdevsim/dev.c:nsim_dev_reload_destroy() { ... if (devlink_is_reload_failed(devlink)) return; ... } When reload_failed is set, devl_rate_nodes_destroy() is never reached. Nothing seems to stop rate nodes from being created while reload_failed is set. One possible sequence: 1) devlink dev reload runs nsim_dev_reload_down(), which resets esw_mode to legacy. nsim_dev_reload_up() then fails, either through the fail_reload debugfs knob (returns -EINVAL) or through an error in nsim_dev_reload_create(). devlink_reload() then calls: devlink_reload_failed_set(devlink, !!err); 2) devlink dev eswitch set ... mode switchdev still succeeds. With zero VFs, nsim_esw_switchdev_enable() only does: nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV; No devlink command in net/devlink/ checks reload_failed. 3) devlink port function rate add .../n1 also succeeds. devlink_nl_rate_new_doit() has no reload_failed check, and nsim_rate_node_new() only checks nsim_esw_mode_is_switchdev(). The node is added to devlink->rate_list. 4) del_device leads to nsim_drv_remove() -> nsim_dev_reload_destroy(), which returns early. nsim_drv_remove() has no other rate cleanup, so devlink_free() hits: WARN_ON(devlink_rates_check(devlink, NULL, NULL)); The devlink_rate and nsim_rate_node allocations and their debugfs directories are leaked. If step 4 is a second devlink dev reload instead, nsim_dev_reload_down() -> nsim_dev_reload_destroy() returns early again, and the WARN in devlink_reload_reinit_sanity_check() fires. These are the same two WARNs the commit message describes. The early return is older than this patch. However, the subject promises to fix the rate node leak during reload and removal, and this case is still reachable. Would it make sense to also destroy the rate nodes before the reload_failed early return, or in nsim_drv_remove()? > > nsim_dev_port_del_all(nsim_dev); > nsim_dev_hwstats_exit(nsim_dev); -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121110858.1337003-1-xietangxin%40h-partners.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] netdevsim: fix rate node leak during reload and removal 2026-11-25 11:22 ` netdev-bot+sashiko @ 2026-11-28 10:16 ` xietangxin 0 siblings, 0 replies; 4+ messages in thread From: xietangxin @ 2026-11-28 10:16 UTC (permalink / raw) To: netdev-bot+sashiko Cc: kuba, andrew+netdev, davem, edumazet, pabeni, dlinkin, vladbu, jiri, netdev, linux-kernel, stable, syzbot+bbd81e1e2276c534dea1, gaoxingwang1, huyizhen2, xuanqiang.luo On 11/25/2026 7:22 PM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue(s) to consider. > > Critical: 0 · High: 0 · Medium: 1 · Low: 0 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwork > know by including "pw-bot: cr" as a separate line at the end of your reply > (one such reply per series is enough). > > - [Medium] The fix is incomplete: rate nodes still leak, and the same > WARNs still fire, when the device has been left in the devlink… > > -- > > netdevsim: fix rate node leak during reload and removal > > nsim_dev_reload_destroy() now checks the eswitch mode unconditionally. > Rate nodes created on a zero-VF switchdev device are then destroyed via > nsim_esw_legacy_enable() -> devl_rate_nodes_destroy() on both reload and > removal, which avoids the devlink_free() and > devlink_reload_reinit_sanity_check() WARNs. > > Link: https://lore.kernel.org/all/17cc4251-04ae-41a7-a872-fc5cf525b58f@linux.dev/ > >> diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c >> index c6b17b3873271..b483c25dfecdd 100644 >> --- a/drivers/net/netdevsim/dev.c >> +++ b/drivers/net/netdevsim/dev.c >> @@ -1700,11 +1700,10 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) >> return; >> debugfs_remove(nsim_dev->take_snapshot); >> >> - if (nsim_dev_get_vfs(nsim_dev)) { >> + if (nsim_dev_get_vfs(nsim_dev)) >> nsim_bus_dev_set_vfs(nsim_dev->nsim_bus_dev, 0); >> - if (nsim_esw_mode_is_switchdev(nsim_dev)) >> - nsim_esw_legacy_enable(nsim_dev, NULL); >> - } >> + if (nsim_esw_mode_is_switchdev(nsim_dev)) >> + nsim_esw_legacy_enable(nsim_dev, NULL); > > [Severity: Medium] > Can rate nodes still leak when the device is in the reload_failed state? > > The new unconditional check sits after the early return at the top of > nsim_dev_reload_destroy(): > > drivers/net/netdevsim/dev.c:nsim_dev_reload_destroy() { > ... > if (devlink_is_reload_failed(devlink)) > return; > ... > } > > When reload_failed is set, devl_rate_nodes_destroy() is never reached. > > Nothing seems to stop rate nodes from being created while reload_failed > is set. One possible sequence: > > 1) devlink dev reload runs nsim_dev_reload_down(), which resets > esw_mode to legacy. nsim_dev_reload_up() then fails, either through > the fail_reload debugfs knob (returns -EINVAL) or through an error in > nsim_dev_reload_create(). devlink_reload() then calls: > > devlink_reload_failed_set(devlink, !!err); > > 2) devlink dev eswitch set ... mode switchdev still succeeds. With zero > VFs, nsim_esw_switchdev_enable() only does: > > nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV; > > No devlink command in net/devlink/ checks reload_failed. > > 3) devlink port function rate add .../n1 also succeeds. > devlink_nl_rate_new_doit() has no reload_failed check, and > nsim_rate_node_new() only checks nsim_esw_mode_is_switchdev(). The > node is added to devlink->rate_list. > > 4) del_device leads to nsim_drv_remove() -> nsim_dev_reload_destroy(), > which returns early. nsim_drv_remove() has no other rate cleanup, so > devlink_free() hits: > > WARN_ON(devlink_rates_check(devlink, NULL, NULL)); > > The devlink_rate and nsim_rate_node allocations and their debugfs > directories are leaked. > > If step 4 is a second devlink dev reload instead, > nsim_dev_reload_down() -> nsim_dev_reload_destroy() returns early again, > and the WARN in devlink_reload_reinit_sanity_check() fires. > > These are the same two WARNs the commit message describes. The early > return is older than this patch. However, the subject promises to fix the > rate node leak during reload and removal, and this case is still > reachable. > > Would it make sense to also destroy the rate nodes before the > reload_failed early return, or in nsim_drv_remove()? > >> >> nsim_dev_port_del_all(nsim_dev); >> nsim_dev_hwstats_exit(nsim_dev); > You are right, the case is reachable. I confirmed it on an unfixed kernel (v7.4-rc4): # echo 1 > /sys/kernel/debug/netdevsim/netdevsim10/fail_reload # devlink dev reload netdevsim/netdevsim10 Error: netdevsim: User setup the reload to fail for testing purposes. # devlink dev eswitch set netdevsim/netdevsim10 mode switchdev # devlink port function rate add netdevsim/netdevsim10/n1 # echo 10 > /sys/bus/netdevsim/del_device [ 962.254414] WARNING: net/devlink/core.c:544 at devlink_free+0x18c/0x26c So a rate node added after a failed reload is not cleaned up on removal and the devlink_free() WARN fires again. I will respin. Instead of destroying the rate nodes before the reload_failed early return, v3 will follow the approach of commit 39c23556e79f ("netdevsim: reject port addition and clean up ports after a failed reload") and reject rate node creation with -EIO while the reload has failed. The respin will also be posted targeting net-next instead of net and will drop the Cc: stable tag, following the routing of that commit. static int nsim_rate_node_new(struct devlink_rate *node, void **priv, struct netlink_ext_ack *extack) { struct nsim_dev *nsim_dev = devlink_priv(node->devlink); struct nsim_rate_node *nsim_node; + if (devlink_is_reload_failed(node->devlink)) + return -EIO; + if (!nsim_esw_mode_is_switchdev(nsim_dev)) { Rate nodes cannot exist at the moment reload_failed is set: the failing reload's reload_down() -> nsim_dev_reload_destroy() destroys them before reload_up() records the failure, so blocking the post-failure creation path closes the leak completely. pw-bot: cr -- Best regards, Tangxin Xie ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-28 10:16 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-21 11:08 [PATCH net v2] netdevsim: fix rate node leak during reload and removal xietangxin 2026-11-23 8:09 ` Xuanqiang Luo 2026-11-25 11:22 ` netdev-bot+sashiko 2026-11-28 10:16 ` xietangxin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®