diff options
Diffstat (limited to 'litmus/ctrldev.c')
-rw-r--r-- | litmus/ctrldev.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/litmus/ctrldev.c b/litmus/ctrldev.c index 6677a67cc945..9969ab17c190 100644 --- a/litmus/ctrldev.c +++ b/litmus/ctrldev.c | |||
@@ -30,27 +30,19 @@ static int alloc_ctrl_page(struct task_struct *t) | |||
30 | static int map_ctrl_page(struct task_struct *t, struct vm_area_struct* vma) | 30 | static int map_ctrl_page(struct task_struct *t, struct vm_area_struct* vma) |
31 | { | 31 | { |
32 | int err; | 32 | int err; |
33 | unsigned long pfn; | ||
34 | 33 | ||
35 | struct page* ctrl = virt_to_page(tsk_rt(t)->ctrl_page); | 34 | struct page* ctrl = virt_to_page(tsk_rt(t)->ctrl_page); |
36 | 35 | ||
37 | /* Increase ref count. Is decreased when vma is destroyed. */ | ||
38 | get_page(ctrl); | ||
39 | |||
40 | /* compute page frame number */ | ||
41 | pfn = page_to_pfn(ctrl); | ||
42 | |||
43 | TRACE_CUR(CTRL_NAME | 36 | TRACE_CUR(CTRL_NAME |
44 | ": mapping %p (pfn:%lx, %lx) to 0x%lx (prot:%lx)\n", | 37 | ": mapping %p (pfn:%lx) to 0x%lx (prot:%lx)\n", |
45 | tsk_rt(t)->ctrl_page, pfn, page_to_pfn(ctrl), vma->vm_start, | 38 | tsk_rt(t)->ctrl_page,page_to_pfn(ctrl), vma->vm_start, |
46 | vma->vm_page_prot); | 39 | vma->vm_page_prot); |
47 | 40 | ||
48 | /* Map it into the vma. Make sure to use PAGE_SHARED, otherwise | 41 | /* Map it into the vma. */ |
49 | * userspace actually gets a copy-on-write page. */ | 42 | err = vm_insert_page(vma, vma->vm_start, ctrl); |
50 | err = remap_pfn_range(vma, vma->vm_start, pfn, PAGE_SIZE, PAGE_SHARED); | ||
51 | 43 | ||
52 | if (err) | 44 | if (err) |
53 | TRACE_CUR(CTRL_NAME ": remap_pfn_range() failed (%d)\n", err); | 45 | TRACE_CUR(CTRL_NAME ": vm_insert_page() failed (%d)\n", err); |
54 | 46 | ||
55 | return err; | 47 | return err; |
56 | } | 48 | } |
@@ -63,19 +55,19 @@ static void litmus_ctrl_vm_close(struct vm_area_struct* vma) | |||
63 | TRACE_CUR(CTRL_NAME | 55 | TRACE_CUR(CTRL_NAME |
64 | ": %p:%p vma:%p vma->vm_private_data:%p closed.\n", | 56 | ": %p:%p vma:%p vma->vm_private_data:%p closed.\n", |
65 | (void*) vma->vm_start, (void*) vma->vm_end, vma, | 57 | (void*) vma->vm_start, (void*) vma->vm_end, vma, |
66 | vma->vm_private_data, current->comm, | 58 | vma->vm_private_data); |
67 | current->pid); | ||
68 | } | 59 | } |
69 | 60 | ||
70 | static int litmus_ctrl_vm_fault(struct vm_area_struct* vma, | 61 | static int litmus_ctrl_vm_fault(struct vm_area_struct* vma, |
71 | struct vm_fault* vmf) | 62 | struct vm_fault* vmf) |
72 | { | 63 | { |
73 | /* This function should never be called, since | 64 | TRACE_CUR("%s flags=0x%x (off:%ld)\n", __FUNCTION__, |
74 | * all pages should have been mapped by mmap() | 65 | vma->vm_flags, vmf->pgoff); |
75 | * already. */ | 66 | |
76 | TRACE_CUR("%s flags=0x%x\n", __FUNCTION__, vma->vm_flags); | 67 | /* This function should never be called, since all pages should have |
68 | * been mapped by mmap() already. */ | ||
69 | WARN_ONCE(1, "Page faults should be impossible in the control page\n"); | ||
77 | 70 | ||
78 | /* nope, you only get one page */ | ||
79 | return VM_FAULT_SIGBUS; | 71 | return VM_FAULT_SIGBUS; |
80 | } | 72 | } |
81 | 73 | ||
@@ -103,9 +95,16 @@ static int litmus_ctrl_mmap(struct file* filp, struct vm_area_struct* vma) | |||
103 | return -EINVAL; | 95 | return -EINVAL; |
104 | 96 | ||
105 | vma->vm_ops = &litmus_ctrl_vm_ops; | 97 | vma->vm_ops = &litmus_ctrl_vm_ops; |
106 | /* this mapping should not be kept across forks, | 98 | /* This mapping should not be kept across forks, |
107 | * and cannot be expanded */ | 99 | * cannot be expanded, and is not a "normal" page. */ |
108 | vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND; | 100 | vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND | VM_IO; |
101 | |||
102 | /* We don't want the first write access to trigger a "minor" page fault | ||
103 | * to mark the page as dirty. This is transient, private memory, we | ||
104 | * don't care if it was touched or not. __S011 means RW access, but not | ||
105 | * execute, and avoids copy-on-write behavior. | ||
106 | * See protection_map in mmap.c. */ | ||
107 | vma->vm_page_prot = __S011; | ||
109 | 108 | ||
110 | err = alloc_ctrl_page(current); | 109 | err = alloc_ctrl_page(current); |
111 | if (!err) | 110 | if (!err) |