ublk: improve getting & putting ublk device
authorMing Lei <ming.lei@redhat.com>
Fri, 23 Feb 2024 07:55:38 +0000 (15:55 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 29 Feb 2024 01:47:08 +0000 (18:47 -0700)
Firstly convert get_device() and put_device() into ublk_get_device()
and ublk_put_device().

Secondly annotate ublk_get_device() & ublk_put_device() as noinline
for trace, especially it is often to trigger device deletion hang
when incorrect order is used on ublkc mmap, ublkc close,
io_uring_sqe_unregister_file, ublkb close.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20240223075539.89945-2-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 01afe90a47ac46e2131a5bb1e895aa75c81ed493..06d88d2008ba533750c4aa496e6c9b69b7ff7e29 100644 (file)
@@ -605,14 +605,16 @@ static inline bool ublk_need_get_data(const struct ublk_queue *ubq)
        return ubq->flags & UBLK_F_NEED_GET_DATA;
 }
 
-static struct ublk_device *ublk_get_device(struct ublk_device *ub)
+/* Called in slow path only, keep it noinline for trace purpose */
+static noinline struct ublk_device *ublk_get_device(struct ublk_device *ub)
 {
        if (kobject_get_unless_zero(&ub->cdev_dev.kobj))
                return ub;
        return NULL;
 }
 
-static void ublk_put_device(struct ublk_device *ub)
+/* Called in slow path only, keep it noinline for trace purpose */
+static noinline void ublk_put_device(struct ublk_device *ub)
 {
        put_device(&ub->cdev_dev);
 }
@@ -671,7 +673,7 @@ static void ublk_free_disk(struct gendisk *disk)
        struct ublk_device *ub = disk->private_data;
 
        clear_bit(UB_STATE_USED, &ub->state);
-       put_device(&ub->cdev_dev);
+       ublk_put_device(ub);
 }
 
 static void ublk_store_owner_uid_gid(unsigned int *owner_uid,
@@ -2142,7 +2144,7 @@ static void ublk_remove(struct ublk_device *ub)
        cancel_work_sync(&ub->stop_work);
        cancel_work_sync(&ub->quiesce_work);
        cdev_device_del(&ub->cdev, &ub->cdev_dev);
-       put_device(&ub->cdev_dev);
+       ublk_put_device(ub);
        ublks_added--;
 }
 
@@ -2235,7 +2237,7 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd)
        if (ub->nr_privileged_daemon != ub->nr_queues_ready)
                set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
 
-       get_device(&ub->cdev_dev);
+       ublk_get_device(ub);
        ub->dev_info.state = UBLK_S_DEV_LIVE;
 
        if (ublk_dev_is_zoned(ub)) {