Skip to content

Commit e8007fa

Browse files
ssiwinski-attomartinkpetersen
authored andcommitted
scsi: sd_zbc: block: Respect bio vector limits for REPORT ZONES buffer
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>
1 parent 0e9693b commit e8007fa

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

block/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask)
611611
{
612612
struct bio *bio;
613613

614-
if (nr_vecs > UIO_MAXIOV)
614+
if (nr_vecs > BIO_MAX_INLINE_VECS)
615615
return NULL;
616616
return kmalloc(struct_size(bio, bi_inline_vecs, nr_vecs), gfp_mask);
617617
}

drivers/scsi/sd_zbc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
169169
unsigned int nr_zones, size_t *buflen)
170170
{
171171
struct request_queue *q = sdkp->disk->queue;
172+
unsigned int max_segments;
172173
size_t bufsize;
173174
void *buf;
174175

@@ -180,12 +181,15 @@ static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
180181
* Furthermore, since the report zone command cannot be split, make
181182
* sure that the allocated buffer can always be mapped by limiting the
182183
* number of pages allocated to the HBA max segments limit.
184+
* Since max segments can be larger than the max inline bio vectors,
185+
* further limit the allocated buffer to BIO_MAX_INLINE_VECS.
183186
*/
184187
nr_zones = min(nr_zones, sdkp->zone_info.nr_zones);
185188
bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
186189
bufsize = min_t(size_t, bufsize,
187190
queue_max_hw_sectors(q) << SECTOR_SHIFT);
188-
bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
191+
max_segments = min(BIO_MAX_INLINE_VECS, queue_max_segments(q));
192+
bufsize = min_t(size_t, bufsize, max_segments << PAGE_SHIFT);
189193

190194
while (bufsize >= SECTOR_SIZE) {
191195
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)