From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: [Qemu-devel] [PULL 02/17] x86: hv_evmcs CPU flag support
Date: Tue, 6 Nov 2018 22:37:48 +0100 [thread overview]
Message-ID: <1541540283-45699-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1541540283-45699-1-git-send-email-pbonzini@redhat.com>
From: Vitaly Kuznetsov <vkuznets@redhat.com>
Adds a new CPU flag to enable the Enlightened VMCS KVM feature.
QEMU enables KVM_CAP_HYPERV_ENLIGHTENED_VMCS and gets back the
version to be advertised in lower 16 bits of CPUID.0x4000000A:EAX.
Suggested-by: Ladi Prosek <lprosek@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20181022165506.30332-3-vkuznets@redhat.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/cpu.c | 1 +
target/i386/cpu.h | 1 +
target/i386/hyperv-proto.h | 2 ++
target/i386/kvm.c | 30 ++++++++++++++++++++++++++++--
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index af7e9f0..f81d35e 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5732,6 +5732,7 @@ static Property x86_cpu_properties[] = {
DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false),
DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, false),
DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false),
+ DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false),
DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false),
DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true),
DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index ad0e0b4..9c52d0c 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1391,6 +1391,7 @@ struct X86CPU {
bool hyperv_frequencies;
bool hyperv_reenlightenment;
bool hyperv_tlbflush;
+ bool hyperv_evmcs;
bool hyperv_ipi;
bool check_cpuid;
bool enforce_cpuid;
diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h
index 8c572cd..c0272b3 100644
--- a/target/i386/hyperv-proto.h
+++ b/target/i386/hyperv-proto.h
@@ -18,6 +18,7 @@
#define HV_CPUID_FEATURES 0x40000003
#define HV_CPUID_ENLIGHTMENT_INFO 0x40000004
#define HV_CPUID_IMPLEMENT_LIMITS 0x40000005
+#define HV_CPUID_NESTED_FEATURES 0x4000000A
#define HV_CPUID_MIN 0x40000005
#define HV_CPUID_MAX 0x4000ffff
#define HV_HYPERVISOR_PRESENT_BIT 0x80000000
@@ -60,6 +61,7 @@
#define HV_RELAXED_TIMING_RECOMMENDED (1u << 5)
#define HV_CLUSTER_IPI_RECOMMENDED (1u << 10)
#define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11)
+#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14)
/*
* Basic virtualized MSRs
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 796a049..f524e7d 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -869,6 +869,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
uint32_t unused;
struct kvm_cpuid_entry2 *c;
uint32_t signature[3];
+ uint16_t evmcs_version;
int kvm_base = KVM_CPUID_SIGNATURE;
int r;
Error *local_err = NULL;
@@ -912,7 +913,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
memset(signature, 0, 12);
memcpy(signature, cpu->hyperv_vendor_id, len);
}
- c->eax = HV_CPUID_MIN;
+ c->eax = cpu->hyperv_evmcs ?
+ HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS;
c->ebx = signature[0];
c->ecx = signature[1];
c->edx = signature[2];
@@ -970,7 +972,16 @@ int kvm_arch_init_vcpu(CPUState *cs)
c->eax |= HV_CLUSTER_IPI_RECOMMENDED;
c->eax |= HV_EX_PROCESSOR_MASKS_RECOMMENDED;
}
-
+ if (cpu->hyperv_evmcs) {
+ if (kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0,
+ (uintptr_t)&evmcs_version)) {
+ fprintf(stderr, "Hyper-V Enlightened VMCS "
+ "(requested by 'hv-evmcs' cpu flag) "
+ "is not supported by kernel\n");
+ return -ENOSYS;
+ }
+ c->eax |= HV_ENLIGHTENED_VMCS_RECOMMENDED;
+ }
c->ebx = cpu->hyperv_spinlock_attempts;
c = &cpuid_data.entries[cpuid_i++];
@@ -981,6 +992,21 @@ int kvm_arch_init_vcpu(CPUState *cs)
kvm_base = KVM_CPUID_SIGNATURE_NEXT;
has_msr_hv_hypercall = true;
+
+ if (cpu->hyperv_evmcs) {
+ __u32 function;
+
+ /* Create zeroed 0x40000006..0x40000009 leaves */
+ for (function = HV_CPUID_IMPLEMENT_LIMITS + 1;
+ function < HV_CPUID_NESTED_FEATURES; function++) {
+ c = &cpuid_data.entries[cpuid_i++];
+ c->function = function;
+ }
+
+ c = &cpuid_data.entries[cpuid_i++];
+ c->function = HV_CPUID_NESTED_FEATURES;
+ c->eax = evmcs_version;
+ }
}
if (cpu->expose_kvm) {
--
1.8.3.1
next prev parent reply other threads:[~2018-11-06 21:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 21:37 [Qemu-devel] [PULL 00/17] Misc patches for QEMU 3.1 hard freeze (?) Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 01/17] icount: fix deadlock when all cpus are sleeping Paolo Bonzini
2018-11-06 21:37 ` Paolo Bonzini [this message]
2018-11-06 21:37 ` [Qemu-devel] [PULL 03/17] i386: clarify that the Q35 machine type implements a P35 chipset Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 04/17] ivshmem: fix memory backend leak Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 05/17] MAINTAINERS: remove or downgrade myself to reviewer from some subsystems Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 06/17] target/i386: Clear RF on SYSCALL instruction Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 07/17] memory: learn about non-volatile memory region Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 08/17] nvdimm: set non-volatile on the " Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 09/17] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 10/17] scripts/dump-guest-memory: Synchronize with guest_phys_blocks_region_add Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 11/17] lsi53c895a: check message length value is valid Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 12/17] scsi-generic: keep VPD page list sorted Paolo Bonzini
2018-11-06 21:37 ` [Qemu-devel] [PULL 13/17] scsi-generic: avoid out-of-bounds access to VPD page list Paolo Bonzini
2018-11-06 21:38 ` [Qemu-devel] [PULL 14/17] scsi-generic: avoid invalid access to struct when emulating block limits Paolo Bonzini
2018-11-06 21:38 ` [Qemu-devel] [PULL 15/17] scsi-generic: do not do VPD emulation for sense other than ILLEGAL_REQUEST Paolo Bonzini
2018-11-06 21:38 ` [Qemu-devel] [PULL 16/17] include/qemu/thread.h: Document qemu_thread_atexit* API Paolo Bonzini
2018-11-06 21:38 ` [Qemu-devel] [PULL 17/17] util/qemu-thread-posix: Fix qemu_thread_atexit* for OSX Paolo Bonzini
2018-11-06 23:08 ` [Qemu-devel] [PULL 00/17] Misc patches for QEMU 3.1 hard freeze (?) Peter Maydell
2018-11-08 11:33 ` Peter Maydell
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=1541540283-45699-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vkuznets@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).