[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 10/11] target/i386/kvm: Clean up error handling in kvm_arch_in
From: |
Zhao Liu |
Subject: |
[PATCH v5 10/11] target/i386/kvm: Clean up error handling in kvm_arch_init() |
Date: |
Wed, 6 Nov 2024 11:07:27 +0800 |
Currently, there're following incorrect error handling cases in
kvm_arch_init():
* Missed to handle failure of kvm_get_supported_feature_msrs().
* Missed to return when kvm_vm_enable_disable_exits() fails.
* MSR filter related cases called exit() directly instead of returning
to kvm_init(). (The caller of kvm_arch_init() - kvm_init() - needs to
know if kvm_arch_init() fails in order to perform cleanup).
Fix the above cases.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Zide Chen <zide.chen@intel.com>
---
v5: cleaned up kvm_vm_enable_energy_msrs().
v3: new commit.
---
target/i386/kvm/kvm.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 69825b53b6da..013c0359acbe 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -3147,7 +3147,7 @@ static int kvm_vm_enable_userspace_msr(KVMState *s)
return 0;
}
-static void kvm_vm_enable_energy_msrs(KVMState *s)
+static int kvm_vm_enable_energy_msrs(KVMState *s)
{
int ret;
@@ -3157,7 +3157,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
if (ret < 0) {
error_report("Could not install MSR_RAPL_POWER_UNIT handler: %s",
strerror(-ret));
- exit(1);
+ return ret;
}
ret = kvm_filter_msr(s, MSR_PKG_POWER_LIMIT,
@@ -3165,7 +3165,7 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
if (ret < 0) {
error_report("Could not install MSR_PKG_POWER_LIMIT handler: %s",
strerror(-ret));
- exit(1);
+ return ret;
}
ret = kvm_filter_msr(s, MSR_PKG_POWER_INFO,
@@ -3173,17 +3173,17 @@ static void kvm_vm_enable_energy_msrs(KVMState *s)
if (ret < 0) {
error_report("Could not install MSR_PKG_POWER_INFO handler: %s",
strerror(-ret));
- exit(1);
+ return ret;
}
ret = kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS,
kvm_rdmsr_pkg_energy_status, NULL);
if (ret < 0) {
error_report("Could not install MSR_PKG_ENERGY_STATUS handler: %s",
strerror(-ret));
- exit(1);
+ return ret;
}
}
- return;
+ return 0;
}
int kvm_arch_init(MachineState *ms, KVMState *s)
@@ -3250,7 +3250,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
return ret;
}
- kvm_get_supported_feature_msrs(s);
+ ret = kvm_get_supported_feature_msrs(s);
+ if (ret < 0) {
+ return ret;
+ }
uname(&utsname);
lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
@@ -3286,6 +3289,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
if (ret < 0) {
error_report("kvm: guest stopping CPU not supported: %s",
strerror(-ret));
+ return ret;
}
}
@@ -3317,12 +3321,15 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
}
if (s->msr_energy.enable == true) {
- kvm_vm_enable_energy_msrs(s);
+ ret = kvm_vm_enable_energy_msrs(s);
+ if (ret < 0) {
+ return ret;
+ }
ret = kvm_msr_energy_thread_init(s, ms);
if (ret < 0) {
error_report("kvm : error RAPL feature requirement not met");
- exit(1);
+ return ret;
}
}
}
--
2.34.1
- [PATCH v5 01/11 for v9.2?] i386/cpu: Mark avx10_version filtered when prefix is NULL, (continued)
- [PATCH v5 01/11 for v9.2?] i386/cpu: Mark avx10_version filtered when prefix is NULL, Zhao Liu, 2024/11/05
- [PATCH v5 03/11] target/i386/kvm: Remove local MSR_KVM_WALL_CLOCK and MSR_KVM_SYSTEM_TIME definitions, Zhao Liu, 2024/11/05
- [PATCH v5 02/11] target/i386/kvm: Add feature bit definitions for KVM CPUID, Zhao Liu, 2024/11/05
- [PATCH v5 06/11] target/i386/kvm: Drop workaround for KVM_X86_DISABLE_EXITS_HTL typo, Zhao Liu, 2024/11/05
- [PATCH v5 05/11] target/i386/kvm: Save/load MSRs of kvmclock2 (KVM_FEATURE_CLOCKSOURCE2), Zhao Liu, 2024/11/05
- [PATCH v5 04/11] target/i386/kvm: Only save/load kvmclock MSRs when kvmclock enabled, Zhao Liu, 2024/11/05
- [PATCH v5 08/11] target/i386/kvm: Clean up return values of MSR filter related functions, Zhao Liu, 2024/11/05
- [PATCH v5 07/11] target/i386/confidential-guest: Fix comment of x86_confidential_guest_kvm_type(), Zhao Liu, 2024/11/05
- [PATCH v5 09/11] target/i386/kvm: Return -1 when kvm_msr_energy_thread_init() fails, Zhao Liu, 2024/11/05
- [PATCH v5 10/11] target/i386/kvm: Clean up error handling in kvm_arch_init(),
Zhao Liu <=
- [PATCH v5 11/11] target/i386/kvm: Replace ARRAY_SIZE(msr_handlers) with KVM_MSR_FILTER_MAX_RANGES, Zhao Liu, 2024/11/05