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.
Unified · Split
| @@ -1297,7 +1297,8 @@ static int shmem_getattr(struct mnt_idmap *idmap, · 1296 unmodified lines | ||
| 1297 | 1297 | struct inode *inode = path->dentry->d_inode; |
| 1298 | 1298 | struct shmem_inode_info *info = SHMEM_I(inode); |
| 1299 | 1299 | |
| 1300 | − if (info->alloced - info->swapped != inode->i_mapping->nrpages) | |
| 1300 | + /* Fast-path hint; recalc under info->lock corrects any stale read. */ | |
| 1301 | + if (data_race(info->alloced - info->swapped != inode->i_mapping->nrpages)) | |
| 1301 | 1302 | shmem_recalc_inode(inode, 0, 0); |
| 1302 | 1303 | |
| 1303 | 1304 | if (info->fsflags & FS_APPEND_FL) |