Commit 7fe70c06 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Paolo Abeni
Browse files

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 <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: default avatarJuri Lelli <juri.lelli@redhat.com>
Link: https://patch.msgid.link/20250512092736.229935-11-bigeasy@linutronix.de


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 3af4cdd6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ struct netdev_xmit {
#ifdef CONFIG_NET_EGRESS
	u8  skip_txqueue;
#endif
#if IS_ENABLED(CONFIG_NET_ACT_MIRRED)
	u8 sched_mirred_nest;
#endif
};

#endif
+25 −3
Original line number Diff line number Diff line
@@ -30,7 +30,29 @@ static LIST_HEAD(mirred_list);
static DEFINE_SPINLOCK(mirred_list_lock);

#define MIRRED_NEST_LIMIT    4
static DEFINE_PER_CPU(unsigned int, mirred_nest_level);

#ifndef CONFIG_PREEMPT_RT
static u8 tcf_mirred_nest_level_inc_return(void)
{
	return __this_cpu_inc_return(softnet_data.xmit.sched_mirred_nest);
}

static void tcf_mirred_nest_level_dec(void)
{
	__this_cpu_dec(softnet_data.xmit.sched_mirred_nest);
}

#else
static u8 tcf_mirred_nest_level_inc_return(void)
{
	return current->net_xmit.sched_mirred_nest++;
}

static void tcf_mirred_nest_level_dec(void)
{
	current->net_xmit.sched_mirred_nest--;
}
#endif

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

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

dec_nest_level:
	__this_cpu_dec(mirred_nest_level);
	tcf_mirred_nest_level_dec();

	return retval;
}