diff options
-rw-r--r-- | Documentation/lguest/lguest.c | 7 | ||||
-rw-r--r-- | arch/x86/include/asm/lguest_hcall.h | 24 | ||||
-rw-r--r-- | arch/x86/lguest/boot.c | 86 | ||||
-rw-r--r-- | arch/x86/lguest/i386_head.S | 4 | ||||
-rw-r--r-- | drivers/lguest/core.c | 4 | ||||
-rw-r--r-- | drivers/lguest/interrupts_and_traps.c | 28 | ||||
-rw-r--r-- | drivers/lguest/lg.h | 8 | ||||
-rw-r--r-- | drivers/lguest/lguest_device.c | 4 | ||||
-rw-r--r-- | drivers/lguest/page_tables.c | 22 | ||||
-rw-r--r-- | drivers/lguest/segments.c | 2 | ||||
-rw-r--r-- | drivers/lguest/x86/core.c | 62 | ||||
-rw-r--r-- | drivers/virtio/virtio_ring.c | 22 |
12 files changed, 181 insertions, 92 deletions
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c index f2dbbf3bdeab..d36fcc0f2715 100644 --- a/Documentation/lguest/lguest.c +++ b/Documentation/lguest/lguest.c | |||
@@ -1630,6 +1630,13 @@ static bool service_io(struct device *dev) | |||
1630 | } | 1630 | } |
1631 | } | 1631 | } |
1632 | 1632 | ||
1633 | /* OK, so we noted that it was pretty poor to use an fdatasync as a | ||
1634 | * barrier. But Christoph Hellwig points out that we need a sync | ||
1635 | * *afterwards* as well: "Barriers specify no reordering to the front | ||
1636 | * or the back." And Jens Axboe confirmed it, so here we are: */ | ||
1637 | if (out->type & VIRTIO_BLK_T_BARRIER) | ||
1638 | fdatasync(vblk->fd); | ||
1639 | |||
1633 | /* We can't trigger an IRQ, because we're not the Launcher. It does | 1640 | /* We can't trigger an IRQ, because we're not the Launcher. It does |
1634 | * that when we tell it we're done. */ | 1641 | * that when we tell it we're done. */ |
1635 | add_used(dev->vq, head, wlen); | 1642 | add_used(dev->vq, head, wlen); |
diff --git a/arch/x86/include/asm/lguest_hcall.h b/arch/x86/include/asm/lguest_hcall.h index 43894428c3c2..0f4ee7148afe 100644 --- a/arch/x86/include/asm/lguest_hcall.h +++ b/arch/x86/include/asm/lguest_hcall.h | |||
@@ -26,36 +26,20 @@ | |||
26 | 26 | ||
27 | #ifndef __ASSEMBLY__ | 27 | #ifndef __ASSEMBLY__ |
28 | #include <asm/hw_irq.h> | 28 | #include <asm/hw_irq.h> |
29 | #include <asm/kvm_para.h> | ||
29 | 30 | ||
30 | /*G:031 But first, how does our Guest contact the Host to ask for privileged | 31 | /*G:031 But first, how does our Guest contact the Host to ask for privileged |
31 | * operations? There are two ways: the direct way is to make a "hypercall", | 32 | * operations? There are two ways: the direct way is to make a "hypercall", |
32 | * to make requests of the Host Itself. | 33 | * to make requests of the Host Itself. |
33 | * | 34 | * |
34 | * Our hypercall mechanism uses the highest unused trap code (traps 32 and | 35 | * We use the KVM hypercall mechanism. Eighteen hypercalls are |
35 | * above are used by real hardware interrupts). Fifteen hypercalls are | ||
36 | * available: the hypercall number is put in the %eax register, and the | 36 | * available: the hypercall number is put in the %eax register, and the |
37 | * arguments (when required) are placed in %edx, %ebx and %ecx. If a return | 37 | * arguments (when required) are placed in %ebx, %ecx and %edx. If a return |
38 | * value makes sense, it's returned in %eax. | 38 | * value makes sense, it's returned in %eax. |
39 | * | 39 | * |
40 | * Grossly invalid calls result in Sudden Death at the hands of the vengeful | 40 | * Grossly invalid calls result in Sudden Death at the hands of the vengeful |
41 | * Host, rather than returning failure. This reflects Winston Churchill's | 41 | * Host, rather than returning failure. This reflects Winston Churchill's |
42 | * definition of a gentleman: "someone who is only rude intentionally". */ | 42 | * definition of a gentleman: "someone who is only rude intentionally". */ |
43 | static inline unsigned long | ||
44 | hcall(unsigned long call, | ||
45 | unsigned long arg1, unsigned long arg2, unsigned long arg3) | ||
46 | { | ||
47 | /* "int" is the Intel instruction to trigger a trap. */ | ||
48 | asm volatile("int $" __stringify(LGUEST_TRAP_ENTRY) | ||
49 | /* The call in %eax (aka "a") might be overwritten */ | ||
50 | : "=a"(call) | ||
51 | /* The arguments are in %eax, %edx, %ebx & %ecx */ | ||
52 | : "a"(call), "d"(arg1), "b"(arg2), "c"(arg3) | ||
53 | /* "memory" means this might write somewhere in memory. | ||
54 | * This isn't true for all calls, but it's safe to tell | ||
55 | * gcc that it might happen so it doesn't get clever. */ | ||
56 | : "memory"); | ||
57 | return call; | ||
58 | } | ||
59 | /*:*/ | 43 | /*:*/ |
60 | 44 | ||
61 | /* Can't use our min() macro here: needs to be a constant */ | 45 | /* Can't use our min() macro here: needs to be a constant */ |
@@ -64,7 +48,7 @@ hcall(unsigned long call, | |||
64 | #define LHCALL_RING_SIZE 64 | 48 | #define LHCALL_RING_SIZE 64 |
65 | struct hcall_args { | 49 | struct hcall_args { |
66 | /* These map directly onto eax, ebx, ecx, edx in struct lguest_regs */ | 50 | /* These map directly onto eax, ebx, ecx, edx in struct lguest_regs */ |
67 | unsigned long arg0, arg2, arg3, arg1; | 51 | unsigned long arg0, arg1, arg2, arg3; |
68 | }; | 52 | }; |
69 | 53 | ||
70 | #endif /* !__ASSEMBLY__ */ | 54 | #endif /* !__ASSEMBLY__ */ |
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c index 90e44a10e68a..e94a11e42f98 100644 --- a/arch/x86/lguest/boot.c +++ b/arch/x86/lguest/boot.c | |||
@@ -107,7 +107,7 @@ static void async_hcall(unsigned long call, unsigned long arg1, | |||
107 | local_irq_save(flags); | 107 | local_irq_save(flags); |
108 | if (lguest_data.hcall_status[next_call] != 0xFF) { | 108 | if (lguest_data.hcall_status[next_call] != 0xFF) { |
109 | /* Table full, so do normal hcall which will flush table. */ | 109 | /* Table full, so do normal hcall which will flush table. */ |
110 | hcall(call, arg1, arg2, arg3); | 110 | kvm_hypercall3(call, arg1, arg2, arg3); |
111 | } else { | 111 | } else { |
112 | lguest_data.hcalls[next_call].arg0 = call; | 112 | lguest_data.hcalls[next_call].arg0 = call; |
113 | lguest_data.hcalls[next_call].arg1 = arg1; | 113 | lguest_data.hcalls[next_call].arg1 = arg1; |
@@ -134,13 +134,32 @@ static void async_hcall(unsigned long call, unsigned long arg1, | |||
134 | * | 134 | * |
135 | * So, when we're in lazy mode, we call async_hcall() to store the call for | 135 | * So, when we're in lazy mode, we call async_hcall() to store the call for |
136 | * future processing: */ | 136 | * future processing: */ |
137 | static void lazy_hcall(unsigned long call, | 137 | static void lazy_hcall1(unsigned long call, |
138 | unsigned long arg1) | ||
139 | { | ||
140 | if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) | ||
141 | kvm_hypercall1(call, arg1); | ||
142 | else | ||
143 | async_hcall(call, arg1, 0, 0); | ||
144 | } | ||
145 | |||
146 | static void lazy_hcall2(unsigned long call, | ||
147 | unsigned long arg1, | ||
148 | unsigned long arg2) | ||
149 | { | ||
150 | if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) | ||
151 | kvm_hypercall2(call, arg1, arg2); | ||
152 | else | ||
153 | async_hcall(call, arg1, arg2, 0); | ||
154 | } | ||
155 | |||
156 | static void lazy_hcall3(unsigned long call, | ||
138 | unsigned long arg1, | 157 | unsigned long arg1, |
139 | unsigned long arg2, | 158 | unsigned long arg2, |
140 | unsigned long arg3) | 159 | unsigned long arg3) |
141 | { | 160 | { |
142 | if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) | 161 | if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_NONE) |
143 | hcall(call, arg1, arg2, arg3); | 162 | kvm_hypercall3(call, arg1, arg2, arg3); |
144 | else | 163 | else |
145 | async_hcall(call, arg1, arg2, arg3); | 164 | async_hcall(call, arg1, arg2, arg3); |
146 | } | 165 | } |
@@ -150,7 +169,7 @@ static void lazy_hcall(unsigned long call, | |||
150 | static void lguest_leave_lazy_mode(void) | 169 | static void lguest_leave_lazy_mode(void) |
151 | { | 170 | { |
152 | paravirt_leave_lazy(paravirt_get_lazy_mode()); | 171 | paravirt_leave_lazy(paravirt_get_lazy_mode()); |
153 | hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0); | 172 | kvm_hypercall0(LHCALL_FLUSH_ASYNC); |
154 | } | 173 | } |
155 | 174 | ||
156 | /*G:033 | 175 | /*G:033 |
@@ -229,7 +248,7 @@ static void lguest_write_idt_entry(gate_desc *dt, | |||
229 | /* Keep the local copy up to date. */ | 248 | /* Keep the local copy up to date. */ |
230 | native_write_idt_entry(dt, entrynum, g); | 249 | native_write_idt_entry(dt, entrynum, g); |
231 | /* Tell Host about this new entry. */ | 250 | /* Tell Host about this new entry. */ |
232 | hcall(LHCALL_LOAD_IDT_ENTRY, entrynum, desc[0], desc[1]); | 251 | kvm_hypercall3(LHCALL_LOAD_IDT_ENTRY, entrynum, desc[0], desc[1]); |
233 | } | 252 | } |
234 | 253 | ||
235 | /* Changing to a different IDT is very rare: we keep the IDT up-to-date every | 254 | /* Changing to a different IDT is very rare: we keep the IDT up-to-date every |
@@ -241,7 +260,7 @@ static void lguest_load_idt(const struct desc_ptr *desc) | |||
241 | struct desc_struct *idt = (void *)desc->address; | 260 | struct desc_struct *idt = (void *)desc->address; |
242 | 261 | ||
243 | for (i = 0; i < (desc->size+1)/8; i++) | 262 | for (i = 0; i < (desc->size+1)/8; i++) |
244 | hcall(LHCALL_LOAD_IDT_ENTRY, i, idt[i].a, idt[i].b); | 263 | kvm_hypercall3(LHCALL_LOAD_IDT_ENTRY, i, idt[i].a, idt[i].b); |
245 | } | 264 | } |
246 | 265 | ||
247 | /* | 266 | /* |
@@ -261,8 +280,8 @@ static void lguest_load_idt(const struct desc_ptr *desc) | |||
261 | */ | 280 | */ |
262 | static void lguest_load_gdt(const struct desc_ptr *desc) | 281 | static void lguest_load_gdt(const struct desc_ptr *desc) |
263 | { | 282 | { |
264 | BUG_ON((desc->size+1)/8 != GDT_ENTRIES); | 283 | BUG_ON((desc->size + 1) / 8 != GDT_ENTRIES); |
265 | hcall(LHCALL_LOAD_GDT, __pa(desc->address), GDT_ENTRIES, 0); | 284 | kvm_hypercall2(LHCALL_LOAD_GDT, __pa(desc->address), GDT_ENTRIES); |
266 | } | 285 | } |
267 | 286 | ||
268 | /* For a single GDT entry which changes, we do the lazy thing: alter our GDT, | 287 | /* For a single GDT entry which changes, we do the lazy thing: alter our GDT, |
@@ -272,7 +291,7 @@ static void lguest_write_gdt_entry(struct desc_struct *dt, int entrynum, | |||
272 | const void *desc, int type) | 291 | const void *desc, int type) |
273 | { | 292 | { |
274 | native_write_gdt_entry(dt, entrynum, desc, type); | 293 | native_write_gdt_entry(dt, entrynum, desc, type); |
275 | hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0); | 294 | kvm_hypercall2(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES); |
276 | } | 295 | } |
277 | 296 | ||
278 | /* OK, I lied. There are three "thread local storage" GDT entries which change | 297 | /* OK, I lied. There are three "thread local storage" GDT entries which change |
@@ -284,7 +303,7 @@ static void lguest_load_tls(struct thread_struct *t, unsigned int cpu) | |||
284 | * can't handle us removing entries we're currently using. So we clear | 303 | * can't handle us removing entries we're currently using. So we clear |
285 | * the GS register here: if it's needed it'll be reloaded anyway. */ | 304 | * the GS register here: if it's needed it'll be reloaded anyway. */ |
286 | lazy_load_gs(0); | 305 | lazy_load_gs(0); |
287 | lazy_hcall(LHCALL_LOAD_TLS, __pa(&t->tls_array), cpu, 0); | 306 | lazy_hcall2(LHCALL_LOAD_TLS, __pa(&t->tls_array), cpu); |
288 | } | 307 | } |
289 | 308 | ||
290 | /*G:038 That's enough excitement for now, back to ploughing through each of | 309 | /*G:038 That's enough excitement for now, back to ploughing through each of |
@@ -382,7 +401,7 @@ static void lguest_cpuid(unsigned int *ax, unsigned int *bx, | |||
382 | static unsigned long current_cr0; | 401 | static unsigned long current_cr0; |
383 | static void lguest_write_cr0(unsigned long val) | 402 | static void lguest_write_cr0(unsigned long val) |
384 | { | 403 | { |
385 | lazy_hcall(LHCALL_TS, val & X86_CR0_TS, 0, 0); | 404 | lazy_hcall1(LHCALL_TS, val & X86_CR0_TS); |
386 | current_cr0 = val; | 405 | current_cr0 = val; |
387 | } | 406 | } |
388 | 407 | ||
@@ -396,7 +415,7 @@ static unsigned long lguest_read_cr0(void) | |||
396 | * the vowels have been optimized out. */ | 415 | * the vowels have been optimized out. */ |
397 | static void lguest_clts(void) | 416 | static void lguest_clts(void) |
398 | { | 417 | { |
399 | lazy_hcall(LHCALL_TS, 0, 0, 0); | 418 | lazy_hcall1(LHCALL_TS, 0); |
400 | current_cr0 &= ~X86_CR0_TS; | 419 | current_cr0 &= ~X86_CR0_TS; |
401 | } | 420 | } |
402 | 421 | ||
@@ -418,7 +437,7 @@ static bool cr3_changed = false; | |||
418 | static void lguest_write_cr3(unsigned long cr3) | 437 | static void lguest_write_cr3(unsigned long cr3) |
419 | { | 438 | { |
420 | lguest_data.pgdir = cr3; | 439 | lguest_data.pgdir = cr3; |
421 | lazy_hcall(LHCALL_NEW_PGTABLE, cr3, 0, 0); | 440 | lazy_hcall1(LHCALL_NEW_PGTABLE, cr3); |
422 | cr3_changed = true; | 441 | cr3_changed = true; |
423 | } | 442 | } |
424 | 443 | ||
@@ -490,11 +509,17 @@ static void lguest_write_cr4(unsigned long val) | |||
490 | * into a process' address space. We set the entry then tell the Host the | 509 | * into a process' address space. We set the entry then tell the Host the |
491 | * toplevel and address this corresponds to. The Guest uses one pagetable per | 510 | * toplevel and address this corresponds to. The Guest uses one pagetable per |
492 | * process, so we need to tell the Host which one we're changing (mm->pgd). */ | 511 | * process, so we need to tell the Host which one we're changing (mm->pgd). */ |
512 | static void lguest_pte_update(struct mm_struct *mm, unsigned long addr, | ||
513 | pte_t *ptep) | ||
514 | { | ||
515 | lazy_hcall3(LHCALL_SET_PTE, __pa(mm->pgd), addr, ptep->pte_low); | ||
516 | } | ||
517 | |||
493 | static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr, | 518 | static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr, |
494 | pte_t *ptep, pte_t pteval) | 519 | pte_t *ptep, pte_t pteval) |
495 | { | 520 | { |
496 | *ptep = pteval; | 521 | *ptep = pteval; |
497 | lazy_hcall(LHCALL_SET_PTE, __pa(mm->pgd), addr, pteval.pte_low); | 522 | lguest_pte_update(mm, addr, ptep); |
498 | } | 523 | } |
499 | 524 | ||
500 | /* The Guest calls this to set a top-level entry. Again, we set the entry then | 525 | /* The Guest calls this to set a top-level entry. Again, we set the entry then |
@@ -503,8 +528,8 @@ static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr, | |||
503 | static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval) | 528 | static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval) |
504 | { | 529 | { |
505 | *pmdp = pmdval; | 530 | *pmdp = pmdval; |
506 | lazy_hcall(LHCALL_SET_PMD, __pa(pmdp)&PAGE_MASK, | 531 | lazy_hcall2(LHCALL_SET_PMD, __pa(pmdp) & PAGE_MASK, |
507 | (__pa(pmdp)&(PAGE_SIZE-1))/4, 0); | 532 | (__pa(pmdp) & (PAGE_SIZE - 1)) / 4); |
508 | } | 533 | } |
509 | 534 | ||
510 | /* There are a couple of legacy places where the kernel sets a PTE, but we | 535 | /* There are a couple of legacy places where the kernel sets a PTE, but we |
@@ -520,7 +545,7 @@ static void lguest_set_pte(pte_t *ptep, pte_t pteval) | |||
520 | { | 545 | { |
521 | *ptep = pteval; | 546 | *ptep = pteval; |
522 | if (cr3_changed) | 547 | if (cr3_changed) |
523 | lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0); | 548 | lazy_hcall1(LHCALL_FLUSH_TLB, 1); |
524 | } | 549 | } |
525 | 550 | ||
526 | /* Unfortunately for Lguest, the pv_mmu_ops for page tables were based on | 551 | /* Unfortunately for Lguest, the pv_mmu_ops for page tables were based on |
@@ -536,7 +561,7 @@ static void lguest_set_pte(pte_t *ptep, pte_t pteval) | |||
536 | static void lguest_flush_tlb_single(unsigned long addr) | 561 | static void lguest_flush_tlb_single(unsigned long addr) |
537 | { | 562 | { |
538 | /* Simply set it to zero: if it was not, it will fault back in. */ | 563 | /* Simply set it to zero: if it was not, it will fault back in. */ |
539 | lazy_hcall(LHCALL_SET_PTE, lguest_data.pgdir, addr, 0); | 564 | lazy_hcall3(LHCALL_SET_PTE, lguest_data.pgdir, addr, 0); |
540 | } | 565 | } |
541 | 566 | ||
542 | /* This is what happens after the Guest has removed a large number of entries. | 567 | /* This is what happens after the Guest has removed a large number of entries. |
@@ -544,7 +569,7 @@ static void lguest_flush_tlb_single(unsigned long addr) | |||
544 | * have changed, ie. virtual addresses below PAGE_OFFSET. */ | 569 | * have changed, ie. virtual addresses below PAGE_OFFSET. */ |
545 | static void lguest_flush_tlb_user(void) | 570 | static void lguest_flush_tlb_user(void) |
546 | { | 571 | { |
547 | lazy_hcall(LHCALL_FLUSH_TLB, 0, 0, 0); | 572 | lazy_hcall1(LHCALL_FLUSH_TLB, 0); |
548 | } | 573 | } |
549 | 574 | ||
550 | /* This is called when the kernel page tables have changed. That's not very | 575 | /* This is called when the kernel page tables have changed. That's not very |
@@ -552,7 +577,7 @@ static void lguest_flush_tlb_user(void) | |||
552 | * slow), so it's worth separating this from the user flushing above. */ | 577 | * slow), so it's worth separating this from the user flushing above. */ |
553 | static void lguest_flush_tlb_kernel(void) | 578 | static void lguest_flush_tlb_kernel(void) |
554 | { | 579 | { |
555 | lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0); | 580 | lazy_hcall1(LHCALL_FLUSH_TLB, 1); |
556 | } | 581 | } |
557 | 582 | ||
558 | /* | 583 | /* |
@@ -689,7 +714,7 @@ static int lguest_clockevent_set_next_event(unsigned long delta, | |||
689 | } | 714 | } |
690 | 715 | ||
691 | /* Please wake us this far in the future. */ | 716 | /* Please wake us this far in the future. */ |
692 | hcall(LHCALL_SET_CLOCKEVENT, delta, 0, 0); | 717 | kvm_hypercall1(LHCALL_SET_CLOCKEVENT, delta); |
693 | return 0; | 718 | return 0; |
694 | } | 719 | } |
695 | 720 | ||
@@ -700,7 +725,7 @@ static void lguest_clockevent_set_mode(enum clock_event_mode mode, | |||
700 | case CLOCK_EVT_MODE_UNUSED: | 725 | case CLOCK_EVT_MODE_UNUSED: |
701 | case CLOCK_EVT_MODE_SHUTDOWN: | 726 | case CLOCK_EVT_MODE_SHUTDOWN: |
702 | /* A 0 argument shuts the clock down. */ | 727 | /* A 0 argument shuts the clock down. */ |
703 | hcall(LHCALL_SET_CLOCKEVENT, 0, 0, 0); | 728 | kvm_hypercall0(LHCALL_SET_CLOCKEVENT); |
704 | break; | 729 | break; |
705 | case CLOCK_EVT_MODE_ONESHOT: | 730 | case CLOCK_EVT_MODE_ONESHOT: |
706 | /* This is what we expect. */ | 731 | /* This is what we expect. */ |
@@ -775,8 +800,8 @@ static void lguest_time_init(void) | |||
775 | static void lguest_load_sp0(struct tss_struct *tss, | 800 | static void lguest_load_sp0(struct tss_struct *tss, |
776 | struct thread_struct *thread) | 801 | struct thread_struct *thread) |
777 | { | 802 | { |
778 | lazy_hcall(LHCALL_SET_STACK, __KERNEL_DS|0x1, thread->sp0, | 803 | lazy_hcall3(LHCALL_SET_STACK, __KERNEL_DS | 0x1, thread->sp0, |
779 | THREAD_SIZE/PAGE_SIZE); | 804 | THREAD_SIZE / PAGE_SIZE); |
780 | } | 805 | } |
781 | 806 | ||
782 | /* Let's just say, I wouldn't do debugging under a Guest. */ | 807 | /* Let's just say, I wouldn't do debugging under a Guest. */ |
@@ -849,7 +874,7 @@ static void set_lguest_basic_apic_ops(void) | |||
849 | /* STOP! Until an interrupt comes in. */ | 874 | /* STOP! Until an interrupt comes in. */ |
850 | static void lguest_safe_halt(void) | 875 | static void lguest_safe_halt(void) |
851 | { | 876 | { |
852 | hcall(LHCALL_HALT, 0, 0, 0); | 877 | kvm_hypercall0(LHCALL_HALT); |
853 | } | 878 | } |
854 | 879 | ||
855 | /* The SHUTDOWN hypercall takes a string to describe what's happening, and | 880 | /* The SHUTDOWN hypercall takes a string to describe what's happening, and |
@@ -859,7 +884,8 @@ static void lguest_safe_halt(void) | |||
859 | * rather than virtual addresses, so we use __pa() here. */ | 884 | * rather than virtual addresses, so we use __pa() here. */ |
860 | static void lguest_power_off(void) | 885 | static void lguest_power_off(void) |
861 | { | 886 | { |
862 | hcall(LHCALL_SHUTDOWN, __pa("Power down"), LGUEST_SHUTDOWN_POWEROFF, 0); | 887 | kvm_hypercall2(LHCALL_SHUTDOWN, __pa("Power down"), |
888 | LGUEST_SHUTDOWN_POWEROFF); | ||
863 | } | 889 | } |
864 | 890 | ||
865 | /* | 891 | /* |
@@ -869,7 +895,7 @@ static void lguest_power_off(void) | |||
869 | */ | 895 | */ |
870 | static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p) | 896 | static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p) |
871 | { | 897 | { |
872 | hcall(LHCALL_SHUTDOWN, __pa(p), LGUEST_SHUTDOWN_POWEROFF, 0); | 898 | kvm_hypercall2(LHCALL_SHUTDOWN, __pa(p), LGUEST_SHUTDOWN_POWEROFF); |
873 | /* The hcall won't return, but to keep gcc happy, we're "done". */ | 899 | /* The hcall won't return, but to keep gcc happy, we're "done". */ |
874 | return NOTIFY_DONE; | 900 | return NOTIFY_DONE; |
875 | } | 901 | } |
@@ -910,7 +936,7 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count) | |||
910 | len = sizeof(scratch) - 1; | 936 | len = sizeof(scratch) - 1; |
911 | scratch[len] = '\0'; | 937 | scratch[len] = '\0'; |
912 | memcpy(scratch, buf, len); | 938 | memcpy(scratch, buf, len); |
913 | hcall(LHCALL_NOTIFY, __pa(scratch), 0, 0); | 939 | kvm_hypercall1(LHCALL_NOTIFY, __pa(scratch)); |
914 | 940 | ||
915 | /* This routine returns the number of bytes actually written. */ | 941 | /* This routine returns the number of bytes actually written. */ |
916 | return len; | 942 | return len; |
@@ -920,7 +946,7 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count) | |||
920 | * Launcher to reboot us. */ | 946 | * Launcher to reboot us. */ |
921 | static void lguest_restart(char *reason) | 947 | static void lguest_restart(char *reason) |
922 | { | 948 | { |
923 | hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0); | 949 | kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART); |
924 | } | 950 | } |
925 | 951 | ||
926 | /*G:050 | 952 | /*G:050 |
@@ -1040,6 +1066,8 @@ __init void lguest_init(void) | |||
1040 | pv_mmu_ops.read_cr3 = lguest_read_cr3; | 1066 | pv_mmu_ops.read_cr3 = lguest_read_cr3; |
1041 | pv_mmu_ops.lazy_mode.enter = paravirt_enter_lazy_mmu; | 1067 | pv_mmu_ops.lazy_mode.enter = paravirt_enter_lazy_mmu; |
1042 | pv_mmu_ops.lazy_mode.leave = lguest_leave_lazy_mode; | 1068 | pv_mmu_ops.lazy_mode.leave = lguest_leave_lazy_mode; |
1069 | pv_mmu_ops.pte_update = lguest_pte_update; | ||
1070 | pv_mmu_ops.pte_update_defer = lguest_pte_update; | ||
1043 | 1071 | ||
1044 | #ifdef CONFIG_X86_LOCAL_APIC | 1072 | #ifdef CONFIG_X86_LOCAL_APIC |
1045 | /* apic read/write intercepts */ | 1073 | /* apic read/write intercepts */ |
diff --git a/arch/x86/lguest/i386_head.S b/arch/x86/lguest/i386_head.S index 10b9bd35a8ff..f79541989471 100644 --- a/arch/x86/lguest/i386_head.S +++ b/arch/x86/lguest/i386_head.S | |||
@@ -27,8 +27,8 @@ ENTRY(lguest_entry) | |||
27 | /* We make the "initialization" hypercall now to tell the Host about | 27 | /* We make the "initialization" hypercall now to tell the Host about |
28 | * us, and also find out where it put our page tables. */ | 28 | * us, and also find out where it put our page tables. */ |
29 | movl $LHCALL_LGUEST_INIT, %eax | 29 | movl $LHCALL_LGUEST_INIT, %eax |
30 | movl $lguest_data - __PAGE_OFFSET, %edx | 30 | movl $lguest_data - __PAGE_OFFSET, %ebx |
31 | int $LGUEST_TRAP_ENTRY | 31 | .byte 0x0f,0x01,0xc1 /* KVM_HYPERCALL */ |
32 | 32 | ||
33 | /* Set up the initial stack so we can run C code. */ | 33 | /* Set up the initial stack so we can run C code. */ |
34 | movl $(init_thread_union+THREAD_SIZE),%esp | 34 | movl $(init_thread_union+THREAD_SIZE),%esp |
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c index 60156dfdc608..4845fb3cf74b 100644 --- a/drivers/lguest/core.c +++ b/drivers/lguest/core.c | |||
@@ -152,8 +152,8 @@ static void unmap_switcher(void) | |||
152 | * code. We have to check that the range is below the pfn_limit the Launcher | 152 | * code. We have to check that the range is below the pfn_limit the Launcher |
153 | * gave us. We have to make sure that addr + len doesn't give us a false | 153 | * gave us. We have to make sure that addr + len doesn't give us a false |
154 | * positive by overflowing, too. */ | 154 | * positive by overflowing, too. */ |
155 | int lguest_address_ok(const struct lguest *lg, | 155 | bool lguest_address_ok(const struct lguest *lg, |
156 | unsigned long addr, unsigned long len) | 156 | unsigned long addr, unsigned long len) |
157 | { | 157 | { |
158 | return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr); | 158 | return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr); |
159 | } | 159 | } |
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c index 415fab0125ac..6e99adbe1946 100644 --- a/drivers/lguest/interrupts_and_traps.c +++ b/drivers/lguest/interrupts_and_traps.c | |||
@@ -34,7 +34,7 @@ static int idt_type(u32 lo, u32 hi) | |||
34 | } | 34 | } |
35 | 35 | ||
36 | /* An IDT entry can't be used unless the "present" bit is set. */ | 36 | /* An IDT entry can't be used unless the "present" bit is set. */ |
37 | static int idt_present(u32 lo, u32 hi) | 37 | static bool idt_present(u32 lo, u32 hi) |
38 | { | 38 | { |
39 | return (hi & 0x8000); | 39 | return (hi & 0x8000); |
40 | } | 40 | } |
@@ -60,7 +60,8 @@ static void push_guest_stack(struct lg_cpu *cpu, unsigned long *gstack, u32 val) | |||
60 | * We set up the stack just like the CPU does for a real interrupt, so it's | 60 | * We set up the stack just like the CPU does for a real interrupt, so it's |
61 | * identical for the Guest (and the standard "iret" instruction will undo | 61 | * identical for the Guest (and the standard "iret" instruction will undo |
62 | * it). */ | 62 | * it). */ |
63 | static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, int has_err) | 63 | static void set_guest_interrupt(struct lg_cpu *cpu, u32 lo, u32 hi, |
64 | bool has_err) | ||
64 | { | 65 | { |
65 | unsigned long gstack, origstack; | 66 | unsigned long gstack, origstack; |
66 | u32 eflags, ss, irq_enable; | 67 | u32 eflags, ss, irq_enable; |
@@ -184,7 +185,7 @@ void maybe_do_interrupt(struct lg_cpu *cpu) | |||
184 | /* set_guest_interrupt() takes the interrupt descriptor and a | 185 | /* set_guest_interrupt() takes the interrupt descriptor and a |
185 | * flag to say whether this interrupt pushes an error code onto | 186 | * flag to say whether this interrupt pushes an error code onto |
186 | * the stack as well: virtual interrupts never do. */ | 187 | * the stack as well: virtual interrupts never do. */ |
187 | set_guest_interrupt(cpu, idt->a, idt->b, 0); | 188 | set_guest_interrupt(cpu, idt->a, idt->b, false); |
188 | } | 189 | } |
189 | 190 | ||
190 | /* Every time we deliver an interrupt, we update the timestamp in the | 191 | /* Every time we deliver an interrupt, we update the timestamp in the |
@@ -244,26 +245,26 @@ void free_interrupts(void) | |||
244 | /*H:220 Now we've got the routines to deliver interrupts, delivering traps like | 245 | /*H:220 Now we've got the routines to deliver interrupts, delivering traps like |
245 | * page fault is easy. The only trick is that Intel decided that some traps | 246 | * page fault is easy. The only trick is that Intel decided that some traps |
246 | * should have error codes: */ | 247 | * should have error codes: */ |
247 | static int has_err(unsigned int trap) | 248 | static bool has_err(unsigned int trap) |
248 | { | 249 | { |
249 | return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17); | 250 | return (trap == 8 || (trap >= 10 && trap <= 14) || trap == 17); |
250 | } | 251 | } |
251 | 252 | ||
252 | /* deliver_trap() returns true if it could deliver the trap. */ | 253 | /* deliver_trap() returns true if it could deliver the trap. */ |
253 | int deliver_trap(struct lg_cpu *cpu, unsigned int num) | 254 | bool deliver_trap(struct lg_cpu *cpu, unsigned int num) |
254 | { | 255 | { |
255 | /* Trap numbers are always 8 bit, but we set an impossible trap number | 256 | /* Trap numbers are always 8 bit, but we set an impossible trap number |
256 | * for traps inside the Switcher, so check that here. */ | 257 | * for traps inside the Switcher, so check that here. */ |
257 | if (num >= ARRAY_SIZE(cpu->arch.idt)) | 258 | if (num >= ARRAY_SIZE(cpu->arch.idt)) |
258 | return 0; | 259 | return false; |
259 | 260 | ||
260 | /* Early on the Guest hasn't set the IDT entries (or maybe it put a | 261 | /* Early on the Guest hasn't set the IDT entries (or maybe it put a |
261 | * bogus one in): if we fail here, the Guest will be killed. */ | 262 | * bogus one in): if we fail here, the Guest will be killed. */ |
262 | if (!idt_present(cpu->arch.idt[num].a, cpu->arch.idt[num].b)) | 263 | if (!idt_present(cpu->arch.idt[num].a, cpu->arch.idt[num].b)) |
263 | return 0; | 264 | return false; |
264 | set_guest_interrupt(cpu, cpu->arch.idt[num].a, | 265 | set_guest_interrupt(cpu, cpu->arch.idt[num].a, |
265 | cpu->arch.idt[num].b, has_err(num)); | 266 | cpu->arch.idt[num].b, has_err(num)); |
266 | return 1; | 267 | return true; |
267 | } | 268 | } |
268 | 269 | ||
269 | /*H:250 Here's the hard part: returning to the Host every time a trap happens | 270 | /*H:250 Here's the hard part: returning to the Host every time a trap happens |
@@ -279,18 +280,19 @@ int deliver_trap(struct lg_cpu *cpu, unsigned int num) | |||
279 | * | 280 | * |
280 | * This routine indicates if a particular trap number could be delivered | 281 | * This routine indicates if a particular trap number could be delivered |
281 | * directly. */ | 282 | * directly. */ |
282 | static int direct_trap(unsigned int num) | 283 | static bool direct_trap(unsigned int num) |
283 | { | 284 | { |
284 | /* Hardware interrupts don't go to the Guest at all (except system | 285 | /* Hardware interrupts don't go to the Guest at all (except system |
285 | * call). */ | 286 | * call). */ |
286 | if (num >= FIRST_EXTERNAL_VECTOR && !could_be_syscall(num)) | 287 | if (num >= FIRST_EXTERNAL_VECTOR && !could_be_syscall(num)) |
287 | return 0; | 288 | return false; |
288 | 289 | ||
289 | /* The Host needs to see page faults (for shadow paging and to save the | 290 | /* The Host needs to see page faults (for shadow paging and to save the |
290 | * fault address), general protection faults (in/out emulation) and | 291 | * fault address), general protection faults (in/out emulation) and |
291 | * device not available (TS handling), and of course, the hypercall | 292 | * device not available (TS handling), invalid opcode fault (kvm hcall), |
292 | * trap. */ | 293 | * and of course, the hypercall trap. */ |
293 | return num != 14 && num != 13 && num != 7 && num != LGUEST_TRAP_ENTRY; | 294 | return num != 14 && num != 13 && num != 7 && |
295 | num != 6 && num != LGUEST_TRAP_ENTRY; | ||
294 | } | 296 | } |
295 | /*:*/ | 297 | /*:*/ |
296 | 298 | ||
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h index f2c641e0bdde..ac8a4a3741b8 100644 --- a/drivers/lguest/lg.h +++ b/drivers/lguest/lg.h | |||
@@ -109,8 +109,8 @@ struct lguest | |||
109 | extern struct mutex lguest_lock; | 109 | extern struct mutex lguest_lock; |
110 | 110 | ||
111 | /* core.c: */ | 111 | /* core.c: */ |
112 | int lguest_address_ok(const struct lguest *lg, | 112 | bool lguest_address_ok(const struct lguest *lg, |
113 | unsigned long addr, unsigned long len); | 113 | unsigned long addr, unsigned long len); |
114 | void __lgread(struct lg_cpu *, void *, unsigned long, unsigned); | 114 | void __lgread(struct lg_cpu *, void *, unsigned long, unsigned); |
115 | void __lgwrite(struct lg_cpu *, unsigned long, const void *, unsigned); | 115 | void __lgwrite(struct lg_cpu *, unsigned long, const void *, unsigned); |
116 | 116 | ||
@@ -140,7 +140,7 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user); | |||
140 | 140 | ||
141 | /* interrupts_and_traps.c: */ | 141 | /* interrupts_and_traps.c: */ |
142 | void maybe_do_interrupt(struct lg_cpu *cpu); | 142 | void maybe_do_interrupt(struct lg_cpu *cpu); |
143 | int deliver_trap(struct lg_cpu *cpu, unsigned int num); | 143 | bool deliver_trap(struct lg_cpu *cpu, unsigned int num); |
144 | void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i, | 144 | void load_guest_idt_entry(struct lg_cpu *cpu, unsigned int i, |
145 | u32 low, u32 hi); | 145 | u32 low, u32 hi); |
146 | void guest_set_stack(struct lg_cpu *cpu, u32 seg, u32 esp, unsigned int pages); | 146 | void guest_set_stack(struct lg_cpu *cpu, u32 seg, u32 esp, unsigned int pages); |
@@ -173,7 +173,7 @@ void guest_pagetable_flush_user(struct lg_cpu *cpu); | |||
173 | void guest_set_pte(struct lg_cpu *cpu, unsigned long gpgdir, | 173 | void guest_set_pte(struct lg_cpu *cpu, unsigned long gpgdir, |
174 | unsigned long vaddr, pte_t val); | 174 | unsigned long vaddr, pte_t val); |
175 | void map_switcher_in_guest(struct lg_cpu *cpu, struct lguest_pages *pages); | 175 | void map_switcher_in_guest(struct lg_cpu *cpu, struct lguest_pages *pages); |
176 | int demand_page(struct lg_cpu *cpu, unsigned long cr2, int errcode); | 176 | bool demand_page(struct lg_cpu *cpu, unsigned long cr2, int errcode); |
177 | void pin_page(struct lg_cpu *cpu, unsigned long vaddr); | 177 | void pin_page(struct lg_cpu *cpu, unsigned long vaddr); |
178 | unsigned long guest_pa(struct lg_cpu *cpu, unsigned long vaddr); | 178 | unsigned long guest_pa(struct lg_cpu *cpu, unsigned long vaddr); |
179 | void page_table_guest_data_init(struct lg_cpu *cpu); | 179 | void page_table_guest_data_init(struct lg_cpu *cpu); |
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c index 8132533d71f9..df44d962626d 100644 --- a/drivers/lguest/lguest_device.c +++ b/drivers/lguest/lguest_device.c | |||
@@ -161,7 +161,7 @@ static void set_status(struct virtio_device *vdev, u8 status) | |||
161 | 161 | ||
162 | /* We set the status. */ | 162 | /* We set the status. */ |
163 | to_lgdev(vdev)->desc->status = status; | 163 | to_lgdev(vdev)->desc->status = status; |
164 | hcall(LHCALL_NOTIFY, (max_pfn<<PAGE_SHIFT) + offset, 0, 0); | 164 | kvm_hypercall1(LHCALL_NOTIFY, (max_pfn << PAGE_SHIFT) + offset); |
165 | } | 165 | } |
166 | 166 | ||
167 | static void lg_set_status(struct virtio_device *vdev, u8 status) | 167 | static void lg_set_status(struct virtio_device *vdev, u8 status) |
@@ -209,7 +209,7 @@ static void lg_notify(struct virtqueue *vq) | |||
209 | * virtqueue structure. */ | 209 | * virtqueue structure. */ |
210 | struct lguest_vq_info *lvq = vq->priv; | 210 | struct lguest_vq_info *lvq = vq->priv; |
211 | 211 | ||
212 | hcall(LHCALL_NOTIFY, lvq->config.pfn << PAGE_SHIFT, 0, 0); | 212 | kvm_hypercall1(LHCALL_NOTIFY, lvq->config.pfn << PAGE_SHIFT); |
213 | } | 213 | } |
214 | 214 | ||
215 | /* An extern declaration inside a C file is bad form. Don't do it. */ | 215 | /* An extern declaration inside a C file is bad form. Don't do it. */ |
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)) |
diff --git a/drivers/lguest/segments.c b/drivers/lguest/segments.c index ec6aa3f1c36b..4f15439b7f12 100644 --- a/drivers/lguest/segments.c +++ b/drivers/lguest/segments.c | |||
@@ -45,7 +45,7 @@ | |||
45 | * "Task State Segment" which controls all kinds of delicate things. The | 45 | * "Task State Segment" which controls all kinds of delicate things. The |
46 | * LGUEST_CS and LGUEST_DS entries are reserved for the Switcher, and the | 46 | * LGUEST_CS and LGUEST_DS entries are reserved for the Switcher, and the |
47 | * the Guest can't be trusted to deal with double faults. */ | 47 | * the Guest can't be trusted to deal with double faults. */ |
48 | static int ignored_gdt(unsigned int num) | 48 | static bool ignored_gdt(unsigned int num) |
49 | { | 49 | { |
50 | return (num == GDT_ENTRY_TSS | 50 | return (num == GDT_ENTRY_TSS |
51 | || num == GDT_ENTRY_LGUEST_CS | 51 | || num == GDT_ENTRY_LGUEST_CS |
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c index bf7942327bda..a6b717644be0 100644 --- a/drivers/lguest/x86/core.c +++ b/drivers/lguest/x86/core.c | |||
@@ -290,6 +290,57 @@ static int emulate_insn(struct lg_cpu *cpu) | |||
290 | return 1; | 290 | return 1; |
291 | } | 291 | } |
292 | 292 | ||
293 | /* Our hypercalls mechanism used to be based on direct software interrupts. | ||
294 | * After Anthony's "Refactor hypercall infrastructure" kvm patch, we decided to | ||
295 | * change over to using kvm hypercalls. | ||
296 | * | ||
297 | * KVM_HYPERCALL is actually a "vmcall" instruction, which generates an invalid | ||
298 | * opcode fault (fault 6) on non-VT cpus, so the easiest solution seemed to be | ||
299 | * an *emulation approach*: if the fault was really produced by an hypercall | ||
300 | * (is_hypercall() does exactly this check), we can just call the corresponding | ||
301 | * hypercall host implementation function. | ||
302 | * | ||
303 | * But these invalid opcode faults are notably slower than software interrupts. | ||
304 | * So we implemented the *patching (or rewriting) approach*: every time we hit | ||
305 | * the KVM_HYPERCALL opcode in Guest code, we patch it to the old "int 0x1f" | ||
306 | * opcode, so next time the Guest calls this hypercall it will use the | ||
307 | * faster trap mechanism. | ||
308 | * | ||
309 | * Matias even benchmarked it to convince you: this shows the average cycle | ||
310 | * cost of a hypercall. For each alternative solution mentioned above we've | ||
311 | * made 5 runs of the benchmark: | ||
312 | * | ||
313 | * 1) direct software interrupt: 2915, 2789, 2764, 2721, 2898 | ||
314 | * 2) emulation technique: 3410, 3681, 3466, 3392, 3780 | ||
315 | * 3) patching (rewrite) technique: 2977, 2975, 2891, 2637, 2884 | ||
316 | * | ||
317 | * One two-line function is worth a 20% hypercall speed boost! | ||
318 | */ | ||
319 | static void rewrite_hypercall(struct lg_cpu *cpu) | ||
320 | { | ||
321 | /* This are the opcodes we use to patch the Guest. The opcode for "int | ||
322 | * $0x1f" is "0xcd 0x1f" but vmcall instruction is 3 bytes long, so we | ||
323 | * complete the sequence with a NOP (0x90). */ | ||
324 | u8 insn[3] = {0xcd, 0x1f, 0x90}; | ||
325 | |||
326 | __lgwrite(cpu, guest_pa(cpu, cpu->regs->eip), insn, sizeof(insn)); | ||
327 | } | ||
328 | |||
329 | static bool is_hypercall(struct lg_cpu *cpu) | ||
330 | { | ||
331 | u8 insn[3]; | ||
332 | |||
333 | /* This must be the Guest kernel trying to do something. | ||
334 | * The bottom two bits of the CS segment register are the privilege | ||
335 | * level. */ | ||
336 | if ((cpu->regs->cs & 3) != GUEST_PL) | ||
337 | return false; | ||
338 | |||
339 | /* Is it a vmcall? */ | ||
340 | __lgread(cpu, insn, guest_pa(cpu, cpu->regs->eip), sizeof(insn)); | ||
341 | return insn[0] == 0x0f && insn[1] == 0x01 && insn[2] == 0xc1; | ||
342 | } | ||
343 | |||
293 | /*H:050 Once we've re-enabled interrupts, we look at why the Guest exited. */ | 344 | /*H:050 Once we've re-enabled interrupts, we look at why the Guest exited. */ |
294 | void lguest_arch_handle_trap(struct lg_cpu *cpu) | 345 | void lguest_arch_handle_trap(struct lg_cpu *cpu) |
295 | { | 346 | { |
@@ -337,7 +388,7 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu) | |||
337 | break; | 388 | break; |
338 | case 32 ... 255: | 389 | case 32 ... 255: |
339 | /* These values mean a real interrupt occurred, in which case | 390 | /* These values mean a real interrupt occurred, in which case |
340 | * the Host handler has already been run. We just do a | 391 | * the Host handler has already been run. We just do a |
341 | * friendly check if another process should now be run, then | 392 | * friendly check if another process should now be run, then |
342 | * return to run the Guest again */ | 393 | * return to run the Guest again */ |
343 | cond_resched(); | 394 | cond_resched(); |
@@ -347,6 +398,15 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu) | |||
347 | * up the pointer now to indicate a hypercall is pending. */ | 398 | * up the pointer now to indicate a hypercall is pending. */ |
348 | cpu->hcall = (struct hcall_args *)cpu->regs; | 399 | cpu->hcall = (struct hcall_args *)cpu->regs; |
349 | return; | 400 | return; |
401 | case 6: | ||
402 | /* kvm hypercalls trigger an invalid opcode fault (6). | ||
403 | * We need to check if ring == GUEST_PL and | ||
404 | * faulting instruction == vmcall. */ | ||
405 | if (is_hypercall(cpu)) { | ||
406 | rewrite_hypercall(cpu); | ||
407 | return; | ||
408 | } | ||
409 | break; | ||
350 | } | 410 | } |
351 | 411 | ||
352 | /* We didn't handle the trap, so it needs to go to the Guest. */ | 412 | /* We didn't handle the trap, so it needs to go to the Guest. */ |
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 5777196bf6c9..5c52369ab9bb 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -23,15 +23,21 @@ | |||
23 | 23 | ||
24 | #ifdef DEBUG | 24 | #ifdef DEBUG |
25 | /* For development, we want to crash whenever the ring is screwed. */ | 25 | /* For development, we want to crash whenever the ring is screwed. */ |
26 | #define BAD_RING(vq, fmt...) \ | 26 | #define BAD_RING(_vq, fmt...) \ |
27 | do { dev_err(&vq->vq.vdev->dev, fmt); BUG(); } while(0) | 27 | do { dev_err(&(_vq)->vq.vdev->dev, fmt); BUG(); } while(0) |
28 | #define START_USE(vq) \ | 28 | /* Caller is supposed to guarantee no reentry. */ |
29 | do { if ((vq)->in_use) panic("in_use = %i\n", (vq)->in_use); (vq)->in_use = __LINE__; mb(); } while(0) | 29 | #define START_USE(_vq) \ |
30 | #define END_USE(vq) \ | 30 | do { \ |
31 | do { BUG_ON(!(vq)->in_use); (vq)->in_use = 0; mb(); } while(0) | 31 | if ((_vq)->in_use) \ |
32 | panic("in_use = %i\n", (_vq)->in_use); \ | ||
33 | (_vq)->in_use = __LINE__; \ | ||
34 | mb(); \ | ||
35 | } while(0) | ||
36 | #define END_USE(_vq) \ | ||
37 | do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; mb(); } while(0) | ||
32 | #else | 38 | #else |
33 | #define BAD_RING(vq, fmt...) \ | 39 | #define BAD_RING(_vq, fmt...) \ |
34 | do { dev_err(&vq->vq.vdev->dev, fmt); (vq)->broken = true; } while(0) | 40 | do { dev_err(&_vq->vq.vdev->dev, fmt); (_vq)->broken = true; } while(0) |
35 | #define START_USE(vq) | 41 | #define START_USE(vq) |
36 | #define END_USE(vq) | 42 | #define END_USE(vq) |
37 | #endif | 43 | #endif |