public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH v2 03/26] KVM: x86 emulator: change ->get_cpuid() accessor to use the x86 semantics
Date: Wed, 27 Jun 2012 18:19:03 +0300	[thread overview]
Message-ID: <1340810369-25392-6-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1340810369-25392-1-git-send-email-avi@redhat.com>

Instead of getting an exact leaf, follow the spec and fall back to the last
main leaf instead.  This lets us easily emulate the cpuid instruction in the
emulator.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/include/asm/kvm_emulate.h |  4 +--
 arch/x86/kvm/emulate.c             | 53 +++++++++++++++++++-------------------
 arch/x86/kvm/x86.c                 | 20 ++------------
 3 files changed, 30 insertions(+), 47 deletions(-)

diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index 1ac46c22..cd5c96b 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -192,8 +192,8 @@ struct x86_emulate_ops {
 			 struct x86_instruction_info *info,
 			 enum x86_intercept_stage stage);
 
-	bool (*get_cpuid)(struct x86_emulate_ctxt *ctxt,
-			 u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
+	void (*get_cpuid)(struct x86_emulate_ctxt *ctxt,
+			  u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
 };
 
 typedef u32 __attribute__((vector_size(16))) sse128_t;
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f95d242..ba1f8ec 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1993,8 +1993,8 @@ static bool vendor_intel(struct x86_emulate_ctxt *ctxt)
 	u32 eax, ebx, ecx, edx;
 
 	eax = ecx = 0;
-	return ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx)
-		&& ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx
+	ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx);
+	return ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx
 		&& ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx
 		&& edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx;
 }
@@ -2013,32 +2013,31 @@ static bool em_syscall_is_enabled(struct x86_emulate_ctxt *ctxt)
 
 	eax = 0x00000000;
 	ecx = 0x00000000;
-	if (ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx)) {
-		/*
-		 * Intel ("GenuineIntel")
-		 * remark: Intel CPUs only support "syscall" in 64bit
-		 * longmode. Also an 64bit guest with a
-		 * 32bit compat-app running will #UD !! While this
-		 * behaviour can be fixed (by emulating) into AMD
-		 * response - CPUs of AMD can't behave like Intel.
-		 */
-		if (ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx &&
-		    ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx &&
-		    edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx)
-			return false;
+	ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx);
+	/*
+	 * Intel ("GenuineIntel")
+	 * remark: Intel CPUs only support "syscall" in 64bit
+	 * longmode. Also an 64bit guest with a
+	 * 32bit compat-app running will #UD !! While this
+	 * behaviour can be fixed (by emulating) into AMD
+	 * response - CPUs of AMD can't behave like Intel.
+	 */
+	if (ebx == X86EMUL_CPUID_VENDOR_GenuineIntel_ebx &&
+	    ecx == X86EMUL_CPUID_VENDOR_GenuineIntel_ecx &&
+	    edx == X86EMUL_CPUID_VENDOR_GenuineIntel_edx)
+		return false;
 
-		/* AMD ("AuthenticAMD") */
-		if (ebx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx &&
-		    ecx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx &&
-		    edx == X86EMUL_CPUID_VENDOR_AuthenticAMD_edx)
-			return true;
-
-		/* AMD ("AMDisbetter!") */
-		if (ebx == X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx &&
-		    ecx == X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx &&
-		    edx == X86EMUL_CPUID_VENDOR_AMDisbetterI_edx)
-			return true;
-	}
+	/* AMD ("AuthenticAMD") */
+	if (ebx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ebx &&
+	    ecx == X86EMUL_CPUID_VENDOR_AuthenticAMD_ecx &&
+	    edx == X86EMUL_CPUID_VENDOR_AuthenticAMD_edx)
+		return true;
+
+	/* AMD ("AMDisbetter!") */
+	if (ebx == X86EMUL_CPUID_VENDOR_AMDisbetterI_ebx &&
+	    ecx == X86EMUL_CPUID_VENDOR_AMDisbetterI_ecx &&
+	    edx == X86EMUL_CPUID_VENDOR_AMDisbetterI_edx)
+		return true;
 
 	/* default: (not Intel, not AMD), apply Intel's stricter rules... */
 	return false;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6ed5983..0d3adaf 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4297,26 +4297,10 @@ static int emulator_intercept(struct x86_emulate_ctxt *ctxt,
 	return kvm_x86_ops->check_intercept(emul_to_vcpu(ctxt), info, stage);
 }
 
