kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH v3.1 02/26] KVM: Split cpuid register access from computatio
Date: Wed, 04 Jul 2012 11:24:25 +0300	[thread overview]
Message-ID: <4FF3FDB9.7090307@redhat.com> (raw)
In-Reply-To: <4FF3FC0B.80500@redhat.com>

Introduce kvm_cpuid() to perform the leaf limit check and calculate
register values, and let kvm_emulate_cpuid() just handle reading and
writing the registers from/to the vcpu.  This allows us to reuse
kvm_cpuid() in a context where directly reading and writing registers
is not desired.

Signed-off-by: Avi Kivity <avi@redhat.com>
---

v3.1: drop duplicate trace


 arch/x86/kvm/cpuid.c | 40 ++++++++++++++++++++++------------------
 arch/x86/kvm/cpuid.h |  1 +
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 61ccbdf..197afd5 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -640,33 +640,37 @@ static struct kvm_cpuid_entry2* check_cpuid_limit(struct kvm_vcpu *vcpu,
 	return kvm_find_cpuid_entry(vcpu, maxlevel->eax, index);
 }
 
-void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
+void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
 {
-	u32 function, index;
+	u32 function = *eax, index = *ecx;
 	struct kvm_cpuid_entry2 *best;
 
-	function = kvm_register_read(vcpu, VCPU_REGS_RAX);
-	index = kvm_register_read(vcpu, VCPU_REGS_RCX);
-	kvm_register_write(vcpu, VCPU_REGS_RAX, 0);
-	kvm_register_write(vcpu, VCPU_REGS_RBX, 0);
-	kvm_register_write(vcpu, VCPU_REGS_RCX, 0);
-	kvm_register_write(vcpu, VCPU_REGS_RDX, 0);
 	best = kvm_find_cpuid_entry(vcpu, function, index);
 
 	if (!best)
 		best = check_cpuid_limit(vcpu, function, index);
 
 	if (best) {
-		kvm_register_write(vcpu, VCPU_REGS_RAX, best->eax);
-		kvm_register_write(vcpu, VCPU_REGS_RBX, best->ebx);
-		kvm_register_write(vcpu, VCPU_REGS_RCX, best->ecx);
-		kvm_register_write(vcpu, VCPU_REGS_RDX, best->edx);
-	}
+		*eax = best->eax;
+		*ebx = best->ebx;
+		*ecx = best->ecx;
+		*edx = best->edx;
+	} else
+		*eax = *ebx = *ecx = *edx = 0;
+}
+
+void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
+{
+	u32 function, eax, ebx, ecx, edx;
+
+	function = eax = kvm_register_read(vcpu, VCPU_REGS_RAX);
+	ecx = kvm_register_read(vcpu, VCPU_REGS_RCX);
+	kvm_cpuid(vcpu, &eax, &ebx, &ecx, &edx);
+	kvm_register_write(vcpu, VCPU_REGS_RAX, eax);
+	kvm_register_write(vcpu, VCPU_REGS_RBX, ebx);
+	kvm_register_write(vcpu, VCPU_REGS_RCX, ecx);
+	kvm_register_write(vcpu, VCPU_REGS_RDX, edx);
 	kvm_x86_ops->skip_emulated_instruction(vcpu);
-	trace_kvm_cpuid(function,
-			kvm_register_read(vcpu, VCPU_REGS_RAX),
-			kvm_register_read(vcpu, VCPU_REGS_RBX),
-			kvm_register_read(vcpu, VCPU_REGS_RCX),
-			kvm_register_read(vcpu, VCPU_REGS_RDX));
+	trace_kvm_cpuid(function, eax, ebx, ecx, edx);
 }
 EXPORT_SYMBOL_GPL(kvm_emulate_cpuid);
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index 26d1fb4..f449edc 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -17,6 +17,7 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
 int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
 			      struct kvm_cpuid2 *cpuid,
 			      struct kvm_cpuid_entry2 __user *entries);
+void kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
 
 
 static inline bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
-- 
1.7.11



  reply	other threads:[~2012-07-04  8:24 UTC|newest]

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