From patchwork Wed Jan 25 21:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13116176 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 CCC14C27C76 for ; Wed, 25 Jan 2023 21:07:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58A276B0080; Wed, 25 Jan 2023 16:07:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53A8E6B0081; Wed, 25 Jan 2023 16:07:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B43D6B0082; Wed, 25 Jan 2023 16:07:29 -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 2C5F26B0080 for ; Wed, 25 Jan 2023 16:07:29 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DCEB3120E6D for ; Wed, 25 Jan 2023 21:07:28 +0000 (UTC) X-FDA: 80394557376.07.0E491BA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 39E441A0025 for ; Wed, 25 Jan 2023 21:07:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Ffx/JJ1O"; spf=pass (imf19.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=1674680847; 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=e+R2Fab+zsp5/4JKdTrc4PXZk8RqADa0qecJwQvHEwc=; b=fu7q7U0pGhIxbw5QghgcJuKWD2mTV+MKd/wDy0MOGsCHunOQQRGoGltfRfujZ5uQiQv4hr hlTPPtpUvnmPaOC/eAjDkK+i20hzlyjzTmhUEMjnZ0IU2Fn5qLxL/GP69eySwEvWPMjWrg HvDqCbWF6o6vzR0cdt+jN4odZqp9Iao= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Ffx/JJ1O"; spf=pass (imf19.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=1674680847; a=rsa-sha256; cv=none; b=saIAG9j8UQa3YyNXLEj77dCmCVNTa1NPUfNeONt/xTHEy8OhJxwAiJhF0/MCY8y4bc75QQ kzpezGv+PSfcXw3qLF6sBeNTn79vux9Oz01EbCkXQ6YmN4PlNDzPqTBHfXok0dt55aOrKq c5Nqvletn8NTpx1RRGNUiQbjNj7+QOo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674680846; 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=e+R2Fab+zsp5/4JKdTrc4PXZk8RqADa0qecJwQvHEwc=; b=Ffx/JJ1OT0lCzNtlpRmsdAVQi9qCZKcRfB9vV85rcCWhxj7xoKLz+n8BOEdLgWeSq5O3Jg HmJ0thqpznMpX9fESNGsxk9lRnbEM36z1b+eEr7KmOQK93yn4JcUaiVBm1l/K9WHJPQL6O soBtPKxaBUhHH8LDhOX32KCoO5OgAYc= 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-47-63ymXbHLOMShaBfr1SrLhg-1; Wed, 25 Jan 2023 16:07:21 -0500 X-MC-Unique: 63ymXbHLOMShaBfr1SrLhg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0770285CCE0; Wed, 25 Jan 2023 21:07:20 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.33.36.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF1B12026D4B; Wed, 25 Jan 2023 21:07:17 +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 6/8] block: Add BIO_PAGE_PINNED and associated infrastructure Date: Wed, 25 Jan 2023 21:06:55 +0000 Message-Id: <20230125210657.2335748-7-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.4 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 39E441A0025 X-Stat-Signature: mpqf91qddt585r9rndhmxr1n5645h7ry X-HE-Tag: 1674680846-968516 X-HE-Meta: U2Fsd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C+0Wch7rRZyzxAq2jIyFVc2HUbYWfIf6t39bXWdAZTgDV3/VPY0OGArvlSzzmUJNGhsnAUHNjtxiFogEnEdQ5jQtvwylgUhDpR32fYU0TqcaOyd//PmQLA2lOBjddwxXotoCTqNKeKFdAheVBRGm+EMP2SUM6NgEJWHn3rh4sGIeh2U0+mFppKJsnh4x0X5h1o2APySSt6a77isHLhHy+Sd3AgwDszuuW5WRoM7RsshWvrWVYBYYU+RV10DvC1MzrHh3xFXGeJvU3sCXdBgIo7j40zSIoqm/vrsKfhI2igX0UMjijrV3u2VnW+MGkl8GD5qX6pD4Dts6lN5vZpOmlZGp3UtQncM32xhuiVFVIFGk+MyvHI0GGaYlqCW0wXO8VXxGl3vNtfBu/GywZUBw== 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: Add BIO_PAGE_PINNED to indicate that the pages in a bio are pinned (FOLL_PIN) and that the pin will need removing. 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 Reviewed-by: David Hildenbrand --- Notes: ver #10) - Drop bio_set_cleanup_mode(), open coding it instead. ver #9) - Only consider pinning in bio_set_cleanup_mode(). Ref'ing pages in struct bio is going away. - page_put_unpin() is removed; call unpin_user_page() and put_page() directly. - Use bio_release_page() in __bio_release_pages(). - BIO_PAGE_PINNED and BIO_PAGE_REFFED can't both be set, so use if-else when testing both of them. ver #8) - Move the infrastructure to clean up pinned pages to this patch [hch]. - Put BIO_PAGE_PINNED before BIO_PAGE_REFFED as the latter should probably be removed at some point. FOLL_PIN can then be renumbered first. block/bio.c | 6 +++--- block/blk.h | 12 ++++++++++++ include/linux/bio.h | 3 ++- include/linux/blk_types.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 851c23641a0d..fc45aaa97696 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1176,7 +1176,7 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty) bio_for_each_segment_all(bvec, bio, iter_all) { if (mark_dirty && !PageCompound(bvec->bv_page)) set_page_dirty_lock(bvec->bv_page); - put_page(bvec->bv_page); + bio_release_page(bio, bvec->bv_page); } } EXPORT_SYMBOL_GPL(__bio_release_pages); @@ -1496,8 +1496,8 @@ void bio_set_pages_dirty(struct bio *bio) * the BIO and re-dirty the pages in process context. * * It is expected that bio_check_pages_dirty() will wholly own the BIO from - * here on. It will run one put_page() against each page and will run one - * bio_put() against the BIO. + * here on. It will unpin each page and will run one bio_put() against the + * BIO. */ static void bio_dirty_fn(struct work_struct *work); diff --git a/block/blk.h b/block/blk.h index 4c3b3325219a..f02381405311 100644 --- a/block/blk.h +++ b/block/blk.h @@ -425,6 +425,18 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset, unsigned int max_sectors, bool *same_page); +/* + * Clean up a page appropriately, where the page may be pinned, may have a + * ref taken on it or neither. + */ +static inline void bio_release_page(struct bio *bio, struct page *page) +{ + if (bio_flagged(bio, BIO_PAGE_PINNED)) + unpin_user_page(page); + else if (bio_flagged(bio, BIO_PAGE_REFFED)) + put_page(page); +} + struct request_queue *blk_alloc_queue(int node_id); int disk_scan_partitions(struct gendisk *disk, fmode_t mode, void *owner); diff --git a/include/linux/bio.h b/include/linux/bio.h index 805957c99147..b2c09997d79c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -484,7 +484,8 @@ void zero_fill_bio(struct bio *bio); static inline void bio_release_pages(struct bio *bio, bool mark_dirty) { - if (bio_flagged(bio, BIO_PAGE_REFFED)) + if (bio_flagged(bio, BIO_PAGE_REFFED) || + bio_flagged(bio, BIO_PAGE_PINNED)) __bio_release_pages(bio, mark_dirty); } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 7daa261f4f98..a0e339ff3d09 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -318,6 +318,7 @@ struct bio { * bio flags */ enum { + BIO_PAGE_PINNED, /* Unpin pages in bio_release_pages() */ BIO_PAGE_REFFED, /* put pages in bio_release_pages() */ BIO_CLONED, /* doesn't own data */ BIO_BOUNCED, /* bio is a bounce bio */