Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796183578; b=q/9GkgpJMTZcqBosra7C+60oambFBsjrxuBQx2FFXSqDIZp4mxZ+/hQpEj339wfn9kGl TKBs5dJu0dFaI15I/nfFGNeTIj990o3ViL6gcychoqyXWMq4k0IdCUuPIcK8Wb3bayj4G 26jkwbOig8saRGDUxbF9daQJn9k9QuBJ+ydO+dpg1SyZjcYDwCrD4c38SDhPX0UUs8evD aNaSz/DTeEnlrEHy7EOOuCipv7eU6YPqKY7vImoYlP4052zbrluq13axHpVOIuWcmIHeq LoMl7SzOg7cotGOnbFPH8UFRrvWvx980s5B2v8cBb/bFYlXez3klEFZnALbR8ejVm0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183578; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Uwv7vJFDP8GoG/fD5Qf/3VCzG6ZYgxb0ETZyBkawLsM=; b=sF92Fg1O+lj8cUrMwcgDvb587SZepwZpTL+Wp1v2HUvnjfSHjYcXYmRQhIyVJju+7hN1 +u1dfe6SBwYhrUOW4uHXf6M3OAtUFNfBBJ6oDo8h6ECmJGW31vQIUw2LZkRHXxDzHvMju eyFbiXYjv+0Etp8wh/eXlXdQ4KfYtEFzLdyXCe2F+Vu11dpv+vjhUM36q5xyZczhENPf4 2I88d7mRLGU9H7ztuB8sHWU5YHHegynvPfDN05FlD/2YCk1CLZ7mLxDyvY4FRUdiHsvy+ uH+TO00/YzlnpVSa0LTJo0T9EVvcw0iZXYPbUGjyEAFOhEK4+cDOxn+GPeAG5GsjbEA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=droIUKI+; arc=none smtp.remote-ip=209.85.214.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2714606A6B4 for ; Wed, 2 Dec 2026 03:52:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2714606A6B4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=droIUKI+ Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2efa9aea3c0so168322885ad.1 for ; Tue, 01 Dec 2026 19:52:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796183577; x=1796788377; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Uwv7vJFDP8GoG/fD5Qf/3VCzG6ZYgxb0ETZyBkawLsM=; b=droIUKI+Afb+f/QKqWe6J5OV3sMVEnNrw/dC7NnoONPxzmjDMqc3gfgA0tzBvvhUB8 fzHVhRw8P47YsDKu3XcfkGj5HMKxTCh6NtXJ7oFyIbYbaCfL7vFw1/E/y5CA4ykr4WGm NkwPmVEXqI23l7WEvSkHrFbzxgbYz5aa15WSMNogiHwL8jCI83VLNWVJ15hg/moq4LS0 WuqO4C294Usaejo4wq5irLBX7/6mXy0100Y3WmnM+PLaeR6zqSVLp7ujIICOCx5rsGKe iqgLRZ4XTLJH0OgW9Pn+vgmklkqN7EbWSFxSQcZAt1OzhEEB2QTL+/6Lohvad9xOrn7x B7eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796183577; x=1796788377; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Uwv7vJFDP8GoG/fD5Qf/3VCzG6ZYgxb0ETZyBkawLsM=; b=uVzEHXfBB3sxamrTq7/GUvXLdbv9fqyeFa5mdM/xfghTjKiJdjt+7M5Ylv6Zc95H9O 9gZ1dSYtMcDrFw3loSO0Jh6Elv1KXyMtE+7MDPgggkONBF/1/E7YEJGIBB5i34toCfQj StXXMm2LL3k6ktKVIO4VCuLZEKXvDhNS0LnyyHQ9xj9Xf45jNnkpnIiTzdbZFmj5jhxQ 4kfgCRuWzd/m4dq4qHvFsIvupE30oqwjxMKewa+fqHwfO/za+Ys/+5KA6EWdRDVJ5syl WVbauXC/JwGnFv207Wlh7IU7VnHPzb4uxWa8BxSk7bh9UYYjrzKmD4gGf3AJ7CJaMnWk ZbJA== X-Gm-Message-State: APuU4Z8ht93AzMXe89WGd13AfMYY/xlJefS/LLJEp782jNoYC5/bsT5D AhrXMNtci2YPoGM2aoRwVLTPtkj3O7DkbnoLvSxkXfmwYpQ6sjwYaYKmOEmwQDmCWtJcbtiXFH7 2wfUHfL7Jza3b/nXvsujbgHyB6g6XH8NBiaSB3erltj/o2AtckNx5SPLtsjgdqhZAg6AalEUeOs BXKgce2lFCu3OtcQdzx4MlpeJaILzO+GSZS3cN2yGd16b29Tjo X-Received: from plfz11.prod.google.com ([2002:a17:902:d54b:b0:2f0:4f60:5499]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e844:b0:2e8:4066:d247 with SMTP id d9443c01a7336-2f050c1e95emr393311645ad.33.1796183576904; Tue, 01 Dec 2026 19:52:56 -0800 (PST) Date: Wed, 2 Dec 2026 03:52:37 +0000 In-Reply-To: <20261202035248.1210026-1-jstultz@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202035248.1210026-1-jstultz@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202035248.1210026-10-jstultz@google.com> Subject: [PATCH v34 09/14] sched/core: Activate blocked donor when no owner is found From: John Stultz To: LKML Cc: K Prateek Nayak , John Stultz , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Juri Lelli , Vincent Guittot , Valentin Schneider , Suleiman Souhlal , Andrea Righi , Johannes Weiner , Metin Kaya , Dietmar Eggemann , Steven Rostedt , Zimuzo Ezeozue , Waiman Long , Boqun Feng , "Paul E. McKenney" , Joel Fernandes , Qais Yousef , Xuewen Yan , kuyo chang , hupu , Zhan Xusheng , "zhidao su (Xiaomi)" , Hui Su , "Shubhang Kaushik (Ampere)" , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" From: K Prateek Nayak mutex_unlock_slowpath() follows: if (owner & MUTEX_FLAG_HANDOFF) break /* ... and do __mutex_handoff() */ if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, __owner_flags(owner))) { if (owner & MUTEX_FLAG_WAITERS) break; /* ... and wake up the first waiter. */ MUTEX_FLAG_HANDOFF is only set by first-waiter after it has been woken up and in absence of MUTEX_FLAG_HANDOFF, the owner clears itself from the lock_word and wakes up the first waiter to try a __mutex_trylock_or_handoff(). MUTEX_FLAG_HANDOFF exists to prevent new optimistic spinners from trying to hijack the lock from waiter all the time and potentially starving them but it is not necessary for MUTEX_FLAG_HANDOFF to be always set in presence of a waiter. If a blocked donor is deactivated when no owner is observed, it may not be woken up until it becomes the first waiter and is naturally woken up which breaks proxy in the interim. Wake up the blocked donor and allow it to grab the lock when no owner is observed. If the task manages to grab the lock, the block chain will follow at the next proxy migration. If the task fails to grab the lock, same situation is restored and everyone migrated to the CPU of new owner. Similarly, do the same for the NULL blocked_on/mutex pointer for consistency. This also lets us get rid of the early returns that Andrea pointed out were problematic for core scheduling. Fixes: f13beb010e4a ("sched: Have try_to_wake_up() handle return-migration for PROXY_WAKING case") Signed-off-by: K Prateek Nayak [jstultz: Extended activation for other cases, dropped early returns] Signed-off-by: John Stultz --- v33: * Added similar logic for the null mutex/blocked_on case v34: * Andrea pointed out the early returns were problematic for core scheduling, so drop them both here. * Also due to dropping early returns we may call wakeup on is_blocked current, which is ok, so drop WARN_ON * Remove stale comment Cc: Peter Zijlstra Cc: Ingo Molnar Cc: K Prateek Nayak Cc: Thomas Gleixner Cc: Juri Lelli Cc: Vincent Guittot Cc: Valentin Schneider Cc: Suleiman Souhlal Cc: Andrea Righi Cc: Johannes Weiner Cc: Metin Kaya Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Zimuzo Ezeozue Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E. McKenney" Cc: Joel Fernandes Cc: Qais Yousef Cc: Xuewen Yan Cc: kuyo chang Cc: hupu Cc: Zhan Xusheng Cc: zhidao su (Xiaomi) Cc: Hui Su Cc: Shubhang Kaushik (Ampere) Cc: kernel-team@android.com --- kernel/sched/core.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 863f4e3a2051f..6691afa9da906 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4431,7 +4431,6 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) * it disabling IRQs (this allows not taking ->pi_lock). */ WARN_ON_ONCE(p->se.sched_delayed); - WARN_ON_ONCE(p->is_blocked); /* If p is current, we know we can run here, so clear blocked_on */ clear_task_blocked_on(p, NULL); if (!ttwu_state_match(p, state, &success)) @@ -7025,6 +7024,19 @@ static inline void proxy_reacquire_rq_lock(struct rq *rq, struct rq_flags *rf) update_rq_clock(rq); } +static void +proxy_activate(struct rq *rq, struct rq_flags *rf, struct task_struct *p) + __must_hold(__rq_lockp(rq)) +{ + lockdep_assert_rq_held(rq); + proxy_resched_idle(rq); + proxy_release_rq_lock(rq, rf); + + wake_up_process(p); + + proxy_reacquire_rq_lock(rq, rf); +} + /* * If the blocked-on relationship crosses CPUs, migrate @p to the * owner's CPU. @@ -7118,15 +7130,11 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) /* Follow blocked_on chain. */ for (p = donor; p->is_blocked; p = owner) { - /* if its PROXY_WAKING, do return migration or run if current */ struct mutex *mutex = p->blocked_on; + if (!mutex) { clear_task_blocked_on(p, mutex); - if (task_current(rq, p)) { - unblock_task(p); - return p; - } - goto deactivate; + goto activate; } /* @@ -7153,16 +7161,12 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) owner = __mutex_owner(mutex); if (!owner) { /* - * If there is no owner, either clear blocked_on - * and return p (if it is current and safe to - * just run on this rq), or return-migrate the task. + * If there is no owner, clear blocked_on + * and wake the task to try and grab the + * lock it is waiting on. */ __clear_task_blocked_on(p, NULL); - if (task_current(rq, p)) { - unblock_task(p); - return p; - } - goto deactivate; + goto activate; } if (!READ_ONCE(owner->on_rq) || owner->se.sched_delayed) { @@ -7252,6 +7256,9 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) resched_idle: return proxy_resched_idle(rq); +activate: + proxy_activate(rq, rf, p); + return NULL; deactivate: proxy_deactivate(rq, p); return NULL; -- 2.56.1.911.g883d8bcb20-goog