Skip to contentSkip to conversation

Fix panic in 2.6 with bounced bio and dm

PATCH In review Mark Haverkamp 5 participants 13 messages Feb 25, 2005 – Feb 28, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix panic in 2.6 with bounced bio and dm

Last September a fix was checked in for a memory leak problem in bounce_end_io causing the entire bio to be checked. This ended up causing some dm cloned bios that had bounce buffers to free NULL pages
because their bi_idx can be non-zero. This patch skips NULL pages in
the bio's bio_vec. I'm not sure if this is the most optimal fix but I think that it is safe since bvec_alloc memsets the bio_vec to zero.

Mark.

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -319,7 +319,7 @@
 	 */
 	__bio_for_each_segment(bvec, bio, i, 0) {
 		org_vec = bio_orig->bi_io_vec + i;
-		if (bvec->bv_page == org_vec->bv_page)
+		if (!bvec->bv_page || bvec->bv_page == org_vec->bv_page)
 			continue;
 
 		mempool_free(bvec->bv_page, pool);	
Signature · 1 line
Mark Haverkamp <[email protected]>
#1 lore raw
Quoted 8 lines · Mark Haverkamp

Last September a fix was checked in for a memory leak problem in bounce_end_io causing the entire bio to be checked. This ended up causing some dm cloned bios that had bounce buffers to free NULL pages
because their bi_idx can be non-zero. This patch skips NULL pages in
the bio's bio_vec. I'm not sure if this is the most optimal fix but I think that it is safe since bvec_alloc memsets the bio_vec to zero.

Mark.

I forgot a signed-off-by

Signed-off-by Mark Haverkamp <[email protected]>

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -319,7 +319,7 @@
 	 */
 	__bio_for_each_segment(bvec, bio, i, 0) {
 		org_vec = bio_orig->bi_io_vec + i;
-		if (bvec->bv_page == org_vec->bv_page)
+		if (!bvec->bv_page || bvec->bv_page == org_vec->bv_page)
 			continue;
 
 		mempool_free(bvec->bv_page, pool);	
Signature · 1 line
Mark Haverkamp <[email protected]>
#2 lore raw
In reply to Mark Haverkamp
Quoted 9 lines · Mark Haverkamp

Last September a fix was checked in for a memory leak problem in bounce_end_io causing the entire bio to be checked. This ended up causing some dm cloned bios that had bounce buffers to free NULL pages
because their bi_idx can be non-zero. This patch skips NULL pages in
the bio's bio_vec. I'm not sure if this is the most optimal fix but I think that it is safe since bvec_alloc memsets the bio_vec to zero.

Thanks, we should get fixed for 2.6.11.

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Quoted 22 lines

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -319,7 +319,7 @@
 	 */
 	__bio_for_each_segment(bvec, bio, i, 0) {
 		org_vec = bio_orig->bi_io_vec + i;
-		if (bvec->bv_page == org_vec->bv_page)
+		if (!bvec->bv_page || bvec->bv_page == org_vec->bv_page)
 			continue;
 
 		mempool_free(bvec->bv_page, pool);	
Signature · 8 lines
-- 
Mark Haverkamp <[email protected]>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#3 lore raw
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Linus

#4 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Mark, what was the bug that triggered you to write this patch?

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Quoted 7 lines
Quoted 2 lines

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Mark, what was the bug that triggered you to write this patch?

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

Mark,

Quoted 1 line
Signature · 1 line
Mark Haverkamp <[email protected]>
#6 lore raw
Quoted 16 lines · Mark Haverkamp
Quoted 15 lines · Jens Axboe
Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Quoted 7 lines
Quoted 1 line

Mark, what was the bug that triggered you to write this patch?

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

I don't think that I explained that correctly. The dm code clones the bio and sets the bi_idx to point to where the IO should start. Then when __blk_queue_bounce gets called, it only fills in its bio starting at bi_idx (it uses bio_for_each_segment) and since it calls bio_alloc instead of bio_clone, any pages it doesn't fill in are NULL. I suppose we could call bio_clone instead of bio_alloc in __blk_queue_bounce and fill in the whole bio.

Mark.

Quoted 5 lines

Mark,

Quoted 1 line
Signature · 1 line
Mark Haverkamp <[email protected]>
#7 lore raw
In reply to Mark Haverkamp
Quoted 16 lines · Mark Haverkamp
Quoted 15 lines · Jens Axboe
Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Quoted 7 lines
Quoted 1 line

Mark, what was the bug that triggered you to write this patch?

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

This should fix it.

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -425,7 +425,7 @@
 	 * at least one page was bounced, fill in possible non-highmem
 	 * pages
 	 */
-	bio_for_each_segment(from, *bio_orig, i) {
+	__bio_for_each_segment(from, *bio_orig, i) {
 		to = bio_iovec_idx(bio, i);
 		if (!to->bv_page) {
 			to->bv_page = from->bv_page;
Signature · 1 line
Jens Axboe
#8 lore raw
Quoted 19 lines · Jens Axboe
Quoted 18 lines · Mark Haverkamp
Quoted 16 lines · Jens Axboe
Quoted 10 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Mark, what was the bug that triggered you to write this patch?

Quoted 7 lines
Quoted 5 lines

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

This should fix it.

Wouldn't this potentially create bounce pages that will never be used?

Quoted 17 lines

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -425,7 +425,7 @@
 	 * at least one page was bounced, fill in possible non-highmem
 	 * pages
 	 */
-	bio_for_each_segment(from, *bio_orig, i) {
+	__bio_for_each_segment(from, *bio_orig, i) {
 		to = bio_iovec_idx(bio, i);
 		if (!to->bv_page) {
 			to->bv_page = from->bv_page;
Signature · 1 line
Mark Haverkamp <[email protected]>
#9 lore raw
Quoted 26 lines · Mark Haverkamp
Quoted 25 lines · Jens Axboe
Quoted 23 lines · Mark Haverkamp
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Quoted 7 lines
Quoted 2 lines

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Mark, what was the bug that triggered you to write this patch?

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

Quoted 3 lines
Quoted 1 line

This should fix it.

Wouldn't this potentially create bounce pages that will never be used?

Sorry, never mind. I didn't notice that this was for the non-highmem pages.

Signature · 1 line
Mark Haverkamp <[email protected]>
#10 lore raw
In reply to Mark Haverkamp
Quoted 26 lines · Mark Haverkamp
Quoted 25 lines · Jens Axboe
Quoted 23 lines · Mark Haverkamp
Quoted 9 lines · Jens Axboe
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Andrew Morton

It seems very weird for dm to be shoving NULL page*'s into the middle of a bio's bvec array, so your fix might end up being a workaround pending a closer look at what's going on in there.

Quoted 7 lines
Quoted 2 lines

Yes. I don't see how this patch can be anything but bandaid to hide the real bug. Where do these "non-page" bvec's originate?

Yep that's the fishy part, there should not be NULL pages in the middle (or empty bios, for that matter) submitted for io.

Mark, what was the bug that triggered you to write this patch?

It happened when some pages of IO from a dm device were bounced. It looks to me when bio's are cloned in the dm code to split it for physical devices that only the pointers to pages that apply to that device are copied and th bi_idx is adjusted to point to the start, leaving some NULL pointers at the start of the bio_vec.

Quoted 3 lines
Quoted 1 line

This should fix it.

Wouldn't this potentially create bounce pages that will never be used?

Well no, it just points them at the "top" pages from the original bio.

Signature · 1 line
Jens Axboe
#11 lore raw
In reply to Jens Axboe

Just trivial, I think you're missing the final "0" argument in the __bio_for_each_segment().

Quoted 26 lines · Jens Axboe

This should fix it.

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -425,7 +425,7 @@
 	 * at least one page was bounced, fill in possible non-highmem
 	 * pages
 	 */
-	bio_for_each_segment(from, *bio_orig, i) {
+	__bio_for_each_segment(from, *bio_orig, i) {
 		to = bio_iovec_idx(bio, i);
 		if (!to->bv_page) {
 			to->bv_page = from->bv_page;
Signature · 8 lines
-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#12 lore raw
Quoted 3 lines · Dave Olien

Just trivial, I think you're missing the final "0" argument in the __bio_for_each_segment().

Yep indeed, was just a hasty edit...

Quoted 29 lines · Jens Axboe
Quoted 26 lines

This should fix it.

===== mm/highmem.c 1.55 vs edited =====

mm/highmem.c +1 -1
@@ -425,7 +425,7 @@
 	 * at least one page was bounced, fill in possible non-highmem
 	 * pages
 	 */
-	bio_for_each_segment(from, *bio_orig, i) {
+	__bio_for_each_segment(from, *bio_orig, i) {
 		to = bio_iovec_idx(bio, i);
 		if (!to->bv_page) {
 			to->bv_page = from->bv_page;
Signature · 8 lines
-- 
Jens Axboe

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Jens Axboe