From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 4C01735DA5B for ; Thu, 25 Jun 2026 09:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782379001; cv=none; b=gLB2tMTI4o96PVGIOVHjo2AYZ7lIP51T9Trv1i+07miU55+Oaw77Pjc4SFHfmSGt0idJQUCMvuk7BIxcMt8WlVlMPYIn3/ct+wGDnQ5ZYvJb3CIyX//x2mxcW4UY8TW6nKICch7iCbrtFCtyU/2AfCpquIzzd7q768GP4Ux+EQ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782379001; c=relaxed/simple; bh=Hb8Cnwi9Sav2pgRtuqLxWwcAFsxzzxJf0ntuHBjxmWU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TuUpfCCdr/TSQ8sUPGziAyPBSavVX/JCKLr2OBd6pHJ817tDz0y6I85YKELw75TQOfUxSLnLbsmHndbUyATR00CUDk1h2rhxzgvx5E1tP1IsMty4kBmr/kaCD4czWtNELkErVlGUhJvN1n7sjTOCdyBtQOAb38D3hSF8899Te3M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=oFg4NV+w; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass 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="oFg4NV+w" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=Vh9Aj2GmcfMxMpTvwtKXW/6ycfoU04A+iJLfROlWqVg=; b=oFg4NV+waHjwckKpVSoSnjxqVw o0z1OgzYTxPGnVFw7m+g4mw7wfadeWM91l5VtX9RQP7g22k8/pXP8482AKpqouaSmd+s8T3tdrhtM rt9BUrIPo1JAbw02JMUdzfA4ds8iOulXoMK49dQSCoXdWrmDwQwToYfi7PIE6bGw8jESePdi0+9I/ U9I8lZGt0J31eIM0ci5Tu+Hz4NVCi27C5pxbutm0XbeJqCOKJZ942jkNb00adtt+1ASFEKMm7Le1K KNds4hUMr6f0eTO6s1hhetCd8aHUb/ggWa3c9Sw8/R6ZXYqT8q5pn064IiDM6LYzHaS1kO6J4SOU5 SsdoB7Xg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wcgCG-00000009dAb-0GME; Thu, 25 Jun 2026 09:16:33 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8D3BA300BDE; Thu, 25 Jun 2026 11:16:31 +0200 (CEST) Date: Thu, 25 Jun 2026 11:16:31 +0200 From: Peter Zijlstra To: Sechang Lim Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, gmonaco@redhat.com Subject: Re: [PATCH] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched() Message-ID: <20260625091631.GB1181229@noisy.programming.kicks-ass.net> References: <20260625065656.392182-1-rhkrqnwk98@gmail.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: <20260625065656.392182-1-rhkrqnwk98@gmail.com> On Thu, Jun 25, 2026 at 06:54:19AM +0000, Sechang Lim wrote: > set_tsk_need_resched() tests TIF_NEED_RESCHED, calls > __trace_set_need_resched() if the flag is clear, then sets it via > set_tsk_thread_flag(). A BPF raw_tp program attached to > sched_set_need_resched executes synchronously inside __bpf_trace_run(). > On return, __bpf_trace_run() drops the RCU lock with > rcu_read_unlock_migrate(), which on the preempt-or-BH-disabled path > calls set_need_resched_current() -> set_tsk_need_resched() again. > > set_tsk_thread_flag() follows the tracepoint call, so every re-entrant > frame sees TIF_NEED_RESCHED clear and calls __trace_set_need_resched() > again: > > BUG: TASK stack guard page was hit at ffffc9001224ff98 > Oops: stack guard page: 0000 [#1] SMP KASAN PTI > RIP: 0010:__bpf_trace_sched_set_need_resched_tp+0x1c/0x190 > Call Trace: > trace_sched_set_need_resched_tp+0x110/0x130 > set_tsk_need_resched include/linux/sched.h:2076 > set_need_resched_current include/linux/sched.h:2094 > rcu_read_unlock_special+0x43a/0x440 > __rcu_read_unlock+0x9e/0x120 > rcu_read_unlock_migrate+0xa9/0x240 > __bpf_trace_run+0x131/0x180 > bpf_trace_run3+0x333/0x430 > __bpf_trace_sched_set_need_resched_tp+0x13a/0x190 > trace_sched_set_need_resched_tp+0x110/0x130 > set_tsk_need_resched include/linux/sched.h:2076 > ... > > Replace the separate test_tsk_thread_flag() + set_tsk_thread_flag() pair > with test_and_set_tsk_thread_flag(). > > Fixes: adcc3bfa8806 ("sched: Adapt sched tracepoints for RV task model") > Signed-off-by: Sechang Lim > --- > include/linux/sched.h | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index ee06cba5c6f5..c9efd08dae92 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2071,10 +2071,9 @@ static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag) > > static inline void set_tsk_need_resched(struct task_struct *tsk) > { > - if (tracepoint_enabled(sched_set_need_resched_tp) && > - !test_tsk_thread_flag(tsk, TIF_NEED_RESCHED)) > + if (!test_and_set_tsk_thread_flag(tsk, TIF_NEED_RESCHED) && > + tracepoint_enabled(sched_set_need_resched_tp)) > __trace_set_need_resched(tsk, TIF_NEED_RESCHED); > - set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); > } __resched_curr() does the same, no? Also, did you check if the RV model perhaps relies on the TIF bit not being set when the tracepoint is tripped?