nfsd: check that server is running in unlock_filesystem
Subsystems (2)
Olga Kornievskaia
reviewerPATCH 1/1 nfsd: check that server is running in unlock_filesystem
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd] [ 59.456069] lr : nfsd4_revoke_states+0x19c/0x898 [nfsd] [ 59.456701] sp : ffff80008cd67900 [ 59.457115] x29: ffff80008cd679d0 x28: 1fffe00016a53f84 x27: dfff800000000000 [ 59.458006] x26: 04b800ef00000000 x25: 1fffe00016a53f80 x24: ffff0000a796ea00 [ 59.458872] x23: ffff0000b89d6000 x22: ffff0000b6c36900 x21: ffff0000b6c36580 [ 59.459738] x20: ffff80008cd67990 x19: ffff0000b6c365c0 x18: 0000000000000000 [ 59.460602] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 59.461480] x14: 0000000000000000 x13: 0000000000000001 x12: ffff7000119acf13 [ 59.462272] x11: 1ffff000119acf12 x10: ffff7000119acf12 x9 : dfff800000000000 [ 59.463002] x8 : ffff80008cd67810 x7 : 0000000000000000 x6 : 0097001de0000000 [ 59.463732] x5 : 0000000000000004 x4 : ffff0000b5818000 x3 : 04b800ef00000004 [ 59.464368] x2 : 0000000000000000 x1 : 0000000000000005 x0 : 04b800ef00000000 [ 59.465072] Call trace: [ 59.465308] nfsd4_revoke_states+0x1b4/0x898 [nfsd] (P) [ 59.465830] write_unlock_fs+0x258/0x440 [nfsd] [ 59.466278] nfsctl_transaction_write+0xb0/0x120 [nfsd] [ 59.466780] vfs_write+0x1f0/0x938 [ 59.467088] ksys_write+0xfc/0x1f8 [ 59.467395] __arm64_sys_write+0x74/0xb8 [ 59.467746] invoke_syscall.constprop.0+0xdc/0x1e8 [ 59.468177] do_el0_svc+0x154/0x1d8 [ 59.468489] el0_svc+0x40/0xe0 [ 59.468767] el0t_64_sync_handler+0xa0/0xe8 [ 59.469138] el0t_64_sync+0x1ac/0x1b0 [ 59.469472] Code: 91001343 92400865 d343fc66 110004a1 (38fb68c0) [ 59.470012] SMP: stopping secondary CPUs [ 59.472070] Starting crashdump kernel... [ 59.472537] Bye!
--- fs/nfsd/nfs4state.c | 3 +++ 1 file changed, 3 insertions(+)
fs/nfsd/nfs4state.c +3 -0
@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types; +if (!nn->nfsd_serv) +return ; + sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock);
Signature · 1 line
2.47.3
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 38 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd] [ 59.456069] lr : nfsd4_revoke_states+0x19c/0x898 [nfsd] [ 59.456701] sp : ffff80008cd67900 [ 59.457115] x29: ffff80008cd679d0 x28: 1fffe00016a53f84 x27: dfff800000000000 [ 59.458006] x26: 04b800ef00000000 x25: 1fffe00016a53f80 x24: ffff0000a796ea00 [ 59.458872] x23: ffff0000b89d6000 x22: ffff0000b6c36900 x21: ffff0000b6c36580 [ 59.459738] x20: ffff80008cd67990 x19: ffff0000b6c365c0 x18: 0000000000000000 [ 59.460602] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 59.461480] x14: 0000000000000000 x13: 0000000000000001 x12: ffff7000119acf13 [ 59.462272] x11: 1ffff000119acf12 x10: ffff7000119acf12 x9 : dfff800000000000 [ 59.463002] x8 : ffff80008cd67810 x7 : 0000000000000000 x6 : 0097001de0000000 [ 59.463732] x5 : 0000000000000004 x4 : ffff0000b5818000 x3 : 04b800ef00000004 [ 59.464368] x2 : 0000000000000000 x1 : 0000000000000005 x0 : 04b800ef00000000 [ 59.465072] Call trace: [ 59.465308] nfsd4_revoke_states+0x1b4/0x898 [nfsd] (P) [ 59.465830] write_unlock_fs+0x258/0x440 [nfsd] [ 59.466278] nfsctl_transaction_write+0xb0/0x120 [nfsd] [ 59.466780] vfs_write+0x1f0/0x938 [ 59.467088] ksys_write+0xfc/0x1f8 [ 59.467395] __arm64_sys_write+0x74/0xb8 [ 59.467746] invoke_syscall.constprop.0+0xdc/0x1e8 [ 59.468177] do_el0_svc+0x154/0x1d8 [ 59.468489] el0_svc+0x40/0xe0 [ 59.468767] el0t_64_sync_handler+0xa0/0xe8 [ 59.469138] el0t_64_sync+0x1ac/0x1b0 [ 59.469472] Code: 91001343 92400865 d343fc66 110004a1 (38fb68c0) [ 59.470012] SMP: stopping secondary CPUs [ 59.472070] Starting crashdump kernel... [ 59.472537] Bye!
Quoted 1 line
[...]
Applied to nfsd-testing, thanks!
[1/1] nfsd: check that server is running in unlock_filesystem
commit: 93a8a71809edddea8212e726abf7b9bf2379bd0c
--
Chuck Lever
Quoted 49 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd] [ 59.456069] lr : nfsd4_revoke_states+0x19c/0x898 [nfsd] [ 59.456701] sp : ffff80008cd67900 [ 59.457115] x29: ffff80008cd679d0 x28: 1fffe00016a53f84 x27: dfff800000000000 [ 59.458006] x26: 04b800ef00000000 x25: 1fffe00016a53f80 x24: ffff0000a796ea00 [ 59.458872] x23: ffff0000b89d6000 x22: ffff0000b6c36900 x21: ffff0000b6c36580 [ 59.459738] x20: ffff80008cd67990 x19: ffff0000b6c365c0 x18: 0000000000000000 [ 59.460602] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 59.461480] x14: 0000000000000000 x13: 0000000000000001 x12: ffff7000119acf13 [ 59.462272] x11: 1ffff000119acf12 x10: ffff7000119acf12 x9 : dfff800000000000 [ 59.463002] x8 : ffff80008cd67810 x7 : 0000000000000000 x6 : 0097001de0000000 [ 59.463732] x5 : 0000000000000004 x4 : ffff0000b5818000 x3 : 04b800ef00000004 [ 59.464368] x2 : 0000000000000000 x1 : 0000000000000005 x0 : 04b800ef00000000 [ 59.465072] Call trace: [ 59.465308] nfsd4_revoke_states+0x1b4/0x898 [nfsd] (P) [ 59.465830] write_unlock_fs+0x258/0x440 [nfsd] [ 59.466278] nfsctl_transaction_write+0xb0/0x120 [nfsd] [ 59.466780] vfs_write+0x1f0/0x938 [ 59.467088] ksys_write+0xfc/0x1f8 [ 59.467395] __arm64_sys_write+0x74/0xb8 [ 59.467746] invoke_syscall.constprop.0+0xdc/0x1e8 [ 59.468177] do_el0_svc+0x154/0x1d8 [ 59.468489] el0_svc+0x40/0xe0 [ 59.468767] el0t_64_sync_handler+0xa0/0xe8 [ 59.469138] el0t_64_sync+0x1ac/0x1b0 [ 59.469472] Code: 91001343 92400865 d343fc66 110004a1 (38fb68c0) [ 59.470012] SMP: stopping secondary CPUs [ 59.472070] Starting crashdump kernel... [ 59.472537] Bye!Fixes 1ac3629bf0125 ("nfsd: prepare for supporting admin-revocation of state")Signed-off-by Olga Kornievskaia <[email protected]>--- fs/nfsd/nfs4state.c | 3 +++ 1 file changed, 3 insertions(+)fs/nfsd/nfs4state.c +0
-0
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct net *net, struct super_block *sb) · line 1783
Quoted 9 lines
fs/nfsd/nfs4state.c +3
-0@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types; +if (!nn->nfsd_serv) +return ; + sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock);
Ouch. Good catch. I'm surprised we haven't seen this before!
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]
But *why* does it crash?
Can you please
./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898
and report what line of code it is crashing on?
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct net *net, struct super_block *sb) · line 1780
Quoted 12 lines
fs/nfsd/nfs4state.c +3
-0@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types; +if (!nn->nfsd_serv) +return ; +
Seeing that nfsd4_revoke_states() doesn't make any reference to nfsd_serv, I think this change is - at best - confusing.
As there is no lock held here, nfsd_serv could spontaneously become NULL at any time, so this is unlikely to be a complete fix.
I would expect each conf_id_hashtbl[] list to be empty when no server is running so the function should do nothing. Clearly my expectation is wrong, but I would like to know *why* it is wrong, and to fix the root cause.
We also need this
fs/nfsd/nfs4state.c +1 -1
@@ -1778,7 +1778,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock); -for (idhashval =0 ; idhashval <CLIENT_HASH_MASK ; idhashval++) { +for (idhashval =0 ; idhashval <CLIENT_HASH_SIZE ; idhashval++) {struct list_head *head = &nn->conf_id_hashtbl[idhashval];struct nfs4_client *clp; retry:
Maybe it should be part of the same patch - maybe not.
Thanks,
NeilBrown
Quoted 12 lines · NeilBrown
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]
Quoted 6 lines
But *why* does it crash?
Can you please
./scripts/faddr2linefs/nfsd/nfs4state.onfsd4_revoke_states+0x1b4/0x898and report what line of code it is crashing on?
okorniev@linux-10:/source/linux$ ./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898 nfsd4_revoke_states+0x1b4/0x898: find_one_sb_stid at /source/linux/fs/nfsd/nfs4state.c:1748 (inlined by) nfsd4_revoke_states at /source/linux/fs/nfsd/nfs4state.c:1786
Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfs4state.c +0
-0@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types;
Quoted 6 lines
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct net *net, struct super_block *sb) · line 1780
Quoted 3 lines
fs/nfsd/nfs4state.c +3
-0+if (!nn->nfsd_serv) +return ; +Seeing that
nfsd4_revoke_states()doesn't make any reference tonfsd_serv, I think this change is - at best - confusing.
This solution was in line with how the rest of proc functionality did it (ie it checks whether or not the server is running).
Quoted 2 lines
As there is no lock held here,
nfsd_servcould spontaneously become NULL at any time, so this is unlikely to be a complete fix.
I disagree that it's not a fix. As the main logic I think should be that the unlock operation shouldn't be attempted if there isn't a running server.
However, what I think you are saying is that the server shutdown cleanup should have cleaned things such that this error shouldn't occur even if there isn't a check for the running server. While I see the logic there, I find it more confusing to ignore the fact that we are not checking for the running state of the server before trying to perform an operation that assumes the server is running.
Quoted 1 line
I would expect each conf_id_hashtbl[] list to be empty
Not only is it empty, it's been freed by nfsd4_state_destroy_net() function.
"systemctl start nfs-server" --- creates the conf_id_hashtbl "systemctl stop nfs-server" --- ends up freeing it echo path > unlock_filesystem --- has no conf_id_hashtbl.
I still stand that the solution here is to check for the running server. If you think the check nn->nfsd_net_up is better than checking for null, I can do that.
Quoted 20 lines
when no server is
running so the function should do nothing. Clearly my expectation is wrong, but I would like to know *why* it is wrong, and to fix the root cause.We also need this
fs/nfsd/nfs4state.c +1
-1@@ -1778,7 +1778,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock); -for (idhashval =0 ; idhashval <CLIENT_HASH_MASK ; idhashval++) { +for (idhashval =0 ; idhashval <CLIENT_HASH_SIZE ; idhashval++) {struct list_head *head = &nn->conf_id_hashtbl[idhashval];struct nfs4_client *clp; retry:
Quoted 1 line
Maybe it should be part of the same patch - maybe not.
I gather this is a needed change but insufficient to fix the issue and should be a separate patch (as a fix for something but not this problem).
Quoted 4 lines
Thanks,
NeilBrown
Quoted 18 lines · Olga Kornievskaia
Quoted 17 lines · NeilBrown
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]But *why* does it crash?
Can you please
./scripts/faddr2linefs/nfsd/nfs4state.onfsd4_revoke_states+0x1b4/0x898
Quoted 7 lines
Quoted 1 line
and report what line of code it is crashing on?
okorniev@linux-10:/source/linux$ ./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898 nfsd4_revoke_states+0x1b4/0x898: find_one_sb_stid at /source/linux/fs/nfsd/nfs4state.c:1748 (inlined by) nfsd4_revoke_states at /source/linux/fs/nfsd/nfs4state.c:1786
Thanks. As you suggest it is likely accessing memory that we freed by nfsd_shutdown_net(). By the time it gets into find_one_sb_stid() it would have already accessed some freed memory so it was lucky to get that far.
Code that wants to access conf_id_hash and related parts of nn should use:
nfsd_net_try_get(net)
to check if it is safe and to keep it safe, and then nfsd_net_put(net) when it has finished. That is more robust than simply checking nfsd_serv.
Quoted 16 lines
Quoted 9 lines
Quoted 9 lines
fs/nfsd/nfs4state.c +0
-0@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types;Quoted 6 lines
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct net *net, struct super_block *sb) · line 1780
Quoted 3 lines
fs/nfsd/nfs4state.c +3
-0+if (!nn->nfsd_serv) +return ; +Seeing that
nfsd4_revoke_states()doesn't make any reference tonfsd_serv, I think this change is - at best - confusing.
Quoted 2 lines
This solution was in line with how the rest of proc functionality did it (ie it checks whether or not the server is running).
That code checks nfsd_serv while holding nfsd_mutex. write_unlock_fs() does not take nfsd_mutex, so testing nfsd_serv in nfsd4_revoke_state() is racy.
Quoted 47 lines
Quoted 3 lines
As there is no lock held here,
nfsd_servcould spontaneously become NULL at any time, so this is unlikely to be a complete fix.I disagree that it's not a fix. As the main logic I think should be that the unlock operation shouldn't be attempted if there isn't a running server.
However, what I think you are saying is that the server shutdown cleanup should have cleaned things such that this error shouldn't occur even if there isn't a check for the running server. While I see the logic there, I find it more confusing to ignore the fact that we are not checking for the running state of the server before trying to perform an operation that assumes the server is running.
Quoted 1 line
I would expect each conf_id_hashtbl[] list to be empty
Not only is it empty, it's been freed by
nfsd4_state_destroy_net()function."systemctl start nfs-server" --- creates the
conf_id_hashtbl"systemctl stop nfs-server" --- ends up freeing it echo path >unlock_filesystem--- has noconf_id_hashtbl.I still stand that the solution here is to check for the running server. If you think the check
nn->nfsd_net_upis better than checking for null, I can do that.Quoted 20 lines
when no server is
running so the function should do nothing. Clearly my expectation is wrong, but I would like to know *why* it is wrong, and to fix the root cause.We also need this
fs/nfsd/nfs4state.c +1
-1@@ -1778,7 +1778,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock); -for (idhashval =0 ; idhashval <CLIENT_HASH_MASK ; idhashval++) { +for (idhashval =0 ; idhashval <CLIENT_HASH_SIZE ; idhashval++) {struct list_head *head = &nn->conf_id_hashtbl[idhashval];struct nfs4_client *clp; retry:
Quoted 5 lines
Quoted 1 line
Maybe it should be part of the same patch - maybe not.
I gather this is a needed change but insufficient to fix the issue and should be a separate patch (as a fix for something but not this problem).
It is just a tangentially related bug that I noticed while reading the code. Not really related to the bug you found, so it deserves to be a separate patch. I'll send something.
Thanks,
NeilBrown
Quoted 33 lines · NeilBrown
Quoted 18 lines · Olga Kornievskaia
Quoted 17 lines · NeilBrown
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]But *why* does it crash?
Can you please
./scripts/faddr2linefs/nfsd/nfs4state.onfsd4_revoke_states+0x1b4/0x898Quoted 7 lines
Quoted 1 line
and report what line of code it is crashing on?
okorniev@linux-10:/source/linux$ ./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898 nfsd4_revoke_states+0x1b4/0x898: find_one_sb_stid at /source/linux/fs/nfsd/nfs4state.c:1748 (inlined by) nfsd4_revoke_states at /source/linux/fs/nfsd/nfs4state.c:1786Thanks. As you suggest it is likely accessing memory that we freed by
nfsd_shutdown_net(). By the time it gets intofind_one_sb_stid()it would have already accessed some freed memory so it was lucky to get that far.
Quoted 7 lines
Code that wants to access
conf_id_hashand related parts of nn should use:
nfsd_net_try_get(net)to check if it is safe and to keep it safe, and then
nfsd_net_put(net)when it has finished. That is more robust than simply checkingnfsd_serv.
I'm confused by the guidance given.
I understood that other uses of nn->nfsd_server did so by grabbing the nfsd_mutex lock. Thus, I ask, if it would be acceptable to do. Again, I vote for this as it's the same as what the other proc uses (note, unsure what the appropriate error code here should be).
fs/nfsd/nfsctl.c +0 -0
@@ -259,6 +259,7 @@ static ssize_t write_unlock_fs(struct file *file,
char *buf, size_t size)
struct path path;
char *fo_path;
int error;+ struct nfsd_net *nn;
/* sanity check */
if (size == 0)
@@ -285,6 +286,11 @@ static ssize_t write_unlock_fs(struct file *file,
char *buf, size_t size)
* 3. Is that directory the root of an exported file system?
*/
error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb);
+ mutex_lock(&nfsd_mutex);
+ nn = net_generic(netns(file), nfsd_net_id);
+ if (!nn->nfsd_serv)
+ return -EINVAL;
+ mutex_unlock(&nfsd_mutex);
nfsd4_revoke_states(netns(file), path.dentry->d_sb);
path_put(&path);However, your preference was to make use of nfsd_net_try_get() function and here's my attempt:
fs/nfsd/nfsctl.c +0 -0
@@ -285,8 +285,10 @@ static ssize_t write_unlock_fs(struct file *file,
char *buf, size_t size)
* 3. Is that directory the root of an exported file system?
*/
error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb);
+ if (!nfsd_net_try_get(netns(file)))
+ return -EINVAL;
nfsd4_revoke_states(netns(file), path.dentry->d_sb);
-
+ nfsd_net_put(netns(file));
path_put(&path);
return error;}
But I'm confused that nfsd_net_try_get() has "__must_hold(rcu)" yet when I look at usage of that function there is only one place that calls under rcu_read_lock(). Thus I'm confused about the said requirement. Also say if rca_read_lock was gotten before nfsd_net_try_get() call can it be released directly after it or is it supposed to be held over the call to nfssd4_revoke_states().
Neil/Chuck/Jeff please which of those 2 patches should I resend (and if the 2nd one needs modifications as I said I'm too unsure about the suggested approach).
Thank you.
Quoted 83 lines
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
fs/nfsd/nfs4state.c +0
-0@@ -1775,6 +1775,9 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb)unsigned int idhashval;unsigned int sc_types;Quoted 6 lines
fs/nfsd/nfs4state.c void nfsd4_revoke_states(struct net *net, struct super_block *sb) · line 1780
Quoted 3 lines
fs/nfsd/nfs4state.c +3
-0+if (!nn->nfsd_serv) +return ; +Seeing that
nfsd4_revoke_states()doesn't make any reference tonfsd_serv, I think this change is - at best - confusing.Quoted 2 lines
This solution was in line with how the rest of proc functionality did it (ie it checks whether or not the server is running).
That code checks
nfsd_servwhile holdingnfsd_mutex.write_unlock_fs()does not takenfsd_mutex, so testingnfsd_servinnfsd4_revoke_state()is racy.Quoted 47 lines
Quoted 3 lines
As there is no lock held here,
nfsd_servcould spontaneously become NULL at any time, so this is unlikely to be a complete fix.I disagree that it's not a fix. As the main logic I think should be that the unlock operation shouldn't be attempted if there isn't a running server.
However, what I think you are saying is that the server shutdown cleanup should have cleaned things such that this error shouldn't occur even if there isn't a check for the running server. While I see the logic there, I find it more confusing to ignore the fact that we are not checking for the running state of the server before trying to perform an operation that assumes the server is running.
Quoted 1 line
I would expect each conf_id_hashtbl[] list to be empty
Not only is it empty, it's been freed by
nfsd4_state_destroy_net()function."systemctl start nfs-server" --- creates the
conf_id_hashtbl"systemctl stop nfs-server" --- ends up freeing it echo path >unlock_filesystem--- has noconf_id_hashtbl.I still stand that the solution here is to check for the running server. If you think the check
nn->nfsd_net_upis better than checking for null, I can do that.Quoted 20 lines
when no server is
running so the function should do nothing. Clearly my expectation is wrong, but I would like to know *why* it is wrong, and to fix the root cause.We also need this
fs/nfsd/nfs4state.c +1
-1@@ -1778,7 +1778,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock); -for (idhashval =0 ; idhashval <CLIENT_HASH_MASK ; idhashval++) { +for (idhashval =0 ; idhashval <CLIENT_HASH_SIZE ; idhashval++) {struct list_head *head = &nn->conf_id_hashtbl[idhashval];struct nfs4_client *clp; retry:Quoted 5 lines
Quoted 1 line
Maybe it should be part of the same patch - maybe not.
I gather this is a needed change but insufficient to fix the issue and should be a separate patch (as a fix for something but not this problem).
It is just a tangentially related bug that I noticed while reading the code. Not really related to the bug you found, so it deserves to be a separate patch. I'll send something.
Thanks,
NeilBrown
Quoted 37 lines · Olga Kornievskaia
Quoted 36 lines · NeilBrown
Quoted 18 lines · Olga Kornievskaia
Quoted 17 lines · NeilBrown
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]But *why* does it crash?
Can you please
./scripts/faddr2linefs/nfsd/nfs4state.onfsd4_revoke_states+0x1b4/0x898Quoted 7 lines
Quoted 1 line
and report what line of code it is crashing on?
okorniev@linux-10:/source/linux$ ./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898 nfsd4_revoke_states+0x1b4/0x898: find_one_sb_stid at /source/linux/fs/nfsd/nfs4state.c:1748 (inlined by) nfsd4_revoke_states at /source/linux/fs/nfsd/nfs4state.c:1786Thanks. As you suggest it is likely accessing memory that we freed by
nfsd_shutdown_net(). By the time it gets intofind_one_sb_stid()it would have already accessed some freed memory so it was lucky to get that far.Code that wants to access
conf_id_hashand related parts of nn should use:
Quoted 6 lines
Quoted 4 lines
nfsd_net_try_get(net)to check if it is safe and to keep it safe, and then
nfsd_net_put(net)when it has finished. That is more robust than simply checkingnfsd_serv.I'm confused by the guidance given.
Probably the guidance was confused.
Quoted 5 lines
I understood that other uses of
nn->nfsd_serverdid so by grabbing thenfsd_mutexlock. Thus, I ask, if it would be acceptable to do. Again, I vote for this as it's the same as what the other proc uses (note, unsure what the appropriate error code here should be).
Yes it would be acceptable to use nfsd_mutex.
I don't like nfsd_mutex and would like to get rid of it. In most cases there is no desire to wait, only to ensure other code waits before destroying anything, and that fits the refcount pattern better.
But we have nfsd_mutex now so it isn't wrong to use it.
Quoted 14 lines
fs/nfsd/nfsctl.c +1
-0@@ -259,6 +259,7 @@ static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) struct path path;char *fo_path;int error; +struct nfsd_net *nn;/* sanity check */ if (size == 0)
fs/nfsd/nfsctl.c static ssize_t write_unlock_fs(struct file *file, · line 295
Quoted 10 lines
fs/nfsd/nfsctl.c +5
-0@@ -285,6 +286,11 @@ static ssize_t write_unlock_fs(struct file *file,char *buf, size_t size) * 3. Is that directory the root of an exported file system? */ error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb); +mutex_lock (&nfsd_mutex); + nn =net_generic (netns (file), nfsd_net_id); +if (!nn->nfsd_serv) +return -EINVAL ; +mutex_unlock (&nfsd_mutex);nfsd4_revoke_states (netns (file), path.dentry->d_sb);
If you move the mutex_unlock to *after* the nfsd4_revoke_states() call, this should be correct.
It might be nicer to change nfsd4_revoke_states() to take an nfsd_net rather than a net, then you could just pass 'nn', but it isn't a big deal.
Quoted 11 lines
fs/nfsd/nfsctl.c +0
-0path_put (&path);However, your preference was to make use of
nfsd_net_try_get()function and here's my attempt:fs/nfsd/nfsctl.c +0
-0
fs/nfsd/nfsctl.c static ssize_t write_unlock_fs(struct file *file, · line 292
Quoted 9 lines
fs/nfsd/nfsctl.c +3
-1@@ -285,8 +285,10 @@ static ssize_t write_unlock_fs(struct file *file,char *buf, size_t size) * 3. Is that directory the root of an exported file system? */ error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb); +if (!nfsd_net_try_get (netns (file))) +return -EINVAL ;nfsd4_revoke_states (netns (file), path.dentry->d_sb); - +nfsd_net_put (netns (file));
This looks correct - except that it might need rcu protection as you note below.
Quoted 10 lines
fs/nfsd/nfsctl.c +0
-0path_put (&path);return error;}
But I'm confused that
nfsd_net_try_get()has "__must_hold(rcu)" yet when I look at usage of that function there is only one place that calls underrcu_read_lock(). Thus I'm confused about the said requirement. Also say ifrca_read_lockwas gotten beforenfsd_net_try_get()call can it be released directly after it or is it supposed to be held over the call tonfssd4_revoke_states().
That __must_hold(rcu) is wrong - sort of.
It should be in the .h file as well to be at all useful. The important thing is that a stable ref should be held to 'net', and rcu is one have a stable reference is via rcu.
I think rcu is needed inside nfsd_net_try_get() to ensure that if 'nn' is not NULL, then percpu_ref_tryget_live() cannot access freed memory. I think it is currently safe because when netd_net_try_get() is called without rcu_read_lock, there is already a ref held and the code is just trying to get an extra one.
In general, if rcu is used to stablise 'net', then nfsd_net_try_get() will stablise it more permanently and also stablise the nfsd-specific parts of 'net'. So after nfsd_net_try_get() succeeds, rcu_read_lock() is no longer needed.
Quoted 4 lines
Neil/Chuck/Jeff please which of those 2 patches should I resend (and if the 2nd one needs modifications as I said I'm too unsure about the suggested approach).
Given the uncertainties around rcu, it is probably best use the nfsd_mutex approach, as long as the we don't unlock until after the work is done.
Thanks,
NeilBrown
Quoted 145 lines · NeilBrown
Quoted 37 lines · Olga Kornievskaia
Quoted 36 lines · NeilBrown
Quoted 18 lines · Olga Kornievskaia
Quoted 17 lines · NeilBrown
Quoted 9 lines · Olga Kornievskaia
If we are trying to unlock the filesystem via an administrative interface and nfsd isn't running, it crashes the server.
[ 59.445578] Modules linked in: nfsd nfs_acl lockd grace nfs_localio ext4 crc16 mbcache jbd2 overlay uinput snd_seq_dummy snd_hrtimer qrtr rfkill vfat fat uvcvideo snd_hda_codec_generic videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videobuf2_common snd_hda_intel snd_intel_dspcfg snd_hda_codec videodev snd_hda_core snd_hwdep mc snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop auth_rpcgss vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs ghash_ce nvme e1000e nvme_core nvme_keyring nvme_auth hkdf sr_mod cdrom vmwgfx drm_ttm_helper ttm 8021q garp stp llc mrp sunrpc dm_mirror dm_region_hash dm_log iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi fuse dm_multipath dm_mod nfnetlink [ 59.451979] CPU: 4 UID: 0 PID: 5193 Comm: bash Kdump: loaded Tainted: G B 6.18.0-rc4+ #74 PREEMPT(voluntary) [ 59.453311] Tainted: [B]=BAD_PAGE [ 59.453913] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 59.454869] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 59.455463] pc : nfsd4_revoke_states+0x1b4/0x898 [nfsd]But *why* does it crash?
Can you please
./scripts/faddr2linefs/nfsd/nfs4state.onfsd4_revoke_states+0x1b4/0x898Quoted 7 lines
Quoted 1 line
and report what line of code it is crashing on?
okorniev@linux-10:/source/linux$ ./scripts/faddr2line fs/nfsd/nfs4state.o nfsd4_revoke_states+0x1b4/0x898 nfsd4_revoke_states+0x1b4/0x898: find_one_sb_stid at /source/linux/fs/nfsd/nfs4state.c:1748 (inlined by) nfsd4_revoke_states at /source/linux/fs/nfsd/nfs4state.c:1786Thanks. As you suggest it is likely accessing memory that we freed by
nfsd_shutdown_net(). By the time it gets intofind_one_sb_stid()it would have already accessed some freed memory so it was lucky to get that far.Code that wants to access
conf_id_hashand related parts of nn should use:Quoted 6 lines
Quoted 4 lines
nfsd_net_try_get(net)to check if it is safe and to keep it safe, and then
nfsd_net_put(net)when it has finished. That is more robust than simply checkingnfsd_serv.I'm confused by the guidance given.
Probably the guidance was confused.
Quoted 5 lines
I understood that other uses of
nn->nfsd_serverdid so by grabbing thenfsd_mutexlock. Thus, I ask, if it would be acceptable to do. Again, I vote for this as it's the same as what the other proc uses (note, unsure what the appropriate error code here should be).Yes it would be acceptable to use
nfsd_mutex.
I don't likenfsd_mutexand would like to get rid of it. In most cases there is no desire to wait, only to ensure other code waits before destroying anything, and that fits the refcount pattern better.But we have
nfsd_mutexnow so it isn't wrong to use it.Quoted 14 lines
fs/nfsd/nfsctl.c +1
-0@@ -259,6 +259,7 @@ static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) struct path path;char *fo_path;int error; +struct nfsd_net *nn;/* sanity check */ if (size == 0)fs/nfsd/nfsctl.c static ssize_t write_unlock_fs(struct file *file, · line 295
Quoted 10 lines
fs/nfsd/nfsctl.c +5
-0@@ -285,6 +286,11 @@ static ssize_t write_unlock_fs(struct file *file,char *buf, size_t size) * 3. Is that directory the root of an exported file system? */ error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb); +mutex_lock (&nfsd_mutex); + nn =net_generic (netns (file), nfsd_net_id); +if (!nn->nfsd_serv) +return -EINVAL ; +mutex_unlock (&nfsd_mutex);nfsd4_revoke_states (netns (file), path.dentry->d_sb);If you move the
mutex_unlockto *after* thenfsd4_revoke_states()call, this should be correct.It might be nicer to change
nfsd4_revoke_states()to take annfsd_netrather than a net, then you could just pass 'nn', but it isn't a big deal.Quoted 11 lines
fs/nfsd/nfsctl.c +0
-0path_put (&path);However, your preference was to make use of
nfsd_net_try_get()function and here's my attempt:fs/nfsd/nfsctl.c +0
-0fs/nfsd/nfsctl.c static ssize_t write_unlock_fs(struct file *file, · line 292
Quoted 9 lines
fs/nfsd/nfsctl.c +3
-1@@ -285,8 +285,10 @@ static ssize_t write_unlock_fs(struct file *file,char *buf, size_t size) * 3. Is that directory the root of an exported file system? */ error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb); +if (!nfsd_net_try_get (netns (file))) +return -EINVAL ;nfsd4_revoke_states (netns (file), path.dentry->d_sb); - +nfsd_net_put (netns (file));This looks correct - except that it might need rcu protection as you note below.
Quoted 10 lines
fs/nfsd/nfsctl.c +0
-0path_put (&path);return error;}
But I'm confused that
nfsd_net_try_get()has "__must_hold(rcu)" yet when I look at usage of that function there is only one place that calls underrcu_read_lock(). Thus I'm confused about the said requirement. Also say ifrca_read_lockwas gotten beforenfsd_net_try_get()call can it be released directly after it or is it supposed to be held over the call tonfssd4_revoke_states().That
__must_hold(rcu)is wrong - sort of.
It should be in the .h file as well to be at all useful. The important thing is that a stable ref should be held to 'net', and rcu is one have a stable reference is via rcu.I think rcu is needed inside
nfsd_net_try_get()to ensure that if 'nn' is not NULL, thenpercpu_ref_tryget_live()cannot access freed memory. I think it is currently safe because whennetd_net_try_get()is called withoutrcu_read_lock, there is already a ref held and the code is just trying to get an extra one.In general, if rcu is used to stablise 'net', then
nfsd_net_try_get()will stablise it more permanently and also stablise the nfsd-specific parts of 'net'. So afternfsd_net_try_get()succeeds,rcu_read_lock()is no longer needed.Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Neil/Chuck/Jeff please which of those 2 patches should I resend (and if the 2nd one needs modifications as I said I'm too unsure about the suggested approach).
Given the uncertainties around rcu, it is probably best use the
nfsd_mutexapproach, as long as the we don't unlock until after the work is done.
Thank you Neil. V2 is sent.
Quoted 3 lines
Thanks,
NeilBrown