All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: pbonzini@redhat.com
Cc: joro@8bytes.org, kvm@vger.kernel.org, nadav.amit@gmail.com,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH 1/2] KVM: x86: update cpuid according to IA32_MISC_ENABLE
Date: Wed, 20 Aug 2014 16:58:28 +0300	[thread overview]
Message-ID: <1408543109-30687-2-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1408543109-30687-1-git-send-email-namit@cs.technion.ac.il>

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 <namit@cs.technion.ac.il>
---
 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


  reply	other threads:[~2014-08-20 14:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-20 13:58 [PATCH 0/2] KVM: vmx: Supporting IA32_MISC_ENABLE MSR Nadav Amit
2014-08-20 13:58 ` Nadav Amit [this message]
2014-08-20 13:58 ` [PATCH 2/2] KVM: vmx: Reflect misc_enables in real CPU Nadav Amit
2014-08-21 11:51   ` Paolo Bonzini
2014-08-21 12:28     ` Nadav Amit
2014-08-20 14:00 ` [PATCH] x86: Test debug exceptions with disabled fast-string Nadav Amit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1408543109-30687-2-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=nadav.amit@gmail.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.