From: Jakub Kicinski <kuba@kernel.org>
To: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
Yael Chemla <ychemla@nvidia.com>
Subject: Re: [PATCH v4 net 2/3] net: Fix dev_net(dev) race in unregister_netdevice_notifier_dev_net().
Date: Thu, 13 Feb 2025 08:32:17 -0800 [thread overview]
Message-ID: <20250213083217.77e18e10@kernel.org> (raw)
In-Reply-To: <20250212064206.18159-3-kuniyu@amazon.com>
On Wed, 12 Feb 2025 15:42:05 +0900 Kuniyuki Iwashima wrote:
> +static void rtnl_net_dev_lock(struct net_device *dev)
> +{
> + struct net *net;
> +
> +#ifdef CONFIG_NET_NS
> +again:
> +#endif
> + /* netns might be being dismantled. */
> + rcu_read_lock();
> + net = dev_net_rcu(dev);
> + net_passive_inc(net);
> + rcu_read_unlock();
> +
> + rtnl_net_lock(net);
> +
> +#ifdef CONFIG_NET_NS
> + /* dev might have been moved to another netns. */
> + if (!net_eq(net, rcu_access_pointer(dev->nd_net.net))) {
> + rtnl_net_unlock(net);
> + net_passive_dec(net);
> + goto again;
> + }
> +#endif
Is there a plan to clean this up in net-next? Or perhaps after Eric's
dev_net() work? Otherwise I'm tempted to suggest to use a loop, maybe:
bool again;
do {
again = false;
/* netns might be being dismantled. */
rcu_read_lock();
net = dev_net_rcu(dev);
net_passive_inc(net);
rcu_read_unlock();
rtnl_net_lock(net);
#ifdef CONFIG_NET_NS
/* dev might have been moved to another netns. */
if (!net_eq(net, rcu_access_pointer(dev->nd_net.net))) {
rtnl_net_unlock(net);
net_passive_dec(net);
again = true;
}
#endif
} while (again);
next prev parent reply other threads:[~2025-02-13 16:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 6:42 [PATCH v4 net 0/3] net: Fix race of rtnl_net_lock(dev_net(dev)) Kuniyuki Iwashima
2025-02-12 6:42 ` [PATCH v4 net 1/3] net: Add net_passive_inc() and net_passive_dec() Kuniyuki Iwashima
2025-02-12 13:52 ` Eric Dumazet
2025-02-12 6:42 ` [PATCH v4 net 2/3] net: Fix dev_net(dev) race in unregister_netdevice_notifier_dev_net() Kuniyuki Iwashima
2025-02-12 13:54 ` Eric Dumazet
2025-02-13 16:32 ` Jakub Kicinski [this message]
2025-02-14 0:25 ` Kuniyuki Iwashima
2025-02-14 21:08 ` Jakub Kicinski
2025-02-15 9:30 ` Kuniyuki Iwashima
2025-02-12 6:42 ` [PATCH v4 net 3/3] dev: Use rtnl_net_dev_lock() in unregister_netdev() Kuniyuki Iwashima
2025-02-12 13:55 ` Eric Dumazet
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=20250213083217.77e18e10@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ychemla@nvidia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).