]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/6.1.73/revert-nfsd-separate-nfsd_last_thread-from-nfsd_put.patch
Linux 5.15.147
[thirdparty/kernel/stable-queue.git] / releases / 6.1.73 / revert-nfsd-separate-nfsd_last_thread-from-nfsd_put.patch
1 From c3cd2872f4aed958f70d7f871ea6cf3ff29d4674 Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3 Date: Sat, 13 Jan 2024 10:38:35 +0100
4 Subject: Revert "nfsd: separate nfsd_last_thread() from nfsd_put()"
5
6 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
7
8 This reverts commit 03d68ffc48b94cc1e15bbf3b4f16f1e1e4fa286a which is
9 commit 9f28a971ee9fdf1bf8ce8c88b103f483be610277 upstream.
10
11 It is reported to cause issues, so revert it.
12
13 Reported-by: email200202 <email200202@yahoo.com>
14 Link: https://lore.kernel.org/r/e341cb408b5663d8c91b8fa57b41bb984be43448.camel@kernel.org
15 Cc: NeilBrown <neilb@suse.de>
16 Cc: Jeff Layton <jlayton@kernel.org>
17 Cc: Chuck Lever <chuck.lever@oracle.com>
18 Cc: Sasha Levin <sashal@kernel.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 fs/nfsd/nfsd.h | 7 +------
22 fs/nfsd/nfssvc.c | 52 +++++++++++++++++++++++++++++++++-------------------
23 2 files changed, 34 insertions(+), 25 deletions(-)
24
25 --- a/fs/nfsd/nfsd.h
26 +++ b/fs/nfsd/nfsd.h
27 @@ -97,12 +97,7 @@ int nfsd_pool_stats_open(struct inode *
28 int nfsd_pool_stats_release(struct inode *, struct file *);
29 void nfsd_shutdown_threads(struct net *net);
30
31 -static inline void nfsd_put(struct net *net)
32 -{
33 - struct nfsd_net *nn = net_generic(net, nfsd_net_id);
34 -
35 - svc_put(nn->nfsd_serv);
36 -}
37 +void nfsd_put(struct net *net);
38
39 bool i_am_nfsd(void);
40
41 --- a/fs/nfsd/nfssvc.c
42 +++ b/fs/nfsd/nfssvc.c
43 @@ -523,14 +523,9 @@ static struct notifier_block nfsd_inet6a
44 /* Only used under nfsd_mutex, so this atomic may be overkill: */
45 static atomic_t nfsd_notifier_refcount = ATOMIC_INIT(0);
46
47 -static void nfsd_last_thread(struct net *net)
48 +static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
49 {
50 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
51 - struct svc_serv *serv = nn->nfsd_serv;
52 -
53 - spin_lock(&nfsd_notifier_lock);
54 - nn->nfsd_serv = NULL;
55 - spin_unlock(&nfsd_notifier_lock);
56
57 /* check if the notifier still has clients */
58 if (atomic_dec_return(&nfsd_notifier_refcount) == 0) {
59 @@ -540,8 +535,6 @@ static void nfsd_last_thread(struct net
60 #endif
61 }
62
63 - svc_xprt_destroy_all(serv, net);
64 -
65 /*
66 * write_ports can create the server without actually starting
67 * any threads--if we get shut down before any threads are
68 @@ -632,8 +625,7 @@ void nfsd_shutdown_threads(struct net *n
69 svc_get(serv);
70 /* Kill outstanding nfsd threads */
71 svc_set_num_threads(serv, NULL, 0);
72 - nfsd_last_thread(net);
73 - svc_put(serv);
74 + nfsd_put(net);
75 mutex_unlock(&nfsd_mutex);
76 }
77
78 @@ -663,6 +655,9 @@ int nfsd_create_serv(struct net *net)
79 serv->sv_maxconn = nn->max_connections;
80 error = svc_bind(serv, net);
81 if (error < 0) {
82 + /* NOT nfsd_put() as notifiers (see below) haven't
83 + * been set up yet.
84 + */
85 svc_put(serv);
86 return error;
87 }
88 @@ -705,6 +700,29 @@ int nfsd_get_nrthreads(int n, int *nthre
89 return 0;
90 }
91
92 +/* This is the callback for kref_put() below.
93 + * There is no code here as the first thing to be done is
94 + * call svc_shutdown_net(), but we cannot get the 'net' from
95 + * the kref. So do all the work when kref_put returns true.
96 + */
97 +static void nfsd_noop(struct kref *ref)
98 +{
99 +}
100 +
101 +void nfsd_put(struct net *net)
102 +{
103 + struct nfsd_net *nn = net_generic(net, nfsd_net_id);
104 +
105 + if (kref_put(&nn->nfsd_serv->sv_refcnt, nfsd_noop)) {
106 + svc_xprt_destroy_all(nn->nfsd_serv, net);
107 + nfsd_last_thread(nn->nfsd_serv, net);
108 + svc_destroy(&nn->nfsd_serv->sv_refcnt);
109 + spin_lock(&nfsd_notifier_lock);
110 + nn->nfsd_serv = NULL;
111 + spin_unlock(&nfsd_notifier_lock);
112 + }
113 +}
114 +
115 int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
116 {
117 int i = 0;
118 @@ -755,7 +773,7 @@ int nfsd_set_nrthreads(int n, int *nthre
119 if (err)
120 break;
121 }
122 - svc_put(nn->nfsd_serv);
123 + nfsd_put(net);
124 return err;
125 }
126
127 @@ -770,7 +788,6 @@ nfsd_svc(int nrservs, struct net *net, c
128 int error;
129 bool nfsd_up_before;
130 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
131 - struct svc_serv *serv;
132
133 mutex_lock(&nfsd_mutex);
134 dprintk("nfsd: creating service\n");
135 @@ -790,25 +807,22 @@ nfsd_svc(int nrservs, struct net *net, c
136 goto out;
137
138 nfsd_up_before = nn->nfsd_net_up;
139 - serv = nn->nfsd_serv;
140
141 error = nfsd_startup_net(net, cred);
142 if (error)
143 goto out_put;
144 - error = svc_set_num_threads(serv, NULL, nrservs);
145 + error = svc_set_num_threads(nn->nfsd_serv, NULL, nrservs);
146 if (error)
147 goto out_shutdown;
148 - error = serv->sv_nrthreads;
149 - if (error == 0)
150 - nfsd_last_thread(net);
151 + error = nn->nfsd_serv->sv_nrthreads;
152 out_shutdown:
153 if (error < 0 && !nfsd_up_before)
154 nfsd_shutdown_net(net);
155 out_put:
156 /* Threads now hold service active */
157 if (xchg(&nn->keep_active, 0))
158 - svc_put(serv);
159 - svc_put(serv);
160 + nfsd_put(net);
161 + nfsd_put(net);
162 out:
163 mutex_unlock(&nfsd_mutex);
164 return error;