Skip to contentSkip to conversation

vfs: Correctly set the dir i_mutex lockdep class

PATCH Superseded Tyler Hicks 3 participants 6 messages Nov 10, 2011 – Jan 20, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: Correctly set the dir i_mutex lockdep class

9a7aa12f3911853a introduced additional logic around setting the i_mutex lockdep class for directory inodes. The idea was that some filesystems may want their own special lockdep class for different directory inodes and calling unlock_new_inode() should not clobber one of those special classes.

I believe that the added conditional, around the *negated* return value of lockdep_match_class(), caused directory inodes to be placed in the wrong lockdep class.

inode_init_always() sets the i_mutex lockdep class with i_mutex_key for all inodes. If the filesystem did not change the class during inode initialization, then the conditional mentioned above was false and the directory inode was incorrectly left in the non-directory lockdep class. If the filesystem did set a special lockdep class, then the conditional mentioned above was true and that class was clobbered with i_mutex_dir_key.

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

---
 fs/inode.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/inode.c +1 -2
index ee4e66b..9d01a0d 100644
@@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
 		struct file_system_type *type = inode->i_sb->s_type;
 
 		/* Set new key only if filesystem hasn't already changed it */
-		if (!lockdep_match_class(&inode->i_mutex,
-		    &type->i_mutex_key)) {
+		if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
 			/*
 			 * ensure nobody is actually holding i_mutex
 			 */
Signature · 1 line
1.7.5.4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Tyler Hicks

9a7aa12f3911853a introduced additional logic around setting the i_mutex lockdep class for directory inodes. The idea was that some filesystems may want their own special lockdep class for different directory inodes and calling unlock_new_inode() should not clobber one of those special classes.

I believe that the added conditional, around the *negated* return value of lockdep_match_class(), caused directory inodes to be placed in the wrong lockdep class.

inode_init_always() sets the i_mutex lockdep class with i_mutex_key for all inodes. If the filesystem did not change the class during inode initialization, then the conditional mentioned above was false and the directory inode was incorrectly left in the non-directory lockdep class. If the filesystem did set a special lockdep class, then the conditional mentioned above was true and that class was clobbered with i_mutex_dir_key.

Quoted 4 lines

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

Duh, you are right. I wonder how come this did not trigger any lockdep
messages during my testing with ocfs2 for which I wrote the patch...

Anyway, thanks for catching this! You can add

Honza

Quoted 22 lines
---
 fs/inode.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/inode.c +1 -2
index ee4e66b..9d01a0d 100644
@@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
 		struct file_system_type *type = inode->i_sb->s_type;
 
 		/* Set new key only if filesystem hasn't already changed it */
-		if (!lockdep_match_class(&inode->i_mutex,
-		    &type->i_mutex_key)) {
+		if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
 			/*
 			 * ensure nobody is actually holding i_mutex
 			 */
Signature · 1 line
1.7.5.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 19 lines · Jan Kara
Quoted 18 lines · Tyler Hicks

9a7aa12f3911853a introduced additional logic around setting the i_mutex lockdep class for directory inodes. The idea was that some filesystems may want their own special lockdep class for different directory inodes and calling unlock_new_inode() should not clobber one of those special classes.

I believe that the added conditional, around the *negated* return value of lockdep_match_class(), caused directory inodes to be placed in the wrong lockdep class.

inode_init_always() sets the i_mutex lockdep class with i_mutex_key for all inodes. If the filesystem did not change the class during inode initialization, then the conditional mentioned above was false and the directory inode was incorrectly left in the non-directory lockdep class. If the filesystem did set a special lockdep class, then the conditional mentioned above was true and that class was clobbered with i_mutex_dir_key.

Quoted 6 lines
Quoted 4 lines

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

Duh, you are right. I wonder how come this did not trigger any lockdep
messages during my testing with ocfs2 for which I wrote the patch...

Good question. Adding the ocfs2 maintainers and devel list to cc, as this patch is likely to change up their lockdep warnings.

I expect this will also solve many of the lockdep issues around the order of i_mutex and mmap_sem being taken in files verse directories. That's why I stumbled across it.

Quoted 3 lines

Anyway, thanks for catching this! You can add

Thanks for the review!

Tyler

Quoted 27 lines

Honza

Quoted 22 lines
---
 fs/inode.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/inode.c +1 -2
index ee4e66b..9d01a0d 100644
@@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
 		struct file_system_type *type = inode->i_sb->s_type;
 
 		/* Set new key only if filesystem hasn't already changed it */
-		if (!lockdep_match_class(&inode->i_mutex,
-		    &type->i_mutex_key)) {
+		if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
 			/*
 			 * ensure nobody is actually holding i_mutex
 			 */
Signature · 1 line
1.7.5.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer
#3 lore raw
Quoted 11 lines · Tyler Hicks
Quoted 7 lines · Jan Kara
Quoted 4 lines · Tyler Hicks

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

Duh, you are right. I wonder how come this did not trigger any lockdep
messages during my testing with ocfs2 for which I wrote the patch...

Good question. Adding the ocfs2 maintainers and devel list to cc, as this patch is likely to change up their lockdep warnings.

	We don't set special classes for dir->i_mutex.  We set special

classes on our DLM stuff, and we do it for our system files, but not for regular directories.

Joel

Signature · 6 lines
Life's Little Instruction Book #356

	"Be there when people need you."

			http://www.jlbec.org/
			[email protected]
#4 lore raw

PATCH RESEND 1/1 vfs: Correctly set the dir i_mutex lockdep class

In reply to Tyler Hicks

9a7aa12f3911853a introduced additional logic around setting the i_mutex lockdep class for directory inodes. The idea was that some filesystems may want their own special lockdep class for different directory inodes and calling unlock_new_inode() should not clobber one of those special classes.

I believe that the added conditional, around the *negated* return value of lockdep_match_class(), caused directory inodes to be placed in the wrong lockdep class.

inode_init_always() sets the i_mutex lockdep class with i_mutex_key for all inodes. If the filesystem did not change the class during inode initialization, then the conditional mentioned above was false and the directory inode was incorrectly left in the non-directory lockdep class. If the filesystem did set a special lockdep class, then the conditional mentioned above was true and that class was clobbered with i_mutex_dir_key.

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

---

Hi Al - I thought I'd resend this fix after seeing Mimi's RFC for more filesystems to use lockdep_annotate_inode_mutex_key(). Currently, that function doesn't do what it is supposed to do.

 fs/inode.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/inode.c +1 -2
index ee4e66b..9d01a0d 100644
@@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
 		struct file_system_type *type = inode->i_sb->s_type;
 
 		/* Set new key only if filesystem hasn't already changed it */
-		if (!lockdep_match_class(&inode->i_mutex,
-		    &type->i_mutex_key)) {
+		if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
 			/*
 			 * ensure nobody is actually holding i_mutex
 			 */
Signature · 1 line
1.7.5.4
#5 lore raw
Quoted 23 lines · Tyler Hicks

9a7aa12f3911853a introduced additional logic around setting the i_mutex lockdep class for directory inodes. The idea was that some filesystems may want their own special lockdep class for different directory inodes and calling unlock_new_inode() should not clobber one of those special classes.

I believe that the added conditional, around the *negated* return value of lockdep_match_class(), caused directory inodes to be placed in the wrong lockdep class.

inode_init_always() sets the i_mutex lockdep class with i_mutex_key for all inodes. If the filesystem did not change the class during inode initialization, then the conditional mentioned above was false and the directory inode was incorrectly left in the non-directory lockdep class. If the filesystem did set a special lockdep class, then the conditional mentioned above was true and that class was clobbered with i_mutex_dir_key.

This patch removes the negation from the conditional so that the i_mutex lockdep class is properly set for directory inodes. Special classes are preserved and directory inodes with unmodified classes are set with i_mutex_dir_key.

Quoted 7 lines

---

Hi Al - I thought I'd resend this fix after seeing Mimi's RFC for more filesystems to use lockdep_annotate_inode_mutex_key(). Currently, that function doesn't do what it is supposed to do.

Hi Al - Just following up again to see if I can get any comments on this bug fix in hopes of getting it picked up soon.

Searching back through list archives, I realize there have been debates about the locking order of i_mutex vs mmap_sem among directory and regular inodes, which I imagine is the reason for this bit of code. But either way, the lock class setting of directory inodes is broken here.

Adding hch and akpm to cc for extra eyes/comments.

Tyler

Quoted 25 lines
 fs/inode.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/inode.c +1 -2
index ee4e66b..9d01a0d 100644
@@ -855,8 +855,7 @@ void lockdep_annotate_inode_mutex_key(struct inode *inode)
 		struct file_system_type *type = inode->i_sb->s_type;
 
 		/* Set new key only if filesystem hasn't already changed it */
-		if (!lockdep_match_class(&inode->i_mutex,
-		    &type->i_mutex_key)) {
+		if (lockdep_match_class(&inode->i_mutex, &type->i_mutex_key)) {
 			/*
 			 * ensure nobody is actually holding i_mutex
 			 */
Signature · 6 lines
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html