aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/lguest
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-03-30 20:57:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-03-30 20:57:39 -0400
commitdb6f204019380c788f1de06ee937bdbccd60e5c0 (patch)
treef8ca32ab6932a21797dbc5aa77688ea017959da0 /arch/x86/lguest
parent3c6fae67d026d57f64eb3da9c0d0e76983e39ae3 (diff)
parentd1881d3192a3d3e8dc4f255b03187f4c36cb0617 (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 'arch/x86/lguest')
-rw-r--r--arch/x86/lguest/boot.c86
-rw-r--r--arch/x86/lguest/i386_head.S4
2 files changed, 59 insertions, 31 deletions
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: */
137static void lazy_hcall(unsigned long call, 137static 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
146static 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
156static 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,
150static void lguest_leave_lazy_mode(void) 169static 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 */
262static void lguest_load_gdt(const struct desc_ptr *desc) 281static 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,
382static unsigned long current_cr0; 401static unsigned long current_cr0;
383static void lguest_write_cr0(unsigned long val) 402static 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. */
397static void lguest_clts(void) 416static 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;
418static void lguest_write_cr3(unsigned long cr3) 437static 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). */
512static 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
493static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr, 518static 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,
503static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval) 528static 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)
536static void lguest_flush_tlb_single(unsigned long addr) 561static 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. */
545static void lguest_flush_tlb_user(void) 570static 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. */
553static void lguest_flush_tlb_kernel(void) 578static 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)
775static void lguest_load_sp0(struct tss_struct *tss, 800static 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. */
850static void lguest_safe_halt(void) 875static 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. */
860static void lguest_power_off(void) 885static 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 */
870static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p) 896static 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. */
921static void lguest_restart(char *reason) 947static 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