Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mpls: Add mpls_dev_rcu().

mpls_dev_get() uses rcu_dereference_rtnl() to fetch dev->mpls_ptr.

We will replace RTNL with a dedicated mutex to protect the field.

Then, we will use rcu_dereference_protected() for clarity.

Let's add mpls_dev_rcu() for the RCU reader.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/20251029173344.2934622-7-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
ab061f33 bc7ebc56

+12 -7
+6 -6
net/mpls/af_mpls.c
··· 136 136 struct mpls_dev *mdev; 137 137 138 138 if (skb->protocol == htons(ETH_P_MPLS_UC)) { 139 - mdev = mpls_dev_get(dev); 139 + mdev = mpls_dev_rcu(dev); 140 140 if (mdev) 141 141 MPLS_INC_STATS_LEN(mdev, skb->len, 142 142 tx_packets, ··· 358 358 359 359 /* Careful this entire function runs inside of an rcu critical section */ 360 360 361 - mdev = mpls_dev_get(dev); 361 + mdev = mpls_dev_rcu(dev); 362 362 if (!mdev) 363 363 goto drop; 364 364 ··· 467 467 return 0; 468 468 469 469 tx_err: 470 - out_mdev = out_dev ? mpls_dev_get(out_dev) : NULL; 470 + out_mdev = out_dev ? mpls_dev_rcu(out_dev) : NULL; 471 471 if (out_mdev) 472 472 MPLS_INC_STATS(out_mdev, tx_errors); 473 473 goto drop; ··· 1118 1118 struct mpls_dev *mdev; 1119 1119 struct nlattr *nla; 1120 1120 1121 - mdev = mpls_dev_get(dev); 1121 + mdev = mpls_dev_rcu(dev); 1122 1122 if (!mdev) 1123 1123 return -ENODATA; 1124 1124 ··· 1138 1138 { 1139 1139 struct mpls_dev *mdev; 1140 1140 1141 - mdev = mpls_dev_get(dev); 1141 + mdev = mpls_dev_rcu(dev); 1142 1142 if (!mdev) 1143 1143 return 0; 1144 1144 ··· 1341 1341 1342 1342 rcu_read_lock(); 1343 1343 for_each_netdev_dump(net, dev, ctx->ifindex) { 1344 - mdev = mpls_dev_get(dev); 1344 + mdev = mpls_dev_rcu(dev); 1345 1345 if (!mdev) 1346 1346 continue; 1347 1347 err = mpls_netconf_fill_devconf(skb, mdev,
+5
net/mpls/internal.h
··· 185 185 return result; 186 186 } 187 187 188 + static inline struct mpls_dev *mpls_dev_rcu(const struct net_device *dev) 189 + { 190 + return rcu_dereference(dev->mpls_ptr); 191 + } 192 + 188 193 static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev) 189 194 { 190 195 return rcu_dereference_rtnl(dev->mpls_ptr);
+1 -1
net/mpls/mpls_iptunnel.c
··· 153 153 return LWTUNNEL_XMIT_DONE; 154 154 155 155 drop: 156 - out_mdev = out_dev ? mpls_dev_get(out_dev) : NULL; 156 + out_mdev = out_dev ? mpls_dev_rcu(out_dev) : NULL; 157 157 if (out_mdev) 158 158 MPLS_INC_STATS(out_mdev, tx_errors); 159 159 kfree_skb(skb);