All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: John Garry <john.g.garry@oracle.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	linux-block@vger.kernel.org
Subject: [PATCH 3/3] block: improve aligning down bios in bio_iov_iter_bounce_write
Date: Mon,  7 Sep 2026 10:40:54 +0300	[thread overview]
Message-ID: <20260907074111.721054-4-hch@lst.de> (raw)
In-Reply-To: <20260907074111.721054-1-hch@lst.de>

Sashiko complained about bio_iov_iter_align_down potentially dropping
bvecs, and thus losing bounce folios.  While losing bio_vecs is real,
bio_iov_iter_bounce_write allocates all segments and thus the entire bio
in multiples of the minsize, thus making the rounding down redundant.

Replace it with a safety rounding down of this_len in case something odd
happens to the greedy folio allocation helper.

Fixes: e7b8b3c5b2a6 ("block: align down bounces bios")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/bio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index f95b63c0604a..57ee335899f3 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1389,6 +1389,14 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
 		folio = folio_alloc_greedy(GFP_KERNEL, &this_len, minsize);
 		if (!folio)
 			break;
+
+		/*
+		 * Align down the size to the minimum alignment.  In practice
+		 * this should not happen as minsize is expected to be a power
+		 * of two, as is the allocation size, but it offers us a cheap
+		 * extra safety belt.
+		 */
+		this_len &= ~(minsize - 1);
 		bio_add_folio_nofail(bio, folio, this_len, 0);
 
 		if (iter->nofault)
@@ -1416,8 +1424,7 @@ static int bio_iov_iter_bounce_write(struct bio *bio, struct iov_iter *iter,
 
 	if (!bio->bi_iter.bi_size)
 		return -ENOMEM;
-	return bio_iov_iter_align_down(bio, iter,
-			&bio->bi_io_vec[bio->bi_vcnt - 1], minsize - 1);
+	return 0;
 }
 
 static int bio_iov_iter_bounce_read(struct bio *bio, struct iov_iter *iter,
-- 
2.53.0


  parent reply	other threads:[~2026-09-07  7:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  7:40 misc block PI / bounce buffering fixes Christoph Hellwig
2026-09-07  7:40 ` [PATCH 1/3] block: avoid integer overflows in max_integrity_io_size Christoph Hellwig
2026-09-07  7:40 ` [PATCH 2/3] block: cap atomic write size by PI buffer size constraints Christoph Hellwig
2026-09-07  8:09   ` John Garry
2026-09-07  8:46     ` Christoph Hellwig
2026-09-07  9:19       ` John Garry
2026-09-09  2:44         ` Martin K. Petersen
2026-09-09  7:52           ` John Garry
2026-09-09  9:16   ` John Garry
2026-09-10  5:36     ` Christoph Hellwig
2026-09-10  8:45       ` John Garry
2026-09-10 12:52         ` John Garry
2026-09-10 14:43           ` John Garry
2026-09-07  7:40 ` Christoph Hellwig [this message]
2026-09-09  2:47 ` misc block PI / bounce buffering fixes Martin K. Petersen (Oracle)
2026-09-11 16:41 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260907074111.721054-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=john.g.garry@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mkp@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.