All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bobby Eshleman <bobbyeshleman@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com, andrew+netdev@lunn.ch, horms@kernel.org,
	dw@davidwei.uk, daniel@iogearbox.net, razor@blackwall.org,
	sdf@fomichev.me, dtatulea@nvidia.com, bobbyeshleman@meta.com
Subject: Re: [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance
Date: Tue, 9 Jun 2026 13:15:05 -0700	[thread overview]
Message-ID: <aih0ST30H9rlKX2f@devvm29614.prn0.facebook.com> (raw)
In-Reply-To: <aihwlI9A2TKktq9I@devvm29614.prn0.facebook.com>

On Tue, Jun 09, 2026 at 12:59:16PM -0700, Bobby Eshleman wrote:
> On Tue, Jun 09, 2026 at 12:08:03PM -0700, Jakub Kicinski wrote:
> > If the currently dumped device disappears while we were mid-dump
> > we will get the next device without resetting the sub-object ID.
> > This is quite unlikely, it was reported by an AI tool not a real
> > user. Let's fix it for better dump consistency.
> > 
> > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> > ---
> >  net/core/netdev-genl.c | 22 +++++++++++++++++-----
> >  1 file changed, 17 insertions(+), 5 deletions(-)
> > 
> > diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> > index d35af460e886..18046ad0f883 100644
> > --- a/net/core/netdev-genl.c
> > +++ b/net/core/netdev-genl.c
> > @@ -310,11 +310,14 @@ int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
> >  			err = -ENODEV;
> >  		}
> >  	} else {
> > +		unsigned long start_ifindex = ctx->ifindex;
> > +
> >  		for_each_netdev_lock_scoped(net, netdev, ctx->ifindex) {
> > +			if (ctx->ifindex != start_ifindex)
> > +				ctx->napi_id = 0;
> >  			err = netdev_nl_napi_dump_one(netdev, skb, info, ctx);
> >  			if (err < 0)
> >  				break;
> > -			ctx->napi_id = 0;
> >  		}
> >  	}
> >  
> > @@ -634,13 +637,17 @@ int netdev_nl_queue_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
> >  			err = -ENODEV;
> >  		}
> >  	} else {
> > +		unsigned long start_ifindex = ctx->ifindex;
> > +
> >  		for_each_netdev_lock_ops_compat_scoped(net, netdev,
> >  						       ctx->ifindex) {
> > +			if (ctx->ifindex != start_ifindex) {
> > +				ctx->rxq_idx = 0;
> > +				ctx->txq_idx = 0;
> > +			}
> >  			err = netdev_nl_queue_dump_one(netdev, skb, info, ctx);
> >  			if (err < 0)
> >  				break;
> > -			ctx->rxq_idx = 0;
> > -			ctx->txq_idx = 0;
> >  		}
> >  	}
> >  
> > @@ -786,8 +793,6 @@ netdev_nl_stats_by_queue(struct net_device *netdev, struct sk_buff *rsp,
> >  		ctx->txq_idx = ++i;
> >  	}
> >  
> > -	ctx->rxq_idx = 0;
> > -	ctx->txq_idx = 0;
> >  	return 0;
> >  }
> >  
> > @@ -902,6 +907,7 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
> >  	struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb);
> >  	const struct genl_info *info = genl_info_dump(cb);
> >  	struct net *net = sock_net(skb->sk);
> > +	unsigned long start_ifindex;
> >  	struct net_device *netdev;
> >  	unsigned int ifindex;
> >  	unsigned int scope;
> > @@ -934,7 +940,13 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
> >  		return err;
> >  	}
> >  
> > +	start_ifindex = ctx->ifindex;
> > +
> >  	for_each_netdev_lock_ops_compat_scoped(net, netdev, ctx->ifindex) {
> > +		if (ctx->ifindex != start_ifindex) {
> > +			ctx->rxq_idx = 0;
> > +			ctx->txq_idx = 0;
> > +		}
> >  		err = netdev_nl_qstats_get_dump_one(netdev, scope, skb,
> >  						    info, ctx);
> >  		if (err < 0)
> > -- 
> > 2.54.0
> > 
> > 
> 
> Reviewed-by: Bobby Eshleman <bobbyeshleman@meta.com>

I just noticed we handle this differently in rtnetlink with
cb->seq/dev_base_seq/nl_dump_check_consistent(), but it seems like
netdev-genl.c intentionally does not use NLM_F_DUMP_INTR?

Best,
Bobby

  reply	other threads:[~2026-06-09 20:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 19:08 [PATCH net-next 0/4] netdev: address a handful of nit picks Jakub Kicinski
2026-06-09 19:08 ` [PATCH net-next 1/4] netdev: check for nla_put_u32() failures Jakub Kicinski
2026-06-09 19:24   ` Bobby Eshleman
2026-06-09 19:52   ` Daniel Borkmann
2026-06-09 22:05     ` Jakub Kicinski
2026-06-09 19:56   ` Joe Damato
2026-06-09 19:08 ` [PATCH net-next 2/4] netdev: correct error code in netdev_nl_queue_fill_lease() Jakub Kicinski
2026-06-09 19:16   ` Bobby Eshleman
2026-06-09 19:48   ` Daniel Borkmann
2026-06-09 19:57   ` Joe Damato
2026-06-09 19:08 ` [PATCH net-next 3/4] netdev: avoid skipping objects on race with device disappearance Jakub Kicinski
2026-06-09 19:48   ` Daniel Borkmann
2026-06-09 19:59   ` Bobby Eshleman
2026-06-09 20:15     ` Bobby Eshleman [this message]
2026-06-09 21:19       ` Jakub Kicinski
2026-06-09 22:04         ` Bobby Eshleman
2026-06-09 19:08 ` [PATCH net-next 4/4] netdev: don't use dev->flags for IFF_UP Jakub Kicinski
2026-06-09 19:49   ` Daniel Borkmann
2026-06-09 19:54   ` Joe Damato
2026-06-09 20:00   ` Bobby Eshleman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aih0ST30H9rlKX2f@devvm29614.prn0.facebook.com \
    --to=bobbyeshleman@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bobbyeshleman@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=dw@davidwei.uk \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=sdf@fomichev.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.