[PATCH 2/6] KVM: x86: pass emulation_reason to handle_emulation_failure()

From: David Edmondson
Date: Mon Apr 12 2021 - 09:09:54 EST


From: Joao Martins <joao.m.martins@xxxxxxxxxx>

Make the emulation_reason available up stack when reporting an
emulation failure.

Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
Signed-off-by: David Edmondson <david.edmondson@xxxxxxxxxx>
---
arch/x86/kvm/x86.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 87e76f3aee64..b9225012ebd2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7119,7 +7119,8 @@ void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip)
}
EXPORT_SYMBOL_GPL(kvm_inject_realmode_interrupt);

-static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
+static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type,
+ int emulation_reason)
{
++vcpu->stat.insn_emulation_fail;
trace_kvm_emulate_insn_failed(vcpu);
@@ -7132,7 +7133,8 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
if (emulation_type & EMULTYPE_SKIP) {
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
- vcpu->run->internal.ndata = 0;
+ vcpu->run->internal.data[0] = emulation_reason;
+ vcpu->run->internal.ndata = 1;
return 0;
}

@@ -7141,7 +7143,8 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
if (!is_guest_mode(vcpu) && static_call(kvm_x86_get_cpl)(vcpu) == 0) {
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
- vcpu->run->internal.ndata = 0;
+ vcpu->run->internal.data[0] = emulation_reason;
+ vcpu->run->internal.ndata = 1;
return 0;
}

@@ -7490,7 +7493,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
inject_emulated_exception(vcpu);
return 1;
}
- return handle_emulation_failure(vcpu, emulation_type);
+ return handle_emulation_failure(vcpu, emulation_type,
+ emulation_reason);
}
}

@@ -7547,7 +7551,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
emulation_type))
return 1;

- return handle_emulation_failure(vcpu, emulation_type);
+ return handle_emulation_failure(vcpu, emulation_type,
+ emulation_reason);
}

if (ctxt->have_exception) {
--
2.30.2