summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2020-08-17 20:52:06 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-09-03 11:26:54 +0200
commit2295664518c381ca422e95f2ca3a23f4bd06a711 (patch)
tree29602a8e30e3a053929ffec5bc53c90602fbd154
parent3e9eb1e893ba5a71d472be4a34644526b366a536 (diff)
downloadlinux-stable-2295664518c381ca422e95f2ca3a23f4bd06a711.tar.gz
linux-stable-2295664518c381ca422e95f2ca3a23f4bd06a711.tar.bz2
linux-stable-2295664518c381ca422e95f2ca3a23f4bd06a711.zip
block: Fix page_is_mergeable() for compound pages
[ Upstream commit d81665198b83e55a28339d1f3e4890ed8a434556 ] If we pass in an offset which is larger than PAGE_SIZE, then page_is_mergeable() thinks it's not mergeable with the previous bio_vec, leading to a large number of bio_vecs being used. Use a slightly more obvious test that the two pages are compatible with each other. Fixes: 52d52d1c98a9 ("block: only allow contiguous page structs in a bio_vec") Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--block/bio.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/block/bio.c b/block/bio.c
index 94d697217887..87505a93bcff 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -683,8 +683,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
struct page *page, unsigned int len, unsigned int off,
bool *same_page)
{
- phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
- bv->bv_offset + bv->bv_len - 1;
+ size_t bv_end = bv->bv_offset + bv->bv_len;
+ phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) + bv_end - 1;
phys_addr_t page_addr = page_to_phys(page);
if (vec_end_addr + 1 != page_addr + off)
@@ -693,9 +693,9 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
return false;
*same_page = ((vec_end_addr & PAGE_MASK) == page_addr);
- if (!*same_page && pfn_to_page(PFN_DOWN(vec_end_addr)) + 1 != page)
- return false;
- return true;
+ if (*same_page)
+ return true;
+ return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
}
static bool bio_try_merge_pc_page(struct request_queue *q, struct bio *bio,