[PATCH 1/2] KVM: x86: Return emulator error if RDMSR/WRMSR emulation failed
From: Hou Wenlong
Date: Thu Jul 28 2022 - 04:25:21 EST
The return value of emulator_{get|set}_mst_with_filter()
is confused, since msr access error and emulator error
are mixed. Although, KVM_MSR_RET_* doesn't conflict with
X86EMUL_IO_NEEDED at present, it is better to convert
msr access error to emulator error if error value is
needed.
Signed-off-by: Hou Wenlong <houwenlong.hwl@xxxxxxxxxxxx>
---
arch/x86/kvm/x86.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5366f884e9a7..8df89b9c212f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7908,11 +7908,12 @@ static int emulator_get_msr_with_filter(struct x86_emulate_ctxt *ctxt,
int r;
r = kvm_get_msr_with_filter(vcpu, msr_index, pdata);
-
- if (r && kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_RDMSR, 0,
- complete_emulated_rdmsr, r)) {
- /* Bounce to user space */
- return X86EMUL_IO_NEEDED;
+ if (r) {
+ if (kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_RDMSR, 0,
+ complete_emulated_rdmsr, r))
+ r = X86EMUL_IO_NEEDED;
+ else
+ r = X86EMUL_UNHANDLEABLE;
}
return r;
@@ -7925,11 +7926,12 @@ static int emulator_set_msr_with_filter(struct x86_emulate_ctxt *ctxt,
int r;
r = kvm_set_msr_with_filter(vcpu, msr_index, data);
-
- if (r && kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_WRMSR, data,
- complete_emulated_msr_access, r)) {
- /* Bounce to user space */
- return X86EMUL_IO_NEEDED;
+ if (r > 0) {
+ if (kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_WRMSR, data,
+ complete_emulated_msr_access, r))
+ r = X86EMUL_IO_NEEDED;
+ else
+ r = X86EMUL_UNHANDLEABLE;
}
return r;
--
2.31.1