mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation
@ 2026-11-19  2:47 Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep Andrew Pam
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Pam @ 2026-11-19  2:47 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker
  Cc: Andrew Pam, Chuck Lever, Jeff Layton, NeilBrown,
	Olga Kornievskaia, Dai Ngo, Tom Talpey, Rafael J. Wysocki,
	Mike Snitzer, linux-nfs, linux-pm, netdev, linux-kernel

An NFS client that hibernates with a mount active can resume with the
mount hung, until the server's nfsd is restarted. The underlying
problem was described on linux-pm in 2011 ("hibernate hangs TCP") and
not fixed. This series fixes it for SUNRPC clients.

After hibernation takes its snapshot, the kernel thaws devices, the NIC
among them, to write the image. Freezable kernel work stays frozen until
the image is restored, but rpciod, xprtiod and the NFSv4 lease renewal
work are not freezable. So RPCs are still sent and answered while the
image is written, and TCP acknowledges data from the server, none of
which the restored image knows about. On resume the client's TCP
sequence numbers, its acknowledgement point and its NFSv4.1 session slot
sequence ids are all behind the server's.

Captured between a Linux 7.0 client and a 6.12 server:

  - 05:06:02 last exchange before the snapshot; client snd_nxt
    2711544997.
  - 05:06:15 hibernation entry.
  - 05:06:44 and 05:07:48, after the snapshot: a lease-renewal
    SEQUENCE on slot 0 (seqid 192219), the next (192220), and
    DELEGRETURNs on slots 1-5. The server executes all of them and
    acknowledges up to TCP sequence 2711546645.
  - 14 hours later, on resume: the client retransmits the slot 0
    SEQUENCE from TCP sequence 2711544997. The server discards it as a
    duplicate and acknowledges 2711546645, which the client ignores as
    acknowledging unsent data. Nothing more crosses the connection.
  - On reconnecting, slot 0 gets NFS4ERR_SEQ_MISORDERED (server at
    192220, client at 192219) every 15 seconds indefinitely; the state
    manager waits in nfs4_begin_drain_session() for that task, and
    every other RPC waits behind it.

Other resumes produced the same rollback with different symptoms:
requests accepted by the server's TCP but never reaching nfsd, a partial
overlap that left nfsd reading a session ID as a record marker
("svc_tcp_read_marker nfsd RPC fragment too large"), or a client
waiting for replies it had acknowledged before the restore, which the
server will not send again.

Patches 1 and 2 make rpciod, xprtiod and lease renewal freezable, so
nothing is sent after the snapshot. That keeps the session slots
consistent, but not the receive side: TCP still acknowledges replies
that arrive after the snapshot. Patch 3 therefore disconnects every
client transport once the system has resumed. Requests in flight are
retransmitted on the new connection, and the server's reply cache
answers any it has already executed.

Testing, in QEMU/KVM: an NFSv4.2 client hibernating in test_resume mode
(the image is written, then restored at once) against an nfsd with a 10
second lease, with 1.2 GB of incompressible data in memory and the swap
device throttled so that writing the image takes 81 seconds. The stress
test runs 20 hibernations back to back while NFS writes (8 MB, fsync)
and reads run continuously. On 7.4-rc2, for v1:

                                         unpatched   1-2 only   1-3
  RPCs received during the image write       12          0        0
  20 hibernations under continuous I/O    hung at 1  hung at 6  20/20

Unpatched, the restored client also showed a SEQUENCE error, two extra
connections and 10 seconds of queueing after a single hibernation; with
the series it resumed without errors. Every freeze of kernel threads
completed in 1 ms or less. A capture of the stress runs confirms patch
3's case: the client's acknowledgement went backwards on the cycle that
hung with patches 1-2 only, and on two of the twenty cycles with patch
3, where the client reconnected and carried on. The indefinite
NFS4ERR_SEQ_MISORDERED loop seen on real hardware was not reproduced in
the VM: it also needs a request holding a session slot across the
restore.

On 7.4-rc3, unpatched, the client hung on the third of twenty
hibernations; v2 and v3 each completed all twenty. v3 also ran twenty
hibernations under lockdep (PROVE_LOCKING, PROVE_RCU,
DEBUG_ATOMIC_SLEEP) without a report from the new code, and was built
with SUNRPC as a module. The test harness (two busybox
initramfs VMs, no root needed) is available on request.

Not addressed: the same window affects every active TCP connection, not
only SUNRPC. Keeping network devices quiet while the image is written,
or resetting TCP connections on restore, would fix that generally, but
would need agreement between the PM core and netdev. This series fixes
the case where protocol state outlives the connection and the client
cannot recover by itself. Patches 1 and 2 also freeze rpciod and xprtiod
during suspend to RAM, which is harmless there.

