* [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE
@ 2025-12-03 23:05 sw.prabhu6
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: sw.prabhu6 @ 2025-12-03 23:05 UTC (permalink / raw)
To: James.Bottomley, martin.petersen, linux-scsi, bvanassche
Cc: linux-kernel, mcgrof, kernel, Swarna Prabhu, Swarna Prabhu,
Pankaj Raghav
From: Swarna Prabhu <sw.prabhu6@gmail.com>
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.
Signed-off-by: Swarna Prabhu <s.prabhu@samsung.com>
Co-developed-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
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 device is attached at sd_probe
and it might be too late to re allocate mempool with
order > 0.
drivers/scsi/sd.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 0252d3f6bed1..f2eac79d7263 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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);
@@ -2880,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);
/*
@@ -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;
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size > PAGE_SIZE
2025-12-03 23:05 [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE sw.prabhu6
@ 2025-12-03 23:05 ` sw.prabhu6
2025-12-04 1:40 ` Luis Chamberlain
2025-12-04 2:02 ` Bart Van Assche
2025-12-04 1:39 ` [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size " Luis Chamberlain
` (2 subsequent siblings)
3 siblings, 2 replies; 7+ messages in thread
From: sw.prabhu6 @ 2025-12-03 23:05 UTC (permalink / raw)
To: James.Bottomley, martin.petersen, linux-scsi, bvanassche
Cc: linux-kernel, mcgrof, kernel, Swarna Prabhu, Swarna Prabhu
From: Swarna Prabhu <sw.prabhu6@gmail.com>
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
> PAGE_SIZE in scsi_debug.
Signed-off-by: Swarna Prabhu <s.prabhu@samsung.com>
---
drivers/scsi/scsi_debug.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index b2ab97be5db3..b5839e62d3bb 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -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;
}
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE
2025-12-03 23:05 [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE sw.prabhu6
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
@ 2025-12-04 1:39 ` Luis Chamberlain
2025-12-04 1:59 ` Bart Van Assche
2025-12-04 2:03 ` Bart Van Assche
3 siblings, 0 replies; 7+ messages in thread
From: Luis Chamberlain @ 2025-12-04 1:39 UTC (permalink / raw)
To: sw.prabhu6
Cc: James.Bottomley, martin.petersen, linux-scsi, bvanassche,
linux-kernel, kernel, Swarna Prabhu, Pankaj Raghav
On Wed, Dec 03, 2025 at 11:05:46PM +0000, sw.prabhu6@gmail.com wrote:
> From: Swarna Prabhu <sw.prabhu6@gmail.com>
>
> 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.
>
> Signed-off-by: Swarna Prabhu <s.prabhu@samsung.com>
> Co-developed-by: Pankaj Raghav <p.raghav@samsung.com>
> Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Just missing the Cc stable # v6.15 tag. Other than that:
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size > PAGE_SIZE
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
@ 2025-12-04 1:40 ` Luis Chamberlain
2025-12-04 2:02 ` Bart Van Assche
1 sibling, 0 replies; 7+ messages in thread
From: Luis Chamberlain @ 2025-12-04 1:40 UTC (permalink / raw)
To: sw.prabhu6
Cc: James.Bottomley, martin.petersen, linux-scsi, bvanassche,
linux-kernel, kernel, Swarna Prabhu
On Wed, Dec 03, 2025 at 11:05:47PM +0000, sw.prabhu6@gmail.com wrote:
> From: Swarna Prabhu <sw.prabhu6@gmail.com>
>
> 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
> > PAGE_SIZE in scsi_debug.
>
> Signed-off-by: Swarna Prabhu <s.prabhu@samsung.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Luis
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE
2025-12-03 23:05 [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE sw.prabhu6
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
2025-12-04 1:39 ` [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size " Luis Chamberlain
@ 2025-12-04 1:59 ` Bart Van Assche
2025-12-04 2:03 ` Bart Van Assche
3 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2025-12-04 1:59 UTC (permalink / raw)
To: sw.prabhu6, James.Bottomley, martin.petersen, linux-scsi
Cc: linux-kernel, mcgrof, kernel, Swarna Prabhu, Pankaj Raghav
On 12/3/25 1:05 PM, sw.prabhu6@gmail.com wrote:
> 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;
Instead of using this cumbersome approach to obtain the SCSI device
pointer, I recommend to change the 'struct request *rq' argument into
'struct scsi_cmnd *cmd' and to obtain the SCSI device pointer as
follows:
struct scsi_device *sdp = cmd->device;
Otherwise this patch looks good to me.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size > PAGE_SIZE
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
2025-12-04 1:40 ` Luis Chamberlain
@ 2025-12-04 2:02 ` Bart Van Assche
1 sibling, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2025-12-04 2:02 UTC (permalink / raw)
To: sw.prabhu6, James.Bottomley, martin.petersen, linux-scsi
Cc: linux-kernel, mcgrof, kernel, Swarna Prabhu
On 12/3/25 1:05 PM, sw.prabhu6@gmail.com wrote:
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index b2ab97be5db3..b5839e62d3bb 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -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;
> }
Please use blk_validate_block_size() instead of open-coding it.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE
2025-12-03 23:05 [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE sw.prabhu6
` (2 preceding siblings ...)
2025-12-04 1:59 ` Bart Van Assche
@ 2025-12-04 2:03 ` Bart Van Assche
3 siblings, 0 replies; 7+ messages in thread
From: Bart Van Assche @ 2025-12-04 2:03 UTC (permalink / raw)
To: sw.prabhu6, James.Bottomley, martin.petersen, linux-scsi
Cc: linux-kernel, mcgrof, kernel, Swarna Prabhu, Pankaj Raghav
On 12/3/25 1:05 PM, sw.prabhu6@gmail.com wrote:
> - 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 use blk_validate_block_size() instead of open-coding it.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-04 2:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-03 23:05 [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size > PAGE_SIZE sw.prabhu6
2025-12-03 23:05 ` [RFC v2 2/2] scsi: scsi_debug: enable sdebug_sector_size " sw.prabhu6
2025-12-04 1:40 ` Luis Chamberlain
2025-12-04 2:02 ` Bart Van Assche
2025-12-04 1:39 ` [RFC v2 1/2] scsi: sd: fix write_same16 and write_same10 for sector size " Luis Chamberlain
2025-12-04 1:59 ` Bart Van Assche
2025-12-04 2:03 ` 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
all inboxes | Powered by JetHome®