From patchwork Tue Mar 17 05:02:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1256054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=rKQMHxj1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48hLg26lvmz9sPF for ; Tue, 17 Mar 2020 16:03:58 +1100 (AEDT) Received: from localhost ([::1]:52850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4OS-0006nR-QX for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2020 01:03:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49669) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4Nq-0006hF-Ou for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE4Np-0001CI-GY for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:18 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:43315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jE4Nm-0000d9-Sm; Tue, 17 Mar 2020 01:03:15 -0400 Received: by mail-pg1-x543.google.com with SMTP id u12so11022010pgb.10; Mon, 16 Mar 2020 22:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FpkqH7lKgv3hBCPD1KWrNB8YKsLdSFik7uBKlmMW2Hc=; b=rKQMHxj19vqhmOULQpa3tDb/GIUmhqwquUQWj9wFye3LxUR+0B6BPuWFj5y45hLWX8 lwjV4V5Qx8D0UQ/Vjlhtoh3NRTh/VJ2ASR8XX6Gg3Qx495Y0LMrvyqYy6oPlkGG/WVxY u4/3MeIriXoAyeKRs/c0g5ML0EcNrjdLgxYWUtg/I3FxU0wLONu0pEZ+9umTQLyK33f+ iagqE47+eCApIkdnWamD+EwvQg9ENjsOgD0I3I7uyd19KnlFuxizvIr/StJ/TorYd3rH yzl5VT+5NDRiCZEWR3TLBMadlTyeuiLKhc7T2iqjlWJBTktSxk+BzYrq2RUBtTKh1gxB U91w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FpkqH7lKgv3hBCPD1KWrNB8YKsLdSFik7uBKlmMW2Hc=; b=rwRi2PCn5WhrN0po7rSuuD2eM8ipIEJtmnissWbVM1mbYKD9muZca9ccnVPe4Fpn/Z rPIAVFrK4kkhF64rOExoyIDvjMkJ3AVpvveWZgezUTzE2x2UaRf98vq9nH3GxnOvxKaJ 0OE4vD/f1ydiNAxOAUtB55BLIQreM6u0QIYP3AH3iBnotDaFF6v9qdINLOUl/H+HLj2y lHbCY/qsSD+vi8hoHkLd2Rjb7Pq1QuxQEK4sf5R7USfosvCHc6sA120pKHMOAyrUEQ1I 26kD46zUU/T37SwzU1jDJI/SaSqTXPv6bZDIiIC2mqm+108UPUHqygNBRqS9h5II8cbl 1UAQ== X-Gm-Message-State: ANhLgQ01OstglbFKRmehJX9/duudPAktFgMx6/XRYMlOY3O95ZqZ842j wfL7Ij8hPkd93AVrfG5bdDG8T7ERiTI= X-Google-Smtp-Source: ADFU+vt9wEos5Ya4Xsc+pLppAGYONPDN2ZFLQUBljyHqor1TDqM90pO2muQVuh/NA+4DheBpe243LQ== X-Received: by 2002:a63:ec50:: with SMTP id r16mr3449405pgj.274.1584421393504; Mon, 16 Mar 2020 22:03:13 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id k67sm994803pga.91.2020.03.16.22.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 22:03:13 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Subject: [PATCH 1/5] ppc/spapr: KVM FWNMI should not be enabled until guest requests it Date: Tue, 17 Mar 2020 15:02:11 +1000 Message-Id: <20200317050215.159334-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200317050215.159334-1-npiggin@gmail.com> References: <20200317050215.159334-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 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: Aravinda Prasad , Alexey Kardashevskiy , qemu-devel@nongnu.org, Nicholas Piggin , Greg Kurz , =?utf-8?b?Q8OpZHJp?= =?utf-8?q?c_Le_Goater?= , Ganesh Goudar , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The KVM FWNMI capability should be enabled with the "ibm,nmi-register" rtas call. Although MCEs from KVM will be delivered as architected interrupts to the guest before "ibm,nmi-register" is called, KVM has different behaviour depending on whether the guest has enabled FWNMI (it attempts to do more recovery on behalf of a non-FWNMI guest). Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_caps.c | 5 +++-- hw/ppc/spapr_rtas.c | 7 +++++++ target/ppc/kvm.c | 7 +++++++ target/ppc/kvm_ppc.h | 6 ++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 679ae7959f..eb5521d0c2 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -517,9 +517,10 @@ static void cap_fwnmi_apply(SpaprMachineState *spapr, uint8_t val, } if (kvm_enabled()) { - if (kvmppc_set_fwnmi() < 0) { + if (!kvmppc_get_fwnmi()) { error_setg(errp, "Firmware Assisted Non-Maskable Interrupts(FWNMI) " - "not supported by KVM"); + "not supported by KVM, " + "try appending -machine cap-fwnmi=off"); } } } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 9fb8c8632a..29abe66d01 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -437,6 +437,13 @@ static void rtas_ibm_nmi_register(PowerPCCPU *cpu, return; } + if (kvm_enabled()) { + if (kvmppc_set_fwnmi() < 0) { + rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED); + return; + } + } + spapr->fwnmi_system_reset_addr = sreset_addr; spapr->fwnmi_machine_check_addr = mce_addr; diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 597f72be1b..03d0667e8f 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -88,6 +88,7 @@ static int cap_ppc_safe_indirect_branch; static int cap_ppc_count_cache_flush_assist; static int cap_ppc_nested_kvm_hv; static int cap_large_decr; +static int cap_fwnmi; static uint32_t debug_inst_opcode; @@ -136,6 +137,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) kvmppc_get_cpu_characteristics(s); cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV); cap_large_decr = kvmppc_get_dec_bits(); + cap_fwnmi = kvm_vm_check_extension(s, KVM_CAP_PPC_FWNMI); /* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -2064,6 +2066,11 @@ void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) } } +bool kvmppc_get_fwnmi(void) +{ + return cap_fwnmi; +} + int kvmppc_set_fwnmi(void) { PowerPCCPU *cpu = POWERPC_CPU(first_cpu); diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 332fa0aa1c..fcaf745516 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -27,6 +27,7 @@ void kvmppc_enable_h_page_init(void); void kvmppc_set_papr(PowerPCCPU *cpu); int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr); void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy); +bool kvmppc_get_fwnmi(void); int kvmppc_set_fwnmi(void); int kvmppc_smt_threads(void); void kvmppc_error_append_smt_possible_hint(Error *const *errp); @@ -163,6 +164,11 @@ static inline void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy) { } +static inline bool kvmppc_get_fwnmi(void) +{ + return false; +} + static inline int kvmppc_set_fwnmi(void) { return -1; From patchwork Tue Mar 17 05:02:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1256055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=VrGYtHhV; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48hLgK5Dw7z9sPF for ; Tue, 17 Mar 2020 16:04:13 +1100 (AEDT) Received: from localhost ([::1]:52856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4Oh-00075r-Kd for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2020 01:04:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49805) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4Nv-0006qW-DB for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE4Nu-0001v8-6Z for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:23 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:39958) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jE4Nr-0001Qj-KJ; Tue, 17 Mar 2020 01:03:19 -0400 Received: by mail-pl1-x641.google.com with SMTP id h11so9065376plk.7; Mon, 16 Mar 2020 22:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ZYw6lvEvF1npHa5ZX6HcYXupR8cZnIrf1sZZ0UGhPA=; b=VrGYtHhV5M4XrGBGw3HFJwa+d3kZ/cVK988ufqLL8+d/yRL6qGnPkT0j281IngHKqs 6wS5qbtf5zVvpNosPirSpacoU67qwyKTM+TpVR2oK3oDGcoV4D3MHaU3AOPzG4wBb6l6 nh6t/5C/f5SizwEkjA+SyrbcvKgBJ2nbcHqlXwMDwCaCCc4HailoDdKu5OCe6bMMR0+W IW1eLENc6otVxhVvAQsS9aYhChWM/KZ+ZUWzvurDGxnJfE8P+phwNeDq7UZ0Kgw1aDch n0YNTQcTj2P0J1oR2Obr9FRTPljNZdZ3zSQ8p0wqj+xIRjORkS3IUqs6uxUG6XYPxtJj g8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ZYw6lvEvF1npHa5ZX6HcYXupR8cZnIrf1sZZ0UGhPA=; b=gu9JtD1m4aFedhU+NfH9XHEUCZ3PaIETr9x/8u/hGhtgxD8NGmD4WU8qWcJ7KVhW3Q MNmSAlCvVtOaPFDuaVrefEnPsm/Q60AVfqpRveqsGe9D2Nd7xcYz4OVRWUDOfOqE6mXr DLH9OHUoOHRWVRVLmCPy3eN7seGmrJly87X/D6PGSS9Og9egjLmb9Zf+CO8UyOEca6Yb HD+J2tuVkQfbNUDaT0TnYXQl0DtIM6GGguCKY79TeaXVOySl9T802+tE/FA622/G31G4 RG1IPSi2MlKowCC3r1uJ9kqdlhBRAyLIoRcqjaBkR48CnkZ+T3t/aMzXL5PLYIewqUJl z0rw== X-Gm-Message-State: ANhLgQ2eBi7iR1cqjiw6DCQzZgVo4Ff8FqnKDnoyPeEGFYykvuESWReE Wtu1eHv8YfjbHcq8zbXpftUKpQVQqN8= X-Google-Smtp-Source: ADFU+vvXKd0g1JsmcLYvfK+2EVOTxkWQy8Nqt+mujMDKcN+btEkrxog7FsmGuusb57xGL3m2uWE/qg== X-Received: by 2002:a17:902:6bcb:: with SMTP id m11mr2708697plt.10.1584421398447; Mon, 16 Mar 2020 22:03:18 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id k67sm994803pga.91.2020.03.16.22.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 22:03:17 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Subject: [PATCH 2/5] ppc/spapr: Improve FWNMI machine check delivery corner case comments Date: Tue, 17 Mar 2020 15:02:12 +1000 Message-Id: <20200317050215.159334-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200317050215.159334-1-npiggin@gmail.com> References: <20200317050215.159334-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 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: Aravinda Prasad , Alexey Kardashevskiy , qemu-devel@nongnu.org, Nicholas Piggin , Greg Kurz , =?utf-8?b?Q8OpZHJp?= =?utf-8?q?c_Le_Goater?= , Ganesh Goudar , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some of the conditions are not as clearly documented as they could be. Also the non-FWNMI case does not need a large comment. Signed-off-by: Nicholas Piggin Reviewed-by: Greg Kurz --- hw/ppc/spapr_events.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 323fcef4aa..05337f0671 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -834,17 +834,13 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) Error *local_err = NULL; if (spapr->fwnmi_machine_check_addr == -1) { - /* - * This implies that we have hit a machine check either when the - * guest has not registered FWNMI (i.e., "ibm,nmi-register" not - * called) or between system reset and "ibm,nmi-register". - * Fall back to the old machine check behavior in such cases. - */ + /* Non-FWNMI case, deliver it like an architected CPU interrupt. */ cs->exception_index = POWERPC_EXCP_MCHECK; ppc_cpu_do_interrupt(cs); return; } + /* Wait for FWNMI interlock. */ while (spapr->fwnmi_machine_check_interlock != -1) { /* * Check whether the same CPU got machine check error @@ -856,8 +852,13 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) return; } qemu_cond_wait_iothread(&spapr->fwnmi_machine_check_interlock_cond); - /* Meanwhile if the system is reset, then just return */ if (spapr->fwnmi_machine_check_addr == -1) { + /* + * If the machine was reset while waiting for the interlock, + * abort the delivery. The machine check applies to a context + * that no longer exists, so it wouldn't make sense to deliver + * it now. + */ return; } } @@ -868,7 +869,9 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) * We don't want to abort so we let the migration to continue. * In a rare case, the machine check handler will run on the target. * Though this is not preferable, it is better than aborting - * the migration or killing the VM. + * the migration or killing the VM. It is okay to call + * migrate_del_blocker on a blocker that was not added (which the + * nmi-interlock handler would do when it's called after this). */ warn_report("Received a fwnmi while migration was in progress"); } From patchwork Tue Mar 17 05:02:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1256056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=opoZ+f1P; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48hLj80mPjz9sRf for ; Tue, 17 Mar 2020 16:05:48 +1100 (AEDT) Received: from localhost ([::1]:52876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4QE-00014k-0Y for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2020 01:05:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49957) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4O0-00072M-M6 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE4Nz-0002dm-BK for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:28 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:35995) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jE4Nw-0002CO-JM; Tue, 17 Mar 2020 01:03:24 -0400 Received: by mail-pj1-x1043.google.com with SMTP id nu11so6642855pjb.1; Mon, 16 Mar 2020 22:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=amo7tEPKLKAI4LAECmJK7fRz7zN6KrBvaL5VCtrB9GE=; b=opoZ+f1PJBBHSae1VU28wafJiBg312u0Y32s6moJ7ne8JRs3Imom3SpQMpe+LlFajp aOFMyTvrDQNvXgSNVo7zODg2qWU2AVY8W38eocq26WikWvoG11PxjseSWTsWEHuVX471 lrQKXNFmiUd+SmGkEOd9AztW2z/RxB+ehvk4ulhCgmi1ZqAWHMIxMbGnDAM19yGKiUXV TuWuavT2zwmDvd+C7gBeWBYH8iqgp/TD0zDpntDzVClOTiO1qhOHtwH/Hn0zqJuVAnBx zWRu3xkmgWgfMqMv/bt8+awSRV4nG6Tdg0gd8ODO26L9HigthdE9QumUaMLi1Fs9vNv1 8Cug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=amo7tEPKLKAI4LAECmJK7fRz7zN6KrBvaL5VCtrB9GE=; b=H36kD9csnktEQf4x+yO0Bk7vr+3+BvAjtAYQryGsyEFI3i8Ra5yHbz8ePhJ0B4KlPk guiN0+MjMVbxEGyF2mHla04Ll9KxDv857HhKyKzLELVWqEkvgPTuuG1MFnUSH+frIajE AJDlRoYlTpz7nQcou1dvRa4LUPVkh4Fa6Ctrfp8+eT9OQ27uYmM68mkgl6KkHbZONW8Q jwAP8Vr8eDIpKJpxVb89Wq9eYGO6+goIfqnKa0kPNbkDkJLTjhJ1HIuDKCR1tDaCF7kk V5hMFRUWy5jGBbgwWSs8wXTzzJpwJVyugldKmlbTljiBxLW+Gzm6U/WwjC7aLN7uV5S6 hkIw== X-Gm-Message-State: ANhLgQ2uO0jJe0MK+XpISvnpSjiwsQfDyA9XRuWqLHzLWUKs1pR026gH lYmmBfFoPv3yRYTUO62fg4CZbtmWcrE= X-Google-Smtp-Source: ADFU+vtpZOSjgzNkEQr8+pR7DKgFMi5P/OoljaJw2SYbUvPB64vcjvtfXWmy5n4bnwKk3XeXwHp/hQ== X-Received: by 2002:a17:902:b58b:: with SMTP id a11mr2716505pls.9.1584421403442; Mon, 16 Mar 2020 22:03:23 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id k67sm994803pga.91.2020.03.16.22.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 22:03:22 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Subject: [PATCH 3/5] ppc/spapr: Add FWNMI machine check delivery warnings Date: Tue, 17 Mar 2020 15:02:13 +1000 Message-Id: <20200317050215.159334-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200317050215.159334-1-npiggin@gmail.com> References: <20200317050215.159334-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1043 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: Aravinda Prasad , Alexey Kardashevskiy , qemu-devel@nongnu.org, Nicholas Piggin , Greg Kurz , =?utf-8?b?Q8OpZHJp?= =?utf-8?q?c_Le_Goater?= , Ganesh Goudar , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add some messages which explain problems and guest misbehaviour that may be difficult to diagnose in rare cases of machine checks. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_events.c | 4 ++++ hw/ppc/spapr_rtas.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 05337f0671..d35151eeb0 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -807,6 +807,8 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) /* get rtas addr from fdt */ rtas_addr = spapr_get_rtas_addr(); if (!rtas_addr) { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "rtas_addr not found."); qemu_system_guest_panicked(NULL); g_free(ext_elog); return; @@ -848,6 +850,8 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) * that CPU called "ibm,nmi-interlock") */ if (spapr->fwnmi_machine_check_interlock == cpu->vcpu_id) { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "nested machine check."); qemu_system_guest_panicked(NULL); return; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 29abe66d01..12cd09701c 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -462,6 +462,10 @@ static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, } if (spapr->fwnmi_machine_check_addr == -1) { + qemu_log_mask(LOG_GUEST_ERROR, + "FWNMI: ibm,nmi-interlock RTAS called with FWNMI not " + "registered.\n"); + /* NMI register not called */ rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); return; From patchwork Tue Mar 17 05:02:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1256057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=DxldPo+r; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48hLjY5RRLz9sPF for ; Tue, 17 Mar 2020 16:06:09 +1100 (AEDT) Received: from localhost ([::1]:52896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4QZ-0001fS-Mg for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2020 01:06:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50081) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4O6-000792-IV for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE4O4-00038u-Ty for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:34 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:34938) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jE4O1-0002q8-HJ; Tue, 17 Mar 2020 01:03:29 -0400 Received: by mail-pl1-x643.google.com with SMTP id g6so9076270plt.2; Mon, 16 Mar 2020 22:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xSf0EPD7sy/azhxGNjVBtSt1UwU5MPu4W81JLtbmm90=; b=DxldPo+re8cYJKqJ1DvVqY4MRZvoOD1upqfxETcDXt6AsS7Q2ZxVDV7T+Hgkc3MpwI YUAn4WLuoAjzjsRWOyghBSfg3Abfek6ycW6n/RMkt0895CTXi+nb2JIC8VBCiO72OUv7 j3RBP/tQiM819iEVo2Tt3LUZ1QeDSpHe53eI0Xc3YrbXRT2khMc8y8LfBpgFyWzCoOav u5R+Fy7MggH6TH5Veub2njAC9C2alirkoenm5BVot9rKBXCjVBq4sFZVOiViPyCfioNg esDFa0soae8J3X/99jAz2gQMMFVvrvecwzR3E/Dq43gc+5/Ei6p0LMUo5fWJqEsuFm3f mz8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xSf0EPD7sy/azhxGNjVBtSt1UwU5MPu4W81JLtbmm90=; b=CPqX/SgJcKaYPsV4nZNnMDCAZmR6IXrtVYUEh32UvwS814PbiDnL3/AM1x1zgf4V63 FSjtYP9M5+ccosV0SHR7bzd/gsJVnkRtMXMGnuBQfWaiiuuF0Kx1mqqRlbN8sFZwL081 TUa+Yk57SswcB0i3mi+dZK+95mrjir3K+SGGp2mVjGK+Qc1QVJ9WZ4hGxVhi01J0reoT xjn1i7E5TbXq7RozqJNi6bmdRV8pVvJR3Uc7SPAJ3Bp7T9Y/sowYFWzqEjlZNjSLg9vw PSRGc0kv5qsQx5eK595J/ork+Wu/sZgcNIblRoYOU9IjGtxPDFnMfIDlO07rKuhSZwcw tQ1w== X-Gm-Message-State: ANhLgQ2oMslZap0nZGAurg8rKmyDyJF8oIaBjowjKcThFYsNm0S3vb33 AEcJ09rd9honXnB4hsKpzPdzrrqBemM= X-Google-Smtp-Source: ADFU+vvs0pn0mbklieTEWcaniq/oMpeWXn5+o/8zG/goaFtCg4lwfZEnMVCS3a6ZTjNv+87iCqLeXg== X-Received: by 2002:a17:90a:fa11:: with SMTP id cm17mr3378361pjb.78.1584421408344; Mon, 16 Mar 2020 22:03:28 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id k67sm994803pga.91.2020.03.16.22.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 22:03:27 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Subject: [PATCH 4/5] ppc/spapr: Don't kill the guest if a recovered FWNMI machine check delivery fails Date: Tue, 17 Mar 2020 15:02:14 +1000 Message-Id: <20200317050215.159334-5-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200317050215.159334-1-npiggin@gmail.com> References: <20200317050215.159334-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 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: Aravinda Prasad , Alexey Kardashevskiy , qemu-devel@nongnu.org, Nicholas Piggin , Greg Kurz , =?utf-8?b?Q8OpZHJp?= =?utf-8?q?c_Le_Goater?= , Ganesh Goudar , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Try to be tolerant of errors if the machine check had been recovered by the host. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_events.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index d35151eeb0..3f524cb0ca 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -807,13 +807,20 @@ static void spapr_mce_dispatch_elog(PowerPCCPU *cpu, bool recovered) /* get rtas addr from fdt */ rtas_addr = spapr_get_rtas_addr(); if (!rtas_addr) { - warn_report("FWNMI: Unable to deliver machine check to guest: " - "rtas_addr not found."); - qemu_system_guest_panicked(NULL); + if (!recovered) { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "rtas_addr not found."); + qemu_system_guest_panicked(NULL); + } else { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "rtas_addr not found. Machine check recovered."); + } g_free(ext_elog); return; } + spapr->fwnmi_machine_check_interlock = cpu->vcpu_id; + stq_be_phys(&address_space_memory, rtas_addr + RTAS_ERROR_LOG_OFFSET, env->gpr[3]); cpu_physical_memory_write(rtas_addr + RTAS_ERROR_LOG_OFFSET + @@ -850,9 +857,14 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) * that CPU called "ibm,nmi-interlock") */ if (spapr->fwnmi_machine_check_interlock == cpu->vcpu_id) { - warn_report("FWNMI: Unable to deliver machine check to guest: " - "nested machine check."); - qemu_system_guest_panicked(NULL); + if (!recovered) { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "nested machine check."); + qemu_system_guest_panicked(NULL); + } else { + warn_report("FWNMI: Unable to deliver machine check to guest: " + "nested machine check. Machine check recovered."); + } return; } qemu_cond_wait_iothread(&spapr->fwnmi_machine_check_interlock_cond); @@ -880,7 +892,6 @@ void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) warn_report("Received a fwnmi while migration was in progress"); } - spapr->fwnmi_machine_check_interlock = cpu->vcpu_id; spapr_mce_dispatch_elog(cpu, recovered); } From patchwork Tue Mar 17 05:02:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1256058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=OwbyvZHD; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48hLkd3ykhz9sPF for ; Tue, 17 Mar 2020 16:07:05 +1100 (AEDT) Received: from localhost ([::1]:52904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4RT-0002wR-Fn for incoming@patchwork.ozlabs.org; Tue, 17 Mar 2020 01:07:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50194) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE4OB-0007Fo-Ir for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE4OA-0003aa-2Z for qemu-devel@nongnu.org; Tue, 17 Mar 2020 01:03:39 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:56068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jE4O6-0003GO-PT; Tue, 17 Mar 2020 01:03:34 -0400 Received: by mail-pj1-x1042.google.com with SMTP id mj6so9360921pjb.5; Mon, 16 Mar 2020 22:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AisOrh8tGWpQt/xWqL0k/5hGpgBWGNSTT7SWHsAxBR0=; b=OwbyvZHDOCm5Ty0gGYoo3ekY95bu0rdU6Mc1QVyp6HCd/Zhm6Ak6SqTLXFcNrWemGG LoCU7s+/Cx2o3f3u0KGBSeywURzKrtrT8J8I43urGompCp09s1VPGZU2HcYrfSyxmP2d aedtGX90CLle7X2DACgu01PqgeMKETvc6IrS4xoMfcsVtzMyLQ4nvKcRjfw3jt45+B6K KYZWSopEkBZeK6vNcbtMGluB8LE4jWGzIHYaGGOmyzx5PpnFBguMgp89zzcPmYm8Zz8H 1qC7cD3Hxbxgu+0+njIeZ5tYq012gfVH7Xt/db26GGUcnX5JaAWLYVPmxXDgMISKtNPc wL1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AisOrh8tGWpQt/xWqL0k/5hGpgBWGNSTT7SWHsAxBR0=; b=eC6/AuwMbKTgBJN+QmXeAFOaEeVmiOJ95L9QTerzOpfUXnrwhdA3OqSt1pd4YAbMDE Y+S/TVfEbKlMDlnwPzKu1yW8gCjn1UuWTDWIY1ItqzxaQL+sOcSPsUTyBiWWQRvjqur0 1qk/YLGto0RO2/J72EwRuB/sz9Qn5TxOa5OCRNy/qQUjzipO1em/z0BCx7+3AZzhjf2x y3lOIUP0VsAobXamE9h+0vq17r8orvVT/uwlLxMPCSUwxa4ePwIuMvhdJcsGu1FSbFC8 Ph/nAeuu1BLsoS/toWfuxLn/55Vv6yGbypigLYQ8tWRUAlKhag54alrGa5LegH+Jvbtd 5b9w== X-Gm-Message-State: ANhLgQ27Zs4f2z8D16Tozvf/0LOJHpVWlZsGBpxU7MfDWuNOjDtpChCa KTHzR5FUfb3TahQIJKTQKW4y1sm7i3c= X-Google-Smtp-Source: ADFU+vvCoiBLNSdw29T7DuiO+K6qm1rt9YqLxzqWjMyc/NgXmYMYSX+Z0Ko8Md93xcbwtLuL9R2IVQ== X-Received: by 2002:a17:902:ac83:: with SMTP id h3mr2653884plr.86.1584421413045; Mon, 16 Mar 2020 22:03:33 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (14-202-190-183.tpgi.com.au. [14.202.190.183]) by smtp.gmail.com with ESMTPSA id k67sm994803pga.91.2020.03.16.22.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 22:03:32 -0700 (PDT) From: Nicholas Piggin To: qemu-ppc@nongnu.org Subject: [PATCH 5/5] target/ppc: Implement simple monitor mce injection Date: Tue, 17 Mar 2020 15:02:15 +1000 Message-Id: <20200317050215.159334-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200317050215.159334-1-npiggin@gmail.com> References: <20200317050215.159334-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 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: Aravinda Prasad , Alexey Kardashevskiy , qemu-devel@nongnu.org, Nicholas Piggin , Greg Kurz , =?utf-8?b?Q8OpZHJp?= =?utf-8?q?c_Le_Goater?= , Ganesh Goudar , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This enables the mce monitor command for ppc, and adds a spapr facility to inject machine check exception to a CPU by setting low level registers. (qemu) mce 0 0x200000 0x80 0xdeadbeef 1 Disabling lock debugging due to kernel taint MCE: CPU0: machine check (Severe) Host SLB Multihit [Recovered] MCE: CPU0: PID: 495 Comm: a NIP: [0000000130ee07c8] MCE: CPU0: Initiator CPU MCE: CPU0: Unknown Signed-off-by: Nicholas Piggin --- hmp-commands.hx | 20 +++++++++++++++++++- hw/ppc/spapr.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 3 +++ target/ppc/cpu.h | 3 +++ target/ppc/monitor.c | 26 ++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 7f0f3974ad..4a9089b431 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1581,12 +1581,30 @@ ERST .cmd = hmp_mce, }, -#endif SRST ``mce`` *cpu* *bank* *status* *mcgstatus* *addr* *misc* Inject an MCE on the given CPU (x86 only). ERST +#endif + +#if defined(TARGET_PPC) + + { + .name = "mce", + .args_type = "cpu_index:i,srr1_mask:l,dsisr:i,dar:l,recovered:i", + .params = "cpu srr1_mask dsisr dar recovered", + .help = "inject a MCE on the given CPU", + .cmd = hmp_mce, + }, + +SRST +``mce`` *cpu* *srr1_mask* *dsisr* *dar* *recovered* + Inject an MCE on the given CPU (PPC only). +ERST + +#endif + { .name = "getfd", .args_type = "fdname:s", diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 78e649f47d..d83245c438 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3454,6 +3454,47 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp) } } +typedef struct MCEInjectionParams { + uint64_t srr1_mask; + uint32_t dsisr; + uint64_t dar; + bool recovered; +} MCEInjectionParams; + +static void spapr_do_mce_on_cpu(CPUState *cs, run_on_cpu_data data) +{ + MCEInjectionParams *params = data.host_ptr; + PowerPCCPU *cpu = POWERPC_CPU(cs); + CPUPPCState *env = &cpu->env; + uint64_t srr1_mce_bits = PPC_BITMASK(42,45) | PPC_BIT(36); /* POWER9 bits */ + + cpu_synchronize_state(cs); + + env->spr[SPR_SRR0] = env->nip; + env->spr[SPR_SRR1] = (env->msr & ~srr1_mce_bits) | + (params->srr1_mask & srr1_mce_bits); + if (params->dsisr) { + env->spr[SPR_DSISR] = params->dsisr; + env->spr[SPR_DAR] = params->dar; + } + + spapr_mce_req_event(cpu, params->recovered); +} + +static void spapr_cpu_mce_inject(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, + uint64_t srr1_mask, uint32_t dsisr, + uint64_t dar, bool recovered) +{ + CPUState *cs = CPU(cpu); + MCEInjectionParams params = { + .srr1_mask = srr1_mask, + .dsisr = dsisr, + .dar = dar, + .recovered = recovered, + }; + run_on_cpu(cs, spapr_do_mce_on_cpu, RUN_ON_CPU_HOST_PTR(¶ms)); +} + int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, void *fdt, int *fdt_start_offset, Error **errp) { @@ -4556,6 +4597,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) vhc->encode_hpt_for_kvm_pr = spapr_encode_hpt_for_kvm_pr; vhc->cpu_exec_enter = spapr_cpu_exec_enter; vhc->cpu_exec_exit = spapr_cpu_exec_exit; + vhc->cpu_mce_inject = spapr_cpu_mce_inject; xic->ics_get = spapr_ics_get; xic->ics_resend = spapr_ics_resend; xic->icp_get = spapr_icp_get; diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 42d64a0368..72f86a2ee8 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -929,4 +929,7 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize, void spapr_set_all_lpcrs(target_ulong value, target_ulong mask); hwaddr spapr_get_rtas_addr(void); + +void spapr_mce_inject(CPUState *cs, uint64_t srr1_mask, uint32_t dsisr, + uint64_t dar, bool recovered); #endif /* HW_SPAPR_H */ diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index f8c7d6f19c..ed8d2015bd 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1189,6 +1189,9 @@ struct PPCVirtualHypervisorClass { #ifndef CONFIG_USER_ONLY void (*cpu_exec_enter)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu); void (*cpu_exec_exit)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu); + void (*cpu_mce_inject)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, + uint64_t srr1_mask, uint32_t dsisr, uint64_t dar, + bool recovered); #endif }; diff --git a/target/ppc/monitor.c b/target/ppc/monitor.c index a5a177d717..ec997ce673 100644 --- a/target/ppc/monitor.c +++ b/target/ppc/monitor.c @@ -28,6 +28,7 @@ #include "qemu/ctype.h" #include "monitor/hmp-target.h" #include "monitor/hmp.h" +#include "qapi/qmp/qdict.h" static target_long monitor_get_ccr(const struct MonitorDef *md, int val) { @@ -72,6 +73,31 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) dump_mmu(env1); } +void hmp_mce(Monitor *mon, const QDict *qdict) +{ + CPUState *cs; + int cpu_index = qdict_get_int(qdict, "cpu_index"); + uint64_t srr1_mask = qdict_get_int(qdict, "srr1_mask"); + uint32_t dsisr = qdict_get_int(qdict, "dsisr"); + uint64_t dar = qdict_get_int(qdict, "dar"); + bool recovered = qdict_get_int(qdict, "recovered"); + + cs = qemu_get_cpu(cpu_index); + + if (cs != NULL) { + PowerPCCPU *cpu = POWERPC_CPU(cs); + + if (cpu->vhyp) { + PPCVirtualHypervisorClass *vhc = + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + if (vhc->cpu_mce_inject) { + vhc->cpu_mce_inject(cpu->vhyp, cpu, + srr1_mask, dsisr, dar, recovered); + } + } + } +} + const MonitorDef monitor_defs[] = { { "fpscr", offsetof(CPUPPCState, fpscr) }, /* Next instruction pointer */