lkml.org 
[lkml]   [2011]   [Nov]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC 2/2] hugetlbfs: implement f_op->{pre,post}_mmap()
Date
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


\
 
 \ /
  Last update: 2011-11-03 06:05    [W:0.136 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site