Thread (4 messages) 4 messages, 2 authors, 10d ago
COOLING10d

[PATCH net-next 2/2] vlan: no longer rely on RTNL in vlan_fill_info()

From: Eric Dumazet <edumazet@google.com>
Date: 2026-09-16 13:25:39
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

vlan_fill_info() used rcu_dereference_rtnl() to walk the egress
priority map, forcing "ip link show" dumps to hold RTNL.

The egress priority map is already fully RCU compliant:
entries are published with rcu_assign_pointer() and freed with
kfree_rcu() from vlan_dev_set_egress_priority() and
vlan_dev_free_egress_priority().

Wrap the QoS mapping serialization in rcu_read_lock() /
rcu_read_unlock() and use rcu_dereference().

Now that all the involved fields are annotated, use READ_ONCE()
for vlan->flags, vlan->nr_ingress_mappings, vlan->nr_egress_mappings
and vlan->ingress_priority_map[].

Also add missing const qualifiers in vlan_get_size() and
vlan_fill_info().

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/8021q/vlan_netlink.c | 48 +++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 71cb98950511fe30f9b117834ce8b9107889f0cb..8c0c33cff4539f22d7fdca2bec68dc484c55209f 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -209,7 +209,7 @@ static inline size_t vlan_qos_map_size(unsigned int n)
 
 static size_t vlan_get_size(const struct net_device *dev)
 {
-	struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
+	const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
 
 	return nla_total_size(2) +	/* IFLA_VLAN_PROTOCOL */
 	       nla_total_size(2) +	/* IFLA_VLAN_ID */
@@ -220,60 +220,72 @@ static size_t vlan_get_size(const struct net_device *dev)
 
 static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
 {
-	struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
-	struct vlan_priority_tci_mapping *pm;
-	struct ifla_vlan_flags f;
+	const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
+	const struct vlan_priority_tci_mapping *pm;
 	struct ifla_vlan_qos_mapping m;
+	struct ifla_vlan_flags f;
 	struct nlattr *nest;
 	unsigned int i;
+	u32 flags;
 
 	if (nla_put_be16(skb, IFLA_VLAN_PROTOCOL, vlan->vlan_proto) ||
 	    nla_put_u16(skb, IFLA_VLAN_ID, vlan->vlan_id))
 		goto nla_put_failure;
-	if (vlan->flags) {
-		f.flags = vlan->flags;
+
+	flags = READ_ONCE(vlan->flags);
+	if (flags) {
+		f.flags = flags;
 		f.mask  = ~0;
 		if (nla_put(skb, IFLA_VLAN_FLAGS, sizeof(f), &f))
 			goto nla_put_failure;
 	}
-	if (vlan->nr_ingress_mappings) {
+
+	rcu_read_lock();
+
+	if (READ_ONCE(vlan->nr_ingress_mappings)) {
 		nest = nla_nest_start_noflag(skb, IFLA_VLAN_INGRESS_QOS);
-		if (nest == NULL)
-			goto nla_put_failure;
+		if (!nest)
+			goto nla_put_failure_unlock;
 
 		for (i = 0; i < ARRAY_SIZE(vlan->ingress_priority_map); i++) {
-			if (!vlan->ingress_priority_map[i])
+			u32 skb_prio = READ_ONCE(vlan->ingress_priority_map[i]);
+
+			if (!skb_prio)
 				continue;
 
 			m.from = i;
-			m.to   = vlan->ingress_priority_map[i];
+			m.to   = skb_prio;
 			if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
 				    sizeof(m), &m))
-				goto nla_put_failure;
+				goto nla_put_failure_unlock;
 		}
 		nla_nest_end(skb, nest);
 	}
 
-	if (vlan->nr_egress_mappings) {
+	if (READ_ONCE(vlan->nr_egress_mappings)) {
 		nest = nla_nest_start_noflag(skb, IFLA_VLAN_EGRESS_QOS);
-		if (nest == NULL)
-			goto nla_put_failure;
+		if (!nest)
+			goto nla_put_failure_unlock;
 
 		for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) {
-			for (pm = rcu_dereference_rtnl(vlan->egress_priority_map[i]); pm;
-			     pm = rcu_dereference_rtnl(pm->next)) {
+			for (pm = rcu_dereference(vlan->egress_priority_map[i]); pm;
+			     pm = rcu_dereference(pm->next)) {
 				u16 vlan_qos = READ_ONCE(pm->vlan_qos);
+
 				m.from = pm->priority;
 				m.to   = (vlan_qos >> 13) & 0x7;
 				if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
 					    sizeof(m), &m))
-					goto nla_put_failure;
+					goto nla_put_failure_unlock;
 			}
 		}
 		nla_nest_end(skb, nest);
 	}
+	rcu_read_unlock();
 	return 0;
 
+nla_put_failure_unlock:
+	rcu_read_unlock();
 nla_put_failure:
 	return -EMSGSIZE;
 }
-- 
2.55.0.1032.g73a4cd73de-goog
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help