aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddie Dong <eddie.dong@intel.com>2007-07-18 04:34:57 -0400
committerAvi Kivity <avi@qumranet.com>2007-10-13 04:18:25 -0400
commit7017fc3d1a12e30ea7df4992152978a188433457 (patch)
treeebbe0e5852ddd58bddfed389412c86c7692d2724
parent85f455f7ddbed403b34b4d54b1eaf0e14126a126 (diff)
KVM: Define and use cr8 access functions
This patch is to wrap APIC base register and CR8 operation which can provide a unique API for user level irqchip and kernel irqchip. This is a preparation of merging lapic/ioapic patch. Signed-off-by: Yaozu (Eddie) Dong <eddie.dong@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--drivers/kvm/kvm.h3
-rw-r--r--drivers/kvm/kvm_main.c32
-rw-r--r--drivers/kvm/svm.c8
-rw-r--r--drivers/kvm/vmx.c14
4 files changed, 40 insertions, 17 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index d71712ddebee..e0a2f13faf8b 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -568,6 +568,9 @@ void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
568void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0); 568void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0);
569void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0); 569void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
570void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0); 570void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
571unsigned long get_cr8(struct kvm_vcpu *vcpu);
572u64 kvm_get_apic_base(struct kvm_vcpu *vcpu);
573void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data);
571void lmsw(struct kvm_vcpu *vcpu, unsigned long msw); 574void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
572 575
573int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata); 576int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 09a04bc9541d..f879efbefcdf 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -602,6 +602,24 @@ void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
602} 602}
603EXPORT_SYMBOL_GPL(set_cr8); 603EXPORT_SYMBOL_GPL(set_cr8);
604 604
605unsigned long get_cr8(struct kvm_vcpu *vcpu)
606{
607 return vcpu->cr8;
608}
609EXPORT_SYMBOL_GPL(get_cr8);
610
611u64 kvm_get_apic_base(struct kvm_vcpu *vcpu)
612{
613 return vcpu->apic_base;
614}
615EXPORT_SYMBOL_GPL(kvm_get_apic_base);
616
617void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data)
618{
619 vcpu->apic_base = data;
620}
621EXPORT_SYMBOL_GPL(kvm_set_apic_base);
622
605void fx_init(struct kvm_vcpu *vcpu) 623void fx_init(struct kvm_vcpu *vcpu)
606{ 624{
607 unsigned after_mxcsr_mask; 625 unsigned after_mxcsr_mask;
@@ -1481,7 +1499,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1481 data = 3; 1499 data = 3;
1482 break; 1500 break;
1483 case MSR_IA32_APICBASE: 1501 case MSR_IA32_APICBASE:
1484 data = vcpu->apic_base; 1502 data = kvm_get_apic_base(vcpu);
1485 break; 1503 break;
1486 case MSR_IA32_MISC_ENABLE: 1504 case MSR_IA32_MISC_ENABLE:
1487 data = vcpu->ia32_misc_enable_msr; 1505 data = vcpu->ia32_misc_enable_msr;
@@ -1559,7 +1577,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1559 case 0x200 ... 0x2ff: /* MTRRs */ 1577 case 0x200 ... 0x2ff: /* MTRRs */
1560 break; 1578 break;
1561 case MSR_IA32_APICBASE: 1579 case MSR_IA32_APICBASE:
1562 vcpu->apic_base = data; 1580 kvm_set_apic_base(vcpu, data);
1563 break; 1581 break;
1564 case MSR_IA32_MISC_ENABLE: 1582 case MSR_IA32_MISC_ENABLE:
1565 vcpu->ia32_misc_enable_msr = data; 1583 vcpu->ia32_misc_enable_msr = data;
@@ -1865,7 +1883,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1865 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 1883 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
1866 1884
1867 /* re-sync apic's tpr */ 1885 /* re-sync apic's tpr */
1868 vcpu->cr8 = kvm_run->cr8; 1886 set_cr8(vcpu, kvm_run->cr8);
1869 1887
1870 if (vcpu->pio.cur_count) { 1888 if (vcpu->pio.cur_count) {
1871 r = complete_pio(vcpu); 1889 r = complete_pio(vcpu);
@@ -2013,9 +2031,9 @@ static int kvm_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
2013 sregs->cr2 = vcpu->cr2; 2031 sregs->cr2 = vcpu->cr2;
2014 sregs->cr3 = vcpu->cr3; 2032 sregs->cr3 = vcpu->cr3;
2015 sregs->cr4 = vcpu->cr4; 2033 sregs->cr4 = vcpu->cr4;
2016 sregs->cr8 = vcpu->cr8; 2034 sregs->cr8 = get_cr8(vcpu);
2017 sregs->efer = vcpu->shadow_efer; 2035 sregs->efer = vcpu->shadow_efer;
2018 sregs->apic_base = vcpu->apic_base; 2036 sregs->apic_base = kvm_get_apic_base(vcpu);
2019 2037
2020 memcpy(sregs->interrupt_bitmap, vcpu->irq_pending, 2038 memcpy(sregs->interrupt_bitmap, vcpu->irq_pending,
2021 sizeof sregs->interrupt_bitmap); 2039 sizeof sregs->interrupt_bitmap);
@@ -2051,13 +2069,13 @@ static int kvm_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
2051 mmu_reset_needed |= vcpu->cr3 != sregs->cr3; 2069 mmu_reset_needed |= vcpu->cr3 != sregs->cr3;
2052 vcpu->cr3 = sregs->cr3; 2070 vcpu->cr3 = sregs->cr3;
2053 2071
2054 vcpu->cr8 = sregs->cr8; 2072 set_cr8(vcpu, sregs->cr8);
2055 2073
2056 mmu_reset_needed |= vcpu->shadow_efer != sregs->efer; 2074 mmu_reset_needed |= vcpu->shadow_efer != sregs->efer;
2057#ifdef CONFIG_X86_64 2075#ifdef CONFIG_X86_64
2058 kvm_arch_ops->set_efer(vcpu, sregs->efer); 2076 kvm_arch_ops->set_efer(vcpu, sregs->efer);
2059#endif 2077#endif
2060 vcpu->apic_base = sregs->apic_base; 2078 kvm_set_apic_base(vcpu, sregs->apic_base);
2061 2079
2062 kvm_arch_ops->decache_cr4_guest_bits(vcpu); 2080 kvm_arch_ops->decache_cr4_guest_bits(vcpu);
2063 2081
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 2237a594a8ef..57525e7ed28f 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1339,10 +1339,10 @@ static void svm_intr_assist(struct vcpu_svm *svm)
1339 1339
1340static void kvm_reput_irq(struct vcpu_svm *svm) 1340static void kvm_reput_irq(struct vcpu_svm *svm)
1341{ 1341{
1342 struct kvm_vcpu *vcpu = &svm->vcpu;
1343 struct vmcb_control_area *control = &svm->vmcb->control; 1342 struct vmcb_control_area *control = &svm->vmcb->control;
1344 1343
1345 if ((control->int_ctl & V_IRQ_MASK) && !irqchip_in_kernel(vcpu->kvm)) { 1344 if ((control->int_ctl & V_IRQ_MASK)
1345 && !irqchip_in_kernel(svm->vcpu.kvm)) {
1346 control->int_ctl &= ~V_IRQ_MASK; 1346 control->int_ctl &= ~V_IRQ_MASK;
1347 push_irq(&svm->vcpu, control->int_vector); 1347 push_irq(&svm->vcpu, control->int_vector);
1348 } 1348 }
@@ -1396,8 +1396,8 @@ static void post_kvm_run_save(struct vcpu_svm *svm,
1396 = (svm->vcpu.interrupt_window_open && 1396 = (svm->vcpu.interrupt_window_open &&
1397 svm->vcpu.irq_summary == 0); 1397 svm->vcpu.irq_summary == 0);
1398 kvm_run->if_flag = (svm->vmcb->save.rflags & X86_EFLAGS_IF) != 0; 1398 kvm_run->if_flag = (svm->vmcb->save.rflags & X86_EFLAGS_IF) != 0;
1399 kvm_run->cr8 = svm->vcpu.cr8; 1399 kvm_run->cr8 = get_cr8(&svm->vcpu);
1400 kvm_run->apic_base = svm->vcpu.apic_base; 1400 kvm_run->apic_base = kvm_get_apic_base(&svm->vcpu);
1401} 1401}
1402 1402
1403/* 1403/*
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index f1e80a95b69d..19676b5a6719 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1369,6 +1369,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
1369 int i; 1369 int i;
1370 int ret = 0; 1370 int ret = 0;
1371 unsigned long kvm_vmx_return; 1371 unsigned long kvm_vmx_return;
1372 u64 msr;
1372 1373
1373 if (!init_rmode_tss(vmx->vcpu.kvm)) { 1374 if (!init_rmode_tss(vmx->vcpu.kvm)) {
1374 ret = -ENOMEM; 1375 ret = -ENOMEM;
@@ -1376,10 +1377,11 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
1376 } 1377 }
1377 1378
1378 vmx->vcpu.regs[VCPU_REGS_RDX] = get_rdx_init_val(); 1379 vmx->vcpu.regs[VCPU_REGS_RDX] = get_rdx_init_val();
1379 vmx->vcpu.cr8 = 0; 1380 set_cr8(&vmx->vcpu, 0);
1380 vmx->vcpu.apic_base = 0xfee00000 | MSR_IA32_APICBASE_ENABLE; 1381 msr = 0xfee00000 | MSR_IA32_APICBASE_ENABLE;
1381 if (vmx->vcpu.vcpu_id == 0) 1382 if (vmx->vcpu.vcpu_id == 0)
1382 vmx->vcpu.apic_base |= MSR_IA32_APICBASE_BSP; 1383 msr |= MSR_IA32_APICBASE_BSP;
1384 kvm_set_apic_base(&vmx->vcpu, msr);
1383 1385
1384 fx_init(&vmx->vcpu); 1386 fx_init(&vmx->vcpu);
1385 1387
@@ -1860,7 +1862,7 @@ static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1860 return 1; 1862 return 1;
1861 case 8: 1863 case 8:
1862 vcpu_load_rsp_rip(vcpu); 1864 vcpu_load_rsp_rip(vcpu);
1863 vcpu->regs[reg] = vcpu->cr8; 1865 vcpu->regs[reg] = get_cr8(vcpu);
1864 vcpu_put_rsp_rip(vcpu); 1866 vcpu_put_rsp_rip(vcpu);
1865 skip_emulated_instruction(vcpu); 1867 skip_emulated_instruction(vcpu);
1866 return 1; 1868 return 1;
@@ -1957,8 +1959,8 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu,
1957 struct kvm_run *kvm_run) 1959 struct kvm_run *kvm_run)
1958{ 1960{
1959 kvm_run->if_flag = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) != 0; 1961 kvm_run->if_flag = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) != 0;
1960 kvm_run->cr8 = vcpu->cr8; 1962 kvm_run->cr8 = get_cr8(vcpu);
1961 kvm_run->apic_base = vcpu->apic_base; 1963 kvm_run->apic_base = kvm_get_apic_base(vcpu);
1962 kvm_run->ready_for_interrupt_injection = (vcpu->interrupt_window_open && 1964 kvm_run->ready_for_interrupt_injection = (vcpu->interrupt_window_open &&
1963 vcpu->irq_summary == 0); 1965 vcpu->irq_summary == 0);
1964} 1966}