Re: [PATCH v3] lockd: serialize server host->h_rpcclnt across rebind, async submit, and shutdown
From: Chuck Lever
Date: Wed Dec 02 2026 - 10:12:37 EST
> diff --git a/fs/lockd/host.c b/fs/lockd/host.c
> index d572cb27533f..911b3fb57b8b 100644
> --- a/fs/lockd/host.c
> +++ b/fs/lockd/host.c
> @@ -381,6 +381,9 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
>
> mutex_lock(&nlm_host_mutex);
>
> + if (READ_ONCE(ln->nlmsvc_shutdown))
> + goto out;
> +
Nit: the kernel-doc comment above nlmsvc_lookup_host() still describes it
as returning a matching host or creating a new one. Could that comment
mention the NULL returns? Something like:
* Returns NULL if lockd is shutting down in this network namespace,
* or if a new nlm_host cannot be allocated.
> @@ -453,15 +456,21 @@ void nlmsvc_release_host(struct nlm_host *host)
> * Create the NLM RPC client for an NLM peer
> */
> struct rpc_clnt *
> -nlm_bind_host(struct nlm_host *host)
> +nlm_bind_host_locked(struct nlm_host *host)
> {
> struct rpc_clnt *clnt;
>
> + lockdep_assert_held(&host->h_mutex);
> +
> dprintk("lockd: nlm_bind_host %s (%s)\n",
> host->h_name, host->h_addrbuf);
>
> - /* Lock host handle */
> - mutex_lock(&host->h_mutex);
> + if (host->h_server) {
> + struct lockd_net *ln = net_generic(host->net, lockd_net_id);
> +
> + if (READ_ONCE(ln->nlmsvc_shutdown))
> + return NULL;
> + }
After the split, the "Create the NLM RPC client" comment sits on
nlm_bind_host_locked(), and the nlm_bind_host() wrapper has no comment at
all. Neither one records that the caller holds h_mutex across a bind that
can sleep in rpc_create(), or that a server host gets NULL once
nlm_shutdown_hosts_net() has started on its net. Can both functions get a
comment that covers the h_mutex requirement and the new NULL return?
nlm_rebind_host() picks up a similar unstated rule. For a server host it
now runs only under h_mutex, while the client-side callers still call it
without the lock. Would a Context: line in its kernel-doc, or a
lockdep_assert_held() conditioned on host->h_server, capture the rule?
> diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
> index 0a6540409ef8..5421e00d2b32 100644
> --- a/fs/lockd/svclock.c
> +++ b/fs/lockd/svclock.c
> @@ -835,7 +835,9 @@ nlmsvc_grant_blocked(struct nlm_block *block)
> * Just retry the grant callback, possibly refreshing the RPC
> * binding */
> if (block->b_granted) {
> + mutex_lock(&block->b_host->h_mutex);
> nlm_rebind_host(block->b_host);
> + mutex_unlock(&block->b_host->h_mutex);
> goto callback;
> }
Is this rebind still needed? The callback label leads to
nlm_async_call()
-> __nlm_async_call()
-> nlm_bind_host_locked()
and nlm_bind_host_locked() calls nlm_rebind_host() under the same h_mutex
whenever h_rpcclnt is set. h_nextrebind turns whichever call runs second
into a no-op. Dropping the explicit call and its lock and unlock would
leave nlm_bind_host_locked() as the one place a server host rebinds. The
"possibly refreshing the RPC binding" comment could then point at the
bind path instead.
Please send a v4 with these nits addressed. Thanks!
--
Chuck Lever