From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 28DE02C0285 for ; Mon, 18 May 2026 15:12:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117148; cv=none; b=JSVVF1GZolNofKy6yWVkeoCKT4bGTi/9oLg7Di0GXAiD7dLohvEq+SLfdtUAIizg3/32uXJ7eNu/hvFz6u4t2as+6nyOuEbKPfx7tuEIcYgCk7R4ksZKf2CR46VVZ/fJHad1S/ic0WIM8xxZsHtr/NTFZlj5GSEE2GEwc/nzFvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779117148; c=relaxed/simple; bh=axXtkIsmUfHg+1AnLkN6p4lq0HTsdOoCZBIHPxjBM6A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UbarOJQL/7wJ3zzoZXrQSwqVYbMZ5NjrZT0/BR1yeA9B6fgVtDmvLSVo/dnLYpOpiuWV7I9qvLEKnM4O6ChYuaNI0GNhzkR0X+ZzJiMmATaDdemCi6bogj9BbEpnkCFkzZ2IvFfIxdgn9VdeAUB6PeYfIh/7xTwufxP84Wlp278= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=PLP/XCAX; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PLP/XCAX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=OwzG+tQjsk4EAtydZJcKTkv74id/QRvCLoKmIK+d/pQ=; b=PLP/XCAXbJdt9Fo9UZA1AsIeV5 a+6e1FPrykJksU9uZD1SZarpSlh3qpMwrYD2juaUdWrtK2wM04hnbCsnSVPSeC0wOqpAdpPG6yPHI nUUzMsNOqpbu+tEKjOjGlTmXZlPSIm98IvwVGYE2f+Ko8P5i/fsC6rSJHqph2UorKiJoGusrpEaRQ A9yJD38Ge1MsX7xyQKvEE5NFH/7m/j0c0D1EdXASPwbMC9kO3HDjf9aC8Zmw0PJo67hJEhMHHX4Vg b8uDuV+KqnXl99wGSzSVFDSMwbeO2aGH4gmNcmY5L2K4f+6+TQWEbW3WVTEXYxweT65J3ekzhS8wz eCPpPrRg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOzdC-00000004tHs-1mmU; Mon, 18 May 2026 15:11:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id ED9D4300CDE; Mon, 18 May 2026 17:11:45 +0200 (CEST) Date: Mon, 18 May 2026 17:11:45 +0200 From: Peter Zijlstra To: Tim Chen Cc: Ingo Molnar , K Prateek Nayak , Vincent Guittot , Chen Yu , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , Luo Gengkun , linux-kernel@vger.kernel.org Subject: Re: [Patch v4 15/16] sched/cache: Fix possible overflow when invalidating the preferred CPU Message-ID: <20260518151145.GX3102624@noisy.programming.kicks-ass.net> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, May 13, 2026 at 01:39:26PM -0700, Tim Chen wrote: > From: Chen Yu > > epoch comes from the local rq->cpu_epoch, but mm->sc_stat.epoch is written > by task_tick_cache() running on any CPU - potentially a different CPU whose > rq->cpu_epoch is further ahead. The unsigned underflow wraps to a huge number, > so the condition fires incorrectly. > > Fix this by converting the result to long. > > Fixes: df0d98475954 ("sched/cache: Introduce infrastructure for cache-aware load balancing") > Signed-off-by: Chen Yu > Co-developed-by: Tim Chen > Signed-off-by: Tim Chen > --- > kernel/sched/fair.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 8617cd3642c7..7e64cd18727e 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -1688,7 +1688,7 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) > * If this process hasn't hit task_cache_work() for a while invalidate > * its preferred state. > */ > - if (epoch - READ_ONCE(mm->sc_stat.epoch) > llc_epoch_affinity_timeout || > + if ((long)(epoch - READ_ONCE(mm->sc_stat.epoch)) > (long)llc_epoch_affinity_timeout || I think your fixes is wrong; afaict this was broken by patch 6, before that llc_epoch_affinity_timeout was EPOCH_LLC_AFFINITY_TIMEOUT, which is a literal 5, and thus a signed type. Anyway, a single (long) cast should be sufficient, the other side will get promoted along IIRC.