From patchwork Thu Apr 13 10:02:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9679073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B84E1601C3 for ; Thu, 13 Apr 2017 10:02:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F552860E for ; Thu, 13 Apr 2017 10:02:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9ACC628652; Thu, 13 Apr 2017 10:02:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 049DE2860E for ; Thu, 13 Apr 2017 10:02:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754893AbdDMKCi (ORCPT ); Thu, 13 Apr 2017 06:02:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36228 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751274AbdDMKCh (ORCPT ); Thu, 13 Apr 2017 06:02:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 169EF6AADC; Thu, 13 Apr 2017 10:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 169EF6AADC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ming.lei@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 169EF6AADC Received: from ming.t460p (ovpn-12-21.pek2.redhat.com [10.72.12.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8084384CDB; Thu, 13 Apr 2017 10:02:25 +0000 (UTC) Date: Thu, 13 Apr 2017 18:02:21 +0800 From: Ming Lei To: Johannes Thumshirn Cc: Jens Axboe , Omar Sandoval , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Linux Block Layer Mailinglist , Linux Kernel Mailinglist Subject: Re: [PATCH] block: bios with an offset are always gappy Message-ID: <20170413100110.GB5964@ming.t460p> References: <20170413080629.7610-1-jthumshirn@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170413080629.7610-1-jthumshirn@suse.de> User-Agent: Mutt/1.8.0 (2017-02-23) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 13 Apr 2017 10:02:37 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Apr 13, 2017 at 10:06:29AM +0200, Johannes Thumshirn wrote: > Doing a mkfs.btrfs on a (qemu emulated) PCIe NVMe causes a kernel panic > in nvme_setup_prps() because the dma_len will drop below zero but the > length not. Looks I can't reproduce the issue in QEMU(32G nvme, either partitioned or not, just use 'mkfs.btrfs /dev/nvme0n1p1'), could you share the exact mkfs command line and size of your emulated NVMe? > > A git bisect tracked the behaviour down to commit 729204ef49ec ("block: > relax check on sg gap"). Since commit 729204ef49ec a bio's offsets are not > taken into account in the decision if the bio will gap any more. Restore > the old behavior of checking bio offsets as well for the decision if a > bio will gap. > > Signed-off-by: Johannes Thumshirn > Fixes: 729204ef49ec ("block: relax check on sg gap") > Cc: Ming Lei > --- > include/linux/blkdev.h | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h > index 7548f332121a..a03b7196209e 100644 > --- a/include/linux/blkdev.h > +++ b/include/linux/blkdev.h > @@ -1677,11 +1677,14 @@ static inline bool bio_will_gap(struct request_queue *q, struct bio *prev, > { > if (bio_has_data(prev) && queue_virt_boundary(q)) { > struct bio_vec pb, nb; > + bool offset; > > bio_get_last_bvec(prev, &pb); > bio_get_first_bvec(next, &nb); > > - if (!bios_segs_mergeable(q, prev, &pb, &nb)) > + offset = pb.bv_offset || nb.bv_offset; We don't consider pb's offset here, because if pb.bv_offset isn't zero, pb should be the only bvec in 'prev' and will be put in a standalone segement, and we still can make 'nb' into this segment if both are mergeable. But the following issue might be caused by commit 729204ef49ec ("block: relax check on sg gap"): - if the 'next' has more than one segment - the segment merged from 'pb' and the 1st segment of 'next' may end at un-aligned virt boundary Could you try the following patch to see if it fixes your issue? diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 7548f332121a..65d1510681c6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1659,16 +1659,28 @@ static inline bool bvec_gap_to_prev(struct request_queue *q, * and the 1st bvec in the 2nd bio can be handled in one segment. */ static inline bool bios_segs_mergeable(struct request_queue *q, - struct bio *prev, struct bio_vec *prev_last_bv, + struct bio *prev, struct bio *next, + struct bio_vec *prev_last_bv, struct bio_vec *next_first_bv) { if (!BIOVEC_PHYS_MERGEABLE(prev_last_bv, next_first_bv)) return false; if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv)) return false; - if (prev->bi_seg_back_size + next_first_bv->bv_len > + if (prev->bi_seg_back_size + next->bi_seg_front_size > queue_max_segment_size(q)) return false; + + /* + * if 'next' has multiple segments, we need to make + * sure the merged segment from 'pb' and the 1st segment + * of 'next' ends at aligned virt boundary. + */ + if ((next->bi_seg_front_size < next->bi_iter.bi_size) && + ((prev_last_bv->bv_offset + prev_last_bv->bv_len + + next->bi_seg_front_size) & queue_virt_boundary(q))) + return false; + return true; } @@ -1681,7 +1693,7 @@ static inline bool bio_will_gap(struct request_queue *q, struct bio *prev, bio_get_last_bvec(prev, &pb); bio_get_first_bvec(next, &nb); - if (!bios_segs_mergeable(q, prev, &pb, &nb)) + if (!bios_segs_mergeable(q, prev, next, &pb, &nb)) return __bvec_gap_to_prev(q, &pb, nb.bv_offset); }