Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4207749imm; Fri, 18 May 2018 00:52:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrNhy47qe+EOrjGzoxVgRUXzpF7LXnRyGA50Yjpy/gAWJrIeyafc6qrjfjWJvOjGvwBO1YL X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr8198355plq.215.1526629967725; Fri, 18 May 2018 00:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526629967; cv=none; d=google.com; s=arc-20160816; b=VAdZB8dKybZSZRCOn9wPHDB9CCHBp6pplsqMLc/ghvnoEP24K0DRS1VImckqMyf8ZA 9sBWd1GyLY+ZWhb1Fh82OKiTFk88wX83hbhAu2pcn04PCNAwEb3OSAgAL2McKWKceaIu L+6vs4gxCHnrMUBTb7rbbrW3EVRNCqDCSIr7zXpSrdoaJlBKDs7pOFDX23G4jHMhVI17 a1MO4iWLvcftLGfF6rkJXkSQpXwD+J6ccLr+H18aS7QurDM48AXv8MkSgIUFs90aE2TS YX8TVhIgZrYMmlLVC7xl6G1er2B0lM8hVYLJ4MVOIXXS8k10ja6qa4Oo95tYBu7f+Rcr PrWg== 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=LiZ3g3YYH7MGKyRcxFAjDEhPbMYKimqKmImbXcK8pYstpu+w9gL0UeUkFhL9hMS745 DevaqccGNE7wojEgkF7epzmGCPbWHCn/I62H3eD6GYVg9aWoWk91O3nGTYzjlG+yyz8s /aY9yOFuszUENYZlJy5ZlubYGysO57iffSR84PcpA42jV72ZsTjEDqp4sa+Mrp3R0inz pLkau49l6qoWh1yQDHc98ENXqSn9gpLzsdSyyvFK1SVYLtHvhRaxRRSVGALhBujWY1SV LChNUkA77CWefBBGy1ymsdnwf83McZdeF0jCJ8555iPha6gXMffXi3zHGvFOnAKfOu8M ECwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uIu71ZQd; 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 y67-v6si7103081pfi.195.2018.05.18.00.52.33; Fri, 18 May 2018 00:52:47 -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=uIu71ZQd; 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 S1752542AbeERHwF (ORCPT + 99 others); Fri, 18 May 2018 03:52:05 -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-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-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