-static bool emulator_get_cpuid(struct x86_emulate_ctxt *ctxt,
+static void emulator_get_cpuid(struct x86_emulate_ctxt *ctxt,
 			       u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
 {
-	struct kvm_cpuid_entry2 *cpuid = NULL;
-
-	if (eax && ecx)
-		cpuid = kvm_find_cpuid_entry(emul_to_vcpu(ctxt),
-					    *eax, *ecx);
-
-	if (cpuid) {
-		*eax = cpuid->eax;
-		*ecx = cpuid->ecx;
-		if (ebx)
-			*ebx = cpuid->ebx;
-		if (edx)
-			*edx = cpuid->edx;
-		return true;
-	}
-
-	return false;
+	kvm_cpuid(emul_to_vcpu(ctxt), eax, ebx, ecx, edx);
 }
 
 static struct x86_emulate_ops emulate_ops = {
-- 
1.7.11


  parent reply	other threads:[~2012-06-27 15:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 15:18 [PATCH v2 00/26] Big big real mode improvements Avi Kivity
2012-06-27 15:18 ` [PATCH v2 01/26] KVM: VMX: Return correct CPL during transition to protected mode Avi Kivity
2012-06-27 15:19 ` [PATCH 1/5] KVM: x86 emulator: emulate BSWAP Avi Kivity
2012-06-27 15:19 ` [PATCH v2 02/26] KVM: Split cpuid register access from computation Avi Kivity
2012-06-27 15:19 ` [PATCH 2/5] KVM: x86 emulator: emulate LLDT Avi Kivity
2012-06-27 15:19 ` Avi Kivity [this message]
2012-06-27 15:19 ` [PATCH 3/5] KVM: x86 emulator: make read_segment_descriptor() return the address Avi Kivity
2012-06-27 15:19 ` [PATCH v2 04/26] KVM: x86 emulator: emulate cpuid Avi Kivity
2012-06-27 15:19 ` [PATCH 4/5] KVM: x86 emulator: make loading TR set the busy bit Avi Kivity
2012-06-27 15:19 ` [PATCH v2 05/26] KVM: x86 emulator: allow loading null SS in long mode Avi Kivity
2012-06-27 15:19 ` [PATCH 5/5] KVM: x86 emulator: implement LTR Avi Kivity
2012-06-27 15:19 ` [PATCH v2 06/26] KVM: x86 emulator: fix LIDT/LGDT in long mode Avi Kivity
2012-06-27 15:19 ` [PATCH v2 07/26] KVM: VMX: Relax check on unusable segment Avi Kivity
2012-06-27 15:19 ` [PATCH v2 08/26] KVM: VMX: Limit iterations with emulator_invalid_guest_state Avi Kivity
2012-06-27 15:19 ` [PATCH v2 09/26] KVM: x86 emulator: emulate LEAVE Avi Kivity
2012-06-27 15:19 ` [PATCH v2 10/26] KVM: x86 emulator: initialize memop Avi Kivity
2012-06-27 15:19 ` [PATCH v2 11/26] KVM: Fix SS default ESP/EBP based addressing Avi Kivity
2012-06-27 15:19 ` [PATCH v2 12/26] KVM: x86 emulator: emulate SGDT/SIDT Avi Kivity
2012-06-27 15:19 ` [PATCH v2 13/26] KVM: VMX: Fix interrupt exit condition during emulation Avi Kivity
2012-06-27 15:19 ` [PATCH v2 14/26] KVM: VMX: Continue emulating after batch exhausted Avi Kivity
2012-06-27 15:19 ` [PATCH v2 15/26] KVM: x86 emulator: emulate LAHF Avi Kivity
2012-06-27 15:19 ` [PATCH v2 16/26] KVM: x86 emulator: fix byte-sized MOVZX/MOVSX Avi Kivity
2012-06-27 15:19 ` [PATCH v2 17/26] KVM: x86 emulator: split push logic from push opcode emulation Avi Kivity
2012-06-27 15:19 ` [PATCH v2 18/26] KVM: x86 emulator: implement ENTER Avi Kivity
2012-06-27 15:19 ` [PATCH v2 19/26] KVM: VMX: Stop invalid guest state emulation on pending event Avi Kivity
2012-06-27 15:19 ` [PATCH v2 20/26] KVM: VMX: Improve error reporting during invalid guest state emulation Avi Kivity
2012-06-27 15:19 ` [PATCH v2 21/26] KVM: x86 emulator: emulate BSWAP Avi Kivity
2012-06-27 15:19 ` [PATCH v2 22/26] KVM: x86 emulator: emulate LLDT Avi Kivity
2012-06-27 15:19 ` [PATCH v2 23/26] KVM: x86 emulator: make read_segment_descriptor() return the address Avi Kivity
2012-06-27 15:19 ` [PATCH v2 24/26] KVM: x86 emulator: make loading TR set the busy bit Avi Kivity
2012-06-27 15:19 ` [PATCH v2 25/26] KVM: x86 emulator: implement LTR Avi Kivity
2012-06-27 15:19 ` [PATCH v2 26/26] KVM: VMX: Emulate invalid guest state by default Avi Kivity
2012-06-27 15:23 ` [PATCH v2 00/26] Big big real mode improvements Avi Kivity

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=1340810369-25392-6-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox