Re: vnode locks vs write backs in the NFS client

From: Konstantin Belousov <kib_at_freebsd.org>
Date: Sun, 29 Nov 2026 22:26:39 UTC
On Sun, Nov 29, 2026 at 03:20:35PM -0700, Rick Macklem wrote:
> On Sun, Nov 29, 2026 at 10:28 AM Konstantin Belousov <kib@freebsd.org> wrote:
> >
> > On Sun, Nov 29, 2026 at 09:57:57AM -0700, Rick Macklem wrote:
> > > Hi,
> > >
> > > During testing of the RDMA code being done by the NVidia folk,
> > > they got a panic caused by VOP_STRATEGY() being called with
> > > an unlocked vnode.
> > >
> > > They had delegations enabled (and were accessing the same
> > > file from multiple mounts) along with WITNESS and INVARIANTS.
> > >
> > > The panic is not surprising, since the nfscl thread tries to do
> > > write backs without the vnode lock. This is not so much a bug
> > > as a faeture, since the NFS client has done write backs with
> > > the buffer lock held, but no vnode lock, since the code was
> > > written decades ago. (Note that LK_EXCLOTHER is a NFS
> > > related "hack", but vop_asser_locked() does not consider
> > > that case as locked.)
> > >
> > > I'm guessing people haven't been reporting this for..
> > > - Running production kernels without DEBUG_VFS_LOCKS,
> > >   INVARIANTS, WITNESS.
> > > - Not enabling delegations (for this case).
> > >
> > > I do believe that the current code is safe, in the sense that
> > > the buffer lock is sufficient to maintain consistency during
> > > write backs to the NFS server. (A "umount -N" handles this
> > > stuff ok. Not sure about "umount -f", but "umount -f' is mostly
> > > useless for the NFS client, anyhow.)
> > >
> > > So, what can we do??
> > >
> > > I think the best approach might be to convert the NFS client to
> > > using shared vnode locks for writing (like ZFS currently
> > > does).  That way, the NFS client can acquire the shared
> > > vnode lock for write-backs when other threads have the
> > > vnode shared locked for writing.
> > > --> However, this could take a while to implement.
> > >
> > > In the meantime, I think we just accept that debug kernels
> > > won't work correctly, at least when delegations are enabled.
> > >
> > > Other ideas?
> >
> > Or add VOP_STRATEGY_UNLOCKED(), changing all implementations in fses to
> > provide VOP_STRATEGY_UNLOCKED().  VOP_STRATEGY() would simply redirect
> > to VOP_STRATEGY_UNLOCKED().
> >
> This seems simple enough, but maybe a bit of an overkill to have both
> VOP_STRATEGY()
> and VOP_STRATEGY_UNLOCKED().
> 
> You guys probably won't like this hokey variant, but what about just dropping
> the requirement for a locked vnode from VOP_STRATEGY() and then
> adding an ASSERT_VOP_LOCKED() to the vop_strategy() for file systems
> that need to have it locked.

Indeed, I prefer to keep VOP_STRATEGY() locked with assert.