[Devel] [PATCH RHEL8 COMMIT] kvm/x86: add log printing on emulation failure
Konstantin Khorenko
khorenko at virtuozzo.com
Thu Jun 10 13:32:09 MSK 2021
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.39
------>
commit 6729be5b7ec6961daa15fc89c612becb64671d82
Author: Denis Plotnikov <dplotnikov at virtuozzo.com>
Date: Thu Jun 10 13:32:09 2021 +0300
kvm/x86: add log printing on emulation failure
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>
---
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 b686a6a17c93..8415bd3d04f5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -58,6 +58,7 @@
#include <linux/mem_encrypt.h>
#include <trace/events/kvm.h>
+#include <linux/kvm_host.h>
#include <asm/debugreg.h>
#include <asm/msr.h>
@@ -6503,6 +6504,34 @@ void 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)
+{
+ 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)
{
++vcpu->stat.insn_emulation_fail;
@@ -6517,6 +6546,7 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
vcpu->run->internal.ndata = 0;
+ printk_emulation_data(vcpu, emulation_type);
return 0;
}
More information about the Devel
mailing list