linux/fs/nfsd
Linus Torvalds 7cd122b552 Some filesystems use a kinda-sorta controlled dentry refcount leak to pin
dentries of created objects in dcache (and undo it when removing those).
 Reference is grabbed and not released, but it's not actually _stored_
 anywhere.  That works, but it's hard to follow and verify; among other
 things, we have no way to tell _which_ of the increments is intended
 to be an unpaired one.  Worse, on removal we need to decide whether
 the reference had already been dropped, which can be non-trivial if
 that removal is on umount and we need to figure out if this dentry is
 pinned due to e.g. unlink() not done.  Usually that is handled by using
 kill_litter_super() as ->kill_sb(), but there are open-coded special
 cases of the same (consider e.g. /proc/self).
 
 Things get simpler if we introduce a new dentry flag (DCACHE_PERSISTENT)
 marking those "leaked" dentries.  Having it set claims responsibility
 for +1 in refcount.
 
 The end result this series is aiming for:
 
 * get these unbalanced dget() and dput() replaced with new primitives that
   would, in addition to adjusting refcount, set and clear persistency flag.
 * instead of having kill_litter_super() mess with removing the remaining
   "leaked" references (e.g. for all tmpfs files that hadn't been removed
   prior to umount), have the regular shrink_dcache_for_umount() strip
   DCACHE_PERSISTENT of all dentries, dropping the corresponding
   reference if it had been set.  After that kill_litter_super() becomes
   an equivalent of kill_anon_super().
 
 Doing that in a single step is not feasible - it would affect too many places
 in too many filesystems.  It has to be split into a series.
 
 This work has really started early in 2024; quite a few preliminary pieces
 have already gone into mainline.  This chunk is finally getting to the
 meat of that stuff - infrastructure and most of the conversions to it.
 
 Some pieces are still sitting in the local branches, but the bulk of
 that stuff is here.
 
 Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQqUNBr3gm4hGXdBJlZ7Krx/gZQ6wUCaTEq1wAKCRBZ7Krx/gZQ
 643uAQC1rRslhw5l7OjxEpIYbGG4M+QaadN4Nf5Sr2SuTRaPJQD/W4oj/u4C2eCw
 Dd3q071tqyvm/PXNgN2EEnIaxlFUlwc=
 =rKq+
 -----END PGP SIGNATURE-----

Merge tag 'pull-persistency' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull persistent dentry infrastructure and conversion from Al Viro:
 "Some filesystems use a kinda-sorta controlled dentry refcount leak to
  pin dentries of created objects in dcache (and undo it when removing
  those). A reference is grabbed and not released, but it's not actually
  _stored_ anywhere.

  That works, but it's hard to follow and verify; among other things, we
  have no way to tell _which_ of the increments is intended to be an
  unpaired one. Worse, on removal we need to decide whether the
  reference had already been dropped, which can be non-trivial if that
  removal is on umount and we need to figure out if this dentry is
  pinned due to e.g. unlink() not done. Usually that is handled by using
  kill_litter_super() as ->kill_sb(), but there are open-coded special
  cases of the same (consider e.g. /proc/self).

  Things get simpler if we introduce a new dentry flag
  (DCACHE_PERSISTENT) marking those "leaked" dentries. Having it set
  claims responsibility for +1 in refcount.

  The end result this series is aiming for:

   - get these unbalanced dget() and dput() replaced with new primitives
     that would, in addition to adjusting refcount, set and clear
     persistency flag.

   - instead of having kill_litter_super() mess with removing the
     remaining "leaked" references (e.g. for all tmpfs files that hadn't
     been removed prior to umount), have the regular
     shrink_dcache_for_umount() strip DCACHE_PERSISTENT of all dentries,
     dropping the corresponding reference if it had been set. After that
     kill_litter_super() becomes an equivalent of kill_anon_super().

  Doing that in a single step is not feasible - it would affect too many
  places in too many filesystems. It has to be split into a series.

  This work has really started early in 2024; quite a few preliminary
  pieces have already gone into mainline. This chunk is finally getting
  to the meat of that stuff - infrastructure and most of the conversions
  to it.

  Some pieces are still sitting in the local branches, but the bulk of
  that stuff is here"

* tag 'pull-persistency' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (54 commits)
  d_make_discardable(): warn if given a non-persistent dentry
  kill securityfs_recursive_remove()
  convert securityfs
  get rid of kill_litter_super()
  convert rust_binderfs
  convert nfsctl
  convert rpc_pipefs
  convert hypfs
  hypfs: swich hypfs_create_u64() to returning int
  hypfs: switch hypfs_create_str() to returning int
  hypfs: don't pin dentries twice
  convert gadgetfs
  gadgetfs: switch to simple_remove_by_name()
  convert functionfs
  functionfs: switch to simple_remove_by_name()
  functionfs: fix the open/removal races
  functionfs: need to cancel ->reset_work in ->kill_sb()
  functionfs: don't bother with ffs->ref in ffs_data_{opened,closed}()
  functionfs: don't abuse ffs_data_closed() on fs shutdown
  convert selinuxfs
  ...
2025-12-05 14:36:21 -08:00
..
Kconfig nfsd: Don't force CRYPTO_LIB_SHA256 to be built-in 2025-09-21 19:24:50 -04:00
Makefile NFSD: Add /sys/kernel/debug/nfsd 2025-05-11 19:48:23 -04:00
acl.h
auth.c nfsd: avoid pointless cred reference count bump 2024-12-02 11:25:14 +01:00
auth.h nfsd: Pass 'cred' instead of 'rqstp' to some functions. 2024-09-20 19:31:03 -04:00
blocklayout.c NFSD: Do the grace period check in ->proc_layoutget 2025-10-01 15:54:01 -04:00
blocklayoutxdr.c NFSD: Implement large extent array support in pNFS 2025-09-21 19:24:50 -04:00
blocklayoutxdr.h NFSD: Implement large extent array support in pNFS 2025-09-21 19:24:50 -04:00
cache.h nfsd: don't allocate the versions array. 2024-09-20 19:29:23 -04:00
current_stateid.h
debugfs.c NFSD: Add io_cache_{read,write} controls to debugfs 2025-10-01 15:54:01 -04:00
export.c NFSD 6.18 Release Notes 2025-10-06 13:22:21 -07:00
export.h NFSD 6.18 Release Notes 2025-10-06 13:22:21 -07:00
filecache.c nfsd: allow filecache to hold S_IFDIR files 2025-11-12 09:38:36 +01:00
filecache.h nfsd: allow filecache to hold S_IFDIR files 2025-11-12 09:38:36 +01:00
flexfilelayout.c NFSD: Define a proc_layoutcommit for the FlexFiles layout type 2025-10-10 12:53:50 -04:00
flexfilelayoutxdr.c NFSD: Rework encoding and decoding of nfsd4_deviceid 2025-09-21 19:24:50 -04:00
flexfilelayoutxdr.h
idmap.h
localio.c NFSD 6.18 Release Notes 2025-10-06 13:22:21 -07:00
lockd.c nfsd: discard nfserr_dropit 2025-10-01 15:54:01 -04:00
netlink.c tools: ynl-gen: add regeneration comment 2025-11-25 19:20:42 -08:00
netlink.h tools: ynl-gen: add regeneration comment 2025-11-25 19:20:42 -08:00
netns.h NFS Client Updates for Linux 6.14 2025-01-28 14:23:46 -08:00
nfs2acl.c nfsd: clear acl_access/acl_default after releasing them 2025-02-02 11:31:45 -05:00
nfs3acl.c nfsd: clear acl_access/acl_default after releasing them 2025-02-02 11:31:45 -05:00
nfs3proc.c vfs-6.19-rc1.directory.locking 2025-12-01 16:13:46 -08:00
nfs3xdr.c nfsd: Use lookup_one() rather than lookup_one_len() 2025-04-07 09:25:32 +02:00
nfs4acl.c NFSD: Remove unnecessary posix_acl_entry pointer initialization 2024-11-11 13:41:58 -05:00
nfs4callback.c NFSD: Avoid corruption of a referring call list 2025-06-12 20:37:32 -04:00
nfs4idmap.c nfsd: call cache_put if xdr_reserve_space returns NULL 2024-09-20 19:31:03 -04:00
nfs4layouts.c NFSD: Rework encoding and decoding of nfsd4_deviceid 2025-09-21 19:24:50 -04:00
nfs4proc.c vfs-6.19-rc1.directory.locking 2025-12-01 16:13:46 -08:00
nfs4recover.c vfs-6.19-rc1.directory.locking 2025-12-01 16:13:46 -08:00
nfs4state.c vfs-6.19-rc1.directory.delegations 2025-12-01 15:34:41 -08:00
nfs4xdr.c nfsd: ensure SEQUENCE replay sends a valid reply. 2025-11-10 09:31:52 -05:00
nfs4xdr_gen.c nfsd: rename NFS4_SHARE_WANT_* constants to OPEN4_SHARE_ACCESS_WANT_* 2025-01-21 15:30:01 -05:00
nfs4xdr_gen.h nfsd: rename NFS4_SHARE_WANT_* constants to OPEN4_SHARE_ACCESS_WANT_* 2025-01-21 15:30:01 -05:00
nfscache.c NFSD: Reduce DRC bucket size 2025-09-21 19:24:50 -04:00
nfsctl.c convert nfsctl 2025-11-17 23:59:27 -05:00
nfsd.h nfsd: add missing FATTR4_WORD2_CLONE_BLKSIZE from supported attributes 2025-11-04 11:02:31 -05:00
nfsfh.c nfsd-6.18 fixes: 2025-11-12 18:41:01 -08:00
nfsfh.h NFSD: Move the fh_getattr() helper 2025-09-21 19:24:50 -04:00
nfsproc.c nfsd: fix end_creating() conversion 2025-11-28 09:51:16 +01:00
nfssvc.c SUNRPC: Move the svc_rpcb_cleanup() call sites 2025-09-23 13:28:19 -04:00
nfsxdr.c NFSD: Remove NFSSVC_MAXBLKSIZE_V2 macro 2025-05-15 16:16:28 -04:00
pnfs.h NFSD: Do the grace period check in ->proc_layoutget 2025-10-01 15:54:01 -04:00
state.h nfsd: wire up GET_DIR_DELEGATION handling 2025-11-12 09:38:37 +01:00
stats.c nfsd: don't ignore the return code of svc_proc_register() 2025-03-10 09:10:59 -04:00
stats.h nfsd: don't ignore the return code of svc_proc_register() 2025-03-10 09:10:59 -04:00
trace.c
trace.h NFSD: filecache: add STATX_DIOALIGN and STATX_DIO_READ_ALIGN support 2025-09-30 16:10:05 -04:00
vfs.c vfs-6.19-rc1.directory.locking 2025-12-01 16:13:46 -08:00
vfs.h nfsd: allow filecache to hold S_IFDIR files 2025-11-12 09:38:36 +01:00
xdr.h
xdr3.h nfsd: Fix NFSv3 atomicity bugs in nfsd_setattr() 2024-03-01 09:12:33 -05:00
xdr4.h nfsd: ensure SEQUENCE replay sends a valid reply. 2025-11-10 09:31:52 -05:00
xdr4cb.h NFSD: Implement CB_SEQUENCE referring call lists 2025-05-11 19:48:20 -04:00