Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796183579; b=kYmLsliWfYz8FgWeaGZlHQwk3DMwk5315u3KOw30prXR2ELjI0vplYLVQdCW2hiEiad8 UiQetw5T7DSlxu6jWIg25K3y/zI5F+z6a9bFfNN5pScwNqar3JfhDI5iEf+ajxoBdlOVB FiNKIc27RIXZnXRFV5EdarQ27kfp+5y7AYDHnFML6ml54pO9kXrE676Vo7I1FaKAtrZa9 tkUJBo5PLLyAi9S4gmaL5eV65jgA3FMT00aUQCV2X+NKKV6SEyKc/H6fpuo1kh+gI3Eub dgBPp+HuvFafeke+Wivo0q0T7hrXuRpRgfChcjENp/tLv6iRPXVF6BqyVkyaX1Gtjrg== 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=X8i9p8/1G49U20/ELAMjJeG81J9+WEWYfPr3XxC43pc=; b=H2VIkhIkZCpl1/yleX/MM7tEgM8/4TXJqZ3eRIgUVMCnnnEJQp0VXXMPstxO3Ju3RYqL u1f35+uSCYjngLGAW6ukCpwkLWUC3fHivTEgL8/c2AI3ULTFdTaMqwGCB2UF/11kYsOZi LpmA2uBjqKBy34u6DZqG9GfaGMNx5HgDksfdqeomh7bqKN5aTBkgzadZ+Hp6JTrVI84UF EIKMv0lniILl32qQYjfU6/anNG1KtypO2B+8wwyzTxkD5s28+Uksky9feP5mxOgEn1Fhs eMcTin7DJkj8IOvLsRA3qi2bdZwTW4C4r7aylnqAdamnYzqoGhMrDGPB8ibU9ELLGgA== 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=M3XDIuMm; arc=none smtp.remote-ip=209.85.216.69 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 AE710606A6B8 for ; Wed, 2 Dec 2026 03:52:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE710606A6B8 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=M3XDIuMm Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3b0a13ae043so13573672a91.0 for ; Tue, 01 Dec 2026 19:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796183578; x=1796788378; 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=X8i9p8/1G49U20/ELAMjJeG81J9+WEWYfPr3XxC43pc=; b=M3XDIuMm4fsgyEGwFPar3s/azq2Go8PXtpWRD6fAcBoC7yT9EaAL9twFuvEGhn4rS5 FW8am1aG+Np1xAeUA0y7ot3geND2sUcwqd/II7XXWWoV/ILzNbNN9VK09gC6bSqJpr0r u9VxNJoQXAS2gnd5D2dJ90Z8SmNUl/r0rKgRMGoxz098iJImkNG6NwV96vxeKQKJOgSM l/RJk8io4Hk3nzyleH2B44w7Qm2wLSA8HBnGf3ubHZU+NXrdOcxgxfbvD3kPTsBveZq/ YseRuCu9q+/WH8qBGPRUrWdGk7fE+mRpHtCe5VKxygHp7yEA46nx+jZW6usLX/3fkpoz eK+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796183578; x=1796788378; 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=X8i9p8/1G49U20/ELAMjJeG81J9+WEWYfPr3XxC43pc=; b=ItpEBUlJEaWJJAYt/5k4D31bG2SPTI9+5Xenpd3f69vEYBSuQD4ccbSXiXIJj5KER9 sHZpSo2unONnDV9Qqt6U6LfIiJCyAVufZJ4aJFAoXpYx1pGfvLrCbbQ6rWoYDaJ61ZGx P1q/LyLb6ZZiCvrxUS5zN6GeDvTL4QRn37dA4l5/u+lpXfS2BEIPKzZZiyDcC1HSEONG dZqIKCa54eHoKxswnh3P8vQ2oLuGifDW3N/aSLaXMR8nRSxiJhqQui7PYHQrSBL0VUk5 nxmBdhk23T8hcjaAlX+uxsxx3s0eTO49DAwzx5rF+UE+99DLY7VD2kpRSi2LBOcie5Hp hVtA== X-Gm-Message-State: APuU4Z/VlFsjHEgswxzuQBpFKQHmblL+5Y4KPD0qsSIGn6V6vy50LWRD 3zEhZfSo5WltnUgzMo+1zaC6+2OONT4YWKy3mgWSdNlAIz5NnIIIXAQFog2xv/H5rfW7nCrO20H gT4Gxh38t/9gV5mdb/51YnhhlyMWddqNziKtm588CzD3/gC/f8ROh+UigOt+maHWwAji5kBuDVS DMGTvhwBFN6LGXjEZbqOceYJfu6zPqoZWl94PeD61cyBjNrR1Q X-Received: from pjboc14.prod.google.com ([2002:a17:90b:1c0e:b0:3b4:d24d:f77f]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e7d0:b0:3ab:afca:1d79 with SMTP id 98e67ed59e1d1-3b41c8d926amr38028273a91.21.1796183577627; Tue, 01 Dec 2026 19:52:57 -0800 (PST) Date: Wed, 2 Dec 2026 03:52:38 +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-11-jstultz@google.com> Subject: [PATCH v34 10/14] sched/proxy: Break cyclic proxy chains by deactivating blocked tasks From: John Stultz To: LKML Cc: "zhidao su (Xiaomi)" , 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 , Hui Su , "Shubhang Kaushik (Ampere)" , kernel-team@android.com Content-Type: text/plain; charset="UTF-8" From: "zhidao su (Xiaomi)" find_proxy_task() follows the blocked_on/owner chain for a blocked donor. If the chain forms a cycle, __schedule() can keep walking the same chain while holding rq->lock. Kernel locks are not allowed to have cycles (except ww_mutexes, which we handle properly), so this logic isn't likely to trip unless a bad driver has incorrect locking (which lockdep should detect). However, eventually we want to have proxy-enabled futexes, where we can't control userland's locking, and will need to avoid wasting cpu time iterating around a cycle. Rescheduling idle is not enough here: the same blocked_on relation remains, so the next scheduling pass can select the same donor and re-enter the same cycle. So if we hit an excessive chain depth, clear the blocked_on relation and deactivate the blocked task. This removes the task from the proxy-exec runnable-chain selection path and lets the scheduler make progress. Use 1024 as the depth limit to match rtmutex's default max_lock_depth. Fixes: 7de9d4f94638 ("sched: Start blocked_on chain processing in find_proxy_task()") Signed-off-by: zhidao su (Xiaomi) [jstultz: Simplified slightly, dropping WARN_ON and owner == donor check, slightly reworked commit message, added curr_in_chain check] Signed-off-by: John Stultz --- v34: * Added curr_in_chain check to make sure we don't deactivate current. * Included fixes tag 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 6691afa9da906..6f5e1a896ee41 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7092,6 +7092,8 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf, proxy_reacquire_rq_lock(rq, rf); } +#define MAX_PROXY_CHAIN_DEPTH 1024 + /* * Find runnable lock owner to proxy for mutex blocked donor * @@ -7127,6 +7129,7 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) int this_cpu = cpu_of(rq); struct task_struct *p; int owner_cpu; + int chain_depth = 0; /* Follow blocked_on chain. */ for (p = donor; p->is_blocked; p = owner) { @@ -7236,6 +7239,15 @@ 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) { + if (curr_in_chain) + return proxy_resched_idle(rq); + __clear_task_blocked_on(p, NULL); + goto deactivate; + } + /* * OK, now we're absolutely sure @owner is on this * rq, therefore holding @rq->lock is sufficient to -- 2.56.1.911.g883d8bcb20-goog