On 10/30/25 11:12 PM, Damien Le Moal wrote:
Modify disk_update_zone_resources() to freeze the device queue before
updating the number of zones, zone capacity and other zone related
resources. The locking order resulting from the call to
queue_limits_commit_update_frozen() is preserved, that is, the queue
limits lock is first taken by calling queue_limits_start_update() before
freezing the queue, and the queue is unfrozen after executing
queue_limits_commit_update(), which replaces the call to
queue_limits_commit_update_frozen().

This change ensures that there are no in-flights I/Os when the zone
resources are updated due to a zone revalidation.

Fixes: 0b83c86b444a ("block: Prevent potential deadlock in 
blk_revalidate_disk_zones()")
Cc: [email protected]
Signed-off-by: Damien Le Moal <[email protected]>
---
  block/blk-zoned.c | 19 ++++++++++++++-----
  1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 5e2a5788dc3b..f3b371056df4 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1516,8 +1516,13 @@ static int disk_update_zone_resources(struct gendisk 
*disk,
  {
        struct request_queue *q = disk->queue;
        unsigned int nr_seq_zones, nr_conv_zones;
-       unsigned int pool_size;
+       unsigned int pool_size, memflags;
        struct queue_limits lim;
+       int ret;
+
+       lim = queue_limits_start_update(q);
+
+       memflags = blk_mq_freeze_queue(q);
disk->nr_zones = args->nr_zones;
        disk->zone_capacity = args->zone_capacity;
@@ -1527,11 +1532,10 @@ static int disk_update_zone_resources(struct gendisk 
*disk,
        if (nr_conv_zones >= disk->nr_zones) {
                pr_warn("%s: Invalid number of conventional zones %u / %u\n",
                        disk->disk_name, nr_conv_zones, disk->nr_zones);
-               return -ENODEV;
+               ret = -ENODEV;
+               goto unfreeze;
        }
- lim = queue_limits_start_update(q);
-
        /*
         * Some devices can advertize zone resource limits that are larger than
         * the number of sequential zones of the zoned block device, e.g. a
@@ -1568,7 +1572,12 @@ static int disk_update_zone_resources(struct gendisk 
*disk,
        }
commit:
-       return queue_limits_commit_update_frozen(q, &lim);
+       ret = queue_limits_commit_update(q, &lim);
+
+unfreeze:
+       blk_mq_unfreeze_queue(q, memflags);
+
+       return ret;
  }
static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx,

Hi Damien,

disk_update_zone_resources() only has a single caller and just below the
only call of this function the following code is present:

        if (ret) {
                unsigned int memflags = blk_mq_freeze_queue(q);

                disk_free_zone_resources(disk);
                blk_mq_unfreeze_queue(q, memflags);
        }

Shouldn't this code be moved into disk_update_zone_resources() such that
error handling happens without unfreezing and refreezing the request
queue?

Thanks,

Bart.

Reply via email to