mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC 1/1] sched: Remove unreliable wake_cpu check in proxy_needs_return
@ 2025-04-07 13:46 hupu
  2025-04-09  6:01 ` Madadi Vineeth Reddy
  2025-04-09 23:35 ` John Stultz
  0 siblings, 2 replies; 8+ messages in thread
From: hupu @ 2025-04-07 13:46 UTC (permalink / raw)
  To: jstultz, linux-kernel
  Cc: juri.lelli, peterz, vschneid, mingo, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, hupu, hupu

The (p->wake_cpu != cpu_of(rq)) check in proxy_needs_return() is unsafe
during early wakeup phase. When called via ttwu_runnable() path:

|-- try_to_wake_up
    |-- ttwu_runnable
        |-- proxy_needs_return    //we are here
    |-- select_task_rq
    |-- set_task_cpu              //set p->wake_cpu here
    |-- ttwu_queue

The p->wake_cpu at this point reflects the CPU where donor last ran before
blocking, not the target migration CPU. During blocking period:
1. CPU affinity may have been changed by other threads
2. Proxy migrations might have altered the effective wake_cpu
3. set_task_cpu() hasn't updated wake_cpu yet in this code path

This makes the wake_cpu vs current CPU comparison meaningless and potentially
dangerous. Rely on find_proxy_task()'s later migration logic to handle CPU
placement based on up-to-date affinity and scheduler state.

Signed-off-by: hupu <hupu.gm@gmail.com>
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3c4ef4c71cfd..ca4ca739eb85 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4047,7 +4047,7 @@ static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p)
 
 	raw_spin_lock(&p->blocked_lock);
 	if (__get_task_blocked_on(p) && p->blocked_on_state & BO_NEEDS_RETURN) {
-		if (!task_current(rq, p) && (p->wake_cpu != cpu_of(rq))) {
+		if (!task_current(rq, p)) {
 			if (task_current_donor(rq, p)) {
 				put_prev_task(rq, p);
 				rq_set_donor(rq, rq->idle);
-- 
2.47.0


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

end of thread, other threads:[~2025-06-05 14:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-07 13:46 [RFC 1/1] sched: Remove unreliable wake_cpu check in proxy_needs_return hupu
2025-04-09  6:01 ` Madadi Vineeth Reddy
2025-04-09  6:56   ` hupu
2025-04-09 23:35 ` John Stultz
2025-04-10  7:14   ` hupu
2025-05-19  5:13     ` hupu
2025-05-25  7:47       ` [RESEND RFC " hupu
2025-06-05 14:54       ` [RFC " hupu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®