]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-use-fsnotify-group-lock-helpers.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-use-fsnotify-group-lock-helpers.patch
1 From 14c94ca02993fdd65b21436e8fe9a2bd18fbd814 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 22 Apr 2022 15:03:20 +0300
4 Subject: nfsd: use fsnotify group lock helpers
5
6 From: Amir Goldstein <amir73il@gmail.com>
7
8 [ Upstream commit b8962a9d8cc2d8c93362e2f684091c79f702f6f3 ]
9
10 Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette")
11 nfsd would close open files in direct reclaim context and that could
12 cause a deadlock when fsnotify mark allocation went into direct reclaim
13 and nfsd shrinker tried to free existing fsnotify marks.
14
15 To avoid issues like this in future code, set the FSNOTIFY_GROUP_NOFS
16 flag on nfsd fsnotify group to prevent going into direct reclaim from
17 fsnotify_add_inode_mark().
18
19 Link: https://lore.kernel.org/r/20220422120327.3459282-10-amir73il@gmail.com
20 Suggested-by: Jan Kara <jack@suse.cz>
21 Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/
22 Signed-off-by: Amir Goldstein <amir73il@gmail.com>
23 Signed-off-by: Jan Kara <jack@suse.cz>
24 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
25 ---
26 fs/nfsd/filecache.c | 13 +++++++------
27 1 file changed, 7 insertions(+), 6 deletions(-)
28
29 diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
30 index 97ca256a76323..b1afe6db589f2 100644
31 --- a/fs/nfsd/filecache.c
32 +++ b/fs/nfsd/filecache.c
33 @@ -118,14 +118,14 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
34 struct inode *inode = nf->nf_inode;
35
36 do {
37 - mutex_lock(&nfsd_file_fsnotify_group->mark_mutex);
38 + fsnotify_group_lock(nfsd_file_fsnotify_group);
39 mark = fsnotify_find_mark(&inode->i_fsnotify_marks,
40 - nfsd_file_fsnotify_group);
41 + nfsd_file_fsnotify_group);
42 if (mark) {
43 nfm = nfsd_file_mark_get(container_of(mark,
44 struct nfsd_file_mark,
45 nfm_mark));
46 - mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
47 + fsnotify_group_unlock(nfsd_file_fsnotify_group);
48 if (nfm) {
49 fsnotify_put_mark(mark);
50 break;
51 @@ -133,8 +133,9 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
52 /* Avoid soft lockup race with nfsd_file_mark_put() */
53 fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group);
54 fsnotify_put_mark(mark);
55 - } else
56 - mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
57 + } else {
58 + fsnotify_group_unlock(nfsd_file_fsnotify_group);
59 + }
60
61 /* allocate a new nfm */
62 new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL);
63 @@ -672,7 +673,7 @@ nfsd_file_cache_init(void)
64 }
65
66 nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops,
67 - 0);
68 + FSNOTIFY_GROUP_NOFS);
69 if (IS_ERR(nfsd_file_fsnotify_group)) {
70 pr_err("nfsd: unable to create fsnotify group: %ld\n",
71 PTR_ERR(nfsd_file_fsnotify_group));
72 --
73 2.43.0
74