From patchwork Mon Apr 3 12:05:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Wang X-Patchwork-Id: 9659465 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 E474D60353 for ; Mon, 3 Apr 2017 12:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D557327F81 for ; Mon, 3 Apr 2017 12:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA1132846A; Mon, 3 Apr 2017 12:05:21 +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,DKIM_SIGNED, DKIM_VALID,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 E505627F81 for ; Mon, 3 Apr 2017 12:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752225AbdDCMFT (ORCPT ); Mon, 3 Apr 2017 08:05:19 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:35637 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752144AbdDCMFS (ORCPT ); Mon, 3 Apr 2017 08:05:18 -0400 Received: by mail-wr0-f172.google.com with SMTP id k6so161261967wre.2 for ; Mon, 03 Apr 2017 05:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=z0zVxl3Y5XzmPZNunyltsYhurau90H5KV2hmYmjlYQE=; b=U2mTheKRLzZpNsyGFHWc/NMIOmdCa2WDg4GJ9R8blHGxEsYXO7+xqpuZfc9zo0A4sf 53cttScq3roz85ujISU/BxabShM+TxyCxkpmZIlI7Gc8cX8ZIkW+5eq2VRdGHbrjpJ2M veDI1tXfFPeySLp1Sdp6uByx7z3NTxjjZxSYgen+gN6cNLq39su9hMjqaXS2sZ6TP7Dh F2T8s8+x62D/WcrZjayeLl3l/DTN+814nNaTJx+Pf7/8DT1uthalMNyZ7uk+oSzaRFyl KqQOvyCSaDsX1URTfeyB73ndy4/v1Ixu7Qhx0wC9sXETZM3xXlh3Nb4YjDHag7R/p7h9 xPYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=z0zVxl3Y5XzmPZNunyltsYhurau90H5KV2hmYmjlYQE=; b=aQMOC7mwbJX144O49AVnJysTZ5lTUXEtRNC6iGsemZLfBiKcANJFkaLo38Mc4jvnzL bcbkHatQBzliWfXjPdPSwcUYUYP73AfXz7el0d5HHHEUOuH/P/ibwQqS+MW5vYv1DHQa S3tk+4eStjoBL5qFHgw14qx37gO1Pyt1D0FLpUScH+4xVfhWXVGgErJKBB8JpUFG6Qyy +w0UnlZ3FYSsHKrd/7W8S0AtwxvtQDb0DaAQAycjOL+My6cFpT0r24inxLDu4rJSyAuV /8zwetodQ28yXP9aiJNRs0NMa6OeqGtjDHeoCTKosm/ZZ0KZ2kj6p2apVSEDx/u0iD+y 3+NQ== X-Gm-Message-State: AFeK/H1eZf87L9qPcRxrF9Zykw3R4CkCUoHs6kWFxjXRnmDqZTlTpS+s0TANGMV8I9V8DAQk X-Received: by 10.223.135.252 with SMTP id c57mr15042841wrc.109.1491221117430; Mon, 03 Apr 2017 05:05:17 -0700 (PDT) Received: from [192.168.71.52] ([62.217.45.26]) by smtp.googlemail.com with ESMTPSA id d7sm7896515wrc.6.2017.04.03.05.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 05:05:16 -0700 (PDT) To: "linux-kernel@vger.kernel.org" , linux-block@vger.kernel.org, linux-raid@vger.kernel.org Cc: Jens Axboe , Shaohua Li , NeilBrown , Jinpu Wang From: Michael Wang Subject: [RFC PATCH] blk: reset 'bi_next' when bio is done inside request Message-ID: <9505ff12-7307-7dec-76b5-2a233a592634@profitbricks.com> Date: Mon, 3 Apr 2017 14:05:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.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 blk_attempt_plug_merge() try to merge bio into request and chain them by 'bi_next', while after the bio is done inside request, we forgot to reset the 'bi_next'. This lead into BUG while removing all the underlying devices from md-raid1, the bio once go through: md_do_sync() sync_request() generic_make_request() blk_queue_bio() blk_attempt_plug_merge() CHAINED HERE will keep chained and reused by: raid1d() sync_request_write() generic_make_request() BUG_ON(bio->bi_next) After reset the 'bi_next' this can no longer happen. Signed-off-by: Michael Wang --- block/blk-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index 43b7d06..91223b2 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2619,8 +2619,10 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes) struct bio *bio = req->bio; unsigned bio_bytes = min(bio->bi_iter.bi_size, nr_bytes); - if (bio_bytes == bio->bi_iter.bi_size) + if (bio_bytes == bio->bi_iter.bi_size) { req->bio = bio->bi_next; + bio->bi_next = NULL; + } req_bio_endio(req, bio, bio_bytes, error);