[Devel] [PATCH RH9 05/28] kvm/x86: add log printing on emulation failure

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Oct 14 13:33:13 MSK 2021


From: Denis Plotnikov <dplotnikov at virtuozzo.com>

This is a temporary patch serving to increase the amount of data
available for analysis in the cases of kvm "emulation failure" for
bugs like the following:

https://jira.sw.ru/browse/PSBM-95474
https://jira.sw.ru/browse/PSBM-68018

Signed-off-by: Denis Plotnikov <dplotnikov at virtuozzo.com>

(cherry-picked from vz7 commit 47d875ee2284 ("kvm/x86: add log printing on
emulation failure"))

https://jira.sw.ru/browse/PSBM-127849
Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>

(cherry picked from vz8 commit e3aa92a51c1dd901cd06ccd70eff7cce0ba3b6c8)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 arch/x86/kvm/x86.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e5d5c5e..08c4c74 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -61,6 +61,7 @@
 #include <linux/suspend.h>
 
 #include <trace/events/kvm.h>
+#include <linux/kvm_host.h>
 
 #include <asm/debugreg.h>
 #include <asm/msr.h>
@@ -7488,6 +7489,34 @@ static void prepare_emulation_failure_exit(struct kvm_vcpu *vcpu)
 	}
 }
 
+static void printk_emulation_data(struct kvm_vcpu *vcpu, int emulation_type)
+{
+	struct x86_emulate_ctxt *ctx = vcpu->arch.emulate_ctxt;
+	int i;
+
+	vcpu_err(vcpu, "=== emulation failure ===\n");
+
+	dump_stack();
+
+	vcpu_err(vcpu, "emulation context data (emulation_type: 0x%x)\n",
+		emulation_type);
+	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",
+		ctx->opcode_len, ctx->b, ctx->op_bytes, ctx->ad_bytes);
+	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, "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, "=== end of emulation failure ===\n");
+}
+
 static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
 {
 	struct kvm *kvm = vcpu->kvm;
@@ -7503,6 +7532,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);
 		return 0;
 	}
 
-- 
1.8.3.1



More information about the Devel mailing list