Skip to content

Commit a9aa604

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: pass a maxlen argument to bio_iov_iter_bounce
Allow the file system to limit the size processed in a single bounce operation. This is needed when generating integrity data so that the size of a single integrity segment can't overflow. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Anuj Gupta <[email protected]> Reviewed-by: Kanchan Joshi <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Tested-by: Anuj Gupta <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0bde8a1 commit a9aa604

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

block/bio.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,10 @@ static void bio_free_folios(struct bio *bio)
13271327
}
13281328
}
13291329

1330-
static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter)
1330+
static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
1331+
size_t maxlen)
13311332
{
1332-
size_t total_len = iov_iter_count(iter);
1333+
size_t total_len = min(maxlen, iov_iter_count(iter));
13331334

13341335
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
13351336
return -EINVAL;
@@ -1367,9 +1368,10 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter)
13671368
return 0;
13681369
}
13691370

1370-
static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter)
1371+
static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
1372+
size_t maxlen)
13711373
{
1372-
size_t len = min(iov_iter_count(iter), SZ_1M);
1374+
size_t len = min3(iov_iter_count(iter), maxlen, SZ_1M);
13731375
struct folio *folio;
13741376

13751377
folio = folio_alloc_greedy(GFP_KERNEL, &len);
@@ -1408,18 +1410,19 @@ static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter)
14081410
* bio_iov_iter_bounce - bounce buffer data from an iter into a bio
14091411
* @bio: bio to send
14101412
* @iter: iter to read from / write into
1413+
* @maxlen: maximum size to bounce
14111414
*
14121415
* Helper for direct I/O implementations that need to bounce buffer because
14131416
* we need to checksum the data or perform other operations that require
14141417
* consistency. Allocates folios to back the bounce buffer, and for writes
14151418
* copies the data into it. Needs to be paired with bio_iov_iter_unbounce()
14161419
* called on completion.
14171420
*/
1418-
int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter)
1421+
int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen)
14191422
{
14201423
if (op_is_write(bio_op(bio)))
1421-
return bio_iov_iter_bounce_write(bio, iter);
1422-
return bio_iov_iter_bounce_read(bio, iter);
1424+
return bio_iov_iter_bounce_write(bio, iter, maxlen);
1425+
return bio_iov_iter_bounce_read(bio, iter, maxlen);
14231426
}
14241427

14251428
static void bvec_unpin(struct bio_vec *bv, bool mark_dirty)

fs/iomap/direct-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
338338
bio->bi_end_io = iomap_dio_bio_end_io;
339339

340340
if (dio->flags & IOMAP_DIO_BOUNCE)
341-
ret = bio_iov_iter_bounce(bio, dio->submit.iter);
341+
ret = bio_iov_iter_bounce(bio, dio->submit.iter, BIO_MAX_SIZE);
342342
else
343343
ret = bio_iov_iter_get_pages(bio, dio->submit.iter,
344344
alignment - 1);

include/linux/bio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty);
474474
extern void bio_set_pages_dirty(struct bio *bio);
475475
extern void bio_check_pages_dirty(struct bio *bio);
476476

477-
int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter);
477+
int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen);
478478
void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty);
479479

480480
extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,

0 commit comments

Comments
 (0)