From: Cen Zhang Date: Wed, 6 May 2026 01:07:09 +0000 (+0800) Subject: f2fs: annotate lockless last_time[] accesses X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b952837f734c3a627877bf922408dac04588a643;p=thirdparty%2Flinux.git f2fs: annotate lockless last_time[] accesses f2fs stores mount-wide activity timestamps in sbi->last_time[] and samples them from background discard, GC, and balance paths without a dedicated lock. The timestamps are used as best-effort heuristics to decide whether background work should run now or sleep a bit longer. The current helpers use plain loads and stores, so KCSAN can report races between frequent foreground updates and background readers. Exact freshness is not required here, but the intentional lockless accesses should be marked explicitly. Use WRITE_ONCE() in f2fs_update_time() and READ_ONCE() in f2fs_time_over() and f2fs_time_to_wait(). This preserves the existing heuristic behavior and avoids adding locking to hot paths. Signed-off-by: Cen Zhang Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim --- diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index e555c1d794dfb..6d2048cffa668 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2125,12 +2125,12 @@ static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) { unsigned long now = jiffies; - sbi->last_time[type] = now; + WRITE_ONCE(sbi->last_time[type], now); /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ if (type == REQ_TIME) { - sbi->last_time[DISCARD_TIME] = now; - sbi->last_time[GC_TIME] = now; + WRITE_ONCE(sbi->last_time[DISCARD_TIME], now); + WRITE_ONCE(sbi->last_time[GC_TIME], now); } } @@ -2138,7 +2138,7 @@ static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) { unsigned long interval = sbi->interval_time[type] * HZ; - return time_after(jiffies, sbi->last_time[type] + interval); + return time_after(jiffies, READ_ONCE(sbi->last_time[type]) + interval); } static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, @@ -2148,7 +2148,7 @@ static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, unsigned int wait_ms = 0; long delta; - delta = (sbi->last_time[type] + interval) - jiffies; + delta = (READ_ONCE(sbi->last_time[type]) + interval) - jiffies; if (delta > 0) wait_ms = jiffies_to_msecs(delta);