Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

loop: move vfs_fsync() out of loop_update_dio()

If vfs_flush() is called with queue frozen, the queue freeze lock may be
connected with FS internal lock, and lockdep warning can be triggered
because the queue freeze lock is connected with too many global or
sub-system locks.

Fix the warning by moving vfs_fsync() out of loop_update_dio():

- vfs_fsync() is only needed when switching to dio

- only loop_change_fd() and loop_configure() may switch from buffered
IO to direct IO, so call vfs_fsync() directly here. This way is safe
because either loop is in unbound, or new file isn't attached

- for the other two cases of set_status and set_block_size, direct IO
can only become off, so no need to call vfs_fsync()

Cc: Christoph Hellwig <hch@infradead.org>
Reported-by: Kun Hu <huk23@m.fudan.edu.cn>
Reported-by: Jiaji Qin <jjtan24@m.fudan.edu.cn>
Closes: https://lore.kernel.org/linux-block/359BC288-B0B1-4815-9F01-3A349B12E816@m.fudan.edu.cn/T/#u
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250318072955.3893805-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Ming Lei and committed by
Jens Axboe
86947bdc ffa1e7ad

+14 -6
+14 -6
drivers/block/loop.c
··· 189 189 */ 190 190 static inline void loop_update_dio(struct loop_device *lo) 191 191 { 192 - bool dio_in_use = lo->lo_flags & LO_FLAGS_DIRECT_IO; 193 - 194 192 lockdep_assert_held(&lo->lo_mutex); 195 193 WARN_ON_ONCE(lo->lo_state == Lo_bound && 196 194 lo->lo_queue->mq_freeze_depth == 0); 197 195 198 196 if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !lo_can_use_dio(lo)) 199 197 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; 200 - 201 - /* flush dirty pages before starting to issue direct I/O */ 202 - if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !dio_in_use) 203 - vfs_fsync(lo->lo_backing_file, 0); 204 198 } 205 199 206 200 /** ··· 630 636 /* size of the new backing store needs to be the same */ 631 637 if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) 632 638 goto out_err; 639 + 640 + /* 641 + * We might switch to direct I/O mode for the loop device, write back 642 + * all dirty data the page cache now that so that the individual I/O 643 + * operations don't have to do that. 644 + */ 645 + vfs_fsync(file, 0); 633 646 634 647 /* and ... switch */ 635 648 disk_force_media_change(lo->lo_disk); ··· 1105 1104 error = queue_limits_commit_update(lo->lo_queue, &lim); 1106 1105 if (error) 1107 1106 goto out_unlock; 1107 + 1108 + /* 1109 + * We might switch to direct I/O mode for the loop device, write back 1110 + * all dirty data the page cache now that so that the individual I/O 1111 + * operations don't have to do that. 1112 + */ 1113 + vfs_fsync(file, 0); 1108 1114 1109 1115 loop_update_dio(lo); 1110 1116 loop_sysfs_init(lo);