From patchwork Thu Feb 9 10:29: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: 13134349 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 AB570C636D4 for ; Thu, 9 Feb 2023 10:30:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BBC16B0083; Thu, 9 Feb 2023 05:30:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96FFF6B0085; Thu, 9 Feb 2023 05:30:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FA7C6B0087; Thu, 9 Feb 2023 05:30:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 556B76B0083 for ; Thu, 9 Feb 2023 05:30:37 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 35F7A1609D9 for ; Thu, 9 Feb 2023 10:30:37 +0000 (UTC) X-FDA: 80447384514.25.A7B15CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 7B27B140021 for ; Thu, 9 Feb 2023 10:30:35 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KOKZsLzY; spf=pass (imf09.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=1675938635; 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=kPiXN6F6Xfu70lVn55rQaj7iJSrUpg0aKLFVQNrDiQUC0M49b3awxubxxYYuBW95W4wsLk tJyUehrZU5GOMFVeMP+XYFRb+yp+kOD2SswXEb4stcOHz35lGCfyaY2wOf1b7+QIzPnEno VNVNeDbsjWLMptJXdFR/Bdqwsj7/8zQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KOKZsLzY; spf=pass (imf09.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=1675938635; a=rsa-sha256; cv=none; b=4wlVRiLhTdnGxD33MNdlsn2Y06YpqypB3vAihIefZTtflah+/yDQgkJn0I5VSGGKT3cu3P y8YfZsOHC/Muj8qxsT0tABZddz7/Tm8ZjJUcxf5W3z7up7woVnluwQ+GpMVWFX+pCT7ice IfG4t3VzYD6Dir5EUyCJpDN9mk/tPCc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675938634; 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=KOKZsLzYA9YeQE+dygKUxbWFT3v3jX/jRXQXg9MNgGNuQrBAjjCwJLawHvwI7OhV+7kVNH efFAJ+DVfU8ilEPk1fz+6Xeo/JG1B4MiiiYaTtjUdb69yOxRaz7497Ws8HrdPzFpaG7xya 0J0WG38V/bZt2v7U8KrVFtfqGXkvYgA= 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-657-CE4ph_C5NsGWDH9cPINp8A-1; Thu, 09 Feb 2023 05:30:31 -0500 X-MC-Unique: CE4ph_C5NsGWDH9cPINp8A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5B3385D062; Thu, 9 Feb 2023 10:30:30 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4D75140EBF6; Thu, 9 Feb 2023 10:30:28 +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 v13 12/12] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Thu, 9 Feb 2023 10:29:54 +0000 Message-Id: <20230209102954.528942-13-dhowells@redhat.com> In-Reply-To: <20230209102954.528942-1-dhowells@redhat.com> References: <20230209102954.528942-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7B27B140021 X-Rspam-User: X-Stat-Signature: tt69xih4pxz4ytqtqnnwbj46sxs3y5nm X-HE-Tag: 1675938635-50466 X-HE-Meta: U2FsdGVkX1+l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bNBFJtlwht1wylWZv7DnEcHIF3scVlywF7LYmaex0XtJr+FY2dDYcPyNf1TLM4UpU4GodvRYeUW0cuzucC0/nrK1ylRgysYQontug2dHRxWARN+e9r6iOIlGlGSCIVsF+pT2P3C63/LNhhrf64j82qHeUK09PG6DRcAB0i9hKtj3Lzx1j2L1KWFOFg5LHxSWxh1nzvP16jo9Z6AWhPl5Ux5cEGtGJH+RmyNXAn6gtYTWzl8au5L81kdMjIK4InoSuGc5s71FQZFSe1AUJyiSO8p4XsFF8ghWJJYWoVycphlZWGNXoaveVipRhc1NB3C8XNtv3QXHtImTS7VzLRFXOKsnaGmrytQlwqCY9ltRmuMYoklbHNC75r0zXHGKbhCjHz/ID86Sw== 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? */