public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] BUG: ll_merge_requests_fn() updates req->nr_phys_segments wrongly
@ 2008-09-23 18:28 Nikanth Karthikesan
  2008-09-25  7:35 ` FUJITA Tomonori
  2008-09-25 13:55 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Nikanth Karthikesan @ 2008-09-23 18:28 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel, linux-scsi, FUJITA Tomonori


From: Nikanth Karthikesan <knikanth@suse.de>

ll_merge_requests_fn() decreases the req->nr_phys_segments if 
blk_phys_contig_segment() returns true, but it is perfectly possible that 
blk_hw_contig_segment() is false. A new hw_segment implies a new phys_segment. 
So decrementing nr_phys_segments wrongly here triggers the BUG_ON() in 
scsi_init_sgtable(), as blk_rq_map_sg() would map 1 phys_segment more than  
req->nr_phys_segment. This is easily reproducible. Other callers of 
blk_rq_map_sg() should also be affected by this bug.

Signed-off-by: Nikanth Karthikesan <knikanth@suse.de>
---

 block/blk-merge.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 5efc9e7..6e6d04b 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -392,11 +392,6 @@ static int ll_merge_requests_fn(struct request_queue *q, 
struct request *req,
 		return 0;
 
 	total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
-	if (blk_phys_contig_segment(q, req->biotail, next->bio))
-		total_phys_segments--;
-
-	if (total_phys_segments > q->max_phys_segments)
-		return 0;
 
 	total_hw_segments = req->nr_hw_segments + next->nr_hw_segments;
 	if (blk_hw_contig_segment(q, req->biotail, next->bio)) {
@@ -410,9 +405,12 @@ static int ll_merge_requests_fn(struct request_queue *q, 
struct request *req,
 		if (next->nr_hw_segments == 1)
 			next->biotail->bi_hw_back_size = len;
 		total_hw_segments--;
+		if (blk_phys_contig_segment(q, req->biotail, next->bio))
+			total_phys_segments--;
 	}
 
-	if (total_hw_segments > q->max_hw_segments)
+	if (total_phys_segments > q->max_phys_segments ||
+	    total_hw_segments > q->max_hw_segments)
 		return 0;
 
 	/* Merge is OK... */










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

end of thread, other threads:[~2008-09-25 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-23 18:28 [PATCH] BUG: ll_merge_requests_fn() updates req->nr_phys_segments wrongly Nikanth Karthikesan
2008-09-25  7:35 ` FUJITA Tomonori
2008-09-25 13:55 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox