From patchwork Wed Jan 25 21:06:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13116177 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 1BDBFC54E94 for ; Wed, 25 Jan 2023 21:07:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B314F6B0081; Wed, 25 Jan 2023 16:07:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB9F96B0082; Wed, 25 Jan 2023 16:07:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90BA86B0083; Wed, 25 Jan 2023 16:07:30 -0500 (EST) 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 7D79F6B0081 for ; Wed, 25 Jan 2023 16:07:30 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5DC408085A for ; Wed, 25 Jan 2023 21:07:30 +0000 (UTC) X-FDA: 80394557460.19.0EC178B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id AD39A14000F for ; Wed, 25 Jan 2023 21:07:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZbRgbNvV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674680848; 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=eEzlfYU/tqpy6qDlnj3bxdUXICRLHkKU5QK5uzYqBQA=; b=78w/NnMqdZSZtAoPtc6sRV6ohf8VvOk/ld5grOjx4CNehF1FndynYj1Q7oIPbxHU6Wxawj pbJo2hToeyEIpE23c71UoUenwYWEZTd66PpD8Iah1qy7ystrS+RB6HQfvNNDMqqQfCxFqw WJAvz5LjJyu82R1JFfS558CIQRhMgn0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZbRgbNvV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674680848; a=rsa-sha256; cv=none; b=dDqQiukRDPiu8H65c/YWdOsas+WSyzhsk1F5qm0JhEWZMCZcBlogEdpfDEN5Bxx3nfKE3e 4uiEyU1zKXYYIKX3ZZes2Ujsz+QdFaXbLdKSXY8uIg6LbiJYPzORtHdNhjxaeGje3HmQZm ok/XyFn7GENTs5MXXtycQT2QygM/w1Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674680848; 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=eEzlfYU/tqpy6qDlnj3bxdUXICRLHkKU5QK5uzYqBQA=; b=ZbRgbNvVzS2Mfb7v+vI2BR+p5Ej6SR88sIt8NCQShJd2hi1wWVPe8bWA+KfWbkdTKEHoDj WsWvnKSgIQFonYZVJc3U05yLZT+iwpopS2ZMgMRuWdr5x16u2iYr3wpbO1SuX+Mh/4/c/X tjhvnncvFJ23Hlm8eICekQnooDDQq9s= 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-331-RfvTkJ_FN4KVukCYXckWLw-1; Wed, 25 Jan 2023 16:07:23 -0500 X-MC-Unique: RfvTkJ_FN4KVukCYXckWLw-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 BFDFF85CCE2; Wed, 25 Jan 2023 21:07:22 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFAC414171BB; Wed, 25 Jan 2023 21:07:20 +0000 (UTC) From: David Howells To: Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jens Axboe , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , 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 v10 7/8] block: Convert bio_iov_iter_get_pages to use iov_iter_extract_pages Date: Wed, 25 Jan 2023 21:06:56 +0000 Message-Id: <20230125210657.2335748-8-dhowells@redhat.com> In-Reply-To: <20230125210657.2335748-1-dhowells@redhat.com> References: <20230125210657.2335748-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Queue-Id: AD39A14000F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 7xdozune69ongd41kchy8ib48osu3535 X-HE-Tag: 1674680848-895909 X-HE-Meta: U2FsdGVkX1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WE8yEuzWnw3t/ZAv2DcO7Bl5c3KlCEmaSNAPlfp+HwTLwuAkXK5ZLP/hNrWj/tTmAfwlXhsKHDmVFUboulbZffpKIl+cBGcVe2S9/RVGzbmd9cRh2yeSX4XKn2oCdTWT8Ugm1qZLsne5hNY9UKUhuQjLoEkEyz5ku3KptFpOklxdeRJ5LgG5faJYuA46X5jVsyWQF/MzXbulc7mBdup/8G4lvaCgrgBmAHsLZNOi+DLEqGvSOdjw4gELFoa3omvQl9ZyhSY98QH7JRG6Kx1XHj7YleD1VPzcARAgR6JIo3m23/6Ve/G7ZQC2DcXrhST3CvO4F6V3t1ydjYdGE4rZCeWz0qVf9sPR7wEXTMUfBbIrPtUrYqRNbF5NC5MI9Fq/Fw== 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 fc45aaa97696..466956779d2c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1212,7 +1212,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; } @@ -1226,7 +1226,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; } @@ -1237,10 +1237,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) { @@ -1272,9 +1272,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; @@ -1307,7 +1307,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; } @@ -1342,7 +1342,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));