Skip to content

Commit e8f3eef

Browse files
naotagregkh
authored andcommitted
block: advance iov_iter on bio_add_hw_page failure
commit 4977d12 upstream. 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: 0512a75 ("block: Introduce REQ_OP_ZONE_APPEND") Cc: stable@vger.kernel.org # 5.8+ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bd353d5 commit e8f3eef

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎block/bio.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
10461046
ssize_t size, left;
10471047
unsigned len, i;
10481048
size_t offset;
1049+
int ret = 0;
10491050

10501051
if (WARN_ON_ONCE(!max_append_sectors))
10511052
return 0;
@@ -1068,15 +1069,17 @@ static int __bio_iov_append_get_pages(struct bio *bio, struct iov_iter *iter)
10681069

10691070
len = min_t(size_t, PAGE_SIZE - offset, left);
10701071
if (bio_add_hw_page(q, bio, page, len, offset,
1071-
max_append_sectors, &same_page) != len)
1072-
return -EINVAL;
1072+
max_append_sectors, &same_page) != len) {
1073+
ret = -EINVAL;
1074+
break;
1075+
}
10731076
if (same_page)
10741077
put_page(page);
10751078
offset = 0;
10761079
}
10771080

1078-
iov_iter_advance(iter, size);
1079-
return 0;
1081+
iov_iter_advance(iter, size - left);
1082+
return ret;
10801083
}
10811084

10821085
/**

0 commit comments

Comments
 (0)