aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Piggin <npiggin@suse.de>2008-08-20 17:09:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-08-20 18:40:32 -0400
commit14bac5acfdb6a40be64acc042c6db73f1a68f6a4 (patch)
tree5148a0440674ef618a5af4e1b549794db9f783c1
parent538f8ea6c85232d00bfa5edd9ba85f16c01057c9 (diff)
mm: xip/ext2 fix block allocation race
XIP can call into get_xip_mem concurrently with the same file,offset with create=1. This usually maps down to get_block, which expects the page lock to prevent such a situation. This causes ext2 to explode for one reason or another. Serialise those calls for the moment. For common usages today, I suspect get_xip_mem rarely is called to create new blocks. In future as XIP technologies evolve we might need to look at which operations require scalability, and rework the locking to suit. Signed-off-by: Nick Piggin <npiggin@suse.de> Cc: Jared Hulbert <jaredeh@gmail.com> Acked-by: Carsten Otte <cotte@freenet.de> Cc: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/filemap_xip.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index 5b9ec47ea25a..b5167dfb2f2d 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -248,15 +248,16 @@ again:
248 int err; 248 int err;
249 249
250 /* maybe shared writable, allocate new block */ 250 /* maybe shared writable, allocate new block */
251 mutex_lock(&xip_sparse_mutex);
251 error = mapping->a_ops->get_xip_mem(mapping, vmf->pgoff, 1, 252 error = mapping->a_ops->get_xip_mem(mapping, vmf->pgoff, 1,
252 &xip_mem, &xip_pfn); 253 &xip_mem, &xip_pfn);
254 mutex_unlock(&xip_sparse_mutex);
253 if (error) 255 if (error)
254 return VM_FAULT_SIGBUS; 256 return VM_FAULT_SIGBUS;
255 /* unmap sparse mappings at pgoff from all other vmas */ 257 /* unmap sparse mappings at pgoff from all other vmas */
256 __xip_unmap(mapping, vmf->pgoff); 258 __xip_unmap(mapping, vmf->pgoff);
257 259
258found: 260found:
259 printk("%s insert %lx@%lx\n", current->comm, (unsigned long)vmf->virtual_address, xip_pfn);
260 err = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, 261 err = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,
261 xip_pfn); 262 xip_pfn);
262 if (err == -ENOMEM) 263 if (err == -ENOMEM)
@@ -340,8 +341,10 @@ __xip_file_write(struct file *filp, const char __user *buf,
340 &xip_mem, &xip_pfn); 341 &xip_mem, &xip_pfn);
341 if (status == -ENODATA) { 342 if (status == -ENODATA) {
342 /* we allocate a new page unmap it */ 343 /* we allocate a new page unmap it */
344 mutex_lock(&xip_sparse_mutex);
343 status = a_ops->get_xip_mem(mapping, index, 1, 345 status = a_ops->get_xip_mem(mapping, index, 1,
344 &xip_mem, &xip_pfn); 346 &xip_mem, &xip_pfn);
347 mutex_unlock(&xip_sparse_mutex);
345 if (!status) 348 if (!status)
346 /* unmap page at pgoff from all other vmas */ 349 /* unmap page at pgoff from all other vmas */
347 __xip_unmap(mapping, index); 350 __xip_unmap(mapping, index);