public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Jiri Pirko <jiri@nvidia.com>, David Ahern <dsahern@kernel.org>,
	netdev@vger.kernel.org,  Florian Westphal <fw@strlen.de>,
	eric.dumazet@gmail.com, Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 5/6] inet: prepare inet_base_seq() to run without RTNL
Date: Thu, 29 Feb 2024 11:40:15 +0000	[thread overview]
Message-ID: <20240229114016.2995906-6-edumazet@google.com> (raw)
In-Reply-To: <20240229114016.2995906-1-edumazet@google.com>

In the following patch, inet_base_seq() will no longer be called
with RTNL held.

Add READ_ONCE()/WRITE_ONCE() annotations in dev_base_seq_inc()
and inet_base_seq().

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/core/dev.c     | 5 +++--
 net/ipv4/devinet.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 053fac78305c7322b894ceb07a925f7e64ed70aa..873e095e141db3e631e51763435ddafbf0d280af 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -180,8 +180,9 @@ static DECLARE_RWSEM(devnet_rename_sem);
 
 static inline void dev_base_seq_inc(struct net *net)
 {
-	while (++net->dev_base_seq == 0)
-		;
+	unsigned int val = net->dev_base_seq + 1;
+
+	WRITE_ONCE(net->dev_base_seq, val ?: 1);
 }
 
 static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 550b775cbbf3c140c66e224c69996df7051b3d36..2afe78dfc3c2f6c0394925f1c35532a2dfd26d71 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1837,7 +1837,7 @@ static int in_dev_dump_addr(struct in_device *in_dev, struct sk_buff *skb,
 static u32 inet_base_seq(const struct net *net)
 {
 	u32 res = atomic_read(&net->ipv4.dev_addr_genid) +
-		  net->dev_base_seq;
+		  READ_ONCE(net->dev_base_seq);
 
 	/* Must not return 0 (see nl_dump_check_consistent()).
 	 * Chose a value far away from 0.
-- 
2.44.0.278.ge034bb2e1d-goog


  parent reply	other threads:[~2024-02-29 11:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 11:40 [PATCH net-next 0/6] inet: no longer use RTNL to protect inet_dump_ifaddr() Eric Dumazet
2024-02-29 11:40 ` [PATCH net-next 1/6] inet: annotate data-races around ifa->ifa_tstamp and ifa->ifa_cstamp Eric Dumazet
2024-02-29 11:40 ` [PATCH net-next 2/6] inet: annotate data-races around ifa->ifa_valid_lft Eric Dumazet
2024-02-29 11:40 ` [PATCH net-next 3/6] inet: annotate data-races around ifa->ifa_preferred_lft Eric Dumazet
2024-02-29 11:40 ` [PATCH net-next 4/6] inet: annotate data-races around ifa->ifa_flags Eric Dumazet
2024-02-29 11:40 ` Eric Dumazet [this message]
2024-02-29 11:40 ` [PATCH net-next 6/6] inet: use xa_array iterator to implement inet_dump_ifaddr() Eric Dumazet
2024-02-29 15:37   ` Jakub Kicinski
2024-02-29 15:45     ` Eric Dumazet
2024-02-29 15:50       ` Eric Dumazet
2024-02-29 16:21         ` Jakub Kicinski
2024-02-29 16:26           ` Eric Dumazet
2024-02-29 14:18 ` [PATCH net-next 0/6] inet: no longer use RTNL to protect inet_dump_ifaddr() Jiri Pirko
2024-03-01 11:20 ` patchwork-bot+netdevbpf

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=20240229114016.2995906-6-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eric.dumazet@gmail.com \
    --cc=fw@strlen.de \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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