* [PATCH v2] block: Fix partition check for host-aware zoned block devices
@ 2021-10-26 6:01 Shin'ichiro Kawasaki
2021-10-27 6:45 ` Christoph Hellwig
2021-10-27 12:58 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Shin'ichiro Kawasaki @ 2021-10-26 6:01 UTC (permalink / raw)
To: linux-block, Jens Axboe
Cc: Christoph Hellwig, Damien Le Moal, Johannes Thumshirn,
Shinichiro Kawasaki
Commit a33df75c6328 ("block: use an xarray for disk->part_tbl") modified
the method to check partition existence in host-aware zoned block
devices from disk_has_partitions() helper function call to empty check
of xarray disk->part_tbl. However, disk->part_tbl always has single
entry for disk->part0 and never becomes empty. This resulted in the
host-aware zoned devices always judged to have partitions, and it made
the sysfs queue/zoned attribute to be "none" instead of "host-aware"
regardless of partition existence in the devices.
This also caused DEBUG_LOCKS_WARN_ON(lock->magic != lock) for
sdkp->rev_mutex in scsi layer when the kernel detects host-aware zoned
device. Since block layer handled the host-aware zoned devices as non-
zoned devices, scsi layer did not have chance to initialize the mutex
for zone revalidation. Therefore, the warning was triggered.
To fix the issues, call the helper function disk_has_partitions() in
place of disk->part_tbl empty check. Since the function was removed with
the commit a33df75c6328, reimplement it to walk through entries in the
xarray disk->part_tbl.
Fixes: a33df75c6328 ("block: use an xarray for disk->part_tbl")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: stable@vger.kernel.org # v5.14+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
Changes from v1:
* Added Reviewed-by tags
block/blk-settings.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index a7c857ad7d10..b880c70e22e4 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -842,6 +842,24 @@ bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging);
+static bool disk_has_partitions(struct gendisk *disk)
+{
+ unsigned long idx;
+ struct block_device *part;
+ bool ret = false;
+
+ rcu_read_lock();
+ xa_for_each(&disk->part_tbl, idx, part) {
+ if (bdev_is_partition(part)) {
+ ret = true;
+ break;
+ }
+ }
+ rcu_read_unlock();
+
+ return ret;
+}
+
/**
* blk_queue_set_zoned - configure a disk queue zoned model.
* @disk: the gendisk of the queue to configure
@@ -876,7 +894,7 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model)
* we do nothing special as far as the block layer is concerned.
*/
if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) ||
- !xa_empty(&disk->part_tbl))
+ disk_has_partitions(disk))
model = BLK_ZONED_NONE;
break;
case BLK_ZONED_NONE:
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block: Fix partition check for host-aware zoned block devices
2021-10-26 6:01 [PATCH v2] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
@ 2021-10-27 6:45 ` Christoph Hellwig
2021-10-27 12:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-10-27 6:45 UTC (permalink / raw)
To: Jens Axboe, Shin'ichiro Kawasaki
Cc: linux-block, Damien Le Moal, Johannes Thumshirn
Jens,
can you pick this up for 5.15? It fixes a nasty regression.
On Tue, Oct 26, 2021 at 03:01:15PM +0900, Shin'ichiro Kawasaki wrote:
> Commit a33df75c6328 ("block: use an xarray for disk->part_tbl") modified
> the method to check partition existence in host-aware zoned block
> devices from disk_has_partitions() helper function call to empty check
> of xarray disk->part_tbl. However, disk->part_tbl always has single
> entry for disk->part0 and never becomes empty. This resulted in the
> host-aware zoned devices always judged to have partitions, and it made
> the sysfs queue/zoned attribute to be "none" instead of "host-aware"
> regardless of partition existence in the devices.
>
> This also caused DEBUG_LOCKS_WARN_ON(lock->magic != lock) for
> sdkp->rev_mutex in scsi layer when the kernel detects host-aware zoned
> device. Since block layer handled the host-aware zoned devices as non-
> zoned devices, scsi layer did not have chance to initialize the mutex
> for zone revalidation. Therefore, the warning was triggered.
>
> To fix the issues, call the helper function disk_has_partitions() in
> place of disk->part_tbl empty check. Since the function was removed with
> the commit a33df75c6328, reimplement it to walk through entries in the
> xarray disk->part_tbl.
>
> Fixes: a33df75c6328 ("block: use an xarray for disk->part_tbl")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Cc: stable@vger.kernel.org # v5.14+
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> ---
> Changes from v1:
> * Added Reviewed-by tags
>
> block/blk-settings.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index a7c857ad7d10..b880c70e22e4 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -842,6 +842,24 @@ bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
> }
> EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging);
>
> +static bool disk_has_partitions(struct gendisk *disk)
> +{
> + unsigned long idx;
> + struct block_device *part;
> + bool ret = false;
> +
> + rcu_read_lock();
> + xa_for_each(&disk->part_tbl, idx, part) {
> + if (bdev_is_partition(part)) {
> + ret = true;
> + break;
> + }
> + }
> + rcu_read_unlock();
> +
> + return ret;
> +}
> +
> /**
> * blk_queue_set_zoned - configure a disk queue zoned model.
> * @disk: the gendisk of the queue to configure
> @@ -876,7 +894,7 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model)
> * we do nothing special as far as the block layer is concerned.
> */
> if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) ||
> - !xa_empty(&disk->part_tbl))
> + disk_has_partitions(disk))
> model = BLK_ZONED_NONE;
> break;
> case BLK_ZONED_NONE:
> --
> 2.31.1
---end quoted text---
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block: Fix partition check for host-aware zoned block devices
2021-10-26 6:01 [PATCH v2] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
2021-10-27 6:45 ` Christoph Hellwig
@ 2021-10-27 12:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-10-27 12:58 UTC (permalink / raw)
To: linux-block, Shin'ichiro Kawasaki
Cc: Damien Le Moal, Johannes Thumshirn, Christoph Hellwig
On Tue, 26 Oct 2021 15:01:15 +0900, Shin'ichiro Kawasaki wrote:
> Commit a33df75c6328 ("block: use an xarray for disk->part_tbl") modified
> the method to check partition existence in host-aware zoned block
> devices from disk_has_partitions() helper function call to empty check
> of xarray disk->part_tbl. However, disk->part_tbl always has single
> entry for disk->part0 and never becomes empty. This resulted in the
> host-aware zoned devices always judged to have partitions, and it made
> the sysfs queue/zoned attribute to be "none" instead of "host-aware"
> regardless of partition existence in the devices.
>
> [...]
Applied, thanks!
[1/1] block: Fix partition check for host-aware zoned block devices
commit: e0c60d0102a5ad3475401e1a2faa3d3623eefce4
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-27 12:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 6:01 [PATCH v2] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
2021-10-27 6:45 ` Christoph Hellwig
2021-10-27 12:58 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).