enable sector size > PAGE_SIZE for scsi
Subsystems (2)
cover enable sector size > PAGE_SIZE for scsi
From: Swarna Prabhu <[email protected]>
Hi All,
This is non RFC v1 series sent based on the feedback received on RFC v2 [1] and RFC v1 [2]. This patchset enables sector sizes > PAGE_SIZE for sd driver and scsi_debug driver since block layer can support block size > PAGE_SIZE. There was one issue with write_same16 and write_same10 command, which is fixed as a part of the series.
Motivation:
- While enabling LBS on ZoneFS, zonefs-tools tests were being skipped for conventional zones when tested on nvme block device emulated using QEMU. Hence there was a need to enable scsi with higher sector sizes to run zonefs tests for conventional zones as well.
Changes since RFC v2:
- Replaced open coded check for enabling sdebug_sector_size > PAGE_SIZE with blk_validate_block_size() in scsi_debug.
- Replaced open coded check for enabling sector_size > PAGE_SIZE with blk_validate_block_size() in sd driver.
- Replaced 'struct request *rq' argument in 'sd_set_special_bvec()' to 'struct scsi_cmnd *cmnd' and used that to get SCSI device pointer 'struct scsi_device *sdp'.
- Slightly modified the commit title for scsi sd driver fix patch.
- Added "Cc: [email protected]" tag to scsi sd driver fix patch.
Changes since RFC v1:
- Re organized the patch series into one patch for scsi_debug driver and one patch for sd driver.
- Updated commit title and description to accommodate the above re organization on commit titled - scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE.
- Updated commit title and description to reflect the re organization on commit titled - scsi: scsi_debug: enable sdebug_sector_size
Quoted 1 line
PAGE_SIZE.
Thanks to Bart for feedback on the RFC v1 and v2 series.
Testing:
-Test suite: xfs and generic from fstest + QEMU emulated block
device(scsi and nvme)
- fstest Config for patched xfs 16k block size [xfs_reflink_16k_scsi]
TEST_DEV=/dev/sda
SCRATCH_DEV_POOL="/dev/sdb"
MKFS_OPTIONS='-f -m reflink=1,rmapbt=1, -i sparse=1, -b size=16384,
-s size=16384' - Generic test results
Baseline: 6.18.0-rc7 kernel + nvme 16k logical block size
Patched: 6.18 kernel + scsi 16k logical block size
5 failures seen on generic tests and the same seen on baseline No regressions introduced by the patch.
- XFS tests results
Baseline: 6.18.0-rc7 kernel + nvme16k logical block size
Patched: 6.18 kernel + sci 16k logical block size
30 failures seen on patched and baseline
No regressions introduced by the patch
- Blktests results
scis and block layer tests with 16k and 32k logical block size. config used:
TEST_DEVS=(/dev/sda)
EXCLUDE=(block/010 block/011) # these didn't run on baseline(nvme 16k) All tests passed.
Link to RFC v2: https://lore.kernel.org/all/[email protected]/ [1] Link to RFC v1: https://lore.kernel.org/all/[email protected]/ [2]
Swarna Prabhu (2):
scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE
scsi: scsi_debug: enable sdebug_sector_size > PAGE_SIZE
drivers/scsi/scsi_debug.c | 8 +------- drivers/scsi/sd.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE
From: Swarna Prabhu <[email protected]>
The WRITE SAME(16) and WRITE SAME(10) scsi commands uses a page from a dedicated mempool('sd_page_pool') for its payload. This pool was initialized to allocate single pages, which was sufficient as long as the device sector size did not exceed the PAGE_SIZE.
Given that block layer now supports block size upto 64K ie beyond PAGE_SIZE, adapt sd_set_special_bvec() to accommodate that.
With the above fix, enable sector sizes > PAGE_SIZE in scsi sd driver.
---
Note: We are allocating pages of order aligned to BLK_MAX_BLOCK_SIZE for the mempool page allocator 'sd_page_pool' all the time. This is because we only know that a bigger sector size device is attached at sd_probe and it might be too late to reallocate mempool with order >0.
drivers/scsi/sd.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/scsi/sd.c +17 -10
@@ -892,14 +892,24 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim, (logical_block_size >>SECTOR_SHIFT ); } -static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) +static void *sd_set_special_bvec (struct scsi_cmnd *cmd,unsigned int data_len) {struct page *page; +struct request *rq =scsi_cmd_to_rq (cmd); +struct scsi_device *sdp = cmd->device; +unsigned sector_size = sdp->sector_size; +unsigned int nr_pages =DIV_ROUND_UP (sector_size,PAGE_SIZE ); +int n =0 ; page =mempool_alloc (sd_page_pool,GFP_ATOMIC );if (!page)return NULL ; -clear_highpage (page); + +do { +clear_highpage (page + n); + n++; + }while (n < nr_pages); +bvec_set_page (&rq->special_vec, page, data_len,0 ); rq->rq_flags |=RQF_SPECIAL_PAYLOAD ;return bvec_virt (&rq->special_vec);
@@ -915,7 +925,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)unsigned int data_len =24 ;char *buf; - buf =sd_set_special_bvec (rq, data_len); + buf =sd_set_special_bvec (cmd, data_len);if (!buf)return BLK_STS_RESOURCE ;
@@ -1004,7 +1014,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =16 ;
@@ -1031,7 +1041,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =10 ;
@@ -2880,10 +2890,7 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, "assuming 512.\n"); } -if (sector_size !=512 && - sector_size !=1024 && - sector_size !=2048 && - sector_size !=4096 ) { +if (blk_validate_block_size (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/*
@@ -4368,7 +4375,7 @@ static int __init init_sd(void)if (err) goto err_out; - sd_page_pool =mempool_create_page_pool (SD_MEMPOOL_SIZE ,0 ); + sd_page_pool =mempool_create_page_pool (SD_MEMPOOL_SIZE ,get_order (BLK_MAX_BLOCK_SIZE ));if (!sd_page_pool) {printk (KERN_ERR "sd: can't init discard page pool\n" ); err = -ENOMEM ;
Signature · 1 line
2.51.0
Re: [PATCH 1/2] scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE
Quoted 19 lines · On 2025/12/09 17:41, [email protected] wrote:
From: Swarna Prabhu <[email protected]>
The WRITE SAME(16) and WRITE SAME(10) scsi commands uses a page from a dedicated
mempool('sd_page_pool')for its payload. This pool was initialized to allocate single pages, which was sufficient as long as the device sector size did not exceed thePAGE_SIZE.Given that block layer now supports block size upto 64K ie beyond
PAGE_SIZE, adaptsd_set_special_bvec()to accommodate that.With the above fix, enable sector sizes >
PAGE_SIZEin scsi sd driver.Signed-off-by Swarna Prabhu <[email protected]>Co-developed-by Pankaj Raghav <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>
Quoted 7 lines
---
Note: We are allocating pages of order aligned toBLK_MAX_BLOCK_SIZEfor the mempool page allocator 'sd_page_pool' all the time. This is because we only know that a bigger sector size device is attached atsd_probeand it might be too late to reallocate mempool with order >0.
That is a lot heavier on the memory for the vast majority of devices which are 512B or 4K block size... It may be better to have the special "large block" mempool attached to the scsi disk struct and keep the default single page mempool for all other regular devices.
Quoted 83 lines
drivers/scsi/sd.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)drivers/scsi/sd.c +17
-10@@ -892,14 +892,24 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim, (logical_block_size >>SECTOR_SHIFT ); } -static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) +static void *sd_set_special_bvec (struct scsi_cmnd *cmd,unsigned int data_len) {struct page *page; +struct request *rq =scsi_cmd_to_rq (cmd); +struct scsi_device *sdp = cmd->device; +unsigned sector_size = sdp->sector_size; +unsigned int nr_pages =DIV_ROUND_UP (sector_size,PAGE_SIZE ); +int n =0 ; page =mempool_alloc (sd_page_pool,GFP_ATOMIC );if (!page)return NULL ; -clear_highpage (page); + +do { +clear_highpage (page + n); + n++; + }while (n < nr_pages); +bvec_set_page (&rq->special_vec, page, data_len,0 ); rq->rq_flags |=RQF_SPECIAL_PAYLOAD ;return bvec_virt (&rq->special_vec);@@ -915,7 +925,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)unsigned int data_len =24 ;char *buf; - buf =sd_set_special_bvec (rq, data_len); + buf =sd_set_special_bvec (cmd, data_len);if (!buf)return BLK_STS_RESOURCE ;@@ -1004,7 +1014,7 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =16 ;@@ -1031,7 +1041,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,u32 nr_blocks =sectors_to_logical (sdp,blk_rq_sectors (rq));u32 data_len = sdp->sector_size; -if (!sd_set_special_bvec (rq, data_len)) +if (!sd_set_special_bvec (cmd, data_len))return BLK_STS_RESOURCE ; cmd->cmd_len =10 ;@@ -2880,10 +2890,7 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, "assuming 512.\n"); } -if (sector_size !=512 && - sector_size !=1024 && - sector_size !=2048 && - sector_size !=4096 ) { +if (blk_validate_block_size (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/* @@ -4368,7 +4375,7 @@ static int __init init_sd(void)if (err) goto err_out; - sd_page_pool =mempool_create_page_pool (SD_MEMPOOL_SIZE ,0 ); + sd_page_pool =mempool_create_page_pool (SD_MEMPOOL_SIZE ,get_order (BLK_MAX_BLOCK_SIZE ));if (!sd_page_pool) {printk (KERN_ERR "sd: can't init discard page pool\n" ); err = -ENOMEM ;
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 1/2] scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE
Quoted 28 lines · Damien Le Moal
Quoted 19 lines · On 2025/12/09 17:41, [email protected] wrote:
From: Swarna Prabhu <[email protected]>
The WRITE SAME(16) and WRITE SAME(10) scsi commands uses a page from a dedicated
mempool('sd_page_pool')for its payload. This pool was initialized to allocate single pages, which was sufficient as long as the device sector size did not exceed thePAGE_SIZE.Given that block layer now supports block size upto 64K ie beyond
PAGE_SIZE, adaptsd_set_special_bvec()to accommodate that.With the above fix, enable sector sizes >
PAGE_SIZEin scsi sd driver.Signed-off-by Swarna Prabhu <[email protected]>Co-developed-by Pankaj Raghav <[email protected]>Signed-off-by Pankaj Raghav <[email protected]>Quoted 7 lines
---
Note: We are allocating pages of order aligned toBLK_MAX_BLOCK_SIZEfor the mempool page allocator 'sd_page_pool' all the time. This is because we only know that a bigger sector size device is attached atsd_probeand it might be too late to reallocate mempool with order >0.
Quoted 5 lines
That is a lot heavier on the memory for the vast majority of devices which are 512B or 4K block size... It may be better to have the special "large block" mempool attached to the scsi disk struct and keep the default single page mempool for all other regular devices.
We had the same feeling as well and we mentioned it in the 1st RFC.
But when will you initialize the mempool for the large block devices? I don't think it makes sense to unconditionally initialize it in init_sd.
Do we do it during the sd_probe() when we first encounter a large block device? That way we may not waste any memory if no large block devices are attached.
--
Pankaj
Re: [PATCH 1/2] scsi: sd: fix write_same(16/10) to enable sector size > PAGE_SIZE
Quoted 15 lines · Pankaj Raghav
Quoted 9 lines
Quoted 8 lines
Cc: [email protected] Signed-off-by: Swarna Prabhu <[email protected]> Co-developed-by: Pankaj Raghav <[email protected]> Signed-off-by: Pankaj Raghav <[email protected]> --- Note: We are allocating pages of order aligned to
BLK_MAX_BLOCK_SIZEfor the mempool page allocator 'sd_page_pool' all the time. This is because we only know that a bigger sector size device is attached atsd_probeand it might be too late to reallocate mempool with order >0.Quoted 5 lines
That is a lot heavier on the memory for the vast majority of devices which are 512B or 4K block size... It may be better to have the special "large block" mempool attached to the scsi disk struct and keep the default single page mempool for all other regular devices.
Quoted 6 lines
We had the same feeling as well and we mentioned it in the 1st RFC.
But when will you initialize the mempool for the large block devices? I don't think it makes sense to unconditionally initialize it in
init_sd. Do we do it during thesd_probe()when we first encounter a large block device? That way we may not waste any memory if no large block devices are attached.
That sounds reasonable to me. Any system that has a device with a large sector size will get this mempool initialized when the first such device is scanned, and systems with regular disks (the vast majority of cases for scsi) will not. You may want to be careful with that initialization in sd_probe() though: scsi device scan is asynchronous and done in parallel for multiple devices, so you will need some atomicity for checking the mempool existence and initializing it if needed.
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH 2/2 scsi: scsi_debug: enable sdebug_sector_size > PAGE_SIZE
In reply to [email protected]From: Swarna Prabhu <[email protected]>
Now that block layer can support block size > PAGE_SIZE and the issue with WRITE_SAME(16) and WRITE_SAME(10) are fixed for sector sizes > PAGE_SIZE, enable sdebug_sector_size
Quoted 1 line
PAGE_SIZEinscsi_debug.
--- drivers/scsi/scsi_debug.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/scsi/scsi_debug.c +1 -7
@@ -8459,13 +8459,7 @@ static int __init scsi_debug_init(void) }else if (sdebug_ndelay >0 ) sdebug_jdelay =JDELAY_OVERRIDDEN ; -switch (sdebug_sector_size) { -case 512 : -case 1024 : -case 2048 : -case 4096 : -break ; -default : +if (blk_validate_block_size (sdebug_sector_size)) {pr_err ("invalid sector_size %d\n" , sdebug_sector_size);return -EINVAL ; }
Signature · 1 line
2.51.0
Quoted 10 lines · On 2025/12/09 17:41, [email protected] wrote:
From: Swarna Prabhu <[email protected]>
Hi All,
This is non RFC v1 series sent based on the feedback received on RFC v2 [1] and RFC v1 [2]. This patchset enables sector sizes >
PAGE_SIZEfor sd driver andscsi_debugdriver since block layer can support block size >PAGE_SIZE. There was one issue withwrite_same16andwrite_same10command, which is fixed as a part of the series.
Quoted 5 lines
Motivation:
- While enabling LBS on ZoneFS, zonefs-tools tests were being skipped for conventional zones when tested on nvme block device emulated using QEMU. Hence there was a need to enable scsi with higher sector sizes to run zonefs tests for conventional zones as well.
This is super confusing: there are no conventional zones with NVMe. And why would a problem with NVMe require scsi patches ?
Quoted 59 lines
Changes since RFC v2:
- Replaced open coded check for enablingsdebug_sector_size>PAGE_SIZEwithblk_validate_block_size()inscsi_debug.
- Replaced open coded check for enablingsector_size>PAGE_SIZEwithblk_validate_block_size()in sd driver.
- Replaced 'struct request *rq' argument in 'sd_set_special_bvec()' to 'structscsi_cmnd*cmnd' and used that to get SCSI device pointer 'structscsi_device*sdp'.
- Slightly modified the commit title for scsi sd driver fix patch.
- Added "Cc: [email protected]" tag to scsi sd driver fix patch.Changes since RFC v1:
- Re organized the patch series into one patch forscsi_debugdriver and one patch for sd driver.
- Updated commit title and description to accommodate the above re organization on commit titled - scsi: sd: fixwrite_same(16/10)to enable sector size >PAGE_SIZE.
- Updated commit title and description to reflect the re organization on commit titled - scsi:scsi_debug: enablesdebug_sector_sizeQuoted 1 line
PAGE_SIZE.Thanks to Bart for feedback on the RFC v1 and v2 series.
Testing:
-Test suite: xfs and generic from fstest + QEMU emulated block
device(scsi and nvme)
- fstest Config for patched xfs 16k block size [xfs_reflink_16k_scsi]TEST_DEV=/dev/sda SCRATCH_DEV_POOL="/dev/sdb" MKFS_OPTIONS='-f -m reflink=1,rmapbt=1, -i sparse=1, -b size=16384, -s size=16384'- Generic test results
Baseline: 6.18.0-rc7 kernel + nvme 16k logical block size
Patched: 6.18 kernel + scsi 16k logical block size
5 failures seen on generic tests and the same seen on baseline No regressions introduced by the patch.
- XFS tests results
Baseline: 6.18.0-rc7 kernel + nvme16k logical block size
Patched: 6.18 kernel + sci 16k logical block size
30 failures seen on patched and baseline
No regressions introduced by the patch
- Blktests results
scis and block layer tests with 16k and 32k logical block size. config used:
TEST_DEVS=(/dev/sda)
EXCLUDE=(block/010 block/011) # these didn't run on baseline(nvme 16k) All tests passed.Link to RFC v2: https://lore.kernel.org/all/[email protected]/ [1] Link to RFC v1: https://lore.kernel.org/all/[email protected]/ [2]
Swarna Prabhu (2):
scsi: sd: fixwrite_same(16/10)to enable sector size >PAGE_SIZE
scsi:scsi_debug: enablesdebug_sector_size>PAGE_SIZEdrivers/scsi/scsi_debug.c | 8 +------- drivers/scsi/sd.c | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-)
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 11 lines · Damien Le Moal
Quoted 10 lines · On 2025/12/09 17:41, [email protected] wrote:
From: Swarna Prabhu <[email protected]>
Hi All,
This is non RFC v1 series sent based on the feedback received on RFC v2 [1] and RFC v1 [2]. This patchset enables sector sizes >
PAGE_SIZEfor sd driver andscsi_debugdriver since block layer can support block size >PAGE_SIZE. There was one issue withwrite_same16andwrite_same10command, which is fixed as a part of the series.
Quoted 9 lines
Quoted 5 lines
Motivation:
- While enabling LBS on ZoneFS, zonefs-tools tests were being skipped for conventional zones when tested on nvme block device emulated using QEMU. Hence there was a need to enable scsi with higher sector sizes to run zonefs tests for conventional zones as well.This is super confusing: there are no conventional zones with NVMe. And why would a problem with NVMe require scsi patches ?
Agree with you. NVME Zoned Namespace require sequential writes.
Our initial goal was to enable LBS on Zonefs. Running zonefs tests on a scsi device covered both conventional and sequential zone based tests. So we had to enable higher sector sizes on scsi device and while doing so fix the issue seen with WRITE SAME commands with higher sector sizes.
Thanks
Swarna
Quoted 21 lines · Swarna Prabhu
Quoted 11 lines · Damien Le Moal
Quoted 10 lines · On 2025/12/09 17:41, [email protected] wrote:
From: Swarna Prabhu <[email protected]>
Hi All,
This is non RFC v1 series sent based on the feedback received on RFC v2 [1] and RFC v1 [2]. This patchset enables sector sizes >
PAGE_SIZEfor sd driver andscsi_debugdriver since block layer can support block size >PAGE_SIZE. There was one issue withwrite_same16andwrite_same10command, which is fixed as a part of the series.Quoted 9 lines
Quoted 5 lines
Motivation:
- While enabling LBS on ZoneFS, zonefs-tools tests were being skipped for conventional zones when tested on nvme block device emulated using QEMU. Hence there was a need to enable scsi with higher sector sizes to run zonefs tests for conventional zones as well.This is super confusing: there are no conventional zones with NVMe. And why would a problem with NVMe require scsi patches ?
Quoted 7 lines
Agree with you. NVME Zoned Namespace require sequential writes.
Our initial goal was to enable LBS on Zonefs. Running zonefs tests on a scsi device covered both conventional and sequential zone based tests. So we had to enable higher sector sizes on scsi device and while doing so fix the issue seen with WRITE SAME commands with higher sector sizes.
OK. Understood. But since this is in the end a scsi fix that is not directly related to zonefs (zonefs does not use write same), I think you can drop any mention of zonefs to avoid any confusion.
Signature · 2 lines
Damien Le Moal Western Digital Research