This series applies on top of Chuck Lever's "SUNRPC: Set WQ_SYSFS on
rpciod and xprtiod":
https://lore.kernel.org/linux-nfs/20260915-performance-v3-3-ae26d460bfd3@kernel.org/
Mike Snitzer's "SUNRPC: Make rpciod and xprtiod visible in sysfs"
changes the same two alloc_workqueue() calls for the same purpose.
Patch 3 is compatible with commit 9d84719d34cb ("SUNRPC: add
request-scoped disconnects when cancelling tasks"): its conditional
disconnect is skipped once the connection cookie has moved on, so it
cannot close the connection that patch 3's reconnect creates.

Changes in v3:
  - Rebased onto Chuck Lever's WQ_SYSFS patch; patch 1 now adds
    WQ_FREEZABLE to its shared wq_flags. The original comment in
    rpciod_start() is left alone. (Anna Schumaker)
  - Patch 3: no array, counting pass or transport references. The
    notifier calls xprt_force_disconnect(), which does not sleep, on
    each transport while holding its switch's xps_lock, which keeps the
    listed transports alive. This also removes the misplaced double
    comment. (Anna Schumaker)
  - Changelogs trimmed to what each patch does and why; the capture and
    test results moved here. (Anna Schumaker)
  - v2: https://lore.kernel.org/all/20261116131428.1024230-1-andrew@sericyb.com.au/

The analysis of the packet captures, the patches, the QEMU test harness
and drafts of the changelogs and this letter were produced with an AI
coding assistant (Claude, from Anthropic), working from the hung client
and server, their logs and captures. It also ran the tests. I have
reviewed and edited the patches and am responsible for them.

Andrew Pam (3):
  SUNRPC: freeze rpciod and xprtiod across system sleep
  NFSv4: run lease renewal on a freezable workqueue
  SUNRPC: reconnect client transports after resuming from hibernation

 fs/nfs/nfs4renewd.c      |  2 +-
 net/sunrpc/clnt.c        | 61 ++++++++++++++++++++++++++++++++++++++++
 net/sunrpc/sched.c       |  3 +-
 net/sunrpc/sunrpc.h      |  2 ++
 net/sunrpc/sunrpc_syms.c |  7 +++++
 5 files changed, 73 insertions(+), 2 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
prerequisite-patch-id: a8475a72e4e9a2df387e41ca12df8aa67733256b
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep
  2026-11-19  2:47 [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation Andrew Pam
@ 2026-11-19  2:47 ` Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 2/3] NFSv4: run lease renewal on a freezable workqueue Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 3/3] SUNRPC: reconnect client transports after resuming from hibernation Andrew Pam
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Pam @ 2026-11-19  2:47 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker
  Cc: Andrew Pam, Chuck Lever, Jeff Layton, NeilBrown,
	Olga Kornievskaia, Dai Ngo, Tom Talpey, Rafael J. Wysocki,
	Mike Snitzer, linux-nfs, linux-pm, netdev, linux-kernel

After hibernation takes its snapshot, the kernel thaws devices to write
the image, and the NIC with them. Freezable kernel threads and
workqueues stay frozen until the image is restored, but rpciod and
xprtiod are not freezable, so RPCs continue to be transmitted, and
transports reconnected, until power-off. The server acts on them; the
restored image knows nothing of them. With NFSv4.1 this wedges the mount
after resume. Restarting the server is the only recovery.

Make both workqueues freezable, as the SMB client already does for all
of its workqueues (WQ_FREEZABLE | WQ_MEM_RECLAIM). Work queued while
frozen runs after thaw_processes(), in the restored kernel, which is
consistent with the server. Memory preallocation for the image happens
before freeze_kernel_threads(), so writeback through rpciod is still
available then, and pm_restrict_gfp_mask() keeps reclaim from issuing
I/O while the image is written.

WQ_FREEZABLE is consulted only when freezing and thawing, not when work
is queued or run, so normal operation is unaffected. Entering system
sleep now waits for in-flight rpciod and xprtiod items to finish; these
are short state-machine steps with non-blocking sends and connects. If
one ever blocked for longer than freeze_timeout_msecs, suspend or
hibernation would fail, naming the busy workqueue, where today it
proceeds. The SMB client and XFS accept the same trade-off for their
reclaim workqueues.

This does not stop the network stack from acknowledging data the
server sends after the snapshot, such as a callback or a reply to a
request still in flight when the snapshot was taken; that remains
a general hibernation and TCP problem.

Drafted with an AI coding assistant (Claude), which analysed a packet
capture and wrote the change and a draft of this description.

Signed-off-by: Andrew Pam <andrew@sericyb.com.au>
---
 net/sunrpc/sched.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index e81419aa553c..f1669d1b8520 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -1273,7 +1273,8 @@ void rpciod_down(void)
  */
 static int rpciod_start(void)
 {
-	const unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_UNBOUND | WQ_SYSFS;
+	const unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_UNBOUND | WQ_SYSFS |
+				      WQ_FREEZABLE;
 	struct workqueue_struct *wq;
 
 	/*
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 2/3] NFSv4: run lease renewal on a freezable workqueue
  2026-11-19  2:47 [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep Andrew Pam
@ 2026-11-19  2:47 ` Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 3/3] SUNRPC: reconnect client transports after resuming from hibernation Andrew Pam
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Pam @ 2026-11-19  2:47 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker
  Cc: Andrew Pam, Chuck Lever, Jeff Layton, NeilBrown,
	Olga Kornievskaia, Dai Ngo, Tom Talpey, Rafael J. Wysocki,
	Mike Snitzer, linux-nfs, linux-pm, netdev, linux-kernel

The renewal work is queued on system_percpu_wq, which is not frozen
during system sleep. During hibernation it can therefore fire after the
snapshot has been taken, while the image is written. It then queues
renewal and DELEGRETURN RPCs and can wake the state manager, all on
behalf of a kernel image whose state is about to be discarded.

With rpciod frozen across system sleep (previous patch) those RPCs are
not transmitted until after resume. Run the renewal itself on
system_freezable_wq too, so it does not run in that window at all; the
delayed work fires after thaw if its time has passed.

Drafted with an AI coding assistant (Claude).

Signed-off-by: Andrew Pam <andrew@sericyb.com.au>
---
 fs/nfs/nfs4renewd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index 30065df1482e..a0326f830bca 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -122,7 +122,7 @@ nfs4_schedule_state_renewal(struct nfs_client *clp)
 		timeout = 5 * HZ;
 	dprintk("%s: requeueing work. Lease period = %ld\n",
 			__func__, (timeout + HZ - 1) / HZ);
-	mod_delayed_work(system_percpu_wq, &clp->cl_renewd, timeout);
+	mod_delayed_work(system_freezable_wq, &clp->cl_renewd, timeout);
 	set_bit(NFS_CS_RENEWD, &clp->cl_res_state);
 	spin_unlock(&clp->cl_lock);
 }
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 3/3] SUNRPC: reconnect client transports after resuming from hibernation
  2026-11-19  2:47 [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep Andrew Pam
  2026-11-19  2:47 ` [PATCH v3 2/3] NFSv4: run lease renewal on a freezable workqueue Andrew Pam
@ 2026-11-19  2:47 ` Andrew Pam
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Pam @ 2026-11-19  2:47 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker
  Cc: Andrew Pam, Chuck Lever, Jeff Layton, NeilBrown,
	Olga Kornievskaia, Dai Ngo, Tom Talpey, Rafael J. Wysocki,
	Mike Snitzer, linux-nfs, linux-pm, netdev, linux-kernel

With rpciod and xprtiod frozen across hibernation, no RPC is sent after
the snapshot. TCP can still acknowledge data the server sends then,
though: typically a reply that was in flight when the snapshot was
taken. The restored image has not seen that data, and the server, which
saw it acknowledged, will not send it again. The client then waits
indefinitely for replies that never arrive.

After resuming, disconnect every client transport. Requests in flight
are retransmitted on the new connection, and the server answers any it
has already executed from its reply cache. Because nothing was sent
after the snapshot, NFSv4.1 session slot sequence ids still agree on
both sides.

The disconnect is done from a PM notifier at PM_POST_HIBERNATION, which
runs in the restored kernel once everything has thawed. It is also sent
when hibernation fails, where the reconnect is unnecessary but harmless.
The notifier walks each client's transport switch under its xps_lock.
Every transport on the switch's list holds a reference that is dropped
only after it has been removed under that lock, so the transports stay
valid while it is held. xprt_force_disconnect() does not sleep, so no
references need to be taken and nothing is allocated.

Drafted with an AI coding assistant (Claude).

Signed-off-by: Andrew Pam <andrew@sericyb.com.au>
---
 net/sunrpc/clnt.c        | 61 ++++++++++++++++++++++++++++++++++++++++
 net/sunrpc/sunrpc.h      |  2 ++
 net/sunrpc/sunrpc_syms.c |  7 +++++
 3 files changed, 70 insertions(+)

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 2f076b4bfd54..89afd2d0a47e 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -32,6 +32,8 @@
 #include <linux/in.h>
 #include <linux/in6.h>
 #include <linux/un.h>
+#include <linux/suspend.h>
+#include <net/net_namespace.h>
 
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/addr.h>
@@ -881,6 +883,65 @@ int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
 }
 EXPORT_SYMBOL_GPL(rpc_clnt_iterate_for_each_xprt);
 
