All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: advance iov_iter on bio_add_hw_page failure
@ 2020-10-28  7:25 Naohiro Aota
  2020-10-28  8:45 ` Johannes Thumshirn
  2020-10-28 13:51 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Naohiro Aota @ 2020-10-28  7:25 UTC (permalink / raw)
  To: axboe, linux-block
  Cc: johannes.thumshirn, Damien.LeMoal, Naohiro Aota, stable

When the bio's size reaches max_append_sectors, bio_add_hw_page returns
0 then __bio_iov_append_get_pages returns -EINVAL. This is an expected
result of building a small enough bio not to be split in the IO path.
However, iov_iter is not advanced in this case, causing the same pages
are filled for the bio again and again.

Fix the case by properly advancing the iov_iter for already processed
pages.

Fixes: 0512a75b98f8 ("block: Introduce REQ_OP_ZONE_APPEND")
Cc: stable@vger.kernel.org # 5.8+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 block/bio.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index e0d41ccc4e90..2dfe40be4d6b 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1082,6 +1082,7 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
 	ssize_t size, left;
 	unsigned len, i;
 	size_t offset;
+	int ret = 0;
 
 	if (WARN_ON_ONCE(!max_append_sectors))
 		return 0;
@@ -1104,15 +1105,17 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
 
 		len = min_t(size_t, PAGE_SIZE - offset, left);
 		if (bio_add_hw_page(q, bio, page, len, offset,
-				max_append_sectors, &same_page) != len)
-			return -EINVAL;
+				max_append_sectors, &same_page) != len) {
+			ret = -EINVAL;
+			break;
+		}
 		if (same_page)
 			put_page(page);
 		offset = 0;
 	}
 
-	iov_iter_advance(iter, size);
-	return 0;
+	iov_iter_advance(iter, size - left);
+	return ret;
 }
 
 /**
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: advance iov_iter on bio_add_hw_page failure
  2020-10-28  7:25 [PATCH] block: advance iov_iter on bio_add_hw_page failure Naohiro Aota
@ 2020-10-28  8:45 ` Johannes Thumshirn
  2020-10-28 13:51 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2020-10-28  8:45 UTC (permalink / raw)
  To: Naohiro Aota, axboe, linux-block; +Cc: Damien Le Moal, stable

Thanks,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: advance iov_iter on bio_add_hw_page failure
  2020-10-28  7:25 [PATCH] block: advance iov_iter on bio_add_hw_page failure Naohiro Aota
  2020-10-28  8:45 ` Johannes Thumshirn
@ 2020-10-28 13:51 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-10-28 13:51 UTC (permalink / raw)
  To: Naohiro Aota, linux-block; +Cc: johannes.thumshirn, Damien.LeMoal, stable

On 10/28/20 1:25 AM, Naohiro Aota wrote:
> When the bio's size reaches max_append_sectors, bio_add_hw_page returns
> 0 then __bio_iov_append_get_pages returns -EINVAL. This is an expected
> result of building a small enough bio not to be split in the IO path.
> However, iov_iter is not advanced in this case, causing the same pages
> are filled for the bio again and again.
> 
> Fix the case by properly advancing the iov_iter for already processed
> pages.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-29  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28  7:25 [PATCH] block: advance iov_iter on bio_add_hw_page failure Naohiro Aota
2020-10-28  8:45 ` Johannes Thumshirn
2020-10-28 13:51 ` Jens Axboe

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.