Skip to content

Commit 949f95f

Browse files
jankaratytso
authored andcommitted
ext4: fix lockdep warning when enabling MMP
When we enable MMP in ext4_multi_mount_protect() during mount or remount, we end up calling sb_start_write() from write_mmp_block(). This triggers lockdep warning because freeze protection ranks above s_umount semaphore we are holding during mount / remount. The problem is harmless because we are guaranteed the filesystem is not frozen during mount / remount but still let's fix the warning by not grabbing freeze protection from ext4_multi_mount_protect(). Cc: [email protected] Reported-by: [email protected] Link: https://syzkaller.appspot.com/bug?id=ab7e5b6f400b7778d46f01841422e5718fb81843 Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent fa08a7b commit 949f95f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

fs/ext4/mmp.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,36 @@ static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp)
3939
* Write the MMP block using REQ_SYNC to try to get the block on-disk
4040
* faster.
4141
*/
42-
static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
42+
static int write_mmp_block_thawed(struct super_block *sb,
43+
struct buffer_head *bh)
4344
{
4445
struct mmp_struct *mmp = (struct mmp_struct *)(bh->b_data);
4546

46-
/*
47-
* We protect against freezing so that we don't create dirty buffers
48-
* on frozen filesystem.
49-
*/
50-
sb_start_write(sb);
5147
ext4_mmp_csum_set(sb, mmp);
5248
lock_buffer(bh);
5349
bh->b_end_io = end_buffer_write_sync;
5450
get_bh(bh);
5551
submit_bh(REQ_OP_WRITE | REQ_SYNC | REQ_META | REQ_PRIO, bh);
5652
wait_on_buffer(bh);
57-
sb_end_write(sb);
5853
if (unlikely(!buffer_uptodate(bh)))
5954
return -EIO;
60-
6155
return 0;
6256
}
6357

58+
static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
59+
{
60+
int err;
61+
62+
/*
63+
* We protect against freezing so that we don't create dirty buffers
64+
* on frozen filesystem.
65+
*/
66+
sb_start_write(sb);
67+
err = write_mmp_block_thawed(sb, bh);
68+
sb_end_write(sb);
69+
return err;
70+
}
71+
6472
/*
6573
* Read the MMP block. It _must_ be read from disk and hence we clear the
6674
* uptodate flag on the buffer.
@@ -344,7 +352,11 @@ int ext4_multi_mount_protect(struct super_block *sb,
344352
seq = mmp_new_seq();
345353
mmp->mmp_seq = cpu_to_le32(seq);
346354

347-
retval = write_mmp_block(sb, bh);
355+
/*
356+
* On mount / remount we are protected against fs freezing (by s_umount
357+
* semaphore) and grabbing freeze protection upsets lockdep
358+
*/
359+
retval = write_mmp_block_thawed(sb, bh);
348360
if (retval)
349361
goto failed;
350362

0 commit comments

Comments
 (0)