From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 2/2] vlan: no longer rely on RTNL in vlan_fill_info()
Date: Wed, 16 Sep 2026 13:25:32 +0000 [thread overview]
Message-ID: <20260916132532.1785657-3-edumazet@google.com> (raw)
In-Reply-To: <20260916132532.1785657-1-edumazet@google.com>
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
next prev parent reply other threads:[~2026-09-16 13:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 13:25 [PATCH net-next 0/2] vlan: lockless vlan_fill_info() Eric Dumazet
2026-09-16 13:25 ` [PATCH net-next 1/2] vlan: annotate data-races in vlan_dev_priv fields Eric Dumazet
2026-09-16 13:25 ` Eric Dumazet [this message]
2026-09-19 0:10 ` [PATCH net-next 0/2] vlan: lockless vlan_fill_info() patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916132532.1785657-3-edumazet@google.com \
--to=edumazet@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox