From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 23882332612 for ; Tue, 28 Apr 2026 16:50:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395051; cv=none; b=umFExx50ET2iqtHr6WCs1YMI51ziQtUYAai8gOlsh1hJAXQHlHcwWMiTxzQPlbeDPzyvyfbV/7o28ZgqLZdP2UnfqTD+RmONX/pyG/GeQC3pKPog2QrrG11ehm9kP/8qLRo7DIlOxPqUR8FurRKtkiJre89L/TWlKhv0MA36dhA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395051; c=relaxed/simple; bh=u0kRTS6GZLRSPKHqN1PbotzGJnNBQtzOhq/gqwav4tA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tHX1GDk/3r23J5tFIoQSVj2xaeN8fwz06YsBfH3quHevNC/hfZig0GdaXWImWZTXwjE+hlG4ujEt+hK30QaYqDin0YcVhqGCpgxVtY8JIicso2JTRgwp4HzTU+nHrMMMN7Pv7cfdXhNNuu7p7knEikagauhDWwqi8AdQYlJBVm4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rTgnxsv4; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rTgnxsv4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hg+yvCCzeXRnX6HCK8j6/wG77tRwE6PWB87gwgtu7Lw=; b=rTgnxsv4AVHCZ53l5tZx7/SjZu cJ8bo7fbdndK3TPDMqN3keoqh+mcuu6b/6mfu3aHNbSTz1swedinhVH6Irfo/GIE/R+Gy1s+/jqpf 12FAT9xMTvbTdWeV0D56Ij2U/Bb5jG0l7KVyOdaY8ZGgMaEnQdqLSspdzN3hSuqk6qUE1D5244S5I i2xirVlhgurwBIA+vdV2E/r+pD3aOZCRiZxu0cfeFwOc6mgaJhqVhfxA7MeDl2nGxTWBfHgf1jzkN gtTDkywiC/8FGob/FRgjLT8CW8vRej4crwoieFD3VBZrlVEfoxpukwZhmKjGDMMrK0Xdi2EFsyMoW Sr+LcHzw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1wHldj-00000003fFt-3RpB; Tue, 28 Apr 2026 16:50:27 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2E3333008E2; Tue, 28 Apr 2026 18:50:26 +0200 (CEST) Date: Tue, 28 Apr 2026 18:50:26 +0200 From: Peter Zijlstra To: K Prateek Nayak Cc: John Stultz , LKML , Vineeth Pillai , Sonam Sanju , Sean Christopherson , Kunwu Chan , Tejun Heo , Joel Fernandes , Qais Yousef , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , 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 Subject: Re: [PATCH 1/2] sched: proxy-exec: Close race causing workqueue work being delayed Message-ID: <20260428165026.GJ3126523@noisy.programming.kicks-ass.net> References: <20260427183848.698551-1-jstultz@google.com> <20260427183848.698551-2-jstultz@google.com> <20260428094353.GB1026330@noisy.programming.kicks-ass.net> <20260428111833.GL3102924@noisy.programming.kicks-ass.net> <9cf9b433-cba5-4a8e-8dbf-6410239cffb6@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9cf9b433-cba5-4a8e-8dbf-6410239cffb6@amd.com> On Tue, Apr 28, 2026 at 06:45:39PM +0530, K Prateek Nayak wrote: > > Something like so perhaps? > > > > --- > > diff --git a/include/linux/sched.h b/include/linux/sched.h > > index 368c7b4d7cb5..0bd5da8360f3 100644 > > --- a/include/linux/sched.h > > +++ b/include/linux/sched.h > > @@ -846,7 +846,11 @@ struct task_struct { > > struct alloc_tag *alloc_tag; > > #endif > > > > - int on_cpu; > > + u8 on_cpu; > > + u8 on_rq; > > + u8 is_blocked; > > + u8 __pad; > > + > > struct __call_single_node wake_entry; > > unsigned int wakee_flips; > > unsigned long wakee_flip_decay_ts; > > @@ -861,7 +865,6 @@ struct task_struct { > > */ > > int recent_used_cpu; > > int wake_cpu; > > - int on_rq; > > > > int prio; > > int static_prio; > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index da20fb6ea25a..06817ae0cbd9 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -615,6 +615,13 @@ EXPORT_SYMBOL(__trace_set_current_state); > > * [ The astute reader will observe that it is possible for two tasks on one > > * CPU to have ->on_cpu = 1 at the same time. ] > > * > > +* p->is_blocked <- { 0, 1 }: > > +* > > +* is set by block_task() and cleared by ttwu_do_activate() and indicates > > +* this task is blocked, as opposed to runnable. Used to distinguish between > > +* preempted and blocked tasks for proxy exec, which keeps everything on the > > +* runqueue. > > + * > > * task_cpu(p): is changed by set_task_cpu(), the rules are: > > * > > * - Don't call set_task_cpu() on a blocked task: > > @@ -2225,6 +2232,7 @@ void deactivate_task(struct rq *rq, struct task_struct *p, int flags) > > > > static void block_task(struct rq *rq, struct task_struct *p, int flags) > > { > > + p->is_blocked = 1; > > We never reach here with PROXY_EXEC. Instead we bail out in the caller > try_to_block_task() ... > > > if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags)) > > __block_task(rq, p); > > } > > @@ -3722,6 +3730,7 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, > > atomic_dec(&task_rq(p)->nr_iowait); > > } > > > > + p->is_blocked = 0; > > activate_task(rq, p, en_flags); > > wakeup_preempt(rq, p, wake_flags); > > > > @@ -7107,7 +7116,7 @@ static void __sched notrace __schedule(int sched_mode) > > struct task_struct *prev_donor = rq->donor; > > > > rq_set_donor(rq, next); > > - if (unlikely(next->blocked_on)) { > > + if (unlikely(next->is_blocked && next->blocked_on)) { > > ... so ->is_blocked here is always false for proxy tasks retained on > the runqueue. Right. Also, egads, we really should fix that block/ttwu part, this is a mess. Anyway, idea is simple even if execution turns into a bit of a mess now, set when task really is blocked and clear on wakeup. > I was trying something like below but I'm somewhere missing a > clear_task_blocked_on() for PROXY_WAKING before going back into > mutex_lock_common(): > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 8ec3b6d7d718b..6ea74aecc5fbd 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -586,6 +586,7 @@ struct sched_entity { > unsigned char sched_delayed; > unsigned char rel_deadline; > unsigned char custom_slice; > + unsigned char sched_proxy; > /* hole */ Should not live in sched_entity I suppose.