From patchwork Wed Mar 15 16:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13176346 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 F1954C7618D for ; Wed, 15 Mar 2023 16:36:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833416B0089; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E27C6B008A; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683986B008C; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 57F326B0089 for ; Wed, 15 Mar 2023 12:36:53 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 00A70C081E for ; Wed, 15 Mar 2023 16:36:52 +0000 (UTC) X-FDA: 80571686664.15.CF67DC9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 3E13D40027 for ; Wed, 15 Mar 2023 16:36:51 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P2AOPD+b; spf=pass (imf04.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=1678898211; 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=vt2uOWVgp5fKOHH8UEZ/PXCfiWtqqQ4S6Ax2mT6r+9cz3JUF5aeUAuWnkNNzTzIHM+b2xp hu+wpYm/D5cXQFBXS7AoD/z8oBlV/0rRIxYuLsDyZKzC6mNylv5hq0Iw0qpuE9AWJTK7BD T2jTqZHg1kGlg8YR3OwOrmRqvYp5vr4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P2AOPD+b; spf=pass (imf04.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=1678898211; a=rsa-sha256; cv=none; b=okSJ5Mtm2hssLX9f9rkJSYwjplqk1ICDJ011T3kIDHfUrG+awXLMlTSE8QtogQ4X5KAmAh Rw44eNSMR0lnmLNLHa6afg5+h34JYSYUbxqvzGFvsMTIikFGm+htaJKyKwYBl+OGo5hfFZ sl+NtENA7AJTtqSMYU3AHEfWGy1abCQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678898210; 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=P2AOPD+bppm4Wo/8L6cSalSo3tl8nwERthPm3V6ZaZ8sVGOu8tDbyNhZhH2bj6c2TD1Dtg /ifMqHO/1bZa/RrvB6phZ5aRUljxPSCY+Q9x47q1IOZ2gRtgu2XGsigtoexTEnjUuXv/d2 Yq6r9S3D0jmmiu4V4MwOT6Rjf5FpOMU= 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-623-xwMSkeoeMNWvPvIQXGfjEA-1; Wed, 15 Mar 2023 12:36:47 -0400 X-MC-Unique: xwMSkeoeMNWvPvIQXGfjEA-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 02AAC88B7A7; Wed, 15 Mar 2023 16:36:38 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id D85421121314; Wed, 15 Mar 2023 16:36: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 , 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 v19 15/15] block: convert bio_map_user_iov to use iov_iter_extract_pages Date: Wed, 15 Mar 2023 16:35:49 +0000 Message-Id: <20230315163549.295454-16-dhowells@redhat.com> In-Reply-To: <20230315163549.295454-1-dhowells@redhat.com> References: <20230315163549.295454-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 3E13D40027 X-Stat-Signature: dtdtqa4wgi8qdn77hn9ayqug1ywcqkte X-Rspam-User: X-Rspamd-Server: rspam08 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rqzuG+sTeGklo2ukIQ8Fml/EfXCmLNfe5Po6ELKzHZeyQgbPZOtxpjPhfiW3QY3lAqy57iI9IV5yxRtRnEGSIhR0jUCt9k50V2/yfbGxuvyByq45EYcuu5bnVYOcT6g/sTUHEtCI0CZakTbhxBBmlRdylddvGfbD9CwFzPhey7v7rBKLWIyTFTviPhTNPTScPgGiFd12K/oD+rrkEE5erpmdv3ExVhivnCueF22FSJR76K2WdwJjsaUC2yZ0tn9rSQvr6dW0Vwh0grz9FUcxUGtkQozFiivwBUWnIAgKVyVnCGN4cWiJaYMo/xgRMgck4ma9vleS0tMQRSTjAPpjFH2kR6pwzOKD9PBunfkpA1WaQWN8fYSE3LYjcSaNV9HUFtU019Beebi15tOHBb7u3QO9r+bXeYYNr/ryT0NVrLUuFEHIJd26mbOVxA== 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? */