From patchwork Wed May 9 01:33:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 10387983 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 B86BA602D8 for ; Wed, 9 May 2018 01:35:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ACE8285F0 for ; Wed, 9 May 2018 01:35:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F62828FF6; Wed, 9 May 2018 01:35:51 +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 377C6285F0 for ; Wed, 9 May 2018 01:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933330AbeEIBfg (ORCPT ); Tue, 8 May 2018 21:35:36 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:34767 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933543AbeEIBe3 (ORCPT ); Tue, 8 May 2018 21:34:29 -0400 Received: by mail-qt0-f195.google.com with SMTP id m5-v6so43683210qti.1; Tue, 08 May 2018 18:34:29 -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=avgvmyeymQW4OPonDDUQCk3kGzDy7lmmuBL7UOcRq/RoVdJlvT9kwoJIVYcULeKREt Pwr7jw/bQc9Bq6WCLfY9P7lL14nrgsfCCvpbTBEO9/6YDWUZWXsxEc5vAQnIaTECmZ2c AUfoX7iTNjUn95xkHudMMPsGzwOhpSZyTixXFCcKgBKDwKWlVLVZ6NqHBQnt5mEEXNqo yxgUqhWsIcGfR/Q0cCpQ9zXVitjTPB4qAwmKE5ihPtOk9qJtfTR07inwXk0Dd509bR2I JsxZc0F0L+U4MUPw45x4uJZPgj7SKK5DvLfndB11P/F1VJheF6vN5Nug1HSoV+/gF+k0 4viA== 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=Hz5LTrjBYWYBPJI2Rli8yJvLfBiRPiQek9fyFJLhR0HA2raxh2LKp8J6U8QD7h58lz KspuIogx4UL6S1pw/mY2bGFDy5Snj9Glpkd+X72v0pivrViab8LEMMnixiPa+gWy4Mfv dnIeH5XnFDPJe255PF0Q+Tci+VgffG0xqW9p8MY0xk/djlI7dbS4RBAz7KdZ382u3zSP fWdcVPfdx6KhfAsALqYV227fBMJhb++PttJhIfLtMOO+2tnZ88R2YYndbQfVZ7rq31E5 Xa6Q48PrV6MlbCRS5oTV09SMl+YAcJJoGR+IQLDOwk4quk7ig8YM+EO9Uf76C/I6sk64 e+jw== X-Gm-Message-State: ALQs6tBWtOkK3YeC40q51kAYObzjooxLhVbuHndV6M87im/vcTXOO9Gd yNqC7wNuo9SedEdzZ9aGYG+PxEhnkQ== X-Google-Smtp-Source: AB8JxZrbqnQx/uhGttGTxS3Oq/pDM8idRbJvktywI98BdDaA1gl2SWAWXpLfc6Tv0VfOwnWcEsphxA== X-Received: by 2002:ac8:2779:: with SMTP id h54-v6mr38374301qth.85.1525829668423; Tue, 08 May 2018 18:34:28 -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 x28-v6sm23719003qtx.95.2018.05.08.18.34.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 18:34:27 -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: Tue, 8 May 2018 21:33:56 -0400 Message-Id: <20180509013358.16399-9-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509013358.16399-1-kent.overstreet@gmail.com> References: <20180509013358.16399-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 --- 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);