[PATCH] fs: annotate data race in get_nr_inodes()
From: Mani Tofigh via B4 Relay
Date: Tue Oct 27 2026 - 16:09:09 EST
From: Mani Tofigh <mt4022@xxxxxxxxxxxx>
get_nr_inodes() sums the per-CPU inode counts without a lock, and the
result is only an estimate, so it's harmless if one of them changes
during the sum. Wrap the reads in data_race() to mark this.
[ 11.857490] BUG: KCSAN: data-race in get_nr_inodes+0x9f/0xf0
[ 11.857568] race at unknown origin, with read to 0xff1100002b6281e8 of 8 bytes by task 106 on cpu 1:
[ 11.857621] get_nr_inodes+0x9f/0xf0
[ 11.857675] get_nr_dirty_inodes+0x1d/0x110
[ 11.857748] writeback_inodes_sb+0x3d/0x60
...
[ 11.870052] value changed: 0x00000000000000b3 -> 0x00000000000000b5
Found with KCSAN while fuzzing under a deterministic hypervisor that's
currently under development.
Signed-off-by: Mani Tofigh <mt4022@xxxxxxxxxxxx>
---
fs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/inode.c b/fs/inode.c
index 1cb6293b237a..ee4366264c36 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -79,7 +79,7 @@ static long get_nr_inodes(void)
int i;
long sum = 0;
for_each_possible_cpu(i)
- sum += per_cpu(nr_inodes, i);
+ sum += data_race(per_cpu(nr_inodes, i));
return sum < 0 ? 0 : sum;
}
---
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
change-id: 20261027-kcsan-inode-ad562064d53f
Best regards,
--
Mani Tofigh <mt4022@xxxxxxxxxxxx>