All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Matthew Bobrowski <repnop@google.com>, linux-fsdevel@vger.kernel.org
Subject: [PATCH v4 03/16] fsnotify: fix wrong lockdep annotations
Date: Fri, 22 Apr 2022 15:03:14 +0300	[thread overview]
Message-ID: <20220422120327.3459282-4-amir73il@gmail.com> (raw)
In-Reply-To: <20220422120327.3459282-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 4853184f7dde..c86982be2d50 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -452,7 +452,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);
@@ -770,7 +770,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);
@@ -779,7 +779,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.35.1


  parent reply	other threads:[~2022-04-22 12:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22 12:03 [PATCH v4 00/16] Evictable fanotify marks Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 01/16] inotify: show inotify mask flags in proc fdinfo Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 02/16] inotify: move control flags from mask to mark flags Amir Goldstein
2022-04-22 12:03 ` Amir Goldstein [this message]
2022-04-22 12:03 ` [PATCH v4 04/16] fsnotify: pass flags argument to fsnotify_alloc_group() Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 05/16] fsnotify: make allow_dups a property of the group Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 06/16] fsnotify: create helpers for group mark_mutex lock Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 07/16] inotify: use fsnotify group lock helpers Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 08/16] audit: " Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 09/16] nfsd: " Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 10/16] dnotify: " Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 11/16] fsnotify: allow adding an inode mark without pinning inode Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 12/16] fanotify: create helper fanotify_mark_user_flags() Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 13/16] fanotify: factor out helper fanotify_mark_update_flags() Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 14/16] fanotify: implement "evictable" inode marks Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 15/16] fanotify: use fsnotify group lock helpers Amir Goldstein
2022-04-22 12:03 ` [PATCH v4 16/16] fanotify: enable "evictable" inode marks Amir Goldstein
2022-04-25 12:59 ` [PATCH v4 00/16] Evictable fanotify marks Jan Kara
2022-04-25 13:32   ` 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=20220422120327.3459282-4-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=repnop@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.