From: Nikita Leshenko <nikita.leshchenko@oracle.com>
To: kvm@vger.kernel.org
Cc: Nikita Leshenko <nikita.leshchenko@oracle.com>,
Liran Alon <liran.alon@oracle.com>,
Joao Martins <joao.m.martins@oracle.com>
Subject: [PATCH] KVM: nVMX: Check that HLT activity state is supported
Date: Tue, 13 Aug 2019 16:13:03 +0300 [thread overview]
Message-ID: <20190813131303.137684-1-nikita.leshchenko@oracle.com> (raw)
Fail VM entry if GUEST_ACTIVITY_HLT is unsupported. According to "SDM A.6 -
Miscellaneous Data", VM entry should fail if the HLT activity is not marked as
supported on IA32_VMX_MISC MSR.
Usermode might disable GUEST_ACTIVITY_HLT support in the vCPU with
vmx_restore_vmx_misc(). Before this commit VM entries would have succeeded
anyway.
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
---
arch/x86/kvm/vmx/nested.c | 16 ++++++++++++----
arch/x86/kvm/vmx/nested.h | 5 +++++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 46af3a5e9209..3165e2f7992f 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2656,11 +2656,19 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
/*
* Checks related to Guest Non-register State
*/
-static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
+static int nested_check_guest_non_reg_state(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
{
- if (vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
- vmcs12->guest_activity_state != GUEST_ACTIVITY_HLT)
+ switch (vmcs12->guest_activity_state) {
+ case GUEST_ACTIVITY_ACTIVE:
+ /* Always supported */
+ break;
+ case GUEST_ACTIVITY_HLT:
+ if (!nested_cpu_has_activity_state_hlt(vcpu))
+ return -EINVAL;
+ break;
+ default:
return -EINVAL;
+ }
return 0;
}
@@ -2710,7 +2718,7 @@ static int nested_vmx_check_guest_state(struct kvm_vcpu *vcpu,
(vmcs12->guest_bndcfgs & MSR_IA32_BNDCFGS_RSVD)))
return -EINVAL;
- if (nested_check_guest_non_reg_state(vmcs12))
+ if (nested_check_guest_non_reg_state(vcpu, vmcs12))
return -EINVAL;
return 0;
diff --git a/arch/x86/kvm/vmx/nested.h b/arch/x86/kvm/vmx/nested.h
index e847ff1019a2..4a294d3ff820 100644
--- a/arch/x86/kvm/vmx/nested.h
+++ b/arch/x86/kvm/vmx/nested.h
@@ -123,6 +123,11 @@ static inline bool nested_cpu_has_zero_length_injection(struct kvm_vcpu *vcpu)
return to_vmx(vcpu)->nested.msrs.misc_low & VMX_MISC_ZERO_LEN_INS;
}
+static inline bool nested_cpu_has_activity_state_hlt(struct kvm_vcpu *vcpu)
+{
+ return to_vmx(vcpu)->nested.msrs.misc_low & VMX_MISC_ACTIVITY_HLT;
+}
+
static inline bool nested_cpu_supports_monitor_trap_flag(struct kvm_vcpu *vcpu)
{
return to_vmx(vcpu)->nested.msrs.procbased_ctls_high &
--
2.20.1
next reply other threads:[~2019-08-13 13:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-13 13:13 Nikita Leshenko [this message]
2019-08-13 14:35 ` [PATCH] KVM: nVMX: Check that HLT activity state is supported Sean Christopherson
2019-08-14 6:59 ` Nikita Leshenko
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=20190813131303.137684-1-nikita.leshchenko@oracle.com \
--to=nikita.leshchenko@oracle.com \
--cc=joao.m.martins@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=liran.alon@oracle.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).