Thread (38 messages) 38 messages, 5 authors, 2024-05-24

Re: [PATCH v2 net-next 00/15] locking: Introduce nested-BH locking.

From: Paolo Abeni <pabeni@redhat.com>
Date: 2024-05-06 14:12:06
Also in: lkml

On Mon, 2024-05-06 at 11:38 +0200, Sebastian Andrzej Siewior wrote:
On 2024-05-06 10:43:49 [+0200], Paolo Abeni wrote:
quoted
On Fri, 2024-05-03 at 20:25 +0200, Sebastian Andrzej Siewior wrote:
quoted
Disabling bottoms halves acts as per-CPU BKL. On PREEMPT_RT code within
local_bh_disable() section remains preemtible. As a result high prior
tasks (or threaded interrupts) will be blocked by lower-prio task (or
threaded interrupts) which are long running which includes softirq
sections.

The proposed way out is to introduce explicit per-CPU locks for
resources which are protected by local_bh_disable() and use those only
on PREEMPT_RT so there is no additional overhead for !PREEMPT_RT builds.
Let me rephrase to check I understood the plan correctly.

The idea is to pair 'bare' local_bh_{disable,enable} with local lock
and late make local_bh_{disable,enable} no ops (on RT).

With 'bare' I mean not followed by a spin_lock() - which is enough to
ensure mutual exclusion vs BH on RT build - am I correct?
I might have I misunderstood your rephrase. But to make it clear:
quoted
$ git grep -p local_lock\( kernel/softirq.c
kernel/softirq.c=void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
kernel/softirq.c:                       local_lock(&softirq_ctrl.lock);
this is what I want to remove. This is upstream RT only (not RT queue
only). !RT builds are not affected by this change.
I was trying to describe the places that need the additional
local_lock(), but I think we are on the same page WRT the overall
semantic.
quoted
Note that some callers use local_bh_disable(), no additional lock, and
there is no specific struct to protect, but enforce explicit
serialization vs bh to a bunch of operation, e.g.  the
local_bh_disable() in inet_twsk_purge().

I guess such call site should be handled, too?
Yes but I didn't find much. inet_twsk_purge() is the first item from my
list. On RT spin_lock() vs spin_lock_bh() is the first item from my
list. On RT spin_lock() vs spin_lock_bh() usage does not deadlock and
could be mixed.

The only resources that can be protected by disabling BH are per-CPU
resources. Either explicit defined (such as napi_alloc_cache) or
implicit by other means of per-CPU usage such as a CPU-bound timer,
worker, …. Protecting global variables by disabling BH is broken on SMP
(see the CAN gw example) so I am not too worried about those.
Unless you are aware of a category I did not think of.
I think sometimes the stack could call local_bh_enable() after a while
WRT the paired spin lock release, to enforce some serialization - alike
what inet_twsk_purge() is doing - but I can't point to any specific
line on top of my head.

A possible side-effect you should/could observe in the final tree is
more pressure on the process scheduler, as something alike:

local_bh_disable()

<spinlock lock unlock>

<again spinlock lock unlock>

local_bh_enable()

could results in more invocation of the scheduler, right? 

Cheers,

Paolo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help