Skip to contentSkip to conversation

NFSv4.0: Fix a state manager deadlock with OPEN_CONFIRM

RFC PATCH New Ionut Nechita (Wind River) 1 participant 2 messages Dec 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NFSv4.0: Fix a state manager deadlock with OPEN_CONFIRM

From: Ionut Nechita <[email protected]>

This RFC fixes a deadlock in the NFSv4.0 client between the state manager and an OPEN_CONFIRM that is waiting for a slot. When it happens, every RPC of the nfs_client stops and every mount of that server hangs. In practice only a reboot recovered the nodes.

We hit it repeatedly on NFSv4.0 mounts of a NetApp ONTAP server: 17 episodes of NFS4ERR_BAD_SEQID errors in 22 days on four nodes, 16 of them ended in a hang. The deadlock itself is proven for two of them:
one by a vmcore, one by a packet capture and the kernel stacks taken during the hang. The other hangs show the same hung-task reports, but there is no data that shows their cause.

How it starts (server side, from a packet capture and the client's nfs4_xdr_status tracepoint):

An OPEN_DOWNGRADE got NFS4ERR_DELAY. The client advanced the open-owner seqid, as RFC 7530 section 9.1.7 requires (DELAY is not in the list of errors that leave the seqid unchanged), and the retry got NFS4ERR_BAD_SEQID. The server evidently did not consume the seqid on DELAY. From then on every CLOSE of a file opened under the old owner fails with BAD_SEQID, and each failure makes nfs4_reset_state_owner() switch to a new open-owner name: about 1,000 owners on one mount in 15 minutes. I/O keeps flowing during this phase. After about 17,000 owner names on the four mounts the server started to set OPEN4_RESULT_CONFIRM on every OPEN of a new owner (it never did before), and 3 seconds later the client stopped.

Why the client stops (from the vmcore, details in the patch):

The OPEN_CONFIRM holds the open-owner seqid and sleeps on the slot table that the state manager drained for NOGRACE recovery. The recovery OPEN of the state manager waits for that seqid in nfs_wait_on_sequence(), so it is never sent and the manager never ends the drain. The other prepare functions (open, close, lock, locku) release the seqid when they have to sleep for a slot; OPEN_CONFIRM does not. All waiters are TASK_KILLABLE, so hung_task only reports the writeback waiters behind them.

The drain covers the whole nfs_client, so per-mount actions do not help. "umount -f" on other mounts of the same server only moved their tasks from the writeback wait to the next RPC (a GETATTR), which waited on the same drained slot table.

The server behaviour is a separate problem; we have no server-side logs for it yet. But a misbehaving server should cost the client a recovery, not a reboot, and the deadlock only needs an OPEN_CONFIRM in flight when the state manager starts draining, which any v4.0 server that uses OPEN_CONFIRM can produce.

The patch makes OPEN_CONFIRM always privileged. I chose this over releasing the seqid while it sleeps, because that would let another OPEN of the still unconfirmed owner overtake the OPEN_CONFIRM (RFC 7530 section 16.18.5).

Testing: compile-tested only (next-20261202, x86_64, W=1). The analysis was done on a 6.12.57 client; the code involved is unchanged since then. I do not have a reproducer yet. It would need a v4.0 server that returns OPEN4_RESULT_CONFIRM while the client runs state recovery, for example nfsd changed to always ask for confirmation, plus an injected BAD_SEQID or a forced lease expiry. Suggestions for an easier way are welcome.

Questions:

1. Is a privileged OPEN_CONFIRM acceptable during the other drains (nfs4_establish_lease(), nfs4_try_migration(), expired delegations)? be05c860d79b added the slot sequence to OPEN_CONFIRM so that it is not sent while the transport is plugged. The recovery OPENs are already privileged in the same situation. Should it be privileged only during state recovery instead?

2. If the OPEN reply carries no valid attributes, _nfs4_proc_open() calls nfs4_proc_getattr() while it still holds the seqid, and that GETATTR can hang on a drained slot table the same way. It is rare for CLAIM_NULL opens. Worth a separate fix?

Ionut Nechita (1):
NFSv4.0: Fix a state manager deadlock with OPEN_CONFIRM

 fs/nfs/nfs4proc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

base-commit: 799dd936553182df5770dde7f38d94c8337df75a

Signature · 1 line
2.55.0
#1 lore raw

RFC PATCH 1/1 NFSv4.0: Fix a state manager deadlock with OPEN_CONFIRM

From: Ionut Nechita <[email protected]>

An OPEN keeps the open-owner seqid at the head of so_seqid.list until _nfs4_opendata_to_nfs4_state() releases it. When the server answers with OPEN4_RESULT_CONFIRM, _nfs4_proc_open() sends the OPEN_CONFIRM inside that window, with the same nfs_seqid (c_arg.seqid == o_arg.seqid).

The OPEN_CONFIRM is not privileged for a normal open. If the state manager has drained the slot table in the meantime (nfs4_do_reclaim() calls nfs4_begin_drain_session()), nfs4_setup_sequence() puts the OPEN_CONFIRM to sleep on slot_tbl_waitq while it still holds the seqid. nfs4_open_prepare(), nfs4_close_prepare(), nfs4_lock_prepare() and nfs4_locku_prepare() release their seqid in that case; nfs4_open_confirm_prepare() does not.

The recovery OPEN of the state manager is privileged and does not need to wait for a slot, but nfs4_open_prepare() first calls nfs_wait_on_sequence() on the same open-owner and sleeps behind the OPEN_CONFIRM. The recovery OPEN is never sent, nfs4_run_open_task() never returns, the state manager never reaches nfs4_end_drain_session(), and the OPEN_CONFIRM never gets a slot. Every other RPC of the nfs_client, on every mount of that server, waits on the drained slot table, and nfs4_wait_clnt_recover() callers wait for NFS4CLNT_MANAGER_RUNNING to clear. In practice only a reboot recovers the node. The waiters sleep in TASK_KILLABLE, so the hung task detector reports only the writeback waiters behind them.

This was seen with NFSv4.0 mounts of a NetApp ONTAP server that started to set OPEN4_RESULT_CONFIRM after a long series of NFS4ERR_BAD_SEQID replies (each of which makes the client use a new open-owner name). A vmcore of a hung client shows:

nfs_client.cl_state MANAGER_RUNNING | RECLAIM_NOGRACE
slot_tbl_state NFS4_SLOT_TBL_DRAINING, highest_used_slotid
NFS4_NO_SLOT (nothing in flight)
slot_tbl_waitq 39 tasks, one of them nfs4_open_confirm_ops
(o_res.rflags 6, sa_privileged 0)
so_seqid.list OPEN_CONFIRM, CLOSE, CLOSE, recovery OPEN
state manager rpc_wait_bit_killable <- nfs4_run_open_task <-
nfs4_open_recover_helper <- nfs4_open_recover <- nfs4_do_open_expired <- nfs40_open_expired <- nfs4_do_reclaim <- nfs4_run_state_manager
opener rpc_wait_bit_killable <- _nfs4_proc_open_confirm

                       <- nfs4_do_open <- nfs4_atomic_open

Always send OPEN_CONFIRM as a privileged request. The OPEN it belongs to has already passed the drain barrier, and the requests queued behind it on so_seqid.list keep their order, so the server still sees the OPEN, its OPEN_CONFIRM and only then the next request of that open-owner.

Releasing the seqid while the OPEN_CONFIRM sleeps, as nfs4_open_prepare() does, is not done here: another OPEN of the same open-owner could then reach the server before the OPEN_CONFIRM and, per RFC 7530 section 16.18.5, cancel the unconfirmed state of the first one.

Fixes be05c860d79b ("NFS: Add nfs4_sequence calls for OPEN_CONFIRM")

---
RFC, compile-tested only. See the cover letter for the background, the test status and the open questions.

 fs/nfs/nfs4proc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/nfs4proc.c +6 -1
index 6759fa61b..fdae6b8c7 100644
@@ -2465,8 +2465,13 @@ static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
 	};
 	int status;
 
+	/*
+	 * OPEN_CONFIRM holds the open-owner seqid. It must be able to get a
+	 * slot while the state manager drains the slot table, otherwise it
+	 * deadlocks with the recovery OPEN that waits for that seqid.
+	 */
 	nfs4_init_sequence(server->nfs_client, &data->c_arg.seq_args,
-			   &data->c_res.seq_res, 1, data->is_recover);
+			   &data->c_res.seq_res, 1, 1);
 	kref_get(&data->kref);
 	data->rpc_done = false;
 	data->rpc_status = 0;
Signature · 1 line
2.55.0