public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Enable testing small DMA segment sizes
@ 2026-03-25 21:37 Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche

Hi Jens,

About one year ago support was merged for DMA segment sizes smaller than the
virtual memory page size. No blktests exist yet for the new codepaths related
to small segment size support. This patch series makes it possible to test
these code paths on a system (e.g. a VM) with 4 KiB pages.

The corresponding blktest patch is available here:
https://lore.kernel.org/linux-block/20260323200751.1238583-1-bvanassche@acm.org/

Please consider this patch series for the next merge window.

Changes compared to v1:
 - Addressed Damien's comment and made the null_blk kernel module parameter more
   clear.
 - Added three patches to this series: one patch that fixes a source code
   comment and two patches that reduce the number of users of the
   BLK_MIN_SEGMENT_SIZE constant.

Bart Van Assche (5):
  block: Fix a source code comment
  block: Fix the max_user_sectors lower bound
  block: Remove a DMA segment boundary mask check
  block: Reduce the minimum value for the maximum DMA segment size
  null_blk: Support configuring the maximum DMA segment size

 block/blk-settings.c              | 14 ++++----------
 block/blk.h                       |  2 +-
 drivers/block/null_blk/main.c     | 13 +++++++++++++
 drivers/block/null_blk/null_blk.h |  1 +
 4 files changed, 19 insertions(+), 11 deletions(-)


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

* [PATCH v2 1/5] block: Fix a source code comment
  2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
@ 2026-03-25 21:37 ` Bart Van Assche
  2026-03-26 14:23   ` Christoph Hellwig
  2026-03-26 14:48   ` Ming Lei
  2026-03-25 21:37 ` [PATCH v2 2/5] block: Fix the max_user_sectors lower bound Bart Van Assche
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche

