diff options
Diffstat (limited to 'drivers/lguest/page_tables.c')
-rw-r--r-- | drivers/lguest/page_tables.c | 115 |
1 files changed, 58 insertions, 57 deletions
diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c index c9acafcab2aa..983e9020cef8 100644 --- a/drivers/lguest/page_tables.c +++ b/drivers/lguest/page_tables.c | |||
@@ -68,17 +68,17 @@ static DEFINE_PER_CPU(pte_t *, switcher_pte_pages); | |||
68 | * page directory entry (PGD) for that address. Since we keep track of several | 68 | * page directory entry (PGD) for that address. Since we keep track of several |
69 | * page tables, the "i" argument tells us which one we're interested in (it's | 69 | * page tables, the "i" argument tells us which one we're interested in (it's |
70 | * usually the current one). */ | 70 | * usually the current one). */ |
71 | static pgd_t *spgd_addr(struct lguest *lg, u32 i, unsigned long vaddr) | 71 | static pgd_t *spgd_addr(struct lg_cpu *cpu, u32 i, unsigned long vaddr) |
72 | { | 72 | { |
73 | unsigned int index = pgd_index(vaddr); | 73 | unsigned int index = pgd_index(vaddr); |
74 | 74 | ||
75 | /* We kill any Guest trying to touch the Switcher addresses. */ | 75 | /* We kill any Guest trying to touch the Switcher addresses. */ |
76 | if (index >= SWITCHER_PGD_INDEX) { | 76 | if (index >= SWITCHER_PGD_INDEX) { |
77 | kill_guest(lg, "attempt to access switcher pages"); | 77 | kill_guest(cpu, "attempt to access switcher pages"); |
78 | index = 0; | 78 | index = 0; |
79 | } | 79 | } |
80 | /* Return a pointer index'th pgd entry for the i'th page table. */ | 80 | /* Return a pointer index'th pgd entry for the i'th page table. */ |
81 | return &lg->pgdirs[i].pgdir[index]; | 81 | return &cpu->lg->pgdirs[i].pgdir[index]; |
82 | } | 82 | } |
83 | 83 | ||
84 | /* This routine then takes the page directory entry returned above, which | 84 | /* This routine then takes the page directory entry returned above, which |
@@ -137,7 +137,7 @@ static unsigned long get_pfn(unsigned long virtpfn, int write) | |||
137 | * entry can be a little tricky. The flags are (almost) the same, but the | 137 | * entry can be a little tricky. The flags are (almost) the same, but the |
138 | * Guest PTE contains a virtual page number: the CPU needs the real page | 138 | * Guest PTE contains a virtual page number: the CPU needs the real page |
139 | * number. */ | 139 | * number. */ |
140 | static pte_t gpte_to_spte(struct lguest *lg, pte_t gpte, int write) | 140 | static pte_t gpte_to_spte(struct lg_cpu *cpu, pte_t gpte, int write) |
141 | { | 141 | { |
142 | unsigned long pfn, base, flags; | 142 | unsigned long pfn, base, flags; |
143 | 143 | ||
@@ -148,7 +148,7 @@ static pte_t gpte_to_spte(struct lguest *lg, pte_t gpte, int write) | |||
148 | flags = (pte_flags(gpte) & ~_PAGE_GLOBAL); | 148 | flags = (pte_flags(gpte) & ~_PAGE_GLOBAL); |
149 | 149 | ||
150 | /* The Guest's pages are offset inside the Launcher. */ | 150 | /* The Guest's pages are offset inside the Launcher. */ |
151 | base = (unsigned long)lg->mem_base / PAGE_SIZE; | 151 | base = (unsigned long)cpu->lg->mem_base / PAGE_SIZE; |
152 | 152 | ||
153 | /* We need a temporary "unsigned long" variable to hold the answer from | 153 | /* We need a temporary "unsigned long" variable to hold the answer from |
154 | * get_pfn(), because it returns 0xFFFFFFFF on failure, which wouldn't | 154 | * get_pfn(), because it returns 0xFFFFFFFF on failure, which wouldn't |
@@ -156,7 +156,7 @@ static pte_t gpte_to_spte(struct lguest *lg, pte_t gpte, int write) | |||
156 | * page, given the virtual number. */ | 156 | * page, given the virtual number. */ |
157 | pfn = get_pfn(base + pte_pfn(gpte), write); | 157 | pfn = get_pfn(base + pte_pfn(gpte), write); |
158 | if (pfn == -1UL) { | 158 | if (pfn == -1UL) { |
159 | kill_guest(lg, "failed to get page %lu", pte_pfn(gpte)); | 159 | kill_guest(cpu, "failed to get page %lu", pte_pfn(gpte)); |
160 | /* When we destroy the Guest, we'll go through the shadow page | 160 | /* When we destroy the Guest, we'll go through the shadow page |
161 | * tables and release_pte() them. Make sure we don't think | 161 | * tables and release_pte() them. Make sure we don't think |
162 | * this one is valid! */ | 162 | * this one is valid! */ |
@@ -176,17 +176,18 @@ static void release_pte(pte_t pte) | |||
176 | } | 176 | } |
177 | /*:*/ | 177 | /*:*/ |
178 | 178 | ||
179 | static void check_gpte(struct lguest *lg, pte_t gpte) | 179 | static void check_gpte(struct lg_cpu *cpu, pte_t gpte) |
180 | { | 180 | { |
181 | if ((pte_flags(gpte) & (_PAGE_PWT|_PAGE_PSE)) | 181 | if ((pte_flags(gpte) & (_PAGE_PWT|_PAGE_PSE)) |
182 | || pte_pfn(gpte) >= lg->pfn_limit) | 182 | || pte_pfn(gpte) >= cpu->lg->pfn_limit) |
183 | kill_guest(lg, "bad page table entry"); | 183 | kill_guest(cpu, "bad page table entry"); |
184 | } | 184 | } |
185 | 185 | ||
186 | static void check_gpgd(struct lguest *lg, pgd_t gpgd) | 186 | static void check_gpgd(struct lg_cpu *cpu, pgd_t gpgd) |
187 | { | 187 | { |
188 | if ((pgd_flags(gpgd) & ~_PAGE_TABLE) || pgd_pfn(gpgd) >= lg->pfn_limit) | 188 | if ((pgd_flags(gpgd) & ~_PAGE_TABLE) || |
189 | kill_guest(lg, "bad page directory entry"); | 189 | (pgd_pfn(gpgd) >= cpu->lg->pfn_limit)) |
190 | kill_guest(cpu, "bad page directory entry"); | ||
190 | } | 191 | } |
191 | 192 | ||
192 | /*H:330 | 193 | /*H:330 |
@@ -206,27 +207,26 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
206 | unsigned long gpte_ptr; | 207 | unsigned long gpte_ptr; |
207 | pte_t gpte; | 208 | pte_t gpte; |
208 | pte_t *spte; | 209 | pte_t *spte; |
209 | struct lguest *lg = cpu->lg; | ||
210 | 210 | ||
211 | /* First step: get the top-level Guest page table entry. */ | 211 | /* First step: get the top-level Guest page table entry. */ |
212 | gpgd = lgread(lg, gpgd_addr(cpu, vaddr), pgd_t); | 212 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); |
213 | /* Toplevel not present? We can't map it in. */ | 213 | /* Toplevel not present? We can't map it in. */ |
214 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) | 214 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) |
215 | return 0; | 215 | return 0; |
216 | 216 | ||
217 | /* Now look at the matching shadow entry. */ | 217 | /* Now look at the matching shadow entry. */ |
218 | spgd = spgd_addr(lg, cpu->cpu_pgd, vaddr); | 218 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); |
219 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) { | 219 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) { |
220 | /* No shadow entry: allocate a new shadow PTE page. */ | 220 | /* No shadow entry: allocate a new shadow PTE page. */ |
221 | unsigned long ptepage = get_zeroed_page(GFP_KERNEL); | 221 | unsigned long ptepage = get_zeroed_page(GFP_KERNEL); |
222 | /* This is not really the Guest's fault, but killing it is | 222 | /* This is not really the Guest's fault, but killing it is |
223 | * simple for this corner case. */ | 223 | * simple for this corner case. */ |
224 | if (!ptepage) { | 224 | if (!ptepage) { |
225 | kill_guest(lg, "out of memory allocating pte page"); | 225 | kill_guest(cpu, "out of memory allocating pte page"); |
226 | return 0; | 226 | return 0; |
227 | } | 227 | } |
228 | /* We check that the Guest pgd is OK. */ | 228 | /* We check that the Guest pgd is OK. */ |
229 | check_gpgd(lg, gpgd); | 229 | check_gpgd(cpu, gpgd); |
230 | /* And we copy the flags to the shadow PGD entry. The page | 230 | /* And we copy the flags to the shadow PGD entry. The page |
231 | * number in the shadow PGD is the page we just allocated. */ | 231 | * number in the shadow PGD is the page we just allocated. */ |
232 | *spgd = __pgd(__pa(ptepage) | pgd_flags(gpgd)); | 232 | *spgd = __pgd(__pa(ptepage) | pgd_flags(gpgd)); |
@@ -235,7 +235,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
235 | /* OK, now we look at the lower level in the Guest page table: keep its | 235 | /* OK, now we look at the lower level in the Guest page table: keep its |
236 | * address, because we might update it later. */ | 236 | * address, because we might update it later. */ |
237 | gpte_ptr = gpte_addr(gpgd, vaddr); | 237 | gpte_ptr = gpte_addr(gpgd, vaddr); |
238 | gpte = lgread(lg, gpte_ptr, pte_t); | 238 | gpte = lgread(cpu, gpte_ptr, pte_t); |
239 | 239 | ||
240 | /* If this page isn't in the Guest page tables, we can't page it in. */ | 240 | /* If this page isn't in the Guest page tables, we can't page it in. */ |
241 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) | 241 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) |
@@ -252,7 +252,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
252 | 252 | ||
253 | /* Check that the Guest PTE flags are OK, and the page number is below | 253 | /* Check that the Guest PTE flags are OK, and the page number is below |
254 | * the pfn_limit (ie. not mapping the Launcher binary). */ | 254 | * the pfn_limit (ie. not mapping the Launcher binary). */ |
255 | check_gpte(lg, gpte); | 255 | check_gpte(cpu, gpte); |
256 | 256 | ||
257 | /* Add the _PAGE_ACCESSED and (for a write) _PAGE_DIRTY flag */ | 257 | /* Add the _PAGE_ACCESSED and (for a write) _PAGE_DIRTY flag */ |
258 | gpte = pte_mkyoung(gpte); | 258 | gpte = pte_mkyoung(gpte); |
@@ -268,17 +268,17 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
268 | /* If this is a write, we insist that the Guest page is writable (the | 268 | /* If this is a write, we insist that the Guest page is writable (the |
269 | * final arg to gpte_to_spte()). */ | 269 | * final arg to gpte_to_spte()). */ |
270 | if (pte_dirty(gpte)) | 270 | if (pte_dirty(gpte)) |
271 | *spte = gpte_to_spte(lg, gpte, 1); | 271 | *spte = gpte_to_spte(cpu, gpte, 1); |
272 | else | 272 | else |
273 | /* If this is a read, don't set the "writable" bit in the page | 273 | /* If this is a read, don't set the "writable" bit in the page |
274 | * table entry, even if the Guest says it's writable. That way | 274 | * table entry, even if the Guest says it's writable. That way |
275 | * we will come back here when a write does actually occur, so | 275 | * we will come back here when a write does actually occur, so |
276 | * we can update the Guest's _PAGE_DIRTY flag. */ | 276 | * we can update the Guest's _PAGE_DIRTY flag. */ |
277 | *spte = gpte_to_spte(lg, pte_wrprotect(gpte), 0); | 277 | *spte = gpte_to_spte(cpu, pte_wrprotect(gpte), 0); |
278 | 278 | ||
279 | /* Finally, we write the Guest PTE entry back: we've set the | 279 | /* Finally, we write the Guest PTE entry back: we've set the |
280 | * _PAGE_ACCESSED and maybe the _PAGE_DIRTY flags. */ | 280 | * _PAGE_ACCESSED and maybe the _PAGE_DIRTY flags. */ |
281 | lgwrite(lg, gpte_ptr, pte_t, gpte); | 281 | lgwrite(cpu, gpte_ptr, pte_t, gpte); |
282 | 282 | ||
283 | /* The fault is fixed, the page table is populated, the mapping | 283 | /* The fault is fixed, the page table is populated, the mapping |
284 | * manipulated, the result returned and the code complete. A small | 284 | * manipulated, the result returned and the code complete. A small |
@@ -303,7 +303,7 @@ static int page_writable(struct lg_cpu *cpu, unsigned long vaddr) | |||
303 | unsigned long flags; | 303 | unsigned long flags; |
304 | 304 | ||
305 | /* Look at the current top level entry: is it present? */ | 305 | /* Look at the current top level entry: is it present? */ |
306 | spgd = spgd_addr(cpu->lg, cpu->cpu_pgd, vaddr); | 306 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); |
307 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) | 307 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) |
308 | return 0; | 308 | return 0; |
309 | 309 | ||
@@ -320,7 +320,7 @@ static int page_writable(struct lg_cpu *cpu, unsigned long vaddr) | |||
320 | void pin_page(struct lg_cpu *cpu, unsigned long vaddr) | 320 | void pin_page(struct lg_cpu *cpu, unsigned long vaddr) |
321 | { | 321 | { |
322 | if (!page_writable(cpu, vaddr) && !demand_page(cpu, vaddr, 2)) | 322 | if (!page_writable(cpu, vaddr) && !demand_page(cpu, vaddr, 2)) |
323 | kill_guest(cpu->lg, "bad stack page %#lx", vaddr); | 323 | kill_guest(cpu, "bad stack page %#lx", vaddr); |
324 | } | 324 | } |
325 | 325 | ||
326 | /*H:450 If we chase down the release_pgd() code, it looks like this: */ | 326 | /*H:450 If we chase down the release_pgd() code, it looks like this: */ |
@@ -372,14 +372,14 @@ unsigned long guest_pa(struct lg_cpu *cpu, unsigned long vaddr) | |||
372 | pte_t gpte; | 372 | pte_t gpte; |
373 | 373 | ||
374 | /* First step: get the top-level Guest page table entry. */ | 374 | /* First step: get the top-level Guest page table entry. */ |
375 | gpgd = lgread(cpu->lg, gpgd_addr(cpu, vaddr), pgd_t); | 375 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); |
376 | /* Toplevel not present? We can't map it in. */ | 376 | /* Toplevel not present? We can't map it in. */ |
377 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) | 377 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) |
378 | kill_guest(cpu->lg, "Bad address %#lx", vaddr); | 378 | kill_guest(cpu, "Bad address %#lx", vaddr); |
379 | 379 | ||
380 | gpte = lgread(cpu->lg, gpte_addr(gpgd, vaddr), pte_t); | 380 | gpte = lgread(cpu, gpte_addr(gpgd, vaddr), pte_t); |
381 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) | 381 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) |
382 | kill_guest(cpu->lg, "Bad address %#lx", vaddr); | 382 | kill_guest(cpu, "Bad address %#lx", vaddr); |
383 | 383 | ||
384 | return pte_pfn(gpte) * PAGE_SIZE | (vaddr & ~PAGE_MASK); | 384 | return pte_pfn(gpte) * PAGE_SIZE | (vaddr & ~PAGE_MASK); |
385 | } | 385 | } |
@@ -404,16 +404,16 @@ static unsigned int new_pgdir(struct lg_cpu *cpu, | |||
404 | int *blank_pgdir) | 404 | int *blank_pgdir) |
405 | { | 405 | { |
406 | unsigned int next; | 406 | unsigned int next; |
407 | struct lguest *lg = cpu->lg; | ||
408 | 407 | ||
409 | /* We pick one entry at random to throw out. Choosing the Least | 408 | /* We pick one entry at random to throw out. Choosing the Least |
410 | * Recently Used might be better, but this is easy. */ | 409 | * Recently Used might be better, but this is easy. */ |
411 | next = random32() % ARRAY_SIZE(lg->pgdirs); | 410 | next = random32() % ARRAY_SIZE(cpu->lg->pgdirs); |
412 | /* If it's never been allocated at all before, try now. */ | 411 | /* If it's never been allocated at all before, try now. */ |
413 | if (!lg->pgdirs[next].pgdir) { | 412 | if (!cpu->lg->pgdirs[next].pgdir) { |
414 | lg->pgdirs[next].pgdir = (pgd_t *)get_zeroed_page(GFP_KERNEL); | 413 | cpu->lg->pgdirs[next].pgdir = |
414 | (pgd_t *)get_zeroed_page(GFP_KERNEL); | ||
415 | /* If the allocation fails, just keep using the one we have */ | 415 | /* If the allocation fails, just keep using the one we have */ |
416 | if (!lg->pgdirs[next].pgdir) | 416 | if (!cpu->lg->pgdirs[next].pgdir) |
417 | next = cpu->cpu_pgd; | 417 | next = cpu->cpu_pgd; |
418 | else | 418 | else |
419 | /* This is a blank page, so there are no kernel | 419 | /* This is a blank page, so there are no kernel |
@@ -421,9 +421,9 @@ static unsigned int new_pgdir(struct lg_cpu *cpu, | |||
421 | *blank_pgdir = 1; | 421 | *blank_pgdir = 1; |
422 | } | 422 | } |
423 | /* Record which Guest toplevel this shadows. */ | 423 | /* Record which Guest toplevel this shadows. */ |
424 | lg->pgdirs[next].gpgdir = gpgdir; | 424 | cpu->lg->pgdirs[next].gpgdir = gpgdir; |
425 | /* Release all the non-kernel mappings. */ | 425 | /* Release all the non-kernel mappings. */ |
426 | flush_user_mappings(lg, next); | 426 | flush_user_mappings(cpu->lg, next); |
427 | 427 | ||
428 | return next; | 428 | return next; |
429 | } | 429 | } |
@@ -436,13 +436,12 @@ static unsigned int new_pgdir(struct lg_cpu *cpu, | |||
436 | void guest_new_pagetable(struct lg_cpu *cpu, unsigned long pgtable) | 436 | void guest_new_pagetable(struct lg_cpu *cpu, unsigned long pgtable) |
437 | { | 437 | { |
438 | int newpgdir, repin = 0; | 438 | int newpgdir, repin = 0; |
439 | struct lguest *lg = cpu->lg; | ||
440 | 439 | ||
441 | /* Look to see if we have this one already. */ | 440 | /* Look to see if we have this one already. */ |
442 | newpgdir = find_pgdir(lg, pgtable); | 441 | newpgdir = find_pgdir(cpu->lg, pgtable); |
443 | /* If not, we allocate or mug an existing one: if it's a fresh one, | 442 | /* If not, we allocate or mug an existing one: if it's a fresh one, |
444 | * repin gets set to 1. */ | 443 | * repin gets set to 1. */ |
445 | if (newpgdir == ARRAY_SIZE(lg->pgdirs)) | 444 | if (newpgdir == ARRAY_SIZE(cpu->lg->pgdirs)) |
446 | newpgdir = new_pgdir(cpu, pgtable, &repin); | 445 | newpgdir = new_pgdir(cpu, pgtable, &repin); |
447 | /* Change the current pgd index to the new one. */ | 446 | /* Change the current pgd index to the new one. */ |
448 | cpu->cpu_pgd = newpgdir; | 447 | cpu->cpu_pgd = newpgdir; |
@@ -499,11 +498,11 @@ void guest_pagetable_clear_all(struct lg_cpu *cpu) | |||
499 | * _PAGE_ACCESSED then we can put a read-only PTE entry in immediately, and if | 498 | * _PAGE_ACCESSED then we can put a read-only PTE entry in immediately, and if |
500 | * they set _PAGE_DIRTY then we can put a writable PTE entry in immediately. | 499 | * they set _PAGE_DIRTY then we can put a writable PTE entry in immediately. |
501 | */ | 500 | */ |
502 | static void do_set_pte(struct lguest *lg, int idx, | 501 | static void do_set_pte(struct lg_cpu *cpu, int idx, |
503 | unsigned long vaddr, pte_t gpte) | 502 | unsigned long vaddr, pte_t gpte) |
504 | { | 503 | { |
505 | /* Look up the matching shadow page directory entry. */ | 504 | /* Look up the matching shadow page directory entry. */ |
506 | pgd_t *spgd = spgd_addr(lg, idx, vaddr); | 505 | pgd_t *spgd = spgd_addr(cpu, idx, vaddr); |
507 | 506 | ||
508 | /* If the top level isn't present, there's no entry to update. */ | 507 | /* If the top level isn't present, there's no entry to update. */ |
509 | if (pgd_flags(*spgd) & _PAGE_PRESENT) { | 508 | if (pgd_flags(*spgd) & _PAGE_PRESENT) { |
@@ -515,8 +514,8 @@ static void do_set_pte(struct lguest *lg, int idx, | |||
515 | * as well put that entry they've given us in now. This shaves | 514 | * as well put that entry they've given us in now. This shaves |
516 | * 10% off a copy-on-write micro-benchmark. */ | 515 | * 10% off a copy-on-write micro-benchmark. */ |
517 | if (pte_flags(gpte) & (_PAGE_DIRTY | _PAGE_ACCESSED)) { | 516 | if (pte_flags(gpte) & (_PAGE_DIRTY | _PAGE_ACCESSED)) { |
518 | check_gpte(lg, gpte); | 517 | check_gpte(cpu, gpte); |
519 | *spte = gpte_to_spte(lg, gpte, | 518 | *spte = gpte_to_spte(cpu, gpte, |
520 | pte_flags(gpte) & _PAGE_DIRTY); | 519 | pte_flags(gpte) & _PAGE_DIRTY); |
521 | } else | 520 | } else |
522 | /* Otherwise kill it and we can demand_page() it in | 521 | /* Otherwise kill it and we can demand_page() it in |
@@ -535,22 +534,22 @@ static void do_set_pte(struct lguest *lg, int idx, | |||
535 | * | 534 | * |
536 | * The benefit is that when we have to track a new page table, we can copy keep | 535 | * The benefit is that when we have to track a new page table, we can copy keep |
537 | * all the kernel mappings. This speeds up context switch immensely. */ | 536 | * all the kernel mappings. This speeds up context switch immensely. */ |
538 | void guest_set_pte(struct lguest *lg, | 537 | void guest_set_pte(struct lg_cpu *cpu, |
539 | unsigned long gpgdir, unsigned long vaddr, pte_t gpte) | 538 | unsigned long gpgdir, unsigned long vaddr, pte_t gpte) |
540 | { | 539 | { |
541 | /* Kernel mappings must be changed on all top levels. Slow, but | 540 | /* Kernel mappings must be changed on all top levels. Slow, but |
542 | * doesn't happen often. */ | 541 | * doesn't happen often. */ |
543 | if (vaddr >= lg->kernel_address) { | 542 | if (vaddr >= cpu->lg->kernel_address) { |
544 | unsigned int i; | 543 | unsigned int i; |
545 | for (i = 0; i < ARRAY_SIZE(lg->pgdirs); i++) | 544 | for (i = 0; i < ARRAY_SIZE(cpu->lg->pgdirs); i++) |
546 | if (lg->pgdirs[i].pgdir) | 545 | if (cpu->lg->pgdirs[i].pgdir) |
547 | do_set_pte(lg, i, vaddr, gpte); | 546 | do_set_pte(cpu, i, vaddr, gpte); |
548 | } else { | 547 | } else { |
549 | /* Is this page table one we have a shadow for? */ | 548 | /* Is this page table one we have a shadow for? */ |
550 | int pgdir = find_pgdir(lg, gpgdir); | 549 | int pgdir = find_pgdir(cpu->lg, gpgdir); |
551 | if (pgdir != ARRAY_SIZE(lg->pgdirs)) | 550 | if (pgdir != ARRAY_SIZE(cpu->lg->pgdirs)) |
552 | /* If so, do the update. */ | 551 | /* If so, do the update. */ |
553 | do_set_pte(lg, pgdir, vaddr, gpte); | 552 | do_set_pte(cpu, pgdir, vaddr, gpte); |
554 | } | 553 | } |
555 | } | 554 | } |
556 | 555 | ||
@@ -601,21 +600,23 @@ int init_guest_pagetable(struct lguest *lg, unsigned long pgtable) | |||
601 | } | 600 | } |
602 | 601 | ||
603 | /* When the Guest calls LHCALL_LGUEST_INIT we do more setup. */ | 602 | /* When the Guest calls LHCALL_LGUEST_INIT we do more setup. */ |
604 | void page_table_guest_data_init(struct lguest *lg) | 603 | void page_table_guest_data_init(struct lg_cpu *cpu) |
605 | { | 604 | { |
606 | /* We get the kernel address: above this is all kernel memory. */ | 605 | /* We get the kernel address: above this is all kernel memory. */ |
607 | if (get_user(lg->kernel_address, &lg->lguest_data->kernel_address) | 606 | if (get_user(cpu->lg->kernel_address, |
607 | &cpu->lg->lguest_data->kernel_address) | ||
608 | /* We tell the Guest that it can't use the top 4MB of virtual | 608 | /* We tell the Guest that it can't use the top 4MB of virtual |
609 | * addresses used by the Switcher. */ | 609 | * addresses used by the Switcher. */ |
610 | || put_user(4U*1024*1024, &lg->lguest_data->reserve_mem) | 610 | || put_user(4U*1024*1024, &cpu->lg->lguest_data->reserve_mem) |
611 | || put_user(lg->pgdirs[0].gpgdir, &lg->lguest_data->pgdir)) | 611 | || put_user(cpu->lg->pgdirs[0].gpgdir, &cpu->lg->lguest_data->pgdir)) |
612 | kill_guest(lg, "bad guest page %p", lg->lguest_data); | 612 | kill_guest(cpu, "bad guest page %p", cpu->lg->lguest_data); |
613 | 613 | ||
614 | /* In flush_user_mappings() we loop from 0 to | 614 | /* In flush_user_mappings() we loop from 0 to |
615 | * "pgd_index(lg->kernel_address)". This assumes it won't hit the | 615 | * "pgd_index(lg->kernel_address)". This assumes it won't hit the |
616 | * Switcher mappings, so check that now. */ | 616 | * Switcher mappings, so check that now. */ |
617 | if (pgd_index(lg->kernel_address) >= SWITCHER_PGD_INDEX) | 617 | if (pgd_index(cpu->lg->kernel_address) >= SWITCHER_PGD_INDEX) |
618 | kill_guest(lg, "bad kernel address %#lx", lg->kernel_address); | 618 | kill_guest(cpu, "bad kernel address %#lx", |
619 | cpu->lg->kernel_address); | ||
619 | } | 620 | } |
620 | 621 | ||
621 | /* When a Guest dies, our cleanup is fairly simple. */ | 622 | /* When a Guest dies, our cleanup is fairly simple. */ |