[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260126205301.GD30838@quark>
Date: Mon, 26 Jan 2026 12:53:01 -0800
From: Eric Biggers <ebiggers@...nel.org>
To: "Darrick J. Wong" <djwong@...nel.org>
Cc: Christoph Hellwig <hch@....de>, Al Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
David Sterba <dsterba@...e.com>, Theodore Ts'o <tytso@....edu>,
Jaegeuk Kim <jaegeuk@...nel.org>, Chao Yu <chao@...nel.org>,
Andrey Albershteyn <aalbersh@...hat.com>,
Matthew Wilcox <willy@...radead.org>, linux-fsdevel@...r.kernel.org,
linux-btrfs@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-f2fs-devel@...ts.sourceforge.net, fsverity@...ts.linux.dev
Subject: Re: [PATCH 07/16] fsverity: don't issue readahead for non-ENOENT
errors from __filemap_get_folio
On Mon, Jan 26, 2026 at 11:11:02AM -0800, Darrick J. Wong wrote:
> On Mon, Jan 26, 2026 at 05:50:53AM +0100, Christoph Hellwig wrote:
> > Issuing more reads on errors is not a good idea, especially when the
> > most common error here is -ENOMEM.
> >
> > Signed-off-by: Christoph Hellwig <hch@....de>
> > ---
> > fs/verity/pagecache.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/verity/pagecache.c b/fs/verity/pagecache.c
> > index 1efcdde20b73..63393f0f5834 100644
> > --- a/fs/verity/pagecache.c
> > +++ b/fs/verity/pagecache.c
> > @@ -22,7 +22,8 @@ struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index,
> > struct folio *folio;
> >
> > folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0);
> > - if (IS_ERR(folio) || !folio_test_uptodate(folio)) {
> > + if (PTR_ERR(folio) == -ENOENT ||
> > + !(IS_ERR(folio) && !folio_test_uptodate(folio))) {
>
> I don't understand this logic at all. If @folio is actually an
> ERR_PTR, then we dereference the non-folio to see if it's not uptodate?
>
> I think (given the previous revisions) that what you want is to initiate
> readahead if either there's no folio at all (ENOENT) or if there is a
> folio but it's not uptodate? But not if there's some other error
> (ENOMEM, EL3HLT, EFSCORRUPTED, etc)?
>
> So maybe you want:
>
> folio = __filemap_get_folio(...);
> if (!IS_ERR(folio)) {
> if (folio_test_uptodate(folio))
> return folio_file_page(folio);
> folio_put(folio);
> } else if (PTR_ERR(folio) == -ENOENT) {
> return ERR_CAST(folio);
> }
>
> 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);
>
> <confused>
That version is wrong too: the condition 'PTR_ERR(folio) == -ENOENT' is
backwards.
This code gets replaced later in the series anyway. For this patch, we
could simply insert two lines:
folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0);
+ if (IS_ERR(folio) && folio != ERR_PTR(-ENOENT))
+ return folio;
Then for the final version in generic_readahead_merkle_tree(), one
option would be:
struct folio *folio;
folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0);
if (folio == ERR_PTR(-ENOENT) ||
(!IS_ERR(folio) && !folio_test_uptodate(folio))) {
DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index);
page_cache_ra_unbounded(&ractl, nr_pages, 0);
}
if (!IS_ERR(folio))
folio_put(folio);
Or as a diff from this series:
- if (PTR_ERR(folio) == -ENOENT ||
- !(IS_ERR(folio) && !folio_test_uptodate(folio))) {
+ if (folio == ERR_PTR(-ENOENT) ||
+ (!IS_ERR(folio) && !folio_test_uptodate(folio))) {
(Note that PTR_ERR() shouldn't be used before it's known that the
pointer is an error pointer.)
- Eric
Powered by blists - more mailing lists