diff mbox series

[net-next] net: warn during dump if NAPI list is not sorted

Message ID 20250110004505.3210140-1-kuba@kernel.org (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: warn during dump if NAPI list is not sorted | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-01-10--09-00 (tests: 882)

Commit Message

Jakub Kicinski Jan. 10, 2025, 12:45 a.m. UTC
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.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
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.

CC: jdamato@fastly.com
CC: almasrymina@google.com
---
 net/core/netdev-genl.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Michal Swiatkowski Jan. 10, 2025, 6:16 a.m. UTC | #1
On Thu, Jan 09, 2025 at 04:45:04PM -0800, Jakub Kicinski 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.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> 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.
> 
> CC: jdamato@fastly.com
> CC: almasrymina@google.com
> ---
>  net/core/netdev-genl.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> index a3bdaf075b6b..c59619a2ec23 100644
> --- a/net/core/netdev-genl.c
> +++ b/net/core/netdev-genl.c
> @@ -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;
>  

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

> -- 
> 2.47.1
diff mbox series

Patch

diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index a3bdaf075b6b..c59619a2ec23 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -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;