From: Marco Stornelli <marco.stornelli@gmail.com>
To: Linux FS Devel <linux-fsdevel@vger.kernel.org>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH, RFC] xip: use i_mutex for xip_file_fault
Date: Sat, 10 Sep 2011 17:31:39 +0200 [thread overview]
Message-ID: <4E6B82DB.50803@gmail.com> (raw)
From: Marco Stornelli <marco.stornelli@gmail.com>
There aren't sufficient sync points for a fs for xip operations. In
particular for the mmap case. It can be not sufficient to lock/unlock
to do some operation inside get_xip_mem callback. For xip_file_read
it's really easy to write a fs specific wrapper, xip_file_write hold
i_mutex so no problem. With this patch we can avoid concurrent truncate
operation and xip mmap.
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
---
--- filemap_xip.c.orig 2011-09-10 17:16:56.000000000 +0200
+++ filemap_xip.c 2011-09-10 17:19:25.000000000 +0200
@@ -230,6 +230,7 @@ static int xip_file_fault(struct vm_area
int error;
/* XXX: are VM_FAULT_ codes OK? */
+ mutex_lock(&inode->i_mutex);
again:
size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
if (vmf->pgoff >= size)
@@ -239,8 +240,10 @@ again:
&xip_mem, &xip_pfn);
if (likely(!error))
goto found;
- if (error != -ENODATA)
+ if (error != -ENODATA) {
+ mutex_unlock(&inode->i_mutex);
return VM_FAULT_OOM;
+ }
/* sparse block */
if ((vma->vm_flags & (VM_WRITE | VM_MAYWRITE)) &&
@@ -253,17 +256,22 @@ again:
error = mapping->a_ops->get_xip_mem(mapping, vmf->pgoff, 1,
&xip_mem, &xip_pfn);
mutex_unlock(&xip_sparse_mutex);
- if (error)
+ if (error) {
+ mutex_unlock(&inode->i_mutex);
return VM_FAULT_SIGBUS;
+ }
/* unmap sparse mappings at pgoff from all other vmas */
__xip_unmap(mapping, vmf->pgoff);
found:
err = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,
xip_pfn);
- if (err == -ENOMEM)
+ if (err == -ENOMEM) {
+ mutex_unlock(&inode->i_mutex);
return VM_FAULT_OOM;
+ }
BUG_ON(err);
+ mutex_unlock(&inode->i_mutex);
return VM_FAULT_NOPAGE;
} else {
int err, ret = VM_FAULT_OOM;
@@ -292,6 +300,7 @@ found:
out:
write_seqcount_end(&xip_sparse_seq);
mutex_unlock(&xip_sparse_mutex);
+ mutex_unlock(&inode->i_mutex);
return ret;
}
next reply other threads:[~2011-09-10 15:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-10 15:31 Marco Stornelli [this message]
2011-09-10 15:56 ` [PATCH, RFC] xip: use i_mutex for xip_file_fault Al Viro
2011-09-11 8:25 ` Marco Stornelli
2011-09-11 11:15 ` Al Viro
2011-09-11 11:25 ` Al Viro
2011-09-11 15:57 ` Marco Stornelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E6B82DB.50803@gmail.com \
--to=marco.stornelli@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.