From nobody Sat Jul 25 05:27:09 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E2093ED109 for ; Fri, 17 Jul 2026 10:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284144; cv=none; b=bSXl9U1bQjN+2QPXktLRauYyIVHxvGSCYTe0Z4FzZ4QTVEz4zKZchVGNVmCTk3ToV95oCyJmV++CwlJUHBlvpQT/dHLVvZ2++kPdpBkgArRgqCYTCIdn39gIsU1XpPbf/Gg6SYPRzRr61u2pdyKUAJL7pYkK6RZdFw8N3dfbGUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284144; c=relaxed/simple; bh=//C6IhK0SNDYLpEVmZHRpvwKY3/Y2RPsgQlJ5rfKZMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZsUMLT3f8JGAl3vYYakjlgzUXHoRPdUCDyeK8++IhxM8FeAIx4VlymEx/9ucuDxKIjh2RC+dGRoQU+VZBROjznqjwKbj7AZVARgtmNZOtJCo+wvXdVaZJapv4ROuTVwlSB+zxzOZ7IBnubgNnaGPkfm9sy5U+Mpiu+4TpIYEha4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QYFSlPts; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QYFSlPts" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784284140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ds0jVVzqCKUivTbkQiB+AgVCmfAzBGwQv2Ev0dgsqiI=; b=QYFSlPtsrIPAjYyK7fw4uIpdx7iR7IW/rPIWJJkqP4r8hqAO3h1Ve1FtBiuU6EqrcIgWS5 bX6aj5AtameUZBp+mY9lM8fIAy4ziSmYmmeNOw+6MRcD+wA9POS7psQ8vl/1aqLnEtJCIM 50j3tWH99CyqzpUJY6Tgfx6bcGYEP8c= From: Guopeng Zhang To: Johannes Weiner , Suren Baghdasaryan , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] sched/psi: Fix long-window growth interpolation Date: Fri, 17 Jul 2026 18:28:23 +0800 Message-ID: <20260717102824.985950-2-guopeng.zhang@linux.dev> In-Reply-To: <20260717102824.985950-1-guopeng.zhang@linux.dev> References: <20260717102824.985950-1-guopeng.zhang@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Guopeng Zhang PSI trigger windows are stored in nanoseconds and can be up to 10 seconds, but window_update() stores the remaining interval in a u32. For example, after 2 seconds have elapsed in a 10-second window, the remaining 8,000,000,000 ns is truncated to 3,705,032,704 ns. Making remaining a u64 avoids the truncation, but the multiplication can still overflow before the division. Both win->prev_growth and remaining can be close to 10,000,000,000, so their product can exceed U64_MAX. Store the remaining interval in a u64 and use mul_u64_u64_div_u64() to calculate the interpolation without overflowing the intermediate product. Fixes: 0e94682b73bf ("psi: introduce psi monitor") Signed-off-by: Guopeng Zhang --- kernel/sched/psi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 4e152410653d..8e4df8b17c25 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -137,6 +137,7 @@ * sampling of the aggregate task states would be. */ #include +#include #include #include #include "sched.h" @@ -451,10 +452,11 @@ static u64 window_update(struct psi_window *win, u64 = now, u64 value) if (elapsed > win->size) window_reset(win, now, value, growth); else { - u32 remaining; + u64 remaining; =20 remaining =3D win->size - elapsed; - growth +=3D div64_u64(win->prev_growth * remaining, win->size); + growth +=3D mul_u64_u64_div_u64(win->prev_growth, remaining, + win->size); } =20 return growth; --=20 2.43.0 From nobody Sat Jul 25 05:27:09 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA9B53DDAF4 for ; Fri, 17 Jul 2026 10:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284152; cv=none; b=bt2GXNjbBiYZNcvYeTkimozDeQYln9Km+GEomN7q5113m14rhxPt9sgcePcxeMqgKRcFVJrhqjc1yTYYQiiUXMO7IPWHUvfMhtz0paHHZbgGDGPy0mD5hbQYLLWvnBHIU5pSkcCcXFQqbslFAQV+EokuIGctjcTOZcgRxFAXF0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284152; c=relaxed/simple; bh=FGKF7Tp+2YyAdDi7j29+KnapI7IG3J96b5n1lYq1eUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uVkCNbP9hGlvviaI9EgppES9uX4ADK21BATBcoh7M4fhP+p4kx8L1uxX81B6QHkoj1OR4IgXlsyOTkLtzM8swADBo4GSFv9RaxDEVx2kbDPrIPfQ0mfDCKBvXI2/TiSnF9rD63nDV7DQvTD3Imm2ECS+fk9cNAqPX3i0JllNLjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tADyvHEN; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tADyvHEN" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784284148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CiT+CqZ/hovHaMWUodMAoZMu8KeDegXTjcNAL85j6ps=; b=tADyvHENzoNGcCQKh4ppG0UhyqTftmsDA2WktGOS8M7owIs4e8mLri2NK7oNwWUyk0/dxs bsXhQ0xI3K0kSYFURMYCjb/Tk0QmWKy0Z3n/pjZ/jLXf5jwbuxCv+EDlAGtNi2M9sqdNXR qLRuwMKFwLwLu0LXNiCo9OrJpy5qYBA= From: Guopeng Zhang To: Johannes Weiner , Suren Baghdasaryan , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] sched/psi: Fix overflow in trigger time conversion on 32-bit Date: Fri, 17 Jul 2026 18:28:24 +0800 Message-ID: <20260717102824.985950-3-guopeng.zhang@linux.dev> In-Reply-To: <20260717102824.985950-1-guopeng.zhang@linux.dev> References: <20260717102824.985950-1-guopeng.zhang@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" From: Guopeng Zhang threshold_us and window_us are u32, while NSEC_PER_USEC is 1000L. On 32-bit architectures, multiplication by NSEC_PER_USEC is evaluated using 32-bit unsigned arithmetic and can wrap before the result is assigned to the u64 trigger fields. For a valid 4,000,000 us threshold and 6,000,000 us window, the threshold is stored as 4,000,000,000 ns, while the window wraps to 1,705,032,704 ns. The stored window is therefore shorter than the threshold, so the trigger no longer monitors the requested 4-second threshold over a 6-second window. Cast both values to u64 before the multiplication so that the conversion to nanoseconds is performed using 64-bit arithmetic. Fixes: 0e94682b73bf ("psi: introduce psi monitor") Signed-off-by: Guopeng Zhang --- kernel/sched/psi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 8e4df8b17c25..f0a5976f49dc 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1391,8 +1391,8 @@ struct psi_trigger *psi_trigger_create(struct psi_gro= up *group, char *buf, =20 t->group =3D group; t->state =3D state; - t->threshold =3D threshold_us * NSEC_PER_USEC; - t->win.size =3D window_us * NSEC_PER_USEC; + t->threshold =3D (u64)threshold_us * NSEC_PER_USEC; + t->win.size =3D (u64)window_us * NSEC_PER_USEC; window_reset(&t->win, sched_clock(), group->total[PSI_POLL][t->state], 0); =20 --=20 2.43.0