Skip to content

Commit 7fe70c0

Browse files
Sebastian Andrzej SiewiorPaolo Abeni
authored andcommitted
net/sched: act_mirred: Move the recursion counter struct netdev_xmit
mirred_nest_level is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Move mirred_nest_level to struct netdev_xmit as u8, provide wrappers. Cc: Jamal Hadi Salim <[email protected]> Cc: Cong Wang <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Juri Lelli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 3af4cdd commit 7fe70c0

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

include/linux/netdevice_xmit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ struct netdev_xmit {
88
#ifdef CONFIG_NET_EGRESS
99
u8 skip_txqueue;
1010
#endif
11+
#if IS_ENABLED(CONFIG_NET_ACT_MIRRED)
12+
u8 sched_mirred_nest;
13+
#endif
1114
};
1215

1316
#endif

net/sched/act_mirred.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,29 @@ static LIST_HEAD(mirred_list);
3030
static DEFINE_SPINLOCK(mirred_list_lock);
3131

3232
#define MIRRED_NEST_LIMIT 4
33-
static DEFINE_PER_CPU(unsigned int, mirred_nest_level);
33+
34+
#ifndef CONFIG_PREEMPT_RT
35+
static u8 tcf_mirred_nest_level_inc_return(void)
36+
{
37+
return __this_cpu_inc_return(softnet_data.xmit.sched_mirred_nest);
38+
}
39+
40+
static void tcf_mirred_nest_level_dec(void)
41+
{
42+
__this_cpu_dec(softnet_data.xmit.sched_mirred_nest);
43+
}
44+
45+
#else
46+
static u8 tcf_mirred_nest_level_inc_return(void)
47+
{
48+
return current->net_xmit.sched_mirred_nest++;
49+
}
50+
51+
static void tcf_mirred_nest_level_dec(void)
52+
{
53+
current->net_xmit.sched_mirred_nest--;
54+
}
55+
#endif
3456

3557
static bool tcf_mirred_is_act_redirect(int action)
3658
{
@@ -423,7 +445,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
423445
int m_eaction;
424446
u32 blockid;
425447

426-
nest_level = __this_cpu_inc_return(mirred_nest_level);
448+
nest_level = tcf_mirred_nest_level_inc_return();
427449
if (unlikely(nest_level > MIRRED_NEST_LIMIT)) {
428450
net_warn_ratelimited("Packet exceeded mirred recursion limit on dev %s\n",
429451
netdev_name(skb->dev));
@@ -454,7 +476,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,
454476
retval);
455477

456478
dec_nest_level:
457-
__this_cpu_dec(mirred_nest_level);
479+
tcf_mirred_nest_level_dec();
458480

459481
return retval;
460482
}

0 commit comments

Comments
 (0)