enable sector size > PAGE_SIZE for scsi
cover enable sector size > PAGE_SIZE for scsi
From: Swarna Prabhu <[email protected]>
Hi All,
Now that block layer can support block size > PAGE_SIZE, enable the same for scsi devices. There was one issue with write_same16 and write_same10 command, which is fixed as a part of the series.
Testing:
1. 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-rc5 kernel + nvme 16k logical block size
Patched: 6.18-rc5 kernel + scsi 16k logical block size
6 failures seen on generic tests and the same seen on baseline No regressions
- XFS tests results
Baseline: 6.18-rc6 kernel + nvme16k logical block size
Patched: 6.18-rc6 kernel + sci 16k logical block size
198 failures seen on patched and baseline
No regressions
- Tests similar to above was run on 32k logical block size
No regressions seen on xfs tests.
Generic/778 (add sudden shutdown tests for multi block atomic writes )test is failing on scsi 32k block size due to atomic write taking too long to start, but is passing on the nvme 32k block size setup. Since sysfs shows atomic write granularity not enforced for scsi device it seems that XFS issues atomic writes slower. Upon increasing the wait timeout from 10s to 40s for the first atomic write in 'start_atomic_write_and_shutdown' generic/778 seems to pass for 32k scsi sector size.
2. blktests: scsi and block layer sub tests
Baseline: tests with scsi 4k block size
Patched: tests with patched kernel + 16k scsi block size
- scsi tests - no regressions.
- block tests - Disabled block/010 and block/011
Hard to reproduce(sporadic) kernel hang seen while running block layer tests ie at block/003 due to fio task being blocked by a mutex held by udev event. Not seen while running it individually.
Rootcause - block/001 stress the scsi debug devices by adding, tearing, removing the devices in parallel that triggers udevs. This races with fio task triggered by block/003. Added udevadm settle and small delay between block/001 and block/003 fixes this and using this as a temporary fix, while we continue to evaluate. Note: block/002 being skipped.
Swarna Prabhu (2):
scsi: fix write_same16 and write_same10 for sector size > PAGE_SIZE
scsi: enable sector_size > PAGE_SIZE
drivers/scsi/scsi_debug.c | 9 ++------- drivers/scsi/sd.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 scsi: fix write_same16 and write_same10 for 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.
---
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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +11 -2
@@ -895,11 +895,20 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) {struct page *page; +struct scsi_device *sdp =scsi_disk (rq->q->disk)->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);
@@ -4368,7 +4377,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: fix write_same16 and write_same10 for sector size > PAGE_SIZE
Quoted 27 lines · On 12/1/25 4:15 PM, [email protected] wrote:
drivers/scsi/sd.c +10
-1@@ -895,11 +895,20 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) {struct page *page; +struct scsi_device *sdp =scsi_disk (rq->q->disk)->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);
drivers/scsi/sd.c static int __init init_sd(void) · line 4383
Quoted 8 lines
drivers/scsi/sd.c +1
-1@@ -4368,7 +4377,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 ;
Have the above changes been tested? I don't see any changes for this code from drivers/scsi/sd.c:
if (sector_size != 512 &&
sector_size != 1024 &&
sector_size != 2048 &&
sector_size != 4096) {
sd_printk(KERN_NOTICE, sdkp, "Unsupported sector size %d.\n",
sector_size);
[ ... ]
}Thanks,
Bart.
Re: [PATCH 1/2] scsi: fix write_same16 and write_same10 for sector size > PAGE_SIZE
Quoted 28 lines · Bart Van Assche
Quoted 27 lines · On 12/1/25 4:15 PM, [email protected] wrote:
drivers/scsi/sd.c +10
-1@@ -895,11 +895,20 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim,static void *sd_set_special_bvec (struct request *rq,unsigned int data_len) {struct page *page; +struct scsi_device *sdp =scsi_disk (rq->q->disk)->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);@@ -4368,7 +4377,7 @@ static int __init init_sd(void)if (err)
Quoted 8 lines
drivers/scsi/sd.c static int __init init_sd(void) · line 4383
Quoted 6 lines
drivers/scsi/sd.c +1
-1goto 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 ;Have the above changes been tested?
Yes, the test details are included in the cover letter
Thanks
Swarna
PATCH 2/2 scsi: enable 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 sector sizes
Quoted 1 line
PAGE_SIZEin scsi andscsi_debug.
--- drivers/scsi/scsi_debug.c | 9 ++------- drivers/scsi/sd.c | 6 ++---- 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/scsi/scsi_debug.c +2 -7
@@ -8459,13 +8459,8 @@ 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 (sdebug_sector_size <512 || sdebug_sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sdebug_sector_size)) {pr_err ("invalid sector_size %d\n" , sdebug_sector_size);return -EINVAL ; }
drivers/scsi/sd.c +2 -4
@@ -2889,10 +2889,8 @@ 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 (sector_size <512 || sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/*
Signature · 1 line
2.51.0
Re: [PATCH 2/2] scsi: enable sector_size > PAGE_SIZE
Quoted 27 lines · On 12/1/25 4:15 PM, [email protected] wrote:
drivers/scsi/scsi_debug.c +2
-7@@ -8459,13 +8459,8 @@ 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 (sdebug_sector_size <512 || sdebug_sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sdebug_sector_size)) {pr_err ("invalid sector_size %d\n" , sdebug_sector_size);return -EINVAL ; }drivers/scsi/sd.c +0
-0@@ -2889,10 +2889,8 @@ sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, "assuming 512.\n"); }
drivers/scsi/sd.c sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, · line 2896
Quoted 10 lines
drivers/scsi/sd.c +2
-4-if (sector_size !=512 && - sector_size !=1024 && - sector_size !=2048 && - sector_size !=4096 ) { +if (sector_size <512 || sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/*
Please reorganize this patch series into one patch for the scsi_debug driver and another patch for the sd driver.
Thanks,
Bart.
Re: [PATCH 2/2] scsi: enable sector_size > PAGE_SIZE
Quoted 31 lines · Bart Van Assche
Quoted 30 lines · On 12/1/25 4:15 PM, [email protected] wrote:
drivers/scsi/scsi_debug.c +2
-7@@ -8459,13 +8459,8 @@ 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 (sdebug_sector_size <512 || sdebug_sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sdebug_sector_size)) {pr_err ("invalid sector_size %d\n" , sdebug_sector_size);return -EINVAL ; }drivers/scsi/sd.c +0
-4@@ -2889,10 +2889,8 @@ 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 ) {
Quoted 9 lines
drivers/scsi/sd.c sd_read_capacity(struct scsi_disk *sdkp, struct queue_limits *lim, · line 2896
Quoted 5 lines
drivers/scsi/sd.c +2
-0+if (sector_size <512 || sector_size >BLK_MAX_BLOCK_SIZE || + !is_power_of_2 (sector_size)) {sd_printk (KERN_NOTICE , sdkp,"Unsupported sector size %d.\n" , sector_size);/* Please reorganize this patch series into one patch for the
scsi_debugdriver and another patch for the sd driver.
Sure, will do.
Thanks
Swarna