mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Jan Kara <jack@suse.com>
Cc: Marco Elver <elver@google.com>,
	 Timothy Day <timday@thelustrecollective.com>,
	linux-ext4@vger.kernel.org,  linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev,  Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] ext2: Make sbi an proper alias for EXT2_SB(sb) in ext2_fill_super()
Date: Fri, 23 Oct 2026 13:53:03 -0700	[thread overview]
Message-ID: <20261023-ext2-fix-context-analysis-clang-24-v1-1-2b35c33cd0fa@kernel.org> (raw)

A recent LLVM change to fix parsing and validating __guarded_by on
structure members [1] reveals a couple of warnings in ext2_fill_super()
from the annotations added by commit 023051c2d0f1 ("ext2: mark
s_mount_state as guarded by s_lock") and commit c23746524faf ("ext2:
annotate s_rsv_window_root as requiring s_rsv_window_lock"):

  fs/ext2/super.c:1040:7: error: writing variable 's_mount_state' requires holding spinlock '_res->s_lock' exclusively [-Werror,-Wthread-safety-precise]
   1040 |         sbi->s_mount_state = le16_to_cpu(es->s_state);
        |              ^
  fs/ext2/super.c:1040:7: note: found near match 'EXT2_SB(sb).s_lock'
  fs/ext2/super.c:1138:8: error: writing variable 's_rsv_window_root' requires holding spinlock '_res->s_rsv_window_lock' exclusively [-Werror,-Wthread-safety-precise]
   1138 |                 sbi->s_rsv_window_root = RB_ROOT;
        |                      ^
  fs/ext2/super.c:1138:8: note: found near match 'EXT2_SB(sb).s_rsv_window_lock'

Context analysis does very minimal alias detection [2], so it is not
able to figure out that sbi == sb->s_fs_info == EXT2_SB(sb). The only
reason there were no warnings before the above LLVM change is because
the annotation was not parsed and verified correctly.

Rework the allocation and assignment of sbi to have a direct assignment
of EXT2_SB(sb) to sbi so that the analysis knows that sbi and
EXT2_SB(sb) refer to the same object, clearing up the warnings.

Fixes: 9708538ba204 ("ext2: enable context analysis support for ext2 filesystem")
Link: https://github.com/llvm/llvm-project/commit/217e229a1f32785fccdd3b3f51429f0d309dea45 [1]
Link: https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#no-alias-analysis [2]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 fs/ext2/super.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index fb217ef2d69f..b55f9ce3267f 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -883,17 +883,18 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
 	__le32 features;
 	int err;
 
-	sbi = kzalloc_obj(*sbi);
-	if (!sbi)
+	sb->s_fs_info = kzalloc_obj(*sb->s_fs_info);
+	if (!sb->s_fs_info)
 		return -ENOMEM;
+	sbi = EXT2_SB(sb);
 
 	sbi->s_blockgroup_lock =
 		kzalloc_obj(struct blockgroup_lock);
 	if (!sbi->s_blockgroup_lock) {
-		kfree(sbi);
+		kfree(sb->s_fs_info);
+		sb->s_fs_info = NULL;
 		return -ENOMEM;
 	}
-	sb->s_fs_info = sbi;
 	sbi->s_sb_block = sb_block;
 
 	guard(spinlock_init)(&EXT2_SB(sb)->s_lock);

---
base-commit: 782654a3e9c4065dea2e9f10539899d348b7a1fc
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
change-id: 20261023-ext2-fix-context-analysis-clang-24-504b5dd53038

Best regards,
--  
Cheers,
Nathan


             reply	other threads:[~2026-10-23 20:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 20:53 Nathan Chancellor [this message]
2026-10-24 17:18 ` [syzbot ci] " syzbot ci

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=20261023-ext2-fix-context-analysis-clang-24-v1-1-2b35c33cd0fa@kernel.org \
    --to=nathan@kernel.org \
    --cc=elver@google.com \
    --cc=jack@suse.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=timday@thelustrecollective.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

all inboxes | Powered by JetHome®