From patchwork Wed May 9 01:33:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 10387957 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 2CA7A602D8 for ; Wed, 9 May 2018 01:34:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE1B228FF5 for ; Wed, 9 May 2018 01:34:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2F8C28FF7; Wed, 9 May 2018 01:34:37 +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 4EB2128FF5 for ; Wed, 9 May 2018 01:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 720706B0311; Tue, 8 May 2018 21:34:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A8D16B0312; Tue, 8 May 2018 21:34:26 -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 522CC6B0313; Tue, 8 May 2018 21:34:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id 24F0D6B0311 for ; Tue, 8 May 2018 21:34:26 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id y9so25161680qki.23 for ; Tue, 08 May 2018 18:34:26 -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=sOaXvFMRxJ8wbH6KTtdYddcySDG7QIVvtK9vhH4NLIM=; b=E4lzNgPzD6kg3bvAfI4cMMc0EOFmurYAlgLoqpK7+JvpIrDfYaDxtr6wEmvTGkyynv TfiEQzWNHYInABBvbfd67/PqFRQn5OVMvnzAnddgVN/HiABWX3EQ2qhoj6kFtAW5p9Ho g4J7qRsCoQawKMrctZSf/8PhXK+wVH3o15qXcCrizIG6Nh591dZsBkVRt7dwkB12Fwwl fgsVNAUEP9Y2gAUP6i9pvXZ+WVedV461vitdTnEqYGV1veYw4kyjBQc6h2ASZ7zaGu3U X4iQJzNWzx6IIMRjsdOc8tUsdairowVDi37VT3y0nDNuq9ux1RN8rAtLNCvvACgJnMvm zcnQ== X-Gm-Message-State: ALQs6tBWcUOlyAhQB2vDWPmidzvNwRC0mVHESIBQl4Rt+PrZRzYo+orr YuyUvO2JIdQQZyJc+JPxlbg6G5z4x+Mdc/PK31si1ByQx3o3fmoN+i7nwffnpGlW2Ipnqg8fjas YvKbTry7OipGW4jP++HEDKKdkGRBn5bA0yvVBVh3TQIrIbgVecSr8qDfjYSaf+zMLo8OWvXYNfi +KbKuHVscA1xOBIrYjj/VrrWr7DUgalZMbxRqYm1fjrrcjxcUuYtSqz2EWS5EWmDJmdKtLjQAuL GhY3UNebvG4FvY3SUdEn1mOK5tf6myHxoatGl5gwCjx2uj1UL3e4LBgII3Lyqd2hBf3W4miEelQ ZG/4wqpLkzvoqL5bhwWH2VQPupE0+KpxgqJApZdv1kF2lANQClac8Ycb34pcR+IzBtmjiiZ+zmF q X-Received: by 2002:aed:3e45:: with SMTP id m5-v6mr37397540qtf.175.1525829665942; Tue, 08 May 2018 18:34:25 -0700 (PDT) X-Received: by 2002:aed:3e45:: with SMTP id m5-v6mr37397515qtf.175.1525829665202; Tue, 08 May 2018 18:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525829665; cv=none; d=google.com; s=arc-20160816; b=S2pzQyw+1jMxGCwOm7MnjE0Oz4KfAjfaxElvrICHzIAmKhtOBLFdL+bHw55jKgCFGz IlRJEMEQqrsINFlAFadVwZl4YenjZ8v5Ku7z3oQkffDBHsGDxyk2sLernmg98a28wM3c Xx4KDtf/ESvW6lnr1wzSQFJmeFBNlGQbzx4OEeTphWHY2h5x6KkXw+sL4aX504zMDZO+ gsnOjeE1ZWISoUQ6QE2W3e1FEwBq085GH9jFLVFB0D7YyWrcIPD1DeCXTYsCc772mWFN 5opOv4PeVWD9y7wcNuHLDgUFexJMXVAE94SYIUyvbdBGhSkjFnbbb/3Jspgsfa1LhpNC 3mhg== 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=sOaXvFMRxJ8wbH6KTtdYddcySDG7QIVvtK9vhH4NLIM=; b=nOlmMjUN6mpyON5BwbjiHlO6isP3gQbzWT0YyMXlpzvdCMId19KA5lmaP9EhAWPhL+ viAMf0IGI5UY6hyedUfgcQ9ydZsUTYeQJUa9rMCefOXuZjbicOFRmiQm5CaJ48E5kn9s 2qw2E/uWDxPP1WZfU3E+MHTzAFHGQimAJj2FErlv04T7DOuPV5i22opB+PMRSUXKuDOs WRip0757ZeeGewkJuoRd68J7GpI6P0hip/AUchzPaxEc5kKOJiFtu4sb4zk/PfTjt8y+ th9pE7T5JuFAby7tMFw/t6z8dX7u4rNGYTiLO4iNsZ7sM6Yh/yi+x46zQWYNBgLJHR/K 7CQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=S5zUSESW; 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 e11-v6sor15166015qtf.146.2018.05.08.18.34.25 for (Google Transport Security); Tue, 08 May 2018 18:34:25 -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=S5zUSESW; 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=sOaXvFMRxJ8wbH6KTtdYddcySDG7QIVvtK9vhH4NLIM=; b=S5zUSESWies5B5AjU/JkfhzchVk9eqBzCP1b9ix/YJJqZB+TjDp8nZvOe+hjaNO1yz o21U1Z5YvtYyhIDQgh7uUrRSrzkFQttUY7igc/vkpoPuFpLWwjKY3PnI00hERhviH9gg Df7C2lJV8AsRGSirm0Samy5a+9QkgReC2KgU7XS94Fkz9oR7XSqZM5mo/6r5mcDT4UWV W5hBumloMNHF6Bmcizsn9OdQINofzqZ9rgZkBuvxa5ke0hYozAvHwA3RfwB5aeXYns4H 3qPias+rRT2/FLYOmDmLn/oTIPjNdLZOXZVaINDhVLd9g82Kyo746dJesXtqQcgRcJSc myQg== X-Google-Smtp-Source: AB8JxZo+NjdTCPSOO4ctEvNkmTuvtN2ROuo6a5NVxnwlw/8MCNFfL5ASxB0HZRuv+Sv8vtTSrAQ9GA== X-Received: by 2002:ac8:2614:: with SMTP id u20-v6mr640785qtu.192.1525829664791; Tue, 08 May 2018 18:34:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 18:34:23 -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 06/10] block: Split out bio_list_copy_data() Date: Tue, 8 May 2018 21:33:54 -0400 Message-Id: <20180509013358.16399-7-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 Found a bug (with ASAN) where we were passing a bio to bio_copy_data() with bi_next not NULL, when it should have been - a driver had left bi_next set to something after calling bio_endio(). Since the normal case is only copying single bios, split out bio_list_copy_data() to avoid more bugs like this in the future. Signed-off-by: Kent Overstreet --- block/bio.c | 83 +++++++++++++++++++++++++---------------- drivers/block/pktcdvd.c | 2 +- include/linux/bio.h | 5 ++- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/block/bio.c b/block/bio.c index d7bd765e9e..c58544d4bc 100644 --- a/block/bio.c +++ b/block/bio.c @@ -971,32 +971,16 @@ void bio_advance(struct bio *bio, unsigned bytes) } EXPORT_SYMBOL(bio_advance); -void bio_copy_data_iter(struct bio *dst, struct bvec_iter dst_iter, - struct bio *src, struct bvec_iter src_iter) +void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter, + struct bio *src, struct bvec_iter *src_iter) { struct bio_vec src_bv, dst_bv; void *src_p, *dst_p; unsigned bytes; - while (1) { - if (!src_iter.bi_size) { - src = src->bi_next; - if (!src) - break; - - src_iter = src->bi_iter; - } - - if (!dst_iter.bi_size) { - dst = dst->bi_next; - if (!dst) - break; - - dst_iter = dst->bi_iter; - } - - src_bv = bio_iter_iovec(src, src_iter); - dst_bv = bio_iter_iovec(dst, dst_iter); + while (src_iter->bi_size && dst_iter->bi_size) { + src_bv = bio_iter_iovec(src, *src_iter); + dst_bv = bio_iter_iovec(dst, *dst_iter); bytes = min(src_bv.bv_len, dst_bv.bv_len); @@ -1010,31 +994,66 @@ void bio_copy_data_iter(struct bio *dst, struct bvec_iter dst_iter, kunmap_atomic(dst_p); kunmap_atomic(src_p); - bio_advance_iter(src, &src_iter, bytes); - bio_advance_iter(dst, &dst_iter, bytes); + bio_advance_iter(src, src_iter, bytes); + bio_advance_iter(dst, dst_iter, bytes); } } EXPORT_SYMBOL(bio_copy_data_iter); /** - * bio_copy_data - copy contents of data buffers from one chain of bios to - * another - * @src: source bio list - * @dst: destination bio list - * - * If @src and @dst are single bios, bi_next must be NULL - otherwise, treats - * @src and @dst as linked lists of bios. + * bio_copy_data - copy contents of data buffers from one bio to another + * @src: source bio + * @dst: destination bio * * Stops when it reaches the end of either @src or @dst - that is, copies * min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of bios). */ void bio_copy_data(struct bio *dst, struct bio *src) { - bio_copy_data_iter(dst, dst->bi_iter, - src, src->bi_iter); + struct bvec_iter src_iter = src->bi_iter; + struct bvec_iter dst_iter = dst->bi_iter; + + bio_copy_data_iter(dst, &dst_iter, src, &src_iter); } EXPORT_SYMBOL(bio_copy_data); +/** + * bio_list_copy_data - copy contents of data buffers from one chain of bios to + * another + * @src: source bio list + * @dst: destination bio list + * + * Stops when it reaches the end of either the @src list or @dst list - that is, + * copies min(src->bi_size, dst->bi_size) bytes (or the equivalent for lists of + * bios). + */ +void bio_list_copy_data(struct bio *dst, struct bio *src) +{ + struct bvec_iter src_iter = src->bi_iter; + struct bvec_iter dst_iter = dst->bi_iter; + + while (1) { + if (!src_iter.bi_size) { + src = src->bi_next; + if (!src) + break; + + src_iter = src->bi_iter; + } + + if (!dst_iter.bi_size) { + dst = dst->bi_next; + if (!dst) + break; + + dst_iter = dst->bi_iter; + } + + bio_copy_data_iter(dst, &dst_iter, src, &src_iter); + } +} +EXPORT_SYMBOL(bio_list_copy_data); + struct bio_map_data { int is_our_pages; struct iov_iter iter; diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index c61d20c9f3..00ea788b17 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -1285,7 +1285,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) * Fill-in bvec with data from orig_bios. */ spin_lock(&pkt->lock); - bio_copy_data(pkt->w_bio, pkt->orig_bios.head); + bio_list_copy_data(pkt->w_bio, pkt->orig_bios.head); pkt_set_state(pkt, PACKET_WRITE_WAIT_STATE); spin_unlock(&pkt->lock); diff --git a/include/linux/bio.h b/include/linux/bio.h index 5a6ee955a8..98b175cc00 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -505,9 +505,10 @@ static inline void bio_flush_dcache_pages(struct bio *bi) } #endif -extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter dst_iter, - struct bio *src, struct bvec_iter src_iter); +extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter, + struct bio *src, struct bvec_iter *src_iter); extern void bio_copy_data(struct bio *dst, struct bio *src); +extern void bio_list_copy_data(struct bio *dst, struct bio *src); extern void bio_free_pages(struct bio *bio); extern struct bio *bio_copy_user_iov(struct request_queue *,