[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/19] target-i386: post memory failure event to QMP
From: |
Paolo Bonzini |
Subject: |
[PULL 17/19] target-i386: post memory failure event to QMP |
Date: |
Mon, 5 Oct 2020 10:23:47 +0200 |
From: zhenwei pi <pizhenwei@bytedance.com>
Post memory failure event through QMP to handle hardware memory corrupted
event. Rather than simply printing to the log, QEMU could report more
effective message to the client. For example, if a guest receives an MCE,
evacuating the host could be a good idea.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20200930100440.1060708-4-pizhenwei@bytedance.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/helper.c | 24 ++++++++++++++++++++----
target/i386/kvm.c | 13 ++++++++++++-
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/target/i386/helper.c b/target/i386/helper.c
index 17e1684ff9..32fa21a7bb 100644
--- a/target/i386/helper.c
+++ b/target/i386/helper.c
@@ -18,6 +18,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/qapi-events-run-state.h"
#include "cpu.h"
#include "exec/exec-all.h"
#include "qemu/qemu-print.h"
@@ -851,6 +852,15 @@ typedef struct MCEInjectionParams {
int flags;
} MCEInjectionParams;
+static void emit_guest_memory_failure(MemoryFailureAction action, bool ar,
+ bool recursive)
+{
+ MemoryFailureFlags mff = {.action_required = ar, .recursive = recursive};
+
+ qapi_event_send_memory_failure(MEMORY_FAILURE_RECIPIENT_GUEST, action,
+ &mff);
+}
+
static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
{
MCEInjectionParams *params = data.host_ptr;
@@ -859,16 +869,18 @@ static void do_inject_x86_mce(CPUState *cs,
run_on_cpu_data data)
uint64_t *banks = cenv->mce_banks + 4 * params->bank;
g_autofree char *msg = NULL;
bool need_reset = false;
+ bool recursive;
+ bool ar = !!(params->status & MCI_STATUS_AR);
cpu_synchronize_state(cs);
+ recursive = !!(cenv->mcg_status & MCG_STATUS_MCIP);
/*
* If there is an MCE exception being processed, ignore this SRAO MCE
* unless unconditional injection was requested.
*/
- if (!(params->flags & MCE_INJECT_UNCOND_AO)
- && !(params->status & MCI_STATUS_AR)
- && (cenv->mcg_status & MCG_STATUS_MCIP)) {
+ if (!(params->flags & MCE_INJECT_UNCOND_AO) && !ar && recursive) {
+ emit_guest_memory_failure(MEMORY_FAILURE_ACTION_IGNORE, ar, recursive);
return;
}
@@ -896,7 +908,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data
data)
return;
}
- if (cenv->mcg_status & MCG_STATUS_MCIP) {
+ if (recursive) {
need_reset = true;
msg = g_strdup_printf("CPU %d: Previous MCE still in progress, "
"raising triple fault", cs->cpu_index);
@@ -909,6 +921,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data
data)
}
if (need_reset) {
+ emit_guest_memory_failure(MEMORY_FAILURE_ACTION_RESET, ar,
+ recursive);
monitor_printf(params->mon, "%s", msg);
qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
@@ -934,6 +948,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data
data)
} else {
banks[1] |= MCI_STATUS_OVER;
}
+
+ emit_guest_memory_failure(MEMORY_FAILURE_ACTION_INJECT, ar, recursive);
}
void cpu_x86_inject_mce(Monitor *mon, X86CPU *cpu, int bank,
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index f6dae4cfb6..8b12387d30 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -13,6 +13,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/qapi-events-run-state.h"
#include "qapi/error.h"
#include <sys/ioctl.h>
#include <sys/utsname.h>
@@ -549,8 +550,17 @@ static void kvm_mce_inject(X86CPU *cpu, hwaddr paddr, int
code)
(MCM_ADDR_PHYS << 6) | 0xc, flags);
}
+static void emit_hypervisor_memory_failure(MemoryFailureAction action, bool ar)
+{
+ MemoryFailureFlags mff = {.action_required = ar, .recursive = false};
+
+ qapi_event_send_memory_failure(MEMORY_FAILURE_RECIPIENT_HYPERVISOR, action,
+ &mff);
+}
+
static void hardware_memory_error(void *host_addr)
{
+ emit_hypervisor_memory_failure(MEMORY_FAILURE_ACTION_FATAL, true);
error_report("QEMU got Hardware memory error at addr %p", host_addr);
exit(1);
}
@@ -605,7 +615,8 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void
*addr)
hardware_memory_error(addr);
}
- /* Hope we are lucky for AO MCE */
+ /* Hope we are lucky for AO MCE, just notify a event */
+ emit_hypervisor_memory_failure(MEMORY_FAILURE_ACTION_IGNORE, false);
}
static void kvm_reset_exception(CPUX86State *env)
--
2.26.2
- [PULL 05/19] configure: move accelerator logic to meson, (continued)
- [PULL 05/19] configure: move accelerator logic to meson, Paolo Bonzini, 2020/10/05
- [PULL 11/19] configure: move OpenBSD W^X test to meson, Paolo Bonzini, 2020/10/05
- [PULL 12/19] default-configs: use TARGET_ARCH key, Paolo Bonzini, 2020/10/05
- [PULL 10/19] default-configs: remove default-configs/devices for user-mode targets, Paolo Bonzini, 2020/10/05
- [PULL 13/19] default-configs: remove redundant keys, Paolo Bonzini, 2020/10/05
- [PULL 15/19] target-i386: seperate MCIP & MCE_MASK error reason, Paolo Bonzini, 2020/10/05
- [PULL 16/19] qapi/run-state.json: introduce memory failure event, Paolo Bonzini, 2020/10/05
- [PULL 09/19] configure: remove target configuration, Paolo Bonzini, 2020/10/05
- [PULL 19/19] dockerfiles: add diffutils to Fedora, Paolo Bonzini, 2020/10/05
- [PULL 14/19] meson: move sparse detection to Meson and rewrite check_sparse.py, Paolo Bonzini, 2020/10/05
- [PULL 17/19] target-i386: post memory failure event to QMP,
Paolo Bonzini <=
- [PULL 18/19] tests: tcg: do not use implicit rules, Paolo Bonzini, 2020/10/05
- Re: [PULL 00/19] Build system + MCE patches for 2020-10-05, Peter Maydell, 2020/10/05