提交 ac10cf20 编写于 作者: A Amir Goldstein 提交者: Zheng Zengkai

fsnotify: fix wrong lockdep annotations

stable inclusion
from stable-v5.10.121
commit f929416d5c9c9908659cde74a3e29e84c8ffe418
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5L6CQ

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=f929416d5c9c9908659cde74a3e29e84c8ffe418

--------------------------------

[ Upstream commit 623af4f5 ]

Commit 6960b0d9 ("fsnotify: change locking order") changed some
of the mark_mutex locks in direct reclaim path to use:
  mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);

This change is explained:
 "...It uses nested locking to avoid deadlock in case we do the final
  iput() on an inode which still holds marks and thus would take the
  mutex again when calling fsnotify_inode_delete() in destroy_inode()."

The problem is that the mutex_lock_nested() is not a nested lock at
all. In fact, it has the opposite effect of preventing lockdep from
warning about a very possible deadlock.

Due to these wrong annotations, a deadlock that was introduced with
nfsd filecache in kernel v5.4 went unnoticed in v5.4.y for over two
years until it was reported recently by Khazhismel Kumykov, only to
find out that the deadlock was already fixed in kernel v5.5.

Fix the wrong lockdep annotations.

Cc: Khazhismel Kumykov <khazhy@google.com>
Fixes: 6960b0d9 ("fsnotify: change locking order")
Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/
Link: https://lore.kernel.org/r/20220422120327.3459282-4-amir73il@gmail.comSigned-off-by: NAmir Goldstein <amir73il@gmail.com>
Signed-off-by: NJan Kara <jack@suse.cz>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 51097828
...@@ -430,7 +430,7 @@ void fsnotify_free_mark(struct fsnotify_mark *mark) ...@@ -430,7 +430,7 @@ void fsnotify_free_mark(struct fsnotify_mark *mark)
void fsnotify_destroy_mark(struct fsnotify_mark *mark, void fsnotify_destroy_mark(struct fsnotify_mark *mark,
struct fsnotify_group *group) struct fsnotify_group *group)
{ {
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); mutex_lock(&group->mark_mutex);
fsnotify_detach_mark(mark); fsnotify_detach_mark(mark);
mutex_unlock(&group->mark_mutex); mutex_unlock(&group->mark_mutex);
fsnotify_free_mark(mark); fsnotify_free_mark(mark);
...@@ -742,7 +742,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, ...@@ -742,7 +742,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
* move marks to free to to_free list in one go and then free marks in * move marks to free to to_free list in one go and then free marks in
* to_free list one by one. * to_free list one by one.
*/ */
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); mutex_lock(&group->mark_mutex);
list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) {
if ((1U << mark->connector->type) & type_mask) if ((1U << mark->connector->type) & type_mask)
list_move(&mark->g_list, &to_free); list_move(&mark->g_list, &to_free);
...@@ -751,7 +751,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, ...@@ -751,7 +751,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
clear: clear:
while (1) { while (1) {
mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); mutex_lock(&group->mark_mutex);
if (list_empty(head)) { if (list_empty(head)) {
mutex_unlock(&group->mark_mutex); mutex_unlock(&group->mark_mutex);
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册