public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [bug-report] possible s64 overflow in max_vruntime()
@ 2022-12-21 15:19 Zhang Qiao
  2022-12-21 16:10 ` Waiman Long
  2022-12-22 12:45 ` Peter Zijlstra
  0 siblings, 2 replies; 24+ messages in thread
From: Zhang Qiao @ 2022-12-21 15:19 UTC (permalink / raw)
  To: Waiman Long, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Daniel Bristot de Oliveira
  Cc: lkml

hi folks,

    I found problem about s64 overflow in max_vruntime().

    I create a task group GROUPA (path: /system.slice/xxx/yyy/CGROUPA) and run a task in this
group on each cpu, these tasks is while loop and 100% cpu usage.

    When unregister net devices, will queue a kwork on system_highpri_wq at flush_all_backlogs()
and wake up a high-priority kworker thread on each cpu. However, the kworker thread has been
waiting on the queue and has not been scheduled.

    After parsing the vmcore, the vruntime of the kworker is 0x918fdb05287da7c3 and the
cfs_rq->min_vruntime is 0x124b17fd59db8d02.

    why the difference between the cfs_rq->min_vruntime and kworker's vruntime is so large?
    1) the kworker of the system_highpri_wq sleep for long long time(about 300 days).
    2) cfs_rq->curr is the ancestor of the GROUPA, cfs->curr->load.weight is 2494, so when
the task belonging to the GROUPA run for a long time, its vruntime will increase by 420
times, cfs_rq->min_vruntime will also grow rapidly.
    3) when wakeup kworker thread, kworker will be set the maximum value between kworker's
vruntime and cfs_rq->min_vruntime. But at max_vruntime(), there will be a s64 overflow issue,
as follow:

---------

static inline u64 min_vruntime(u64 min_vruntime, u64 vruntime)
{
	/*
	 * vruntime=0x124b17fd59db8d02
	 * min_vruntime=0x918fdb05287da7c3
	 * vruntime - min_vruntime = 9276074894177461567 > s64_max, will s64 overflow
	 */
	s64 delta = (s64)(vruntime - min_vruntime);
	if (delta < 0)
		min_vruntime = vruntime;

	return min_vruntime;
}

----------

max_vruntime() will return the kworker's old vruntime, it is incorrect and the correct result
shoud be cfs_rq->minvruntime. This incorrect result is greater than cfs_rq->min_vruntime and
will cause kworker thread starved.

    Does anyone have a good suggestion for slove this problem? or bugfix patch.

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-02-09 14:35 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-21 15:19 [bug-report] possible s64 overflow in max_vruntime() Zhang Qiao
2022-12-21 16:10 ` Waiman Long
2022-12-22 12:45 ` Peter Zijlstra
2022-12-23 13:57   ` Zhang Qiao
2023-01-12  3:01     ` Zhang Qiao
2023-01-25 19:57     ` Roman Kagan
2023-01-25 19:45   ` Roman Kagan
2023-01-26 12:49     ` Peter Zijlstra
2023-01-26 18:31       ` Roman Kagan
2023-01-27 11:44         ` Peter Zijlstra
2023-01-27 16:18           ` Vincent Guittot
2023-01-27 22:10             ` Benjamin Segall
2023-01-27 22:29               ` Vincent Guittot
2023-01-31  3:21             ` Chen Yu
2023-01-31  9:59               ` Roman Kagan
2023-01-31 11:10                 ` Vincent Guittot
2023-02-01 12:52                   ` Chen Yu
2023-02-07 19:37                   ` Roman Kagan
2023-02-08 10:13                     ` Vincent Guittot
2023-02-08 18:09                       ` Roman Kagan
2023-02-09 11:26                         ` Vincent Guittot
2023-02-09 13:33                           ` Roman Kagan
2023-02-09 13:44                             ` Vincent Guittot
2023-02-09 14:34                               ` Roman Kagan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox