]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net_sched: act_vlan: use RCU in tcf_vlan_dump()
authorEric Dumazet <edumazet@google.com>
Wed, 27 Aug 2025 12:53:47 +0000 (12:53 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 28 Aug 2025 23:46:23 +0000 (16:46 -0700)
Also storing tcf_action into struct tcf_vlan_params
makes sure there is no discrepancy in tcf_vlan_act().

No longer block BH in tcf_vlan_init() when acquiring tcf_lock.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250827125349.3505302-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/tc_act/tc_vlan.h
net/sched/act_vlan.c

index 3f5e9242b5e83d082b8a633b3702feadd5672b47..beadee41669a22d7519adaf348fb602cac7d273f 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/tc_act/tc_vlan.h>
 
 struct tcf_vlan_params {
+       int               action;
        int               tcfv_action;
        unsigned char     tcfv_push_dst[ETH_ALEN];
        unsigned char     tcfv_push_src[ETH_ALEN];
index 383bf18b6862f9a7a96087f1ed786fb869b70415..b46f980f3b2ae0bc50f1a37442945d281b7abddd 100644 (file)
@@ -25,7 +25,6 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb,
 {
        struct tcf_vlan *v = to_vlan(a);
        struct tcf_vlan_params *p;
-       int action;
        int err;
        u16 tci;
 
@@ -38,8 +37,6 @@ TC_INDIRECT_SCOPE int tcf_vlan_act(struct sk_buff *skb,
        if (skb_at_tc_ingress(skb))
                skb_push_rcsum(skb, skb->mac_len);
 
-       action = READ_ONCE(v->tcf_action);
-
        p = rcu_dereference_bh(v->vlan_p);
 
        switch (p->tcfv_action) {
@@ -97,7 +94,7 @@ out:
                skb_pull_rcsum(skb, skb->mac_len);
 
        skb_reset_mac_len(skb);
-       return action;
+       return p->action;
 
 drop:
        tcf_action_inc_drop_qstats(&v->common);
@@ -255,10 +252,11 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
                           ETH_ALEN);
        }
 
-       spin_lock_bh(&v->tcf_lock);
+       p->action = parm->action;
+       spin_lock(&v->tcf_lock);
        goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
        p = rcu_replace_pointer(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
-       spin_unlock_bh(&v->tcf_lock);
+       spin_unlock(&v->tcf_lock);
 
        if (goto_ch)
                tcf_chain_put_by_act(goto_ch);
@@ -297,9 +295,9 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
        };
        struct tcf_t t;
 
-       spin_lock_bh(&v->tcf_lock);
-       opt.action = v->tcf_action;
-       p = rcu_dereference_protected(v->vlan_p, lockdep_is_held(&v->tcf_lock));
+       rcu_read_lock();
+       p = rcu_dereference(v->vlan_p);
+       opt.action = p->action;
        opt.v_action = p->tcfv_action;
        if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt))
                goto nla_put_failure;
@@ -325,12 +323,12 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
        tcf_tm_dump(&t, &v->tcf_tm);
        if (nla_put_64bit(skb, TCA_VLAN_TM, sizeof(t), &t, TCA_VLAN_PAD))
                goto nla_put_failure;
-       spin_unlock_bh(&v->tcf_lock);
+       rcu_read_unlock();
 
        return skb->len;
 
 nla_put_failure:
-       spin_unlock_bh(&v->tcf_lock);
+       rcu_read_unlock();
        nlmsg_trim(skb, b);
        return -1;
 }