[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC 19/22] i386: prepare hyperv_expand_features() to be called at
From: |
Vitaly Kuznetsov |
Subject: |
[PATCH RFC 19/22] i386: prepare hyperv_expand_features() to be called at CPU feature expansion time |
Date: |
Fri, 4 Sep 2020 16:54:28 +0200 |
If hyperv_expand_features() is called before vCPU is created, cs->kvm_state
is NULL. We can only do the expantion if system wide KVM_GET_SUPPORTED_HV_CPUID
is supported.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
target/i386/kvm.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index b76d4a5a147b..c17e7db5e627 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -986,6 +986,10 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState
*cs)
do_sys_ioctl =
kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID) > 0;
+ if (!do_sys_ioctl && !cs->kvm_state) {
+ return NULL;
+ }
+
/*
* When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with
* -E2BIG, however, it doesn't report back the right size. Keep increasing
@@ -1023,6 +1027,10 @@ static struct kvm_cpuid2
*get_supported_hv_cpuid_legacy(CPUState *cs)
struct kvm_cpuid2 *cpuid;
struct kvm_cpuid_entry2 *entry_feat, *entry_recomm;
+ if (!cs->kvm_state) {
+ return NULL;
+ }
+
/* HV_CPUID_FEATURES, HV_CPUID_ENLIGHTMENT_INFO */
cpuid = g_malloc0(sizeof(*cpuid) + 2 * sizeof(*cpuid->entries));
cpuid->nent = 2;
@@ -1218,12 +1226,15 @@ static void hyperv_expand_features(CPUState *cs, Error
**errp)
if (!hyperv_enabled(cpu))
return;
- if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) {
+ if (kvm_check_extension(kvm_state, KVM_CAP_HYPERV_CPUID) > 0) {
cpuid = get_supported_hv_cpuid(cs);
} else {
cpuid = get_supported_hv_cpuid_legacy(cs);
}
+ if (!cpuid)
+ return;
+
if (cpu->hyperv_passthrough) {
c = cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0);
if (c) {
--
2.25.4
- Re: [PATCH RFC 12/22] i386: always fill Hyper-V CPUID feature leaves from X86CPU data, (continued)
- [PATCH RFC 15/22] i386: switch hyperv_expand_features() to using error_setg(), Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 18/22] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 22/22] i386: expand Hyper-V features early, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 21/22] i386: record if Hyper-V features were already expanded, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 19/22] i386: prepare hyperv_expand_features() to be called at CPU feature expansion time,
Vitaly Kuznetsov <=
- [PATCH RFC 16/22] i386: make hyperv_expand_features() return void, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 17/22] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size, Vitaly Kuznetsov, 2020/09/04
- [PATCH RFC 20/22] i386: use global kvm_state in hyperv_enabled() check, Vitaly Kuznetsov, 2020/09/04