From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 31EF1175A64 for ; Thu, 25 Jun 2026 09:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782380366; cv=none; b=M9gOpvxbTV1ocq+WEHmmhSkCyOz2avG3ZdoEpT/uxBuAf4B6y3012TmFx+3JLLWJ/8sTUJeAyzwd04orAQwrPGdoLm4cUIWs39nIz7lZmnkPRMO/9kQ9icolBMg9WoZZsKKAETbLAkpyDODexqNCsc6SdKtIWF8Bzli2VWI7hXw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782380366; c=relaxed/simple; bh=h5YIEW+rUTDFTidTFOhVE0SV5DCSb/40DnBspexcnkc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=Iuol7tJVFzUvehaktHU2XTFYjMUKRsivk/tnw1c/JkB33OyrpgRO6VP0yPsgkvVISYLPishgpwfH//E9l/Y4pQH77hkXFGjyI1Nge1OKKC3S16BvckdSRbg2b8tsZ/+tO1RKGIq1i+jIgh9GDXYDg3AhcMkIDflA5hDgZ5rRP7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OemTG/49; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=B70gSdUw; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OemTG/49"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="B70gSdUw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782380364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=21aENga7I4Rh2S/L31iosRPT20cSMyEOVU1pKZZkVcI=; b=OemTG/49xo7eNmg6+MCmn8tYBLsBYHQm0FBtl7lakZ1+z+j0skBRVNwyeDvJhfuyn8QO3x Bf7airdv0Ea4bzs8qpO4KLjZFdctlHxu3axAo31AtSXD8cm/N6JNvPErE5Fr3g+VTYBcVf QsxuTmZghGtwyHw4cHE4w50AG05KJZE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-knDAPZoKNqmEroS2mm--FQ-1; Thu, 25 Jun 2026 05:39:21 -0400 X-MC-Unique: knDAPZoKNqmEroS2mm--FQ-1 X-Mimecast-MFC-AGG-ID: knDAPZoKNqmEroS2mm--FQ_1782380360 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49245e10b73so12983925e9.3 for ; Thu, 25 Jun 2026 02:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1782380360; x=1782985160; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=21aENga7I4Rh2S/L31iosRPT20cSMyEOVU1pKZZkVcI=; b=B70gSdUwqZ6LeBjC17a+AfNyyxlXNt9+d+wMUesLgqCksEB4ezbZpoERBdDtHdVzTc L9qNK7oPD9FjgAr0Ee6Ibl7DY4MhD3Yv7pJLauRlJ47R6c4v11JWuMKvIrjJ4rJJEviq mZwKNnoWOYn/4Rw3BRrWnHC3YSFAlxl2OHnT8QAMIXI+/j50svLp9zGi9ouwCyqIvXRG hNfMpavVBfgjx3On7ywS5cds+Siv6mDYYmh1o05eGotL0bmbygbRc5luE4ssL5JjV3VX 5Q0yRflGbdCO36owU7T44mfMjtfyWFHy9igdO5HmmtSOsa8y9Hzsj9EKajMquCU79/NK +uBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782380360; x=1782985160; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=21aENga7I4Rh2S/L31iosRPT20cSMyEOVU1pKZZkVcI=; b=qm5e3JpgOfg1sGT2IS7w2IWJSqj6jnz4fXICdlpmGEhT1ryqTSku6oMlb+H3n3HMZw cs3dkBFiV6NioGAGKgdjBZEe0stz73j9gFmTCEnnNrDSi+i6BP2dfhSUIMgK49UiicmO 0L8dEZDxHpEBRoJzy8ul21a438MEAYMOhwHOAErhaZCXcFVcTfbxpJ6c4eyH7DcV+GUh E/whPdgghnmP1kQDer5ENgvCCjvGFzzcHkdZbA2NALWKFmnXJL7oCNkCd7z2k1HeOATX 3eaotPLYTZlpBDO5DeQuwxdEcM6NhP/YN2laWECr6UrOfG+4r6H77IrrsWr+luCZ3Eb9 0FsA== X-Gm-Message-State: AOJu0YxCN58tZDTHDoeQa30z5OoRz8gc2hwke+DmT7PJPakz++3Co+4E /x9HEVPXDAVXZ6NaEkk8g6UyyD+sTRVdCyraHi+yWEvA+5wHZpMZqjKl6Bwun/8yEWrCKxhrIeP J4y0811dMEQ8kv2JgXxMQ24/NEfh3NeLTrek6hTPELbasXvu36W7gM8PdXt6Hofc+6w== X-Gm-Gg: AfdE7cl5i6lhawFz35XvLk09+V+imjrtGDHuZFGBuwEpbIBiB/W1aRKf2hzBOqvW2/S e4/VQfywBtnMXPxYg75/Xrm2GITtZ/N+kcAQbpizW5opEay/SzdgB5BrNdV9j3UMizUQqFr4bKI kH8rrq07lm1vxNb4kuXlk7t1EsYcv0huWbf7uHl7EHYo8ZqEO67cMjtxMPtoFTeQPHESejkTzhc 5Ut0bDbz/wWqth0a8YN4jJGtZpUcG2T5hsp5/9TR80dGRlTYHrqn/7+tzElMNF0UOIPlFwUknyh TsqFu+rfMeg1rDt6ANkCT+iGWm/9ilYRPeeRCXnzoAke4+7s8q1PREFcTdscFrKJgL2cLYiSoj7 LfBjBFx8KwjCk+IA= X-Received: by 2002:a05:600c:e547:20b0:492:40f2:4d78 with SMTP id 5b1f17b1804b1-4926685ffd3mr16088915e9.2.1782380360376; Thu, 25 Jun 2026 02:39:20 -0700 (PDT) X-Received: by 2002:a05:600c:e547:20b0:492:40f2:4d78 with SMTP id 5b1f17b1804b1-4926685ffd3mr16088525e9.2.1782380359946; Thu, 25 Jun 2026 02:39:19 -0700 (PDT) Received: from [192.168.1.167] ([185.168.96.228]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4926544dfaesm34245765e9.2.2026.06.25.02.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2026 02:39:19 -0700 (PDT) Message-ID: Subject: Re: [PATCH] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched() From: Gabriele Monaco To: Peter Zijlstra , 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 Date: Thu, 25 Jun 2026 11:39:18 +0200 In-Reply-To: <20260625091631.GB1181229@noisy.programming.kicks-ass.net> References: <20260625065656.392182-1-rhkrqnwk98@gmail.com> <20260625091631.GB1181229@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2026-06-25 at 11:16 +0200, Peter Zijlstra wrote: > 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().=C2=A0 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. > >=20 > > 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: > >=20 > > =C2=A0 BUG: TASK stack guard page was hit at ffffc9001224ff98 > > =C2=A0 Oops: stack guard page: 0000 [#1] SMP KASAN PTI > > =C2=A0 RIP: 0010:__bpf_trace_sched_set_need_resched_tp+0x1c/0x190 > > =C2=A0 Call Trace: > > =C2=A0=C2=A0 trace_sched_set_need_resched_tp+0x110/0x130 > > =C2=A0=C2=A0 set_tsk_need_resched include/linux/sched.h:2076 > > =C2=A0=C2=A0 set_need_resched_current include/linux/sched.h:2094 > > =C2=A0=C2=A0 rcu_read_unlock_special+0x43a/0x440 > > =C2=A0=C2=A0 __rcu_read_unlock+0x9e/0x120 > > =C2=A0=C2=A0 rcu_read_unlock_migrate+0xa9/0x240 > > =C2=A0=C2=A0 __bpf_trace_run+0x131/0x180 > > =C2=A0=C2=A0 bpf_trace_run3+0x333/0x430 > > =C2=A0=C2=A0 __bpf_trace_sched_set_need_resched_tp+0x13a/0x190 > > =C2=A0=C2=A0 trace_sched_set_need_resched_tp+0x110/0x130 > > =C2=A0=C2=A0 set_tsk_need_resched include/linux/sched.h:2076 > > =C2=A0=C2=A0 ... > >=20 > > Replace the separate test_tsk_thread_flag() + set_tsk_thread_flag() > > pair > > with test_and_set_tsk_thread_flag(). > >=20 > > Fixes: adcc3bfa8806 ("sched: Adapt sched tracepoints for RV task > > model") > > Signed-off-by: Sechang Lim > > --- > > =C2=A0include/linux/sched.h | 5 ++--- > > =C2=A01 file changed, 2 insertions(+), 3 deletions(-) > >=20 > > 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) > > =C2=A0 > > =C2=A0static inline void set_tsk_need_resched(struct task_struct *tsk) > > =C2=A0{ > > - if (tracepoint_enabled(sched_set_need_resched_tp) && > > - =C2=A0=C2=A0=C2=A0 !test_tsk_thread_flag(tsk, TIF_NEED_RESCHED)) > > + if (!test_and_set_tsk_thread_flag(tsk, TIF_NEED_RESCHED) > > && > > + =C2=A0=C2=A0=C2=A0 tracepoint_enabled(sched_set_need_resched_tp)) > > =C2=A0 __trace_set_need_resched(tsk, TIF_NEED_RESCHED); > > - set_tsk_thread_flag(tsk,TIF_NEED_RESCHED); > > =C2=A0} >=20 > __resched_curr() does the same, no? I think it wouldn't make the same re-entrant call but it's probably a good idea to make it consistent and have the flag set before the tracepoint every time. > Also, did you check if the RV model perhaps relies on the TIF bit not > being set when the tracepoint is tripped? It does not, we just check the tif passed to the tracepoint and not the one in the task, the assumption here is that it is set during that exact tracepoint (before or after doesn't matter, but it would matter if it was set on a previous event). Depending on what handlers do, this may become a problem for RV as well. Thanks, Gabriele