+/*
+ * TCP may have acknowledged data from the server after the hibernation
+ * snapshot was taken, which the restored kernel has never seen. Disconnect
+ * every client transport after resume, so that outstanding requests are
+ * retransmitted on a new connection.
+ *
+ * Each transport on a switch's list holds a reference that is dropped only
+ * after it is removed under xps_lock, and xprt_force_disconnect() does not
+ * sleep.
+ */
+static int rpc_pm_notify(struct notifier_block *nb, unsigned long action,
+			 void *data)
+{
+	struct net *net;
+
+	if (action != PM_POST_HIBERNATION)
+		return NOTIFY_DONE;
+
+	down_read(&net_rwsem);
+	for_each_net(net) {
+		struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
+		struct rpc_clnt *clnt;
+
+		spin_lock(&sn->rpc_client_lock);
+		rcu_read_lock();
+		list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
+			struct rpc_xprt_switch *xps;
+			struct rpc_xprt *xprt;
+
+			xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
+			if (!xps)
+				continue;
+			spin_lock(&xps->xps_lock);
+			list_for_each_entry(xprt, &xps->xps_xprt_list,
+					    xprt_switch)
+				xprt_force_disconnect(xprt);
+			spin_unlock(&xps->xps_lock);
+		}
+		rcu_read_unlock();
+		spin_unlock(&sn->rpc_client_lock);
+	}
+	up_read(&net_rwsem);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block rpc_pm_nb = {
+	.notifier_call = rpc_pm_notify,
+};
+
+int rpc_pm_notifier_register(void)
+{
+	return register_pm_notifier(&rpc_pm_nb);
+}
+
+void rpc_pm_notifier_unregister(void)
+{
+	unregister_pm_notifier(&rpc_pm_nb);
+}
+
 /*
  * Kill all tasks for the given client.
  * XXX: kill their descendants as well?
diff --git a/net/sunrpc/sunrpc.h b/net/sunrpc/sunrpc.h
index 11b9e5cead8e..1833b167616c 100644
--- a/net/sunrpc/sunrpc.h
+++ b/net/sunrpc/sunrpc.h
@@ -43,6 +43,8 @@ struct rpc_task;
 struct rpc_xprt;
 int rpc_clients_notifier_register(void);
 void rpc_clients_notifier_unregister(void);
+int rpc_pm_notifier_register(void);
+void rpc_pm_notifier_unregister(void);
 void auth_domain_cleanup(void);
 void svc_sock_update_bufs(struct svc_serv *serv);
 enum svc_auth_status svc_authenticate(struct svc_rqst *rqstp);
diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c
index 1a3884a0376a..d32786f51ae5 100644
--- a/net/sunrpc/sunrpc_syms.c
+++ b/net/sunrpc/sunrpc_syms.c
@@ -116,6 +116,10 @@ init_sunrpc(void)
 	if (err)
 		goto out6;
 
+	err = rpc_pm_notifier_register();
+	if (err)
+		goto out7;
+
 	sunrpc_debugfs_init();
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
 	rpc_register_sysctl();
@@ -124,6 +128,8 @@ init_sunrpc(void)
 	init_socket_xprt();	/* clnt sock transport */
 	return 0;
 
+out7:
+	genl_unregister_family(&sunrpc_nl_family);
 out6:
 	rpc_sysfs_exit();
 out5:
@@ -141,6 +147,7 @@ init_sunrpc(void)
 static void __exit
 cleanup_sunrpc(void)
 {
+	rpc_pm_notifier_unregister();
 	genl_unregister_family(&sunrpc_nl_family);
 	rpc_sysfs_exit();
 	rpc_cleanup_clids();
-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19  2:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  2:47 [PATCH v3 0/3] SUNRPC: keep NFS client connections consistent across hibernation Andrew Pam
2026-11-19  2:47 ` [PATCH v3 1/3] SUNRPC: freeze rpciod and xprtiod across system sleep Andrew Pam
2026-11-19  2:47 ` [PATCH v3 2/3] NFSv4: run lease renewal on a freezable workqueue Andrew Pam
2026-11-19  2:47 ` [PATCH v3 3/3] SUNRPC: reconnect client transports after resuming from hibernation Andrew Pam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®