lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20220721060246.1696852-8-harshadshirwadkar@gmail.com>
Date:   Thu, 21 Jul 2022 06:02:45 +0000
From:   Harshad Shirwadkar <harshadshirwadkar@...il.com>
To:     linux-ext4@...r.kernel.org
Cc:     tytso@....edu, Harshad Shirwadkar <harshadshirwadkar@...il.com>
Subject: [RFC PATCH v4 7/8] ext4: add lockdep annotation in fc commit path

This patch adds lockdep annotation in fast commit commit path.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@...il.com>
---
 fs/ext4/ext4.h        |  9 +++++++++
 fs/ext4/fast_commit.c | 12 ++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 51ed372faff0..eabf0c9a3765 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1070,6 +1070,15 @@ struct ext4_inode_info {
 	 */
 	spinlock_t i_fc_lock;
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+	/*
+	 * Lockdep entity to track fast commit waiting dependencies. Any caller
+	 * who sets / resets EXT4_STATE_FC_COMMITTING flag should let lockdep
+	 * know that they are doing so by locking / unlocking fc_commit_map.
+	 */
+	struct lockdep_map	i_fc_commit_map;
+	struct lock_class_key	i_fc_commit_key;
+#endif
 	/*
 	 * i_disksize keeps track of what the inode size is ON DISK, not
 	 * in memory.  During truncate, i_size is set to the new size by
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index a9cac460de26..727a87073e6a 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -201,6 +201,8 @@ void ext4_fc_init_inode(struct inode *inode)
 	INIT_LIST_HEAD(&ei->i_fc_list);
 	INIT_LIST_HEAD(&ei->i_fc_dilist);
 	init_waitqueue_head(&ei->i_fc_wait);
+	lockdep_init_map(&ei->i_fc_commit_map, "i_fc_commit",
+			 &ei->i_fc_commit_key, 0);
 }
 
 /*
@@ -1061,6 +1063,7 @@ static int ext4_fc_perform_commit(journal_t *journal)
 	list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) {
 		ext4_set_inode_state(&iter->vfs_inode,
 				     EXT4_STATE_FC_COMMITTING);
+		mutex_acquire(&iter->i_fc_commit_map, 0, 0, _THIS_IP_);
 	}
 	spin_unlock(&sbi->s_fc_lock);
 	jbd2_journal_unlock_updates(journal);
@@ -1119,6 +1122,7 @@ static int ext4_fc_perform_commit(journal_t *journal)
 	}
 	list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) {
 		ext4_clear_inode_state(inode, EXT4_STATE_FC_COMMITTING);
+		mutex_release(&iter->i_fc_commit_map, _THIS_IP_);
 		/*
 		 * Make sure clearing of EXT4_STATE_FC_COMMITTING is
 		 * visible before we send the wakeup. Pairs with implicit
@@ -1266,8 +1270,12 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
 	spin_lock(&sbi->s_fc_lock);
 	list_for_each_entry_safe(iter, iter_n, &sbi->s_fc_q[FC_Q_MAIN],
 				 i_fc_list) {
-		ext4_clear_inode_state(&iter->vfs_inode,
-				       EXT4_STATE_FC_COMMITTING);
+		if (ext4_test_inode_state(&iter->vfs_inode,
+						EXT4_STATE_FC_COMMITTING)) {
+			ext4_clear_inode_state(&iter->vfs_inode,
+					       EXT4_STATE_FC_COMMITTING);
+			mutex_release(&iter->i_fc_commit_map, _THIS_IP_);
+		}
 		if (iter->i_sync_tid <= tid)
 			ext4_fc_reset_inode(&iter->vfs_inode);
 		/*
-- 
2.37.0.170.g444d1eabd0-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