All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Zone related cleanups
@ 2025-11-07  6:38 Damien Le Moal
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Damien Le Moal @ 2025-11-07  6:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Christoph Hellwig

3 more patches to go on top of the cached report zone support (and its
fixes from Christoph)..
The first one improves blk_zone_wp_offset(), the second patch refactors
the use of this function to simplify the code a little. The last patch
introduces bdev_zone_start() as a replacement to using ALIGN_DOWN() for
getting the start sector of a zone.

Changes from v1:
 - Added patch 1
 - Changed patch 2 to not open code blk_zone_wp_offset() in
   disk_zone_wplug_sync_wp_offset().
 - Added review tags to patch 3

Damien Le Moal (3):
  block: improve blk_zone_wp_offset()
  block: refactor disk_zone_wplug_sync_wp_offset()
  block: introduce bdev_zone_start()

 block/blk-zoned.c      | 39 +++++++++++++++++++--------------------
 include/linux/blkdev.h |  6 ++++++
 2 files changed, 25 insertions(+), 20 deletions(-)

-- 
2.51.1


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

* [PATCH v2 1/3] block: improve blk_zone_wp_offset()
  2025-11-07  6:38 [PATCH v2 0/3] Zone related cleanups Damien Le Moal
@ 2025-11-07  6:38 ` Damien Le Moal
  2025-11-07  8:34   ` Hannes Reinecke
                     ` (2 more replies)
  2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 12+ messages in thread
From: Damien Le Moal @ 2025-11-07  6:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Christoph Hellwig

blk_zone_wp_offset() is always called with a struct blk_zone obtained
from the device, that is, it will never see the BLK_ZONE_COND_ACTIVE
condition. However, handling this condition makes this function more
solid and will also avoid issues when propagating cached report requests
to underlying stacked devices is implemented. Add BLK_ZONE_COND_ACTIVE
as a new case in blk_zone_wp_offset() switch.

Also while at it, change the handling of the full condition to return
UINT_MAX for the zone write pointer to reflect the fact that the write
pointer of a full zone is invalid.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-zoned.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 8204214e3b89..7ce7b8ea5a4f 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -800,18 +800,18 @@ static unsigned int blk_zone_wp_offset(struct blk_zone *zone)
 	case BLK_ZONE_COND_IMP_OPEN:
 	case BLK_ZONE_COND_EXP_OPEN:
 	case BLK_ZONE_COND_CLOSED:
+	case BLK_ZONE_COND_ACTIVE:
 		return zone->wp - zone->start;
-	case BLK_ZONE_COND_FULL:
-		return zone->len;
 	case BLK_ZONE_COND_EMPTY:
 		return 0;
+	case BLK_ZONE_COND_FULL:
 	case BLK_ZONE_COND_NOT_WP:
 	case BLK_ZONE_COND_OFFLINE:
 	case BLK_ZONE_COND_READONLY:
 	default:
 		/*
-		 * Conventional, offline and read-only zones do not have a valid
-		 * write pointer.
+		 * Conventional, full, offline and read-only zones do not have
+		 * a valid write pointer.
 		 */
 		return UINT_MAX;
 	}
-- 
2.51.1


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

* [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset()
  2025-11-07  6:38 [PATCH v2 0/3] Zone related cleanups Damien Le Moal
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
@ 2025-11-07  6:38 ` Damien Le Moal
  2025-11-07  8:35   ` Hannes Reinecke
                     ` (2 more replies)
  2025-11-07  6:38 ` [PATCH v2 3/3] block: introduce bdev_zone_start() Damien Le Moal
  2025-11-07 16:28 ` [PATCH v2 0/3] Zone related cleanups Jens Axboe
  3 siblings, 3 replies; 12+ messages in thread
From: Damien Le Moal @ 2025-11-07  6:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Christoph Hellwig

The helper function blk_zone_wp_offset() is called from
disk_zone_wplug_sync_wp_offset(), and again called from
blk_revalidate_seq_zone() right after the call to
disk_zone_wplug_sync_wp_offset().

