diff mbox series

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

Message ID 20210412130938.68178-3-david.edmondson@oracle.com (mailing list archive)
State New
Headers show
Series KVM: x86: Make the cause of instruction emulation available to user-space | expand

Commit Message

David Edmondson April 12, 2021, 1:09 p.m. UTC
From: Joao Martins <joao.m.martins@oracle.com>

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

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

Patch

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) {