]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: dst: introduce dst->dev_rcu
authorEric Dumazet <edumazet@google.com>
Thu, 28 Aug 2025 19:58:16 +0000 (19:58 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sat, 30 Aug 2025 02:36:31 +0000 (19:36 -0700)
Followup of commit 88fe14253e18 ("net: dst: add four helpers
to annotate data-races around dst->dev").

We want to gradually add explicit RCU protection to dst->dev,
including lockdep support.

Add an union to alias dst->dev_rcu and dst->dev.

Add dst_dev_net_rcu() helper.

Fixes: 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20250828195823.3958522-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/dst.h
net/core/dst.c
net/ipv4/route.c

index bab01363bb975dc20ea0e1485a515c1872537ab9..f8aa1239b4db639bd6b63f4ddb4ec4d7ee459ac0 100644 (file)
 struct sk_buff;
 
 struct dst_entry {
-       struct net_device       *dev;
+       union {
+               struct net_device       *dev;
+               struct net_device __rcu *dev_rcu;
+       };
        struct  dst_ops         *ops;
        unsigned long           _metrics;
        unsigned long           expires;
@@ -570,9 +573,12 @@ static inline struct net_device *dst_dev(const struct dst_entry *dst)
 
 static inline struct net_device *dst_dev_rcu(const struct dst_entry *dst)
 {
-       /* In the future, use rcu_dereference(dst->dev) */
-       WARN_ON_ONCE(!rcu_read_lock_held());
-       return READ_ONCE(dst->dev);
+       return rcu_dereference(dst->dev_rcu);
+}
+
+static inline struct net *dst_dev_net_rcu(const struct dst_entry *dst)
+{
+       return dev_net_rcu(dst_dev_rcu(dst));
 }
 
 static inline struct net_device *skb_dst_dev(const struct sk_buff *skb)
@@ -592,7 +598,7 @@ static inline struct net *skb_dst_dev_net(const struct sk_buff *skb)
 
 static inline struct net *skb_dst_dev_net_rcu(const struct sk_buff *skb)
 {
-       return dev_net_rcu(skb_dst_dev(skb));
+       return dev_net_rcu(skb_dst_dev_rcu(skb));
 }
 
 struct dst_entry *dst_blackhole_check(struct dst_entry *dst, u32 cookie);
index e2de8b68c41d3fa6f8a94b61b88f531a2d79d3b4..e9d35f49c9e7800d7397b643c70931dd516a6265 100644 (file)
@@ -150,7 +150,7 @@ void dst_dev_put(struct dst_entry *dst)
                dst->ops->ifdown(dst, dev);
        WRITE_ONCE(dst->input, dst_discard);
        WRITE_ONCE(dst->output, dst_discard_out);
-       WRITE_ONCE(dst->dev, blackhole_netdev);
+       rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
        netdev_ref_replace(dev, blackhole_netdev, &dst->dev_tracker,
                           GFP_ATOMIC);
 }
index cc86a917a1bbbd3a207f82906d30436f29beb448..44382d17558909318770acdf43d2c3b1da2b621c 100644 (file)
@@ -1027,7 +1027,7 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
                return;
 
        rcu_read_lock();
-       net = dev_net_rcu(dst_dev(dst));
+       net = dst_dev_net_rcu(dst);
        if (mtu < net->ipv4.ip_rt_min_pmtu) {
                lock = true;
                mtu = min(old_mtu, net->ipv4.ip_rt_min_pmtu);
@@ -1327,7 +1327,7 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
        struct net *net;
 
        rcu_read_lock();
-       net = dev_net_rcu(dst_dev(dst));
+       net = dst_dev_net_rcu(dst);
        advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size,
                                   net->ipv4.ip_rt_min_advmss);
        rcu_read_unlock();