Change disk_zone_wplug_sync_wp_offset() to return the value of obtained
with blk_zone_wp_offset() to avoid this double call, which simplifies a
little blk_revalidate_seq_zone().

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-zoned.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 7ce7b8ea5a4f..b580d59ce210 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -817,23 +817,24 @@ static unsigned int blk_zone_wp_offset(struct blk_zone *zone)
 	}
 }
 
-static void disk_zone_wplug_sync_wp_offset(struct gendisk *disk,
-					   struct blk_zone *zone)
+static unsigned int disk_zone_wplug_sync_wp_offset(struct gendisk *disk,
+						   struct blk_zone *zone)
 {
 	struct blk_zone_wplug *zwplug;
-	unsigned long flags;
+	unsigned int wp_offset = blk_zone_wp_offset(zone);
 
 	zwplug = disk_get_zone_wplug(disk, zone->start);
-	if (!zwplug)
-		return;
+	if (zwplug) {
+		unsigned long flags;
 
-	spin_lock_irqsave(&zwplug->lock, flags);
-	if (zwplug->flags & BLK_ZONE_WPLUG_NEED_WP_UPDATE)
-		disk_zone_wplug_set_wp_offset(disk, zwplug,
-					      blk_zone_wp_offset(zone));
-	spin_unlock_irqrestore(&zwplug->lock, flags);
+		spin_lock_irqsave(&zwplug->lock, flags);
+		if (zwplug->flags & BLK_ZONE_WPLUG_NEED_WP_UPDATE)
+			disk_zone_wplug_set_wp_offset(disk, zwplug, wp_offset);
+		spin_unlock_irqrestore(&zwplug->lock, flags);
+		disk_put_zone_wplug(zwplug);
+	}
 
-	disk_put_zone_wplug(zwplug);
+	return wp_offset;
 }
 
 /**
@@ -2101,9 +2102,7 @@ static int blk_revalidate_seq_zone(struct blk_zone *zone, unsigned int idx,
 	if (!queue_emulates_zone_append(disk->queue) || !disk->zone_wplugs_hash)
 		return 0;
 
-	disk_zone_wplug_sync_wp_offset(disk, zone);
-
-	wp_offset = blk_zone_wp_offset(zone);
+	wp_offset = disk_zone_wplug_sync_wp_offset(disk, zone);
 	if (!wp_offset || wp_offset >= zone->capacity)
 		return 0;
 
-- 
2.51.1


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

* [PATCH v2 3/3] block: introduce bdev_zone_start()
  2025-11-07  6:38 [PATCH v2 0/3] Zone related cleanups Damien Le Moal
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
  2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
@ 2025-11-07  6:38 ` Damien Le Moal
  2025-11-07  8:36   ` Hannes Reinecke
  2025-11-07 16:28 ` [PATCH v2 0/3] Zone related cleanups Jens Axboe
  3 siblings, 1 reply; 12+ messages in thread
From: Damien Le Moal @ 2025-11-07  6:38 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Christoph Hellwig

Introduce the function bdev_zone_start() as a more explicit (and clear)
replacement for ALIGN_DOWN() to get the start sector of a zone
containing a particular sector of a zoned block device.

Use this new helper in blkdev_get_zone_info() and
blkdev_report_zones_cached().

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-zoned.c      | 4 ++--
 include/linux/blkdev.h | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index b580d59ce210..3791755bc6ad 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -950,7 +950,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 		return -EINVAL;
 
 	memset(zone, 0, sizeof(*zone));
-	sector = ALIGN_DOWN(sector, zone_sectors);
+	sector = bdev_zone_start(bdev, sector);
 
 	if (!blkdev_has_cached_report_zones(bdev))
 		return blkdev_report_zone_fallback(bdev, sector, zone);
@@ -1068,7 +1068,7 @@ int blkdev_report_zones_cached(struct block_device *bdev, sector_t sector,
 		return blkdev_do_report_zones(bdev, sector, nr_zones, &args);
 	}
 
-	for (sector = ALIGN_DOWN(sector, zone_sectors);
+	for (sector = bdev_zone_start(bdev, sector);
 	     sector < capacity && idx < nr_zones;
 	     sector += zone_sectors, idx++) {
 		ret = blkdev_get_zone_info(bdev, sector, &zone);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 6a498aa7f7e7..2fff8a80dbd2 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1522,6 +1522,12 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev)
 	return q->limits.chunk_sectors;
 }
 
+static inline sector_t bdev_zone_start(struct block_device *bdev,
+				       sector_t sector)
+{
+	return sector & ~(bdev_zone_sectors(bdev) - 1);
+}
+
 static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
 						   sector_t sector)
 {
-- 
2.51.1


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

* Re: [PATCH v2 1/3] block: improve blk_zone_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
@ 2025-11-07  8:34   ` Hannes Reinecke
  2025-11-07 11:40   ` Christoph Hellwig
  2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Hannes Reinecke @ 2025-11-07  8:34 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Christoph Hellwig

On 11/7/25 07:38, Damien Le Moal wrote:
> blk_zone_wp_offset() is always called with a struct blk_zone obtained
> from the device, that is, it will never see the BLK_ZONE_COND_ACTIVE
> condition. However, handling this condition makes this function more
> solid and will also avoid issues when propagating cached report requests
> to underlying stacked devices is implemented. Add BLK_ZONE_COND_ACTIVE
> as a new case in blk_zone_wp_offset() switch.
> 
> Also while at it, change the handling of the full condition to return
> UINT_MAX for the zone write pointer to reflect the fact that the write
> pointer of a full zone is invalid.
> 
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
>   block/blk-zoned.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

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

* Re: [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
@ 2025-11-07  8:35   ` Hannes Reinecke
  2025-11-07 11:40   ` Christoph Hellwig
  2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Hannes Reinecke @ 2025-11-07  8:35 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Christoph Hellwig

On 11/7/25 07:38, Damien Le Moal wrote:
> The helper function blk_zone_wp_offset() is called from
> disk_zone_wplug_sync_wp_offset(), and again called from
> blk_revalidate_seq_zone() right after the call to
> disk_zone_wplug_sync_wp_offset().
> 
> Change disk_zone_wplug_sync_wp_offset() to return the value of obtained
> with blk_zone_wp_offset() to avoid this double call, which simplifies a
> little blk_revalidate_seq_zone().
> 
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
>   block/blk-zoned.c | 27 +++++++++++++--------------
>   1 file changed, 13 insertions(+), 14 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

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

* Re: [PATCH v2 3/3] block: introduce bdev_zone_start()
  2025-11-07  6:38 ` [PATCH v2 3/3] block: introduce bdev_zone_start() Damien Le Moal
@ 2025-11-07  8:36   ` Hannes Reinecke
  0 siblings, 0 replies; 12+ messages in thread
From: Hannes Reinecke @ 2025-11-07  8:36 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Christoph Hellwig

On 11/7/25 07:38, Damien Le Moal wrote:
> Introduce the function bdev_zone_start() as a more explicit (and clear)
> replacement for ALIGN_DOWN() to get the start sector of a zone
> containing a particular sector of a zoned block device.
> 
> Use this new helper in blkdev_get_zone_info() and
> blkdev_report_zones_cached().
> 
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Bart Van Assche <bvanassche@acm.org>
> ---
>   block/blk-zoned.c      | 4 ++--
>   include/linux/blkdev.h | 6 ++++++
>   2 files changed, 8 insertions(+), 2 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich

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

* Re: [PATCH v2 1/3] block: improve blk_zone_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
  2025-11-07  8:34   ` Hannes Reinecke
@ 2025-11-07 11:40   ` Christoph Hellwig
  2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2025-11-07 11:40 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block, Christoph Hellwig

Looks good:

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


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

* Re: [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
  2025-11-07  8:35   ` Hannes Reinecke
@ 2025-11-07 11:40   ` Christoph Hellwig
  2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2025-11-07 11:40 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block, Christoph Hellwig

Looks good:

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


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

* Re: [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
  2025-11-07  8:35   ` Hannes Reinecke
  2025-11-07 11:40   ` Christoph Hellwig
@ 2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Bart Van Assche @ 2025-11-07 16:06 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Christoph Hellwig

On 11/6/25 10:38 PM, Damien Le Moal wrote:
> The helper function blk_zone_wp_offset() is called from
> disk_zone_wplug_sync_wp_offset(), and again called from
> blk_revalidate_seq_zone() right after the call to
> disk_zone_wplug_sync_wp_offset().
> 
> Change disk_zone_wplug_sync_wp_offset() to return the value of obtained
> with blk_zone_wp_offset() to avoid this double call, which simplifies a
> little blk_revalidate_seq_zone().
Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v2 1/3] block: improve blk_zone_wp_offset()
  2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
  2025-11-07  8:34   ` Hannes Reinecke
  2025-11-07 11:40   ` Christoph Hellwig
@ 2025-11-07 16:06   ` Bart Van Assche
  2 siblings, 0 replies; 12+ messages in thread
From: Bart Van Assche @ 2025-11-07 16:06 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block; +Cc: Christoph Hellwig

On 11/6/25 10:38 PM, Damien Le Moal wrote:
> blk_zone_wp_offset() is always called with a struct blk_zone obtained
> from the device, that is, it will never see the BLK_ZONE_COND_ACTIVE
> condition. However, handling this condition makes this function more
> solid and will also avoid issues when propagating cached report requests
> to underlying stacked devices is implemented. Add BLK_ZONE_COND_ACTIVE
> as a new case in blk_zone_wp_offset() switch.

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

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

* Re: [PATCH v2 0/3] Zone related cleanups
  2025-11-07  6:38 [PATCH v2 0/3] Zone related cleanups Damien Le Moal
                   ` (2 preceding siblings ...)
  2025-11-07  6:38 ` [PATCH v2 3/3] block: introduce bdev_zone_start() Damien Le Moal
@ 2025-11-07 16:28 ` Jens Axboe
  3 siblings, 0 replies; 12+ messages in thread
From: Jens Axboe @ 2025-11-07 16:28 UTC (permalink / raw)
  To: linux-block, Damien Le Moal; +Cc: Christoph Hellwig


On Fri, 07 Nov 2025 15:38:41 +0900, Damien Le Moal wrote:
> 3 more patches to go on top of the cached report zone support (and its
> fixes from Christoph)..
> The first one improves blk_zone_wp_offset(), the second patch refactors
> the use of this function to simplify the code a little. The last patch
> introduces bdev_zone_start() as a replacement to using ALIGN_DOWN() for
> getting the start sector of a zone.
> 
> [...]

Applied, thanks!

[1/3] block: improve blk_zone_wp_offset()
      commit: bbac6e0fa57f6624123edf20ba8f9b7c0e092117
[2/3] block: refactor disk_zone_wplug_sync_wp_offset()
      commit: e2b0ec776164c11569ee021fac89596a2642654c
[3/3] block: introduce bdev_zone_start()
      commit: 25976c314f6596254c9b1e2291d94393b7d5ae81

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-11-07 16:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-07  6:38 [PATCH v2 0/3] Zone related cleanups Damien Le Moal
2025-11-07  6:38 ` [PATCH v2 1/3] block: improve blk_zone_wp_offset() Damien Le Moal
2025-11-07  8:34   ` Hannes Reinecke
2025-11-07 11:40   ` Christoph Hellwig
2025-11-07 16:06   ` Bart Van Assche
2025-11-07  6:38 ` [PATCH v2 2/3] block: refactor disk_zone_wplug_sync_wp_offset() Damien Le Moal
2025-11-07  8:35   ` Hannes Reinecke
2025-11-07 11:40   ` Christoph Hellwig
2025-11-07 16:06   ` Bart Van Assche
2025-11-07  6:38 ` [PATCH v2 3/3] block: introduce bdev_zone_start() Damien Le Moal
2025-11-07  8:36   ` Hannes Reinecke
2025-11-07 16:28 ` [PATCH v2 0/3] Zone related cleanups Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.