Skip to content

Improve the loop driver - #1164

Open
blktests-ci[bot] wants to merge 13 commits into
for-next_basefrom
series/1149306=>for-next
Open

Improve the loop driver#1164
blktests-ci[bot] wants to merge 13 commits into
for-next_basefrom
series/1149306=>for-next

Conversation

@blktests-ci

@blktests-ci blktests-ci Bot commented Aug 20, 2026

Copy link
Copy Markdown

Pull request for series with
subject: Improve the loop driver
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1149306

The purpose of loop_validate_file() is to prevent that the file descriptor
of an already bound loop device is changed into a file descriptor
associated with a file that depends on the loop device. This must be
prevented because otherwise infinite I/O loops could be triggered and
filesystems involved in this loop would become impossible to unmount.

Fix loop_validate_file() by comparing gendisk pointers instead of dev_t
values.

Cc: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Fixes: d2ac838 ("loop: add recursion validation to LOOP_CHANGE_FD")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Checking inode attributes after a loop that modifies the file pointer
the inode has been derived from confuses some static analyzers. Hence
swap the loop and the inode attribute check.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Let the compiler verify __must_hold(), __guarded_by() etc. Suppress the
warnings reported for loop_global_{,un}_lock*() by adding a
__context_unsafe() annotation. Both __context_unsafe() annotations will be
removed by a later patch.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Prepare for nesting lo_mutex in loop_validate_file().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Annotate all functions that are called with lo_mutex held with
__must_hold(&lo->lo_mutex). Add a 'lo' argument to loop_validate_file()
such that a __must_hold(&lo->lo_mutex) annotation can be added to this
function too.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Protect all lo_backing_file accesses from the control path with
lo->lo_mutex. Use READ_ONCE() to read lo_backing_file from the data path.
Serialization of I/O path lo_backing_file reads and control path
lo_backing_file changes happens by freezing the request queue.

Remove lo_lock because it is no longer used.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Fix race conditions in loop_validate_file() by adding reference counting
to the file chain traversal.

Ensure the file reference is kept alive during all dereferences by
calling get_file() before the loop and deferring fput() until after we
have locked the target device's lo_mutex and confirmed it is in the
Lo_bound state.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Now that all lo_state and lo_backing_file accesses from the control path
are serialized by lo_mutex, it is no longer necessary to use memory
barriers to order the lo_state and lo_backing_file accesses. Hence,
remove these memory barriers. While several lockless accesses of these
two member variables remain in the I/O path, these are serialized with
backing file changes by freezing the request queue. See also
loop_change_fd().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Prepare for adding a second call of __loop_change_fd().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Prepare for adding a second __loop_configure() call.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Keep the behavior in loop_global_lock_killable() for the global == true
case. Expand loop_global_lock_killable(lo, false) calls into a
mutex_lock_killable() and a mutex_unlock() call.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Prepare for annotating the rootcg_cmd_list member with __guarded_by().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Document which synchronization object protects which variable. Suppress
complaints about accesses without locking in initialization and cleanup
functions with context_unsafe() and __assume_ctx_lock().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
@blktests-ci

blktests-ci Bot commented Aug 20, 2026

Copy link
Copy Markdown
Author

Upstream branch: a33221f
series: https://patchwork.kernel.org/project/linux-block/list/?series=1149306
version: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant