linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lockdep: Fix wait context check on softirq for PREEMPT_RT
@ 2024-12-02  1:20 Ryo Takakura
  2024-12-02 10:32 ` Peter Zijlstra
  0 siblings, 1 reply; 10+ messages in thread
From: Ryo Takakura @ 2024-12-02  1:20 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng, bigeasy, clrkwllms,
	rostedt, tglx
  Cc: linux-kernel, linux-rt-devel, Ryo Takakura

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@gmail.com>


---

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.

Thanks!
Ryo Takakura

---
 include/linux/irqflags.h |  2 +-
 kernel/locking/lockdep.c | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h
index 3f003d5fd..c33c3bbd8 100644
--- a/include/linux/irqflags.h
+++ b/include/linux/irqflags.h
@@ -121,7 +121,7 @@ do {						\
 # define lockdep_irq_work_exit(__work)		do { } while (0)
 #endif
 
-#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT)
+#if defined(CONFIG_TRACE_IRQFLAGS)
 # define lockdep_softirq_enter()		\
 do {						\
 	current->softirq_context++;		\
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 536bd4715..2a508d6a6 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -4602,7 +4602,7 @@ mark_usage(struct task_struct *curr, struct held_lock *hlock, int check)
 				if (!mark_lock(curr, hlock,
 						LOCK_USED_IN_HARDIRQ_READ))
 					return 0;
-			if (curr->softirq_context)
+			if (!IS_ENABLED(CONFIG_PREEMPT_RT) && curr->softirq_context)
 				if (!mark_lock(curr, hlock,
 						LOCK_USED_IN_SOFTIRQ_READ))
 					return 0;
@@ -4610,7 +4610,7 @@ mark_usage(struct task_struct *curr, struct held_lock *hlock, int check)
 			if (lockdep_hardirq_context())
 				if (!mark_lock(curr, hlock, LOCK_USED_IN_HARDIRQ))
 					return 0;
-			if (curr->softirq_context)
+			if (!IS_ENABLED(CONFIG_PREEMPT_RT) && curr->softirq_context)
 				if (!mark_lock(curr, hlock, LOCK_USED_IN_SOFTIRQ))
 					return 0;
 		}
@@ -4651,8 +4651,11 @@ mark_usage(struct task_struct *curr, struct held_lock *hlock, int check)
 
 static inline unsigned int task_irq_context(struct task_struct *task)
 {
-	return LOCK_CHAIN_HARDIRQ_CONTEXT * !!lockdep_hardirq_context() +
-	       LOCK_CHAIN_SOFTIRQ_CONTEXT * !!task->softirq_context;
+	if (IS_ENABLED(CONFIG_PREEMPT_RT))
+		return LOCK_CHAIN_HARDIRQ_CONTEXT * !!lockdep_hardirq_context();
+	else
+		return LOCK_CHAIN_HARDIRQ_CONTEXT * !!lockdep_hardirq_context() +
+		       LOCK_CHAIN_SOFTIRQ_CONTEXT * !!task->softirq_context;
 }
 
 static int separate_irq_context(struct task_struct *curr,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-12-21  5:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02  1:20 [PATCH] lockdep: Fix wait context check on softirq for PREEMPT_RT Ryo Takakura
2024-12-02 10:32 ` Peter Zijlstra
2024-12-03  7:49   ` Boqun Feng
2024-12-03 11:57     ` Ryo Takakura
2024-12-09 16:09     ` Ryo Takakura
2024-12-19 22:27       ` Boqun Feng
2024-12-20  7:15         ` Sebastian Andrzej Siewior
2024-12-20 16:10         ` Ryo Takakura
2024-12-20 19:00           ` Boqun Feng
2024-12-21  5:17             ` Ryo Takakura

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).