From patchwork Tue Feb 7 17:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13131888 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 5259CC636D3 for ; Tue, 7 Feb 2023 17:13:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3C45900004; Tue, 7 Feb 2023 12:13:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DECCA900002; Tue, 7 Feb 2023 12:13:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB60C900004; Tue, 7 Feb 2023 12:13: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 BA175900002 for ; Tue, 7 Feb 2023 12:13:46 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8D38D120A4A for ; Tue, 7 Feb 2023 17:13:46 +0000 (UTC) X-FDA: 80441142852.24.05BE0CD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id C4F351C000B for ; Tue, 7 Feb 2023 17:13:44 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IoCSlkNO; spf=pass (imf20.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=1675790024; 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=7RYncx3d2QCFno76YxQ26A3gARIW2WsBk/g5n5z32ew=; b=tV8T+Yod3D1A+EffVfe0SJ+242JA0xBP7uqRFbiGtzqd6qEHeMsDCj5+vsKHWaXj+n0nDY O3H1I/QJoqjL9zgCD1oe7GNnMe1XpvmsIrLIwUgjoQOFhb0WDDUPQtJkINMuWZVrGm/KFf R1sPEXg5BZIBdNSApbyLUBtn86N2A5Q= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IoCSlkNO; spf=pass (imf20.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=1675790024; a=rsa-sha256; cv=none; b=uSGdMwsvpA0A8ts+Wj+14R4Nb7GJdnBq/Oz2dndo7BScX6bX9467Aw37SUUl4B6LCAbbuq IUyV2uxYkyMd2gAhr0d02v0wn7YVxoqYXtE2fdvSeW87POcCs8pEistLFkzWFJugV6Pxnq +p9Y+JX52XC+03bq1K6sgpGHw58jdf4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675790024; 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=7RYncx3d2QCFno76YxQ26A3gARIW2WsBk/g5n5z32ew=; b=IoCSlkNOt7CrFrcCpJ6QK5ZwjVHg+hQzjg0+qm5bzRog0pqovQmc79wKjWGeALTidRA+lW mXU5ppj4m3muCXuF4tvfx7rvVGyDp/llePrvAXazxU5l/2/m4jnH77g479DPEWNCWnx2YQ ry4gxn40tj6W6bany9TR4x/Hf5UMkzw= 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-73-lolXqV_9N4uHxYJn3WqZgg-1; Tue, 07 Feb 2023 12:13:39 -0500 X-MC-Unique: lolXqV_9N4uHxYJn3WqZgg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC1C480D0E2; Tue, 7 Feb 2023 17:13:38 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A3F01121314; Tue, 7 Feb 2023 17:13:36 +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 , 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 v12 10/10] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Tue, 7 Feb 2023 17:13:05 +0000 Message-Id: <20230207171305.3716974-11-dhowells@redhat.com> In-Reply-To: <20230207171305.3716974-1-dhowells@redhat.com> References: <20230207171305.3716974-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C4F351C000B X-Stat-Signature: 1d5fk1dkdhfdxsyqd19gyfoqmgnicg5p X-Rspam-User: X-HE-Tag: 1675790024-411511 X-HE-Meta: U2FsdGVkX18eLQhOMBLYP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eGB4pyumdEE/oFH4JMm8lw8mlInGCOlOd7zJuZVqGl+Ex4/KuLZ9ktd1foYlQVlAoX2DqTf9R89vLHuDj0hm/6VqPewFBdJFeN8mF1fAKn5b3GXi2AiZSK8Al0yk9NO2atJscjMvorDvFUZSHsmwAJfDlAb5fIAiMLr879wcZn84RT/jLa5nRXs4nNkfqSLnPrU/OexUQnGuD0NTBkOZ3+1cSkX7IPUhdfMid5+HhvkMR/KTtQT8JIARf8BMjaGLJX4mqtpp8OXLQ/hlDN6pIQTUHMIJs9CuqBcQ49pG+hKhl2Z9/1ynUp9vSKsqGQYJC23RJX2ASmQMb/B56IiQuxcqsXd3DyRvHea/DFsTez+yIxrqIcf5qxHadEhTVOWgv3Yw== 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 f1f70b50388d..0f1593e144da 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -281,22 +281,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; @@ -318,7 +317,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; } @@ -330,7 +329,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? */