From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit X-Migadu-Flow: FLOW_OUT 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_group *group, char *buf, t->group = group; t->state = state; - t->threshold = threshold_us * NSEC_PER_USEC; - t->win.size = window_us * NSEC_PER_USEC; + t->threshold = (u64)threshold_us * NSEC_PER_USEC; + t->win.size = (u64)window_us * NSEC_PER_USEC; window_reset(&t->win, sched_clock(), group->total[PSI_POLL][t->state], 0); -- 2.43.0