From: Andrea Righi <arighi@nvidia.com>
To: Breno Leitao <leitao@debian.org>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org,
jake@hillion.co.uk, kernel-team@meta.com
Subject: Re: [PATCH v2] sched/ext: Prevent update_locked_rq() calls with NULL rq
Date: Wed, 16 Jul 2025 21:29:58 +0200 [thread overview]
Message-ID: <aHf9tlDr5FKLLyyX@gpd4> (raw)
In-Reply-To: <20250716-scx_warning-v2-1-1d015b2d8efa@debian.org>
On Wed, Jul 16, 2025 at 10:38:48AM -0700, Breno Leitao wrote:
> Avoid invoking update_locked_rq() when the runqueue (rq) pointer is NULL
> in the SCX_CALL_OP and SCX_CALL_OP_RET macros.
Maybe it'd be useful to clarify that rq == NULL indicates a callback
invoked from an unlocked context. In that case, we don't need to store any
rq, since the default is already NULL (unlocked), and we can avoid
unnecessary updates.
With something like that:
Acked-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
>
> Previously, calling update_locked_rq(NULL) with preemption enabled could
> trigger the following warning:
>
> BUG: using __this_cpu_write() in preemptible [00000000]
>
> This happens because __this_cpu_write() is unsafe to use in preemptible
> context.
>
> Ensure that update_locked_rq() is only called when rq is non-NULL,
> preventing calling __this_cpu_write() on preemptible context.
>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Fixes: 18853ba782bef ("sched_ext: Track currently locked rq")
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> Changes in v2:
> - Avoid calling update_locked_rq() completely on preemptible mode (Peter Zijlstra)
> - Link to v1: https://lore.kernel.org/r/20250716-scx_warning-v1-1-0e814f78eb8c@debian.org
> ---
> kernel/sched/ext.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index b498d867ba210..7dd5cbcb7a069 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -1272,7 +1272,8 @@ static inline struct rq *scx_locked_rq(void)
>
> #define SCX_CALL_OP(sch, mask, op, rq, args...) \
> do { \
> - update_locked_rq(rq); \
> + if (rq) \
> + update_locked_rq(rq); \
> if (mask) { \
> scx_kf_allow(mask); \
> (sch)->ops.op(args); \
> @@ -1280,14 +1281,16 @@ do { \
> } else { \
> (sch)->ops.op(args); \
> } \
> - update_locked_rq(NULL); \
> + if (rq) \
> + update_locked_rq(NULL); \
> } while (0)
>
> #define SCX_CALL_OP_RET(sch, mask, op, rq, args...) \
> ({ \
> __typeof__((sch)->ops.op(args)) __ret; \
> \
> - update_locked_rq(rq); \
> + if (rq) \
> + update_locked_rq(rq); \
> if (mask) { \
> scx_kf_allow(mask); \
> __ret = (sch)->ops.op(args); \
> @@ -1295,7 +1298,8 @@ do { \
> } else { \
> __ret = (sch)->ops.op(args); \
> } \
> - update_locked_rq(NULL); \
> + if (rq) \
> + update_locked_rq(NULL); \
> __ret; \
> })
>
>
> ---
> base-commit: 155a3c003e555a7300d156a5252c004c392ec6b0
> change-id: 20250716-scx_warning-5143cf17f806
>
> Best regards,
> --
> Breno Leitao <leitao@debian.org>
>
next prev parent reply other threads:[~2025-07-16 19:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-16 17:38 [PATCH v2] sched/ext: Prevent update_locked_rq() calls with NULL rq Breno Leitao
2025-07-16 19:29 ` Andrea Righi [this message]
2025-07-17 1:04 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aHf9tlDr5FKLLyyX@gpd4 \
--to=arighi@nvidia.com \
--cc=bsegall@google.com \
--cc=changwoo@igalia.com \
--cc=dietmar.eggemann@arm.com \
--cc=jake@hillion.co.uk \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@meta.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.