Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=14358e6ddaed27499d7d366b3e65c3e46b39e1c4
Commit:     14358e6ddaed27499d7d366b3e65c3e46b39e1c4
Parent:     d475fd428ce77aa2a8bc650d230e17663a4f49c3
Author:     Peter Zijlstra <[EMAIL PROTECTED]>
AuthorDate: Sun Oct 14 01:38:33 2007 +0200
Committer:  Peter Zijlstra <[EMAIL PROTECTED]>
CommitDate: Sun Oct 14 01:38:33 2007 +0200

    lockdep: annotate dir vs file i_mutex
    
    On Mon, 2007-09-24 at 22:13 -0400, Steven Rostedt wrote:
    > The circular lock seems to be this:
    >
    > #1:
    >
    >   sys_mmap2:              down_write(&mm->mmap_sem);
    >   nfs_revalidate_mapping: mutex_lock(&inode->i_mutex);
    >
    >
    > #0:
    >
    >   vfs_readdir:     mutex_lock(&inode->i_mutex);
    >    - during the readdir (filldir64), we take a user fault (missing page?)
    >     and call do_page_fault -
    >   do_page_fault:   down_read(&mm->mmap_sem);
    >
    >
    > So it does indeed look like a circular locking. Now the question is, "is
    > this a bug?".  Looking like the inode of #1 must be a file or something
    > else that you can mmap and the inode of #0 seems it must be a directory.
    > I would say "no".
    >
    > Now if you can readdir on a file or mmap a directory, then this could be
    > an issue.
    >
    > Otherwise, I'd love to see someone teach lockdep about this issue! ;-)
    
    Make a distinction between file and dir usage of i_mutex.
    The inode should be complete and unused at unlock_new_inode(), re-init
    i_mutex depending on its type.
    
    Signed-off-by: Peter Zijlstra <[EMAIL PROTECTED]>
---
 fs/inode.c         |   12 ++++++++++++
 include/linux/fs.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index bf6adf1..f97de0a 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -567,6 +567,18 @@ EXPORT_SYMBOL(new_inode);
 
 void unlock_new_inode(struct inode *inode)
 {
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+       struct file_system_type *type = inode->i_sb->s_type;
+       /*
+        * ensure nobody is actually holding i_mutex
+        */
+       mutex_destroy(&inode->i_mutex);
+       mutex_init(&inode->i_mutex);
+       if (inode->i_mode & S_IFDIR)
+               lockdep_set_class(&inode->i_mutex, &type->i_mutex_dir_key);
+       else
+               lockdep_set_class(&inode->i_mutex, &type->i_mutex_key);
+#endif
        /*
         * This is special!  We do not need the spinlock
         * when clearing I_LOCK, because we're guaranteed
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0cad20e..6d760f1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1308,6 +1308,7 @@ struct file_system_type {
 
        struct lock_class_key i_lock_key;
        struct lock_class_key i_mutex_key;
+       struct lock_class_key i_mutex_dir_key;
        struct lock_class_key i_alloc_sem_key;
 };
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to