From nobody Mon Feb 9 22:20:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601886890; cv=none; d=zohomail.com; s=zohoarc; b=IPULppc79WAciLcB1vGpTVDv7n0q0WjIYizWap7t0jr34jKS3BifBzDow8v8ItNIfdsrNJopMf0BnHklYSvL0uIY5GXwss7EnKTWrjEI8nIxMNaaZLt7ltf/5Rdn9QPx1Qw5ZsDj1BO5z9F0f2DAw8OpFFamj7cvDRn5I5fQDj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601886890; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+qTSz1E9WPbTWRbvvqKtc2mBpV+7bgZoqIwjSP5/4yk=; b=RwIYMEX7MRAs3/SyquLsfgJfbD4LqKMvo/Izd1u+sbPtxIpH2tgnlf/UiU1TqBDokL+4e8wJjUrgjhMbNpIXOn/7KPiAhzKkVT0aVQqmopAgvjdnQ7uKyAn4DIQM3lXj107LSacA64MyAWrQj0h5Uzo/DN0H04h/+H2oq0nu4ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1601886890441392.4954180445559; Mon, 5 Oct 2020 01:34:50 -0700 (PDT) Received: from localhost ([::1]:50636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPLxH-0002Jr-Eh for importer@patchew.org; Mon, 05 Oct 2020 04:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPLmw-0008GY-84 for qemu-devel@nongnu.org; Mon, 05 Oct 2020 04:24:06 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:51340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPLmu-0007LC-GH for qemu-devel@nongnu.org; Mon, 05 Oct 2020 04:24:05 -0400 Received: by mail-wm1-x343.google.com with SMTP id d81so2593057wmc.1 for ; Mon, 05 Oct 2020 01:24:04 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:2e86:3d8b:8b70:920c]) by smtp.gmail.com with ESMTPSA id z15sm11931434wrv.94.2020.10.05.01.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 01:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+qTSz1E9WPbTWRbvvqKtc2mBpV+7bgZoqIwjSP5/4yk=; b=IuCquimDXf+B7F5q6uUK2dKhSU9jrnsEg4ueW3wqSeQ+Hu2ZI8R4secncuTQ9i3VG1 43jU2dJK2YUtXZt8SKNhpXP2m+WUaYkUa8KCUixgWO0J/zzWC/SNqGrbQhCwZ6RQxHhc 82db94RxcgAT0pzSv6u+YCMLHQe9vby1ebCTyA2+Oja4ZCZ6B6DR/DGkNoLyIMP9XDLp 58RmwlJCGvr4uHcjtleq5oWRvzcv50vvxcCxASD5wC5QKwTJMCwh2xpjqeS6Yee/k2Dv rDMSOTDe6WnIJ7mz7FJ2eWLIXx8TZarec1jekZL4ih1awyiUy1RbcqO71nEOBVCPzRqg wkkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+qTSz1E9WPbTWRbvvqKtc2mBpV+7bgZoqIwjSP5/4yk=; b=uR79FDfajC7ZlkjWxtFk/MvfYohzpL1Ld5n4aGT1vAauDUi4r1HYWtEDRU7D/ZfdKc dPw47aozs/Vt9x8N2fT8j4cBvTbYHH3jptVJWtawaB1HwQy0tHwJQOl8adPWxBWTLSLb X6ppsMJh82EVWHkHMhT5kCwcXXdl77hkw2CSqsz+lDpqCw5XBEeFmGPw0njJ0Ldqtjt0 +V2W3q+noCbFE1wea7yJ4aCNWcbGokZLoVOApGHEijkwA9CHMPwg8k0UZoFKOpW24/w1 8A5qwse0ybaykXsmy1yeFUiflv7hVUGZZKvwvGo5g83TGAYxkAoXBG6Qc3tfdJRxYZ54 ZbBg== X-Gm-Message-State: AOAM531SPDtcnmZt/IZNYxwijGuM6ZukcVJxmsJcttzmqqgUPXd4d8u8 CvPrx+CslGjlwgt2bG4dAcAI3X0cRUk= X-Google-Smtp-Source: ABdhPJyu2P2Ic9BnxwXAGYPeNKmI9StUsr8W4hUfFXG780b7NDvObCHcGe1HiRUL+G2IOAvLx2e5XA== X-Received: by 2002:a1c:7708:: with SMTP id t8mr3611232wmi.6.1601886242818; Mon, 05 Oct 2020 01:24:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 17/19] target-i386: post memory failure event to QMP Date: Mon, 5 Oct 2020 10:23:47 +0200 Message-Id: <20201005082349.354095-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201005082349.354095-1-pbonzini@redhat.com> References: <20201005082349.354095-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhenwei pi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: zhenwei pi 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 Message-Id: <20200930100440.1060708-4-pizhenwei@bytedance.com> Signed-off-by: Paolo Bonzini --- 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 @@ */ =20 #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; =20 +static void emit_guest_memory_failure(MemoryFailureAction action, bool ar, + bool recursive) +{ + MemoryFailureFlags mff =3D {.action_required =3D ar, .recursive =3D re= cursive}; + + 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 =3D data.host_ptr; @@ -859,16 +869,18 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cp= u_data data) uint64_t *banks =3D cenv->mce_banks + 4 * params->bank; g_autofree char *msg =3D NULL; bool need_reset =3D false; + bool recursive; + bool ar =3D !!(params->status & MCI_STATUS_AR); =20 cpu_synchronize_state(cs); + recursive =3D !!(cenv->mcg_status & MCG_STATUS_MCIP); =20 /* * 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, recurs= ive); return; } =20 @@ -896,7 +908,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_= data data) return; } =20 - if (cenv->mcg_status & MCG_STATUS_MCIP) { + if (recursive) { need_reset =3D true; msg =3D g_strdup_printf("CPU %d: Previous MCE still in progres= s, " "raising triple fault", cs->cpu_index); @@ -909,6 +921,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_= data data) } =20 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] |=3D MCI_STATUS_OVER; } + + emit_guest_memory_failure(MEMORY_FAILURE_ACTION_INJECT, ar, recursive); } =20 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 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/qapi-events-run-state.h" #include "qapi/error.h" #include #include @@ -549,8 +550,17 @@ static void kvm_mce_inject(X86CPU *cpu, hwaddr paddr, = int code) (MCM_ADDR_PHYS << 6) | 0xc, flags); } =20 +static void emit_hypervisor_memory_failure(MemoryFailureAction action, boo= l ar) +{ + MemoryFailureFlags mff =3D {.action_required =3D ar, .recursive =3D fa= lse}; + + qapi_event_send_memory_failure(MEMORY_FAILURE_RECIPIENT_HYPERVISOR, ac= tion, + &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, voi= d *addr) hardware_memory_error(addr); } =20 - /* 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); } =20 static void kvm_reset_exception(CPUX86State *env) --=20 2.26.2