Improve the loop driver - #1164
Open
blktests-ci[bot] wants to merge 13 commits into
Open
Conversation
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>
Author
|
Upstream branch: a33221f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: Improve the loop driver
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1149306