Skip to contentSkip to conversation

sched/core: Fix potential deadlock on rq lock

PATCH In review Wang Tao 5 participants 16 messages Sep 11, 2025 – Nov 17, 2025

Subsystems (2)
lore
Share & tools
lore

Wang Tao

author
#0 lore raw

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 CPU1
sched_tick_remote
WARN_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.

Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")
---
 kernel/sched/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/sched/core.c +2 -0
index be00629f0ba4..8b2d5b5bfb93 100644
@@ -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
maintainer
#1 lore raw
Quoted 32 lines · Wang Tao

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 CPU1
sched_tick_remote
WARN_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

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")

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.

#2 lore raw
Quoted 36 lines · Peter Zijlstra
Quoted 35 lines · Wang Tao

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 CPU1
sched_tick_remote
WARN_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.

Quoted 6 lines
Quoted 2 lines
Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")

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
#3 lore raw
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_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 CPU1
sched_tick_remote
WARN_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.

Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")
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
#4 lore raw
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_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 CPU1
sched_tick_remote
WARN_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.

Fixes d84b31313ef8 ("sched/isolation: Offload residual 1Hz scheduler tick")
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,
Phil

Quoted 6 lines

Thanks.

Signature · 2 lines
Frederic Weisbecker
SUSE Labs
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
#5 lore raw

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.

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
index be00629f0ba4..ef90d358252d 100644
@@ -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
Acked-by on v1 1/1
#6 lore raw

Re: [PATCH] sched: Increase sched_tick_remote timeout

Quoted 9 lines · Phil Auld

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.

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Signature · 2 lines
Frederic Weisbecker
SUSE Labs
#7 lore raw

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_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.

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
#8 lore raw

Re: [PATCH] sched: Increase sched_tick_remote timeout

In reply to Phil Auld

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?

Quoted 26 lines · Phil Auld

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.

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
index be00629f0ba4..ef90d358252d 100644
@@ -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);
 
#9 lore raw

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_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.

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
index be00629f0ba4..ef90d358252d 100644
@@ -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);
#10 lore raw

Re: [PATCH] sched: Increase sched_tick_remote timeout

In reply to Phil Auld

Hi,

Quoted 9 lines · On Thu, Sep 11, 2025 at 12:13:00PM -0400 Phil Auld wrote:

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.

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
index be00629f0ba4..ef90d358252d 100644
@@ -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
#11 lore raw

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_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.

Quoted 7 lines
Quoted 4 lines
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,
Phil

Quoted 20 lines
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index be00629f0ba4..ef90d358252d 100644
@@ -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
#12 lore raw

Re: [PATCH] sched: Increase sched_tick_remote timeout

In reply to Phil Auld

Hi 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_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.

Quoted 7 lines
Quoted 4 lines
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,
Phil

Quoted 20 lines
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index be00629f0ba4..ef90d358252d 100644
@@ -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
merge bot Applied
#13 lore raw

[tip: sched/core] sched: Increase sched_tick_remote timeout

In reply to Phil Auld
The 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
index 68f19aa..699db3f 100644
@@ -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);
 
#14 lore raw

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_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
index 68f19aa..699db3f 100644
@@ -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);
 
merge bot Applied
#15 lore raw

[tip: sched/core] sched: Increase sched_tick_remote timeout

In reply to Phil Auld
The 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
index 68f19aa..699db3f 100644
@@ -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);