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: 10387963 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 A326560236 for ; Wed, 9 May 2018 01:34:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71E6028FF5 for ; Wed, 9 May 2018 01:34:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6649C28FF7; Wed, 9 May 2018 01:34:45 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0294828FF5 for ; Wed, 9 May 2018 01:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E266F6B0313; Tue, 8 May 2018 21:34:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DAE566B0316; Tue, 8 May 2018 21:34:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4EF06B0318; Tue, 8 May 2018 21:34:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 9869F6B0313 for ; Tue, 8 May 2018 21:34:29 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id q13-v6so15479943qtk.8 for ; Tue, 08 May 2018 18:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=fqpcuOVKwdr29HTrcpcuP9yfcZ37FVUA+6RpBhy717c=; b=nRPDACm/l6fLFiC5anm9dvlrD7Fytr5kEkqEuMzxwb1GHt3MfGAeJra9nNWw7jFRB+ 9dV0bZVpTNo2YAHcNHHaVYggIqgpeKuR67igWKp9xYX1FGRowjOvcbKFQ3SAcKLLIoiL hNOAcoY2mCtvpQquLmXJ2y3YIvCIDMAHzYUKaNqXjhHgX9Tmq7AyQ9pvYFNVHojbNUeL bSt9P6+JIcmFfhx9+ZeJAW0E1DTdPhurfQZslxb6zDhr2ryM3bOYNpe/zbNjNLdwPBKR T6u3Ds79t6+lWDLoGIhNv25PNUcnrbzxKBIDolo7dniiyoFfri0k5XWv0626m9yLyBL2 c3cw== X-Gm-Message-State: ALQs6tB4egs506eUXc3/dBa9kmHfFWxZgeTfWQJicqOaBy8LJJ7TWE/1 dDG5gEl7o5D1q+W1cvYZxCI7m9kka+4mA846nYClIlGH0ruhEjPfsXpeEQe1lQXZZ+az5gVvQXM G/DCPCm9ab9/PJAgQqD2CLEYKpnFYEplGhr5sxUIwVyJBFQw/pLcSQCBdpu7k4Qeq/G0rMbf53/ HFqU1iGfFD2EWJD8Z4Dn6XZWYwFLoqUq4FJgWq/5ggbIgTgNb7m6C5ahK2XUOEINmIE4jMTrZ27 RABiDJWzkg79d/W3U27F7p+ESrwW5ZsyCx9lKVGLHrqnMWEia4FuiH+UsN5W/qQNH1t3oU9H7qI dAFN05yp/HfNFQeAFS2iGe1UNTePKeHnsIiPyc78PpHJlwDa4UL4KNzUHZHxnQLnTfCgcqagf2d o X-Received: by 2002:ac8:1933:: with SMTP id t48-v6mr39669261qtj.371.1525829669409; Tue, 08 May 2018 18:34:29 -0700 (PDT) X-Received: by 2002:ac8:1933:: with SMTP id t48-v6mr39669238qtj.371.1525829668810; Tue, 08 May 2018 18:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525829668; cv=none; d=google.com; s=arc-20160816; b=OOG2sRvIFVI3HOW5RJTiPPw+N1ANnx6O0lREqAFk7ZphBOhyG/hhR0muih/SpQuDIZ UYWGvaQM5HvcOn8zMZ/nlocJspsD9Hl2ef0dHJtPwYIZvOt2C2PAd2jBTXPGOZPrMMvA OpT+gfz95gPp1mZoerAzUMEVDNbm5/POpAcsCsOOEcSlzL27xfF1orzI9Hq8MUqSDmjW BkSQJiVVXoJf/cNPGbuxtwGRtbWEWxyeTyEgxE6sNLsXzdJ2trrH5bbhhxhA0jeuLdDb 8bO339EoOr9NCHg/+ZMo+rK5x5vT8Fz6W1y53G8XXSx5gBkdJ7rYc3x+yylVRkVRXa9D ouqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=fqpcuOVKwdr29HTrcpcuP9yfcZ37FVUA+6RpBhy717c=; b=apxqwswz9SVbfF357A27QhhXOOR89Y+wQwJ68Loa3zalbyc22MO0jMF59nTy8mz1DS qb5wkYwo2AVcV3OOB2veivCqRH0kSLZ2ghsgrgOrZ4dTctPZWJqq1bWxX5lYq8i0BF/T p8ZrHvkB9nDL+tA5ymHfz+FM5WZPXGkgZ5HmeOPEeFDv0DtHUgtteya7ir4oYn3ZmHZJ /rDNUjhlXfYKPX9L9yqaRTh9K464bBGvd/9/k+wtKIS2UKv+JyXUg216gCZbmU06gvGQ Oiq6GhwV7S4gJViwK/GxUWa+9bdPlcTXc73dkmDoSYzljRQD09dNQwwXgVlNKcxQhn14 4prA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=avgvmyey; spf=pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r32-v6sor9747063qtr.105.2018.05.08.18.34.28 for (Google Transport Security); Tue, 08 May 2018 18:34:28 -0700 (PDT) Received-SPF: pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=avgvmyey; spf=pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);