]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
35d9189e9a1dad4a2bb5948f11ad076d96d4a349
[thirdparty/kernel/stable-queue.git] /
1 From 8e5ced7804cb9184c4a23f8054551240562a8eda Mon Sep 17 00:00:00 2001
2 From: David Howells <dhowells@redhat.com>
3 Date: Tue, 30 Jul 2024 17:01:40 +0100
4 Subject: netfs, ceph: Revert "netfs: Remove deprecated use of PG_private_2 as a second writeback flag"
5
6 From: David Howells <dhowells@redhat.com>
7
8 commit 8e5ced7804cb9184c4a23f8054551240562a8eda upstream.
9
10 This reverts commit ae678317b95e760607c7b20b97c9cd4ca9ed6e1a.
11
12 Revert the patch that removes the deprecated use of PG_private_2 in
13 netfslib for the moment as Ceph is actually still using this to track
14 data copied to the cache.
15
16 Fixes: ae678317b95e ("netfs: Remove deprecated use of PG_private_2 as a second writeback flag")
17 Reported-by: Max Kellermann <max.kellermann@ionos.com>
18 Signed-off-by: David Howells <dhowells@redhat.com>
19 cc: Ilya Dryomov <idryomov@gmail.com>
20 cc: Xiubo Li <xiubli@redhat.com>
21 cc: Jeff Layton <jlayton@kernel.org>
22 cc: Matthew Wilcox <willy@infradead.org>
23 cc: ceph-devel@vger.kernel.org
24 cc: netfs@lists.linux.dev
25 cc: linux-fsdevel@vger.kernel.org
26 cc: linux-mm@kvack.org
27 https: //lore.kernel.org/r/3575457.1722355300@warthog.procyon.org.uk
28 Signed-off-by: Christian Brauner <brauner@kernel.org>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 ---
31 fs/ceph/addr.c | 19 +++++
32 fs/netfs/buffered_read.c | 8 ++
33 fs/netfs/io.c | 144 +++++++++++++++++++++++++++++++++++++++++++
34 include/trace/events/netfs.h | 1
35 4 files changed, 170 insertions(+), 2 deletions(-)
36
37 --- a/fs/ceph/addr.c
38 +++ b/fs/ceph/addr.c
39 @@ -498,6 +498,11 @@ const struct netfs_request_ops ceph_netf
40 };
41
42 #ifdef CONFIG_CEPH_FSCACHE
43 +static void ceph_set_page_fscache(struct page *page)
44 +{
45 + folio_start_private_2(page_folio(page)); /* [DEPRECATED] */
46 +}
47 +
48 static void ceph_fscache_write_terminated(void *priv, ssize_t error, bool was_async)
49 {
50 struct inode *inode = priv;
51 @@ -515,6 +520,10 @@ static void ceph_fscache_write_to_cache(
52 ceph_fscache_write_terminated, inode, true, caching);
53 }
54 #else
55 +static inline void ceph_set_page_fscache(struct page *page)
56 +{
57 +}
58 +
59 static inline void ceph_fscache_write_to_cache(struct inode *inode, u64 off, u64 len, bool caching)
60 {
61 }
62 @@ -706,6 +715,8 @@ static int writepage_nounlock(struct pag
63 len = wlen;
64
65 set_page_writeback(page);
66 + if (caching)
67 + ceph_set_page_fscache(page);
68 ceph_fscache_write_to_cache(inode, page_off, len, caching);
69
70 if (IS_ENCRYPTED(inode)) {
71 @@ -789,6 +800,8 @@ static int ceph_writepage(struct page *p
72 return AOP_WRITEPAGE_ACTIVATE;
73 }
74
75 + folio_wait_private_2(page_folio(page)); /* [DEPRECATED] */
76 +
77 err = writepage_nounlock(page, wbc);
78 if (err == -ERESTARTSYS) {
79 /* direct memory reclaimer was killed by SIGKILL. return 0
80 @@ -1062,7 +1075,8 @@ get_more_pages:
81 unlock_page(page);
82 break;
83 }
84 - if (PageWriteback(page)) {
85 + if (PageWriteback(page) ||
86 + PagePrivate2(page) /* [DEPRECATED] */) {
87 if (wbc->sync_mode == WB_SYNC_NONE) {
88 doutc(cl, "%p under writeback\n", page);
89 unlock_page(page);
90 @@ -1070,6 +1084,7 @@ get_more_pages:
91 }
92 doutc(cl, "waiting on writeback %p\n", page);
93 wait_on_page_writeback(page);
94 + folio_wait_private_2(page_folio(page)); /* [DEPRECATED] */
95 }
96
97 if (!clear_page_dirty_for_io(page)) {
98 @@ -1254,6 +1269,8 @@ new_request:
99 }
100
101 set_page_writeback(page);
102 + if (caching)
103 + ceph_set_page_fscache(page);
104 len += thp_size(page);
105 }
106 ceph_fscache_write_to_cache(inode, offset, len, caching);
107 --- a/fs/netfs/buffered_read.c
108 +++ b/fs/netfs/buffered_read.c
109 @@ -466,7 +466,7 @@ retry:
110 if (!netfs_is_cache_enabled(ctx) &&
111 netfs_skip_folio_read(folio, pos, len, false)) {
112 netfs_stat(&netfs_n_rh_write_zskip);
113 - goto have_folio;
114 + goto have_folio_no_wait;
115 }
116
117 rreq = netfs_alloc_request(mapping, file,
118 @@ -507,6 +507,12 @@ retry:
119 netfs_put_request(rreq, false, netfs_rreq_trace_put_return);
120
121 have_folio:
122 + if (test_bit(NETFS_ICTX_USE_PGPRIV2, &ctx->flags)) {
123 + ret = folio_wait_private_2_killable(folio);
124 + if (ret < 0)
125 + goto error;
126 + }
127 +have_folio_no_wait:
128 *_folio = folio;
129 kleave(" = 0");
130 return 0;
131 --- a/fs/netfs/io.c
132 +++ b/fs/netfs/io.c
133 @@ -99,6 +99,146 @@ static void netfs_rreq_completed(struct
134 }
135
136 /*
137 + * [DEPRECATED] Deal with the completion of writing the data to the cache. We
138 + * have to clear the PG_fscache bits on the folios involved and release the
139 + * caller's ref.
140 + *
141 + * May be called in softirq mode and we inherit a ref from the caller.
142 + */
143 +static void netfs_rreq_unmark_after_write(struct netfs_io_request *rreq,
144 + bool was_async)
145 +{
146 + struct netfs_io_subrequest *subreq;
147 + struct folio *folio;
148 + pgoff_t unlocked = 0;
149 + bool have_unlocked = false;
150 +
151 + rcu_read_lock();
152 +
153 + list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
154 + XA_STATE(xas, &rreq->mapping->i_pages, subreq->start / PAGE_SIZE);
155 +
156 + xas_for_each(&xas, folio, (subreq->start + subreq->len - 1) / PAGE_SIZE) {
157 + if (xas_retry(&xas, folio))
158 + continue;
159 +
160 + /* We might have multiple writes from the same huge
161 + * folio, but we mustn't unlock a folio more than once.
162 + */
163 + if (have_unlocked && folio->index <= unlocked)
164 + continue;
165 + unlocked = folio_next_index(folio) - 1;
166 + trace_netfs_folio(folio, netfs_folio_trace_end_copy);
167 + folio_end_private_2(folio);
168 + have_unlocked = true;
169 + }
170 + }
171 +
172 + rcu_read_unlock();
173 + netfs_rreq_completed(rreq, was_async);
174 +}
175 +
176 +static void netfs_rreq_copy_terminated(void *priv, ssize_t transferred_or_error,
177 + bool was_async) /* [DEPRECATED] */
178 +{
179 + struct netfs_io_subrequest *subreq = priv;
180 + struct netfs_io_request *rreq = subreq->rreq;
181 +
182 + if (IS_ERR_VALUE(transferred_or_error)) {
183 + netfs_stat(&netfs_n_rh_write_failed);
184 + trace_netfs_failure(rreq, subreq, transferred_or_error,
185 + netfs_fail_copy_to_cache);
186 + } else {
187 + netfs_stat(&netfs_n_rh_write_done);
188 + }
189 +
190 + trace_netfs_sreq(subreq, netfs_sreq_trace_write_term);
191 +
192 + /* If we decrement nr_copy_ops to 0, the ref belongs to us. */
193 + if (atomic_dec_and_test(&rreq->nr_copy_ops))
194 + netfs_rreq_unmark_after_write(rreq, was_async);
195 +
196 + netfs_put_subrequest(subreq, was_async, netfs_sreq_trace_put_terminated);
197 +}
198 +
199 +/*
200 + * [DEPRECATED] Perform any outstanding writes to the cache. We inherit a ref
201 + * from the caller.
202 + */
203 +static void netfs_rreq_do_write_to_cache(struct netfs_io_request *rreq)
204 +{
205 + struct netfs_cache_resources *cres = &rreq->cache_resources;
206 + struct netfs_io_subrequest *subreq, *next, *p;
207 + struct iov_iter iter;
208 + int ret;
209 +
210 + trace_netfs_rreq(rreq, netfs_rreq_trace_copy);
211 +
212 + /* We don't want terminating writes trying to wake us up whilst we're
213 + * still going through the list.
214 + */
215 + atomic_inc(&rreq->nr_copy_ops);
216 +
217 + list_for_each_entry_safe(subreq, p, &rreq->subrequests, rreq_link) {
218 + if (!test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags)) {
219 + list_del_init(&subreq->rreq_link);
220 + netfs_put_subrequest(subreq, false,
221 + netfs_sreq_trace_put_no_copy);
222 + }
223 + }
224 +
225 + list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
226 + /* Amalgamate adjacent writes */
227 + while (!list_is_last(&subreq->rreq_link, &rreq->subrequests)) {
228 + next = list_next_entry(subreq, rreq_link);
229 + if (next->start != subreq->start + subreq->len)
230 + break;
231 + subreq->len += next->len;
232 + list_del_init(&next->rreq_link);
233 + netfs_put_subrequest(next, false,
234 + netfs_sreq_trace_put_merged);
235 + }
236 +
237 + ret = cres->ops->prepare_write(cres, &subreq->start, &subreq->len,
238 + subreq->len, rreq->i_size, true);
239 + if (ret < 0) {
240 + trace_netfs_failure(rreq, subreq, ret, netfs_fail_prepare_write);
241 + trace_netfs_sreq(subreq, netfs_sreq_trace_write_skip);
242 + continue;
243 + }
244 +
245 + iov_iter_xarray(&iter, ITER_SOURCE, &rreq->mapping->i_pages,
246 + subreq->start, subreq->len);
247 +
248 + atomic_inc(&rreq->nr_copy_ops);
249 + netfs_stat(&netfs_n_rh_write);
250 + netfs_get_subrequest(subreq, netfs_sreq_trace_get_copy_to_cache);
251 + trace_netfs_sreq(subreq, netfs_sreq_trace_write);
252 + cres->ops->write(cres, subreq->start, &iter,
253 + netfs_rreq_copy_terminated, subreq);
254 + }
255 +
256 + /* If we decrement nr_copy_ops to 0, the usage ref belongs to us. */
257 + if (atomic_dec_and_test(&rreq->nr_copy_ops))
258 + netfs_rreq_unmark_after_write(rreq, false);
259 +}
260 +
261 +static void netfs_rreq_write_to_cache_work(struct work_struct *work) /* [DEPRECATED] */
262 +{
263 + struct netfs_io_request *rreq =
264 + container_of(work, struct netfs_io_request, work);
265 +
266 + netfs_rreq_do_write_to_cache(rreq);
267 +}
268 +
269 +static void netfs_rreq_write_to_cache(struct netfs_io_request *rreq) /* [DEPRECATED] */
270 +{
271 + rreq->work.func = netfs_rreq_write_to_cache_work;
272 + if (!queue_work(system_unbound_wq, &rreq->work))
273 + BUG();
274 +}
275 +
276 +/*
277 * Handle a short read.
278 */
279 static void netfs_rreq_short_read(struct netfs_io_request *rreq,
280 @@ -275,6 +415,10 @@ again:
281 clear_bit_unlock(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
282 wake_up_bit(&rreq->flags, NETFS_RREQ_IN_PROGRESS);
283
284 + if (test_bit(NETFS_RREQ_COPY_TO_CACHE, &rreq->flags) &&
285 + test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags))
286 + return netfs_rreq_write_to_cache(rreq);
287 +
288 netfs_rreq_completed(rreq, was_async);
289 }
290
291 --- a/include/trace/events/netfs.h
292 +++ b/include/trace/events/netfs.h
293 @@ -145,6 +145,7 @@
294 EM(netfs_folio_trace_clear_g, "clear-g") \
295 EM(netfs_folio_trace_clear_s, "clear-s") \
296 EM(netfs_folio_trace_copy_to_cache, "mark-copy") \
297 + EM(netfs_folio_trace_end_copy, "end-copy") \
298 EM(netfs_folio_trace_filled_gaps, "filled-gaps") \
299 EM(netfs_folio_trace_kill, "kill") \
300 EM(netfs_folio_trace_kill_cc, "kill-cc") \