Fix a source code comment that is no longer correct since commit
889c57066cee ("block: make segment size limit workable for > 4K
PAGE_SIZE").

Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-settings.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 78c83817b9d3..87724d30be4f 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -470,8 +470,8 @@ int blk_validate_limits(struct queue_limits *lim)
 	} else {
 		/*
 		 * The maximum segment size has an odd historic 64k default that
-		 * drivers probably should override.  Just like the I/O size we
-		 * require drivers to at least handle a full page per segment.
+		 * drivers probably should override. The maximum DMA segment
+		 * size may be less than the virtual memory page size.
 		 */
 		if (!lim->max_segment_size)
 			lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;

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

* [PATCH v2 2/5] block: Fix the max_user_sectors lower bound
  2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
@ 2026-03-25 21:37 ` Bart Van Assche
  2026-03-26 14:23   ` Christoph Hellwig
  2026-03-26 14:46   ` Ming Lei
  2026-03-25 21:37 ` [PATCH v2 3/5] block: Remove a DMA segment boundary mask check Bart Van Assche
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche, Daniel Gomez, Luis Chamberlain

The lowest value that can be supported for lim->max_user_sectors is the
logical block size. This patch prepares for reducing BLK_MIN_SEGMENT_SIZE
to a value that may be less than the logical block size.

Cc: Ming Lei <ming.lei@redhat.com>
Fixes: 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-settings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 87724d30be4f..13f5457f9f4e 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -403,7 +403,7 @@ int blk_validate_limits(struct queue_limits *lim)
 	max_hw_sectors = min_not_zero(lim->max_hw_sectors,
 				lim->max_dev_sectors);
 	if (lim->max_user_sectors) {
-		if (lim->max_user_sectors < BLK_MIN_SEGMENT_SIZE / SECTOR_SIZE)
+		if (lim->max_user_sectors < lim->logical_block_size / SECTOR_SIZE)
 			return -EINVAL;
 		lim->max_sectors = min(max_hw_sectors, lim->max_user_sectors);
 	} else if (lim->io_opt > (BLK_DEF_MAX_SECTORS_CAP << SECTOR_SHIFT)) {

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

* [PATCH v2 3/5] block: Remove a DMA segment boundary mask check
  2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 2/5] block: Fix the max_user_sectors lower bound Bart Van Assche
@ 2026-03-25 21:37 ` Bart Van Assche
  2026-03-26 14:51   ` Ming Lei
  2026-03-25 21:37 ` [PATCH v2 4/5] block: Reduce the minimum value for the maximum DMA segment size Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 5/5] null_blk: Support configuring " Bart Van Assche
  4 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche, Hannes Reinecke

Commit d690cb8ae14b ("block: add an API to atomically update queue limits")
introduced the following code:

       /*
        * By default there is no limit on the segment boundary alignment,
        * but if there is one it can't be smaller than the page size as
        * that would break all the normal I/O patterns.
        */
       if (!lim->seg_boundary_mask)
               lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
       if (WARN_ON_ONCE(lim->seg_boundary_mask < PAGE_SIZE - 1))
               return -EINVAL;

The comment about "breaking normal I/O patterns" is incorrect - block
layer code like get_max_segment_size() supports arbitrary boundary mask
values as long as the boundary mask is not zero. Remove the comment and
the check because both are confusing.

This patch prepares for reducing the value of BLK_MIN_SEGMENT_SIZE.

Fixes: d690cb8ae14b ("block: add an API to atomically update queue limits")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-settings.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 13f5457f9f4e..8538e50afe2c 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -447,15 +447,9 @@ int blk_validate_limits(struct queue_limits *lim)
 	if (!lim->max_discard_segments)
 		lim->max_discard_segments = 1;
 
-	/*
-	 * By default there is no limit on the segment boundary alignment,
-	 * but if there is one it can't be smaller than the page size as
-	 * that would break all the normal I/O patterns.
-	 */
+	/* By default there is no limit on the segment boundary alignment. */
 	if (!lim->seg_boundary_mask)
 		lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
-	if (WARN_ON_ONCE(lim->seg_boundary_mask < BLK_MIN_SEGMENT_SIZE - 1))
-		return -EINVAL;
 
 	/*
 	 * Stacking device may have both virtual boundary and max segment

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

* [PATCH v2 4/5] block: Reduce the minimum value for the maximum DMA segment size
  2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
                   ` (2 preceding siblings ...)
  2026-03-25 21:37 ` [PATCH v2 3/5] block: Remove a DMA segment boundary mask check Bart Van Assche
@ 2026-03-25 21:37 ` Bart Van Assche
  2026-03-25 21:37 ` [PATCH v2 5/5] null_blk: Support configuring " Bart Van Assche
  4 siblings, 0 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche

All block devices that are supported by the Linux kernel have a DMA engine
that supports DMA segments of 4 KiB or larger. Allow smaller DMA segment
sizes because these are useful for block layer testing. Reject values below
512 because such values would result in an excessive number of DMA segments.

The only code affected by this change is the following code:

	if (WARN_ON_ONCE(lim->max_segment_size < BLK_MIN_SEGMENT_SIZE))
		return -EINVAL;

Cc: Ming Lei <ming.lei@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk.h b/block/blk.h
index 7082dd5a87f9..7c792c012b0d 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -23,7 +23,7 @@ struct elv_change_ctx;
 #define BLK_DEF_MAX_SECTORS_CAP	(SZ_4M >> SECTOR_SHIFT)
 
 #define	BLK_DEV_MAX_SECTORS	(LLONG_MAX >> 9)
-#define	BLK_MIN_SEGMENT_SIZE	4096
+#define	BLK_MIN_SEGMENT_SIZE	512
 
 /* Max future timer expiry for timeouts */
 #define BLK_MAX_TIMEOUT		(5 * HZ)

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

* [PATCH v2 5/5] null_blk: Support configuring the maximum DMA segment size
  2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
                   ` (3 preceding siblings ...)
  2026-03-25 21:37 ` [PATCH v2 4/5] block: Reduce the minimum value for the maximum DMA segment size Bart Van Assche
@ 2026-03-25 21:37 ` Bart Van Assche
  4 siblings, 0 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-25 21:37 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Ming Lei,
	Bart Van Assche, Damien Le Moal, Chaitanya Kulkarni, Keith Busch,
	Johannes Thumshirn, Genjian Zhang, Hans Holmberg, Thorsten Blum,
	Nilay Shroff, Kees Cook, Martin K. Petersen

Add support for configuring the maximum DMA segment size. The maximum DMA
segment size may be set to a value smaller than the virtual memory page
size. No checks are performed on the new max_segment_size parameter
because all positive values are valid. The value 0 is converted into a
valid value by blk_validate_limits().

Since rq_for_each_segment() may yield bvecs larger than the maximum DMA
segment size, add code in the rq_for_each_segment() loop that restricts
the bvec length to the maximum DMA segment size.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Cc: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/block/null_blk/main.c     | 13 +++++++++++++
 drivers/block/null_blk/null_blk.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 677ac829ef80..c43d74cdfd23 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -169,6 +169,10 @@ static int g_max_sectors;
 module_param_named(max_sectors, g_max_sectors, int, 0444);
 MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)");
 
