Skip to content

Commit f3a7dc5

Browse files
ssiwinski-attoopsiff
authored andcommitted
scsi: sd_zbc: block: Respect bio vector limits for REPORT ZONES buffer
commit e8007fa upstream. The REPORT ZONES buffer size is currently limited by the HBA's maximum segment count to ensure the buffer can be mapped. However, the block layer further limits the number of iovec entries to 1024 when allocating a bio. To avoid allocation of buffers too large to be mapped, further restrict the maximum buffer size to BIO_MAX_INLINE_VECS. Replace the UIO_MAXIOV symbolic name with the more contextually appropriate BIO_MAX_INLINE_VECS. Fixes: b091ac6 ("sd_zbc: Fix report zones buffer allocation") Cc: stable@vger.kernel.org Signed-off-by: Steve Siwinski <ssiwinski@atto.com> Link: https://lore.kernel.org/r/20250508200122.243129-1-ssiwinski@atto.com Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit c682a193447a0f2743b3192a9dfe1272dcc98f31)
1 parent 7eddddf commit f3a7dc5

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

block/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask)
600600
{
601601
struct bio *bio;
602602

603-
if (nr_vecs > UIO_MAXIOV)
603+
if (nr_vecs > BIO_MAX_INLINE_VECS)
604604
return NULL;
605605
return kmalloc(struct_size(bio, bi_inline_vecs, nr_vecs), gfp_mask);
606606
}

drivers/scsi/sd_zbc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
202202
unsigned int nr_zones, size_t *buflen)
203203
{
204204
struct request_queue *q = sdkp->disk->queue;
205+
unsigned int max_segments;
205206
size_t bufsize;
206207
void *buf;
207208

@@ -213,12 +214,15 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
213214
* Furthermore, since the report zone command cannot be split, make
214215
* sure that the allocated buffer can always be mapped by limiting the
215216
* number of pages allocated to the HBA max segments limit.
217+
* Since max segments can be larger than the max inline bio vectors,
218+
* further limit the allocated buffer to BIO_MAX_INLINE_VECS.
216219
*/
217220
nr_zones = min(nr_zones, sdkp->zone_info.nr_zones);
218221
bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
219222
bufsize = min_t(size_t, bufsize,
220223
queue_max_hw_sectors(q) << SECTOR_SHIFT);
221-
bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
224+
max_segments = min(BIO_MAX_INLINE_VECS, queue_max_segments(q));
225+
bufsize = min_t(size_t, bufsize, max_segments << PAGE_SHIFT);
222226

223227
while (bufsize >= SECTOR_SIZE) {
224228
buf = kvzalloc(bufsize, GFP_KERNEL | __GFP_NORETRY);

include/linux/bio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/uio.h>
1212

1313
#define BIO_MAX_VECS 256U
14+
#define BIO_MAX_INLINE_VECS UIO_MAXIOV
1415

1516
struct queue_limits;
1617

0 commit comments

Comments
 (0)