From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org,
Greg KH <greg@kroah.com>
Cc: Justin Forbes <jmforbes@linuxtx.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
Randy Dunlap <rdunlap@xenotime.net>,
Dave Jones <davej@redhat.com>,
Chuck Wolber <chuckw@quantumlinux.com>,
Chris Wedgwood <reviews@ml.cw.f00f.org>,
Michael Krufky <mkrufky@linuxtv.org>,
Chuck Ebbert <cebbert@redhat.com>,
Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
Jens Axboe <jens.axboe@oracle.com>,
Nikanth Karthikesan <knikanth@suse.de>
Subject: [patch 17/22] block: fix nr_phys_segments miscalculation bug
Date: Fri, 14 Nov 2008 21:23:42 -0800 [thread overview]
Message-ID: <20081115052342.GR3710@kroah.com> (raw)
In-Reply-To: <20081115052220.GA3710@kroah.com>
[-- Attachment #1: block-fix-nr_phys_segments-miscalculation-bug.patch --]
[-- Type: text/plain, Size: 3938 bytes --]
2.6.27-stable review patch. If anyone has any objections, please let us know.
------------------
From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
commit 8677142710516d986d932d6f1fba7be8382c1fec upstream
backported by Nikanth Karthikesan <knikanth@suse.de> to the 2.6.27.y tree.
block: fix nr_phys_segments miscalculation bug
This fixes the bug reported by Nikanth Karthikesan <knikanth@suse.de>:
http://lkml.org/lkml/2008/10/2/203
The root cause of the bug is that blk_phys_contig_segment
miscalculates q->max_segment_size.
blk_phys_contig_segment checks:
req->biotail->bi_size + next_req->bio->bi_size > q->max_segment_size
But blk_recalc_rq_segments might expect that req->biotail and the
previous bio in the req are supposed be merged into one
segment. blk_recalc_rq_segments might also expect that next_req->bio
and the next bio in the next_req are supposed be merged into one
segment. In such case, we merge two requests that can't be merged
here. Later, blk_rq_map_sg gives more segments than it should.
We need to keep track of segment size in blk_recalc_rq_segments and
use it to see if two requests can be merged. This patch implements it
in the similar way that we used to do for hw merging (virtual
merging).
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Nikanth Karthikesan <knikanth@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
block/blk-merge.c | 19 +++++++++++++++++--
include/linux/bio.h | 7 +++++++
2 files changed, 24 insertions(+), 2 deletions(-)
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -95,6 +95,9 @@ new_hw_segment:
nr_hw_segs++;
}
+ if (nr_phys_segs == 1 && seg_size > rq->bio->bi_seg_front_size)
+ rq->bio->bi_seg_front_size = seg_size;
+
nr_phys_segs++;
bvprv = bv;
seg_size = bv->bv_len;
@@ -106,6 +109,10 @@ new_hw_segment:
rq->bio->bi_hw_front_size = hw_seg_size;
if (hw_seg_size > rq->biotail->bi_hw_back_size)
rq->biotail->bi_hw_back_size = hw_seg_size;
+ if (nr_phys_segs == 1 && seg_size > rq->bio->bi_seg_front_size)
+ rq->bio->bi_seg_front_size = seg_size;
+ if (seg_size > rq->biotail->bi_seg_back_size)
+ rq->biotail->bi_seg_back_size = seg_size;
rq->nr_phys_segments = nr_phys_segs;
rq->nr_hw_segments = nr_hw_segs;
}
@@ -133,7 +140,8 @@ static int blk_phys_contig_segment(struc
if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt)))
return 0;
- if (bio->bi_size + nxt->bi_size > q->max_segment_size)
+ if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
+ q->max_segment_size)
return 0;
/*
@@ -377,6 +385,8 @@ static int ll_merge_requests_fn(struct r
{
int total_phys_segments;
int total_hw_segments;
+ unsigned int seg_size =
+ req->biotail->bi_seg_back_size + next->bio->bi_seg_front_size;
/*
* First check if the either of the requests are re-queued
@@ -392,8 +402,13 @@ static int ll_merge_requests_fn(struct r
return 0;
total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
- if (blk_phys_contig_segment(q, req->biotail, next->bio))
+ if (blk_phys_contig_segment(q, req->biotail, next->bio)) {
+ if (req->nr_phys_segments == 1)
+ req->bio->bi_seg_front_size = seg_size;
+ if (next->nr_phys_segments == 1)
+ next->biotail->bi_seg_back_size = seg_size;
total_phys_segments--;
+ }
if (total_phys_segments > q->max_phys_segments)
return 0;
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -98,6 +98,13 @@ struct bio {
unsigned int bi_size; /* residual I/O count */
/*
+ * To keep track of the max segment size, we account for the
+ * sizes of the first and last mergeable segments in this bio.
+ */
+ unsigned int bi_seg_front_size;
+ unsigned int bi_seg_back_size;
+
+ /*
* To keep track of the max hw size, we account for the
* sizes of the first and last virtually mergeable segments
* in this bio
--
next prev parent reply other threads:[~2008-11-15 5:30 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20081115051732.506914008@mini.kroah.org>
2008-11-15 5:22 ` [patch 00/22] 2.6.27.7-stable review Greg KH
2008-11-15 5:22 ` [patch 01/22] touch_mnt_namespace when the mount flags change Greg KH
2008-11-15 5:22 ` [patch 02/22] iwlagn: avoid sleep in softirq context Greg KH
2008-11-15 5:22 ` [patch 03/22] ath5k: fix suspend-related oops on rmmod Greg KH
2008-11-15 5:22 ` [patch 04/22] ath5k: Fix reset sequence for AR5212 in general and RF5111 in particular Greg KH
2008-11-15 5:22 ` [patch 05/22] bnx2x: Removing the PMF indication when unloading Greg KH
2008-11-15 5:23 ` [patch 06/22] bnx2x: PCI configuration bug on big-endian Greg KH
2008-11-15 5:23 ` [patch 07/22] bnx2x: Calling netif_carrier_off at the end of the probe Greg KH
2008-11-15 5:23 ` [patch 08/22] ARM: 5329/1: Feroceon: fix feroceon_l2_inv_range Greg KH
2008-11-15 5:23 ` [patch 09/22] Fix platform drivers that crash on suspend/resume Greg KH
2008-11-15 5:23 ` [patch 10/22] hostap: pad the skb->cb usage in lieu of a proper fix Greg KH
2008-11-15 5:23 ` [patch 11/22] ACPI: avoid empty file name in sysfs Greg KH
2008-11-15 5:23 ` [patch 12/22] ACPI: EC: make kernel messages more useful when GPE storm is detected Greg KH
2008-11-15 5:23 ` [patch 13/22] hugetlb: make unmap_ref_private multi-size-aware Greg KH
2008-11-15 5:23 ` [patch 14/22] rtl8187: Add Abocom USB ID Greg KH
2008-11-15 5:23 ` [patch 15/22] rtl8187 : support for Sitecom WL-168 0001 v4 Greg KH
2008-11-15 5:23 ` [patch 16/22] kbuild: Fixup deb-pkg target to generate separate firmware deb Greg KH
2008-11-15 5:23 ` Greg KH [this message]
2008-11-15 5:23 ` [patch 18/22] powerpc/mpic: Fix regression caused by change of default IRQ affinity Greg KH
2008-11-15 5:23 ` [patch 19/22] Input: ALPS - add signature for DualPoint found in Dell Latitude E6500 Greg KH
2008-11-15 5:23 ` [patch 20/22] memory hotplug: fix page_zone() calculation in test_pages_isolated() Greg KH
2008-11-15 5:23 ` [patch 21/22] r8169: select MII in Kconfig Greg KH
2008-11-15 5:24 ` [patch 22/22] sony-laptop: ignore missing _DIS method on pic device Greg KH
2008-11-16 10:38 ` [patch 00/22] 2.6.27.7-stable review François Valenduc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081115052342.GR3710@kroah.com \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=cavokz@gmail.com \
--cc=cebbert@redhat.com \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=eteo@redhat.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=greg@kroah.com \
--cc=jake@lwn.net \
--cc=jens.axboe@oracle.com \
--cc=jmforbes@linuxtx.org \
--cc=knikanth@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mkrufky@linuxtv.org \
--cc=rbranco@la.checkpoint.com \
--cc=rdunlap@xenotime.net \
--cc=reviews@ml.cw.f00f.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=w@1wt.eu \
--cc=zwane@arm.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox