On 2022/01/27 19:28, Jan Kara wrote: > So this also relies on disk->open_mutex for correctness. Otherwise a race > like: > > Thread1 Thread2 > lo_open() > if (atomic_inc_return(&lo->lo_refcnt) > 1) > mutex_lock_killable(&lo->lo_mutex); > lo_open() > if (atomic_inc_return(&lo->lo_refcnt) > 1) > return 0; > .. > > can result in Thread2 using the loop device before Thread1 actually did the > "first open" checks. So perhaps one common comment for lo_open + lo_release > explaining the locking? Please see https://lkml.kernel.org/r/7bebf860-2415-7eb6-55a1-47dc4439d9e9@xxxxxxxxxxxxxxxxxxx .