]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
inet: prepare inet_base_seq() to run without RTNL
authorEric Dumazet <edumazet@google.com>
Thu, 29 Feb 2024 11:40:15 +0000 (11:40 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Mar 2024 11:09:39 +0000 (11:09 +0000)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/dev.c
net/ipv4/devinet.c

index 4868e67345096dc37e35b3e19ac5673f08b8cf2b..fe054cbd41e92cbca87f1c0640c6ebe4fb6b2d86 100644 (file)
@@ -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)
index 550b775cbbf3c140c66e224c69996df7051b3d36..2afe78dfc3c2f6c0394925f1c35532a2dfd26d71 100644 (file)
@@ -1837,7 +1837,7 @@ done:
 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.