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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4F69C62C.7020604@kernel.org>
Date:	Wed, 21 Mar 2012 20:14:36 +0800
From:	Shaohua Li <shli@...nel.org>
To:	Vivek Goyal <vgoyal@...hat.com>, axboe@...nel.dk
CC:	linux-kernel@...r.kernel.org, neilb@...e.de,
	martin.petersen@...cle.com
Subject: [patch 1/2]block: handle merged discard request

On 3/21/12 9:22 AM, Shaohua Li wrote:
> 2012/3/21 Vivek Goyal<vgoyal@...hat.com>:
>> On Fri, Mar 16, 2012 at 03:32:15PM +0800, Shaohua Li wrote:
>>> Didn't allow discard request merge temporarily, as SCSI layer isn't ready
>>> for discard merge as Martin Petersen pointed out. This isn't fair for
>>> non-scsi device, but looks this is the only way I can do currently.
>>>
>>> We should have the same issue before, but maybe because discard merge is
>>> very rare case. But now raid0/10 makes the merge quite possible, so we need
>>> disable it explicitly.
>> I think you will need to do little more cleanup to make discard
>> unmergeable.
>>
>> - Change rq_mergeable(rq)
>> - Change attempt_merge() and get rid of special conditions of allowing
>>   discard merge.
>>
>> Martin had a bigger patch where he wanted to cleanup many discard specific
>> condition checks.
>>
>> As you are just focusing on disabling merging for discard requests, you
>> might as well just pick the relevant pieces from the patch.
>>
>> http://www.spinics.net/lists/linux-scsi/msg57779.html
> Thanks for pointing out the thread. I didn't think disabling discard merging
> permanently is a good idea. We can't do the merge because that code isn't
> ready (actually just for driver of SCSI). Enabling discard merge is required
> for device with slow discard (and very helpful for raid), so I just want a
> temporarily disabling for the merge. Just changing RQ_NOMERGE_FLAGS
> is an easy workaround for this goal.
I looked at the SCSI code for discard again, looks we can easily make 
discard
mergeable. It's a little hacky (the whole SCSI discard implementation is 
hacky
actually), but quite simple and end the trouble of discard merge 
immediately.

Thanks,
Shaohua


The SCSI discard implementation hacks the first bio of request to
add payload, which makes blk_update_request() can't correctly mark
bios finish.
The patch solves it. We set discard bio size to 0 and finish it after
the hacked payload finishes. The check in blk_update_request() should
make us safe.
It's a little hack here (but the whole discard implementation of SCSI
is hacky) and this makes us have discard request merge immediately,
which is great for some SSDs with slow discard.

Signed-off-by: Shaohua Li <shli@...ionio.com>

---
  block/blk-core.c |   11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)

Index: linux/block/blk-core.c
===================================================================
--- linux.orig/block/blk-core.c	2012-03-21 17:58:07.322320702 +0800
+++ linux/block/blk-core.c	2012-03-21 18:04:34.662320467 +0800
@@ -1177,7 +1177,7 @@ EXPORT_SYMBOL(blk_put_request);
  void blk_add_request_payload(struct request *rq, struct page *page,
  		unsigned int len)
  {
-	struct bio *bio = rq->bio;
+	struct bio *bio = rq->bio, *next = bio->bi_next;

  	bio->bi_io_vec->bv_page = page;
  	bio->bi_io_vec->bv_offset = 0;
@@ -1187,6 +1187,11 @@ void blk_add_request_payload(struct requ
  	bio->bi_vcnt = 1;
  	bio->bi_phys_segments = 1;

+	while (next) {
+		next->bi_size = 0;
+		next = next->bi_next;
+	}
+
  	rq->__data_len = rq->resid_len = len;
  	rq->nr_phys_segments = 1;
  	rq->buffer = bio_data(bio);
@@ -2185,8 +2190,10 @@ bool blk_update_request(struct request *
  		if (bio) {
  			/*
  			 * end more in this run, or just return 'not-done'
+			 * The discard check is a hack, see blk_add_request_payload
  			 */
-			if (unlikely(nr_bytes <= 0))
+			if (unlikely(nr_bytes <= 0 &&
+			   !((req->cmd_flags & REQ_DISCARD) && bio->bi_size == 0)))
  				break;
  		}
  	}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