From: "Jan Beulich" Subject: Re: [PATCH for-xen-4.5] x86/pvh/vpmu: Disable VPMU for PVH guests Date: Tue, 25 Nov 2014 08:45:22 +0000 Message-ID: <54744FB2020000780004A935@mail.emea.novell.com> References: <1416858554-1817-1-git-send-email-boris.ostrovsky@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1416858554-1817-1-git-send-email-boris.ostrovsky@oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: keir@xen.org, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 24.11.14 at 20:49, wrote: > Currently when VPMU is enabled on a system both HVM and PVH VPCUs will > initialize their VPMUs, including setting up vpmu_ops. As result even > though VPMU will not work for PVH guests (APIC is not supported there), > the guest may decide to perform a write to a PMU MSR. This will cause a > call to is_vlapic_lvtpc_enabled() which will crash the hypervisor, e.g.: > > (XEN) Xen call trace: > (XEN) [] is_vlapic_lvtpc_enabled+0x13/0x22 > (XEN) [] core2_vpmu_do_wrmsr+0x415/0x589 > (XEN) [] vpmu_do_wrmsr+0x2a/0x33 > (XEN) [] vmx_msr_write_intercept+0x268/0x557 > (XEN) [] hvm_msr_write_intercept+0x36c/0x39b > (XEN) [] vmx_vmexit_handler+0x1082/0x185b > (XEN) [] vmx_asm_vmexit_handler+0x41/0xc0 > > If we prevent VPMU from being initialized on PVH guests we will avoid > those accesses. I think this fix is too specific; instead we should mark the LAPIC disabled, which will implicitly prevent the issue afaict - see below. Jan x86/PVH: properly disable vLAPIC Rather than guarding higher level operations (like vPMU initialization as suggested by Boris in http://lists.xenproject.org/archives/html/xen-devel/2014-11/msg02278.html) mark the vLAPIC hardware disabled for PVH guests and prevent it from getting moved out of this state. Reported-by: Boris Ostrovsky Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2217,8 +2217,7 @@ int hvm_vcpu_initialise(struct vcpu *v) goto fail1; /* NB: vlapic_init must be called before hvm_funcs.vcpu_initialise */ - if ( is_hvm_vcpu(v) ) - rc = vlapic_init(v); + rc = vlapic_init(v); if ( rc != 0 ) /* teardown: vlapic_destroy */ goto fail2; @@ -4483,7 +4482,8 @@ int hvm_msr_write_intercept(unsigned int break; case MSR_IA32_APICBASE: - if ( !vlapic_msr_set(vcpu_vlapic(v), msr_content) ) + if ( unlikely(is_pvh_vcpu(v)) || + !vlapic_msr_set(vcpu_vlapic(v), msr_content) ) goto gp_fault; break; --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1429,6 +1429,12 @@ int vlapic_init(struct vcpu *v) HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "%d", v->vcpu_id); + if ( is_pvh_vcpu(v) ) + { + vlapic->hw.disabled = VLAPIC_HW_DISABLED; + return 0; + } + vlapic->pt.source = PTSRC_lapic; if (vlapic->regs_page == NULL)