+static unsigned int g_max_segment_size = BLK_MAX_SEGMENT_SIZE;
+module_param_named(max_segment_size, g_max_segment_size, int, 0444);
+MODULE_PARM_DESC(max_segment_size, "Maximum size of a DMA segment in bytes");
+
 static unsigned int nr_devices = 1;
 module_param(nr_devices, uint, 0444);
 MODULE_PARM_DESC(nr_devices, "Number of devices to register");
@@ -450,6 +454,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL);
 NULLB_DEVICE_ATTR(queue_mode, uint, NULL);
 NULLB_DEVICE_ATTR(blocksize, uint, NULL);
 NULLB_DEVICE_ATTR(max_sectors, uint, NULL);
+NULLB_DEVICE_ATTR(max_segment_size, uint, NULL);
 NULLB_DEVICE_ATTR(irqmode, uint, NULL);
 NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL);
 NULLB_DEVICE_ATTR(index, uint, NULL);
@@ -608,6 +613,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
 	&nullb_device_attr_index,
 	&nullb_device_attr_irqmode,
 	&nullb_device_attr_max_sectors,
+	&nullb_device_attr_max_segment_size,
 	&nullb_device_attr_mbps,
 	&nullb_device_attr_memory_backed,
 	&nullb_device_attr_no_sched,
@@ -805,6 +811,7 @@ static struct nullb_device *null_alloc_dev(void)
 	dev->queue_mode = g_queue_mode;
 	dev->blocksize = g_bs;
 	dev->max_sectors = g_max_sectors;
+	dev->max_segment_size = g_max_segment_size;
 	dev->irqmode = g_irqmode;
 	dev->hw_queue_depth = g_hw_queue_depth;
 	dev->blocking = g_blocking;
@@ -1251,6 +1258,9 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
 	unsigned int valid_len = len;
 	void *p;
 
