Skip to content

Commit caedcc5

Browse files
edumazetkuba-moo
authored andcommitted
net: dst: introduce dst->dev_rcu
Followup of commit 88fe142 ("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: 4a6ce2b ("net: introduce a new function dst_dev_put()") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e71aa5a commit caedcc5

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

include/net/dst.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
struct sk_buff;
2525

2626
struct dst_entry {
27-
struct net_device *dev;
27+
union {
28+
struct net_device *dev;
29+
struct net_device __rcu *dev_rcu;
30+
};
2831
struct dst_ops *ops;
2932
unsigned long _metrics;
3033
unsigned long expires;
@@ -570,9 +573,12 @@ static inline struct net_device *dst_dev(const struct dst_entry *dst)
570573

571574
static inline struct net_device *dst_dev_rcu(const struct dst_entry *dst)
572575
{
573-
/* In the future, use rcu_dereference(dst->dev) */
574-
WARN_ON_ONCE(!rcu_read_lock_held());
575-
return READ_ONCE(dst->dev);
576+
return rcu_dereference(dst->dev_rcu);
577+
}
578+
579+
static inline struct net *dst_dev_net_rcu(const struct dst_entry *dst)
580+
{
581+
return dev_net_rcu(dst_dev_rcu(dst));
576582
}
577583

578584
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)
592598

593599
static inline struct net *skb_dst_dev_net_rcu(const struct sk_buff *skb)
594600
{
595-
return dev_net_rcu(skb_dst_dev(skb));
601+
return dev_net_rcu(skb_dst_dev_rcu(skb));
596602
}
597603

598604
struct dst_entry *dst_blackhole_check(struct dst_entry *dst, u32 cookie);

net/core/dst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void dst_dev_put(struct dst_entry *dst)
150150
dst->ops->ifdown(dst, dev);
151151
WRITE_ONCE(dst->input, dst_discard);
152152
WRITE_ONCE(dst->output, dst_discard_out);
153-
WRITE_ONCE(dst->dev, blackhole_netdev);
153+
rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
154154
netdev_ref_replace(dev, blackhole_netdev, &dst->dev_tracker,
155155
GFP_ATOMIC);
156156
}

net/ipv4/route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
10271027
return;
10281028

10291029
rcu_read_lock();
1030-
net = dev_net_rcu(dst_dev(dst));
1030+
net = dst_dev_net_rcu(dst);
10311031
if (mtu < net->ipv4.ip_rt_min_pmtu) {
10321032
lock = true;
10331033
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)
13271327
struct net *net;
13281328

13291329
rcu_read_lock();
1330-
net = dev_net_rcu(dst_dev(dst));
1330+
net = dst_dev_net_rcu(dst);
13311331
advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size,
13321332
net->ipv4.ip_rt_min_advmss);
13331333
rcu_read_unlock();

0 commit comments

Comments
 (0)