[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aJQYShudNtx5eeVV@oa-fangxiang3.localdomain>
Date: Thu, 7 Aug 2025 11:06:50 +0800
From: Fang Xiang <fangxiang3@...omi.com>
To: Zicheng Qu <quzicheng@...wei.com>
CC: <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>,
<tanghui20@...wei.com>, <zhangqiao22@...wei.com>, <judy.chenhui@...wei.com>
Subject: Re: [PATCH] sched/fair: Fix overflow in vruntime_eligible() causing
NULL return
On Wed, Jul 09, 2025 at 09:38:29AM +0000, Zicheng Qu wrote:
> In the vruntime_eligible() function, the original comparison:
> return avg >= (s64)(vruntime - cfs_rq->min_vruntime) * load;
> could produce incorrect results due to integer overflow in the 'avg' or
> s64 part.
>
> This overflow causes the comparison to return false even when the
> mathematical result should be true, leading all tasks to be falsely
> deemed ineligible. Consequently, pick_eevdf() returns NULL, triggering a
> kernel crash.
>
> The best approach should be to dig deep into why overflow occurs, which
> attributes lead to the overflow, whether it is normal, and how to avoid
> it. Not pretty sure if this part of the modification will introduce new
> issues, but it may be incorrect to simply spot a potentially
> overflowing integer type and directly use the >= sign for comparison.
> Therefore, drawing on the enqueue method in the rb tree, to avoid the
> impact of overflow, the method of first performing subtraction and then
> comparing with 0 is also adopted.
>
> The following are the relevant attributes that cause the return of NULL:
> crash> struct cfs_rq.avg_vruntime,avg_load,min_vruntime
> ffff9ea77ecb4280
> avg_vruntime = -4392414779907141680,
> avg_load = 28644,
> min_vruntime = 239776551994501,
>
> sched_entity: curr
> crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag
> 0xffff9ea74510d800
> deadline = 86432035728535,
> min_vruntime = 86431486021988,
> vruntime = 86431531134184,
> load = {
> weight = 6066,
> inv_weight = 0
> },
> vlag = 86431823023195,
>
> the sched_entity mapping to the root node in the cfs_rq
> crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
> sched_entity.run_node 0xffff9ea849fbc350
> deadline = 18446615868453340281,
> min_vruntime = 18446615868452621390,
> vruntime = 18446615868453018539,
> load = {
> weight = 9777152,
> inv_weight = 449829
> },
> vlag = -5599,
>
> the sched_entity mapping to the leftmost node in the csf_rq, also the
> left child of root node.
> crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
> sched_entity.run_node 0xffff9ea78d0280d0
> deadline = 18446615868452943132,
> min_vruntime = 18446615868452621390,
> vruntime = 18446615868452621390,
> load = {
> weight = 9777152,
> inv_weight = 449829
> },
> vlag = 444143,
>
> the sched_entity mapping to the rightmost node in the csf_rq, also the
> right child of root node.
> crash> struct sched_entity.deadline,min_vruntime,vruntime,load,vlag -l
> sched_entity.run_node 0xffff9ea783144350
> deadline = 515705106937888,
> min_vruntime = 515705106616146,
> vruntime = 515705106616146,
> load = {
> weight = 9777152,
> inv_weight = 449829
> },
> vlag = -260493,
>
> Fixes: 147f3efaa241 ("sched/fair: Implement an EEVDF-like scheduling policy")
> Signed-off-by: Zicheng Qu <quzicheng@...wei.com>
> ---
> kernel/sched/fair.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 7a14da5396fb..bfa4090cef93 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -734,7 +734,7 @@ static int vruntime_eligible(struct cfs_rq *cfs_rq, u64 vruntime)
> load += weight;
> }
>
> - return avg >= (s64)(vruntime - cfs_rq->min_vruntime) * load;
> + return avg - (s64)(vruntime - cfs_rq->min_vruntime) * load >= 0;
> }
>
> int entity_eligible(struct cfs_rq *cfs_rq, struct sched_entity *se)
> --
> 2.34.1
>
May I ask which specific version of the 6.6 LTS branch are you using?
On the 6.6.54 kernel version, I've also encountered the same issue in my device.
The following are the relevant attributes that cause the return of NULL in pick_eevdf():
cfs_rq:
avg_vruntime = -34534164181975319,
avg_load = 1531079,
min_vruntime = 26052230711305,
nr_running = 245,
h_nr_running = 245,
sched_entity: curr is NULL
the sched_entity mapping to the root node in the cfs_rq
deadline = 26052232578140,
min_vruntime = 17382361763776,
vruntime = 26052229578140,
load = {
weight = 1048576,
inv_weight = 4194304
},
vlag = 656101,
the sched_entity mapping to the leftmost node in the csf_rq
deadline = 17382364763776,
min_vruntime = 17382361763776,
vruntime = 17382361763776,
load = {
weight = 1048576,
inv_weight = 4194304
},
vlag = 8648818863863,
Powered by blists - more mailing lists