Skip to contentSkip to conversation

block: avoid scatterlist offsets > PAGE_SIZE

PATCH Applied Christoph Hellwig 4 participants 4 messages Apr 19, 2019 – Apr 22, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: avoid scatterlist offsets > PAGE_SIZE

While we generally allow scatterlists to have offsets larger than page size for an entry, and other subsystems like the crypto code make use of that, the block layer isn't quite ready for that. Flip the switch back to avoid them for now, and revisit that decision early in a merge window once the known offenders are fixed.

Fixes 8a96a0e40810 ("block: rewrite blk_bvec_map_sg to avoid a nth_page call")
---
 block/blk-merge.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
block/blk-merge.c +13 -1
index 247b17f2a0f6..21e87a714a73 100644
@@ -474,9 +474,21 @@ 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);
+		struct page *page = bvec->bv_page;
+
+		/*
+		 * Unfortunately a fair number of drivers barf on scatterlists
+		 * that have an offset larger than PAGE_SIZE, despite other
+		 * subsystems dealing with that invariant just fine.  For now
+		 * stick to the legacy format where we never present those from
+		 * the block layer, but the code below should be removed once
+		 * these offenders (mostly MMC/SD drivers) are fixed.
+		 */
+		page += (offset >> PAGE_SHIFT);
+		offset &= ~PAGE_MASK;
 
 		*sg = blk_next_sg(sg, sglist);
-		sg_set_page(*sg, bvec->bv_page, len, offset);
+		sg_set_page(*sg, page, len, offset);
 
 		total += len;
 		nbytes -= len;
Signature · 1 line
2.20.1
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Christoph Hellwig

While we generally allow scatterlists to have offsets larger than page size for an entry, and other subsystems like the crypto code make use of that, the block layer isn't quite ready for that. Flip the switch back to avoid them for now, and revisit that decision early in a merge window once the known offenders are fixed.

Fixes 8a96a0e40810 ("block: rewrite blk_bvec_map_sg to avoid a nth_page call")

(cautious)

Cautious because there are currently a number if crashes and runtime warnings in -next. I don't think any are related to the block code, but I may be wrong.

Guenter

Quoted 34 lines
---
 block/blk-merge.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
block/blk-merge.c +13 -1
index 247b17f2a0f6..21e87a714a73 100644
@@ -474,9 +474,21 @@ 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);
+		struct page *page = bvec->bv_page;
+
+		/*
+		 * Unfortunately a fair number of drivers barf on scatterlists
+		 * that have an offset larger than PAGE_SIZE, despite other
+		 * subsystems dealing with that invariant just fine.  For now
+		 * stick to the legacy format where we never present those from
+		 * the block layer, but the code below should be removed once
+		 * these offenders (mostly MMC/SD drivers) are fixed.
+		 */
+		page += (offset >> PAGE_SHIFT);
+		offset &= ~PAGE_MASK;
 
 		*sg = blk_next_sg(sg, sglist);
-		sg_set_page(*sg, bvec->bv_page, len, offset);
+		sg_set_page(*sg, page, len, offset);
 
 		total += len;
 		nbytes -= len;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 28 lines · Christoph Hellwig

While we generally allow scatterlists to have offsets larger than page size for an entry, and other subsystems like the crypto code make use of that, the block layer isn't quite ready for that. Flip the switch back to avoid them for now, and revisit that decision early in a merge window once the known offenders are fixed.

Fixes 8a96a0e40810 ("block: rewrite blk_bvec_map_sg to avoid a nth_page call")
---
 block/blk-merge.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
block/blk-merge.c +6 -0
index 247b17f2a0f6..21e87a714a73 100644
@@ -474,9 +474,21 @@ 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);
+               struct page *page = bvec->bv_page;
+
+               /*
+                * Unfortunately a fair number of drivers barf on scatterlists
+                * that have an offset larger than PAGE_SIZE, despite other
+                * subsystems dealing with that invariant just fine.  For now

block/blk-merge.c static unsigned blk_bvec_map_sg(struct request_queue *q, · line 491

Quoted 10 lines
block/blk-merge.c +7 -1
+                * stick to the legacy format where we never present those from
+                * the block layer, but the code below should be removed once
+                * these offenders (mostly MMC/SD drivers) are fixed.
+                */
+               page += (offset >> PAGE_SHIFT);
+               offset &= ~PAGE_MASK;
 
                *sg = blk_next_sg(sg, sglist);
-               sg_set_page(*sg, bvec->bv_page, len, offset);
+               sg_set_page(*sg, page, len, offset);
Signature · 1 line
Ming Lei
maintainer Applied
#3 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

While we generally allow scatterlists to have offsets larger than page size for an entry, and other subsystems like the crypto code make use of that, the block layer isn't quite ready for that. Flip the switch back to avoid them for now, and revisit that decision early in a merge window once the known offenders are fixed.

Applied, thanks.

Signature · 1 line
Jens Axboe