lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <14af463a-d21e-4239-9091-a667f200acff@amd.com>
Date: Fri, 9 Jan 2026 15:51:30 +0530
From: K Prateek Nayak <kprateek.nayak@....com>
To: Zicheng Qu <quzicheng@...wei.com>, <mingo@...hat.com>,
	<peterz@...radead.org>, <juri.lelli@...hat.com>,
	<vincent.guittot@...aro.org>, <dietmar.eggemann@....com>,
	<rostedt@...dmis.org>, <bsegall@...gle.com>, <mgorman@...e.de>,
	<vschneid@...hat.com>, <linux-kernel@...r.kernel.org>
CC: <tanghui20@...wei.com>
Subject: Re: [PATCH] sched/fair: Fix vruntime drift by preventing double lag
 scaling during reweight

Hello Zicheng,

On 1/9/2026 2:10 PM, Zicheng Qu wrote:
> Hi Prateek,
> 
> On 1/9/2026 12:50 PM, K Prateek Nayak wrote:
>> If I'm not mistaken, the problem is that we'll see "curr->on_rq" and
>> then do:
>>
>>      if (curr && curr->on_rq)
>>          load += scale_load_down(curr->load.weight);
>>
>>      lag *= load + scale_load_down(se->load.weight);
>>
>>
>> which shouldn't be the case since we are accounting "se" twice when
>> it is also the "curr" and avg_vruntime() would have also accounted it
>> already since "curr->on_rq" and then we do everything twice for "se".
> Thanks for the analysis — I agree your concern is reasonable, but I
> think the issue here is slightly different from "accounting se twice",
> but a semantic mismatch in how place_entity() is used.
> 
> place_entity() is meant to compensate lag for entities being inserted
> into the runqueue, accounting for the effect of a new entity on the
> weighted average vruntime. That assumption holds when an se is joining
> the rq. However, when se == cfs_rq->curr, the entity never left the
> runqueue and avg_vruntime() has not changed, so applying enqueue-style
> lag scaling is not appropriate.

I believe the intention is to discount the contribution of the
task and then re-account it again after the reweigh. I don't think
se being the "curr" makes it any different except for the fact that
its vruntime and load contribution isn't reflected in the sum and
is added in by avg_vruntime()

>> I'm wondering if instead of adding a flag, we can do:
> Yes, I totally agree that adding a new flag is unnecessary. We
> can handle this directly in place_entity() by skipping lag scaling in
> case of `se == cfs_rq->curr`, for example:
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index da46c3164537..1b279bf43f38 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5123,6 +5123,15 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
> 
>                 lag = se->vlag;
> 
> +              /*
> +               * place_entity() compensates lag for entities being inserted into the
> +               * runqueue. When se == cfs_rq->curr, the entity never left the rq and
> +               * avg_vruntime() did not change, so enqueue-style lag scaling does not
> +               * apply.
> +               */
> +              if (se == cfs_rq->curr)
> +                      goto skip_lag_scale;

This affects the place_entity() from enqueue_task() where se is dequeued
(se->on_rq == 0) but it is still the curr - can happen when rq drops
lock for newidle balance and a concurrent wakeup is queuing the task.

You need to check for "se == cfs_rq->curr && se->on_rq" here and then
this bit should be good.

Let me stare more at the avg_vruntime() since "curr->on_rq" would add
its vruntime too in that calculation.

> +
>                 /*
>                  * If we want to place a task and preserve lag, we have to
>                  * consider the effect of the new entity on the weighted
> @@ -5185,6 +5194,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>                 lag = div_s64(lag, load);
>         }
> 
> +skip_lag_scale:
>         se->vruntime = vruntime - lag;
> 
>         if (se->rel_deadline) {
> 
> Best regards,
> Zicheng

-- 
Thanks and Regards,
Prateek


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