diff options
| author | Mike Snitzer <snitzer@kernel.org> | 2026-11-02 16:52:18 -0500 |
|---|---|---|
| committer | Anna Schumaker <anna.schumaker@hammerspace.com> | 2026-11-09 15:04:57 -0500 |
| commit | 000a87910213562ff09f5bc38cd366ce34fccf71 (patch) | |
| tree | fafce83ff5cd1055a491765effb46dace29349d1 | |
| parent | f14b157168ac106cfac6d577e08726488b1b886c (diff) | |
NFS/localio: hold the client across an asynchronous LOCALIO probe
nfs_local_probe_async() queues the client's own cl_local_probe_work
without a reference on the client, and nfs_free_client() does not cancel
it. The work takes a reference only once it runs. If the last
nfs_put_client() comes first, for example at umount after an NFSv3 I/O
queued a throttled probe, the client is freed with its work queued, and
the work then runs on freed memory.
Take the reference when the work is queued, and drop it when the work
has run. If the work is already queued, it already holds a reference,
and the one just taken is dropped.
Fixes: 76d4cb6345da ("nfs: probe for LOCALIO when v4 client reconnects to server")
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Anna Schumaker <anna.schumaker@hammerspace.com>
| -rw-r--r-- | fs/nfs/localio.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index cdada6cbb13b..d5859e8c2a2a 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -203,15 +203,22 @@ void nfs_local_probe_async_work(struct work_struct *work) struct nfs_client *clp = container_of(work, struct nfs_client, cl_local_probe_work); - if (!refcount_inc_not_zero(&clp->cl_count)) - return; nfs_local_probe(clp); + /* The reference nfs_local_probe_async() took for this work */ nfs_put_client(clp); } +/* + * The work is part of the client, so it holds a reference on the client + * from when it is queued until it has run: the last nfs_put_client() + * cannot free the client under a queued probe. + */ void nfs_local_probe_async(struct nfs_client *clp) { - queue_work(nfsiod_workqueue, &clp->cl_local_probe_work); + if (!refcount_inc_not_zero(&clp->cl_count)) + return; + if (!queue_work(nfsiod_workqueue, &clp->cl_local_probe_work)) + nfs_put_client(clp); /* already queued, with its reference */ } EXPORT_SYMBOL_GPL(nfs_local_probe_async); |
