[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 13/31] xen/x86: allow disabling the emulated local apic
Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx> Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> Cc: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@xxxxxxx> Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Cc: Jun Nakajima <jun.nakajima@xxxxxxxxx> Cc: Eddie Dong <eddie.dong@xxxxxxxxx> Cc: Kevin Tian <kevin.tian@xxxxxxxxx> --- xen/arch/x86/hvm/svm/svm.c | 16 +++++++++------- xen/arch/x86/hvm/vlapic.c | 30 +++++++++++++++++++++++++----- xen/arch/x86/hvm/vmsi.c | 6 ++++++ xen/arch/x86/hvm/vmx/vmcs.c | 14 ++++++++++++++ xen/arch/x86/hvm/vmx/vmx.c | 9 ++++++++- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 8de41fa..97dc507 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1035,6 +1035,7 @@ static void noreturn svm_do_resume(struct vcpu *v) struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; bool_t debug_state = v->domain->debugger_attached; bool_t vcpu_guestmode = 0; + struct vlapic *vlapic = vcpu_vlapic(v); if ( nestedhvm_enabled(v->domain) && nestedhvm_vcpu_in_guestmode(v) ) vcpu_guestmode = 1; @@ -1058,14 +1059,14 @@ static void noreturn svm_do_resume(struct vcpu *v) hvm_asid_flush_vcpu(v); } - if ( !vcpu_guestmode ) + if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) ) { vintr_t intr; /* Reflect the vlapic's TPR in the hardware vtpr */ intr = vmcb_get_vintr(vmcb); intr.fields.tpr = - (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0xFF) >> 4; + (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4; vmcb_set_vintr(vmcb, intr); } @@ -2294,6 +2295,7 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) int inst_len, rc; vintr_t intr; bool_t vcpu_guestmode = 0; + struct vlapic *vlapic = vcpu_vlapic(v); hvm_invalidate_regs_fields(regs); @@ -2311,11 +2313,11 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) * NB. We need to preserve the low bits of the TPR to make checked builds * of Windows work, even though they don't actually do anything. */ - if ( !vcpu_guestmode ) { + if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) ) { intr = vmcb_get_vintr(vmcb); - vlapic_set_reg(vcpu_vlapic(v), APIC_TASKPRI, + vlapic_set_reg(vlapic, APIC_TASKPRI, ((intr.fields.tpr & 0x0F) << 4) | - (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0x0F)); + (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0x0F)); } exit_reason = vmcb->exitcode; @@ -2697,14 +2699,14 @@ void svm_vmexit_handler(struct cpu_user_regs *regs) } out: - if ( vcpu_guestmode ) + if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) ) /* Don't clobber TPR of the nested guest. */ return; /* The exit may have updated the TPR: reflect this in the hardware vtpr */ intr = vmcb_get_vintr(vmcb); intr.fields.tpr = - (vlapic_get_reg(vcpu_vlapic(v), APIC_TASKPRI) & 0xFF) >> 4; + (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4; vmcb_set_vintr(vmcb, intr); } diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index b893b40..e355679 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -993,6 +993,9 @@ static void set_x2apic_id(struct vlapic *vlapic) bool_t vlapic_msr_set(struct vlapic *vlapic, uint64_t value) { + if ( !has_vlapic(vlapic_domain(vlapic)) ) + return 0; + if ( (vlapic->hw.apic_base_msr ^ value) & MSR_IA32_APICBASE_ENABLE ) { if ( unlikely(value & MSR_IA32_APICBASE_EXTD) ) @@ -1042,8 +1045,7 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) uint64_t guest_tsc; struct vcpu *v = vlapic_vcpu(vlapic); - /* may need to exclude some other conditions like vlapic->hw.disabled */ - if ( !vlapic_lvtt_tdt(vlapic) ) + if ( !vlapic_lvtt_tdt(vlapic) || vlapic_hw_disabled(vlapic) ) { HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER, "ignore tsc deadline msr write"); return; @@ -1118,6 +1120,9 @@ static int __vlapic_accept_pic_intr(struct vcpu *v) int vlapic_accept_pic_intr(struct vcpu *v) { + if ( vlapic_hw_disabled(vcpu_vlapic(v)) ) + return 0; + TRACE_2D(TRC_HVM_EMUL_LAPIC_PIC_INTR, (v == v->domain->arch.hvm_domain.i8259_target), v ? __vlapic_accept_pic_intr(v) : -1); @@ -1265,6 +1270,9 @@ static int lapic_save_hidden(struct domain *d, hvm_domain_context_t *h) struct vlapic *s; int rc = 0; + if ( !has_vlapic(d) ) + return 0; + for_each_vcpu ( d, v ) { s = vcpu_vlapic(v); @@ -1281,6 +1289,9 @@ static int lapic_save_regs(struct domain *d, hvm_domain_context_t *h) struct vlapic *s; int rc = 0; + if ( !has_vlapic(d) ) + return 0; + for_each_vcpu ( d, v ) { if ( hvm_funcs.sync_pir_to_irr ) @@ -1328,7 +1339,10 @@ static int lapic_load_hidden(struct domain *d, hvm_domain_context_t *h) uint16_t vcpuid; struct vcpu *v; struct vlapic *s; - + + if ( !has_vlapic(d) ) + return 0; + /* Which vlapic to load? */ vcpuid = hvm_load_instance(h); if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL ) @@ -1360,7 +1374,10 @@ static int lapic_load_regs(struct domain *d, hvm_domain_context_t *h) uint16_t vcpuid; struct vcpu *v; struct vlapic *s; - + + if ( !has_vlapic(d) ) + return 0; + /* Which vlapic to load? */ vcpuid = hvm_load_instance(h); if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL ) @@ -1399,7 +1416,7 @@ int vlapic_init(struct vcpu *v) HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "%d", v->vcpu_id); - if ( is_pvh_vcpu(v) ) + if ( is_pvh_vcpu(v) || !has_vlapic(v->domain) ) { vlapic->hw.disabled = VLAPIC_HW_DISABLED; return 0; @@ -1452,6 +1469,9 @@ void vlapic_destroy(struct vcpu *v) { struct vlapic *vlapic = vcpu_vlapic(v); + if ( !has_vlapic(vlapic_domain(vlapic)) ) + return; + tasklet_kill(&vlapic->init_sipi.tasklet); TRACE_0D(TRC_HVM_EMUL_LAPIC_STOP_TIMER); destroy_periodic_time(&vlapic->pt); diff --git a/xen/arch/x86/hvm/vmsi.c b/xen/arch/x86/hvm/vmsi.c index ac838a9..e6a145d 100644 --- a/xen/arch/x86/hvm/vmsi.c +++ b/xen/arch/x86/hvm/vmsi.c @@ -482,6 +482,9 @@ found: void msixtbl_init(struct domain *d) { + if ( !has_vlapic(d) ) + return; + INIT_LIST_HEAD(&d->arch.hvm_domain.msixtbl_list); spin_lock_init(&d->arch.hvm_domain.msixtbl_list_lock); @@ -493,6 +496,9 @@ void msixtbl_pt_cleanup(struct domain *d) struct msixtbl_entry *entry, *temp; unsigned long flags; + if ( !has_vlapic(d) ) + return; + /* msixtbl_list_lock must be acquired with irq_disabled for check_lock() */ local_irq_save(flags); spin_lock(&d->arch.hvm_domain.msixtbl_list_lock); diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index a0a97e7..5acb246 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1027,6 +1027,20 @@ static int construct_vmcs(struct vcpu *v) ASSERT(!(v->arch.hvm_vmx.exec_control & CPU_BASED_RDTSC_EXITING)); } + if ( !has_vlapic(d) ) + { + /* Disable virtual apics, TPR */ + v->arch.hvm_vmx.secondary_exec_control &= + ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES + | SECONDARY_EXEC_APIC_REGISTER_VIRT + | SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY); + v->arch.hvm_vmx.exec_control &= ~CPU_BASED_TPR_SHADOW; + + /* In turn, disable posted interrupts. */ + __vmwrite(PIN_BASED_VM_EXEC_CONTROL, + vmx_pin_based_exec_control & ~PIN_BASED_POSTED_INTERRUPT); + } + vmx_update_cpu_exec_control(v); __vmwrite(VM_EXIT_CONTROLS, vmexit_ctl); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index c32d863..3d242fd 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -89,6 +89,9 @@ static int vmx_domain_initialise(struct domain *d) { int rc; + if ( !has_vlapic(d) ) + return 0; + if ( (rc = vmx_alloc_vlapic_mapping(d)) != 0 ) return rc; @@ -97,6 +100,9 @@ static int vmx_domain_initialise(struct domain *d) static void vmx_domain_destroy(struct domain *d) { + if ( !has_vlapic(d) ) + return; + vmx_free_vlapic_mapping(d); } @@ -2390,7 +2396,8 @@ static void vmx_install_vlapic_mapping(struct vcpu *v) { paddr_t virt_page_ma, apic_page_ma; - if ( !cpu_has_vmx_virtualize_apic_accesses ) + if ( !cpu_has_vmx_virtualize_apic_accesses || + v->domain->arch.hvm_domain.vmx.apic_access_mfn == 0 ) return; virt_page_ma = page_to_maddr(vcpu_vlapic(v)->regs_page); -- 1.9.5 (Apple Git-50.3) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |