Re: [PATCH] lockdep: Fix wait context check on softirq for PREEMPT_RT

From: Peter Zijlstra
Date: Mon Dec 02 2024 - 05:33:03 EST


On Mon, Dec 02, 2024 at 10:20:17AM +0900, Ryo Takakura wrote:
> Commit 0c1d7a2c2d32 ("lockdep: Remove softirq accounting on
> PREEMPT_RT.") stopped updating @softirq_context on PREEMPT_RT
> to ignore "inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage"
> as the report accounts softirq context which PREEMPT_RT doesn't
> have to.
>
> However, wait context check still needs to report mutex usage
> within softirq, even when its threaded on PREEMPT_RT. The check
> is failing to report the usage as task_wait_context() checks if
> its in softirq by referencing @softirq_context, ending up not
> assigning the correct wait type of LD_WAIT_CONFIG for PREEMPT_RT's
> softirq.
>
> [ 0.184549] | wait context tests |
> [ 0.184549] --------------------------------------------------------------------------
> [ 0.184549] | rcu | raw | spin |mutex |
> [ 0.184549] --------------------------------------------------------------------------
> [ 0.184550] in hardirq context: ok | ok | ok | ok |
> [ 0.185083] in hardirq context (not threaded): ok | ok | ok | ok |
> [ 0.185606] in softirq context: ok | ok | ok |FAILED|
>
> Account softirq context but only when !PREEMPT_RT so that
> task_wait_context() returns LD_WAIT_CONFIG as intended.
>
> Signed-off-by: Ryo Takakura <ryotkkr98@xxxxxxxxx>
>
>
> ---
>
> Hi!
>
> I wasn't able come up with a way to fix the wait context test while
> keeping the commit 0c1d7a2c2d32 ("lockdep: Remove softirq accounting
> on PREEMPT_RT.") without referencing @softirq_context...
> Hoping to get a feedback on it!
>
> Also I wonder if the test can be skipped as I believe its taken care
> by spinlock wait context test since the PREEMPT_RT's softirq context is
> protected by local_lock which is mapped to rt_spinlock.

Right,.. so I remember talking about this with Boqun, and I think we
were going to 'fix' the test, but I can't quite remember.

Perhaps adding the local_lock to SOFTIRQ_ENTER?