On 2021/08/17 17:10, Hillf Danton wrote: > See if it is safe to kfree(lo) after removing it from idr, with the > deadlock dissolved. It is not safe to call loop_remove() after idr_remove(). Please see HIDDEN_LOOP_DEVICE magic in "[PATCH] loop: break loop_ctl_mutex into loop_idr_spinlock and loop_removal_mutex". > > --- x/drivers/block/loop.c > +++ y/drivers/block/loop.c > @@ -2459,7 +2459,9 @@ static int loop_control_remove(int idx) > mutex_unlock(&lo->lo_mutex); > > idr_remove(&loop_index_idr, lo->lo_number); > + mutex_unlock(&loop_ctl_mutex); > loop_remove(lo); > + return 0; > out_unlock_ctrl: > mutex_unlock(&loop_ctl_mutex); > return ret; > -- > "[PATCH] loop: break loop_ctl_mutex into loop_idr_spinlock and loop_removal_mutex" can be a further improvement after "[PATCH v3] block: genhd: don't call probe function with major_names_lock held". I really would like to apply "[PATCH v3] block: genhd: don't call probe function with major_names_lock held" first.