From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF3822DE6FE for ; Fri, 28 Nov 2025 09:37:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764322632; cv=none; b=l6P8yUkM7UMvfDpMrCpW8gt3jrRweWgAnamZaIJQQFvenY31Dk4rzU8MPLIsUtAiqciUzE0QFHcTbj7MC2wJTKmdcZzI7eMz4lyjf8dMDcmrWuMQRvASfuWwdrdfkGkUAr5GnppFBs0pzltA0v20Sff6DkXIEVpomRvbi0xhyRg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764322632; c=relaxed/simple; bh=Bu4AGX8mEvyEf2eAOymkMtovHFAQb6AfLrVB6UGui04=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eVeUos8jLf461K46GtJReXmiT/bnfGsiBhan5PN/hg34W/V0IoDH/cgOeYEqmY4MrvYdklZgoYVCw1VEHq8BCCJAsUaZ/6LIjOk28xj5+N+FIG19xIS8Bpp7Dt+TKzDr79pxxl+5yiPSdKcXQLrKjRJOW07qNqBjBaRZ0vDwFmE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=M+RL6w2x; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="M+RL6w2x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:To:From: Content-Type; bh=wO4uGgqbBkNys+jSQZ9pEi5UdimdoK5Rou24HDofcnU=; b=M+RL6w2xMFmDgYCgt4hxQ9oThUVhk5XcMcMxvFnXHk7RgHl99fd6kYiP+QV1Nu tWX+Z8TDdD7ueHGRHZyF5hE3n46suyfjzdqxYpoxklw2IcIO4+HO1ZqKI2Q1He3r coGtNIbVDMKFTAfwHgHDTEUV44eCP4hShke6TirRLAyiI= Received: from [192.168.11.71] (unknown []) by gzsmtp3 (Coremail) with SMTP id PigvCgB3ngfNbClpPmiyFg--.27030S2; Fri, 28 Nov 2025 17:35:11 +0800 (CST) Message-ID: <9622a5ec-c754-4066-9ab9-683e98e91fcf@163.com> Date: Fri, 28 Nov 2025 17:35:09 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] sched: Fix psi_dequeue for Proxy Execution Content-Language: en-US To: John Stultz , LKML Cc: K Prateek Nayak , Johannes Weiner , Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Suren Baghdasaryan , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Mel Gorman , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , Thomas Gleixner , Daniel Lezcano , Suleiman Souhlal , kuyo chang , hupu , kernel-team@android.com References: <20251121190144.845002-1-jstultz@google.com> From: Haiyue Wang In-Reply-To: <20251121190144.845002-1-jstultz@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:PigvCgB3ngfNbClpPmiyFg--.27030S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxArW7JFyDurWDuryfJryfXrb_yoWrXr1Upa y7Kr1UArs7CFZYya97Zryj9Fy7G395Wr13Xrsrt348Cry7Ar429r1Skw4agrWDWrs3CF4Y vF429as2kw1jvFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UIYL9UUUUU= X-CM-SenderInfo: 5kdl53xhzdqiywtou0bp/xtbCzRDzX2kpbNBWFAAA3P On 11/22/2025 3:01 AM, John Stultz wrote: > Currently, if the sleep flag is set, psi_dequeue() doesn't > change any of the psi_flags. > > This is because psi_switch_task() will clear TSK_ONCPU as well psi_task_switch() > as other potential flags (TSK_RUNNING), and the assumption is > that a voluntary sleep always consists of a task being dequeued > followed shortly there after with a psi_sched_switch() call. > > Proxy Execution changes this expectation, as mutex-blocked tasks > that would normally sleep stay on the runqueue. But in the case > where the mutex-owning task goes to sleep, or the owner is on a > remote cpu, we will then deactivate the blocked task shortly > after. > > In that situation, the mutex-blocked task will have had its > TSK_ONCPU cleared when it was switched off the cpu, but it will > stay TSK_RUNNING. Then if we later dequeue it (as currently done > if we hit a case find_proxy_task() can't yet handle, such as the > case of the owner being on another rq or a sleeping owner) > psi_dequeue() won't change any state (leaving it TSK_RUNNING), > as it incorrectly expects a psi_task_switch() call to > immediately follow. > > Later on when the task get woken/re-enqueued, and psi_flags are > set for TSK_RUNNING, we hit an error as the task is already > TSK_RUNNING: > psi: inconsistent task state! task=188:kworker/28:0 cpu=28 psi_flags=4 clear=0 set=4 > > To resolve this, extend the logic in psi_dequeue() so that > if the sleep flag is set, we also check if psi_flags have > TSK_ONCPU set (meaning the psi_task_switch is imminent) before > we do the shortcut return. > > If TSK_ONCPU is not set, that means we've already switched away, > and this psi_dequeue call needs to clear the flags. > > Fixes: be41bde4c3a8 ("sched: Add an initial sketch of the find_proxy_task() function") > Reported-by: K Prateek Nayak > Closes: https://lore.kernel.org/lkml/20251117185550.365156-1-kprateek.nayak@amd.com/ > Signed-off-by: John Stultz > Tested-by: K Prateek Nayak > Acked-by: Johannes Weiner > --- > proxy-v13: > * Reworked for collision > proxy-v15: > * Fixed commit message typo noticed by Todd Kjos > v1 (separate from proxy series): > * Reworded commit message in response to K Prateek pointing > out this issue can affect us earlier in the full proxy > series then I had anticipated. > v2 (separate from proxy series): > * Minor tweak to comment suggested by Johannes > > Cc: Joel Fernandes > Cc: Qais Yousef > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Juri Lelli > Cc: Vincent Guittot > Cc: Dietmar Eggemann > Cc: Valentin Schneider > Cc: Johannes Weiner > Cc: Suren Baghdasaryan > Cc: Steven Rostedt > Cc: Ben Segall > Cc: Zimuzo Ezeozue > Cc: Mel Gorman > Cc: Will Deacon > Cc: Waiman Long > Cc: Boqun Feng > Cc: "Paul E. McKenney" > Cc: Metin Kaya > Cc: Xuewen Yan > Cc: K Prateek Nayak > Cc: Thomas Gleixner > Cc: Daniel Lezcano > Cc: Suleiman Souhlal > Cc: kuyo chang > Cc: hupu > Cc: kernel-team@android.com > --- > kernel/sched/stats.h | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > Tested-by: Haiyue Wang > > /*