From nobody Thu Oct 2 03:24:58 2025 Delivered-To: importer@patchew.org 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1584441402; cv=none; d=zohomail.com; s=zohoarc; b=IwwrwEToC8U9K/yLRwHhuInYeECQjw9CGwGadNd8cTTFaJRQu7F00R/OGerc8IQtlmFdEWWOtGbnNDgUD68Z35g1sJWMRs9c9GJUbUxKAo8XhP8Sm7aEp3wbvcsjUZ+oXnL0s9LzP7aXXHeCOdbIp0RVOyLFzzIYg/Wb0DzLHEU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584441402; 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=wFp8VXiOTEkSeeyIz1qNQljvgr/Y2ZBYsgkua3b157c=; b=OEAYCWbzp8yhzMlheo8CBux0ZShmIzJxGGgnDpsoUfncU8RxPhp63JBFUkqjQSwqRGRVkeT0WZftFbsYfPsjxHIWwzRaUNYzanj1+ogSQZG0U1eF4wLE50uFHVyKra4/kTfOKD6MDEvkbZJ75y1ydfsERTRCpC+sWVkJEi8e49g= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584441402616863.3510743317898; Tue, 17 Mar 2020 03:36:42 -0700 (PDT) Received: from localhost ([::1]:56234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE9aT-0005X7-HX for importer@patchew.org; Tue, 17 Mar 2020 06:36:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46628) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jE96W-0002Ph-MB for qemu-devel@nongnu.org; Tue, 17 Mar 2020 06:05:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jE96U-0008Td-Kv for qemu-devel@nongnu.org; Tue, 17 Mar 2020 06:05:44 -0400 Received: from ozlabs.org ([203.11.71.1]:41279) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jE96U-0008DY-79; Tue, 17 Mar 2020 06:05:42 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 48hTL34bSpz9sTd; Tue, 17 Mar 2020 21:04:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1584439483; bh=K5aTTPyNTiXqeOFBunos2P9/ndyBJIQYmUSNYf41ZFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iIMZrzVdNvmPhM6YjcW+ERmTHq82D/SPCh7tlGw1FUDJn+UeeRj63ht8HByWXD021 T3e3EabJdXqFv68QOvZe8RgaOD+hzEN94x+9aqpQvqIXSgumFvshLV4PWwL61HXqEj DxpFRY0POwSZUwLYpEk+qqQ0eTj1Fks1fFpOfYWo= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 43/45] ppc/spapr: Implement FWNMI System Reset delivery Date: Tue, 17 Mar 2020 21:04:21 +1100 Message-Id: <20200317100423.622643-44-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200317100423.622643-1-david@gibson.dropbear.id.au> References: <20200317100423.622643-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 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: lvivier@redhat.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, Nicholas Piggin , qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson 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: Nicholas Piggin PAPR requires that if "ibm,nmi-register" succeeds, then the hypervisor delivers all system reset and machine check exceptions to the registered addresses. System Resets are delivered with registers set to the architected state, and with no interlock. Signed-off-by: Nicholas Piggin Message-Id: <20200316142613.121089-8-npiggin@gmail.com> Signed-off-by: David Gibson --- hw/ppc/spapr.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 6d65c0797b..8fcd21ac7b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -951,7 +951,29 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, vo= id *fdt) _FDT(fdt_setprop(fdt, rtas, "ibm,max-associativity-domains", maxdomains, sizeof(maxdomains))); =20 - _FDT(fdt_setprop_cell(fdt, rtas, "rtas-size", RTAS_SIZE)); + /* + * FWNMI reserves RTAS_ERROR_LOG_MAX for the machine check error log, + * and 16 bytes per CPU for system reset error log plus an extra 8 byt= es. + * + * The system reset requirements are driven by existing Linux and Powe= rVM + * implementation which (contrary to PAPR) saves r3 in the error log + * structure like machine check, so Linux expects to find the saved r3 + * value at the address in r3 upon FWNMI-enabled sreset interrupt (and + * does not look at the error value). + * + * System reset interrupts are not subject to interlock like machine + * check, so this memory area could be corrupted if the sreset is + * interrupted by a machine check (or vice versa) if it was shared. To + * prevent this, system reset uses per-CPU areas for the sreset save + * area. A system reset that interrupts a system reset handler could + * still overwrite this area, but Linux doesn't try to recover in that + * case anyway. + * + * The extra 8 bytes is required because Linux's FWNMI error log check + * is off-by-one. + */ + _FDT(fdt_setprop_cell(fdt, rtas, "rtas-size", RTAS_ERROR_LOG_MAX + + ms->smp.max_cpus * sizeof(uint64_t)*2 + sizeof(uint64_t))); _FDT(fdt_setprop_cell(fdt, rtas, "rtas-error-log-max", RTAS_ERROR_LOG_MAX)); _FDT(fdt_setprop_cell(fdt, rtas, "rtas-event-scan-rate", @@ -3384,8 +3406,28 @@ static void spapr_machine_finalizefn(Object *obj) =20 void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg) { + SpaprMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); + cpu_synchronize_state(cs); - ppc_cpu_do_system_reset(cs, -1); + /* If FWNMI is inactive, addr will be -1, which will deliver to 0x100 = */ + if (spapr->fwnmi_system_reset_addr !=3D -1) { + uint64_t rtas_addr, addr; + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + CPUPPCState *env =3D &cpu->env; + + /* get rtas addr from fdt */ + rtas_addr =3D spapr_get_rtas_addr(); + if (!rtas_addr) { + qemu_system_guest_panicked(NULL); + return; + } + + addr =3D rtas_addr + RTAS_ERROR_LOG_MAX + cs->cpu_index * sizeof(u= int64_t)*2; + stq_be_phys(&address_space_memory, addr, env->gpr[3]); + stq_be_phys(&address_space_memory, addr + sizeof(uint64_t), 0); + env->gpr[3] =3D addr; + } + ppc_cpu_do_system_reset(cs, spapr->fwnmi_system_reset_addr); } =20 static void spapr_nmi(NMIState *n, int cpu_index, Error **errp) --=20 2.24.1