]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: warn during dump if NAPI list is not sorted
authorJakub Kicinski <kuba@kernel.org>
Fri, 10 Jan 2025 00:45:04 +0000 (16:45 -0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 11 Jan 2025 02:36:43 +0000 (18:36 -0800)
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.

Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Reviewed-by: Joe Damato <jdamato@fastly.com>
Link: https://patch.msgid.link/20250110004505.3210140-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/netdev-genl.c

index a3bdaf075b6b95d16da0ff4ad0d625d370b8c985..c59619a2ec236e5a9a55f86ef2170fd00c896b53 100644 (file)
@@ -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;