From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387403; b=ecKfL0bRObshH/A2GF7ZJsNek1hUxV4EwNsoUcAC9xhMetc4tiO6tM8o6QGJ1iGE17pB W7sLNRHdUg46JxYl22ew0SBk5Y/Ud49b2JEFlWQO8QCrIBmZTz8gm9+4+czZ6m5DGUjXD drCz/AaFCVU8wc+rLP/EAT5J59Hloz36g6qBg7dl2KmMLfhIopolv/SdrmP82Me3YE8Ug tv7XRVkyf12FqJjq5is02kd6Ej+VOcGfUUm3fykm6FjS8PXZBbZPAbHYmRsAuBOeaiHfu /fDOcP2g2um11uN/dQymGHnlMIPOt7FKM9+r5qjGdPno51saLNuFYK8OQzhICpL8lnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387403; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=+x/fvvuakyEIT4Mr91msQOcRRUE2ABzwinq+YA8qcZ0=; b=anZJbrqKM3/PUHPHJWKFbs3OBcEpUg4orb2q4eDRAsjocVcFkMqSatowNPFukXZPe27D gah8Ie7KqRLY3nxRvSM+p9AzC2g+jMIG8k2ReWAn1iKWnIgo3sBiCn8DTQm0NnRJ4g2Ga LxrFfWPD4Nb8uRiIomSDlcwj+czLzFdVHb90XcT9qXjT683WeGlQ8Ixe82g1U3QlyoMm3 BtXcPbKRsDv9Punap3VrKwWIbq0Xixl6Nb/XANBQD3ZTz5pTlxEoHHC1ei1/psycLYQ7z Jt75IJKzCxbj0rfYB7hXIwTxJ3YvbpklsE3WZcbVwFhDm6zEIJPXbq2YJahXe7wmYhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="b/cLbNRe"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF99606A322; Fri, 4 Dec 2026 12:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=b/cLbNRe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 532391F000CE; Fri, 4 Dec 2026 12:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387402; bh=+x/fvvuakyEIT4Mr91msQOcRRUE2ABzwinq+YA8qcZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=b/cLbNRex471VmxNU8m9yTYfrQ5Uued09XtPbeo/JTABLyb4TH904SM9cE9PfgyvY OIeYFG+e65Pt3Ja7IWH/vWRahdsUxn0DbNRBJsWDLXvZuXqZAmIRkhLP7WWzqfs8Qv Z/yc/0ek/fLKrzgaqioY25sqzYsEnID9VeQSJc0U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiayuan Chen , Andrew Morton , syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com, Muchun Song , Johannes Weiner , Michal Hocko , Chris Li , Jan Kara , Jens Axboe , Roman Gushchin , Shakeel Butt , Tejun Heo , Sasha Levin Subject: [PATCH 6.1 0227/1059] mm/memcontrol: fix data-race on reading jiffies_64 Date: Fri, 4 Dec 2026 18:55:58 +0900 Message-ID: <20261204100650.155848825@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen [ Upstream commit c20cf1c3c8cdd98618d6fcc794003a0e003ae858 ] KCSAN reported a data-race between tick_do_update_jiffies64() updating jiffies_64 and mem_cgroup_flush_stats_ratelimited() reading it directly. Unlike jiffies, jiffies_64 is not volatile, so raw reads are plain accesses and can even be torn on 32-bit. Use get_jiffies_64() instead, and fix the same pattern in mem_cgroup_flush_foreign(). Link: https://lore.kernel.org/20260827025457.116191-1-jiayuan.chen@linux.dev Fixes: 508bed884767 ("mm: memcg: change flush_next_time to flush_last_time") Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Jiayuan Chen Signed-off-by: Andrew Morton Reported-by: syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com Acked-by: Muchun Song Acked-by: Johannes Weiner Acked-by: Michal Hocko Cc: Chris Li Cc: Jan Kara Cc: Jens Axboe Cc: Roman Gushchin Cc: Shakeel Butt Cc: Tejun Heo Cc: [ sashal: Applied the same get_jiffies_64() conversion to the older flush_next_time code, which has no flush_last_time or READ_ONCE; dropped the cosmetic whitespace change. ] Signed-off-by: Sasha Levin --- mm/memcontrol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4a841e2a4853c..ae060f1772b11 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -631,7 +631,7 @@ static void __mem_cgroup_flush_stats(void) if (!spin_trylock_irqsave(&stats_flush_lock, flag)) return; - flush_next_time = jiffies_64 + 2*FLUSH_TIME; + flush_next_time = get_jiffies_64() + 2*FLUSH_TIME; cgroup_rstat_flush_irqsafe(root_mem_cgroup->css.cgroup); atomic_set(&stats_flush_threshold, 0); spin_unlock_irqrestore(&stats_flush_lock, flag); @@ -645,7 +645,7 @@ void mem_cgroup_flush_stats(void) void mem_cgroup_flush_stats_delayed(void) { - if (time_after64(jiffies_64, flush_next_time)) + if (time_after64(get_jiffies_64(), flush_next_time)) mem_cgroup_flush_stats(); } @@ -4732,7 +4732,7 @@ void mem_cgroup_flush_foreign(struct bdi_writeback *wb) { struct mem_cgroup *memcg = mem_cgroup_from_css(wb->memcg_css); unsigned long intv = msecs_to_jiffies(dirty_expire_interval * 10); - u64 now = jiffies_64; + u64 now = get_jiffies_64(); int i; for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++) { -- 2.53.0