From patchwork Tue Jun 26 00:10:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10487607 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 AA17260532 for ; Tue, 26 Jun 2018 00:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BE1C28668 for ; Tue, 26 Jun 2018 00:10:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9086428707; Tue, 26 Jun 2018 00:10:17 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 1188528702 for ; Tue, 26 Jun 2018 00:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933915AbeFZAKN (ORCPT ); Mon, 25 Jun 2018 20:10:13 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:6902 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754682AbeFZAKM (ORCPT ); Mon, 25 Jun 2018 20:10:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1529971813; x=1561507813; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=QZpc6RSJnGnQqY/OEYVsxaBjbgwpJtNNxqtWLKc03NI=; b=AKTc208Cyt8jZ1eRom4RgFpta8lPimfT8gASGZ1gLVicp3rd5CezxKMp B192imyETxSuXES4bdRNXYa8XlhVZYQyDpp/EYQUbDQx+2h/FaSZm6SS6 1BANVkGhnGE7sxDHHqHCPasA3fm/EDf0Nov7pLRkp0Ojdc1GSanJHMf+t O9S8AjcpD1PP27iB1bbt176lZoZGZLy5H9rkFHkTpXJIsZv1X83U1SLJK vXQ2eCqFDVzB8jUiAeMPALfxVplgSx9mftvzaq4et1hkgKyrOVG8K6w7/ ZXP73xBgD8jy2Wlqi+9FGU0hKQ406PJ6Ho/ib1hj1932tvymXDjUKrIup Q==; X-IronPort-AV: E=Sophos;i="5.51,272,1526313600"; d="scan'208";a="81809626" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2018 08:10:12 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 25 Jun 2018 16:59:31 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2018 17:10:10 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Mike Snitzer , Ming Lei Subject: [PATCH 3/3] block: Fix blk_end_request_all() for WRITE SAME requests Date: Mon, 25 Jun 2018 17:10:09 -0700 Message-Id: <20180626001009.16557-4-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626001009.16557-1-bart.vanassche@wdc.com> References: <20180626001009.16557-1-bart.vanassche@wdc.com> 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 Most REQ_OP_WRITE_SAME requests have a data buffer size that differs from the number of bytes affected on the storage medium. Since blk_update_request() expects that its third argument is the number of bytes that have been completed from the data out buffer, pass that number fo blk_update_request(). This patch avoids that removing a path controlled by the dm-mpath driver while mkfs is running triggers the following kernel bug: -----------[ cut here ]------------ kernel BUG at block/blk-core.c:3347! invalid opcode: 0000 [#1] PREEMPT SMP KASAN CPU: 20 PID: 24369 Comm: mkfs.ext4 Not tainted 4.18.0-rc1-dbg+ #2 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.0.0-prebuilt.qemu-pro ject.org 04/01/2014 RIP: 0010:blk_end_request_all+0x68/0x70 Call Trace: dm_softirq_done+0x326/0x3d0 [dm_mod] blk_done_softirq+0x19b/0x1e0 __do_softirq+0x128/0x60d irq_exit+0x100/0x110 smp_call_function_single_interrupt+0x90/0x330 call_function_single_interrupt+0xf/0x20 Signed-off-by: Bart Van Assche Cc: Mike Snitzer Cc: Christoph Hellwig Cc: Ming Lei --- block/blk-core.c | 31 ++++++++++++++++++++++++------- block/blk-mq.c | 2 +- block/blk.h | 2 ++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 81936b9d6d26..6f9483d4b988 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2686,6 +2686,21 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request * } EXPORT_SYMBOL_GPL(blk_insert_cloned_request); +/** + * blk_rq_bio_bytes - sum of all bytes in all bios associated with a request + * @rq: request pointer. + */ +unsigned int blk_rq_bio_bytes(const struct request *rq) +{ + unsigned int bytes = 0; + struct bio *bio; + + for (bio = rq->bio; bio; bio = bio->bi_next) + bytes += bio->bi_iter.bi_size; + + return bytes; +} + /** * blk_rq_err_bytes - determine number of bytes till the next failure boundary * @rq: request to examine @@ -3080,8 +3095,8 @@ EXPORT_SYMBOL_GPL(blk_steal_bios); * (e.g. request-based dm) so that they can handle partial completion. * Actual device drivers should use blk_end_request instead. * - * Passing the result of blk_rq_bytes() as @nr_bytes guarantees - * %false return from this function. + * Passing the result of blk_rq_bio_bytes() as @nr_bytes guarantees that + * this function will return %false. * * Return: * %false - this request doesn't have any more data @@ -3152,7 +3167,7 @@ bool blk_update_request(struct request *req, blk_status_t error, * If total number of sectors is less than the first segment * size, something has gone terribly wrong. */ - if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) { + if (blk_rq_bio_bytes(req) < blk_rq_cur_bytes(req)) { blk_dump_rq_flags(req, "request botched"); req->__data_len = blk_rq_cur_bytes(req); } @@ -3341,9 +3356,10 @@ void blk_end_request_all(struct request *rq, blk_status_t error) unsigned int bidi_bytes = 0; if (unlikely(blk_bidi_rq(rq))) - bidi_bytes = blk_rq_bytes(rq->next_rq); + bidi_bytes = blk_rq_bio_bytes(rq->next_rq); - pending = blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes); + pending = blk_end_bidi_request(rq, error, blk_rq_bio_bytes(rq), + bidi_bytes); BUG_ON(pending); } EXPORT_SYMBOL(blk_end_request_all); @@ -3388,9 +3404,10 @@ void __blk_end_request_all(struct request *rq, blk_status_t error) WARN_ON_ONCE(rq->q->mq_ops); if (unlikely(blk_bidi_rq(rq))) - bidi_bytes = blk_rq_bytes(rq->next_rq); + bidi_bytes = blk_rq_bio_bytes(rq->next_rq); - pending = __blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes); + pending = __blk_end_bidi_request(rq, error, blk_rq_bio_bytes(rq), + bidi_bytes); BUG_ON(pending); } EXPORT_SYMBOL(__blk_end_request_all); diff --git a/block/blk-mq.c b/block/blk-mq.c index 8c00fcd300b9..852a87895b90 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -543,7 +543,7 @@ EXPORT_SYMBOL(__blk_mq_end_request); void blk_mq_end_request(struct request *rq, blk_status_t error) { - if (blk_update_request(rq, error, blk_rq_bytes(rq))) + if (blk_update_request(rq, error, blk_rq_bio_bytes(rq))) BUG(); __blk_mq_end_request(rq, error); } diff --git a/block/blk.h b/block/blk.h index a8f0f7986cfd..37a31d992c83 100644 --- a/block/blk.h +++ b/block/blk.h @@ -149,6 +149,8 @@ static inline void blk_queue_enter_live(struct request_queue *q) percpu_ref_get(&q->q_usage_counter); } +unsigned int blk_rq_bio_bytes(const struct request *rq); + #ifdef CONFIG_BLK_DEV_INTEGRITY void blk_flush_integrity(void); bool __bio_integrity_endio(struct bio *);