From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Borislav Petkov <bp@suse.de>
Subject: [Qemu-devel] [RFC 1/2] kvm: Implement kvm_arch_get_emulated_cpuid()
Date: Thu, 5 Jun 2014 13:12:20 -0300 [thread overview]
Message-ID: <1401984741-26882-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1401984741-26882-1-git-send-email-ehabkost@redhat.com>
From: Borislav Petkov <bp@suse.de>
Add support for the KVM_GET_EMULATED_CPUID ioctl and leave feature bits
enabled, when requested by userspace, if kvm emulates them.
Signed-off-by: Borislav Petkov <bp@suse.de>
[ehabkost: removed target-i386/cpu.c code, changed patch description]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/sysemu/kvm.h | 3 +++
target-i386/kvm.c | 38 ++++++++++++++++++++++++++++++++++----
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index e7ad9d1..ab1ffdb 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -324,6 +324,9 @@ int kvm_check_extension(KVMState *s, unsigned int extension);
uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
uint32_t index, int reg);
+uint32_t kvm_arch_get_emulated_cpuid(KVMState *env, uint32_t function,
+ uint32_t index, int reg);
+
#if !defined(CONFIG_USER_ONLY)
int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f9ffa4b..242df34 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -88,7 +88,7 @@ bool kvm_allows_irq0_override(void)
return !kvm_irqchip_in_kernel() || kvm_has_gsi_routing();
}
-static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
+static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int ioctl, int max)
{
struct kvm_cpuid2 *cpuid;
int r, size;
@@ -96,7 +96,7 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
size = sizeof(*cpuid) + max * sizeof(*cpuid->entries);
cpuid = (struct kvm_cpuid2 *)g_malloc0(size);
cpuid->nent = max;
- r = kvm_ioctl(s, KVM_GET_SUPPORTED_CPUID, cpuid);
+ r = kvm_ioctl(s, ioctl, cpuid);
if (r == 0 && cpuid->nent >= max) {
r = -E2BIG;
}
@@ -105,7 +105,10 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
g_free(cpuid);
return NULL;
} else {
- fprintf(stderr, "KVM_GET_SUPPORTED_CPUID failed: %s\n",
+ fprintf(stderr, "%s failed: %s\n",
+ (ioctl == (int)KVM_GET_SUPPORTED_CPUID
+ ? "KVM_GET_SUPPORTED_CPUID"
+ : "KVM_GET_EMULATED_CPUID"),
strerror(-r));
exit(1);
}
@@ -120,7 +123,17 @@ static struct kvm_cpuid2 *get_supported_cpuid(KVMState *s)
{
struct kvm_cpuid2 *cpuid;
int max = 1;
- while ((cpuid = try_get_cpuid(s, max)) == NULL) {
+ while ((cpuid = try_get_cpuid(s, KVM_GET_SUPPORTED_CPUID, max)) == NULL) {
+ max *= 2;
+ }
+ return cpuid;
+}
+
+static struct kvm_cpuid2 *get_emulated_cpuid(KVMState *s)
+{
+ struct kvm_cpuid2 *cpuid;
+ int max = 1;
+ while ((cpuid = try_get_cpuid(s, KVM_GET_EMULATED_CPUID, max)) == NULL) {
max *= 2;
}
return cpuid;
@@ -248,6 +261,23 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
return ret;
}
+uint32_t kvm_arch_get_emulated_cpuid(KVMState *s, uint32_t function,
+ uint32_t index, int reg)
+{
+ struct kvm_cpuid2 *cpuid __attribute__((unused));
+
+ if (!kvm_check_extension(s, KVM_CAP_EXT_EMUL_CPUID))
+ return 0;
+
+ cpuid = get_emulated_cpuid(s);
+
+ struct kvm_cpuid_entry2 *entry = cpuid_find_entry(cpuid, function, index);
+ if (entry)
+ return cpuid_entry_get_reg(entry, reg);
+
+ return 0;
+}
+
typedef struct HWPoisonPage {
ram_addr_t ram_addr;
QLIST_ENTRY(HWPoisonPage) list;
--
1.9.0
next prev parent reply other threads:[~2014-06-05 16:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-05 16:12 [Qemu-devel] [RFC 0/2] GET_EMULATED_CPUID support with "allow-emulation" option Eduardo Habkost
2014-06-05 16:12 ` Eduardo Habkost [this message]
2014-06-05 16:12 ` [Qemu-devel] [RFC 2/2] target-i386: Add "allow-emulation" X86CPU property Eduardo Habkost
2014-06-05 19:57 ` [Qemu-devel] [RFC 2/2 v2] target-i386: Add "x-allow-emulation" " Eduardo Habkost
2014-06-05 22:27 ` Alexander Graf
2014-06-05 16:24 ` [Qemu-devel] [RFC 0/2] GET_EMULATED_CPUID support with "allow-emulation" option Alexander Graf
2014-06-05 16:26 ` Paolo Bonzini
2014-06-05 16:40 ` Alexander Graf
2014-06-05 16:44 ` Paolo Bonzini
2014-06-05 16:45 ` Alexander Graf
2014-06-05 16:52 ` Paolo Bonzini
2014-06-05 16:54 ` Alexander Graf
2014-06-05 16:57 ` Paolo Bonzini
2014-06-05 17:19 ` Eduardo Habkost
2014-06-05 17:39 ` Paolo Bonzini
2014-06-05 18:02 ` Eduardo Habkost
2014-06-05 19:12 ` Eduardo Habkost
2014-06-05 19:24 ` Borislav Petkov
2014-06-05 19:45 ` Eric Blake
2014-06-05 19:52 ` Eduardo Habkost
2014-06-05 16:58 ` Alexander Graf
2014-06-05 17:48 ` Eduardo Habkost
2014-06-05 22:24 ` Alexander Graf
2014-06-06 1:21 ` Borislav Petkov
2014-06-06 2:37 ` Eduardo Habkost
2014-06-06 11:16 ` Alexander Graf
2014-06-06 18:38 ` Eduardo Habkost
2014-06-05 17:17 ` Eduardo Habkost
2014-06-05 17:38 ` Paolo Bonzini
2014-06-05 17:52 ` Eduardo Habkost
2014-06-05 17:34 ` Eduardo Habkost
2014-06-06 13:29 ` gleb
2014-06-05 18:11 ` Eduardo Habkost
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=1401984741-26882-2-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=bp@suse.de \
--cc=qemu-devel@nongnu.org \
/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).