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-next>] [day] [month] [year] [list]
Message-Id: <752ae417c02b9277ca3ec18893747c54dd5f277f.1724245193.git.hongyan.xia2@arm.com>
Date: Wed, 21 Aug 2024 14:02:52 +0100
From: Hongyan Xia <hongyan.xia2@....com>
To: Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Juri Lelli <juri.lelli@...hat.com>,
	Vincent Guittot <vincent.guittot@...aro.org>,
	Dietmar Eggemann <dietmar.eggemann@....com>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ben Segall <bsegall@...gle.com>,
	Mel Gorman <mgorman@...e.de>,
	Valentin Schneider <vschneid@...hat.com>
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] sched/fair: Warn against unbalanced util_est during dequeue

The latest tip/sched/core seems to have an unbalanced util_est issue. As
I am debugging it, I found the logic util_est_dequeue() doesn't make
much sense. It guards against util_est underflow like this:

enqueued -= min_t(unsigned int, enqueued, _task_util_est(p));

However, this is misleading because when the number of tasks drops to 0,
util_est should be exactly 0, no more, no less, because
util_est_update() is done after util_est_dequeue() and there is no
change of util_est between util_est_enqueue() and dequeue(). Even if the
current logic guards against underflow, it doesn't guard against
overflow and may cause problems to go un-noticed.

Do not guard against underflow and add a warning to check that util_est
should be exactly 0 when queue is empty.

Signed-off-by: Hongyan Xia <hongyan.xia2@....com>
---
 kernel/sched/fair.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fea057b311f6..574ef19df64b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4950,7 +4950,7 @@ static inline void util_est_dequeue(struct cfs_rq *cfs_rq,
 
 	/* Update root cfs_rq's estimated utilization */
 	enqueued  = cfs_rq->avg.util_est;
-	enqueued -= min_t(unsigned int, enqueued, _task_util_est(p));
+	enqueued -= _task_util_est(p);
 	WRITE_ONCE(cfs_rq->avg.util_est, enqueued);
 
 	trace_sched_util_est_cfs_tp(cfs_rq);
@@ -7176,10 +7176,14 @@ static bool dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	util_est_dequeue(&rq->cfs, p);
 
 	if (dequeue_entities(rq, &p->se, flags) < 0) {
+		if (!rq->cfs.h_nr_running)
+			SCHED_WARN_ON(rq->cfs.avg.util_est);
 		util_est_update(&rq->cfs, p, DEQUEUE_SLEEP);
 		return false;
 	}
 
+	if (!rq->cfs.h_nr_running)
+		SCHED_WARN_ON(rq->cfs.avg.util_est);
 	util_est_update(&rq->cfs, p, flags & DEQUEUE_SLEEP);
 	hrtick_update(rq);
 	return true;
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