sched: do not call __put_task_struct() on rt if pi_blocked_on is set
PATCH v6 1/1 sched: do not call __put_task_struct() on rt if pi_blocked_on is set
With PREEMPT_RT enabled, some of the calls to put_task_struct() coming from rt_mutex_adjust_prio_chain() could happen in preemptible context and with a mutex enqueued. That could lead to this sequence:
rt_mutex_adjust_prio_chain()
put_task_struct()
__put_task_struct()
sched_ext_free()
spin_lock_irqsave()
rtlock_lock() ---> TRIGGERS
lockdep_assert(!current->pi_blocked_on);This is not a SCHED_EXT bug. The first cleanup function called by __put_task_struct() is sched_ext_free() and it happens to take a (RT) spin_lock, which in the scenario described above, would trigger the lockdep assertion of "!current->pi_blocked_on".
Crystal Wood was able to identify the problem as __put_task_struct() being called during rt_mutex_adjust_prio_chain(), in the context of a process with a mutex enqueued.
Instead of adding more complex conditions to decide when to directly call __put_task_struct() and when to defer the call, unconditionally resort to the deferred call on PREEMPT_RT to simplify the code.
---
v6: (Sebastian) rework patch description with the note from Crystal Wood.
v5: Add the "Fixes:" tag.
v4: Fix the implementation of what was requested on v3.
v3: (Sebastian, PeterZ) always call the deferred __put_task_struct() on RT.
v2: (Rostedt) remove the #ifdef from put_task_struct() and create
tsk_is_pi_blocked_on() in sched.h to make the change cleaner.
include/linux/sched/task.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
include/linux/sched/task.h +10 -17
@@ -135,24 +135,17 @@ static inline void put_task_struct(struct task_struct *t)return ;/* -* In !RT, it is always safe to call __put_task_struct(). -* Under RT, we can only call it in preemptible context. -*/ -if (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) { - static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); - -lock_map_acquire_try (&put_task_map); -__put_task_struct (t); -lock_map_release (&put_task_map); -return ; - } - -/* -* under PREEMPT_RT, we can't call put_task_struct +* Under PREEMPT_RT, we can't call __put_task_struct * in atomic context because it will indirectly -* acquire sleeping locks. +* acquire sleeping locks. The same is true if the +* current process has a mutex enqueued (blocked on +* a PI chain). +* +* In !RT, it is always safe to call __put_task_struct(). +* Though, in order to simplify the code, resort to the +* deferred call too. * -* call_rcu() will schedule delayed_put_task_struct_rcu() +* call_rcu() will schedule __put_task_struct_rcu_cb() * to be called in process context. * * __put_task_struct() is called when
@@ -165,7 +158,7 @@ static inline void put_task_struct(struct task_struct *t)* * delayed_free_task() also uses ->rcu, but it is only called * when it fails to fork a process. Therefore, there is no -* way it can conflict with put_task_struct(). +* way it can conflict with __put_task_struct(). */ call_rcu (&t->rcu, __put_task_struct_rcu_cb); }
Signature · 1 line
2.50.0
Quoted 21 lines · Luis Claudio R. Goncalves
With
PREEMPT_RTenabled, some of the calls toput_task_struct()coming fromrt_mutex_adjust_prio_chain()could happen in preemptible context and with a mutex enqueued. That could lead to this sequence:rt_mutex_adjust_prio_chain() put_task_struct() __put_task_struct() sched_ext_free() spin_lock_irqsave() rtlock_lock() ---> TRIGGERS lockdep_assert(!current->pi_blocked_on);This is not a
SCHED_EXTbug. The first cleanup function called by__put_task_struct()issched_ext_free()and it happens to take a (RT)spin_lock, which in the scenario described above, would trigger the lockdep assertion of "!current->pi_blocked_on".Crystal Wood was able to identify the problem as
__put_task_struct()being called duringrt_mutex_adjust_prio_chain(), in the context of a process with a mutex enqueued.
Quoted 8 lines
Instead of adding more complex conditions to decide when to directly call
__put_task_struct()and when to defer the call, unconditionally resort to the deferred call onPREEMPT_RTto simplify the code.Suggested-by Crystal Wood <[email protected]>Reviewed-by Wander Lairson Costa <[email protected]>Fixes 893cdaaa3977 ("sched: avoid false lockdep splat in put_task_struct()")Signed-off-by Luis Claudio R. Goncalves <[email protected]>
FWIW:
Quoted 21 lines · Luis Claudio R. Goncalves
With
PREEMPT_RTenabled, some of the calls toput_task_struct()coming fromrt_mutex_adjust_prio_chain()could happen in preemptible context and with a mutex enqueued. That could lead to this sequence:rt_mutex_adjust_prio_chain() put_task_struct() __put_task_struct() sched_ext_free() spin_lock_irqsave() rtlock_lock() ---> TRIGGERS lockdep_assert(!current->pi_blocked_on);This is not a
SCHED_EXTbug. The first cleanup function called by__put_task_struct()issched_ext_free()and it happens to take a (RT)spin_lock, which in the scenario described above, would trigger the lockdep assertion of "!current->pi_blocked_on".Crystal Wood was able to identify the problem as
__put_task_struct()being called duringrt_mutex_adjust_prio_chain(), in the context of a process with a mutex enqueued.
Quoted 8 lines
Instead of adding more complex conditions to decide when to directly call
__put_task_struct()and when to defer the call, unconditionally resort to the deferred call onPREEMPT_RTto simplify the code.Suggested-by Crystal Wood <[email protected]>Reviewed-by Wander Lairson Costa <[email protected]>Fixes 893cdaaa3977 ("sched: avoid false lockdep splat in put_task_struct()")Signed-off-by Luis Claudio R. Goncalves <[email protected]>
Side note: This simplifies the call chain to always free the task struct via RCU. This also means that the stack is not immediately available for recycle (CONFIG_VMAP_STACK) but after the grace period. Based on my testing the new task was also deployed on a remote CPU therefore I wouldn't worry too much here. Just wanted to point the only difference I could come up with.
Sebastian
[tip: sched/core] sched: Do not call __put_task_struct() on rt if pi_blocked_on is set
In reply to Luis Claudio R. GoncalvesThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 8671bad873ebeb082afcf7b4501395c374da6023 Gitweb: https://git.kernel.org/tip/8671bad873ebeb082afcf7b4501395c374da6023 Author: Luis Claudio R. Goncalves <[email protected]> AuthorDate: Mon, 07 Jul 2025 11:03:59 -03:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 14 Jul 2025 17:16:33 +02:00
sched: Do not call __put_task_struct() on rt if pi_blocked_on is set
With PREEMPT_RT enabled, some of the calls to put_task_struct() coming from rt_mutex_adjust_prio_chain() could happen in preemptible context and with a mutex enqueued. That could lead to this sequence:
rt_mutex_adjust_prio_chain()
put_task_struct()
__put_task_struct()
sched_ext_free()
spin_lock_irqsave()
rtlock_lock() ---> TRIGGERS
lockdep_assert(!current->pi_blocked_on);This is not a SCHED_EXT bug. The first cleanup function called by __put_task_struct() is sched_ext_free() and it happens to take a (RT) spin_lock, which in the scenario described above, would trigger the lockdep assertion of "!current->pi_blocked_on".
Crystal Wood was able to identify the problem as __put_task_struct() being called during rt_mutex_adjust_prio_chain(), in the context of a process with a mutex enqueued.
Instead of adding more complex conditions to decide when to directly call __put_task_struct() and when to defer the call, unconditionally resort to the deferred call on PREEMPT_RT to simplify the code.
--- include/linux/sched/task.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
include/linux/sched/task.h +10 -17
@@ -131,24 +131,17 @@ static inline void put_task_struct(struct task_struct *t)return ;/* -* In !RT, it is always safe to call __put_task_struct(). -* Under RT, we can only call it in preemptible context. -*/ -if (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) { - static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); - -lock_map_acquire_try (&put_task_map); -__put_task_struct (t); -lock_map_release (&put_task_map); -return ; - } - -/* -* under PREEMPT_RT, we can't call put_task_struct +* Under PREEMPT_RT, we can't call __put_task_struct * in atomic context because it will indirectly -* acquire sleeping locks. +* acquire sleeping locks. The same is true if the +* current process has a mutex enqueued (blocked on +* a PI chain). +* +* In !RT, it is always safe to call __put_task_struct(). +* Though, in order to simplify the code, resort to the +* deferred call too. * -* call_rcu() will schedule delayed_put_task_struct_rcu() +* call_rcu() will schedule __put_task_struct_rcu_cb() * to be called in process context. * * __put_task_struct() is called when
@@ -161,7 +154,7 @@ static inline void put_task_struct(struct task_struct *t)* * delayed_free_task() also uses ->rcu, but it is only called * when it fails to fork a process. Therefore, there is no -* way it can conflict with put_task_struct(). +* way it can conflict with __put_task_struct(). */ call_rcu (&t->rcu, __put_task_struct_rcu_cb); }
Quoted 4 lines · Luis Claudio R. Goncalves
Instead of adding more complex conditions to decide when to directly call
__put_task_struct()and when to defer the call, unconditionally resort to the deferred call onPREEMPT_RTto simplify the code.
^^^^^^^^^^^^^
Confused... with this patch put_task_struct() always uses the deferred call, regardless of PREEMPT_RT?
Oleg.
Quoted 48 lines
include/linux/sched/task.h +10
-17@@ -135,24 +135,17 @@ static inline void put_task_struct(struct task_struct *t)return ;/* -* In !RT, it is always safe to call __put_task_struct(). -* Under RT, we can only call it in preemptible context. -*/ -if (!IS_ENABLED (CONFIG_PREEMPT_RT ) ||preemptible ()) { - static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); - -lock_map_acquire_try (&put_task_map); -__put_task_struct (t); -lock_map_release (&put_task_map); -return ; - } - -/* -* under PREEMPT_RT, we can't call put_task_struct +* Under PREEMPT_RT, we can't call __put_task_struct * in atomic context because it will indirectly -* acquire sleeping locks. +* acquire sleeping locks. The same is true if the +* current process has a mutex enqueued (blocked on +* a PI chain). +* +* In !RT, it is always safe to call __put_task_struct(). +* Though, in order to simplify the code, resort to the +* deferred call too. * -* call_rcu() will schedule delayed_put_task_struct_rcu() +* call_rcu() will schedule __put_task_struct_rcu_cb() * to be called in process context. * * __put_task_struct() is called when @@ -165,7 +158,7 @@ static inline void put_task_struct(struct task_struct *t)* * delayed_free_task() also uses ->rcu, but it is only called * when it fails to fork a process. Therefore, there is no -* way it can conflict with put_task_struct(). +* way it can conflict with __put_task_struct(). */ call_rcu (&t->rcu, __put_task_struct_rcu_cb); }Signature · 1 line
2.50.0
Quoted 10 lines · Oleg Nesterov
Quoted 4 lines · Luis Claudio R. Goncalves
Instead of adding more complex conditions to decide when to directly call
__put_task_struct()and when to defer the call, unconditionally resort to the deferred call onPREEMPT_RTto simplify the code.^^^^^^^^^^^^^Confused... with this patch
put_task_struct()always uses the deferred call, regardless ofPREEMPT_RT?Oleg.
You are correct.
I mistakenly sent the patch from v3, with the updated description. I had been working on that patch in parallel for a future RFC and mixed them up when updating the description for v6. The changes from v4 onward were updates to the patch description only.
The fact that I had discussed this patch (the one submitted) with some people and was asking for tests to assess robustness and dependability may have further composed the confusion.
I posted v6 (with the wrong patch) a couple of hours before leaving for a 2-week vacation. This is also why I didn't notice the wrong submission before. That was an unfortunate mistake on my part, no bad intent.
Not sure how to proceed here, if I should resend the correct patch or a follow-up fix like this:
======
From: Luis Claudio R. Goncalves <[email protected]>
Subject: sched: restore the behavior of put_task_struct() for non-rt
Commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set") changed the behavior of put_task_struct() unconditionally, even when PREEMPT_RT was not enabled, in clear mismatch with the commit description.
Restore the previous behavior of put_task_struct() for the PREEMPT_RT disabled case.
---
include/linux/sched/task.h +10 -4
@@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)if (!refcount_dec_and_test (&t->usage))return ; +/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + } +/* * Under PREEMPT_RT, we can't call __put_task_struct * in atomic context because it will indirectly
@@ -137,10 +150,6 @@ static inline void put_task_struct(struct task_struct *t)* current process has a mutex enqueued (blocked on * a PI chain). * -* In !RT, it is always safe to call __put_task_struct(). -* Though, in order to simplify the code, resort to the -* deferred call too. -* * call_rcu() will schedule __put_task_struct_rcu_cb() * to be called in process context. *
Oleg Nesterov
Acked-byQuoted 22 lines · Luis Claudio R. Goncalves
From: Luis Claudio R. Goncalves <[email protected]>
Subject: sched: restore the behavior ofput_task_struct()for non-rtCommit
8671bad873eb("sched: Do not call__put_task_struct()on rt ifpi_blocked_onis set") changed the behavior ofput_task_struct()unconditionally, even whenPREEMPT_RTwas not enabled, in clear mismatch with the commit description.Restore the previous behavior of
put_task_struct()for thePREEMPT_RTdisabled case.Fixes 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")Signed-off-by Luis Claudio R. Goncalves <[email protected]>---
include/linux/sched/task.h +0
-0@@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)if (!refcount_dec_and_test (&t->usage))return ;
include/linux/sched/task.h static inline void put_task_struct(struct task_struct *t) · line 144
Quoted 10 lines
include/linux/sched/task.h +9
-0+/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + }
FWIW:
At the same time... I don't understand this DEFINE_WAIT_OVERRIDE_MAP(). IIUC, we need to shut up lockdep when put_task_struct() is called under raw_spinlock_t and __put_task_struct() paths take spinlock_t, right? Perhaps this deserves a comment...
But if I am right, why LD_WAIT_SLEEP? LD_WAIT_CONFIG should equally work, no?
LD_WAIT_SLEEP can fool lockdep more than we need, suppose that __put_task_struct() does mutex_lock(). Not really a problem, might_sleep/etc will complain in this case, but still.
Or I am totally confused?
Oleg.
Quoted 36 lines · Oleg Nesterov
Quoted 22 lines · Luis Claudio R. Goncalves
From: Luis Claudio R. Goncalves <[email protected]>
Subject: sched: restore the behavior ofput_task_struct()for non-rtCommit
8671bad873eb("sched: Do not call__put_task_struct()on rt ifpi_blocked_onis set") changed the behavior ofput_task_struct()unconditionally, even whenPREEMPT_RTwas not enabled, in clear mismatch with the commit description.Restore the previous behavior of
put_task_struct()for thePREEMPT_RTdisabled case.Fixes 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set")Signed-off-by Luis Claudio R. Goncalves <[email protected]>---
include/linux/sched/task.h +0
-0@@ -130,6 +133,16 @@ static inline void put_task_struct(struct task_struct *t)if (!refcount_dec_and_test (&t->usage))return ;include/linux/sched/task.h static inline void put_task_struct(struct task_struct *t) · line 144
Quoted 10 lines
include/linux/sched/task.h +9
-0+/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + }FWIW:
Quoted 7 lines
Acked-by Oleg Nesterov <[email protected]>At the same time... I don't understand this
DEFINE_WAIT_OVERRIDE_MAP(). IIUC, we need to shut up lockdep whenput_task_struct()is called underraw_spinlock_tand__put_task_struct()paths takespinlock_t, right? Perhaps this deserves a comment...
I reverted that code to the previous state, commit 893cdaaa3977 ("sched:
avoid false lockdep splat in put_task_struct()") and simplified the "if" statement. In the original code, PREEMPT_RT could call __put_task_struct() if the context was preemptible. But in the proposed code __put_task_struct() is only called if PREEMPT_RT is disabled. In this case I believe we could simply do:
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ __put_task_struct(t);
+ return;
+ }
Does that make sense?
Luis
Quoted 10 lines
But if I am right, why
LD_WAIT_SLEEP?LD_WAIT_CONFIGshould equally work, no?
LD_WAIT_SLEEPcan fool lockdep more than we need, suppose that__put_task_struct()doesmutex_lock(). Not really a problem, might_sleep/etc will complain in this case, but still.Or I am totally confused?
Oleg.
---end quoted text---
Quoted 19 lines · Luis Claudio R. Goncalves
Quoted 17 lines · Oleg Nesterov
include/linux/sched/task.h static inline void put_task_struct(struct task_struct *t) · line 144
Quoted 10 lines · Luis Claudio R. Goncalves
include/linux/sched/task.h +9
-0+/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + }FWIW:
Acked-by Oleg Nesterov <[email protected]>
Quoted 8 lines
Quoted 4 lines
At the same time... I don't understand this
DEFINE_WAIT_OVERRIDE_MAP(). IIUC, we need to shut up lockdep whenput_task_struct()is called underraw_spinlock_tand__put_task_struct()paths takespinlock_t, right? Perhaps this deserves a comment...I reverted that code to the previous state, commit
893cdaaa3977("sched:
avoid false lockdep splat input_task_struct()") and simplified the "if" statement.
Yes, yes, I see and I have already acked your patch.
Quoted 11 lines
In the original code,
PREEMPT_RTcould call__put_task_struct()if the context was preemptible. But in the proposed code__put_task_struct()is only called ifPREEMPT_RTis disabled. In this case I believe we could simply do:include/linux/sched/task.h +4
-0+if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { +__put_task_struct (t); +return ; + }Does that make sense?
Hmm... But, again unless I am totally confused, we do need the DEFINE_WAIT_OVERRIDE_MAP() trick even if !PREEMPT_RT ?
Looking at lockdep_wait_type, I think that with CONFIG_PROVE_RAW_LOCK_NESTING=y lockdep enforces the PREEMPT_RT locking rules even if PREEMPT_RT is not set?
But:
Quoted 5 lines
Quoted 5 lines
But if I am right, why
LD_WAIT_SLEEP?LD_WAIT_CONFIGshould equally work, no?
LD_WAIT_SLEEPcan fool lockdep more than we need, suppose that__put_task_struct()doesmutex_lock(). Not really a problem, might_sleep/etc will complain in this case, but still.
I still think LD_WAIT_CONFIG makes more sense.
Oleg.
Quoted 26 lines · Oleg Nesterov
Quoted 24 lines · Luis Claudio R. Goncalves
Quoted 21 lines · Oleg Nesterov
include/linux/sched/task.h static inline void put_task_struct(struct task_struct *t) · line 144
Quoted 10 lines · Luis Claudio R. Goncalves
include/linux/sched/task.h +9
-0+/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + }FWIW:
Acked-by Oleg Nesterov <[email protected]>At the same time... I don't understand this
DEFINE_WAIT_OVERRIDE_MAP(). IIUC, we need to shut up lockdep whenput_task_struct()is called underraw_spinlock_tand__put_task_struct()paths takespinlock_t, right? Perhaps this deserves a comment...
Quoted 5 lines
Quoted 3 lines
I reverted that code to the previous state, commit
893cdaaa3977("sched:
avoid false lockdep splat input_task_struct()") and simplified the "if" statement.Yes, yes, I see and I have already acked your patch.
So I think you should just resend it.
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
Oleg.
Quoted 27 lines · Oleg Nesterov
Quoted 26 lines · Oleg Nesterov
Quoted 24 lines · Luis Claudio R. Goncalves
Quoted 21 lines · Oleg Nesterov
include/linux/sched/task.h static inline void put_task_struct(struct task_struct *t) · line 144
Quoted 10 lines · Luis Claudio R. Goncalves
include/linux/sched/task.h +9
-0+/* In !RT, it is always safe to call __put_task_struct(). */ +if (!IS_ENABLED (CONFIG_PREEMPT_RT )) { + static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_SLEEP); + +lock_map_acquire_try (&put_task_map); +__put_task_struct (t); +lock_map_release (&put_task_map); +return ; + }FWIW:
Acked-by Oleg Nesterov <[email protected]>At the same time... I don't understand this
DEFINE_WAIT_OVERRIDE_MAP(). IIUC, we need to shut up lockdep whenput_task_struct()is called underraw_spinlock_tand__put_task_struct()paths takespinlock_t, right? Perhaps this deserves a comment...
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I reverted that code to the previous state, commit
893cdaaa3977("sched:
avoid false lockdep splat input_task_struct()") and simplified the "if" statement.Yes, yes, I see and I have already acked your patch.
So I think you should just resend it.
Thank you! I was a bit unsure on how to proceed :)
Quoted 2 lines
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
For what is worth, I tested the change with LD_WAIT_CONFIG and it worked as expected.
Luis
Quoted 2 lines
Oleg.
---end quoted text---
Sebastian Andrzej Siewior
maintainerQuoted 2 lines · Oleg Nesterov
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
You are correct Oleg. I've been just verifying it and yes: LD_WAIT_SLEEP suppresses also mutex while the intention is to only suppress spinlock_t.
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.
Quoted 1 line
Oleg.
Sebastian
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Oleg Nesterov
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
You are correct Oleg. I've been just verifying it and yes:
LD_WAIT_SLEEPsuppresses also mutex while the intention is to only suppressspinlock_t.
Good, thanks.
Quoted 2 lines
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.
Yes. I'll send the simple patch when this patch from Luis is merged.
Oleg
Sebastian Andrzej Siewior
maintainerQuoted 10 lines · Oleg Nesterov
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Oleg Nesterov
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
You are correct Oleg. I've been just verifying it and yes:
LD_WAIT_SLEEPsuppresses also mutex while the intention is to only suppressspinlock_t.
Quoted 6 lines
Good, thanks.
Quoted 2 lines
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.
Yes. I'll send the simple patch when this patch from Luis is merged.
Okay. Let me cover then the other instances.
Quoted 1 line
Oleg
Sebastian
Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 10 lines · Oleg Nesterov
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Oleg Nesterov
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
You are correct Oleg. I've been just verifying it and yes:
LD_WAIT_SLEEPsuppresses also mutex while the intention is to only suppressspinlock_t.
Quoted 8 lines
Quoted 6 lines
Good, thanks.
Quoted 2 lines
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.
Yes. I'll send the simple patch when this patch from Luis is merged.
Okay. Let me cover then the other instances.
I was going to update them all, but feel free to do.
Oleg.
Sebastian Andrzej Siewior
maintainerQuoted 5 lines · Oleg Nesterov
Quoted 3 lines
Quoted 1 line
Yes. I'll send the simple patch when this patch from Luis is merged.
Okay. Let me cover then the other instances.
I was going to update them all, but feel free to do.
Oh no. Please do cover them all and I review then. I understood that you make a single patch for a single instance.
Quoted 1 line
Oleg.
Sebastian
usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
In reply to Sebastian Andrzej SiewiorHi Sebastian,
(change subject to not add more confusion)
Quoted 10 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Oleg Nesterov
s/LD_WAIT_SLEEP/LD_WAIT_CONFIG/ needs another discussion even if I am right, sorry for the confusion.
You are correct Oleg. I've been just verifying it and yes:
LD_WAIT_SLEEPsuppresses also mutex while the intention is to only suppressspinlock_t.
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.
No ;)
I was going to send the patch which does s/SLEEP/CONFIG/, but this would be wrong. printk_legacy_map can use LD_WAIT_CONFIG, but lets look at debug_objects_fill_pool()
if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) {
/*
* Annotate away the spinlock_t inside raw_spinlock_t warning
* by temporarily raising the wait-type to WAIT_SLEEP, matching
* the preemptible() condition above.
*/
static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP);
lock_map_acquire_try(&fill_pool_map);
fill_pool();
lock_map_release(&fill_pool_map);
}If CONFIG_PREEMPT_RT=y and preemptible() is true, LD_WAIT_CONFIG won't work. lockdep will complain if fill_pool() takes a spinlock_t, spinlock is LD_WAIT_SLEEP on RT.
I guess debug_objects_fill_pool() actually needs something like
if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) {
static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_CONFIG);
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
lock_map_acquire_try(&fill_pool_map);
fill_pool();
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
lock_map_release(&fill_pool_map);
}but this is obviously too ugly. I am wondering if we can cleanup this logic somehow...
Oleg.
Sebastian Andrzej Siewior
maintainerRe: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 1 line · Oleg Nesterov
Hi Sebastian,
Hi,
Quoted 24 lines
Quoted 5 lines
You are correct Oleg. I've been just verifying it and yes:
LD_WAIT_SLEEPsuppresses also mutex while the intention is to only suppressspinlock_t.
We have four users in tree, based on quick check all four should use CONFIG, three of them do use SLEEP.No ;)
I was going to send the patch which does s/SLEEP/CONFIG/, but this would be wrong.
printk_legacy_mapcan useLD_WAIT_CONFIG, but lets look atdebug_objects_fill_pool()if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) { /* * Annotate away the spinlock_t inside raw_spinlock_t warning * by temporarily raising the wait-type to WAIT_SLEEP, matching * the preemptible() condition above. */ static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_SLEEP); lock_map_acquire_try(&fill_pool_map); fill_pool(); lock_map_release(&fill_pool_map); }
Quoted 3 lines
If
CONFIG_PREEMPT_RT=yandpreemptible()is true,LD_WAIT_CONFIGwon't work. lockdep will complain iffill_pool()takes aspinlock_t, spinlock isLD_WAIT_SLEEPon RT.
Where is this? This is then wrong then because _SLEEP is for MUTEX and those things that sleep-sleep and pretend to sleep.
spinlock_t should be LD_WAIT_CONFIG. This is used in include/linux/spinlock_types.h via SPIN_DEP_MAP_INIT which is only defined once as LD_WAIT_CONFIG.
rt_mutex is defined as LD_WAIT_SLEEP but this one is not the one we use for spinlock_t.
What you want to have working in the end is the following scenario:
|static DEFINE_SPINLOCK(lock_spinlock);
|static DEFINE_RAW_SPINLOCK(lock_raw_spinlock);
|static DEFINE_RAW_SPINLOCK(lock_raw_spinlock2);
|
|static void lockdep_test(void)
|{
| static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_CONFIG);
|
| raw_spin_lock(&lock_raw_spinlock);
| lock_map_acquire_try(&put_task_map);
|
| spin_lock(&lock_spinlock);
| spin_unlock(&lock_spinlock);
|
| raw_spin_lock(&lock_raw_spinlock2);
| raw_spin_unlock(&lock_raw_spinlock2);
|
| lock_map_release(&put_task_map);
| raw_spin_unlock(&lock_raw_spinlock);
|}This will work. On RT as well but is wrong and will not happen due to the preemptible() check. On !RT it will so you want lockdep to be quiet.
Quoted 2 lines
Oleg.
Sebastian
Re: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Oleg Nesterov
If
CONFIG_PREEMPT_RT=yandpreemptible()is true,LD_WAIT_CONFIGwon't work. lockdep will complain iffill_pool()takes aspinlock_t, spinlock isLD_WAIT_SLEEPon RT.
Quoted 6 lines
Where is this? This is then wrong then because
_SLEEPis for MUTEX and those things that sleep-sleep and pretend to sleep.
spinlock_tshould beLD_WAIT_CONFIG. This is used ininclude/linux/spinlock_types.hviaSPIN_DEP_MAP_INITwhich is only defined once asLD_WAIT_CONFIG.
Hmm. I'll recheck, quite possibly I missed something.
But. From include/linux/spinlock_types.h
/* PREEMPT_RT kernels map spinlock to rt_mutex */
#include <linux/rtmutex.h>
typedef struct spinlock {
struct rt_mutex_base lock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
} spinlock_t;Quoted 2 lines
rt_mutexis defined asLD_WAIT_SLEEPbut this one is not the one we use forspinlock_t.
see above...
Quoted 14 lines
What you want to have working in the end is the following scenario:
|static DEFINE_SPINLOCK(lock_spinlock); |static DEFINE_RAW_SPINLOCK(lock_raw_spinlock); |static DEFINE_RAW_SPINLOCK(lock_raw_spinlock2); | |static void lockdep_test(void) |{ | static DEFINE_WAIT_OVERRIDE_MAP(put_task_map, LD_WAIT_CONFIG); | | raw_spin_lock(&lock_raw_spinlock); | lock_map_acquire_try(&put_task_map); | | spin_lock(&lock_spinlock);
Yes, but this won't work on RT? Again, I didn't check (yet), possibly I am wrong...
Quoted 2 lines
This will work. On RT as well but is wrong and will not happen due to the
preemptible()check. On !RT it will so you want lockdep to be quiet.
See above and please correct me.
Oleg.
Sebastian Andrzej Siewior
maintainerRe: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 4 lines · Oleg Nesterov
Hmm. I'll recheck, quite possibly I missed something.
But. From
include/linux/spinlock_types.h
Quoted 12 lines
/* PREEMPT_RT kernels map spinlock to rt_mutex */ #include <linux/rtmutex.h> typedef struct spinlock { struct rt_mutex_base lock; #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif } spinlock_t;Quoted 2 lines
rt_mutexis defined asLD_WAIT_SLEEPbut this one is not the one we use forspinlock_t.
I may need to update the comment then if this is the source of your of confusion. The rtmutex.h header is required for the rtmutex bits which does contain struct rt_mutex_base which is used below you see. struct rt_mutex iself is not used here and has a different semantic (this one does use SLEEP).
Quoted 1 line
Oleg.
Sebastian
Re: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Sebastian,
sorry. I guess this is my fault, but I can't understand your reply... Could you spell please?
Just in case, I will read your reply tomorrow.
Oleg.
Quoted 29 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Oleg Nesterov
Hmm. I'll recheck, quite possibly I missed something.
But. From
include/linux/spinlock_types.hQuoted 12 lines
/* PREEMPT_RT kernels map spinlock to rt_mutex */ #include <linux/rtmutex.h> typedef struct spinlock { struct rt_mutex_base lock; #ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map; #endif } spinlock_t;Quoted 2 lines
rt_mutexis defined asLD_WAIT_SLEEPbut this one is not the one we use forspinlock_t.I may need to update the comment then if this is the source of your of confusion. The
rtmutex.hheader is required for the rtmutex bits which does contain structrt_mutex_basewhich is used below you see. structrt_mutexiself is not used here and has a different semantic (this one does use SLEEP).Quoted 1 line
Oleg.
Sebastian
Sebastian Andrzej Siewior
maintainerRe: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 1 line · Oleg Nesterov
Sebastian,
Hi Oleg,
Quoted 2 lines
sorry. I guess this is my fault, but I can't understand your reply... Could you spell please?
So you refer to this:
| /* PREEMPT_RT kernels map spinlock to rt_mutex */
| #include <linux/rtmutex.h>
|
| typedef struct spinlock {
| struct rt_mutex_base lock;
| #ifdef CONFIG_DEBUG_LOCK_ALLOC
| struct lockdep_map dep_map;
| #endif
| } spinlock_t;spinlock_t on PREEMPT_RT does not use (struct) rt_mutex as the comment claims. It uses just the basic building block which is "struct rt_mutex_base". This requires linux/rtmutex.h.
spinlock_t on PREEMPT_RT uses LD_WAIT_CONFIG via SPIN_DEP_MAP_INIT as !PREEMPT_RT. Nothing changes here.
struct rt_mutex on the other hand uses LD_WAIT_SLEEP and this one is like struct mutex but with PI.
Sebastian
Re: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 19 lines · Sebastian Andrzej Siewior
Quoted 1 line · Oleg Nesterov
Sebastian,
Hi Oleg,
Quoted 2 lines
sorry. I guess this is my fault, but I can't understand your reply... Could you spell please?
So you refer to this:
| /* PREEMPT_RT kernels map spinlock to rt_mutex */ | #include <linux/rtmutex.h> | | typedef struct spinlock { | struct rt_mutex_base lock; | #ifdef CONFIG_DEBUG_LOCK_ALLOC | struct lockdep_map dep_map; | #endif | } spinlock_t;
Quoted 6 lines
spinlock_tonPREEMPT_RTdoes not use (struct)rt_mutexas the comment claims. It uses just the basic building block which is "structrt_mutex_base". This requireslinux/rtmutex.h.
spinlock_tonPREEMPT_RTusesLD_WAIT_CONFIGviaSPIN_DEP_MAP_INITas !PREEMPT_RT. Nothing changes here.
Ah, indeed, I was confused and didn't even bother to read the definitions below, spinlock->dep_map is initialized by the same SPIN_DEP_MAP_INIT()...
Sebastian, thanks for correcting me! Sorry, I could not carefully read your emails yesterday.
Oleg.
Sebastian Andrzej Siewior
maintainerRe: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 7 lines · Oleg Nesterov
Quoted 1 line
| /*
PREEMPT_RTkernels map spinlock tort_mutex*/Ah, indeed, I was confused and didn't even bother to read the definitions below,
spinlock->dep_mapis initialized by the sameSPIN_DEP_MAP_INIT()...Sebastian, thanks for correcting me! Sorry, I could not carefully read your emails yesterday.
No worries. Just let me know if the cited comment requires an update.
Quoted 1 line
Oleg.
Sebastian
Re: usage of DEFINE_WAIT_OVERRIDE_MAP(LD_WAIT_SLEEP)
Quoted 11 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Oleg Nesterov
Quoted 1 line
| /*
PREEMPT_RTkernels map spinlock tort_mutex*/Ah, indeed, I was confused and didn't even bother to read the definitions below,
spinlock->dep_mapis initialized by the sameSPIN_DEP_MAP_INIT()...Sebastian, thanks for correcting me! Sorry, I could not carefully read your emails yesterday.
No worries. Just let me know if the cited comment requires an update.
No, no, I think the comment is fine. Just the ignorance on my side.
Oleg.