From: Matthew Wilcox <willy@infradead.org>
To: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Cc: "brauner@kernel.org" <brauner@kernel.org>,
"ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"dan.carpenter@linaro.org" <dan.carpenter@linaro.org>
Subject: Re: [PATCH] ceph: Fix error handling in fill_readdir_cache()
Date: Wed, 5 Mar 2025 04:29:44 +0000 [thread overview]
Message-ID: <Z8fTOEerurzqKybx@casper.infradead.org> (raw)
In-Reply-To: <7f2e7a8938775916fd926f9e7ff073d42f89108b.camel@ibm.com>
On Tue, Mar 04, 2025 at 06:41:46PM +0000, Viacheslav Dubeyko wrote:
> On Tue, 2025-03-04 at 15:48 +0000, Matthew Wilcox (Oracle) wrote:
> > __filemap_get_folio() returns an ERR_PTR, not NULL. There are extensive
> > assumptions that ctl->folio is NULL, not an error pointer, so it seems
> > better to fix this one place rather than change all the places which
> > check ctl->folio.
> >
> > Fixes: baff9740bc8f ("ceph: Convert ceph_readdir_cache_control to store a folio")
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > Cc: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
> > ---
> > fs/ceph/inode.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
> > index c15970fa240f..6ac2bd555e86 100644
> > --- a/fs/ceph/inode.c
> > +++ b/fs/ceph/inode.c
> > @@ -1870,9 +1870,12 @@ static int fill_readdir_cache(struct inode *dir, struct dentry *dn,
> >
> > ctl->folio = __filemap_get_folio(&dir->i_data, pgoff,
> > fgf, mapping_gfp_mask(&dir->i_data));
>
> Could we expect to receive NULL here somehow? I assume we should receive valid
> pointer or ERR_PTR always here.
There's no way to get a NULL pointer here. __filemap_get_folio() always
returns a valid folio or an ERR_PTR.
> > - if (!ctl->folio) {
> > + if (IS_ERR(ctl->folio)) {
> > + int err = PTR_ERR(ctl->folio);
> > +
> > + ctl->folio = NULL;
> > ctl->index = -1;
> > - return idx == 0 ? -ENOMEM : 0;
> > + return idx == 0 ? err : 0;
> > }
> > /* reading/filling the cache are serialized by
> > * i_rwsem, no need to use folio lock */
>
> But I prefer to check on NULL anyway, because we try to unlock the folio here:
>
> /* reading/filling the cache are serialized by
> * i_rwsem, no need to use folio lock */
> folio_unlock(ctl->folio);
>
> And absence of check on NULL makes me slightly nervous. :)
We'd get a very visible and obvious splat if we did! But we make this
assumption all over the VFS and in other filesystems. There's no need
to be more cautious in ceph than in other places.
next prev parent reply other threads:[~2025-03-05 4:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 15:48 [PATCH] ceph: Fix error handling in fill_readdir_cache() Matthew Wilcox (Oracle)
2025-03-04 18:41 ` Viacheslav Dubeyko
2025-03-05 4:29 ` Matthew Wilcox [this message]
2025-03-05 8:18 ` Dan Carpenter
2025-03-05 10:48 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z8fTOEerurzqKybx@casper.infradead.org \
--to=willy@infradead.org \
--cc=Slava.Dubeyko@ibm.com \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.