Received: by 10.192.165.148 with SMTP id m20csp4961393imm; Tue, 8 May 2018 18:37:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq4KysJgqKO/Nng96/i7XrnaeMbAIK17nH6hZpzXBOZd6AvBOJrH+zR08FIN5uuI2co8dQe X-Received: by 2002:a65:508c:: with SMTP id r12-v6mr34027206pgp.185.1525829857612; Tue, 08 May 2018 18:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525829857; cv=none; d=google.com; s=arc-20160816; b=XKrH1HCQIVyJDSbR0vouuCPPrzYyaCRzMiXywf+6DG8/TJwCDPLX1do+k6Qk88Xxyr MStDzVxs/MT0ukDeO9dysq6Tzekp66zebfC9CBTU32gY4rsquCVF31/lc7Vuxh2qsTun 306qLcVIiPQZ3q32SmXUKUSxOEMydrJTx5OtsKI17wDEqXi7MlsRPiX8fLfBOZfhp0mw cX+/TkX9WzMfST4UhQhS7RVJt7yM7ZdTRbgxgE4dcd8RBuiJFjd5rDawSdcfvgmztec3 tCN0pub4YQlF6geF6EnrUqX4uOglAjWGDry+IzEFwjFWDQzIEIFPGgwxgXVnHaFPtqfG i/pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fqpcuOVKwdr29HTrcpcuP9yfcZ37FVUA+6RpBhy717c=; b=fVLNkUsbGjnM4wDqxNzMyUIePorzKZDabCvTSN9fKnwG7tT3BrziceOj52XWmnnxux VQzhmYH6BYiPtIkdLmhE7Q+PBjh3zRLyo5BDkkqFvFcpzC1nuwbdHRdrVoAM731rBbQY MSxQ2AugtjxUUwiIZ932QxXas8IFXlYM4MSNKrTZtXi5qtuZiLCICnTSMPAOllZ1NQF2 91cnzxRZlCfnnd+LfAoFYeMyHF0Dj8q8jXxwRM1e9cg29iYwrWCR+JfH8PUhXxyr98pc D5PhlbjFZHdidIsrV3PN8mhTwzktN8UbkknguOzoxvRe4QrfKVYaIiWTrtLKAxViIcho rDsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=avgvmyey; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4-v6si2619291pgn.403.2018.05.08.18.37.22; Tue, 08 May 2018 18:37:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=avgvmyey; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933658AbeEIBfh (ORCPT + 99 others); Tue, 8 May 2018 21:35:37 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.0