From patchwork Thu Apr 13 08:06:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 9678927 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 CD37B60381 for ; Thu, 13 Apr 2017 08:06:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFEF228623 for ; Thu, 13 Apr 2017 08:06:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B459028649; Thu, 13 Apr 2017 08:06:43 +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 27F1228623 for ; Thu, 13 Apr 2017 08:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751488AbdDMIGl (ORCPT ); Thu, 13 Apr 2017 04:06:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:37842 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751373AbdDMIGj (ORCPT ); Thu, 13 Apr 2017 04:06:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1BD44AAF2; Thu, 13 Apr 2017 08:06:38 +0000 (UTC) From: Johannes Thumshirn To: Jens Axboe , Omar Sandoval Cc: Ming Lei , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Linux Block Layer Mailinglist , Linux Kernel Mailinglist , Johannes Thumshirn Subject: [PATCH] block: bios with an offset are always gappy Date: Thu, 13 Apr 2017 10:06:29 +0200 Message-Id: <20170413080629.7610-1-jthumshirn@suse.de> X-Mailer: git-send-email 2.12.0 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 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. 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; + + if (offset || !bios_segs_mergeable(q, prev, &pb, &nb)) return __bvec_gap_to_prev(q, &pb, nb.bv_offset); }