Skip to contentSkip to conversation

net: warn during dump if NAPI list is not sorted

PATCH Applied Jakub Kicinski 4 participants 4 messages Jan 10, 2025 – Jan 11, 2025

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: warn during dump if NAPI list is not sorted

Dump continuation depends on the NAPI list being sorted. Broken netlink dump continuation may be rare and hard to debug so add a warning if we notice the potential problem while walking the list.

---
This is really a follow up to commit d6c7b03497ee ("net: make sure we retain NAPI ordering on netdev->napi_list") but I had to wait for some fixes to make it to net-next.

---
 net/core/netdev-genl.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/core/netdev-genl.c +7 -0
index a3bdaf075b6b..c59619a2ec23 100644
@@ -263,14 +263,21 @@ netdev_nl_napi_dump_one(struct net_device *netdev, struct sk_buff *rsp,
 			struct netdev_nl_dump_ctx *ctx)
 {
 	struct napi_struct *napi;
+	unsigned int prev_id;
 	int err = 0;
 
 	if (!(netdev->flags & IFF_UP))
 		return err;
 
+	prev_id = UINT_MAX;
 	list_for_each_entry(napi, &netdev->napi_list, dev_list) {
 		if (napi->napi_id < MIN_NAPI_ID)
 			continue;
+
+		/* Dump continuation below depends on the list being sorted */
+		WARN_ON_ONCE(napi->napi_id >= prev_id);
+		prev_id = napi->napi_id;
+
 		if (ctx->napi_id && napi->napi_id >= ctx->napi_id)
 			continue;
 
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Jakub Kicinski

Dump continuation depends on the NAPI list being sorted. Broken netlink dump continuation may be rare and hard to debug so add a warning if we notice the potential problem while walking the list.

---
This is really a follow up to commit d6c7b03497ee ("net: make sure we retain NAPI ordering on netdev->napi_list") but I had to wait for some fixes to make it to net-next.

---
 net/core/netdev-genl.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/core/netdev-genl.c +2 -0
index a3bdaf075b6b..c59619a2ec23 100644
@@ -263,14 +263,21 @@ netdev_nl_napi_dump_one(struct net_device *netdev, struct sk_buff *rsp,
 			struct netdev_nl_dump_ctx *ctx)
 {
 	struct napi_struct *napi;
+	unsigned int prev_id;
 	int err = 0;
 
 	if (!(netdev->flags & IFF_UP))
 		return err;
 
+	prev_id = UINT_MAX;
 	list_for_each_entry(napi, &netdev->napi_list, dev_list) {

net/core/netdev-genl.c netdev_nl_napi_dump_one(struct net_device *netdev, struct sk_buff *rsp, · line 283

Quoted 10 lines
net/core/netdev-genl.c +5 -0
 		if (napi->napi_id < MIN_NAPI_ID)
 			continue;
+
+		/* Dump continuation below depends on the list being sorted */
+		WARN_ON_ONCE(napi->napi_id >= prev_id);
+		prev_id = napi->napi_id;
+
 		if (ctx->napi_id && napi->napi_id >= ctx->napi_id)
 			continue;
 
Quoted 2 lines
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 11 lines · Jakub Kicinski

Dump continuation depends on the NAPI list being sorted. Broken netlink dump continuation may be rare and hard to debug so add a warning if we notice the potential problem while walking the list.

---
This is really a follow up to commit d6c7b03497ee ("net: make sure we retain NAPI ordering on netdev->napi_list") but I had to wait for some fixes to make it to net-next.

Quoted 5 lines
---
 net/core/netdev-genl.c | 7 +++++++
 1 file changed, 7 insertions(+)

Thanks.

#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 9 Jan 2025 16:45:04 -0800 you wrote:

Dump continuation depends on the NAPI list being sorted. Broken netlink dump continuation may be rare and hard to debug so add a warning if we notice the potential problem while walking the list.

[...]

Here is the summary with links:
- [net-next] net: warn during dump if NAPI list is not sorted

    https://git.kernel.org/netdev/net-next/c/af3525d41001

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html