From nobody Fri Nov 29 23:59:09 2024 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DDEA1D58B7; Fri, 13 Sep 2024 08:58:36 +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=1726217918; cv=none; b=I3VBvvoHOLTNJ+WPofGdI0M6LwiP+tmLDIraFsPSEmd5gBech6rbIzq0gMNYFEcSR5RA97dVdXX4lq/S9IYrUQS4EPz5qKUJwONezXc7f9M9jVEMuLwAoFSsbc6kHVBzv8fY6zLF/Y3Dns3RD3hErsfzoytKwGQ6fQwfEUqG/0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726217918; c=relaxed/simple; bh=gvYM1eP7xAAEJwcJpVXx5FknQI88VmeZhycs4DExV5M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=AQYV7ZNXN6gocWZvY4cqMI5vCBNZf8VeXDTDLFSovfixP72fDDA60V4knIBg5+i11Sv03s0vNUAxemeh1+oW2+ZFn2V8SBN30znpVP/7GsXB3DIe5Vga4qeRfDIMGNZBF8s9W3nbVQcWqpvvhynVBOp7KI6TZ43Ma8N1Kv/PqB4= 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 CEB8D13D5; Fri, 13 Sep 2024 01:59:05 -0700 (PDT) Received: from e126645.arm.com (unknown [10.57.75.215]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C1D4E3F73B; Fri, 13 Sep 2024 01:58:33 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , stable@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH] sched/fair: Fix integer underflow Date: Fri, 13 Sep 2024 10:58:23 +0200 Message-Id: <20240913085824.404709-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: 0b0695f2b34a ("sched/fair: Rework load_balance()") 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