Messages in this thread Patch in this message | | | From | "J. R. Okajima" <> | Subject | [RFC 2/2] hugetlbfs: implement f_op->{pre,post}_mmap() | Date | Thu, 3 Nov 2011 13:53:55 +0900 |
| |
To fix the AB-BA deadlock problem between mm->mmap_sem and inode->i_mutex.
Signed-off-by: J. R. Okajima <hooanon05@yahoo.co.jp> --- fs/hugetlbfs/inode.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 7aafeb8..f044d54 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -76,6 +76,21 @@ static void huge_pagevec_release(struct pagevec *pvec) pagevec_reinit(pvec); } +static int hugetlbfs_file_pre_mmap(struct file *file, unsigned long prot, + unsigned long flag) +{ + struct inode *inode = file->f_path.dentry->d_inode; + mutex_lock(&inode->i_mutex); + return 0; +} + +static void hugetlbfs_file_post_mmap(struct file *file, unsigned long prot, + unsigned long flag) +{ + struct inode *inode = file->f_path.dentry->d_inode; + mutex_unlock(&inode->i_mutex); +} + static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) { struct inode *inode = file->f_path.dentry->d_inode; @@ -99,7 +114,6 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) vma_len = (loff_t)(vma->vm_end - vma->vm_start); - mutex_lock(&inode->i_mutex); file_accessed(file); ret = -ENOMEM; @@ -116,8 +130,6 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) if (vma->vm_flags & VM_WRITE && inode->i_size < len) inode->i_size = len; out: - mutex_unlock(&inode->i_mutex); - return ret; } @@ -693,7 +705,9 @@ static void init_once(void *foo) const struct file_operations hugetlbfs_file_operations = { .read = hugetlbfs_read, + .pre_mmap = hugetlbfs_file_pre_mmap, .mmap = hugetlbfs_file_mmap, + .post_mmap = hugetlbfs_file_post_mmap, .fsync = noop_fsync, .get_unmapped_area = hugetlb_get_unmapped_area, .llseek = default_llseek, -- 1.7.2.5
| |