From nobody Thu Nov 28 11:41:47 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 745C017FD; Tue, 1 Oct 2024 13:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727790401; cv=none; b=ueij2DIJ/zg0jspruPF99CzTUMp4pGalFdLXJTQDsSSfcK8AZY4gjw96kBC+UV9m4Lj7XHSvk0y5oRF4QrfCIUo8UNc5VroOV6X4nHQkDJWImYlK32CxAmfDe7KFohxt9XazYPxfg2nJ/eWpDeYkG+ycZC19Ggbf5fcAqDxMcnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727790401; c=relaxed/simple; bh=TKxnXDkGhATn0FqIrpUz5udTcw+K0UUOvMulDmQ8L8A=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Uaq1PRGkPmMcoAjYSrTeaBCetuXt2jtmPK41PGQ51/b3sMx2UvGzpFLrOa3kGkWd8nM4vmLD5TunaZ6I192D/G+vm5uywT0MmrhLLF5T+RZx7w7o2D+JvCiYBuQ/I4dlTyLgjwTfvfdVWlu4Tt/VQAnjVxjcoLkgn6q6rCP8DVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53ED3339; Tue, 1 Oct 2024 06:47:08 -0700 (PDT) Received: from e126645.arm.com (unknown [10.57.84.141]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6F5153F64C; Tue, 1 Oct 2024 06:46:35 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , stable@vger.kernel.org, Vincent Guittot , Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Rik van Riel Subject: [PATCH v2] sched/fair: Fix integer underflow Date: Tue, 1 Oct 2024 15:46:03 +0200 Message-Id: <20241001134603.2758480-1-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" (struct sg_lb_stats).idle_cpus is of type 'unsigned int'. (local->idle_cpus - busiest->idle_cpus) can underflow to UINT_MAX for instance, and max_t(long, 0, UINT_MAX) will output UINT_MAX. Use lsub_positive() instead of max_t(). Fixes: 16b0a7a1a0af ("sched/fair: Ensure tasks spreading in LLC during LB") cc: stable@vger.kernel.org Signed-off-by: Pierre Gondois Reviewed-by: Vincent Guittot --- kernel/sched/fair.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9057584ec06d..6d9124499f52 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10775,8 +10775,8 @@ static inline void calculate_imbalance(struct lb_en= v *env, struct sd_lb_stats *s * idle CPUs. */ env->migration_type =3D migrate_task; - env->imbalance =3D max_t(long, 0, - (local->idle_cpus - busiest->idle_cpus)); + env->imbalance =3D local->idle_cpus; + lsub_positive(&env->imbalance, busiest->idle_cpus); } =20 #ifdef CONFIG_NUMA --=20 2.25.1