* [PATCH] mm/memcontrol: fix data-race on reading jiffies_64
@ 2026-08-27 2:54 Jiayuan Chen
2026-08-27 3:08 ` Muchun Song
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jiayuan Chen @ 2026-08-27 2:54 UTC (permalink / raw)
To: linux-mm
Cc: Jiayuan Chen, stable, syzbot+ced4d9a8cadb5ef3adae,
Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
Muchun Song, Andrew Morton, Yosry Ahmed, Chris Li, Jens Axboe,
Jan Kara, Tejun Heo, cgroups, linux-kernel
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().
Cc: <stable@vger.kernel.org>
Fixes: 508bed884767 ("mm: memcg: change flush_next_time to flush_last_time")
Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing")
Reported-by: syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
feel free to drop Fixes tag.
---
mm/memcontrol.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 11b85f4b6828..5a3fe057debc 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -757,7 +757,7 @@ static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force)
return;
if (mem_cgroup_is_root(memcg))
- WRITE_ONCE(flush_last_time, jiffies_64);
+ WRITE_ONCE(flush_last_time, get_jiffies_64());
css_rstat_flush(&memcg->css);
}
@@ -785,7 +785,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
{
/* Only flush if the periodic flusher is one full cycle late */
- if (time_after64(jiffies_64, READ_ONCE(flush_last_time) + 2*FLUSH_TIME))
+ if (time_after64(get_jiffies_64(), READ_ONCE(flush_last_time) + 2 * FLUSH_TIME))
mem_cgroup_flush_stats(memcg);
}
@@ -3945,7 +3945,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.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/memcontrol: fix data-race on reading jiffies_64
2026-08-27 2:54 [PATCH] mm/memcontrol: fix data-race on reading jiffies_64 Jiayuan Chen
@ 2026-08-27 3:08 ` Muchun Song
2026-08-27 14:16 ` Michal Hocko
2026-08-27 14:59 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Muchun Song @ 2026-08-27 3:08 UTC (permalink / raw)
To: Jiayuan Chen
Cc: linux-mm, stable, syzbot+ced4d9a8cadb5ef3adae, Johannes Weiner,
Michal Hocko, Roman Gushchin, Shakeel Butt, Andrew Morton,
Yosry Ahmed, Chris Li, Jens Axboe, Jan Kara, Tejun Heo, cgroups,
linux-kernel
> On Aug 27, 2026, at 10:54, Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
>
> 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().
>
> Cc: <stable@vger.kernel.org>
> Fixes: 508bed884767 ("mm: memcg: change flush_next_time to flush_last_time")
> Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing")
> Reported-by: syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Acked-by: Muchun Song <muchun.song@linux.dev>
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/memcontrol: fix data-race on reading jiffies_64
2026-08-27 2:54 [PATCH] mm/memcontrol: fix data-race on reading jiffies_64 Jiayuan Chen
2026-08-27 3:08 ` Muchun Song
@ 2026-08-27 14:16 ` Michal Hocko
2026-08-27 14:59 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2026-08-27 14:16 UTC (permalink / raw)
To: Jiayuan Chen
Cc: linux-mm, stable, syzbot+ced4d9a8cadb5ef3adae, Johannes Weiner,
Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton,
Yosry Ahmed, Chris Li, Jens Axboe, Jan Kara, Tejun Heo, cgroups,
linux-kernel
On Thu 27-08-26 10:54:56, Jiayuan Chen wrote:
> 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().
Yes, this looks more correct. I do not expect this to have any
practically visible effects, right?
> Cc: <stable@vger.kernel.org>
> Fixes: 508bed884767 ("mm: memcg: change flush_next_time to flush_last_time")
> Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing")
> Reported-by: syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> feel free to drop Fixes tag.
> ---
> mm/memcontrol.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 11b85f4b6828..5a3fe057debc 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -757,7 +757,7 @@ static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force)
> return;
>
> if (mem_cgroup_is_root(memcg))
> - WRITE_ONCE(flush_last_time, jiffies_64);
> + WRITE_ONCE(flush_last_time, get_jiffies_64());
>
> css_rstat_flush(&memcg->css);
> }
> @@ -785,7 +785,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
> void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
> {
> /* Only flush if the periodic flusher is one full cycle late */
> - if (time_after64(jiffies_64, READ_ONCE(flush_last_time) + 2*FLUSH_TIME))
> + if (time_after64(get_jiffies_64(), READ_ONCE(flush_last_time) + 2 * FLUSH_TIME))
> mem_cgroup_flush_stats(memcg);
> }
>
> @@ -3945,7 +3945,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.43.0
>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/memcontrol: fix data-race on reading jiffies_64
2026-08-27 2:54 [PATCH] mm/memcontrol: fix data-race on reading jiffies_64 Jiayuan Chen
2026-08-27 3:08 ` Muchun Song
2026-08-27 14:16 ` Michal Hocko
@ 2026-08-27 14:59 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2026-08-27 14:59 UTC (permalink / raw)
To: Jiayuan Chen
Cc: linux-mm, stable, syzbot+ced4d9a8cadb5ef3adae, Michal Hocko,
Roman Gushchin, Shakeel Butt, Muchun Song, Andrew Morton,
Yosry Ahmed, Chris Li, Jens Axboe, Jan Kara, Tejun Heo, cgroups,
linux-kernel
On Thu, Aug 27, 2026 at 10:54:56AM +0800, Jiayuan Chen wrote:
> 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().
>
> Cc: <stable@vger.kernel.org>
> Fixes: 508bed884767 ("mm: memcg: change flush_next_time to flush_last_time")
> Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing")
> Reported-by: syzbot+ced4d9a8cadb5ef3adae@syzkaller.appspotmail.com
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Minor nit:
> @@ -785,7 +785,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg)
> void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg)
> {
> /* Only flush if the periodic flusher is one full cycle late */
> - if (time_after64(jiffies_64, READ_ONCE(flush_last_time) + 2*FLUSH_TIME))
> + if (time_after64(get_jiffies_64(), READ_ONCE(flush_last_time) + 2 * FLUSH_TIME))
> mem_cgroup_flush_stats(memcg);
time_is_after_jiffies64()
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-27 14:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27 2:54 [PATCH] mm/memcontrol: fix data-race on reading jiffies_64 Jiayuan Chen
2026-08-27 3:08 ` Muchun Song
2026-08-27 14:16 ` Michal Hocko
2026-08-27 14:59 ` Johannes Weiner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox