Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: freeze queue when updating zone resources

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. In case of error when
the limits are applied, directly call disk_free_zone_resources() from
disk_update_zone_resources() while the disk queue is still frozen to
avoid needing to freeze & unfreeze the queue again in
blk_revalidate_disk_zones(), thus simplifying that function code a
little.

Fixes: 0b83c86b444a ("block: Prevent potential deadlock in blk_revalidate_disk_zones()")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Damien Le Moal and committed by
Jens Axboe
bba4322e efae226c

+24 -18
+24 -18
block/blk-zoned.c
··· 1557 1557 { 1558 1558 struct request_queue *q = disk->queue; 1559 1559 unsigned int nr_seq_zones, nr_conv_zones; 1560 - unsigned int pool_size; 1560 + unsigned int pool_size, memflags; 1561 1561 struct queue_limits lim; 1562 + int ret = 0; 1563 + 1564 + lim = queue_limits_start_update(q); 1565 + 1566 + memflags = blk_mq_freeze_queue(q); 1562 1567 1563 1568 disk->nr_zones = args->nr_zones; 1564 1569 disk->zone_capacity = args->zone_capacity; ··· 1573 1568 if (nr_conv_zones >= disk->nr_zones) { 1574 1569 pr_warn("%s: Invalid number of conventional zones %u / %u\n", 1575 1570 disk->disk_name, nr_conv_zones, disk->nr_zones); 1576 - return -ENODEV; 1571 + ret = -ENODEV; 1572 + goto unfreeze; 1577 1573 } 1578 - 1579 - lim = queue_limits_start_update(q); 1580 1574 1581 1575 /* 1582 1576 * Some devices can advertize zone resource limits that are larger than ··· 1613 1609 } 1614 1610 1615 1611 commit: 1616 - return queue_limits_commit_update_frozen(q, &lim); 1612 + ret = queue_limits_commit_update(q, &lim); 1613 + 1614 + unfreeze: 1615 + if (ret) 1616 + disk_free_zone_resources(disk); 1617 + 1618 + blk_mq_unfreeze_queue(q, memflags); 1619 + 1620 + return ret; 1617 1621 } 1618 1622 1619 1623 static int blk_revalidate_conv_zone(struct blk_zone *zone, unsigned int idx, ··· 1786 1774 sector_t zone_sectors = q->limits.chunk_sectors; 1787 1775 sector_t capacity = get_capacity(disk); 1788 1776 struct blk_revalidate_zone_args args = { }; 1789 - unsigned int noio_flag; 1777 + unsigned int memflags, noio_flag; 1790 1778 int ret = -ENOMEM; 1791 1779 1792 1780 if (WARN_ON_ONCE(!blk_queue_is_zoned(q))) ··· 1836 1824 ret = -ENODEV; 1837 1825 } 1838 1826 1839 - /* 1840 - * Set the new disk zone parameters only once the queue is frozen and 1841 - * all I/Os are completed. 1842 - */ 1843 1827 if (ret > 0) 1844 - ret = disk_update_zone_resources(disk, &args); 1845 - else 1846 - pr_warn("%s: failed to revalidate zones\n", disk->disk_name); 1847 - if (ret) { 1848 - unsigned int memflags = blk_mq_freeze_queue(q); 1828 + return disk_update_zone_resources(disk, &args); 1849 1829 1850 - disk_free_zone_resources(disk); 1851 - blk_mq_unfreeze_queue(q, memflags); 1852 - } 1830 + pr_warn("%s: failed to revalidate zones\n", disk->disk_name); 1831 + 1832 + memflags = blk_mq_freeze_queue(q); 1833 + disk_free_zone_resources(disk); 1834 + blk_mq_unfreeze_queue(q, memflags); 1853 1835 1854 1836 return ret; 1855 1837 }