[Devel] [PATCH RHEL7 COMMIT] kvm/x86: extend info on emualation failure

Konstantin Khorenko khorenko at virtuozzo.com
Mon Dec 9 14:52:30 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-1062.7.1.vz7.130.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.7.1.vz7.130.1
------>
commit c4f456a14a562a29fbbcf258a6b5262c421d1d0d
Author: Denis Plotnikov <dplotnikov at virtuozzo.com>
Date:   Mon Dec 9 14:52:28 2019 +0300

    kvm/x86: extend info on emualation failure
    
    Patch makes handle emulation failure report the phase where
    the failure occur: on decoding or on emulation.
    
    This is for bugs debugging like
    https://jira.sw.ru/browse/PSBM-99553
    
    Signed-off-by: Denis Plotnikov <dplotnikov at virtuozzo.com>
---
 arch/x86/kvm/x86.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1cf172cf58d5..6fe747e2c925 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5524,10 +5524,11 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip)
 }
 EXPORT_SYMBOL_GPL(kvm_inject_realmode_interrupt);
 
-static void printk_emulation_data(struct kvm_vcpu *vcpu, int emulation_type)
+static void printk_emulation_data(struct kvm_vcpu *vcpu, int emulation_type,
+				  bool decoding)
 {
 	struct x86_emulate_ctxt *ctx = &vcpu->arch.emulate_ctxt;
-	int i;
+	uint64_t i;
 
 	vcpu_err(vcpu, "=== emulation failure ===\n");
 
@@ -5535,6 +5536,8 @@ static void printk_emulation_data(struct kvm_vcpu *vcpu, int emulation_type)
 
 	vcpu_err(vcpu, "emulation context data (emulation_type: 0x%x)\n",
 		emulation_type);
+	vcpu_err(vcpu, "failed phase: %s\n",
+		decoding ? "decoding" : "emulation");
 	vcpu_err(vcpu, "eflags: 0x%lx start_eip: 0x%lx mode: %d\n",
 		ctx->eflags, ctx->eip, ctx->mode);
 	vcpu_err(vcpu, "opcode_len: %u b: 0x%x op_bytes: %u ad_bytes: %u\n",
@@ -5542,17 +5545,21 @@ static void printk_emulation_data(struct kvm_vcpu *vcpu, int emulation_type)
 	vcpu_err(vcpu, "d: 0x%llx current_eip: 0x%lx\n ", ctx->d, ctx->_eip);
 	vcpu_err(vcpu, "fetch data: data: %p ptr %p pos %p\n",
 		ctx->fetch.data, ctx->fetch.ptr, ctx->fetch.end);
+	vcpu_err(vcpu, "have excpetion: %s\n",
+		ctx->have_exception ? "yes" : "no");
+
 	vcpu_err(vcpu, "fetch data content: ");
 
 	for (i = 0; i < ARRAY_SIZE(ctx->fetch.data); i++) {
 		printk("0x%02x ", ctx->fetch.data[i]);
 	}
-	printk("\n");
+	vcpu_err(vcpu, "\n");
 
 	vcpu_err(vcpu, "=== end of emulation failure ===\n");
 }
 
-static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
+static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type,
+				    bool decoding)
 {
 	int r = EMULATE_DONE;
 
@@ -5567,7 +5574,7 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
 		vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
 		vcpu->run->internal.ndata = 0;
 		r = EMULATE_FAIL;
-		printk_emulation_data(vcpu, emulation_type);
+		printk_emulation_data(vcpu, emulation_type, decoding);
 	}
 
 	kvm_queue_exception(vcpu, UD_VECTOR);
@@ -5906,7 +5913,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 			}
 			if (emulation_type & EMULTYPE_SKIP)
 				return EMULATE_FAIL;
-			return handle_emulation_failure(vcpu, emulation_type);
+			return handle_emulation_failure(vcpu, emulation_type,
+							true);
 		}
 	}
 
@@ -5945,7 +5953,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 					emulation_type))
 			return EMULATE_DONE;
 
-		return handle_emulation_failure(vcpu, emulation_type);
+		return handle_emulation_failure(vcpu, emulation_type, false);
 	}
 
 	if (ctxt->have_exception) {



More information about the Devel mailing list