Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1113791imm; Wed, 1 Aug 2018 10:24:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfNHVQ8DhHVItO7JaDZKqhUKFkIzn8llJXkECInGjMYojCXHe9S4qpEXMEgPPCjETyIOg8X X-Received: by 2002:a17:902:7c0a:: with SMTP id x10-v6mr25135642pll.77.1533144259900; Wed, 01 Aug 2018 10:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533144259; cv=none; d=google.com; s=arc-20160816; b=AlLVMoJmZEUH5ttLpCE01RniyBvWrXFe8+heXtCdB3JLEmR+2+/QFZyfzdlvgyh3ar p9ruFoLlvQJA2CnQ8wKjgfDucOm8cmfjlbxmDwVLMYYn7PtmQgEXruNLrSsNhkiL3T5R dh0p0mIlSYCxpJRxdA5BPf06Np9trSWeD7GajaUb7aKvi3ndB0wrTGn1VzM4MKPY4SAH tGLMwZra19IXWE/ixqeiPFZAfE8ZdyAfdurSGDDcJgvqh9GxR+7XdbXBVuA90aRfgmSA TJewkICDhoLw0ChbgihQIuo3CTXpGnNhFmY8fC+AR/jg16Sptzv82X5FXn4/YwMiCY4I HfAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QYEetHorPetg3GgnNI7rE7Xa5+HYQJwFikhAXF2/jS0=; b=bYom8vPNmhqEXHxuJ1t/Hl5LpFqbuE4nTTWXjDmZIiUhBNLq8ytQvJkSZEIpNT9qiO LB6lJY0SG/F1e3yZVPEyYw6AyNdf1jgD/7v36a+53pinh2iLnym5FpsBUlIqtrhnFNVW uDs4ixBu5N500BsftaJdjivzHzKd/xcGCOKKNNFPeLXf+DVKhM4+Y4XKklXSFQ35h2UW qta0WyOpcyhSfi6LKELVsA+HqVj/bi1beKY0B7CPTUsCsCCBpwZCaaSD896I6/8ACWJn pVN+vfnC8dHUN/dey6UvkN/pSZBnu7qyd7RLQp3mOqx38AZfRuH9dFWMUXC/iDkj07hy EOZg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si12124390plc.168.2018.08.01.10.24.05; Wed, 01 Aug 2018 10:24:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390369AbeHATJS (ORCPT + 99 others); Wed, 1 Aug 2018 15:09:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50746 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389759AbeHATJS (ORCPT ); Wed, 1 Aug 2018 15:09:18 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 83224CC3; Wed, 1 Aug 2018 17:22:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hannes Reinecke , Ming Lei , Jan Kara , Christoph Hellwig , Martin Wilck , Jens Axboe Subject: [PATCH 4.14 215/246] block: bio_iov_iter_get_pages: fix size of last iovec Date: Wed, 1 Aug 2018 18:52:05 +0200 Message-Id: <20180801165022.002412959@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Wilck commit b403ea2404889e1227812fa9657667a1deb9c694 upstream. If the last page of the bio is not "full", the length of the last vector slot needs to be corrected. This slot has the index (bio->bi_vcnt - 1), but only in bio->bi_io_vec. In the "bv" helper array, which is shifted by the value of bio->bi_vcnt at function invocation, the correct index is (nr_pages - 1). v2: improved readability following suggestions from Ming Lei. v3: followed a formatting suggestion from Christoph Hellwig. Fixes: 2cefe4dbaadf ("block: add bio_iov_iter_get_pages()") Reviewed-by: Hannes Reinecke Reviewed-by: Ming Lei Reviewed-by: Jan Kara Reviewed-by: Christoph Hellwig Signed-off-by: Martin Wilck Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/bio.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) --- a/block/bio.c +++ b/block/bio.c @@ -881,16 +881,16 @@ EXPORT_SYMBOL(bio_add_page); */ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { - unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt; + unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt, idx; struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt; struct page **pages = (struct page **)bv; - size_t offset, diff; + size_t offset; ssize_t size; size = iov_iter_get_pages(iter, pages, LONG_MAX, nr_pages, &offset); if (unlikely(size <= 0)) return size ? size : -EFAULT; - nr_pages = (size + offset + PAGE_SIZE - 1) / PAGE_SIZE; + idx = nr_pages = (size + offset + PAGE_SIZE - 1) / PAGE_SIZE; /* * Deep magic below: We need to walk the pinned pages backwards @@ -903,17 +903,15 @@ int bio_iov_iter_get_pages(struct bio *b bio->bi_iter.bi_size += size; bio->bi_vcnt += nr_pages; - diff = (nr_pages * PAGE_SIZE - offset) - size; - while (nr_pages--) { - bv[nr_pages].bv_page = pages[nr_pages]; - bv[nr_pages].bv_len = PAGE_SIZE; - bv[nr_pages].bv_offset = 0; + while (idx--) { + bv[idx].bv_page = pages[idx]; + bv[idx].bv_len = PAGE_SIZE; + bv[idx].bv_offset = 0; } bv[0].bv_offset += offset; bv[0].bv_len -= offset; - if (diff) - bv[bio->bi_vcnt - 1].bv_len -= diff; + bv[nr_pages - 1].bv_len -= nr_pages * PAGE_SIZE - offset - size; iov_iter_advance(iter, size); return 0;