From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nadav Amit Subject: [PATCH 1/2] KVM: x86: update cpuid according to IA32_MISC_ENABLE Date: Wed, 20 Aug 2014 16:58:28 +0300 Message-ID: <1408543109-30687-2-git-send-email-namit@cs.technion.ac.il> References: <1408543109-30687-1-git-send-email-namit@cs.technion.ac.il> Cc: joro@8bytes.org, kvm@vger.kernel.org, nadav.amit@gmail.com, Nadav Amit To: pbonzini@redhat.com Return-path: Received: from mailgw12.technion.ac.il ([132.68.225.12]:6451 "EHLO mailgw12.technion.ac.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbaHTOA0 (ORCPT ); Wed, 20 Aug 2014 10:00:26 -0400 In-Reply-To: <1408543109-30687-1-git-send-email-namit@cs.technion.ac.il> Sender: kvm-owner@vger.kernel.org List-ID: Virtual BIOS may use the "Limit CPUID Maxval" and "XD Bit Disable" fields in IA32_MISC_ENABLE. These two fields update the CPUID, and in the case of "XD Bit Disable" also disable NX support. This patch reflects this behavior in CPUID, and disables NX bit accordingly. Signed-off-by: Nadav Amit --- arch/x86/kvm/cpuid.c | 20 ++++++++++++++++++++ arch/x86/kvm/vmx.c | 8 ++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 38a0afe..ff7f429 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -757,6 +757,25 @@ static struct kvm_cpuid_entry2* check_cpuid_limit(struct kvm_vcpu *vcpu, return kvm_find_cpuid_entry(vcpu, maxlevel->eax, index); } +static void cpuid_override(struct kvm_vcpu *vcpu, u32 function, u32 index, + u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) +{ + switch (function) { + case 0: + if (vcpu->arch.ia32_misc_enable_msr & + MSR_IA32_MISC_ENABLE_LIMIT_CPUID) + *eax = min_t(u32, *eax, 3); + break; + case 1: + if (vcpu->arch.ia32_misc_enable_msr & + MSR_IA32_MISC_ENABLE_XD_DISABLE) + *edx &= ~bit(X86_FEATURE_NX); + break; + default: + break; + } +} + void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) { u32 function = *eax, index = *ecx; @@ -774,6 +793,7 @@ void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) *edx = best->edx; } else *eax = *ebx = *ecx = *edx = 0; + cpuid_override(vcpu, function, index, eax, ebx, ecx, edx); trace_kvm_cpuid(function, *eax, *ebx, *ecx, *edx); } EXPORT_SYMBOL_GPL(kvm_cpuid); diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index cad37d5..45bab55 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1633,9 +1633,13 @@ static bool update_transition_efer(struct vcpu_vmx *vmx, int efer_offset) vmx->guest_msrs[efer_offset].mask = ~ignore_bits; clear_atomic_switch_msr(vmx, MSR_EFER); + /* Clear nx according if xd_disable is on */ + guest_efer = vmx->vcpu.arch.efer; + if (vmx->vcpu.arch.ia32_misc_enable_msr & + MSR_IA32_MISC_ENABLE_XD_DISABLE) + guest_efer &= ~EFER_NX; /* On ept, can't emulate nx, and must switch nx atomically */ - if (enable_ept && ((vmx->vcpu.arch.efer ^ host_efer) & EFER_NX)) { - guest_efer = vmx->vcpu.arch.efer; + if (enable_ept && ((guest_efer ^ host_efer) & EFER_NX)) { if (!(guest_efer & EFER_LMA)) guest_efer &= ~EFER_LME; add_atomic_switch_msr(vmx, MSR_EFER, guest_efer, host_efer); -- 1.9.1