Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
To: akpm@linux-foundation.org, hughd@google.com
Cc: baolin.wang@linux.alibaba.com, elver@google.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>,
	syzbot+dfb578404df369f6599b@syzkaller.appspotmail.com
Subject: [PATCH] mm/shmem: annotate benign data-race in shmem_getattr()
Date: Wed,  8 Jul 2026 13:19:41 +0200	[thread overview]
Message-ID: <20260708111941.35460-1-jaeyeon.lee.dev@gmail.com> (raw)

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.

Reported-by: syzbot+dfb578404df369f6599b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=dfb578404df369f6599b
Signed-off-by: Jaeyeon Lee <jaeyeon.lee.dev@gmail.com>
---
 mm/shmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 0ea74fa84f25..3fb6dbbfa20b 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -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)
-- 
2.43.0



                 reply	other threads:[~2026-07-08 11:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260708111941.35460-1-jaeyeon.lee.dev@gmail.com \
    --to=jaeyeon.lee.dev@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=elver@google.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=syzbot+dfb578404df369f6599b@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox