kernel_samsung_a53x/fs/nfsd
Yang Erkun d4913fa414 nfsd: cancel nfsd_shrinker_work using sync mode in nfs4_state_shutdown_net
commit d5ff2fb2e7167e9483846e34148e60c0c016a1f6 upstream.

In the normal case, when we excute `echo 0 > /proc/fs/nfsd/threads`, the
function `nfs4_state_destroy_net` in `nfs4_state_shutdown_net` will
release all resources related to the hashed `nfs4_client`. If the
`nfsd_client_shrinker` is running concurrently, the `expire_client`
function will first unhash this client and then destroy it. This can
lead to the following warning. Additionally, numerous use-after-free
errors may occur as well.

nfsd_client_shrinker         echo 0 > /proc/fs/nfsd/threads

expire_client                nfsd_shutdown_net
  unhash_client                ...
                               nfs4_state_shutdown_net
                                 /* won't wait shrinker exit */
  /*                             cancel_work(&nn->nfsd_shrinker_work)
   * nfsd_file for this          /* won't destroy unhashed client1 */
   * client1 still alive         nfs4_state_destroy_net
   */

                               nfsd_file_cache_shutdown
                                 /* trigger warning */
                                 kmem_cache_destroy(nfsd_file_slab)
                                 kmem_cache_destroy(nfsd_file_mark_slab)
  /* release nfsd_file and mark */
  __destroy_client

====================================================================
BUG nfsd_file (Not tainted): Objects remaining in nfsd_file on
__kmem_cache_shutdown()
--------------------------------------------------------------------
CPU: 4 UID: 0 PID: 764 Comm: sh Not tainted 6.12.0-rc3+ #1

 dump_stack_lvl+0x53/0x70
 slab_err+0xb0/0xf0
 __kmem_cache_shutdown+0x15c/0x310
 kmem_cache_destroy+0x66/0x160
 nfsd_file_cache_shutdown+0xac/0x210 [nfsd]
 nfsd_destroy_serv+0x251/0x2a0 [nfsd]
 nfsd_svc+0x125/0x1e0 [nfsd]
 write_threads+0x16a/0x2a0 [nfsd]
 nfsctl_transaction_write+0x74/0xa0 [nfsd]
 vfs_write+0x1a5/0x6d0
 ksys_write+0xc1/0x160
 do_syscall_64+0x5f/0x170
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

====================================================================
BUG nfsd_file_mark (Tainted: G    B   W         ): Objects remaining
nfsd_file_mark on __kmem_cache_shutdown()
--------------------------------------------------------------------

 dump_stack_lvl+0x53/0x70
 slab_err+0xb0/0xf0
 __kmem_cache_shutdown+0x15c/0x310
 kmem_cache_destroy+0x66/0x160
 nfsd_file_cache_shutdown+0xc8/0x210 [nfsd]
 nfsd_destroy_serv+0x251/0x2a0 [nfsd]
 nfsd_svc+0x125/0x1e0 [nfsd]
 write_threads+0x16a/0x2a0 [nfsd]
 nfsctl_transaction_write+0x74/0xa0 [nfsd]
 vfs_write+0x1a5/0x6d0
 ksys_write+0xc1/0x160
 do_syscall_64+0x5f/0x170
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

To resolve this issue, cancel `nfsd_shrinker_work` using synchronous
mode in nfs4_state_shutdown_net.

Fixes: 7c24fa225081 ("NFSD: replace delayed_work with work_struct for nfsd_client_shrinker")
Signed-off-by: Yang Erkun <yangerkun@huaweicloud.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-01-15 16:29:52 +01:00
..
acl.h NFSD: add posix ACLs to struct nfsd_attrs 2024-11-19 12:28:04 +01:00
auth.c
auth.h
blocklayout.c nfsd: move nfserrno() to vfs.c 2024-11-19 12:28:26 +01:00
blocklayoutxdr.c nfsd: move nfserrno() to vfs.c 2024-11-19 12:28:26 +01:00
blocklayoutxdr.h
cache.h Revert "nfsd: make all of the nfsd stats per-network namespace" 2024-11-24 00:23:43 +01:00
current_stateid.h
export.c nfsd: make sure exp active before svc_export_show 2024-12-17 13:24:24 +01:00
export.h Revert "NFSD: Fix frame size warning in svc_export_parse()" 2024-11-24 00:23:45 +01:00
fault_inject.c
filecache.c Revert "nfsd: remove unneeded EEXIST error check in nfsd_do_file_acquire" 2024-11-24 00:23:21 +01:00
filecache.h NFSD: Convert filecache to rhltable 2024-11-19 12:28:32 +01:00
flexfilelayout.c nfsd: move nfserrno() to vfs.c 2024-11-19 12:28:26 +01:00
flexfilelayoutxdr.c
flexfilelayoutxdr.h
idmap.h
Kconfig nfsd: allow disabling NFSv2 at compile time 2024-11-19 12:28:26 +01:00
lockd.c Keep read and write fds with each nlm_file 2024-11-19 12:27:44 +01:00
Makefile nfsd: allow disabling NFSv2 at compile time 2024-11-19 12:28:26 +01:00
netns.h NFSD: Limit the number of concurrent async COPY operations 2024-12-17 13:20:51 +01:00
nfs2acl.c NFSD: Finish converting the NFSv2 GETACL result encoder 2024-11-19 12:28:26 +01:00
nfs3acl.c NFSD: Finish converting the NFSv3 GETACL result encoder 2024-11-19 12:28:26 +01:00
nfs3proc.c NFSD: Add an NFSD_FILE_GC flag to enable nfsd_file garbage collection 2024-11-19 12:28:26 +01:00
nfs3xdr.c NFSD: Clean up WRITE arg decoders 2024-11-19 12:28:23 +01:00
nfs4acl.c NFSD: add posix ACLs to struct nfsd_attrs 2024-11-19 12:28:04 +01:00
nfs4callback.c nfsd: restore callback functionality for NFSv4.0 2025-01-15 16:29:49 +01:00
nfs4idmap.c Revert "nfsd: call cache_put if xdr_reserve_space returns NULL" 2024-11-24 00:23:20 +01:00
nfs4layouts.c NFSD: Add tracepoints to report NFSv4 callback completions 2024-11-19 12:28:22 +01:00
nfs4proc.c NFSD: Fix nfsd4_shutdown_copy() 2024-12-17 13:24:13 +01:00
nfs4recover.c NFSD: Cap the number of bytes copied by nfs4_reset_recoverydir() 2024-12-17 13:24:13 +01:00
nfs4state.c nfsd: cancel nfsd_shrinker_work using sync mode in nfs4_state_shutdown_net 2025-01-15 16:29:52 +01:00
nfs4xdr.c Revert "NFSD: Fix NFSv4's PUTPUBFH operation" 2024-11-24 00:23:02 +01:00
nfscache.c Revert "NFSD: Refactor nfsd_reply_cache_free_locked()" 2024-11-24 00:23:45 +01:00
nfsctl.c Revert "nfsd: expose /proc/net/sunrpc/nfsd in net namespaces" 2024-11-24 00:23:44 +01:00
nfsd.h Revert "nfsd: remove nfsd_stats, make th_cnt a global counter" 2024-11-24 00:23:43 +01:00
nfsfh.c Revert "nfsd: make all of the nfsd stats per-network namespace" 2024-11-24 00:23:43 +01:00
nfsfh.h NFSD: Use const pointers as parameters to fh_ helpers 2024-11-19 12:28:27 +01:00
nfsproc.c NFSD: Use set_bit(RQ_DROPME) 2024-11-19 12:28:29 +01:00
nfssvc.c Revert "NFSD: simplify error paths in nfsd_svc()" 2024-11-24 00:23:45 +01:00
nfsxdr.c NFSD: Clean up WRITE arg decoders 2024-11-19 12:28:23 +01:00
pnfs.h
state.h NFSD: add delegation reaper to react to low memory condition 2024-11-19 12:28:29 +01:00
stats.c Revert "NFSD: Rewrite synopsis of nfsd_percpu_counters_init()" 2024-11-24 00:23:45 +01:00
stats.h Revert "NFSD: Rewrite synopsis of nfsd_percpu_counters_init()" 2024-11-24 00:23:45 +01:00
trace.c NFSD: Add SPDX header for fs/nfsd/trace.c 2024-11-19 12:27:20 +01:00
trace.h Revert "NFSD: Replace nfsd_prune_bucket()" 2024-11-24 00:23:45 +01:00
vfs.c Revert "nfsd: make all of the nfsd stats per-network namespace" 2024-11-24 00:23:43 +01:00
vfs.h NFSD: Pass the target nfsd_file to nfsd_commit() 2024-11-19 12:28:26 +01:00
xdr.h SUNRPC: Change return value type of .pc_encode 2024-11-19 12:27:48 +01:00
xdr3.h SUNRPC: Change return value type of .pc_encode 2024-11-19 12:27:48 +01:00
xdr4.h NFSD: Limit the number of concurrent async COPY operations 2024-12-17 13:20:51 +01:00
xdr4cb.h NFSD: add support for sending CB_RECALL_ANY 2024-11-19 12:28:29 +01:00