Currently the code misuse GD_SUPPRESS_PART_SCAN flag as it tries to use it as a switch for the auto partition scan. When UBLK_F_NO_AUTO_PART_SCAN is not passed a proper auto partition scanning is not done because the first call to ublk_partition_scan_work will clear the bit GD_SUPPRESS_PART_SCAN but not actually load the partitions. How it should work: Unprivileged daemons - never scan partitions, they have GD_SUPPRESS_PART_SCAN always set - they are marked as devices without partitions. While ioctl(BLKRRPART) does require CAP_SYS_ADMIN, block layer have its own a check in disk_has_partscan(...) if partitions are supported. Trusted daemons - auto scan partitions by default and they do not have the bit set, so they do have partitions. For trusted daemons auto partitions scan is performed but it can be skipped if user have set UBLK_F_NO_AUTO_PART_SCAN flag. Rework the code to work as described above: - remove checks in ublk_partition_scan_work and rely on the caller to schedule the work only if it has to be done. - keep GD_SUPPRESS_PART_SCAN always set on unprivileged - keep GD_SUPPRESS_PART_SCAN always clear on trusted - Properly handle user request to skip auto partitioning scanning Fixes: 8443e2087e70 ("ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag") Signed-off-by: Alexander Atanasov --- drivers/block/ublk_drv.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) Cc: Yoav Cohen diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 3c918db4905c..e662c6e8e722 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -2361,14 +2361,9 @@ static void ublk_partition_scan_work(struct work_struct *work) if (!disk) return; - if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN, - &disk->state))) - goto out; - mutex_lock(&disk->open_mutex); bdev_disk_changed(disk, false); mutex_unlock(&disk->open_mutex); -out: ublk_put_disk(disk); } @@ -4429,12 +4424,11 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, set_bit(UB_STATE_USED, &ub->state); - /* Skip partition scan if disabled by user */ - if (ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN) { + if (!ub->unprivileged_daemons) { + /* Enable partition scanning for trusted daemons */ clear_bit(GD_SUPPRESS_PART_SCAN, &disk->state); - } else { - /* Schedule async partition scan for trusted daemons */ - if (!ub->unprivileged_daemons) + /* Skip auto partition scan if requested by user */ + if (!(ub->dev_info.flags & UBLK_F_NO_AUTO_PART_SCAN)) schedule_work(&ub->partition_scan_work); } base-commit: 72f4d6fca699a1e35b39c5e5dacac2926d254135 -- 2.43.0