nfsd: use fsnotify group lock helpers
[ Upstream commit b8962a9d8cc2d8c93362e2f684091c79f702f6f3 ] Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette") nfsd would close open files in direct reclaim context and that could cause a deadlock when fsnotify mark allocation went into direct reclaim and nfsd shrinker tried to free existing fsnotify marks. To avoid issues like this in future code, set the FSNOTIFY_GROUP_NOFS flag on nfsd fsnotify group to prevent going into direct reclaim from fsnotify_add_inode_mark(). Link: https://lore.kernel.org/r/20220422120327.3459282-10-amir73il@gmail.com Suggested-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
e26b208539
commit
924ad2359b
1 changed files with 7 additions and 6 deletions
|
@ -118,14 +118,14 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
|
||||||
struct inode *inode = nf->nf_inode;
|
struct inode *inode = nf->nf_inode;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
mutex_lock(&nfsd_file_fsnotify_group->mark_mutex);
|
fsnotify_group_lock(nfsd_file_fsnotify_group);
|
||||||
mark = fsnotify_find_mark(&inode->i_fsnotify_marks,
|
mark = fsnotify_find_mark(&inode->i_fsnotify_marks,
|
||||||
nfsd_file_fsnotify_group);
|
nfsd_file_fsnotify_group);
|
||||||
if (mark) {
|
if (mark) {
|
||||||
nfm = nfsd_file_mark_get(container_of(mark,
|
nfm = nfsd_file_mark_get(container_of(mark,
|
||||||
struct nfsd_file_mark,
|
struct nfsd_file_mark,
|
||||||
nfm_mark));
|
nfm_mark));
|
||||||
mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
|
fsnotify_group_unlock(nfsd_file_fsnotify_group);
|
||||||
if (nfm) {
|
if (nfm) {
|
||||||
fsnotify_put_mark(mark);
|
fsnotify_put_mark(mark);
|
||||||
break;
|
break;
|
||||||
|
@ -133,8 +133,9 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)
|
||||||
/* Avoid soft lockup race with nfsd_file_mark_put() */
|
/* Avoid soft lockup race with nfsd_file_mark_put() */
|
||||||
fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group);
|
fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group);
|
||||||
fsnotify_put_mark(mark);
|
fsnotify_put_mark(mark);
|
||||||
} else
|
} else {
|
||||||
mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex);
|
fsnotify_group_unlock(nfsd_file_fsnotify_group);
|
||||||
|
}
|
||||||
|
|
||||||
/* allocate a new nfm */
|
/* allocate a new nfm */
|
||||||
new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL);
|
new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL);
|
||||||
|
@ -678,7 +679,7 @@ nfsd_file_cache_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops,
|
nfsd_file_fsnotify_group = fsnotify_alloc_group(&nfsd_file_fsnotify_ops,
|
||||||
0);
|
FSNOTIFY_GROUP_NOFS);
|
||||||
if (IS_ERR(nfsd_file_fsnotify_group)) {
|
if (IS_ERR(nfsd_file_fsnotify_group)) {
|
||||||
pr_err("nfsd: unable to create fsnotify group: %ld\n",
|
pr_err("nfsd: unable to create fsnotify group: %ld\n",
|
||||||
PTR_ERR(nfsd_file_fsnotify_group));
|
PTR_ERR(nfsd_file_fsnotify_group));
|
||||||
|
|
Loading…
Add table
Reference in a new issue