Re: [PATCH v7 1/3] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq
From: Qais Yousef
Date: Thu Nov 26 2026 - 06:49:24 EST
> > -static void __init init_uclamp_rq(struct rq *rq)
> > +void init_uclamp_rq(struct rq *rq)
> > {
> > enum uclamp_id clamp_id;
> > struct uclamp_rq *uc_rq = rq->uclamp;
> >
> > for_each_clamp_id(clamp_id) {
> > - uc_rq[clamp_id] = (struct uclamp_rq) {
> > - .value = uclamp_none(clamp_id)
> > - };
> > + memset(uc_rq[clamp_id].bucket, 0, sizeof(uc_rq[clamp_id].bucket));
>
> nit: indent
Hmm I thought I fixed that before posting.
>
> > + uclamp_rq_set(rq, clamp_id, uclamp_none(clamp_id));
>
> So I did reproduce WARN_ON_ONCE(!bucket->tasks) on CONFIG_UCLAMP_TASK_GROUP=y, which
> relies on .active being in sync with bucket->active.
More details will make following your thoughts easier.
> FWIW I don't see a good way of mitigating the missed decrement for .active,
> but if somebody else sees it please shout.
> I'll post my proposal in a minute
Please send it on top of patch 2 and 3 at least as they are good clean ups that
I'd like them in still. I think the two approaches are not mutually exclusive
and the maintainers can pick both this patch and your other proposal
potentially.
Given that this imbalance can only (if at all) happen once after boot I don't
think that WARN_ON_ONCE() is consequential assuming we fail safe - which
I think we do but since you weren't specific about the path and I didn't go and
try to untangle it, I could have missed something.
FWIW, I think since there are no correctness issue but inconvenient _expected_
harmless warning, we are good. It could just make debugging harder if this
warning is due to the race or a true bug. All the sensible choices have some
imperfections..