From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD31C38E5CA; Thu, 22 Jan 2026 21:27:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117223; cv=none; b=E1Gyo3nZHgpBLPe9fBb+8X2Vm9jUbk2TK2h2sj43DofF33RR3KLYoqqpSzaphlf6rfgqAKBQlM6RMBFrxWwmIRInthkTxuVOgdzyWHc4eQZA82YNqqXAgRpwMurJNG73rGEu7+OR1h4oZiCzk7PB/EZ9GXApK7mBxipaL0Wuyi0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769117223; c=relaxed/simple; bh=U10N7ULI9KAcvzTiDsxNFxtjl4EJCZqPOvlb4g1ZbUc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j9+Orau13yT8HQQ6s1RjeiA5ZNAeciDIe5DJ5bl+teZ11zSa7NlueKZQW8v8HMAhtFLtcH6xPScgWjLzWBzosFmVDXDmgaeepuArWVbGS7kDyRfPH+bW/a0j1LezF3XMQgwHyJQxtBqAPFN4nWElg+vVWUfYPgLGfwlxUNk7sY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OJPq9gkt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OJPq9gkt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CE21C19423; Thu, 22 Jan 2026 21:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769117221; bh=U10N7ULI9KAcvzTiDsxNFxtjl4EJCZqPOvlb4g1ZbUc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OJPq9gktVwk0sp4pr0hoATeQnthpgn9hLQIzJzJiyOCIZuuq72NaoYVe0Qh3fFELw UDA79/097W+MDYAWljX5K4kMsMbyLiXZ6zKD5WeXv42sohvNwPOcVDlHoCWY960VOF GUImQW0Sp1IVRwcpGVtZpOGhzaR7ldOijeiofs912DMIk4jeVieWzVqth0edJFSznb nTrcBZM4Vqj4kERQp3Th9UY7id7oVIwuUUBTYeKS8WdcRDowvxa+GWalm6PbDo2Diy oR3JOS01L1a7BiX7g8oTwxsxd+8zvqOb3ch72LS/IJ+67nhwE7rQbxkuXgPdl/KO8s YBwcrpMqB9/2A== Date: Thu, 22 Jan 2026 13:27:00 -0800 From: "Darrick J. Wong" To: Christoph Hellwig , t@magnolia.djwong.org Cc: Eric Biggers , Al Viro , Christian Brauner , Jan Kara , David Sterba , Theodore Ts'o , Jaegeuk Kim , Chao Yu , Andrey Albershteyn , "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, fsverity@lists.linux.dev Subject: Re: [PATCH 04/11] fsverity: start consolidating pagecache code Message-ID: <20260122212700.GD5910@frogsfrogsfrogs> References: <20260122082214.452153-1-hch@lst.de> <20260122082214.452153-5-hch@lst.de> Precedence: bulk X-Mailing-List: fsverity@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260122082214.452153-5-hch@lst.de> On Thu, Jan 22, 2026 at 09:22:00AM +0100, Christoph Hellwig wrote: > ext4 and f2fs are largely using the same code to read a page full > of Merkle tree blocks from the page cache, and the upcoming xfs > fsverity support would add another copy. > > Move the ext4 code to fs/verity/ and use it in f2fs as well. For f2fs > this removes the previous f2fs-specific error injection, but otherwise > the behavior remains unchanged. > > Signed-off-by: Christoph Hellwig > --- > fs/ext4/verity.c | 17 +---------------- > fs/f2fs/verity.c | 17 +---------------- > fs/verity/pagecache.c | 38 ++++++++++++++++++++++++++++++++++++++ > include/linux/fsverity.h | 3 +++ > 4 files changed, 43 insertions(+), 32 deletions(-) > create mode 100644 fs/verity/pagecache.c > > diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c > index 2ce4cf8a1e31..a071860ad36a 100644 > --- a/fs/ext4/verity.c > +++ b/fs/ext4/verity.c > @@ -361,23 +361,8 @@ static struct page *ext4_read_merkle_tree_page(struct inode *inode, > pgoff_t index, > unsigned long num_ra_pages) > { > - struct folio *folio; > - > index += ext4_verity_metadata_pos(inode) >> PAGE_SHIFT; > - > - folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); > - if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > - DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > - > - if (!IS_ERR(folio)) > - folio_put(folio); > - else if (num_ra_pages > 1) > - page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > - folio = read_mapping_folio(inode->i_mapping, index, NULL); > - if (IS_ERR(folio)) > - return ERR_CAST(folio); > - } > - return folio_file_page(folio, index); > + return generic_read_merkle_tree_page(inode, index, num_ra_pages); > } > > static int ext4_write_merkle_tree_block(struct file *file, const void *buf, > diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c > index c1c4d8044681..d37e584423af 100644 > --- a/fs/f2fs/verity.c > +++ b/fs/f2fs/verity.c > @@ -259,23 +259,8 @@ static struct page *f2fs_read_merkle_tree_page(struct inode *inode, > pgoff_t index, > unsigned long num_ra_pages) > { > - struct folio *folio; > - > index += f2fs_verity_metadata_pos(inode) >> PAGE_SHIFT; > - > - folio = f2fs_filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); > - if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > - DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > - > - if (!IS_ERR(folio)) > - folio_put(folio); > - else if (num_ra_pages > 1) > - page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > - folio = read_mapping_folio(inode->i_mapping, index, NULL); > - if (IS_ERR(folio)) > - return ERR_CAST(folio); > - } > - return folio_file_page(folio, index); > + return generic_read_merkle_tree_page(inode, index, num_ra_pages); > } > > static int f2fs_write_merkle_tree_block(struct file *file, const void *buf, > diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c > new file mode 100644 > index 000000000000..1efcdde20b73 > --- /dev/null > +++ b/fs/verity/pagecache.c > @@ -0,0 +1,38 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2019 Google LLC > + */ > + > +#include > +#include > + > +/** > + * generic_read_merkle_tree_page - generic ->read_merkle_tree_page helper > + * @inode: inode containing the Merkle tree > + * @index: 0-based index of the page in the inode > + * @num_ra_pages: The number of Merkle tree pages that should be prefetched. > + * > + * The caller needs to adjust @index from the Merkle-tree relative index passed > + * to ->read_merkle_tree_page to the actual index where the Merkle tree is > + * stored in the page cache for @inode. > + */ > +struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index, > + unsigned long num_ra_pages) > +{ > + struct folio *folio; > + > + folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); Nice hoist, though I wonder -- as an exported fs function, should we be checking that the returned folio doesn't cover EOF? Not that any of the users actually check that returned merkle tree folios fit that criterion. as a pure hoist this is ok so Reviewed-by: "Darrick J. Wong" --D > + if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > + DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > + > + if (!IS_ERR(folio)) > + folio_put(folio); > + else if (num_ra_pages > 1) > + page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > + folio = read_mapping_folio(inode->i_mapping, index, NULL); > + if (IS_ERR(folio)) > + return ERR_CAST(folio); > + } > + return folio_file_page(folio, index); > +} > +EXPORT_SYMBOL_GPL(generic_read_merkle_tree_page); > diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h > index e22cf84fe83a..121703625cc8 100644 > --- a/include/linux/fsverity.h > +++ b/include/linux/fsverity.h > @@ -309,4 +309,7 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp) > > void fsverity_cleanup_inode(struct inode *inode); > > +struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index, > + unsigned long num_ra_pages); > + > #endif /* _LINUX_FSVERITY_H */ > -- > 2.47.3 > > From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE247D6CFA4 for ; Thu, 22 Jan 2026 21:27:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version:References: Message-ID:To:Date:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uzosJSV/e/oEvgQ6ZwdfskAEwNxae/KK9g3nWJTAw2E=; b=K6VmPXdsCF30hoEOfFLQu7Ibo0 VDPj7NylLF2NUg3RX47nC6ItdnsItGBXej+6zWRK/ZuprluFTQ7RBLZ9x18xWNgsVjiuJU6myBoz5 V9RYavMztMaCH2oc4Gp0XP6W+mxjQhnwTp+u+b7qbZtyH9eF8MXSYpY5QIDTHTkUFDAY=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vj2Cu-0000IL-Kr; Thu, 22 Jan 2026 21:27:13 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vj2Cu-0000ID-AE for linux-f2fs-devel@lists.sourceforge.net; Thu, 22 Jan 2026 21:27:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9ys9C5h+WPUsArQCAQRISWZcS94d0E0oSPEgHwQ/PnQ=; b=MMCxqPhljVTWY5mfzpPk8s8UUV P28A0AyxOu7T0sWgVeDDlLXsGn2aVPwMP4WDyQnnos3+3w3iaqLkvxkFStlm6cLM2X9tldeqn1zqW W26zvq6TYYnk+UUBJRjE2AXS/Jpn5Pe4ChXdgy8d9WGYPTmI+D55GxLj2XLCc91Icy9U=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=9ys9C5h+WPUsArQCAQRISWZcS94d0E0oSPEgHwQ/PnQ=; b=PFKGjRRqOuwvArYqU0LEwlxLDr OlREsKz6D1giYkDWvhHKIcTn0vT/4Ql21hXMklWs9mMhrsOeJy2NpAxCV3F6H0l9WGG6PEi9wqSqH K+C6s0HLrU4Ck6+how+XeSigy1hBFup2O0LmI6MA0Q+wfr2EKXbPUqq/179lStNhH26w=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1vj2Cu-0004pP-FL for linux-f2fs-devel@lists.sourceforge.net; Thu, 22 Jan 2026 21:27:13 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id D8DE26014A; Thu, 22 Jan 2026 21:27:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CE21C19423; Thu, 22 Jan 2026 21:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769117221; bh=U10N7ULI9KAcvzTiDsxNFxtjl4EJCZqPOvlb4g1ZbUc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OJPq9gktVwk0sp4pr0hoATeQnthpgn9hLQIzJzJiyOCIZuuq72NaoYVe0Qh3fFELw UDA79/097W+MDYAWljX5K4kMsMbyLiXZ6zKD5WeXv42sohvNwPOcVDlHoCWY960VOF GUImQW0Sp1IVRwcpGVtZpOGhzaR7ldOijeiofs912DMIk4jeVieWzVqth0edJFSznb nTrcBZM4Vqj4kERQp3Th9UY7id7oVIwuUUBTYeKS8WdcRDowvxa+GWalm6PbDo2Diy oR3JOS01L1a7BiX7g8oTwxsxd+8zvqOb3ch72LS/IJ+67nhwE7rQbxkuXgPdl/KO8s YBwcrpMqB9/2A== Date: Thu, 22 Jan 2026 13:27:00 -0800 To: Christoph Hellwig , t@magnolia.djwong.org Message-ID: <20260122212700.GD5910@frogsfrogsfrogs> References: <20260122082214.452153-1-hch@lst.de> <20260122082214.452153-5-hch@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20260122082214.452153-5-hch@lst.de> X-Headers-End: 1vj2Cu-0004pP-FL Subject: Re: [f2fs-dev] [PATCH 04/11] fsverity: start consolidating pagecache code X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "Darrick J. Wong via Linux-f2fs-devel" Reply-To: "Darrick J. Wong" Cc: fsverity@lists.linux.dev, Christian Brauner , Jan Kara , Andrey Albershteyn , "Matthew Wilcox \(Oracle\)" , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fsdevel@vger.kernel.org, Al Viro , Jaegeuk Kim , David Sterba , Theodore Ts'o , linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Thu, Jan 22, 2026 at 09:22:00AM +0100, Christoph Hellwig wrote: > ext4 and f2fs are largely using the same code to read a page full > of Merkle tree blocks from the page cache, and the upcoming xfs > fsverity support would add another copy. > > Move the ext4 code to fs/verity/ and use it in f2fs as well. For f2fs > this removes the previous f2fs-specific error injection, but otherwise > the behavior remains unchanged. > > Signed-off-by: Christoph Hellwig > --- > fs/ext4/verity.c | 17 +---------------- > fs/f2fs/verity.c | 17 +---------------- > fs/verity/pagecache.c | 38 ++++++++++++++++++++++++++++++++++++++ > include/linux/fsverity.h | 3 +++ > 4 files changed, 43 insertions(+), 32 deletions(-) > create mode 100644 fs/verity/pagecache.c > > diff --git a/fs/ext4/verity.c b/fs/ext4/verity.c > index 2ce4cf8a1e31..a071860ad36a 100644 > --- a/fs/ext4/verity.c > +++ b/fs/ext4/verity.c > @@ -361,23 +361,8 @@ static struct page *ext4_read_merkle_tree_page(struct inode *inode, > pgoff_t index, > unsigned long num_ra_pages) > { > - struct folio *folio; > - > index += ext4_verity_metadata_pos(inode) >> PAGE_SHIFT; > - > - folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); > - if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > - DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > - > - if (!IS_ERR(folio)) > - folio_put(folio); > - else if (num_ra_pages > 1) > - page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > - folio = read_mapping_folio(inode->i_mapping, index, NULL); > - if (IS_ERR(folio)) > - return ERR_CAST(folio); > - } > - return folio_file_page(folio, index); > + return generic_read_merkle_tree_page(inode, index, num_ra_pages); > } > > static int ext4_write_merkle_tree_block(struct file *file, const void *buf, > diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c > index c1c4d8044681..d37e584423af 100644 > --- a/fs/f2fs/verity.c > +++ b/fs/f2fs/verity.c > @@ -259,23 +259,8 @@ static struct page *f2fs_read_merkle_tree_page(struct inode *inode, > pgoff_t index, > unsigned long num_ra_pages) > { > - struct folio *folio; > - > index += f2fs_verity_metadata_pos(inode) >> PAGE_SHIFT; > - > - folio = f2fs_filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); > - if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > - DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > - > - if (!IS_ERR(folio)) > - folio_put(folio); > - else if (num_ra_pages > 1) > - page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > - folio = read_mapping_folio(inode->i_mapping, index, NULL); > - if (IS_ERR(folio)) > - return ERR_CAST(folio); > - } > - return folio_file_page(folio, index); > + return generic_read_merkle_tree_page(inode, index, num_ra_pages); > } > > static int f2fs_write_merkle_tree_block(struct file *file, const void *buf, > diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c > new file mode 100644 > index 000000000000..1efcdde20b73 > --- /dev/null > +++ b/fs/verity/pagecache.c > @@ -0,0 +1,38 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright 2019 Google LLC > + */ > + > +#include > +#include > + > +/** > + * generic_read_merkle_tree_page - generic ->read_merkle_tree_page helper > + * @inode: inode containing the Merkle tree > + * @index: 0-based index of the page in the inode > + * @num_ra_pages: The number of Merkle tree pages that should be prefetched. > + * > + * The caller needs to adjust @index from the Merkle-tree relative index passed > + * to ->read_merkle_tree_page to the actual index where the Merkle tree is > + * stored in the page cache for @inode. > + */ > +struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index, > + unsigned long num_ra_pages) > +{ > + struct folio *folio; > + > + folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); Nice hoist, though I wonder -- as an exported fs function, should we be checking that the returned folio doesn't cover EOF? Not that any of the users actually check that returned merkle tree folios fit that criterion. as a pure hoist this is ok so Reviewed-by: "Darrick J. Wong" --D > + if (IS_ERR(folio) || !folio_test_uptodate(folio)) { > + DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index); > + > + if (!IS_ERR(folio)) > + folio_put(folio); > + else if (num_ra_pages > 1) > + page_cache_ra_unbounded(&ractl, num_ra_pages, 0); > + folio = read_mapping_folio(inode->i_mapping, index, NULL); > + if (IS_ERR(folio)) > + return ERR_CAST(folio); > + } > + return folio_file_page(folio, index); > +} > +EXPORT_SYMBOL_GPL(generic_read_merkle_tree_page); > diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h > index e22cf84fe83a..121703625cc8 100644 > --- a/include/linux/fsverity.h > +++ b/include/linux/fsverity.h > @@ -309,4 +309,7 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp) > > void fsverity_cleanup_inode(struct inode *inode); > > +struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index, > + unsigned long num_ra_pages); > + > #endif /* _LINUX_FSVERITY_H */ > -- > 2.47.3 > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel