[PATCH v1 5/9] ext2: mark s_mount_state as guarded by s_lock
From: Timothy Day
Date: Sun Jul 12 2026 - 12:58:18 EST
s_mount_state tracks the filesystem's mount/error state and is protected
by s_lock everywhere it is accessed. Annotate it with __guarded_by() for
Clang's context analysis.
ext2_setup_super() reads s_mount_state and is called with s_lock held
from the remount path, so annotate it with __must_hold().
There are two accesses (the initial read in ext2_fill_super() and the
setup_super() call) in the mount flow. This is before the superblock
is live, so no concurrent access should be possible. Since the s_lock
isn't being taken in this case, wrap them in context_unsafe().
Signed-off-by: Timothy Day <timday@xxxxxxxxxxxxxxxxxxxxxxx>
---
fs/ext2/ext2.h | 2 +-
fs/ext2/super.c | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index ecca898653eb8..4c30d6f5c9726 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -86,7 +86,7 @@ struct ext2_sb_info {
unsigned long s_sb_block;
kuid_t s_resuid;
kgid_t s_resgid;
- unsigned short s_mount_state;
+ unsigned short s_mount_state __guarded_by(&s_lock);
unsigned short s_pad;
int s_addr_per_block_bits;
int s_desc_per_block_bits;
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index f742b9b6b017a..a5a5285dd5784 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -633,6 +633,7 @@ static int ext2_parse_param(struct fs_context *fc, struct fs_parameter *param)
static int ext2_setup_super (struct super_block * sb,
struct ext2_super_block * es,
int read_only)
+ __must_hold(&EXT2_SB(sb)->s_lock)
{
int res = 0;
struct ext2_sb_info *sbi = EXT2_SB(sb);
@@ -1035,7 +1036,8 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
sbi->s_desc_per_block = sb->s_blocksize /
sizeof (struct ext2_group_desc);
sbi->s_sbh = bh;
- sbi->s_mount_state = le16_to_cpu(es->s_state);
+ /* concurrent access is not possible before the mount completes */
+ context_unsafe(sbi->s_mount_state = le16_to_cpu(es->s_state));
sbi->s_addr_per_block_bits =
ilog2 (EXT2_ADDR_PER_BLOCK(sb));
sbi->s_desc_per_block_bits =
@@ -1203,7 +1205,8 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
ext2_msg(sb, KERN_WARNING,
"warning: mounting ext3 filesystem as ext2");
- if (ext2_setup_super (sb, es, sb_rdonly(sb)))
+ /* concurrent access is not possible before the mount completes */
+ if (context_unsafe(ext2_setup_super(sb, es, sb_rdonly(sb))))
sb->s_flags |= SB_RDONLY;
ext2_write_super(sb);
return 0;
--
2.39.5