From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Matthew Bobrowski <mbobrowski@mbobrowski.org>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 05/16] fsnotify: fix wrong lockdep annotations
Date: Tue, 29 Mar 2022 10:48:53 +0300 [thread overview]
Message-ID: <20220329074904.2980320-6-amir73il@gmail.com> (raw)
In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com>
Commit 6960b0d909cd ("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: 6960b0d909cd ("fsnotify: change locking order")
Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/notify/mark.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 698ed0a1a47e..3faf47def7d8 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -437,7 +437,7 @@ void fsnotify_free_mark(struct fsnotify_mark *mark)
void fsnotify_destroy_mark(struct fsnotify_mark *mark,
struct fsnotify_group *group)
{
- mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
+ mutex_lock(&group->mark_mutex);
fsnotify_detach_mark(mark);
mutex_unlock(&group->mark_mutex);
fsnotify_free_mark(mark);
@@ -754,7 +754,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
* 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) {
if (mark->connector->type == obj_type)
list_move(&mark->g_list, &to_free);
@@ -763,7 +763,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,
clear:
while (1) {
- mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING);
+ mutex_lock(&group->mark_mutex);
if (list_empty(head)) {
mutex_unlock(&group->mark_mutex);
break;
--
2.25.1
next prev parent reply other threads:[~2022-03-29 7:49 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-29 7:48 [PATCH v2 00/16] Evictable fanotify marks Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 01/16] inotify: show inotify mask flags in proc fdinfo Amir Goldstein
2022-04-05 12:40 ` Jan Kara
2022-04-05 12:43 ` Jan Kara
2022-03-29 7:48 ` [PATCH v2 02/16] inotify: move control flags from mask to mark flags Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 03/16] fsnotify: pass flags argument to fsnotify_add_mark() via mark Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 04/16] fsnotify: remove unneeded refcounts of s_fsnotify_connectors Amir Goldstein
2022-04-05 12:54 ` Jan Kara
2022-04-05 13:09 ` Amir Goldstein
2022-04-06 17:47 ` Jan Kara
2022-04-06 18:19 ` Amir Goldstein
2022-03-29 7:48 ` Amir Goldstein [this message]
2022-03-29 7:48 ` [PATCH v2 06/16] fsnotify: create helpers for group mark_mutex lock Amir Goldstein
2022-04-07 14:35 ` Jan Kara
2022-04-07 14:53 ` Amir Goldstein
2022-04-08 8:38 ` Amir Goldstein
2022-04-11 10:31 ` Jan Kara
2022-03-29 7:48 ` [PATCH v2 07/16] inotify: use fsnotify group lock helpers Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 08/16] audit: " Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 09/16] nfsd: " Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 10/16] dnotify: " Amir Goldstein
2022-03-29 7:48 ` [PATCH v2 11/16] fsnotify: allow adding an inode mark without pinning inode Amir Goldstein
2022-03-29 7:49 ` [PATCH v2 12/16] fanotify: factor out helper fanotify_mark_update_flags() Amir Goldstein
2022-04-11 10:52 ` Jan Kara
2022-04-11 12:00 ` Amir Goldstein
2022-03-29 7:49 ` [PATCH v2 13/16] fanotify: implement "evictable" inode marks Amir Goldstein
2022-04-11 11:47 ` Jan Kara
2022-04-11 12:57 ` Amir Goldstein
2022-04-11 14:19 ` Jan Kara
2022-04-12 8:07 ` Amir Goldstein
2022-03-29 7:49 ` [PATCH v2 14/16] fanotify: add FAN_IOC_SET_MARK_PAGE_ORDER ioctl for testing Amir Goldstein
2022-04-11 12:53 ` Jan Kara
2022-04-11 13:07 ` Amir Goldstein
2022-03-29 7:49 ` [PATCH v2 15/16] fanotify: use fsnotify group lock helpers Amir Goldstein
2022-03-29 7:49 ` [PATCH v2 16/16] fanotify: enable "evictable" inode marks Amir Goldstein
2022-04-09 16:12 ` [PATCH v2 00/16] Evictable fanotify marks Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220329074904.2980320-6-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mbobrowski@mbobrowski.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).