linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix partition check for host-aware zoned block devices
@ 2021-10-15  2:07 Shin'ichiro Kawasaki
  2021-10-15  7:32 ` Johannes Thumshirn
  2021-10-16  4:34 ` Christoph Hellwig
  0 siblings, 2 replies; 6+ messages in thread
From: Shin'ichiro Kawasaki @ 2021-10-15  2:07 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+
---
 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] 6+ messages in thread

* Re: [PATCH] block: Fix partition check for host-aware zoned block devices
  2021-10-15  2:07 [PATCH] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
@ 2021-10-15  7:32 ` Johannes Thumshirn
  2021-10-16  4:34 ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2021-10-15  7:32 UTC (permalink / raw)
  To: Shinichiro Kawasaki, linux-block, Jens Axboe
  Cc: Christoph Hellwig, Damien Le Moal

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Fix partition check for host-aware zoned block devices
  2021-10-15  2:07 [PATCH] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
  2021-10-15  7:32 ` Johannes Thumshirn
@ 2021-10-16  4:34 ` Christoph Hellwig
  2021-10-16 14:26   ` Matthew Wilcox
  1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-16  4:34 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki
  Cc: linux-block, Jens Axboe, Christoph Hellwig, Damien Le Moal,
	Johannes Thumshirn, Matthew Wilcox

On Fri, Oct 15, 2021 at 11:07:40AM +0900, Shin'ichiro Kawasaki wrote:
> 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

Matthew,

we talked about possiblig adding a xa_nr_entries helper a while ago.
This would be a good place for it, as we could just check
xa_nr_entries() > 1 for example.

> 
> 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+
> ---
>  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] 6+ messages in thread

* Re: [PATCH] block: Fix partition check for host-aware zoned block devices
  2021-10-16  4:34 ` Christoph Hellwig
@ 2021-10-16 14:26   ` Matthew Wilcox
  2021-10-18  8:22     ` Christoph Hellwig
  2021-10-19  9:52     ` Shinichiro Kawasaki
  0 siblings, 2 replies; 6+ messages in thread
From: Matthew Wilcox @ 2021-10-16 14:26 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Shin'ichiro Kawasaki, linux-block, Jens Axboe,
	Damien Le Moal, Johannes Thumshirn

On Sat, Oct 16, 2021 at 06:34:50AM +0200, Christoph Hellwig wrote:
> On Fri, Oct 15, 2021 at 11:07:40AM +0900, Shin'ichiro Kawasaki wrote:
> > 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.
> 
> Looks good,
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Matthew,
> 
> we talked about possiblig adding a xa_nr_entries helper a while ago.
> This would be a good place for it, as we could just check
> xa_nr_entries() > 1 for example.

Do I understand the problem correctly, that you don't actually want to
know whether there's more than one entry in the array, but rather that
there's an entry at an index other than 0?

If so, that's an easy question to answer, we just don't have a helper
for it yet.  Something like this should do:

static inline bool xa_is_trivial(const struct xarray *xa)
{
	void *entry = READ_ONCE(xa->xa_head);

	return entry || !xa_is_node(entry);
}

Probably needs a better name than that.

> > 
> > 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+
> > ---
> >  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] 6+ messages in thread

* Re: [PATCH] block: Fix partition check for host-aware zoned block devices
  2021-10-16 14:26   ` Matthew Wilcox
@ 2021-10-18  8:22     ` Christoph Hellwig
  2021-10-19  9:52     ` Shinichiro Kawasaki
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-18  8:22 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Christoph Hellwig, Shin'ichiro Kawasaki, linux-block,
	Jens Axboe, Damien Le Moal, Johannes Thumshirn

On Sat, Oct 16, 2021 at 03:26:18PM +0100, Matthew Wilcox wrote:
> Do I understand the problem correctly, that you don't actually want to
> know whether there's more than one entry in the array, but rather that
> there's an entry at an index other than 0?

In this case both checks are equivalemt because index 0 is always
present once the disk is life.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] block: Fix partition check for host-aware zoned block devices
  2021-10-16 14:26   ` Matthew Wilcox
  2021-10-18  8:22     ` Christoph Hellwig
@ 2021-10-19  9:52     ` Shinichiro Kawasaki
  1 sibling, 0 replies; 6+ messages in thread
From: Shinichiro Kawasaki @ 2021-10-19  9:52 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Christoph Hellwig, linux-block, Jens Axboe, Damien Le Moal,
	Johannes Thumshirn

On Oct 16, 2021 / 15:26, Matthew Wilcox wrote:
> On Sat, Oct 16, 2021 at 06:34:50AM +0200, Christoph Hellwig wrote:
> > On Fri, Oct 15, 2021 at 11:07:40AM +0900, Shin'ichiro Kawasaki wrote:
> > > 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.
> > 
> > Looks good,
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Matthew,
> > 
> > we talked about possiblig adding a xa_nr_entries helper a while ago.
> > This would be a good place for it, as we could just check
> > xa_nr_entries() > 1 for example.
> 
> Do I understand the problem correctly, that you don't actually want to
> know whether there's more than one entry in the array, but rather that
> there's an entry at an index other than 0?
> 
> If so, that's an easy question to answer, we just don't have a helper
> for it yet.  Something like this should do:
> 
> static inline bool xa_is_trivial(const struct xarray *xa)
> {
> 	void *entry = READ_ONCE(xa->xa_head);
> 
> 	return entry || !xa_is_node(entry);
> }
> 
> Probably needs a better name than that.

Thanks for the discussion. Based on the code above, I tried following hunk
below, and confirmed the new helper function can be used to fix the issue I
found. Good. To make it work, I needed to change the logical operator in the
function from OR to AND. As for the function name, my mere suggestion is
xa_has_single_entry(), but this may not be the best.

I would like to ask advice on the next action for the fix. If my original patch
can go to upstream first, I think the changes for this new xarray helper can be
done later. This approach would be good if the new helper will not be propagated
to the stable branches. Another approach is to do both of this new helper
introduction and the issue fix at this moment. Which approach is the better?


diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index a91e3d90df8a..7a31c9423d01 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -1238,6 +1238,20 @@ static inline unsigned long xa_to_sibling(const void *entry)
 	return xa_to_internal(entry);
 }
 
+/**
+ * xa_has_single_entry() - Does it have an entry at an index other than 0?
+ * @entry: XArray entry.
+ *
+ * Context: Any context.
+ * Return: %true if there is no entry at an index other than 0.
+ */
+static inline bool xa_has_single_entry(const struct xarray *xa)
+{
+	const void *entry = READ_ONCE(xa->xa_head);
+
+	return entry && !xa_is_node(entry);
+}
+
 /**
  * xa_is_sibling() - Is the entry a sibling entry?
  * @entry: Entry retrieved from the XArray


-- 
Best Regards,
Shin'ichiro Kawasaki

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-19  9:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  2:07 [PATCH] block: Fix partition check for host-aware zoned block devices Shin'ichiro Kawasaki
2021-10-15  7:32 ` Johannes Thumshirn
2021-10-16  4:34 ` Christoph Hellwig
2021-10-16 14:26   ` Matthew Wilcox
2021-10-18  8:22     ` Christoph Hellwig
2021-10-19  9:52     ` Shinichiro Kawasaki

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).