+	WARN_ONCE(len > dev->max_segment_size, "%u > %u\n", len,
+		  dev->max_segment_size);
+
 	p = kmap_local_page(page) + off;
 	if (!is_write) {
 		if (dev->zoned) {
@@ -1298,6 +1308,8 @@ static blk_status_t null_handle_data_transfer(struct nullb_cmd *cmd,
 	spin_lock_irq(&nullb->lock);
 	rq_for_each_segment(bvec, rq, iter) {
 		len = bvec.bv_len;
+		len = min(bvec.bv_len, nullb->dev->max_segment_size);
+		bvec.bv_len = len;
 		if (transferred_bytes + len > max_bytes)
 			len = max_bytes - transferred_bytes;
 		err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset,
@@ -1961,6 +1973,7 @@ static int null_add_dev(struct nullb_device *dev)
 		.logical_block_size	= dev->blocksize,
 		.physical_block_size	= dev->blocksize,
 		.max_hw_sectors		= dev->max_sectors,
+		.max_segment_size	= dev->max_segment_size,
 		.dma_alignment		= 1,
 	};
 
diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h
index 6c4c4bbe7dad..43dc47789718 100644
--- a/drivers/block/null_blk/null_blk.h
+++ b/drivers/block/null_blk/null_blk.h
@@ -93,6 +93,7 @@ struct nullb_device {
 	unsigned int queue_mode; /* block interface */
 	unsigned int blocksize; /* block size */
 	unsigned int max_sectors; /* Max sectors per command */
+	unsigned int max_segment_size; /* Max size of a single DMA segment. */
 	unsigned int irqmode; /* IRQ completion handler */
 	unsigned int hw_queue_depth; /* queue depth */
 	unsigned int index; /* index of the disk, only valid with a disk */

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

* Re: [PATCH v2 1/5] block: Fix a source code comment
  2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
@ 2026-03-26 14:23   ` Christoph Hellwig
  2026-03-26 14:48   ` Ming Lei
  1 sibling, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2026-03-26 14:23 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Ming Lei

On Wed, Mar 25, 2026 at 02:37:11PM -0700, Bart Van Assche wrote:
> Fix a source code comment that is no longer correct since commit
> 889c57066cee ("block: make segment size limit workable for > 4K
> PAGE_SIZE").
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Looks good:

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


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

* Re: [PATCH v2 2/5] block: Fix the max_user_sectors lower bound
  2026-03-25 21:37 ` [PATCH v2 2/5] block: Fix the max_user_sectors lower bound Bart Van Assche
@ 2026-03-26 14:23   ` Christoph Hellwig
  2026-03-26 14:46   ` Ming Lei
  1 sibling, 0 replies; 14+ messages in thread
From: Christoph Hellwig @ 2026-03-26 14:23 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Ming Lei, Daniel Gomez, Luis Chamberlain

On Wed, Mar 25, 2026 at 02:37:12PM -0700, Bart Van Assche wrote:
> The lowest value that can be supported for lim->max_user_sectors is the
> logical block size. This patch prepares for reducing BLK_MIN_SEGMENT_SIZE
> to a value that may be less than the logical block size.
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Fixes: 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  block/blk-settings.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 87724d30be4f..13f5457f9f4e 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -403,7 +403,7 @@ int blk_validate_limits(struct queue_limits *lim)
>  	max_hw_sectors = min_not_zero(lim->max_hw_sectors,
>  				lim->max_dev_sectors);
>  	if (lim->max_user_sectors) {
> -		if (lim->max_user_sectors < BLK_MIN_SEGMENT_SIZE / SECTOR_SIZE)
> +		if (lim->max_user_sectors < lim->logical_block_size / SECTOR_SIZE)

Overly long line.


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

* Re: [PATCH v2 2/5] block: Fix the max_user_sectors lower bound
  2026-03-25 21:37 ` [PATCH v2 2/5] block: Fix the max_user_sectors lower bound Bart Van Assche
  2026-03-26 14:23   ` Christoph Hellwig
@ 2026-03-26 14:46   ` Ming Lei
  1 sibling, 0 replies; 14+ messages in thread
From: Ming Lei @ 2026-03-26 14:46 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Daniel Gomez, Luis Chamberlain

On Wed, Mar 25, 2026 at 02:37:12PM -0700, Bart Van Assche wrote:
> The lowest value that can be supported for lim->max_user_sectors is the
> logical block size. This patch prepares for reducing BLK_MIN_SEGMENT_SIZE
> to a value that may be less than the logical block size.
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Fixes: 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE")

Before commit 889c57066cee, PAGE_SIZE is applied for the limit, so you don't
fix commit 889c57066cee.

The 1st bad commit is actually commit d690cb8ae14b ("block: add an API to atomically
update queue limits').

Please fix the fix tag, otherwise feel free to add:

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


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

* Re: [PATCH v2 1/5] block: Fix a source code comment
  2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
  2026-03-26 14:23   ` Christoph Hellwig
@ 2026-03-26 14:48   ` Ming Lei
  1 sibling, 0 replies; 14+ messages in thread
From: Ming Lei @ 2026-03-26 14:48 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal

On Wed, Mar 25, 2026 at 02:37:11PM -0700, Bart Van Assche wrote:
> Fix a source code comment that is no longer correct since commit
> 889c57066cee ("block: make segment size limit workable for > 4K
> PAGE_SIZE").
> 
> Cc: Ming Lei <ming.lei@redhat.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


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

* Re: [PATCH v2 3/5] block: Remove a DMA segment boundary mask check
  2026-03-25 21:37 ` [PATCH v2 3/5] block: Remove a DMA segment boundary mask check Bart Van Assche
@ 2026-03-26 14:51   ` Ming Lei
  2026-03-26 15:51     ` Bart Van Assche
  0 siblings, 1 reply; 14+ messages in thread
From: Ming Lei @ 2026-03-26 14:51 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Hannes Reinecke

On Wed, Mar 25, 2026 at 02:37:13PM -0700, Bart Van Assche wrote:
> Commit d690cb8ae14b ("block: add an API to atomically update queue limits")
> introduced the following code:
> 
>        /*
>         * By default there is no limit on the segment boundary alignment,
>         * but if there is one it can't be smaller than the page size as
>         * that would break all the normal I/O patterns.
>         */
>        if (!lim->seg_boundary_mask)
>                lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
>        if (WARN_ON_ONCE(lim->seg_boundary_mask < PAGE_SIZE - 1))
>                return -EINVAL;
> 
> The comment about "breaking normal I/O patterns" is incorrect - block
> layer code like get_max_segment_size() supports arbitrary boundary mask
> values as long as the boundary mask is not zero. Remove the comment and
> the check because both are confusing.
> 
> This patch prepares for reducing the value of BLK_MIN_SEGMENT_SIZE.
> 
> Fixes: d690cb8ae14b ("block: add an API to atomically update queue limits")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  block/blk-settings.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index 13f5457f9f4e..8538e50afe2c 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -447,15 +447,9 @@ int blk_validate_limits(struct queue_limits *lim)
>  	if (!lim->max_discard_segments)
>  		lim->max_discard_segments = 1;
>  
> -	/*
> -	 * By default there is no limit on the segment boundary alignment,
> -	 * but if there is one it can't be smaller than the page size as
> -	 * that would break all the normal I/O patterns.
> -	 */
> +	/* By default there is no limit on the segment boundary alignment. */
>  	if (!lim->seg_boundary_mask)
>  		lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
> -	if (WARN_ON_ONCE(lim->seg_boundary_mask < BLK_MIN_SEGMENT_SIZE - 1))
> -		return -EINVAL;

Please fold this change into the real code for reducing
BLK_MIN_SEGMENT_SIZE, then it provides consistent handling/view about
->seg_boundary_mask and BLK_MIN_SEGMENT_SIZE.

Thanks,
Ming


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

* Re: [PATCH v2 3/5] block: Remove a DMA segment boundary mask check
  2026-03-26 14:51   ` Ming Lei
@ 2026-03-26 15:51     ` Bart Van Assche
  2026-03-27  0:52       ` Ming Lei
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2026-03-26 15:51 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Hannes Reinecke

On 3/26/26 7:51 AM, Ming Lei wrote:
> On Wed, Mar 25, 2026 at 02:37:13PM -0700, Bart Van Assche wrote:
>> diff --git a/block/blk-settings.c b/block/blk-settings.c
>> index 13f5457f9f4e..8538e50afe2c 100644
>> --- a/block/blk-settings.c
>> +++ b/block/blk-settings.c
>> @@ -447,15 +447,9 @@ int blk_validate_limits(struct queue_limits *lim)
>>   	if (!lim->max_discard_segments)
>>   		lim->max_discard_segments = 1;
>>   
>> -	/*
>> -	 * By default there is no limit on the segment boundary alignment,
>> -	 * but if there is one it can't be smaller than the page size as
>> -	 * that would break all the normal I/O patterns.
>> -	 */
>> +	/* By default there is no limit on the segment boundary alignment. */
>>   	if (!lim->seg_boundary_mask)
>>   		lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
>> -	if (WARN_ON_ONCE(lim->seg_boundary_mask < BLK_MIN_SEGMENT_SIZE - 1))
>> -		return -EINVAL;
> 
> Please fold this change into the real code for reducing
> BLK_MIN_SEGMENT_SIZE, then it provides consistent handling/view about
> ->seg_boundary_mask and BLK_MIN_SEGMENT_SIZE.

Hmm ... wouldn't combining these two patches into a single patch violate
the "one change per patch" rule?

Thanks,

Bart.

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

* Re: [PATCH v2 3/5] block: Remove a DMA segment boundary mask check
  2026-03-26 15:51     ` Bart Van Assche
@ 2026-03-27  0:52       ` Ming Lei
  2026-03-27  1:55         ` Bart Van Assche
  0 siblings, 1 reply; 14+ messages in thread
From: Ming Lei @ 2026-03-27  0:52 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Hannes Reinecke

On Thu, Mar 26, 2026 at 08:51:46AM -0700, Bart Van Assche wrote:
> On 3/26/26 7:51 AM, Ming Lei wrote:
> > On Wed, Mar 25, 2026 at 02:37:13PM -0700, Bart Van Assche wrote:
> > > diff --git a/block/blk-settings.c b/block/blk-settings.c
> > > index 13f5457f9f4e..8538e50afe2c 100644
> > > --- a/block/blk-settings.c
> > > +++ b/block/blk-settings.c
> > > @@ -447,15 +447,9 @@ int blk_validate_limits(struct queue_limits *lim)
> > >   	if (!lim->max_discard_segments)
> > >   		lim->max_discard_segments = 1;
> > > -	/*
> > > -	 * By default there is no limit on the segment boundary alignment,
> > > -	 * but if there is one it can't be smaller than the page size as
> > > -	 * that would break all the normal I/O patterns.
> > > -	 */
> > > +	/* By default there is no limit on the segment boundary alignment. */
> > >   	if (!lim->seg_boundary_mask)
> > >   		lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
> > > -	if (WARN_ON_ONCE(lim->seg_boundary_mask < BLK_MIN_SEGMENT_SIZE - 1))
> > > -		return -EINVAL;
> > 
> > Please fold this change into the real code for reducing
> > BLK_MIN_SEGMENT_SIZE, then it provides consistent handling/view about
> > ->seg_boundary_mask and BLK_MIN_SEGMENT_SIZE.
> 
> Hmm ... wouldn't combining these two patches into a single patch violate
> the "one change per patch" rule?

OK, looks it is two things.

But why do you remove the check? Looks you just encourage driver to use insane
lim->seg_boundary_mask. IMO, it is just fragile.

Thanks,
Ming


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

* Re: [PATCH v2 3/5] block: Remove a DMA segment boundary mask check
  2026-03-27  0:52       ` Ming Lei
@ 2026-03-27  1:55         ` Bart Van Assche
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Van Assche @ 2026-03-27  1:55 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal,
	Hannes Reinecke

On 3/26/26 5:52 PM, Ming Lei wrote:
> But why do you remove the check? Looks you just encourage driver to use insane
> lim->seg_boundary_mask. IMO, it is just fragile.

Hi Ming,

Users cannot and should not modify lim->seg_boundary_mask. Only block 
drivers should set this mask.

A possible alternative to removing this check is to change it into the
following:

	if (WARN_ON_ONCE(lim->seg_boundary_mask < SZ_4K - 1))
		return -EINVAL;

All block and SCSI drivers I know of have a seg_boundary_mask that is
greater than or equal to 4095. Does this look better to you?

Here is an example of a driver with DMA boundary (the SCSI name for the
segment boundary mask) equal to 4095:

drivers/scsi/qedi/qedi.h:67:#define QEDI_HW_DMA_BOUNDARY	0xfff
drivers/scsi/qedi/qedi_iscsi.c:59:	.dma_boundary = QEDI_HW_DMA_BOUNDARY,

Thanks,

Bart.

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

end of thread, other threads:[~2026-03-27  1:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25 21:37 [PATCH v2 0/5] Enable testing small DMA segment sizes Bart Van Assche
2026-03-25 21:37 ` [PATCH v2 1/5] block: Fix a source code comment Bart Van Assche
2026-03-26 14:23   ` Christoph Hellwig
2026-03-26 14:48   ` Ming Lei
2026-03-25 21:37 ` [PATCH v2 2/5] block: Fix the max_user_sectors lower bound Bart Van Assche
2026-03-26 14:23   ` Christoph Hellwig
2026-03-26 14:46   ` Ming Lei
2026-03-25 21:37 ` [PATCH v2 3/5] block: Remove a DMA segment boundary mask check Bart Van Assche
2026-03-26 14:51   ` Ming Lei
2026-03-26 15:51     ` Bart Van Assche
2026-03-27  0:52       ` Ming Lei
2026-03-27  1:55         ` Bart Van Assche
2026-03-25 21:37 ` [PATCH v2 4/5] block: Reduce the minimum value for the maximum DMA segment size Bart Van Assche
2026-03-25 21:37 ` [PATCH v2 5/5] null_blk: Support configuring " Bart Van Assche

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox