All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Stephan Bärwolf" <stephan.baerwolf@tu-ilmenau.de>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 1/2] KVM: extend "struct x86_emulate_ops" with "get_cpuid"
Date: Thu, 12 Jan 2012 16:43:03 +0100	[thread overview]
Message-ID: <4F0EFF87.8070402@tu-ilmenau.de> (raw)
In-Reply-To: <20120112104756.GB31635@amt.cnet>

[-- Attachment #1: Type: text/plain, Size: 2625 bytes --]

>From a8f796f81979094b81cb74535632786ce1ccf9bb Mon Sep 17 00:00:00 2001
From: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Date: Sun, 8 Jan 2012 23:25:59 +0000
Subject: [PATCH 1/2] KVM: extend "struct x86_emulate_ops" with "get_cpuid"

In order to be able to proceed checks on CPU-specific properties
within the emulator, function "get_cpuid" is introduced.
With "get_cpuid" it is possible to virtually call the guests
"cpuid"-opcode without changing the VM's context.

Cc: <stable@vger.kernel.org>
Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
---
 arch/x86/include/asm/kvm_emulate.h |    4 ++++
 arch/x86/kvm/x86.c                 |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/kvm_emulate.h
b/arch/x86/include/asm/kvm_emulate.h
index a026507..b172bf4 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -189,6 +189,10 @@ struct x86_emulate_ops {
     int (*intercept)(struct x86_emulate_ctxt *ctxt,
              struct x86_instruction_info *info,
              enum x86_intercept_stage stage);
+
+    /* retrieve ctxt's vcpu's cpuid */
+    bool (*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/x86.c b/arch/x86/kvm/x86.c
index 4c938da..6181783 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4655,6 +4655,26 @@ 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,
+                         u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
+{
+    struct kvm_cpuid_entry2 *cpuid = NULL;
+
+    if ((ctxt) && (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;
+}
+
 static struct x86_emulate_ops emulate_ops = {
     .read_std            = kvm_read_guest_virt_system,
     .write_std           = kvm_write_guest_virt_system,
@@ -4685,6 +4705,7 @@ static struct x86_emulate_ops emulate_ops = {
     .get_fpu             = emulator_get_fpu,
     .put_fpu             = emulator_put_fpu,
     .intercept           = emulator_intercept,
+    .get_cpuid           = emulator_get_cpuid,
 };
 
 static void cache_all_regs(struct kvm_vcpu *vcpu)
-- 
1.7.3.4



[-- Attachment #2: 0001-KVM-extend-struct-x86_emulate_ops-with-get_cpuid.patch --]
[-- Type: text/x-patch, Size: 2538 bytes --]

>From a8f796f81979094b81cb74535632786ce1ccf9bb Mon Sep 17 00:00:00 2001
From: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Date: Sun, 8 Jan 2012 23:25:59 +0000
Subject: [PATCH 1/2] KVM: extend "struct x86_emulate_ops" with "get_cpuid"

In order to be able to proceed checks on CPU-specific properties
within the emulator, function "get_cpuid" is introduced.
With "get_cpuid" it is possible to virtually call the guests
"cpuid"-opcode without changing the VM's context.

Cc: <stable@vger.kernel.org>
Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
---
 arch/x86/include/asm/kvm_emulate.h |    4 ++++
 arch/x86/kvm/x86.c                 |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index a026507..b172bf4 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -189,6 +189,10 @@ struct x86_emulate_ops {
 	int (*intercept)(struct x86_emulate_ctxt *ctxt,
 			 struct x86_instruction_info *info,
 			 enum x86_intercept_stage stage);
+
+	/* retrieve ctxt's vcpu's cpuid */
+	bool (*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/x86.c b/arch/x86/kvm/x86.c
index 4c938da..6181783 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4655,6 +4655,26 @@ 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,
+                         u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
+{
+	struct kvm_cpuid_entry2 *cpuid = NULL;
+
+	if ((ctxt) && (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;
+}
+
 static struct x86_emulate_ops emulate_ops = {
 	.read_std            = kvm_read_guest_virt_system,
 	.write_std           = kvm_write_guest_virt_system,
@@ -4685,6 +4705,7 @@ static struct x86_emulate_ops emulate_ops = {
 	.get_fpu             = emulator_get_fpu,
 	.put_fpu             = emulator_put_fpu,
 	.intercept           = emulator_intercept,
+	.get_cpuid           = emulator_get_cpuid,
 };
 
 static void cache_all_regs(struct kvm_vcpu *vcpu)
-- 
1.7.3.4


  parent reply	other threads:[~2012-01-12 15:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-29  1:59 KVM guest-kernel panics double fault Stephan Bärwolf
2011-12-29 10:04 ` Avi Kivity
2012-01-08  2:31   ` Stephan Bärwolf
2012-01-08 10:21     ` Avi Kivity
2012-01-10 10:11       ` Stephan Bärwolf
2012-01-10 10:31         ` Avi Kivity
2012-01-10 12:17           ` Stephan Bärwolf
2012-01-10 12:34             ` Avi Kivity
2012-01-10 12:48               ` Stephan Bärwolf
2012-01-10 14:26                 ` [PATCH 0/2] " Stephan Bärwolf
2012-01-10 14:26                 ` [PATCH 1/2] KVM: extend "struct x86_emulate_ops" with "get_cpuid" Stephan Bärwolf
2012-01-10 14:26                 ` [PATCH 2/2] KVM: fix missing "illegal instruction"-trap in protected modes Stephan Bärwolf
2012-01-11 19:09                   ` Marcelo Tosatti
2012-01-11 20:01                     ` Stephan Bärwolf
2012-01-11 21:21                       ` Marcelo Tosatti
2012-01-11 22:19                         ` Stephan Bärwolf
2012-01-12 10:47                           ` Marcelo Tosatti
2012-01-12 15:43                             ` [PATCH 0/2] KVM guest-kernel panics double fault Stephan Bärwolf
2012-01-12 15:56                               ` Jan Kiszka
2012-01-13 10:13                                 ` Marcelo Tosatti
2012-01-15 19:44                                   ` Stephan Bärwolf
2012-01-16  9:58                                     ` Marcelo Tosatti
2012-01-16 11:24                                       ` Stephan Bärwolf
2012-01-12 15:43                             ` Stephan Bärwolf [this message]
2012-01-12 15:43                             ` [PATCH 2/2] KVM: fix missing "illegal instruction"-trap in protected modes Stephan Bärwolf

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=4F0EFF87.8070402@tu-ilmenau.de \
    --to=stephan.baerwolf@tu-ilmenau.de \
    --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 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.