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

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 20 11:40:37 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.12
------>
commit 848acf60750c9bcac5fddfdf04d01aa0fa57ce7e
Author: Denis Plotnikov <dplotnikov at virtuozzo.com>
Date:   Wed Oct 20 11:40:36 2021 +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>
    (cherry-picked from vz7 commit c4f456a14a56 ("kvm/x86: extend info on emualation
    failure"))
    
    https://jira.sw.ru/browse/PSBM-127849
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
    
    (cherry picked from vz8 commit 5a3089e978c6274806deb2b775ce3b71c7f720f7)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko 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 08c4c74ebd4c..a1098f6c0e02 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7489,10 +7489,11 @@ static void prepare_emulation_failure_exit(struct kvm_vcpu *vcpu)
 	}
 }
 
-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");
 
@@ -7500,6 +7501,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",
@@ -7507,17 +7510,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)
 {
 	struct kvm *kvm = vcpu->kvm;
 
@@ -7532,7 +7539,7 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
 	if (kvm->arch.exit_on_emulation_error ||
 	    (emulation_type & EMULTYPE_SKIP)) {
 		prepare_emulation_failure_exit(vcpu);
-		printk_emulation_data(vcpu, emulation_type);
+		printk_emulation_data(vcpu, emulation_type, decoding);
 		return 0;
 	}
 
@@ -7885,7 +7892,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,
+							true);
 		}
 	}
 
@@ -7942,7 +7950,7 @@ 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, false);
 	}
 
 	if (ctxt->have_exception) {


More information about the Devel mailing list