* [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
@ 2021-09-06 14:06 Naohiro Aota
2021-09-06 14:09 ` Johannes Thumshirn
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Naohiro Aota @ 2021-09-06 14:06 UTC (permalink / raw)
To: linux-scsi; +Cc: Damien Le Moal, jejb, martin.petersen, Naohiro Aota
Reporting zones on a SCSI device sometimes fail with the following error.
[76248.516390] ata16.00: invalid transfer count 131328
[76248.523618] sd 15:0:0:0: [sda] REPORT ZONES start lba 536870912 failed
The error (from drivers/ata/libata-scsi.c ata_scsi_zbc_in_xlat())
indicates that buffer size is not aligned to SECTOR_SIZE.
This happens when the __vmalloc() failed. Consider we are reporting 4096
zones, then we will have "bufsize = roundup((4096 + 1) * 64,
SECTOR_SIZE)" = (513 * 512) = 262656. Then, __vmalloc() failure halven
the bufsize to 131328, which is no longer aligned to SECTOR_SIZE.
Use rounddown() to ensure the size is always aligned to SECTOR_SIZE and
fix the comment as well.
Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()")
Cc: stable@vger.kernel.org # 5.5+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
drivers/scsi/sd_zbc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index 186b5ff52c3a..ea8b3f6ee5cd 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -154,8 +154,8 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
/*
* Report zone buffer size should be at most 64B times the number of
- * zones requested plus the 64B reply header, but should be at least
- * SECTOR_SIZE for ATA devices.
+ * zones requested plus the 64B reply header, but should be aligned
+ * to SECTOR_SIZE for ATA devices.
* Make sure that this size does not exceed the hardware capabilities.
* Furthermore, since the report zone command cannot be split, make
* sure that the allocated buffer can always be mapped by limiting the
@@ -174,7 +174,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
*buflen = bufsize;
return buf;
}
- bufsize >>= 1;
+ bufsize = rounddown(bufsize >> 1, SECTOR_SIZE);
}
return NULL;
--
2.33.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
2021-09-06 14:06 [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE Naohiro Aota
@ 2021-09-06 14:09 ` Johannes Thumshirn
2021-09-06 22:32 ` Damien Le Moal
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2021-09-06 14:09 UTC (permalink / raw)
To: Naohiro Aota, linux-scsi; +Cc: Damien Le Moal, jejb, martin.petersen
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
2021-09-06 14:06 [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE Naohiro Aota
2021-09-06 14:09 ` Johannes Thumshirn
@ 2021-09-06 22:32 ` Damien Le Moal
2021-09-08 14:22 ` Himanshu Madhani
2021-09-14 3:43 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2021-09-06 22:32 UTC (permalink / raw)
To: Naohiro Aota, linux-scsi; +Cc: jejb, martin.petersen
On 2021/09/06 23:06, Naohiro Aota wrote:
> Reporting zones on a SCSI device sometimes fail with the following error.
>
> [76248.516390] ata16.00: invalid transfer count 131328
> [76248.523618] sd 15:0:0:0: [sda] REPORT ZONES start lba 536870912 failed
>
> The error (from drivers/ata/libata-scsi.c ata_scsi_zbc_in_xlat())
> indicates that buffer size is not aligned to SECTOR_SIZE.
>
> This happens when the __vmalloc() failed. Consider we are reporting 4096
> zones, then we will have "bufsize = roundup((4096 + 1) * 64,
> SECTOR_SIZE)" = (513 * 512) = 262656. Then, __vmalloc() failure halven
> the bufsize to 131328, which is no longer aligned to SECTOR_SIZE.
>
> Use rounddown() to ensure the size is always aligned to SECTOR_SIZE and
> fix the comment as well.
>
> Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()")
> Cc: stable@vger.kernel.org # 5.5+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
> drivers/scsi/sd_zbc.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index 186b5ff52c3a..ea8b3f6ee5cd 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -154,8 +154,8 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
>
> /*
> * Report zone buffer size should be at most 64B times the number of
> - * zones requested plus the 64B reply header, but should be at least
> - * SECTOR_SIZE for ATA devices.
> + * zones requested plus the 64B reply header, but should be aligned
> + * to SECTOR_SIZE for ATA devices.
> * Make sure that this size does not exceed the hardware capabilities.
> * Furthermore, since the report zone command cannot be split, make
> * sure that the allocated buffer can always be mapped by limiting the
> @@ -174,7 +174,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
> *buflen = bufsize;
> return buf;
> }
> - bufsize >>= 1;
> + bufsize = rounddown(bufsize >> 1, SECTOR_SIZE);
> }
>
> return NULL;
>
Good catch ! My bad :)
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
2021-09-06 14:06 [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE Naohiro Aota
2021-09-06 14:09 ` Johannes Thumshirn
2021-09-06 22:32 ` Damien Le Moal
@ 2021-09-08 14:22 ` Himanshu Madhani
2021-09-14 3:43 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Himanshu Madhani @ 2021-09-08 14:22 UTC (permalink / raw)
To: Naohiro Aota
Cc: linux-scsi, Damien Le Moal, James E.J. Bottomley, Martin Petersen
> On Sep 6, 2021, at 9:06 AM, Naohiro Aota <naohiro.aota@wdc.com> wrote:
>
> Reporting zones on a SCSI device sometimes fail with the following error.
>
> [76248.516390] ata16.00: invalid transfer count 131328
> [76248.523618] sd 15:0:0:0: [sda] REPORT ZONES start lba 536870912 failed
>
> The error (from drivers/ata/libata-scsi.c ata_scsi_zbc_in_xlat())
> indicates that buffer size is not aligned to SECTOR_SIZE.
>
> This happens when the __vmalloc() failed. Consider we are reporting 4096
> zones, then we will have "bufsize = roundup((4096 + 1) * 64,
> SECTOR_SIZE)" = (513 * 512) = 262656. Then, __vmalloc() failure halven
> the bufsize to 131328, which is no longer aligned to SECTOR_SIZE.
>
> Use rounddown() to ensure the size is always aligned to SECTOR_SIZE and
> fix the comment as well.
>
> Fixes: 23a50861adda ("scsi: sd_zbc: Cleanup sd_zbc_alloc_report_buffer()")
> Cc: stable@vger.kernel.org # 5.5+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
> drivers/scsi/sd_zbc.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index 186b5ff52c3a..ea8b3f6ee5cd 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -154,8 +154,8 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
>
> /*
> * Report zone buffer size should be at most 64B times the number of
> - * zones requested plus the 64B reply header, but should be at least
> - * SECTOR_SIZE for ATA devices.
> + * zones requested plus the 64B reply header, but should be aligned
> + * to SECTOR_SIZE for ATA devices.
> * Make sure that this size does not exceed the hardware capabilities.
> * Furthermore, since the report zone command cannot be split, make
> * sure that the allocated buffer can always be mapped by limiting the
> @@ -174,7 +174,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
> *buflen = bufsize;
> return buf;
> }
> - bufsize >>= 1;
> + bufsize = rounddown(bufsize >> 1, SECTOR_SIZE);
> }
>
> return NULL;
> --
> 2.33.0
>
Makes sense.
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
--
Himanshu Madhani Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
2021-09-06 14:06 [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE Naohiro Aota
` (2 preceding siblings ...)
2021-09-08 14:22 ` Himanshu Madhani
@ 2021-09-14 3:43 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-09-14 3:43 UTC (permalink / raw)
To: Naohiro Aota, linux-scsi; +Cc: Martin K . Petersen, Damien Le Moal, jejb
On Mon, 6 Sep 2021 23:06:42 +0900, Naohiro Aota wrote:
> Reporting zones on a SCSI device sometimes fail with the following error.
>
> [76248.516390] ata16.00: invalid transfer count 131328
> [76248.523618] sd 15:0:0:0: [sda] REPORT ZONES start lba 536870912 failed
>
> The error (from drivers/ata/libata-scsi.c ata_scsi_zbc_in_xlat())
> indicates that buffer size is not aligned to SECTOR_SIZE.
>
> [...]
Applied to 5.15/scsi-fixes, thanks!
[1/1] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE
https://git.kernel.org/mkp/scsi/c/7215e909814f
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-14 3:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 14:06 [PATCH] scsi: sd_zbc: ensure buffer size is aligned to SECTOR_SIZE Naohiro Aota
2021-09-06 14:09 ` Johannes Thumshirn
2021-09-06 22:32 ` Damien Le Moal
2021-09-08 14:22 ` Himanshu Madhani
2021-09-14 3:43 ` Martin K. Petersen
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.