aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/tlb.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/kernel/tlb.c')
-rw-r--r--arch/um/kernel/tlb.c163
1 files changed, 87 insertions, 76 deletions
diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c
index 7d914bb6b002..80ed6188e8a2 100644
--- a/arch/um/kernel/tlb.c
+++ b/arch/um/kernel/tlb.c
@@ -16,115 +16,117 @@
16#include "os.h" 16#include "os.h"
17 17
18static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len, 18static int add_mmap(unsigned long virt, unsigned long phys, unsigned long len,
19 int r, int w, int x, struct host_vm_op *ops, int index, 19 int r, int w, int x, struct host_vm_op *ops, int *index,
20 int last_filled, union mm_context *mmu, void **flush, 20 int last_filled, union mm_context *mmu, void **flush,
21 void *(*do_ops)(union mm_context *, struct host_vm_op *, 21 int (*do_ops)(union mm_context *, struct host_vm_op *,
22 int, int, void *)) 22 int, int, void **))
23{ 23{
24 __u64 offset; 24 __u64 offset;
25 struct host_vm_op *last; 25 struct host_vm_op *last;
26 int fd; 26 int fd, ret = 0;
27 27
28 fd = phys_mapping(phys, &offset); 28 fd = phys_mapping(phys, &offset);
29 if(index != -1){ 29 if(*index != -1){
30 last = &ops[index]; 30 last = &ops[*index];
31 if((last->type == MMAP) && 31 if((last->type == MMAP) &&
32 (last->u.mmap.addr + last->u.mmap.len == virt) && 32 (last->u.mmap.addr + last->u.mmap.len == virt) &&
33 (last->u.mmap.r == r) && (last->u.mmap.w == w) && 33 (last->u.mmap.r == r) && (last->u.mmap.w == w) &&
34 (last->u.mmap.x == x) && (last->u.mmap.fd == fd) && 34 (last->u.mmap.x == x) && (last->u.mmap.fd == fd) &&
35 (last->u.mmap.offset + last->u.mmap.len == offset)){ 35 (last->u.mmap.offset + last->u.mmap.len == offset)){
36 last->u.mmap.len += len; 36 last->u.mmap.len += len;
37 return index; 37 return 0;
38 } 38 }
39 } 39 }
40 40
41 if(index == last_filled){ 41 if(*index == last_filled){
42 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 42 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
43 index = -1; 43 *index = -1;
44 } 44 }
45 45
46 ops[++index] = ((struct host_vm_op) { .type = MMAP, 46 ops[++*index] = ((struct host_vm_op) { .type = MMAP,
47 .u = { .mmap = { 47 .u = { .mmap = {
48 .addr = virt, 48 .addr = virt,
49 .len = len, 49 .len = len,
50 .r = r, 50 .r = r,
51 .w = w, 51 .w = w,
52 .x = x, 52 .x = x,
53 .fd = fd, 53 .fd = fd,
54 .offset = offset } 54 .offset = offset }
55 } }); 55 } });
56 return index; 56 return ret;
57} 57}
58 58
59static int add_munmap(unsigned long addr, unsigned long len, 59static int add_munmap(unsigned long addr, unsigned long len,
60 struct host_vm_op *ops, int index, int last_filled, 60 struct host_vm_op *ops, int *index, int last_filled,
61 union mm_context *mmu, void **flush, 61 union mm_context *mmu, void **flush,
62 void *(*do_ops)(union mm_context *, struct host_vm_op *, 62 int (*do_ops)(union mm_context *, struct host_vm_op *,
63 int, int, void *)) 63 int, int, void **))
64{ 64{
65 struct host_vm_op *last; 65 struct host_vm_op *last;
66 int ret = 0;
66 67
67 if(index != -1){ 68 if(*index != -1){
68 last = &ops[index]; 69 last = &ops[*index];
69 if((last->type == MUNMAP) && 70 if((last->type == MUNMAP) &&
70 (last->u.munmap.addr + last->u.mmap.len == addr)){ 71 (last->u.munmap.addr + last->u.mmap.len == addr)){
71 last->u.munmap.len += len; 72 last->u.munmap.len += len;
72 return index; 73 return 0;
73 } 74 }
74 } 75 }
75 76
76 if(index == last_filled){ 77 if(*index == last_filled){
77 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 78 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
78 index = -1; 79 *index = -1;
79 } 80 }
80 81
81 ops[++index] = ((struct host_vm_op) { .type = MUNMAP, 82 ops[++*index] = ((struct host_vm_op) { .type = MUNMAP,
82 .u = { .munmap = { 83 .u = { .munmap = {
83 .addr = addr, 84 .addr = addr,
84 .len = len } } }); 85 .len = len } } });
85 return index; 86 return ret;
86} 87}
87 88
88static int add_mprotect(unsigned long addr, unsigned long len, int r, int w, 89static int add_mprotect(unsigned long addr, unsigned long len, int r, int w,
89 int x, struct host_vm_op *ops, int index, 90 int x, struct host_vm_op *ops, int *index,
90 int last_filled, union mm_context *mmu, void **flush, 91 int last_filled, union mm_context *mmu, void **flush,
91 void *(*do_ops)(union mm_context *, 92 int (*do_ops)(union mm_context *, struct host_vm_op *,
92 struct host_vm_op *, int, int, void *)) 93 int, int, void **))
93{ 94{
94 struct host_vm_op *last; 95 struct host_vm_op *last;
96 int ret = 0;
95 97
96 if(index != -1){ 98 if(*index != -1){
97 last = &ops[index]; 99 last = &ops[*index];
98 if((last->type == MPROTECT) && 100 if((last->type == MPROTECT) &&
99 (last->u.mprotect.addr + last->u.mprotect.len == addr) && 101 (last->u.mprotect.addr + last->u.mprotect.len == addr) &&
100 (last->u.mprotect.r == r) && (last->u.mprotect.w == w) && 102 (last->u.mprotect.r == r) && (last->u.mprotect.w == w) &&
101 (last->u.mprotect.x == x)){ 103 (last->u.mprotect.x == x)){
102 last->u.mprotect.len += len; 104 last->u.mprotect.len += len;
103 return index; 105 return 0;
104 } 106 }
105 } 107 }
106 108
107 if(index == last_filled){ 109 if(*index == last_filled){
108 *flush = (*do_ops)(mmu, ops, last_filled, 0, *flush); 110 ret = (*do_ops)(mmu, ops, last_filled, 0, flush);
109 index = -1; 111 *index = -1;
110 } 112 }
111 113
112 ops[++index] = ((struct host_vm_op) { .type = MPROTECT, 114 ops[++*index] = ((struct host_vm_op) { .type = MPROTECT,
113 .u = { .mprotect = { 115 .u = { .mprotect = {
114 .addr = addr, 116 .addr = addr,
115 .len = len, 117 .len = len,
116 .r = r, 118 .r = r,
117 .w = w, 119 .w = w,
118 .x = x } } }); 120 .x = x } } });
119 return index; 121 return ret;
120} 122}
121 123
122#define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1)) 124#define ADD_ROUND(n, inc) (((n) + (inc)) & ~((inc) - 1))
123 125
124void fix_range_common(struct mm_struct *mm, unsigned long start_addr, 126void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
125 unsigned long end_addr, int force, 127 unsigned long end_addr, int force,
126 void *(*do_ops)(union mm_context *, struct host_vm_op *, 128 int (*do_ops)(union mm_context *, struct host_vm_op *,
127 int, int, void *)) 129 int, int, void **))
128{ 130{
129 pgd_t *npgd; 131 pgd_t *npgd;
130 pud_t *npud; 132 pud_t *npud;
@@ -136,20 +138,21 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
136 struct host_vm_op ops[1]; 138 struct host_vm_op ops[1];
137 void *flush = NULL; 139 void *flush = NULL;
138 int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1; 140 int op_index = -1, last_op = sizeof(ops) / sizeof(ops[0]) - 1;
141 int ret = 0;
139 142
140 if(mm == NULL) return; 143 if(mm == NULL) return;
141 144
142 ops[0].type = NONE; 145 ops[0].type = NONE;
143 for(addr = start_addr; addr < end_addr;){ 146 for(addr = start_addr; addr < end_addr && !ret;){
144 npgd = pgd_offset(mm, addr); 147 npgd = pgd_offset(mm, addr);
145 if(!pgd_present(*npgd)){ 148 if(!pgd_present(*npgd)){
146 end = ADD_ROUND(addr, PGDIR_SIZE); 149 end = ADD_ROUND(addr, PGDIR_SIZE);
147 if(end > end_addr) 150 if(end > end_addr)
148 end = end_addr; 151 end = end_addr;
149 if(force || pgd_newpage(*npgd)){ 152 if(force || pgd_newpage(*npgd)){
150 op_index = add_munmap(addr, end - addr, ops, 153 ret = add_munmap(addr, end - addr, ops,
151 op_index, last_op, mmu, 154 &op_index, last_op, mmu,
152 &flush, do_ops); 155 &flush, do_ops);
153 pgd_mkuptodate(*npgd); 156 pgd_mkuptodate(*npgd);
154 } 157 }
155 addr = end; 158 addr = end;
@@ -162,9 +165,9 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
162 if(end > end_addr) 165 if(end > end_addr)
163 end = end_addr; 166 end = end_addr;
164 if(force || pud_newpage(*npud)){ 167 if(force || pud_newpage(*npud)){
165 op_index = add_munmap(addr, end - addr, ops, 168 ret = add_munmap(addr, end - addr, ops,
166 op_index, last_op, mmu, 169 &op_index, last_op, mmu,
167 &flush, do_ops); 170 &flush, do_ops);
168 pud_mkuptodate(*npud); 171 pud_mkuptodate(*npud);
169 } 172 }
170 addr = end; 173 addr = end;
@@ -177,9 +180,9 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
177 if(end > end_addr) 180 if(end > end_addr)
178 end = end_addr; 181 end = end_addr;
179 if(force || pmd_newpage(*npmd)){ 182 if(force || pmd_newpage(*npmd)){
180 op_index = add_munmap(addr, end - addr, ops, 183 ret = add_munmap(addr, end - addr, ops,
181 op_index, last_op, mmu, 184 &op_index, last_op, mmu,
182 &flush, do_ops); 185 &flush, do_ops);
183 pmd_mkuptodate(*npmd); 186 pmd_mkuptodate(*npmd);
184 } 187 }
185 addr = end; 188 addr = end;
@@ -198,24 +201,32 @@ void fix_range_common(struct mm_struct *mm, unsigned long start_addr,
198 } 201 }
199 if(force || pte_newpage(*npte)){ 202 if(force || pte_newpage(*npte)){
200 if(pte_present(*npte)) 203 if(pte_present(*npte))
201 op_index = add_mmap(addr, 204 ret = add_mmap(addr,
202 pte_val(*npte) & PAGE_MASK, 205 pte_val(*npte) & PAGE_MASK,
203 PAGE_SIZE, r, w, x, ops, 206 PAGE_SIZE, r, w, x, ops,
204 op_index, last_op, mmu, 207 &op_index, last_op, mmu,
205 &flush, do_ops); 208 &flush, do_ops);
206 else op_index = add_munmap(addr, PAGE_SIZE, ops, 209 else ret = add_munmap(addr, PAGE_SIZE, ops,
207 op_index, last_op, mmu, 210 &op_index, last_op, mmu,
208 &flush, do_ops); 211 &flush, do_ops);
209 } 212 }
210 else if(pte_newprot(*npte)) 213 else if(pte_newprot(*npte))
211 op_index = add_mprotect(addr, PAGE_SIZE, r, w, x, ops, 214 ret = add_mprotect(addr, PAGE_SIZE, r, w, x, ops,
212 op_index, last_op, mmu, 215 &op_index, last_op, mmu,
213 &flush, do_ops); 216 &flush, do_ops);
214 217
215 *npte = pte_mkuptodate(*npte); 218 *npte = pte_mkuptodate(*npte);
216 addr += PAGE_SIZE; 219 addr += PAGE_SIZE;
217 } 220 }
218 flush = (*do_ops)(mmu, ops, op_index, 1, flush); 221
222 if(!ret)
223 ret = (*do_ops)(mmu, ops, op_index, 1, &flush);
224
225 /* This is not an else because ret is modified above */
226 if(ret) {
227 printk("fix_range_common: failed, killing current process\n");
228 force_sig(SIGKILL, current);
229 }
219} 230}
220 231
221int flush_tlb_kernel_range_common(unsigned long start, unsigned long end) 232int flush_tlb_kernel_range_common(unsigned long start, unsigned long end)