sched/core: Fix potential deadlock on rq lock
Subsystems (2)
PATCH 1/1 sched/core: Fix potential deadlock on rq lock
When CPU 1 enters the nohz_full state, and the kworker on CPU 0 executes the function sched_tick_remote, holding the lock on CPU1's rq and triggering the warning WARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3). This leads to the process of printing the warning message, where the console_sem semaphore is held. At this point, the print task on the CPU1's rq cannot acquire the console_sem and joins the wait queue, entering the UNINTERRUPTIBLE state. It waits for the console_sem to be released and then wakes up. After the task on CPU 0 releases the console_sem, it wakes up the waiting console_sem task. In try_to_wake_up, it attempts to acquire the lock on CPU1's rq again, resulting in a deadlock.
The triggering scenario is as follows:
CPU0 CPU1sched_tick_remoteWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3)
report_bug con_write
printk
console_unlock
do_con_write console_lock down(&console_sem) list_add_tail(&waiter.list, &sem->wait_list);
up(&console_sem)wake_up_q(&wake_q)try_to_wake_up__task_rq_lock_raw_spin_lock
This patch fixes the issue by deffering all printk console printing during the lock holding period.
--- kernel/sched/core.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
@@ -5723,8 +5723,10 @@ static void sched_tick_remote(struct work_struct *work)* Make sure the next tick runs within a * reasonable amount of time. */ +printk_deferred_enter ();u64 delta =rq_clock_task (rq) - curr->se.exec_start;WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +printk_deferred_exit (); } curr->sched_class->task_tick (rq, curr,0 );
Signature · 1 line
2.34.1
Peter Zijlstra
maintainerQuoted 32 lines · Wang Tao
When CPU 1 enters the
nohz_fullstate, and the kworker on CPU 0 executes the functionsched_tick_remote, holding the lock on CPU1's rq and triggering the warningWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3). This leads to the process of printing the warning message, where theconsole_semsemaphore is held. At this point, the print task on the CPU1's rq cannot acquire theconsole_semand joins the wait queue, entering the UNINTERRUPTIBLE state. It waits for theconsole_semto be released and then wakes up. After the task on CPU 0 releases theconsole_sem, it wakes up the waitingconsole_semtask. Intry_to_wake_up, it attempts to acquire the lock on CPU1's rq again, resulting in a deadlock.The triggering scenario is as follows:
CPU0 CPU1
sched_tick_remoteWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3)
report_bugcon_write
printk
console_unlockdo_con_write console_lock down(&console_sem) list_add_tail(&waiter.list, &sem->wait_list);
up(&console_sem)wake_up_q(&wake_q)try_to_wake_up__task_rq_lock_raw_spin_lock
Quoted 5 lines
This patch fixes the issue by deffering all printk console printing during the lock holding period.
Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")Signed-off-by Wang Tao <[email protected]>
I fundamentally hate that deferred thing and consider it a printk bug.
But really, if you trip that WARN, fix it and the problem goes away.
Quoted 36 lines · Peter Zijlstra
Quoted 35 lines · Wang Tao
When CPU 1 enters the
nohz_fullstate, and the kworker on CPU 0 executes the functionsched_tick_remote, holding the lock on CPU1's rq and triggering the warningWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3). This leads to the process of printing the warning message, where theconsole_semsemaphore is held. At this point, the print task on the CPU1's rq cannot acquire theconsole_semand joins the wait queue, entering the UNINTERRUPTIBLE state. It waits for theconsole_semto be released and then wakes up. After the task on CPU 0 releases theconsole_sem, it wakes up the waitingconsole_semtask. Intry_to_wake_up, it attempts to acquire the lock on CPU1's rq again, resulting in a deadlock.The triggering scenario is as follows:
CPU0 CPU1
sched_tick_remoteWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3)
report_bugcon_write
printk
console_unlockdo_con_write console_lock down(&console_sem) list_add_tail(&waiter.list, &sem->wait_list);
up(&console_sem)wake_up_q(&wake_q)try_to_wake_up__task_rq_lock_raw_spin_lockThis patch fixes the issue by deffering all printk console printing during the lock holding period.
Quoted 6 lines
Quoted 2 lines
Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")Signed-off-by Wang Tao <[email protected]>I fundamentally hate that deferred thing and consider it a printk bug.
But really, if you trip that WARN, fix it and the problem goes away.
And probably it triggers a lot of false positives. An overloaded housekeeping CPU can easily be off for 2 seconds. We should make it 30 seconds.
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 40 lines · On Thu, Sep 11, 2025 at 05:02:45PM +0200 Frederic Weisbecker wrote:
Quoted 39 lines · Peter Zijlstra
Quoted 37 lines · Wang Tao
When CPU 1 enters the
nohz_fullstate, and the kworker on CPU 0 executes the functionsched_tick_remote, holding the lock on CPU1's rq and triggering the warningWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3). This leads to the process of printing the warning message, where theconsole_semsemaphore is held. At this point, the print task on the CPU1's rq cannot acquire theconsole_semand joins the wait queue, entering the UNINTERRUPTIBLE state. It waits for theconsole_semto be released and then wakes up. After the task on CPU 0 releases theconsole_sem, it wakes up the waitingconsole_semtask. Intry_to_wake_up, it attempts to acquire the lock on CPU1's rq again, resulting in a deadlock.The triggering scenario is as follows:
CPU0 CPU1
sched_tick_remoteWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3)
report_bugcon_write
printk
console_unlockdo_con_write console_lock down(&console_sem) list_add_tail(&waiter.list, &sem->wait_list);
up(&console_sem)wake_up_q(&wake_q)try_to_wake_up__task_rq_lock_raw_spin_lockThis patch fixes the issue by deffering all printk console printing during the lock holding period.
Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")Signed-off-by Wang Tao <[email protected]>
Quoted 7 lines
Quoted 3 lines
I fundamentally hate that deferred thing and consider it a printk bug.
But really, if you trip that WARN, fix it and the problem goes away.
And probably it triggers a lot of false positives. An overloaded housekeeping CPU can easily be off for 2 seconds. We should make it 30 seconds.
It does trigger pretty easily. We've done some work to try to make better (spreading HK work around for example) but you can still hit it. Especially, if there are virtualization layers involved...
Increasing that time a bit would be great :)
Cheers,
Phil
Quoted 6 lines
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Quoted 49 lines · Phil Auld
Quoted 40 lines · On Thu, Sep 11, 2025 at 05:02:45PM +0200 Frederic Weisbecker wrote:
Quoted 39 lines · Peter Zijlstra
Quoted 37 lines · Wang Tao
When CPU 1 enters the
nohz_fullstate, and the kworker on CPU 0 executes the functionsched_tick_remote, holding the lock on CPU1's rq and triggering the warningWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3). This leads to the process of printing the warning message, where theconsole_semsemaphore is held. At this point, the print task on the CPU1's rq cannot acquire theconsole_semand joins the wait queue, entering the UNINTERRUPTIBLE state. It waits for theconsole_semto be released and then wakes up. After the task on CPU 0 releases theconsole_sem, it wakes up the waitingconsole_semtask. Intry_to_wake_up, it attempts to acquire the lock on CPU1's rq again, resulting in a deadlock.The triggering scenario is as follows:
CPU0 CPU1
sched_tick_remoteWARN_ON_ONCE(delta > (u64)NSEC_PER_SEC * 3)
report_bugcon_write
printk
console_unlockdo_con_write console_lock down(&console_sem) list_add_tail(&waiter.list, &sem->wait_list);
up(&console_sem)wake_up_q(&wake_q)try_to_wake_up__task_rq_lock_raw_spin_lockThis patch fixes the issue by deffering all printk console printing during the lock holding period.
Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")Signed-off-by Wang Tao <[email protected]>Quoted 7 lines
Quoted 3 lines
I fundamentally hate that deferred thing and consider it a printk bug.
But really, if you trip that WARN, fix it and the problem goes away.
And probably it triggers a lot of false positives. An overloaded housekeeping CPU can easily be off for 2 seconds. We should make it 30 seconds.
Quoted 5 lines
It does trigger pretty easily. We've done some work to try to make better (spreading HK work around for example) but you can still hit it. Especially, if there are virtualization layers involved...
Increasing that time a bit would be great :)
Interested in sending the patch? :-)
Thanks.
Quoted 14 lines
Cheers,
PhilQuoted 6 lines
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Signature · 2 lines
Frederic Weisbecker SUSE Labs
PATCH 1/1 sched: Increase sched_tick_remote timeout
Increase the sched_tick_remote WARN_ON timeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );
Signature · 1 line
2.51.0
Re: [PATCH] sched: Increase sched_tick_remote timeout
Quoted 9 lines · Phil Auld
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Re: [PATCH] sched: Increase sched_tick_remote timeout
Do we have plans to merge this patch into the mainline?
Thanks,
Tao
Quoted 12 lines · Frederic Weisbecker
Quoted 9 lines · Phil Auld
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>
Re: [PATCH] sched: Increase sched_tick_remote timeout
In reply to Phil AuldIncreasing timeout alerts can reduce the probability of deadlocks. However, in the 'sched_tick_remote' method, there are 'WARN_ON_ONCE(rq->curr!= rq->donor)' and 'assert_clock_updated' in 'rq_clock_task'. Regardless of why these alerts are triggered, once they are triggered, 'printk' is called, which still leaves potential deadlock issues. Is there a better way to address these problems?
Quoted 26 lines · Phil Auld
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );
Re: [PATCH] sched: Increase sched_tick_remote timeout
Quoted 2 lines · On Tue, Sep 16, 2025 at 04:44:39PM +0800 wangtao (EQ) wrote:
Increasing timeout alerts can reduce the probability of deadlocks. However, in the '
sched_tick_remote' method, there are 'WARN_ON_ONCE(rq->curr!= rq->donor)' and 'assert_clock_updated' in 'rq_clock_task'. Regardless of why these alerts are triggered, once they are triggered, 'printk' is called, which still leaves potential deadlock issues. Is there a better way to address these problems?
I'm not specically trying to solve the printk deadlock problem. My patch is to make this particular warning go away by reducing the false positives. That's tangential to your original posting.
You can use the new printk mechanism with an atomic console to get around the printk bug I think.
I think you could also use a serial console instead of a framebuffer based console.
Cheers,
Phil
Quoted 27 lines · Phil Auld
Quoted 25 lines
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );
Re: [PATCH] sched: Increase sched_tick_remote timeout
In reply to Phil AuldHi,
Quoted 9 lines · On Thu, Sep 11, 2025 at 12:13:00PM -0400 Phil Auld wrote:
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>
Frederic ack'd this. Any other thoughts or opinions on this one character patch?
Cheers,
Phil
Quoted 20 lines
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );Signature · 1 line
2.51.0
Re: [PATCH] sched: Increase sched_tick_remote timeout
Quoted 8 lines · On Tue, Sep 23, 2025 at 06:47:39AM -0400 Phil Auld wrote:
Hi,
Quoted 5 lines · On Thu, Sep 11, 2025 at 12:13:00PM -0400 Phil Auld wrote:
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>Frederic ack'd this. Any other thoughts or opinions on this one character patch?
Ping...
Quoted 30 lines
Cheers,
PhilQuoted 20 lines
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );Signature · 1 line
2.51.0
Re: [PATCH] sched: Increase sched_tick_remote timeout
In reply to Phil AuldHi Peter,
Quoted 8 lines · On Tue, Sep 23, 2025 at 06:47:39AM -0400 Phil Auld wrote:
Hi,
Quoted 5 lines · On Thu, Sep 11, 2025 at 12:13:00PM -0400 Phil Auld wrote:
Increase the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Phil Auld <[email protected]>Suggested-by Frederic Weisbecker <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Frederic Weisbecker <[email protected]>Frederic ack'd this. Any other thoughts or opinions on this one character patch?
Can we have this timeout increase, please?
Thanks,
Phil
Quoted 30 lines
Cheers,
PhilQuoted 20 lines
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5724,7 +5724,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );Signature · 1 line
2.51.0
[tip: sched/core] sched: Increase sched_tick_remote timeout
In reply to Phil AuldThe 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: 2616d12247639da40339757adc08c822147aa993 Gitweb: https://git.kernel.org/tip/2616d12247639da40339757adc08c822147aa993 Author: Phil Auld <[email protected]> AuthorDate: Thu, 11 Sep 2025 12:13:00 -04:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 14 Nov 2025 13:03:06 +01:00
sched: Increase sched_tick_remote timeout
Increase the sched_tick_remote WARN_ON timeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -5619,7 +5619,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );
Re: [tip: sched/core] sched: Increase sched_tick_remote timeout
Quoted 9 lines · On Fri, Nov 14, 2025 at 12:19:06PM -0000 tip-bot2 for Phil Auld wrote:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 2616d12247639da40339757adc08c822147aa993 Gitweb: https://git.kernel.org/tip/2616d12247639da40339757adc08c822147aa993 Author: Phil Auld <[email protected]> AuthorDate: Thu, 11 Sep 2025 12:13:00 -04:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 14 Nov 2025 13:03:06 +01:00
Thanks Peter!
Quoted 30 lines
sched: Increase
sched_tick_remotetimeoutIncrease the
sched_tick_remoteWARN_ONtimeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.Suggested-by Frederic Weisbecker <[email protected]>Signed-off-by Phil Auld <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/core.c +1
-1@@ -5619,7 +5619,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );
[tip: sched/core] sched: Increase sched_tick_remote timeout
In reply to Phil AuldThe 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: aaab6bb54ab9bc4c37ff33b816031918d2760517 Gitweb: https://git.kernel.org/tip/aaab6bb54ab9bc4c37ff33b816031918d2760517 Author: Phil Auld <[email protected]> AuthorDate: Thu, 11 Sep 2025 12:13:00 -04:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Mon, 17 Nov 2025 17:13:15 +01:00
sched: Increase sched_tick_remote timeout
Increase the sched_tick_remote WARN_ON timeout to remove false positives due to temporarily busy HK cpus. The suggestion was 30 seconds to catch really stuck remote tick processing but not trigger it too easily.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -5619,7 +5619,7 @@ static void sched_tick_remote(struct work_struct *work)* reasonable amount of time. */ u64 delta =rq_clock_task (rq) - curr->se.exec_start; -WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *3 ); +WARN_ON_ONCE (delta > (u64 )NSEC_PER_SEC *30 ); } curr->sched_class->task_tick (rq, curr,0 );