From patchwork Wed Mar 8 14:37:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13165961 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 14DDFC6FD1E for ; Wed, 8 Mar 2023 14:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C0826B0083; Wed, 8 Mar 2023 09:38:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34A346B0085; Wed, 8 Mar 2023 09:38:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EA6F6B0087; Wed, 8 Mar 2023 09:38:42 -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 113226B0083 for ; Wed, 8 Mar 2023 09:38:42 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E94E81A06B6 for ; Wed, 8 Mar 2023 14:38:41 +0000 (UTC) X-FDA: 80545987242.19.7F9A503 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 3D11918001C for ; Wed, 8 Mar 2023 14:38:40 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MIW8cIro; spf=pass (imf06.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=1678286320; 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=7b6tezcmsCRtrHxO2uDV+B0gtFM5s5ObrJQQe5H2QZI=; b=NtflZAW3LJ5aih3M/hEi94LTBMjAQNTKkWEpSQCUy4Dn+sCsHjVngXPJpKaZ/x9cEP3kuH TaA4FfMKmVNPaWtaGV4Z4NKwQX/o4epXH06HlrvqAs2Njltj0XNTphrrmGIxEVkETGoESi kFSj/JGSPETbxETMn9ea3RQ41FvcSGU= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MIW8cIro; spf=pass (imf06.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=1678286320; a=rsa-sha256; cv=none; b=2ixACymIxhvpx5bdsH+ncVqMN5wz0Mi/n2LQiZgVIji59YlfRIaefsa/j0QoiK0H22QxqG H4DcBne37eoLSSip6kwMLvTqvgv0ODW3/oeGq7DAYuFQ/Q2DXBWaW2QRlHwQJ/Qgq5nn84 FIPIOYivCr7dFbL6UIILbPYhpTr0vWI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678286319; 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=7b6tezcmsCRtrHxO2uDV+B0gtFM5s5ObrJQQe5H2QZI=; b=MIW8cIroCYZs6LPkKy51w6N0nLba+VioKsQ9W83mLC+m2s1ykDf/63TDg8xDjo6KdZBhCS jxodRbKagV/lTiCu+3Hk3cDBTHYUgnbY3lpHaO6PeT2v18JDP7hWiw2Yy37IfzcSZAJpWn dq7REaTOg/Bo2+m+SU2ZkTfYham4J68= 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-63-tDBcsQw1OWOKllv3Uzl2mQ-1; Wed, 08 Mar 2023 09:38:35 -0500 X-MC-Unique: tDBcsQw1OWOKllv3Uzl2mQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09511384D043; Wed, 8 Mar 2023 14:38:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 067E8492B07; Wed, 8 Mar 2023 14:38:30 +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 12/13] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Wed, 8 Mar 2023 14:37:53 +0000 Message-Id: <20230308143754.1976726-13-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.9 X-Stat-Signature: o55ygkqakthdgwq5a53mkmnt3f9wbrzh X-Rspam-User: X-Rspamd-Queue-Id: 3D11918001C X-Rspamd-Server: rspam06 X-HE-Tag: 1678286320-364251 X-H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55L//V2C8/Wr35Qhw8nqcCsc6N90wmLwAXND02CT/LU8PZCYlVp3bLHOi+tIlc9C0CiQlrCqshFW2FTwtbDsYDt9zYSUmzfWW/lfkbpF9bHcSmV3r6Jjl6P4S33BzYhE/TMkA+v/bZEqJ1xYIWI7Hm8hSWfZ4vYserL+Z/K3WNbLUOaSVZ2yUGuW3pWCWoxvKD4oX8mnM/BCsnLn+DZZTSlm4am1Z7HUbtSu5K04dzyIVFzxHZsj/+CthRWUz0UY/F85hAP/xhWPfZWfKknvV4MMSYpbOdbaVQoX171VeoII5p+jHVc7LMoE7s8FPN8Et6DezdKEqafZY+a10DZky7s7BK8zCKCjlC8jTrevs4HqIACOmCGYAgA0yCy17+8k1TqAibZ9rZAF2xMVWhzIpuyC6vXZvK6f2be0/8Q== 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 affected by/visible to 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/bio.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/block/bio.c b/block/bio.c index 51ae957cc4b6..fc98c1c723ca 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1204,7 +1204,7 @@ static int bio_iov_add_page(struct bio *bio, struct page *page, } if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1218,7 +1218,7 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, queue_max_zone_append_sectors(q), &same_page) != len) return -EINVAL; if (same_page) - put_page(page); + bio_release_page(bio, page); return 0; } @@ -1229,10 +1229,10 @@ static int bio_iov_add_zone_append_page(struct bio *bio, struct page *page, * @bio: bio to add pages to * @iter: iov iterator describing the region to be mapped * - * Pins pages from *iter and appends them to @bio's bvec array. The - * pages will have to be released using put_page() when done. - * For multi-segment *iter, this function only adds pages from the - * next non-empty segment of the iov iterator. + * Extracts pages from *iter and appends them to @bio's bvec array. The pages + * will have to be cleaned up in the way indicated by the BIO_PAGE_PINNED flag. + * For a multi-segment *iter, this function only adds pages from the next + * non-empty segment of the iov iterator. */ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) { @@ -1264,9 +1264,9 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) * result to ensure the bio's total size is correct. The remainder of * the iov data will be picked up in the next bio iteration. */ - size = iov_iter_get_pages(iter, pages, - UINT_MAX - bio->bi_iter.bi_size, - nr_pages, &offset, extraction_flags); + size = iov_iter_extract_pages(iter, &pages, + UINT_MAX - bio->bi_iter.bi_size, + nr_pages, extraction_flags, &offset); if (unlikely(size <= 0)) return size ? size : -EFAULT; @@ -1299,7 +1299,7 @@ static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) iov_iter_revert(iter, left); out: while (i < nr_pages) - put_page(pages[i++]); + bio_release_page(bio, pages[i++]); return ret; } @@ -1334,7 +1334,8 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) return 0; } - bio_set_flag(bio, BIO_PAGE_REFFED); + if (iov_iter_extract_will_pin(iter)) + bio_set_flag(bio, BIO_PAGE_PINNED); do { ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0));