Re: [RFC PATCH] namei: revalidate the symlink dentry before invoking get_link in RCU-walk

From: Jan Kara

Date: Mon Nov 23 2026 - 03:50:42 EST


On Mon 23-11-26 08:59:08, Dave Chinner wrote:
> On Fri, Nov 20, 2026 at 08:24:36AM -0800, Christoph Hellwig wrote:
> > On Fri, Nov 20, 2026 at 02:59:42PM +0100, Christian Brauner wrote:
> > > This only makes the window smaller.
> > >
> > > XFS can still reinitialize the inode right after this check and while
> > > get() is running. Then ->get_link() operates on an inode that is being
> > > reset underneath it. And the !get check only catches the case where the
> > > that re-init already finished before we loaded ->get_link.
> > >
> > > RCU pathwalk relies on inode memory not being reused before a grace
> > > period has passed. XFS itself frees inodes via call_rcu() but the
> > > recycle path hands the same struct inode out again without waiting for
> > > existing RCU walkers.
> > >
> > > So that should be fixed in XFS, either by not recycling an inode in
> > > place while RCU walkers can still see it or by keeping i_op and the link
> > > state valid across a recycle.
> >
> > Not recycling the inode really isn't an option, as that means there
> > would cause duplicate inodes in the xfs inode cache. Keeping i_op and
> > state in place sounds a bit more feasibly, but could be iffy as well.
> >
> > The best thing would be to find a way to keep the inode alive at the VFS
> > level when XFS marks it reclaimable. That would be a huge an invasive
> > change, but it would solve this and many other problems as well.
>
> I don't think that's feasible without a massive rework of the VFS
> inode life cycle management and/or the way XFS tracks inode metadata
> dirtiness for writeback purposes.
>
> Background:
>
> The xfs_iget_recycle() code exists because dirty XFS_IRECLAIMABLE
> inodes are tied into the journal machinery and need writeback before
> they can be reclaimed. This is all invisible to the VFS, and it is
> done via lockless lookups and atomic state checks without the need
> for reference counts within XFS itself.
>
> The issue is that reclaiming such an inode generally requires a log
> force to stabilise it in the journal before it can be written back,
> and the act of writing it back requires access to the inode state.
> Hence the journal requires the XFS inode to live in XFS_IRECLAIMABLE
> state until metadata writeback is complete, regardless of any other
> inode state changes.
>
> xfs_ireclaim() can expedite the writeback portion of reclaim (by
> running an inode flush) but it does not expedite the required
> journal flush if the inode is still dirty in memory. On lookup
> of an XFS_IRECLAIMABLE inode in RCU mode, we cannot directly reclaim
> a dirty XFS_IRECLAIMABLE inode because it requires blocking on both
> a log force and metadata writeback. That's why the inode is sitting
> in the XFS_IRECLAIMABLE limbo in the first place...
>
> That's where the xfs_iget_recycle() code stepped in - it
> reinitialises the VFS portion of the inode without affecting the
> internal journal state of the inode. This allows new modifications to
> be added to the inode and the attached log item without any
> discontinuities in journal state.
>
> The reason it does a full initialisation of the VFS inode is that
> the inode can change identity whilst in XFS_IRECLAIMABLE. i.e. it
> could be unlinked and then reallocated as a different inode (same
> number, different generation), and so the type can change (e.g. REG
> -> DIR) and hence a full VFS init is required to recycle it.
>
> And the reason that we've always done this recycle is for
> performance reasons - the inode allocation algorithms can prefer to
> allocate recently freed inodes (for locality reasons), and hence
> recently unlinked inodes in the IRECLAIMABLE state can be
> reallocated and need recycling because the final unlink state hasn't
> reached stable media before they are recycled.
>
> Doing things like forcing logs, instant reclaim, RCU
> synchronisation, etc have all had significant performance impacts
> due to the additional latency these operations add to common
> workload patterns. Hence the rarity of this recycle issue hasn't
> outweighed the cost of the "simple" fixes to everyday operation.

I'd just mention one possible solution which you didn't mention below (I
don't know how complex it would get for XFS but we effectively do this in
ext4) - make the VFS part of the inode and the journalled portion of the
inode separate entities in memory (independently allocated & freed). Then
you can free the VFS portion of the inode while still keeping the
journalled portion allocated. If the inode location on disk gets
reallocated, you allocate fresh VFS part and recycle the journalled part.
In ext4 we have this natural separation between the buffer carrying the
inode structure on disk which is part of the journalling process and the
inode itself so this separation is easy there. For XFS I presume this is
complex or you wouldn't bother with all the separate inode lifetime logic
but I just wanted to toss this idea out.

Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR