diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-30 20:57:39 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-30 20:57:39 -0400 |
| commit | db6f204019380c788f1de06ee937bdbccd60e5c0 (patch) | |
| tree | f8ca32ab6932a21797dbc5aa77688ea017959da0 /drivers/lguest/page_tables.c | |
| parent | 3c6fae67d026d57f64eb3da9c0d0e76983e39ae3 (diff) | |
| parent | d1881d3192a3d3e8dc4f255b03187f4c36cb0617 (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-lguest-and-virtio
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-lguest-and-virtio:
lguest: barrier me harder
lguest: use bool instead of int
lguest: use KVM hypercalls
lguest: wire up pte_update/pte_update_defer
lguest: fix spurious BUG_ON() on invalid guest stack.
virtio: more neatening of virtio_ring macros.
virtio: fix BAD_RING, START_US and END_USE macros
Diffstat (limited to 'drivers/lguest/page_tables.c')
| -rw-r--r-- | drivers/lguest/page_tables.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c index 576a8318221c..a059cf9980f7 100644 --- a/drivers/lguest/page_tables.c +++ b/drivers/lguest/page_tables.c | |||
| @@ -199,7 +199,7 @@ static void check_gpgd(struct lg_cpu *cpu, pgd_t gpgd) | |||
| 199 | * | 199 | * |
| 200 | * If we fixed up the fault (ie. we mapped the address), this routine returns | 200 | * If we fixed up the fault (ie. we mapped the address), this routine returns |
| 201 | * true. Otherwise, it was a real fault and we need to tell the Guest. */ | 201 | * true. Otherwise, it was a real fault and we need to tell the Guest. */ |
| 202 | int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | 202 | bool demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) |
| 203 | { | 203 | { |
| 204 | pgd_t gpgd; | 204 | pgd_t gpgd; |
| 205 | pgd_t *spgd; | 205 | pgd_t *spgd; |
| @@ -211,7 +211,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
| 211 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); | 211 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); |
| 212 | /* Toplevel not present? We can't map it in. */ | 212 | /* Toplevel not present? We can't map it in. */ |
| 213 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) | 213 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) |
| 214 | return 0; | 214 | return false; |
| 215 | 215 | ||
| 216 | /* Now look at the matching shadow entry. */ | 216 | /* Now look at the matching shadow entry. */ |
| 217 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); | 217 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); |
| @@ -222,7 +222,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
| 222 | * simple for this corner case. */ | 222 | * simple for this corner case. */ |
| 223 | if (!ptepage) { | 223 | if (!ptepage) { |
| 224 | kill_guest(cpu, "out of memory allocating pte page"); | 224 | kill_guest(cpu, "out of memory allocating pte page"); |
| 225 | return 0; | 225 | return false; |
| 226 | } | 226 | } |
| 227 | /* We check that the Guest pgd is OK. */ | 227 | /* We check that the Guest pgd is OK. */ |
| 228 | check_gpgd(cpu, gpgd); | 228 | check_gpgd(cpu, gpgd); |
| @@ -238,16 +238,16 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
| 238 | 238 | ||
| 239 | /* If this page isn't in the Guest page tables, we can't page it in. */ | 239 | /* If this page isn't in the Guest page tables, we can't page it in. */ |
| 240 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) | 240 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) |
| 241 | return 0; | 241 | return false; |
| 242 | 242 | ||
| 243 | /* Check they're not trying to write to a page the Guest wants | 243 | /* Check they're not trying to write to a page the Guest wants |
| 244 | * read-only (bit 2 of errcode == write). */ | 244 | * read-only (bit 2 of errcode == write). */ |
| 245 | if ((errcode & 2) && !(pte_flags(gpte) & _PAGE_RW)) | 245 | if ((errcode & 2) && !(pte_flags(gpte) & _PAGE_RW)) |
| 246 | return 0; | 246 | return false; |
| 247 | 247 | ||
| 248 | /* User access to a kernel-only page? (bit 3 == user access) */ | 248 | /* User access to a kernel-only page? (bit 3 == user access) */ |
| 249 | if ((errcode & 4) && !(pte_flags(gpte) & _PAGE_USER)) | 249 | if ((errcode & 4) && !(pte_flags(gpte) & _PAGE_USER)) |
| 250 | return 0; | 250 | return false; |
| 251 | 251 | ||
| 252 | /* Check that the Guest PTE flags are OK, and the page number is below | 252 | /* Check that the Guest PTE flags are OK, and the page number is below |
| 253 | * the pfn_limit (ie. not mapping the Launcher binary). */ | 253 | * the pfn_limit (ie. not mapping the Launcher binary). */ |
| @@ -283,7 +283,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
| 283 | * manipulated, the result returned and the code complete. A small | 283 | * manipulated, the result returned and the code complete. A small |
| 284 | * delay and a trace of alliteration are the only indications the Guest | 284 | * delay and a trace of alliteration are the only indications the Guest |
| 285 | * has that a page fault occurred at all. */ | 285 | * has that a page fault occurred at all. */ |
| 286 | return 1; | 286 | return true; |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | /*H:360 | 289 | /*H:360 |
| @@ -296,7 +296,7 @@ int demand_page(struct lg_cpu *cpu, unsigned long vaddr, int errcode) | |||
| 296 | * | 296 | * |
| 297 | * This is a quick version which answers the question: is this virtual address | 297 | * This is a quick version which answers the question: is this virtual address |
| 298 | * mapped by the shadow page tables, and is it writable? */ | 298 | * mapped by the shadow page tables, and is it writable? */ |
| 299 | static int page_writable(struct lg_cpu *cpu, unsigned long vaddr) | 299 | static bool page_writable(struct lg_cpu *cpu, unsigned long vaddr) |
| 300 | { | 300 | { |
| 301 | pgd_t *spgd; | 301 | pgd_t *spgd; |
| 302 | unsigned long flags; | 302 | unsigned long flags; |
| @@ -304,7 +304,7 @@ static int page_writable(struct lg_cpu *cpu, unsigned long vaddr) | |||
| 304 | /* Look at the current top level entry: is it present? */ | 304 | /* Look at the current top level entry: is it present? */ |
| 305 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); | 305 | spgd = spgd_addr(cpu, cpu->cpu_pgd, vaddr); |
| 306 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) | 306 | if (!(pgd_flags(*spgd) & _PAGE_PRESENT)) |
| 307 | return 0; | 307 | return false; |
| 308 | 308 | ||
| 309 | /* Check the flags on the pte entry itself: it must be present and | 309 | /* Check the flags on the pte entry itself: it must be present and |
| 310 | * writable. */ | 310 | * writable. */ |
| @@ -373,8 +373,10 @@ unsigned long guest_pa(struct lg_cpu *cpu, unsigned long vaddr) | |||
| 373 | /* First step: get the top-level Guest page table entry. */ | 373 | /* First step: get the top-level Guest page table entry. */ |
| 374 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); | 374 | gpgd = lgread(cpu, gpgd_addr(cpu, vaddr), pgd_t); |
| 375 | /* Toplevel not present? We can't map it in. */ | 375 | /* Toplevel not present? We can't map it in. */ |
| 376 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) | 376 | if (!(pgd_flags(gpgd) & _PAGE_PRESENT)) { |
| 377 | kill_guest(cpu, "Bad address %#lx", vaddr); | 377 | kill_guest(cpu, "Bad address %#lx", vaddr); |
| 378 | return -1UL; | ||
| 379 | } | ||
| 378 | 380 | ||
| 379 | gpte = lgread(cpu, gpte_addr(gpgd, vaddr), pte_t); | 381 | gpte = lgread(cpu, gpte_addr(gpgd, vaddr), pte_t); |
| 380 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) | 382 | if (!(pte_flags(gpte) & _PAGE_PRESENT)) |
