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

net_sched: act_vlan: use RCU in tcf_vlan_dump()

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>

authored by

Eric Dumazet and committed by
Jakub Kicinski
48b5e5db 3133d5c1

+10 -11
+1
include/net/tc_act/tc_vlan.h
··· 10 10 #include <linux/tc_act/tc_vlan.h> 11 11 12 12 struct tcf_vlan_params { 13 + int action; 13 14 int tcfv_action; 14 15 unsigned char tcfv_push_dst[ETH_ALEN]; 15 16 unsigned char tcfv_push_src[ETH_ALEN];
+9 -11
net/sched/act_vlan.c
··· 25 25 { 26 26 struct tcf_vlan *v = to_vlan(a); 27 27 struct tcf_vlan_params *p; 28 - int action; 29 28 int err; 30 29 u16 tci; 31 30 ··· 36 37 */ 37 38 if (skb_at_tc_ingress(skb)) 38 39 skb_push_rcsum(skb, skb->mac_len); 39 - 40 - action = READ_ONCE(v->tcf_action); 41 40 42 41 p = rcu_dereference_bh(v->vlan_p); 43 42 ··· 94 97 skb_pull_rcsum(skb, skb->mac_len); 95 98 96 99 skb_reset_mac_len(skb); 97 - return action; 100 + return p->action; 98 101 99 102 drop: 100 103 tcf_action_inc_drop_qstats(&v->common); ··· 252 255 ETH_ALEN); 253 256 } 254 257 255 - spin_lock_bh(&v->tcf_lock); 258 + p->action = parm->action; 259 + spin_lock(&v->tcf_lock); 256 260 goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); 257 261 p = rcu_replace_pointer(v->vlan_p, p, lockdep_is_held(&v->tcf_lock)); 258 - spin_unlock_bh(&v->tcf_lock); 262 + spin_unlock(&v->tcf_lock); 259 263 260 264 if (goto_ch) 261 265 tcf_chain_put_by_act(goto_ch); ··· 295 297 }; 296 298 struct tcf_t t; 297 299 298 - spin_lock_bh(&v->tcf_lock); 299 - opt.action = v->tcf_action; 300 - p = rcu_dereference_protected(v->vlan_p, lockdep_is_held(&v->tcf_lock)); 300 + rcu_read_lock(); 301 + p = rcu_dereference(v->vlan_p); 302 + opt.action = p->action; 301 303 opt.v_action = p->tcfv_action; 302 304 if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt)) 303 305 goto nla_put_failure; ··· 323 325 tcf_tm_dump(&t, &v->tcf_tm); 324 326 if (nla_put_64bit(skb, TCA_VLAN_TM, sizeof(t), &t, TCA_VLAN_PAD)) 325 327 goto nla_put_failure; 326 - spin_unlock_bh(&v->tcf_lock); 328 + rcu_read_unlock(); 327 329 328 330 return skb->len; 329 331 330 332 nla_put_failure: 331 - spin_unlock_bh(&v->tcf_lock); 333 + rcu_read_unlock(); 332 334 nlmsg_trim(skb, b); 333 335 return -1; 334 336 }