From patchwork Fri May 18 07:49:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 10408427 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 CBA6D601F9 for ; Fri, 18 May 2018 07:52:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE8E32886A for ; Fri, 18 May 2018 07:52:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B22A528875; Fri, 18 May 2018 07:52:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 6752A2886A for ; Fri, 18 May 2018 07:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752479AbeERHwE (ORCPT ); Fri, 18 May 2018 03:52:04 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:36043 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752438AbeERHuT (ORCPT ); Fri, 18 May 2018 03:50:19 -0400 Received: by mail-qt0-f194.google.com with SMTP id q6-v6so9158752qtn.3; Fri, 18 May 2018 00:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fqpcuOVKwdr29HTrcpcuP9yfcZ37FVUA+6RpBhy717c=; b=uIu71ZQdeI1ndH9icxcbtzWAv0ORfYnA6jvJ45G6L5EmoFVjWghggvqFtjB1Ly91Hj Ru9d3jgd2nbCR6mPdNZuNksWOAdU/eXEGVI7J3GujHiEgf1xJDNXZoHwJ/J0c+jh9Q7Q BvhvAK7RXytcffi/2C22MF6f8ivYqv9U4uAmmQvyeK/W3ZU3U1ER5lmIOHU6W4aBNTIc 1ZJx8/bMGCxol4/9Pj+OseiCLb0k9DuOmFuKdjAdhB6Y6TzLMPr+hjigP0QyY83fRm9/ hYyj/U3J3Wqo3Kcn2j2CnrJ73mVnNAUzfoSgLjHm2cObyV37IQHyGD4wbfTd4hRIhd0E iqpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fqpcuOVKwdr29HTrcpcuP9yfcZ37FVUA+6RpBhy717c=; b=tHNxhWJdcLC5s/ZEns/uTm45sYS2qLhxV4EpiFzUExYr3YRclSO07Wo6Suf9/D3SG4 BhoGSAWWr7rrx1y41dxPSFAa1KLGKUDEyPHfSUdwrU1KtxVvh9pynnm0CJp4l5YDAltH KyqvDQAFyGPGfa1wzdkqFCfFpuJ+Xa6IfDg6RVfIp4M8pTmMQlwjVIicoqgHtWFQoi/N XAmLrcwKo1XadGPzgWGgN2xmLopDweEyuD5vY+lvtrsiW9dTSZuNNyZTjrSRlVp9yoTS J4oc7VE84OWFYLFX3WwzTVK8kIlCh5utdvdSxAq7ntyp92XlH+Iu1JuWZcvFBLVLKJS5 BJkA== X-Gm-Message-State: ALKqPwfP18wNXW+kVSr3pjwA3jqJwQMJRb7lygKqi0BRp2nvndeWzvU4 TYl7IYGwb2wHREWN+DL7en9SCbk0PA== X-Google-Smtp-Source: AB8JxZoHK/E0vev1xIMhyFJRsgZsS0exT6REF5M+9o57sIHq4fTBsYOykGI80Ca7O8eSXp2XftqsUQ== X-Received: by 2002:aed:2a67:: with SMTP id k36-v6mr8305492qtf.302.1526629818628; Fri, 18 May 2018 00:50:18 -0700 (PDT) Received: from localhost.localdomain (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id s64-v6sm5443004qkl.85.2018.05.18.00.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 00:50:17 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, Jens Axboe , Ingo Molnar Cc: Kent Overstreet Subject: [PATCH 08/10] block: Add warning for bi_next not NULL in bio_endio() Date: Fri, 18 May 2018 03:49:14 -0400 Message-Id: <20180518074918.13816-17-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518074918.13816-1-kent.overstreet@gmail.com> References: <20180518074918.13816-1-kent.overstreet@gmail.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 Recently found a bug where a driver left bi_next not NULL and then called bio_endio(), and then the submitter of the bio used bio_copy_data() which was treating src and dst as lists of bios. Fixed that bug by splitting out bio_list_copy_data(), but in case other things are depending on bi_next in weird ways, add a warning to help avoid more bugs like that in the future. Signed-off-by: Kent Overstreet Reviewed-by: Johannes Thumshirn --- block/bio.c | 3 +++ block/blk-core.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index ce8e259f9a..5c81391100 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1775,6 +1775,9 @@ void bio_endio(struct bio *bio) if (!bio_integrity_endio(bio)) return; + if (WARN_ONCE(bio->bi_next, "driver left bi_next not NULL")) + bio->bi_next = NULL; + /* * Need to have a real endio function for chained bios, otherwise * various corner cases will break (like stacking block devices that diff --git a/block/blk-core.c b/block/blk-core.c index 66f24798ef..f3cf79198a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -204,6 +204,10 @@ static void req_bio_endio(struct request *rq, struct bio *bio, bio_advance(bio, nbytes); /* don't actually finish bio if it's part of flush sequence */ + /* + * XXX this code looks suspicious - it's not consistent with advancing + * req->bio in caller + */ if (bio->bi_iter.bi_size == 0 && !(rq->rq_flags & RQF_FLUSH_SEQ)) bio_endio(bio); } @@ -2982,8 +2986,10 @@ bool blk_update_request(struct request *req, blk_status_t error, 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; + } /* Completion has already been traced */ bio_clear_flag(bio, BIO_TRACE_COMPLETION);