From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 C9077360EED for ; Wed, 13 May 2026 20:33:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778704435; cv=none; b=O5FNa5hCMA6Kwglh7mWRdiVljBWi+1VPZakMOodIz5vPHbFIsKl5OVR4g9NDrBieWfsmu57yunMMni0UDISLI1/T7hdm6jKJdg0/qwByrJiNw6LzkGNmmopP9TgmotsA9oFqLmolcAESMMbWBaFPi9b55TCcvoeeomaZ7zm9+JA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778704435; c=relaxed/simple; bh=t1FwK5H8eA5XceraosnpeVkGplWnliav65lNNIbDDfU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qll82RvDi6W+m6eZBwh+Jw/k+zZZFZx4CHmwexgD9MvflV+bSViGh3Bo2qS+Pto41JI3yGuHJkiHjq2jMYcByxPm0ANWmP8tcbWnnING202ruEeOk0XQFe7qvY8wysDEoC4e8ebmc8P/BXutfVXFGuLhvgUQi9Wuc22EzGbm+p4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=i0LZbcXM; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i0LZbcXM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778704434; x=1810240434; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t1FwK5H8eA5XceraosnpeVkGplWnliav65lNNIbDDfU=; b=i0LZbcXMHI8g/H89E89jOLAe2N5P3uMI7eZV+dXc06+TfeHo+fdjN4i5 GyjEJUr9XC7ZzRRRJc4wfSb8jA6qmm1Ptwx219yDHjs41fTv/8+EwbB4m ewbIsAmWSLEj6iLRDKOaL2PjWILspb//uIeqRoyBSuE1UlB3UmrC12osI Pa0oNGDxzUTe0Q9IqsEvMad/Jl30GxtJmj/vrxmUTVOh4MtvbitY9YulT NSG9kBkbYGHU0usp5mY+U2WoQ9O8xMQk761dI+EYlGe/POnS8UqH2CI53 fcOOUvUvHxKmSEWEClgNKUHe5/BOo4YMoZLhfITMGrBev49mGahVHSIGR w==; X-CSE-ConnectionGUID: nImrx8VQSEyknvWWV0vYhw== X-CSE-MsgGUID: L7hL1qc7SWuUGXZdmoqH6g== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="79623292" X-IronPort-AV: E=Sophos;i="6.23,233,1770624000"; d="scan'208";a="79623292" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 13:33:49 -0700 X-CSE-ConnectionGUID: ww2XjdZVQwGP/xMBgK9hIw== X-CSE-MsgGUID: 7sZq6untS8OBizL5JkqDVg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,233,1770624000"; d="scan'208";a="238076408" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by orviesa008.jf.intel.com with ESMTP; 13 May 2026 13:33:48 -0700 From: Tim Chen To: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , Vincent Guittot Cc: 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 , Tim Chen , 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: [Patch v4 15/16] sched/cache: Fix possible overflow when invalidating the preferred CPU Date: Wed, 13 May 2026 13:39:26 -0700 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 || invalid_llc_nr(mm, p, cpu_of(rq)) || exceed_llc_capacity(mm, cpu_of(rq))) { if (READ_ONCE(mm->sc_stat.cpu) != -1) -- 2.32.0