From: K Prateek Nayak <kprateek.nayak@amd.com>
To: John Stultz <jstultz@google.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Joel Fernandes <joelagnelf@nvidia.com>,
Qais Yousef <qyousef@layalina.io>, Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Valentin Schneider <vschneid@redhat.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>,
"Zimuzo Ezeozue" <zezeozue@google.com>,
Will Deacon <will@kernel.org>, Waiman Long <longman@redhat.com>,
Boqun Feng <boqun.feng@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Metin Kaya <Metin.Kaya@arm.com>,
Xuewen Yan <xuewen.yan94@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
"Daniel Lezcano" <daniel.lezcano@linaro.org>,
Suleiman Souhlal <suleiman@google.com>,
kuyo chang <kuyo.chang@mediatek.com>, hupu <hupu.gm@gmail.com>,
<linux-kernel@vger.kernel.org>, Mike Galbraith <efault@gmx.de>
Subject: Re: [PATCH 1/6] sched/proxy: Remove superfluous clear_task_blocked_in()
Date: Fri, 29 May 2026 12:15:09 +0530 [thread overview]
Message-ID: <dc61cf77-e541-441d-a708-c40e19aa0db2@amd.com> (raw)
In-Reply-To: <CANDhNCrBDc4qiTZouGjj8tpS9OeCx9HYuPebrtO-+17-DhW+3g@mail.gmail.com>
Hello John,
On 5/29/2026 4:50 AM, John Stultz wrote:
> However, even with the fix I poined out, I've unfortunately hit races
> with the ww_mutex selftest at the point of this patch in the series.
> Basically between commit
> 1b89b7b21bf5 ("sched/proxy: Remove superfluous clear_task_blocked_in()")
> and
> a8be1edac5a1 ("sched/proxy: Remove PROXY_WAKING")
>
> I'm currently tracing down exactly why the race is cropping up but I
> believe the chunk removed in this case is avoiding cases where we end
> up getting PROXY_WAKING set on a TASK_RUNNING task.
This seems to be the failure path:
/* Task p*/
mutex_lock(mutex)
... try_to_wake_up(p)
schedule_preempt_disabled() ttwu_runnable()
__schedule() __task_rq_lock() /* Wins */
rq_lock() /* Waits */ if (task_on_rq_queued(p))
/*
* p->is_blocked is still not set!
* proxy_needs_return() bails out early.
*/
ttwu_do_wakeup()
p->__state = TASK_RUNNING;
__tsk_rq_unlock();
...
/* p->__state = TASK_RUNNING */
prev_state = p->__state;
if (prev_state && ...) {
/*
* Skipped since task is
* already TASK_RUNNING
*/
}
/* p->is_blocked = 0; p->blocked_on = PROXY_WAKING */
next = p;
/* Returns from schedule_preempt_disabled()
set_task_blocked_on(p, mutex)
!!! p->blocked_on == PROXY_WAKING && p->blocked_on != mutex !!!
---
Also proxy_needs_return() bails out too early - a wakeup from signal
should still clear p->blocked_on even if p->wake_cpu is same as
task_cpu().
I think we need the following at commit 83f9b04ef50c ("sched/proxy:
Switch proxy to use p->is_blocked") to clear p->blocked_on in the wakeup
path irrespective of p->is_blocked:
(Lightly tested)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a125e65c35bb..fe903976fd09 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3764,28 +3764,28 @@ static inline void proxy_reset_donor(struct rq *rq)
*/
static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p)
{
- if (!p->is_blocked)
- return false;
-
- /*
- * Typically per __set_task_cpu(), task_cpu(p) == p->wake_cpu.
- *
- * However, proxy_set_task_cpu() is such that it preserves the
- * original cpu in p->wake_cpu while migrating p for proxy reasons
- * (possibly outside of the allowed p->cpus_ptr).
- *
- * Furthermore, migration_cpu_stop() / __migrate_swap_task(), will
- * only set p->wake_cpu when !p->on_rq, and since here p->on_rq, this
- * will not apply. But if it did, this check is the safe way around
- * and would migrate.
- */
- if (task_cpu(p) == p->wake_cpu)
+ if (!task_is_blocked(p))
return false;
scoped_guard(raw_spinlock, &p->blocked_lock) {
/* Task is waking up; clear any blocked_on relationship */
__clear_task_blocked_on(p, NULL);
+ /*
+ * Typically per __set_task_cpu(), task_cpu(p) == p->wake_cpu.
+ *
+ * However, proxy_set_task_cpu() is such that it preserves the
+ * original cpu in p->wake_cpu while migrating p for proxy reasons
+ * (possibly outside of the allowed p->cpus_ptr).
+ *
+ * Furthermore, migration_cpu_stop() / __migrate_swap_task(), will
+ * only set p->wake_cpu when !p->on_rq, and since here p->on_rq, this
+ * will not apply. But if it did, this check is the safe way around
+ * and would migrate.
+ */
+ if (task_cpu(p) == p->wake_cpu)
+ return false;
+
/* If already current, don't need to return migrate */
if (task_current(rq, p))
return false;
---
Part of that belongs in commit e2ff8b7bde07 ("sched/proxy: Only return
migrate when needed") and the first hunk of 83f9b04ef50c ("sched/proxy:
Switch proxy to use p->is_blocked") in proxy_needs_return() should be
dropped.
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-05-29 6:45 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 11:16 [PATCH 0/6] sched/proxy: doodles Peter Zijlstra
2026-05-26 11:16 ` [PATCH 1/6] sched/proxy: Remove superfluous clear_task_blocked_in() Peter Zijlstra
2026-05-26 23:39 ` John Stultz
2026-05-26 23:54 ` John Stultz
2026-05-27 8:59 ` Peter Zijlstra
2026-05-28 23:20 ` John Stultz
2026-05-29 6:45 ` K Prateek Nayak [this message]
2026-05-29 7:14 ` John Stultz
2026-05-29 8:24 ` K Prateek Nayak
2026-05-29 8:47 ` Peter Zijlstra
2026-05-29 8:50 ` Peter Zijlstra
2026-05-29 10:46 ` K Prateek Nayak
2026-05-30 2:56 ` John Stultz
2026-05-29 9:33 ` Peter Zijlstra
2026-05-29 6:48 ` John Stultz
2026-05-29 7:58 ` K Prateek Nayak
2026-05-29 10:06 ` Peter Zijlstra
2026-05-29 10:54 ` K Prateek Nayak
2026-06-04 18:45 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-05-26 11:16 ` [PATCH 2/6] sched/proxy: Optimize try_to_wake_up() Peter Zijlstra
2026-05-27 1:56 ` John Stultz
2026-06-04 18:45 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-05-26 11:16 ` [PATCH 3/6] sched: Be more strict about p->is_blocked Peter Zijlstra
2026-05-27 1:56 ` John Stultz
2026-06-04 18:45 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-05-26 11:16 ` [PATCH 4/6] sched/proxy: Switch proxy to use p->is_blocked Peter Zijlstra
2026-05-26 14:57 ` Peter Zijlstra
2026-05-26 19:48 ` John Stultz
2026-05-27 2:25 ` John Stultz
2026-05-27 8:29 ` Peter Zijlstra
2026-06-04 18:45 ` [tip: sched/core] sched/proxy: Only return migrate when needed tip-bot2 for Peter Zijlstra
2026-06-04 18:45 ` [tip: sched/core] sched/proxy: Switch proxy to use p->is_blocked tip-bot2 for Peter Zijlstra
2026-05-26 11:16 ` [PATCH 5/6] sched/proxy: Remove PROXY_WAKING Peter Zijlstra
2026-06-01 10:54 ` Peter Zijlstra
2026-06-01 20:32 ` John Stultz
2026-06-02 5:22 ` K Prateek Nayak
2026-06-02 6:58 ` John Stultz
2026-06-02 10:02 ` Peter Zijlstra
2026-06-04 18:29 ` John Stultz
2026-06-04 18:41 ` Peter Zijlstra
2026-06-02 3:19 ` K Prateek Nayak
2026-06-04 18:45 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-05-26 11:16 ` [PATCH 6/6] sched: Simplify ttwu_runnable() Peter Zijlstra
2026-06-04 18:45 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2026-05-26 11:45 ` [PATCH 0/6] sched/proxy: doodles Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dc61cf77-e541-441d-a708-c40e19aa0db2@amd.com \
--to=kprateek.nayak@amd.com \
--cc=Metin.Kaya@arm.com \
--cc=boqun.feng@gmail.com \
--cc=bsegall@google.com \
--cc=daniel.lezcano@linaro.org \
--cc=dietmar.eggemann@arm.com \
--cc=efault@gmx.de \
--cc=hupu.gm@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=kuyo.chang@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--cc=rostedt@goodmis.org \
--cc=suleiman@google.com \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.org \
--cc=xuewen.yan94@gmail.com \
--cc=zezeozue@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome