From patchwork Tue Mar 14 22:07:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13175058 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 CB5D2C7618D for ; Tue, 14 Mar 2023 22:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 669FF8E0010; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61A158E000B; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1BE8E0010; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3F0508E000B for ; Tue, 14 Mar 2023 18:09:05 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 13F8BA037E for ; Tue, 14 Mar 2023 22:09:05 +0000 (UTC) X-FDA: 80568895050.23.C63B3DC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 590D22001E for ; Tue, 14 Mar 2023 22:09:03 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gigarPfn; spf=pass (imf13.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=1678831743; 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=aeS9tKbIZKULa0AyWq3uuRPvVmQvXtuHBH4vTUau3iEWxVP9F+SJZgrT3U+N5Fhh4XIjle IP+SkAM0+9lOititEGzjyLHMl4pzeq9q7F9106f8R7j1ZyBCxlCwTXQj+OBYixPCtT9oWw Ig3q1/n1jTCztRHmMQK2HCNiwJht/ts= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gigarPfn; spf=pass (imf13.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=1678831743; a=rsa-sha256; cv=none; b=Ve+FCjAYGMJ+Is1ig2VZFmt0/bS8rgJUKBB+6xxTEb2tmI0+eYZ2i3UbI4W9UkeCQiLmlD gMvJPezKWD7pkSikB+zudbkKzyjRTC16bPC2pfGvtABYohHgfhV+YJZrXpnsKFUhE42qZR s2k4Ob7M8QeXSvGd/JAwIN7BhpKP84A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678831742; 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=gigarPfncQ24JpmGkxEkWHw52jpUSt1R5Zkkc6NS8lVbiXt8YWMDLy5G0Cm3lolXdf+GAt 4jcm63l23iAei4M93G2Myo0QpY90x5qZC6D13mlkjlQsKNIflujGyvJt5lQtwzTRX4wwTb JkRPVXbIHQdYGpLw/EHf/9pqID/kHzA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-167-ZOrmw3hpN2OQ1vha5UlzMg-1; Tue, 14 Mar 2023 18:08:52 -0400 X-MC-Unique: ZOrmw3hpN2OQ1vha5UlzMg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 129C91C08791; Tue, 14 Mar 2023 22:08:51 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC4CA47507A; Tue, 14 Mar 2023 22:08:48 +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 , Christian Brauner , 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 v18 15/15] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Tue, 14 Mar 2023 22:07:57 +0000 Message-Id: <20230314220757.3827941-16-dhowells@redhat.com> In-Reply-To: <20230314220757.3827941-1-dhowells@redhat.com> References: <20230314220757.3827941-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Stat-Signature: 1rkeupjkxtk8uh8t4f1h466tohrbyi66 X-Rspam-User: X-Rspamd-Queue-Id: 590D22001E X-Rspamd-Server: rspam06 X-HE-Tag: 1678831743-166531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btmP10qjuQlPo/w6ZBrnKN2/DrL+4HgFGzhOwRpXQunXVlLxZBFnJ5sxOHLvVkEHOaHOW6YPVdi8CrgyfzJ0uD2SvWlczM6HxPLn2+xNsCLfhrSZ/b3V6lg0Nk6LofxyCmavpjHlxbkZWHf5v3DNu1/r2ESDIrqWamQD+cdD38N1WmCW/8OmJpBhVS237CaWeNHxDnhXg3PthyX8p4zuHP2lgInGxrtBlbI8sYEX15ijWFk3HxnZV4MQzs0Z4nPPKebYFgUwbAwXsL6un6idRFprcymdqMpKpDXLmfISSsLHPSamrpNksm0DEYoWYofHFRCfQCE9rkQ9cVdnqiWAY7kPGBvwdim6krIg9t36iMod31tUZttw1CO+uCOl399aHotOd3DFnabKCsmrzsYH+v/jhySAxSnoAJPqw== 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? */