linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: fix splitting segments
@ 2019-12-29  2:32 Ming Lei
  2019-12-29 16:14 ` Jens Axboe
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Ming Lei @ 2019-12-29  2:32 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, Ming Lei

There are two issues in get_max_segment_size():

1) the default segment boudary mask is bypassed, and some devices still
require segment to not cross the default 4G boundary

2) the segment start address isn't taken into account when checking
segment boundary limit

Fixes the two issues.

Fixes: dcebd755926b ("block: use bio_for_each_bvec() to compute multi-page bvec count")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-merge.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index d783bdc4559b..234377d8146b 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -157,16 +157,14 @@ static inline unsigned get_max_io_size(struct request_queue *q,
 	return sectors & (lbs - 1);
 }
 
-static unsigned get_max_segment_size(const struct request_queue *q,
-				     unsigned offset)
+static inline unsigned get_max_segment_size(const struct request_queue *q,
+					    const struct page *start_page,
+					    unsigned long offset)
 {
 	unsigned long mask = queue_segment_boundary(q);
 
-	/* default segment boundary mask means no boundary limit */
-	if (mask == BLK_SEG_BOUNDARY_MASK)
-		return queue_max_segment_size(q);
-
-	return min_t(unsigned long, mask - (mask & offset) + 1,
+	offset = mask & (page_to_phys(start_page) + offset);
+	return min_t(unsigned long, mask - offset + 1,
 		     queue_max_segment_size(q));
 }
 
@@ -201,7 +199,8 @@ static bool bvec_split_segs(const struct request_queue *q,
 	unsigned seg_size = 0;
 
 	while (len && *nsegs < max_segs) {
-		seg_size = get_max_segment_size(q, bv->bv_offset + total_len);
+		seg_size = get_max_segment_size(q, bv->bv_page,
+						bv->bv_offset + total_len);
 		seg_size = min(seg_size, len);
 
 		(*nsegs)++;
@@ -419,7 +418,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q,
 
 	while (nbytes > 0) {
 		unsigned offset = bvec->bv_offset + total;
-		unsigned len = min(get_max_segment_size(q, offset), nbytes);
+		unsigned len = min(get_max_segment_size(q, bvec->bv_page,
+					offset), nbytes);
 		struct page *page = bvec->bv_page;
 
 		/*
-- 
2.20.1


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

end of thread, other threads:[~2020-01-11 12:57 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-29  2:32 [PATCH] block: fix splitting segments Ming Lei
2019-12-29 16:14 ` Jens Axboe
2019-12-30  1:15   ` Bart Van Assche
2019-12-30  1:25     ` Ming Lei
2020-01-07 12:47 ` Guenter Roeck
2020-01-07 15:23   ` Ming Lei
2020-01-07 18:11     ` Guenter Roeck
2020-01-07 22:30       ` Ming Lei
2020-01-07 22:32         ` Jens Axboe
2020-01-08  1:59           ` Ming Lei
2020-01-08  2:36             ` Jens Axboe
2020-01-07 23:06         ` Guenter Roeck
2020-01-08 14:02 ` Christoph Hellwig
2020-01-09  2:03   ` Ming Lei
2020-01-09  7:16     ` Christoph Hellwig
2020-01-09 15:18       ` Jens Axboe
2020-01-10  2:58         ` Ming Lei
2020-01-10  3:00           ` Ming Lei
2020-01-10  5:10             ` Guenter Roeck
2020-01-10  6:37               ` Ming Lei
2020-01-10  7:15                 ` Ming Lei
2020-01-10 12:48                   ` Guenter Roeck
2020-01-10 12:36                 ` Guenter Roeck
2020-01-11 12:57                   ` Ming Lei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).