On Thu, Jul 22, 2021 at 04:19:42PM +0800, Ming Lei wrote: > > goto bdput; > > - if ((disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP) > > + if (disk->flags & GENHD_FL_HIDDEN) > > But del_gendisk() can be called just between bdget() and checking GENHD_FL_UP. > > And not see difference by moving remove_inode_hash() with disk open_mutex held. The difference is not about having the open_mutex held, but about doing it earlier. The only check that matters is the GENHD_FL_UP check in blkdev_get_by_dev. The earlier check just reduces the amount of work we're doing for a disk already being delete. With the early unhash there is no need for that check as we won't even find the inode for a disk in del_gendisk. We still need the non-racy check under the lock, but the patch doesn't touch that one. Maybe I need to split this into two patches and improve the commit log.