From patchwork Wed Mar 8 14:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13165962 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 16761C678D5 for ; Wed, 8 Mar 2023 14:38:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC4846B0085; Wed, 8 Mar 2023 09:38:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A744E6B0087; Wed, 8 Mar 2023 09:38:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93CFE6B0088; Wed, 8 Mar 2023 09:38:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 83BEB6B0085 for ; Wed, 8 Mar 2023 09:38:46 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 564C5AAC14 for ; Wed, 8 Mar 2023 14:38:46 +0000 (UTC) X-FDA: 80545987452.01.C9BEE7C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 91BE420016 for ; Wed, 8 Mar 2023 14:38:44 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g7wvu3lL; spf=pass (imf03.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=1678286324; a=rsa-sha256; cv=none; b=xVSvXLYoQsX2F83YU7GMQFKR4+bKzsIsXaChiqmNr0F6rz6/KJ1w4FUsLGpZSDlOWQEABC 0S2TPt6+v2hXsQy/uxZ2HB0kuzxdRvcP2cyZuCXjX8Xl6cg6uLu+DFIPPckvPA87A9QVWy 82AUIBzg89vM77yn7vqSgSDW3XNkwQs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g7wvu3lL; spf=pass (imf03.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=1678286324; 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=1ttZpvPebCpVKzZO/gVzfXWczEWJgE2A6kNNeqiWhbFKBkrB8GP0avx69G+hB9zjwX9Jv9 iYmDebPKtIC2jTTSi/2GaT2RyaaEzAFs6r5YM5ml2JtpFDMD3e4kXB7gsBBABZQbFJwHXf rnD3bahLzBYU2rWJSVQCC4L93siWACE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678286324; 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=g7wvu3lLUQ8KJN1Z7rHEGmI8bIL8oZj8Qr5ZDcVbk7+OsthW/ENOBnraRBRhMEFK9DQMbn HYrF3mV10WMkY0dW7NFNCLRYDdE4ATfNWvGb2k0dUunJWVtUm1b3IGrXh7GOlZDgWmsAHh YYKC8mqOwSYvLWdrfy88B9WpCYf1+qw= 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-561-Gwr4SSb3NC615tqa25vaUQ-1; Wed, 08 Mar 2023 09:38:36 -0500 X-MC-Unique: Gwr4SSb3NC615tqa25vaUQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4D16858F09; Wed, 8 Mar 2023 14:38:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EC4C440D9; Wed, 8 Mar 2023 14:38:33 +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 v16 13/13] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Wed, 8 Mar 2023 14:37:54 +0000 Message-Id: <20230308143754.1976726-14-dhowells@redhat.com> In-Reply-To: <20230308143754.1976726-1-dhowells@redhat.com> References: <20230308143754.1976726-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Rspamd-Queue-Id: 91BE420016 X-Rspamd-Server: rspam01 X-Stat-Signature: z7uqkjswfuawdfyiyrxrbixsethrnzs1 X-HE-Tag: 1678286324-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aGbM3c3fuGSjvHg/SOtt0NQdaNLaML3KgMRvBpp12erl1AFRAEx+bakECFbLzamjIIuYjPne/Bg1bgsStqeEpkwqNcNEJ+Vkh0AJbKMo1Yv7w7xErgEzDJH/Y19eu/4xzE/TW1vKzy2eSZhZau1Rc+lTHhtj0DZrFlrmf0IkZ7i7uwEx0Ri8f+lgKJ7zJl92YtK6Wnzr26CRLUHidV4owkv+nUbTkOqe43vgPokDycnr0jtd8jeDUXUy/D44B0WNxdiVDZb0xlxQKVhOe61x/WQ62Bs7u06kOtcZZCR/6FhwXZjZo6e/9Vud1kC/Q47MdWaV13VJVWKzZTunHsSb9+dUpJnGqwDmIitEqjP4BwVdvRl+U0VKWbU8TjjIftdp6RYSCg96ELFssxkbroj1Sgz5Qjf0zTKdbDKl4/Tol5Ux125wmw== 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? */