From patchwork Mon Dec 5 03:56:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9460263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4865F60236 for ; Mon, 5 Dec 2016 03:57:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F1821EEB for ; Mon, 5 Dec 2016 03:57:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35AB32621D; Mon, 5 Dec 2016 03:57:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF95F21EEB for ; Mon, 5 Dec 2016 03:57:28 +0000 (UTC) Received: from localhost ([::1]:36769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDkP9-00038i-Hy for patchwork-qemu-devel@patchwork.kernel.org; Sun, 04 Dec 2016 22:57:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDkOo-00038J-7p for qemu-devel@nongnu.org; Sun, 04 Dec 2016 22:57:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cDkOj-00051G-II for qemu-devel@nongnu.org; Sun, 04 Dec 2016 22:57:06 -0500 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:35475) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cDkOj-00050j-AZ; Sun, 04 Dec 2016 22:57:01 -0500 Received: by mail-pf0-x242.google.com with SMTP id i88so6915773pfk.2; Sun, 04 Dec 2016 19:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=GmBGnDS4YHbIX06WFGJZkjvkSS06d96WR/IBNffH/pE=; b=0anXEVN0tZ0oaDgsgCplF+zyp6A+eolt81TaCz4geE3iekcjn9f3Kk30pHkyQolYLE LBHo7cQY6MXdPLdcY6TEdGnPyHe7hMibHs6g0301dBeWh3ZpiwFaFe2L74r9BSXBwpNy tMUfRosxYA48xEzXY6Rxgn1aVesxJaMCmIbvHaPVDxSTmcpM2VcqcOBw1nxwJsQbceAt hMiCsZlreEhigMN2hsmlvsgfimuMNyowMQSgNCIkm/JSzJj4CEknEP2GWEvDKA3V559b WQCQq+1+YHFj6tuhqwB44ZsRR41+1y8ZEu6+oSbzLUeT9NdNuAEkQuEhGKFPieqrGzzn fgRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GmBGnDS4YHbIX06WFGJZkjvkSS06d96WR/IBNffH/pE=; b=A6tVgNtWUsnboj0jMRl1nBVWP2nCkD3A8AoV/oJd0I2C9xQYhLlSxJcWXqHgYTcVTP aMgII6IwLYE2SzZVNFmFZ0Z0xbGttBlYJGEEVUCXgNSHNIgfClYMSCEtGjYF3DXTBPPg 6nvgleZ5A8klZ1BwaFiAAOULavrWbAsP8I6H9ZRMq6Vuj1++rlTro4XPrcDWqJ2bHHpI dJOUXZPH/05MlSfm+S/PtKnJDCgyDHlwYzWUlSMKnHZPQdHpawPTrzeKID4vw+PKoUhX oNDnLFi4zMGpIy4lKpek7wFJIs2Qy8G9DBNeSmEd9LxPyD/WujZGZKE3xWKWUbYXgDEo K4zg== X-Gm-Message-State: AKaTC031/sQcuq8Bdpt9rDOw6fweKA7lwApmfkviZgi6iCsi2SMkbg33EUvXbjaCUzjgVA== X-Received: by 10.84.146.140 with SMTP id g12mr118900486pla.62.1480910219971; Sun, 04 Dec 2016 19:56:59 -0800 (PST) Received: from roar.au.ibm.com (27-33-21-189.tpgi.com.au. [27.33.21.189]) by smtp.gmail.com with ESMTPSA id o126sm23081522pga.34.2016.12.04.19.56.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Dec 2016 19:56:59 -0800 (PST) From: Nicholas Piggin To: David Gibson , qemu-devel@nongnu.org, qemu-ppc@nongnu.org Date: Mon, 5 Dec 2016 14:56:47 +1100 Message-Id: <20161205035647.17406-1-npiggin@gmail.com> X-Mailer: git-send-email 2.10.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH] ppc/spapr: implement H_SIGNAL_SYS_RESET X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Greg Kurz , Nicholas Piggin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The H_SIGNAL_SYS_RESET hcall allows a guest CPU to raise a system reset exception on CPUs within the same guest -- all CPUs, all-but-self, or a specific CPU (including self). This has not made its way to a PAPR release yet, but we have an hcall number assigned. H_SIGNAL_SYS_RESET = 0x380 Syntax: hcall(uint64 H_SIGNAL_SYS_RESET, int64 target); Generate a system reset NMI on the threads indicated by target. Values for target: -1 = target all online threads including the caller -2 = target all online threads except for the caller All other negative values: reserved Positive values: The thread to be targeted, obtained from the value of the "ibm,ppc-interrupt-server#s" property of the CPU in the OF device tree. Semantics: - Invalid target: return H_Parameter. - Otherwise: Generate a system reset NMI on target thread(s), return H_Success. Signed-off-by: Nicholas Piggin --- Hi, I have taken into account feedback since last posting, the comments were appreciated. http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg04881.html - Improved changelog description. - Shared code with QEMU NMI injection. - Move hcall-specific parameter definitions out of header. - Added an "unofficial" PAPR specification to changelog. There is interest to improve the community process with PAPR development, but I can't say if/when/how, so this is the best I can do. * Some additional background information follows * The Linux powerpc branch has a corresponding change to add this hcall definition: https://git.kernel.org/cgit/linux/kernel/git/powerpc/linux.git/commit/?h=next&id=53ce299615e587e900548eb6b384c3081b71bbfa The motivation is to allow a crash or debug event to pull stuck (interrupts disabled) CPUs into the crash/debug handlers. This is in response to a problem encountered in the wild on a customer machine. Linux guest patches to that end were posted for review: https://lists.ozlabs.org/pipermail/linuxppc-dev/2016-November/150684.html Additionally, there is ongoing firmware effort to provide a similar service for non-virtualized environments: https://lists.ozlabs.org/pipermail/skiboot/2016-November/005481.html Thanks, Nick hw/ppc/spapr.c | 4 ++-- hw/ppc/spapr_hcall.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 5 ++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 208ef7b..5d2adf8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2252,7 +2252,7 @@ static void spapr_machine_finalizefn(Object *obj) g_free(spapr->kvm_type); } -static void ppc_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg) +void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg) { cpu_synchronize_state(cs); ppc_cpu_do_system_reset(cs); @@ -2263,7 +2263,7 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp) CPUState *cs; CPU_FOREACH(cs) { - async_run_on_cpu(cs, ppc_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL); + async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); } } diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 9a9bedf..b61ac9d 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -881,6 +881,46 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPRMachineState *spapr, return ret; } +#define H_SIGNAL_SYS_RESET_ALL -1 +#define H_SIGNAL_SYS_RESET_ALLBUTSELF -2 + +static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, + sPAPRMachineState *spapr, + target_ulong opcode, target_ulong *args) +{ + target_long target = args[0]; + CPUState *cs; + + if (target < 0) { + /* Broadcast */ + if (target < H_SIGNAL_SYS_RESET_ALLBUTSELF) { + return H_PARAMETER; + } + + CPU_FOREACH(cs) { + PowerPCCPU *c = POWERPC_CPU(cs); + + if (target == H_SIGNAL_SYS_RESET_ALLBUTSELF) { + if (c == cpu) { + continue; + } + } + run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); + } + return H_SUCCESS; + + } else { + /* Unicast */ + CPU_FOREACH(cs) { + if (cpu->cpu_dt_id == target) { + run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); + return H_SUCCESS; + } + } + return H_PARAMETER; + } +} + typedef struct { uint32_t cpu_version; Error *err; @@ -1101,6 +1141,7 @@ static void hypercall_register_types(void) /* hcall-splpar */ spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa); spapr_register_hypercall(H_CEDE, h_cede); + spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); /* processor register resource access h-calls */ spapr_register_hypercall(H_SET_SPRG0, h_set_sprg0); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index bd5bcf7..443c425 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -347,7 +347,8 @@ struct sPAPRMachineState { #define H_XIRR_X 0x2FC #define H_RANDOM 0x300 #define H_SET_MODE 0x31C -#define MAX_HCALL_OPCODE H_SET_MODE +#define H_SIGNAL_SYS_RESET 0x380 +#define MAX_HCALL_OPCODE H_SIGNAL_SYS_RESET /* The hcalls above are standardized in PAPR and implemented by pHyp * as well. @@ -662,4 +663,6 @@ int spapr_rng_populate_dt(void *fdt); #define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020 #define SPAPR_LMB_FLAGS_RESERVED 0x00000080 +void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg); + #endif /* HW_SPAPR_H */