Fixed a deadlock, and disabled distributed actions in the fault handler (except for...
authorDavid Katz <dgk8293@vt.edu>
Fri, 30 May 2014 23:10:08 +0000 (19:10 -0400)
committerDavid Katz <dgk8293@vt.edu>
Fri, 30 May 2014 23:10:08 +0000 (19:10 -0400)
arch/x86/mm/fault.c
include/linux/process_server.h
mm/mmap.c
mm/mremap.c

index 97fff65..5689762 100644 (file)
@@ -1002,6 +1002,8 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
        int write = error_code & PF_WRITE;
        unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
                                        (write ? FAULT_FLAG_WRITE : 0);
+    int original_enable_do_mmap_pgoff_hook = current->enable_do_mmap_pgoff_hook;
+    int original_enable_distributed_munmap = current->enable_distributed_munmap;
 
        tsk = current;
        mm = tsk->mm;
@@ -1110,6 +1112,9 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
         goto ret;
     }
 
+    current->enable_do_mmap_pgoff_hook = 0;
+    current->enable_distributed_munmap = 0;
+
        /*
         * When running in the kernel we expect faults to occur only to
         * addresses in user space.  All other faults represent errors in
@@ -1216,6 +1221,9 @@ good_area:
        up_read(&mm->mmap_sem);
 
 ret:
+    current->enable_do_mmap_pgoff_hook = original_enable_do_mmap_pgoff_hook;
+    current->enable_distributed_munmap = original_enable_distributed_munmap;
+
 #ifdef PROCESS_SERVER_USE_HEAVY_LOCK
     process_server_release_heavy_lock();
 #else
index 0589f4c..578029b 100644 (file)
@@ -29,8 +29,8 @@
 #define PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
 //#undef PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
 
-//#define PROCESS_SERVER_USE_HEAVY_LOCK
-#undef PROCESS_SERVER_USE_HEAVY_LOCK
+#define PROCESS_SERVER_USE_HEAVY_LOCK
+//#undef PROCESS_SERVER_USE_HEAVY_LOCK
 
 /*
  * Migration hook.
index 908c989..f20f526 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -994,11 +994,13 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
             struct vm_area_struct* vma_out = NULL;
             addr = get_unmapped_area(file, NULL, len, pgoff, flags);
 #ifdef PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
+            up_write(&mm->mmap_sem);
 #ifdef PROCESS_SERVER_USE_HEAVY_LOCK
             process_server_acquire_heavy_lock();
 #else
             process_server_acquire_page_lock_range(addr,len);
 #endif
+            down_write(&mm->mmap_sem);
 #endif
             fault_ret = process_server_pull_remote_mappings(mm,
                                                             NULL,
@@ -1037,11 +1039,13 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 
 #ifdef PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
     if(current->enable_do_mmap_pgoff_hook && !range_locked) {
+        up_write(&mm->mmap_sem);
 #ifdef PROCESS_SERVER_USE_HEAVY_LOCK
         process_server_acquire_heavy_lock();
 #else
         process_server_acquire_page_lock_range(addr,len);
 #endif
+        down_write(&mm->mmap_sem);
     }
 #endif
 
@@ -2150,28 +2154,33 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
        if ((len = PAGE_ALIGN(len)) == 0)
                return -EINVAL;
 
-
-       /* Find the first overlapping VMA */
-       vma = find_vma(mm, start);
-       if (!vma)
-               return 0;
-       prev = vma->vm_prev;
-       /* we have  start < vma->vm_end  */
-
-       /* if it doesn't overlap, we have nothing.. */
-       end = start + len;
-       if (vma->vm_start >= end)
-               return 0;
-
 #ifdef PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
     if(current->enable_distributed_munmap) {
+        up_write(&mm->mmap_sem);
 #ifdef PROCESS_SERVER_USE_HEAVY_LOCK
         process_server_acquire_heavy_lock();
 #else
         process_server_acquire_page_lock_range(start,len);
 #endif
+        down_write(&mm->mmap_sem);
     }
 #endif
+
+       /* Find the first overlapping VMA */
+       vma = find_vma(mm, start);
+       if (!vma) {
+        error = 0;
+        goto err;
+    }
+       prev = vma->vm_prev;
+       /* we have  start < vma->vm_end  */
+
+       /* if it doesn't overlap, we have nothing.. */
+       end = start + len;
+       if (vma->vm_start >= end) {
+               error = 0;
+        goto err;
+    }
        
     /*
         * If we need to split any vma, do it now to save pain later.
index 079e971..a729a27 100644 (file)
@@ -443,6 +443,7 @@ unsigned long do_mremap(unsigned long addr,
     // remaps, it is naughty, and just does a distributed
     // munmap (except locally).  That should probably change.
 #ifdef PROCESS_SERVER_ENFORCE_VMA_MOD_ATOMICITY
+    up_write(&mm->mmap_sem);
 #ifdef PROCESS_SERVER_USE_HEAVY_LOCK
     process_server_acquire_heavy_lock();
 #else 
@@ -461,6 +462,7 @@ unsigned long do_mremap(unsigned long addr,
     }
     }
 #endif
+    down_write(&mm->mmap_sem);
 #endif
 
     // Pull in all remote mappings so nothing is lost later.