Skip to content

Commit 1221b9e

Browse files
Ming Leiaxboe
authored andcommitted
ublk: improve getting & putting ublk device
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ec30b46 commit 1221b9e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/block/ublk_drv.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,16 @@ static inline bool ublk_need_get_data(const struct ublk_queue *ubq)
605605
return ubq->flags & UBLK_F_NEED_GET_DATA;
606606
}
607607

608-
static struct ublk_device *ublk_get_device(struct ublk_device *ub)
608+
/* Called in slow path only, keep it noinline for trace purpose */
609+
static noinline struct ublk_device *ublk_get_device(struct ublk_device *ub)
609610
{
610611
if (kobject_get_unless_zero(&ub->cdev_dev.kobj))
611612
return ub;
612613
return NULL;
613614
}
614615

615-
static void ublk_put_device(struct ublk_device *ub)
616+
/* Called in slow path only, keep it noinline for trace purpose */
617+
static noinline void ublk_put_device(struct ublk_device *ub)
616618
{
617619
put_device(&ub->cdev_dev);
618620
}
@@ -671,7 +673,7 @@ static void ublk_free_disk(struct gendisk *disk)
671673
struct ublk_device *ub = disk->private_data;
672674

673675
clear_bit(UB_STATE_USED, &ub->state);
674-
put_device(&ub->cdev_dev);
676+
ublk_put_device(ub);
675677
}
676678

677679
static void ublk_store_owner_uid_gid(unsigned int *owner_uid,
@@ -2142,7 +2144,7 @@ static void ublk_remove(struct ublk_device *ub)
21422144
cancel_work_sync(&ub->stop_work);
21432145
cancel_work_sync(&ub->quiesce_work);
21442146
cdev_device_del(&ub->cdev, &ub->cdev_dev);
2145-
put_device(&ub->cdev_dev);
2147+
ublk_put_device(ub);
21462148
ublks_added--;
21472149
}
21482150

@@ -2235,7 +2237,7 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd)
22352237
if (ub->nr_privileged_daemon != ub->nr_queues_ready)
22362238
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
22372239

2238-
get_device(&ub->cdev_dev);
2240+
ublk_get_device(ub);
22392241
ub->dev_info.state = UBLK_S_DEV_LIVE;
22402242

22412243
if (ublk_dev_is_zoned(ub)) {

0 commit comments

Comments
 (0)