diff mbox series

nfsd: destroy percpu stats counters after reply cache shutdown

Message ID 20220523185226.7614-1-jumaco@dev-dsk-jumaco-1e-78723413.us-east-1.amazon.com (mailing list archive)
State New
Headers show
Series nfsd: destroy percpu stats counters after reply cache shutdown | expand

Commit Message

Julian Schroeder May 23, 2022, 6:52 p.m. UTC
From: Julian Schroeder <jumaco@amazon.com>

Upon nfsd shutdown any pending DRC cache is freed. DRC cache use is
tracked via a percpu counter. In the current code the percpu counter
is destroyed before. If any pending cache is still present,
percpu_counter_add is called with a percpu counter==NULL. This causes
a kernel crash.
The solution is to destroy the percpu counter after the cache is freed.

Fixes: e567b98ce9a4b (“nfsd: protect concurrent access to nfsd stats counters”)
Signed-off-by: Julian Schroeder <jumaco@amazon.com>
---
 fs/nfsd/nfscache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Chuck Lever III May 23, 2022, 7:25 p.m. UTC | #1
> On May 23, 2022, at 2:52 PM, Julian Schroeder <jumaco@dev-dsk-jumaco-1e-78723413.us-east-1.amazon.com> wrote:
> 
> From: Julian Schroeder <jumaco@amazon.com>
> 
> Upon nfsd shutdown any pending DRC cache is freed. DRC cache use is
> tracked via a percpu counter. In the current code the percpu counter
> is destroyed before. If any pending cache is still present,
> percpu_counter_add is called with a percpu counter==NULL. This causes
> a kernel crash.
> The solution is to destroy the percpu counter after the cache is freed.
> 
> Fixes: e567b98ce9a4b (“nfsd: protect concurrent access to nfsd stats counters”)
> Signed-off-by: Julian Schroeder <jumaco@amazon.com>
> ---
> fs/nfsd/nfscache.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
> index 0b3f12aa37ff..7da88bdc0d6c 100644
> --- a/fs/nfsd/nfscache.c
> +++ b/fs/nfsd/nfscache.c
> @@ -206,7 +206,6 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn)
> 	struct svc_cacherep	*rp;
> 	unsigned int i;
> 
> -	nfsd_reply_cache_stats_destroy(nn);
> 	unregister_shrinker(&nn->nfsd_reply_cache_shrinker);
> 
> 	for (i = 0; i < nn->drc_hashsize; i++) {
> @@ -217,6 +216,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn)
> 									rp, nn);
> 		}
> 	}
> +	nfsd_reply_cache_stats_destroy(nn);
> 
> 	kvfree(nn->drc_hashtbl);
> 	nn->drc_hashtbl = NULL;
> -- 
> 2.32.0
> 

Thank you, Julian. Patch applied to the NFSD for-5.19 topic branch.

--
Chuck Lever
diff mbox series

Patch

diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 0b3f12aa37ff..7da88bdc0d6c 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -206,7 +206,6 @@  void nfsd_reply_cache_shutdown(struct nfsd_net *nn)
 	struct svc_cacherep	*rp;
 	unsigned int i;
 
-	nfsd_reply_cache_stats_destroy(nn);
 	unregister_shrinker(&nn->nfsd_reply_cache_shrinker);
 
 	for (i = 0; i < nn->drc_hashsize; i++) {
@@ -217,6 +216,7 @@  void nfsd_reply_cache_shutdown(struct nfsd_net *nn)
 									rp, nn);
 		}
 	}
+	nfsd_reply_cache_stats_destroy(nn);
 
 	kvfree(nn->drc_hashtbl);
 	nn->drc_hashtbl = NULL;