lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1540045777-10290-1-git-send-email-jianchao.w.wang@oracle.com>
Date:   Sat, 20 Oct 2018 22:29:37 +0800
From:   Jianchao Wang <jianchao.w.wang@...cle.com>
To:     axboe@...nel.dk
Cc:     martin.petersen@...cle.com, tom.leiming@...il.com, hch@....de,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH V2] block: fix the DISCARD request merge

There are two cases when handle DISCARD merge
 - max_discard_segments == 1
   bios need to be contiguous
 - max_discard_segments > 1
   Only nvme right now. It takes every bio as a range and different
   range needn't to be contiguous.

But now, attempt_merge screws this up. It always consider contiguity
for DISCARD for the case max_discard_segments > 1 and cannot merge
contiguous DISCARD for the case max_discard_segments == 1, because
rq_attempt_discard_merge always returns false in this case.
This patch fixes both of the two cases above.

Signed-off-by: Jianchao Wang <jianchao.w.wang@...cle.com>
---

V2:
  - Add max_discard_segments > 1 checking in attempt_merge
  - Change patch title and comment
  - Add more comment in attempt_merge

 block/blk-merge.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 42a4674..8f22374 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -734,8 +734,15 @@ static struct request *attempt_merge(struct request_queue *q,
 	/*
 	 * not contiguous
 	 */
-	if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
-		return NULL;
+	if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) {
+		/*
+		 * When max_discard_segments is bigger than 1 (only nvme right
+		 * now), needn't consider the contiguity.
+		 */
+		if (!(req_op(req) == REQ_OP_DISCARD &&
+		      queue_max_discard_segments(q) > 1))
+			return NULL;
+	}
 
 	if (rq_data_dir(req) != rq_data_dir(next)
 	    || req->rq_disk != next->rq_disk
@@ -757,10 +764,17 @@ static struct request *attempt_merge(struct request_queue *q,
 	 * If we are allowed to merge, then append bio list
 	 * from next to rq and release next. merge_requests_fn
 	 * will have updated segment counts, update sector
-	 * counts here. Handle DISCARDs separately, as they
-	 * have separate settings.
+	 * counts here.
+	 * Two cases of Handling DISCARD:
+	 *  - max_discard_segments == 1
+	 *    The bios need to be contiguous.
+	 *  - max_discard_segments > 1
+	 *    Only nvme right now. It takes every bio as a
+	 *    range and send them to controller together. The ranges
+	 *    needn't to be contiguous.
 	 */
-	if (req_op(req) == REQ_OP_DISCARD) {
+	if (req_op(req) == REQ_OP_DISCARD &&
+	    queue_max_discard_segments(q) > 1) {
 		if (!req_attempt_discard_merge(q, req, next))
 			return NULL;
 	} else if (!ll_merge_requests_fn(q, req, next))
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