From patchwork Wed Mar 8 16:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13166170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B215C678D5 for ; Wed, 8 Mar 2023 16:53:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA6A9280007; Wed, 8 Mar 2023 11:53:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C31066B0082; Wed, 8 Mar 2023 11:53:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAA386B0083; Wed, 8 Mar 2023 11:53:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 95A646B0081 for ; Wed, 8 Mar 2023 11:53:48 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 032FA1A06B3 for ; Wed, 8 Mar 2023 16:53:47 +0000 (UTC) X-FDA: 80546327736.19.8AA8CDF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 09729C0021 for ; Wed, 8 Mar 2023 16:53:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JxKwvN2s; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678294426; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gIKMSgtKI0+T2jjDihR3uNZ9dKHoZzHE/RnqYef6EBU=; b=wZhYo+I8SSSGArHG3AwmNJ7aK5FQif+SW1fxiMOeCMYLyfLlBdozsuOOmBjWKY4zB3fALp eh7Ab8q+DFt+0LKFPWwXI84vVwv4xeTS4K9Fxs5tNfSXs54rMdoJQMS4OY+BpadlcNpVih k57lVINw44hNiT0mxXgR3WBBrStmQco= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JxKwvN2s; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678294426; a=rsa-sha256; cv=none; b=RT/MObXGEf7oEOt9JGbuCCoP//BVKNjYzFveoB88oMJkc9s52tSzqlYbniSNXVxreH6Nr+ zvyTV+OOD1yNkkoeUFtG5EW93bbmJacZdJma6a8tzijlvVqdGyqlezVAXDw5qp+AOQcgaw w1v+y/mQTwH5/zfFCTDMXwsg4XJVDCM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678294425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gIKMSgtKI0+T2jjDihR3uNZ9dKHoZzHE/RnqYef6EBU=; b=JxKwvN2s9N7I+fG6nrIs1jEtX7w4AvWrrk2xiZDCVOwuEj5TGBqXpKrcyB6jq0G13NP70S SR4meaACkYlJyD/X1ohZYJC+TMgg4suqr7lwQZpO+eFE+YB65palEDAD2OyUpzlq70WUJY 6MvnJY60qDiT3WFhf0jWzULpt0p7FH0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-kBmAFUeENu2Sp64iGCfrUw-1; Wed, 08 Mar 2023 11:53:40 -0500 X-MC-Unique: kBmAFUeENu2Sp64iGCfrUw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E02FE882823; Wed, 8 Mar 2023 16:53:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCEEA492B05; Wed, 8 Mar 2023 16:53:35 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v17 14/14] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Wed, 8 Mar 2023 16:52:51 +0000 Message-Id: <20230308165251.2078898-15-dhowells@redhat.com> In-Reply-To: <20230308165251.2078898-1-dhowells@redhat.com> References: <20230308165251.2078898-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 09729C0021 X-Stat-Signature: s6hb7uzmqpa78mpnpsxab7np54y9ujwg X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678294425-899934 X-HE-Meta: U2FsdGVkX18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u2qpTBDlEyy1jRztXapZlL0jYs8QfBVGTClgDoHp4UMmnLp3JPfg0S3+XJy8Dd5fKZOP6B8XVzsMou9cVkpkH1U1iQg1hrSw931UxUGbnEI4d3Qipl4oZtZj3G4iCHcDy1KExQIAzHXcAEmN6gAwYop2BQ1zSStTquKAQc2isx2oQmTsTIqnzluATMmqSHRaAjJK/ZhWuwVC1HtDDeI30mLjID5au0Fwqc8yaMWtVyEKhS9nujsBWQSm6wV2ZYx+hUqkCXOMfPvVhWIHy5IqfZdn2nuek+1NII3QMFXUUQdTLGVJJtdqDOnxgLAEcysUynRF8WN4pAUAylGO7vBGXW79xF8ALrN7JfFw8Zj3a8Pxmh7VNeJCjw+zbpIMy/1ziQ== 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: This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O could otherwise end up being visible to/affected by the child process). Signed-off-by: David Howells Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard cc: Al Viro cc: Jens Axboe cc: Jan Kara cc: Matthew Wilcox cc: Logan Gunthorpe cc: linux-block@vger.kernel.org --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #8) - Split the patch up a bit [hch]. - We should only be using pinned/non-pinned pages and not ref'd pages, so adjust the comments appropriately. ver #7) - Don't treat BIO_PAGE_REFFED/PINNED as being the same as FOLL_GET/PIN. ver #5) - Transcribe the FOLL_* flags returned by iov_iter_extract_pages() to BIO_* flags and got rid of bi_cleanup_mode. - Replaced BIO_NO_PAGE_REF to BIO_PAGE_REFFED in the preceding patch. block/blk-map.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index c77fdb1fbda7..7b12f4bb4d4c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -280,22 +280,21 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (blk_queue_pci_p2pdma(rq->q)) extraction_flags |= ITER_ALLOW_P2PDMA; + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); - bio_set_flag(bio, BIO_PAGE_REFFED); while (iov_iter_count(iter)) { - struct page **pages, *stack_pages[UIO_FASTIOV]; + struct page *stack_pages[UIO_FASTIOV]; + struct page **pages = stack_pages; ssize_t bytes; size_t offs; int npages; - if (nr_vecs <= ARRAY_SIZE(stack_pages)) { - pages = stack_pages; - bytes = iov_iter_get_pages(iter, pages, LONG_MAX, - nr_vecs, &offs, extraction_flags); - } else { - bytes = iov_iter_get_pages_alloc(iter, &pages, - LONG_MAX, &offs, extraction_flags); - } + if (nr_vecs > ARRAY_SIZE(stack_pages)) + pages = NULL; + + bytes = iov_iter_extract_pages(iter, &pages, LONG_MAX, + nr_vecs, extraction_flags, &offs); if (unlikely(bytes <= 0)) { ret = bytes ? bytes : -EFAULT; goto out_unmap; @@ -317,7 +316,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, if (!bio_add_hw_page(rq->q, bio, page, n, offs, max_sectors, &same_page)) { if (same_page) - put_page(page); + bio_release_page(bio, page); break; } @@ -329,7 +328,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, * release the pages we didn't map into the bio, if any */ while (j < npages) - put_page(pages[j++]); + bio_release_page(bio, pages[j++]); if (pages != stack_pages) kvfree(pages); /* couldn't stuff something into bio? */