From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796183579; b=xn53+mpcDtzQNLE5Jd9bMBRurUVxY7saSAMBVIFzK8OwfdO25w7GWOKOQokqTdnAswKs K7GvVSkUS623FfJz/ub0jjmEfA4DX+sM0xuXpUuglfkCqdNz4LjtgjFQKBfYt8eAHBIhH YmYc13PLM6eP8Yk7HI+iItihgNeZpp5lEVWGHWAMrji9TFFRH6TmlKRg54mZ3g89Q5wKz EUYKh7e+pF5Hrmf3VZdJq3P9yBXAxVpYA/u5AcKST6ntlnVN/e1A3cbZSsIyZfxj38Omg OtKzsh+187/rsfIPsNb05RnZ/id//0PfpAgS78wKrUwnMsPDbLK8VkgEeuZUkcjpLCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183579; 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=96sPDoM2WFRn7eCMZ2SWVt51STmGiMZ7UF+TKRGoO8M=; b=xo3ZTYtqwV5KYwgbIKoeRikqEXy5CE9IW/msqhh3ZvRxW9w72EWosZoGC41BaeIEdcL0 MGgTL1yjTD44pOiZXqomarFA36wIWGNpLyWNBtCpVraJWvOGcZw0shIYXpGiLZNmNQnp4 6Ns6TujkMr0zRMsryU+zjlPn9aqFvb/hvUce3xcbKCmPPSyMxviPMMit1cRMBthwsMuCq 0C2Hq4hiXdq3g9fA5w5cY6j8mfUX3RgKQGuiHbk+WKzRks4HfhOxLQqxYHQ1Jibyf3yrG T4QjPIi13pPtvncndsiKWugjywsgPEKexJcsBHEi3VlcWTeGTYhtmPNs7A8+DyC6s+g== 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="kwRBAWh/"; arc=none smtp.remote-ip=209.85.214.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 839DF606A697 for ; Wed, 2 Dec 2026 03:52:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 839DF606A697 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=kwRBAWh/ Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2f053f95aadso113961575ad.2 for ; Tue, 01 Dec 2026 19:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796183579; x=1796788379; 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=96sPDoM2WFRn7eCMZ2SWVt51STmGiMZ7UF+TKRGoO8M=; b=kwRBAWh/QKBi9lxfoyF8iuYhOYa/ra7SHGtCEUftRCq0Ytyc8WjhEUOkXjklPVrGve 112WnDzhbX1KvSqvt5/ru1Ssl8ZXmKQRp92v0lNJz/X/pb++ba4GRjf0ZxW+jwk3vjkp n424FMg7KIvR2MwSGfJWd3Q/JrwMWykQwtUPt2bH8ljPnJpw3DgUBiU9wgSGDwPFBdUX FsKcvj6PLHSobHommSfFgPtg6t1RP3wMeSY4PBYL4QHoNvZz8dbMj4ldwy1pmnOwtL8N HK3xMx0UWoGCWaDO2PbtPIsex6TJI8EzN2HTcIeqkfaWSBuDrZj8gluf69aWikKgxTja L0Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796183579; x=1796788379; 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=96sPDoM2WFRn7eCMZ2SWVt51STmGiMZ7UF+TKRGoO8M=; b=1p16LcjLqWH9BpLEAdHa4enfGsx8eSMXoUWWu1nw19w2yV+KNfe99g35eXisHhnGvw pSchFjRdohxbeN6pg+VRtRLGlJgBpkhx2+DqvVSPooz/4Xhy5fD3oQxD8aw53+uQBQ5w J1qq/ShX/bUKWvcA2g2osg6PeJtivSGJFAf0tSU/5FJ6U5Ftw3HCmSJBRR7VOe5l19ya MCcN6mYQSzV04fD+LiqPR771JUlV0WEx9uK/iyiiDs5Pomgy0va/U804BP9wAZUR8qwR wgAysA9uQeT+F/t/pRdihz90Mz/dgBk7QEjtzdCGJiQvqB84Fm5Uav17l5QZJhV64GRn 8hzA== X-Gm-Message-State: APuU4Z+Gfmo5UZY08NPE1DmUUh9fWa/yzLiCjshwX4HrrGaG2r/66zvK /NeuXz+IfISzfAd25c+YXdEcMzoAe3g110atcGiKPPIQk8A0gq9+mOpvgGtS/nfa2BK6kQgJbmA a7i5g/x2BxE17jRwg2i/hM9FcZSaIVVGdd9hlpVDRNxC0fd2uE+otuIL6YJAgYO7hOiizEgL1Ci uIvzdbXEU1crthU76uySJlDrRSFGA8CLoc+qhjpRafePZ06LJm X-Received: from plge8.prod.google.com ([2002:a17:902:cf48:b0:2e9:5b68:4b7d]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:dac6:b0:2e3:1bb4:6121 with SMTP id d9443c01a7336-2f03f177052mr360398725ad.49.1796183578358; Tue, 01 Dec 2026 19:52:58 -0800 (PST) Date: Wed, 2 Dec 2026 03:52:39 +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-12-jstultz@google.com> Subject: [PATCH v34 11/14] sched/proxy: Detect cycles in proxy walks earlier From: John Stultz To: LKML Cc: Hui Su , Kayra Cizmeci , John Stultz , Peter Zijlstra , Ingo Molnar , K Prateek Nayak , 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)" , "Shubhang Kaushik (Ampere)" , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" From: Hui Su Proxy execution follows blocked_on relationships to find a runnable lock owner. A cycle in that chain can make find_proxy_task() loop indefinitely while holding rq->lock. Use Brent checkpoint state directly in the real owner walk. Cycle detection reuses the owner resolution already performed by that walk and requires no separate preflight traversal. The checkpoint, power, and span state are all invocation-local. Keep the existing owner == p wakeup-race handling ahead of cycle detection. Unlike a sequence-marker approach, this adds no task_struct or runqueue state and requires no activation-time reset. Reviewed-by: Kayra Cizmeci Signed-off-by: Hui Su [jstultz: Minor tweaks to work with hard MAX_PROXY_CHAIN_DEPTH limit, and shortened the commit message.] Signed-off-by: John Stultz --- v34: * Dropped bit of the commit message referencing an older cover letter as suggested by Kayra Cizmeci 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6f5e1a896ee41..e324ff189fc00 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7125,6 +7125,9 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) __must_hold(__rq_lockp(rq)) { struct task_struct *owner = NULL; + struct task_struct *cycle_checkpoint = donor; + unsigned int cycle_power = 1; + unsigned int cycle_span = 0; bool curr_in_chain = false; int this_cpu = cpu_of(rq); struct task_struct *p; @@ -7135,6 +7138,12 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) for (p = donor; p->is_blocked; p = owner) { struct mutex *mutex = p->blocked_on; + if (cycle_span == cycle_power) { + cycle_checkpoint = p; + cycle_power <<= 1; + cycle_span = 0; + } + if (!mutex) { clear_task_blocked_on(p, mutex); goto activate; @@ -7240,8 +7249,13 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) goto resched_idle; } - /* Limit the depth we'll proxy to avoid cyclic deadlocks */ - if (++chain_depth > MAX_PROXY_CHAIN_DEPTH) { + /* + * Check for cycles, and worst case limit the depth + * we'll proxy to avoid cyclic deadlocks + */ + cycle_span++; + if (owner == cycle_checkpoint || + (++chain_depth > MAX_PROXY_CHAIN_DEPTH)) { if (curr_in_chain) return proxy_resched_idle(rq); __clear_task_blocked_on(p, NULL); -- 2.56.1.911.g883d8bcb20-goog