Re: [PATCH v2 08/17] loop: take freeze protection for discard and write zeroes

From: Jan Kara

Date: Mon Nov 16 2026 - 08:14:18 EST


On Mon 16-11-26 12:03:48, Christian Brauner wrote:
> Discard and write zeroes requests end up in lo_fallocate() which calls
> ->fallocate() of the backing file directly. That skips the freeze
> protection vfs_fallocate() would have taken. So they go straight
> through to a filesystem that is frozen. With the backing file on ext4:
>
> WARNING: fs/ext4/ext4_jbd2.c:90 at ext4_journal_check_start+0x1f6/0x2d0, CPU#3: kworker/u16:1/44
> Workqueue: loop1 loop_rootcg_workfn
> Call Trace:
> <TASK>
> __ext4_journal_start_sb+0x7a/0x470
> ext4_dirty_inode+0xa1/0x120
> __mark_inode_dirty+0x154/0x1110
> file_update_time_flags+0x3ab/0x4b0
> ext4_fallocate+0x286/0x3440
> lo_fallocate+0x13e/0x290
> loop_process_work+0x486/0xe70
> process_one_work+0x946/0x1820
> worker_thread+0x4f1/0xd60
> kthread+0x364/0x460
> ret_from_fork+0x525/0x770
> ret_from_fork_asm+0x1a/0x30
> </TASK>
>
> Take freeze protection around ->fallocate() like vfs_fallocate() does.
>
> Fixes: dfaa2ef68e80 ("loop: add discard support for loop devices")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza

> ---
> drivers/block/loop.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index a3325ceab484a..d2f29aadabcc1 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -259,7 +259,8 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
> if (!bdev_max_discard_sectors(lo->lo_device))
> return -EOPNOTSUPP;
>
> - ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq));
> + scoped_guard(file_write, file)
> + ret = file->f_op->fallocate(file, mode, pos, blk_rq_bytes(rq));
> if (unlikely(ret && ret != -EINVAL && ret != -EOPNOTSUPP))
> return -EIO;
>
>
> --
> 2.53.0
>
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR