Skip to contentSkip to conversation

mm/shmem: annotate benign data-race in shmem_getattr()

PATCH Applied Jaeyeon Lee 1 participant 1 message Jul 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/shmem: annotate benign data-race in shmem_getattr()

shmem_getattr() reads info->alloced, info->swapped and i_mapping->nrpages without info->lock to decide whether shmem_recalc_inode() should be called. shmem_recalc_inode() recomputes these under info->lock, so a stale read here only affects whether shmem_recalc_inode() runs.

Annotate data_race() to silence KCSAN.

---
 mm/shmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/shmem.c +2 -1
index 0ea74fa84f25..3fb6dbbfa20b 100644
@@ -1287,7 +1287,8 @@ static int shmem_getattr(struct mnt_idmap *idmap,
 	struct inode *inode = path->dentry->d_inode;
 	struct shmem_inode_info *info = SHMEM_I(inode);
 
-	if (info->alloced - info->swapped != inode->i_mapping->nrpages)
+	/* Fast-path hint; recalc under info->lock corrects any stale read. */
+	if (data_race(info->alloced - info->swapped != inode->i_mapping->nrpages))
 		shmem_recalc_inode(inode, 0, 0);
 
 	if (info->fsflags & FS_APPEND_FL)
Signature · 1 line
2.43.0