Re: [PATCH v6 net-next 08/15] net: softnet_data: Make xmit.recursion per task.

From: Sebastian Andrzej Siewior
Date: Fri Jun 14 2024 - 04:28:19 EST


On 2024-06-12 13:18:29 [-0400], Steven Rostedt wrote:
> On Wed, 12 Jun 2024 18:44:34 +0200
> Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> wrote:
>
> > Softirq is preemptible on PREEMPT_RT. Without a per-CPU lock in
> > local_bh_disable() there is no guarantee that only one device is
> > transmitting at a time.
> > With preemption and multiple senders it is possible that the per-CPU
> > recursion counter gets incremented by different threads and exceeds
> > XMIT_RECURSION_LIMIT leading to a false positive recursion alert.
> >
> > Instead of adding a lock to protect the per-CPU variable it is simpler
> > to make the counter per-task. Sending and receiving skbs happens always
> > in thread context anyway.
> >
> > Having a lock to protected the per-CPU counter would block/ serialize two
> > sending threads needlessly. It would also require a recursive lock to
> > ensure that the owner can increment the counter further.
> >
> > Make the recursion counter a task_struct member on PREEMPT_RT.
>
> I'm curious to what would be the harm to using a per_task counter
> instead of per_cpu outside of PREEMPT_RT. That way, we wouldn't have to
> have the #ifdef.

There should be a hole on !RT, too so we shouldn't gain weight. The
limit is set to 8 so an u8 would be enough. The counter is only accessed
with BH-disabled so it will be used only in one context since it can't
schedule().

I think it should work fine. netdev folks, you want me to remove that
ifdef and use a per-Task counter unconditionally?

> -- Steve

Sebastian