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>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] sched_ext: Track currently locked rq
Date: Wed, 16 Jul 2025 14:40:14 +0200 [thread overview]
Message-ID: <aHedrl4G5DecVzpS@gpd4> (raw)
In-Reply-To: <qxulb3ckm256bltfep45iac3vifv342o24654ulh4zt6shvg5j@grp7crx56rk3>
Hi Breno,
On Wed, Jul 16, 2025 at 03:47:38AM -0700, Breno Leitao wrote:
> Hello Andrea,
>
> On Tue, Jul 15, 2025 at 07:20:28PM +0200, Andrea Righi wrote:
> > > On Tue, Apr 22, 2025 at 10:26:32AM +0200, Andrea Righi wrote:
>
> > >
> > > > + lockdep_assert_rq_held(rq);
> > > > + __this_cpu_write(locked_rq, rq);
> > >
> > > This is hitting the following BUG() on some of my debug kernels:
> > >
> > > BUG: using __this_cpu_write() in preemptible [00000000] code: scx_layered_6-9/68770
> > >
> > > I have lockdep enabled, and I don't see the assert above. I am wondering
> > > if rq is locked but preemption continues to be enabled (!?)
> >
> > Interesting. And it makes sense, because we may have callbacks called from
> > a preemptible context (especially when rq == NULL).
> >
> > I think we can just put a preempt_disable() / preempt_enable() around
> > __this_cpu_write(). If we jump to another CPU during the callback it's
> > fine, since we would track the rq state on the other CPU with its own local
> > variable. And if we were able to jump there, it means that preemption was
> > disabled as well.
>
> First of all thanks for the suggestion!
>
> What about a patch like the following:
Looks good to me, feel free to add my:
Acked-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
>
> commit 9ed31e914181ec8f2d0b4484c42b00b6794661b9
> Author: Breno Leitao <leitao@debian.org>
> Date: Wed Jul 16 03:10:59 2025 -0700
>
> sched/ext: Suppress warning in __this_cpu_write() by disabling preemption
>
> __this_cpu_write() emits a warning if used with preemption enabled.
>
> Function update_locked_rq() might be called with preemption enabled,
> which causes the following warning:
>
> BUG: using __this_cpu_write() in preemptible [00000000] code: scx_layered_6-9/68770
>
> Disable preemption around the __this_cpu_write() call in
> update_locked_rq() to suppress the warning, without affecting behavior.
>
> If preemption triggers a jump to another CPU during the callback it's
> fine, since we would track the rq state on the other CPU with its own
> local variable.
>
> Suggested-by: Andrea Righi <arighi@nvidia.com>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Fixes: 18853ba782bef ("sched_ext: Track currently locked rq")
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index b498d867ba210..24fcbd7331f73 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -1258,7 +1258,14 @@ static inline void update_locked_rq(struct rq *rq)
> */
> if (rq)
> lockdep_assert_rq_held(rq);
> + /*
> + * __this_cpu_write() emits a warning when used with preemption enabled.
> + * While there's no functional issue if the callback runs on another
> + * CPU, we disable preemption here solely to suppress that warning.
> + */
> + preempt_disable();
> __this_cpu_write(locked_rq, rq);
> + preempt_enable();
> }
>
> /*
next prev parent reply other threads:[~2025-07-16 12:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 8:26 [PATCH v3 0/2] sched_ext: Introduce rq lock tracking Andrea Righi
2025-04-22 8:26 ` [PATCH 1/2] sched_ext: Track currently locked rq Andrea Righi
2025-07-15 9:13 ` Breno Leitao
2025-07-15 17:20 ` Andrea Righi
2025-07-16 10:47 ` Breno Leitao
2025-07-16 12:40 ` Andrea Righi [this message]
2025-07-16 12:43 ` Breno Leitao
2025-04-22 8:26 ` [PATCH 2/2] sched_ext: Fix missing rq lock in scx_bpf_cpuperf_set() Andrea Righi
2025-04-22 19:33 ` [PATCH v3 0/2] sched_ext: Introduce rq lock tracking Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2025-04-20 19:30 [PATCH v2 " Andrea Righi
2025-04-20 19:30 ` [PATCH 1/2] sched_ext: Track currently locked rq Andrea Righi
2025-04-21 19:03 ` Tejun Heo
2025-04-22 6:27 ` Andrea Righi
2025-04-19 12:24 [PATCH 0/2] sched_ext: Introduce rq lock tracking Andrea Righi
2025-04-19 12:24 ` [PATCH 1/2] sched_ext: Track currently locked rq Andrea Righi
2025-04-19 17:34 ` Tejun Heo
2025-04-19 20:10 ` Andrea Righi
2025-04-19 20:30 ` Andrea Righi
2025-04-19 21:27 ` Andrea Righi
2025-04-20 17:44 ` Tejun Heo
2025-04-20 18:34 ` Andrea Righi
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=aHedrl4G5DecVzpS@gpd4 \
--to=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.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.