From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Liran Alon <liran.alon@oracle.com>,
Roman Kagan <rkagan@virtuozzo.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: [PATCH RFC] i386/kvm: fix enlightened VMCS with fine-grained VMX feature enablement
Date: Thu, 2 Jan 2020 21:39:26 +0100 [thread overview]
Message-ID: <20200102203926.1179743-1-vkuznets@redhat.com> (raw)
When enlightened VMCS is enabled, certain VMX controls disappear, e.g.
posted interrupts for PINBASED_CTLS. With fine-grained VMX feature
enablement QEMU tries to do KVM_SET_MSRS with default (matching CPU
model) values and fails as KVM doesn't allow to set now-unsupported
controls.
The ideal solution for the issue would probably be to re-read VMX
feature MSRs after enabling KVM_CAP_HYPERV_ENLIGHTENED_VMCS, however,
this doesn't seem to be possible: currently, KVM returns global
&vmcs_config.nested values for VMX MSRs when userspace does KVM_GET_MSR.
It is also possible to modify KVM to apply 'evmcs filtering' to VMX
MSRs when userspace tries to set them and hide the issue but this doesn't
seem to be entirely correct.
It is unfortunate that we now need to support the list of VMX features
disabled by enlightened VMCS in QEMU. When (and if) enlightened VMCS v2
arrives we'll need to fix QEMU and allow previously disabled features.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
- I don't quite like this workaround myself, thus RFC. I'm sure someone
will suggest a better alternative.
---
target/i386/kvm.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 0b511906e3fe..1b0589b79358 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1198,6 +1198,30 @@ static int hyperv_handle_properties(CPUState *cs,
}
if (!r) {
+ /*
+ * Certain VMX controls are unsupported when enlightened VMCS is
+ * enabled, filter them out here so we don't attempt to set them
+ * with KVM_SET_MSR even if they are supported by CPU model.
+ * The list below is for eVMCS version 1.
+ */
+ env->features[FEAT_VMX_PINBASED_CTLS] &=
+ ~(VMX_PIN_BASED_VMX_PREEMPTION_TIMER |
+ VMX_PIN_BASED_POSTED_INTR);
+ env->features[FEAT_VMX_SECONDARY_CTLS] &=
+ ~(VMX_SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
+ VMX_SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
+ VMX_SECONDARY_EXEC_APIC_REGISTER_VIRT |
+ VMX_SECONDARY_EXEC_ENABLE_PML |
+ VMX_SECONDARY_EXEC_ENABLE_VMFUNC |
+ VMX_SECONDARY_EXEC_SHADOW_VMCS |
+ /* VMX_SECONDARY_EXEC_TSC_SCALING | */
+ VMX_SECONDARY_EXEC_PAUSE_LOOP_EXITING);
+ env->features[FEAT_VMX_ENTRY_CTLS] &=
+ ~VMX_VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
+ env->features[FEAT_VMX_EXIT_CTLS] &=
+ ~VMX_VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
+ env->features[FEAT_VMX_VMFUNC] &= ~MSR_VMX_VMFUNC_EPT_SWITCHING;
+
env->features[FEAT_HV_RECOMM_EAX] |=
HV_ENLIGHTENED_VMCS_RECOMMENDED;
env->features[FEAT_HV_NESTED_EAX] = evmcs_version;
--
2.24.1
next reply other threads:[~2020-01-02 20:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-02 20:39 Vitaly Kuznetsov [this message]
2020-01-07 8:31 ` [PATCH RFC] i386/kvm: fix enlightened VMCS with fine-grained VMX feature enablement Paolo Bonzini
2020-01-07 12:08 ` Vitaly Kuznetsov
2020-01-07 12:25 ` Paolo Bonzini
2020-01-07 18:15 ` Vitaly Kuznetsov
2020-01-07 21:23 ` Paolo Bonzini
2020-01-08 10:32 ` Vitaly Kuznetsov
2020-01-10 15:02 ` Vitaly Kuznetsov
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=20200102203926.1179743-1-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=ehabkost@redhat.com \
--cc=liran.alon@oracle.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=rth@twiddle.net \
/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).