From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893906; cv=none; d=zohomail.com; s=zohoarc; b=aNGjUb2YcL/fGmWx1eH+nPSkgWqjXHD4dSfSNWbAzrNc3XobMc+nhNpOH0d6IXYPg/+CVRNa3gTroQ4FjjtdmqtUWRIZXtun+98PID0dMpUAE6IKh+VDrvDfM5lmWiLnRkJ37fYop14wUhYnlDkVrT51PJ8dwSjVi3BIbJ/SbmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893906; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KdSC/2SwrQzJeucHQAe5URjKPn9snhPM4o+bwfM/pec=; b=jXiJw7T3wm14UpRRzXMtIKJKzcFxHopn0KknDma1yU/YcSJ/T3x4viDbDLosYPZ2pjBOE9LLWWwL7PTN2AH2mTsBihRIv/MoEAAdHTLvgcSCgYZU9pygWXMTdqf7kxDyCSe0Ppd1j3gpHzags9NbP1+9K3a4HDtHr5my6szsx88= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741893906874571.0860422671074; Thu, 13 Mar 2025 12:25:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoA0-0002oQ-5S; Thu, 13 Mar 2025 15:24:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tso9y-0002n5-J8; Thu, 13 Mar 2025 15:24:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tso9w-0000sw-Fu; Thu, 13 Mar 2025 15:24:02 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo44T030318; Thu, 13 Mar 2025 19:23:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:23:57 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJMtme019938; Thu, 13 Mar 2025 19:23:57 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hme-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:23:57 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DJ1GKM003181; Thu, 13 Mar 2025 19:23:56 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atstufts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:23:56 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJNqQH59310580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:23:52 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BBA720043; Thu, 13 Mar 2025 19:23:52 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F29B20040; Thu, 13 Mar 2025 19:23:50 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:23:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=KdSC/2 SwrQzJeucHQAe5URjKPn9snhPM4o+bwfM/pec=; b=pmuhwmrkndYKba4wVd9xzc s2irSMVmsPZisKib0sTZfUetkb90pyzKbAxAjOi63+X4OYVBti4ZYR2oOVRRZguJ vyhtaB7Pmjj2GngMOFXxnb9XMS+6uWAuCHNXPoQ6IdYK0CkH2HacR0pEXG8OReNb Jw+Ia3nUD3vzFQdHy8fzexQN+BDB4QDY7Zhx9gTbaC1uDTINjKSTP/3xHN1dGtca 5kT5IkP8Y///evex/XEThyVPrB0k6AApQjozjSPUdnd1W/800KF7pwZVWDUVb1u8 RbrwxW4i4X79Sx6WNWDUV/ZzdEwHRXfLKlfDMDJF2IbhpqVLCiWmSkm4sPKVZUkg == From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 1/8] hw/ppc: Implement skeleton code for fadump in PSeries Date: Fri, 14 Mar 2025 00:53:34 +0530 Message-ID: <20250313192341.132171-2-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PqVmuWxwBjehb-N-sc1iHMFMIB2kbk2a X-Proofpoint-ORIG-GUID: _TO3BCXRd_V_bmW8YmCqX5d-DOHqwA0z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893908412019000 Add skeleton for handle "ibm,configure-kernel-dump" rtas call in QEMU. Verify basic details mandated by the PAPR, such as number of inputs/output, and add handling for the three fadump commands: regiser/unregister/invalidate. Currently fadump register will always return HARDWARE ERROR, since it's not implemented yet. So if the kernel's attempt to register fadump will itself fail as the support is not there yet in QEMU. The checks are based on the table in following requirement in PAPR v2.13: "R1=E2=80=937.3.30=E2=80=931. For the Configure Platform Assisted Kerne= l Dump option ..." Signed-off-by: Aditya Gupta --- hw/ppc/meson.build | 1 + hw/ppc/spapr_fadump.c | 22 +++++++++++ hw/ppc/spapr_rtas.c | 66 +++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 11 +++++- include/hw/ppc/spapr_fadump.h | 69 +++++++++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 hw/ppc/spapr_fadump.c create mode 100644 include/hw/ppc/spapr_fadump.h diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build index 9893f8adebb0..863972741b15 100644 --- a/hw/ppc/meson.build +++ b/hw/ppc/meson.build @@ -26,6 +26,7 @@ ppc_ss.add(when: 'CONFIG_PSERIES', if_true: files( 'spapr_nvdimm.c', 'spapr_rtas_ddw.c', 'spapr_numa.c', + 'spapr_fadump.c', 'pef.c', )) ppc_ss.add(when: ['CONFIG_PSERIES', 'CONFIG_TCG'], if_true: files( diff --git a/hw/ppc/spapr_fadump.c b/hw/ppc/spapr_fadump.c new file mode 100644 index 000000000000..20b7b804c485 --- /dev/null +++ b/hw/ppc/spapr_fadump.c @@ -0,0 +1,22 @@ +/* + * Firmware Assisted Dump in PSeries + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/ppc/spapr.h" + +/* + * Handle the "FADUMP_CMD_REGISTER" command in 'ibm,configure-kernel-dump' + * + * Returns: + * * RTAS_OUT_HW_ERROR: Not implemented/Misc issue such as memory access + * failures + */ +uint32_t do_fadump_register(void) +{ + /* WIP: FADUMP_CMD_REGISTER implemented in future patch */ + + return RTAS_OUT_HW_ERROR; +} diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 503d441b48e4..b8bfa9c33fb5 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -341,6 +341,68 @@ static void rtas_ibm_set_system_parameter(PowerPCCPU *= cpu, rtas_st(rets, 0, ret); } =20 +/* Papr Section 7.4.9 ibm,configure-kernel-dump RTAS call */ +static void rtas_configure_kernel_dump(PowerPCCPU *cpu, + SpaprMachineState *spapr, + uint32_t token, uint32_t nargs, + target_ulong args, + uint32_t nret, target_ulong rets) +{ + target_ulong cmd =3D rtas_ld(args, 0); + uint32_t ret_val; + + /* Number of outputs has to be 1 */ + if (nret !=3D 1) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: ibm,configure-kernel-dump RTAS called with nret != =3D 1.\n"); + return; + } + + /* Number of inputs has to be 3 */ + if (nargs !=3D 3) { + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } + + switch (cmd) { + case FADUMP_CMD_REGISTER: + ret_val =3D do_fadump_register(); + if (ret_val !=3D RTAS_OUT_SUCCESS) { + rtas_st(rets, 0, ret_val); + return; + } + break; + case FADUMP_CMD_UNREGISTER: + if (spapr->fadump_dump_active =3D=3D 1) { + rtas_st(rets, 0, RTAS_OUT_DUMP_ACTIVE); + return; + } + + spapr->fadump_registered =3D false; + spapr->fadump_dump_active =3D false; + memset(&spapr->registered_fdm, 0, sizeof(spapr->registered_fdm)); + break; + case FADUMP_CMD_INVALIDATE: + if (spapr->fadump_dump_active) { + spapr->fadump_registered =3D false; + spapr->fadump_dump_active =3D false; + memset(&spapr->registered_fdm, 0, sizeof(spapr->registered_fdm= )); + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Nothing to invalidate, no dump active\n"); + } + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Unknown command: %lu\n", cmd); + + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } + + rtas_st(rets, 0, RTAS_OUT_SUCCESS); +} + static void rtas_ibm_os_term(PowerPCCPU *cpu, SpaprMachineState *spapr, uint32_t token, uint32_t nargs, @@ -656,6 +718,10 @@ static void core_rtas_register_types(void) spapr_rtas_register(RTAS_IBM_NMI_INTERLOCK, "ibm,nmi-interlock", rtas_ibm_nmi_interlock); =20 + /* Register fadump rtas call */ + spapr_rtas_register(RTAS_CONFIGURE_KERNEL_DUMP, "ibm,configure-kernel-= dump", + rtas_configure_kernel_dump); + qtest_set_command_cb(spapr_qtest_callback); } =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 39bd5bd5ed31..4c1636497e30 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -13,6 +13,7 @@ #include "hw/ppc/xics.h" /* For ICSState */ #include "hw/ppc/spapr_tpm_proxy.h" #include "hw/ppc/spapr_nested.h" /* For SpaprMachineStateNested */ +#include "hw/ppc/spapr_fadump.h" /* For FadumpMemStruct */ =20 struct SpaprVioBus; struct SpaprPhbState; @@ -283,6 +284,11 @@ struct SpaprMachineState { Error *fwnmi_migration_blocker; =20 SpaprWatchdog wds[WDT_MAX_WATCHDOGS]; + + /* Fadump State */ + bool fadump_registered; + bool fadump_dump_active; + FadumpMemStruct registered_fdm; }; =20 #define H_SUCCESS 0 @@ -708,6 +714,8 @@ void push_sregs_to_kvm_pr(SpaprMachineState *spapr); #define RTAS_OUT_PARAM_ERROR -3 #define RTAS_OUT_NOT_SUPPORTED -3 #define RTAS_OUT_NO_SUCH_INDICATOR -3 +#define RTAS_OUT_DUMP_ALREADY_REGISTERED -9 +#define RTAS_OUT_DUMP_ACTIVE -10 #define RTAS_OUT_NOT_AUTHORIZED -9002 #define RTAS_OUT_SYSPARM_PARAM_ERROR -9999 =20 @@ -770,8 +778,9 @@ void push_sregs_to_kvm_pr(SpaprMachineState *spapr); #define RTAS_IBM_SUSPEND_ME (RTAS_TOKEN_BASE + 0x2A) #define RTAS_IBM_NMI_REGISTER (RTAS_TOKEN_BASE + 0x2B) #define RTAS_IBM_NMI_INTERLOCK (RTAS_TOKEN_BASE + 0x2C) +#define RTAS_CONFIGURE_KERNEL_DUMP (RTAS_TOKEN_BASE + 0x2D) =20 -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2D) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2E) =20 /* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20 diff --git a/include/hw/ppc/spapr_fadump.h b/include/hw/ppc/spapr_fadump.h new file mode 100644 index 000000000000..45109fd9e137 --- /dev/null +++ b/include/hw/ppc/spapr_fadump.h @@ -0,0 +1,69 @@ +/* + * Firmware Assisted Dump in PSeries + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef PPC_SPAPR_FADUMP_H +#define PPC_SPAPR_FADUMP_H + +#include "qemu/osdep.h" +#include "cpu.h" + +/* Fadump commands */ +#define FADUMP_CMD_REGISTER 1 +#define FADUMP_CMD_UNREGISTER 2 +#define FADUMP_CMD_INVALIDATE 3 + +#define FADUMP_VERSION 1 + +/* + * The Firmware Assisted Dump Memory structure supports a maximum of 10 se= ctions + * in the dump memory structure. Presently, three sections are used for + * CPU state data, HPTE & Parameters area, while the remaining seven secti= ons + * can be used for boot memory regions. + */ +#define FADUMP_MAX_SECTIONS 10 +#define RTAS_FADUMP_MAX_BOOT_MEM_REGS 7 + +typedef struct FadumpSection FadumpSection; +typedef struct FadumpSectionHeader FadumpSectionHeader; +typedef struct FadumpMemStruct FadumpMemStruct; + +struct SpaprMachineState; + +/* Kernel Dump section info */ +struct FadumpSection { + __be32 request_flag; + __be16 source_data_type; + __be16 error_flags; + __be64 source_address; + __be64 source_len; + __be64 bytes_dumped; + __be64 destination_address; +}; + +/* ibm,configure-kernel-dump header. */ +struct FadumpSectionHeader { + __be32 dump_format_version; + __be16 dump_num_sections; + __be16 dump_status_flag; + __be32 offset_first_dump_section; + + /* Fields for disk dump option. */ + __be32 dd_block_size; + __be64 dd_block_offset; + __be64 dd_num_blocks; + __be32 dd_offset_disk_path; + + /* Maximum time allowed to prevent an automatic dump-reboot. */ + __be32 max_time_auto; +}; + +/* Note: All the data in these structures is in big-endian */ +struct FadumpMemStruct { + FadumpSectionHeader header; + FadumpSection rgn[FADUMP_MAX_SECTIONS]; +}; + +uint32_t do_fadump_register(void); +#endif /* PPC_SPAPR_FADUMP_H */ --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893921; cv=none; d=zohomail.com; s=zohoarc; b=R2mnHqrqsGDL0F/eE35qUHqrZe576NyrJO/MQbPUD+ZNo0L0BNSAeis6SnJdhLsrNsvi4Db44rRmwtRZdj03l0aK8lH4P5+Ve0xJETv41E5iK3mOvpWGPgE+VY/geMFlwT8q3rXTTp1gT7WgmV5UPQ2xOtbJwPB4KrReyr+34zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893921; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ImNWkpaXEqwbMy5GCrrvtrhO9XfnFlcOfSdaOM9TASc=; b=kntP0EbtmB2Z/BqvzWE4RjjjtjJui2ocp7jsOwBJuqLYbM69/NGk3MKGwXVrWZ30qETswh9RTiPEOPm7FYws14+AnDaWQCJqGzkcIgWnjZJOvBiZQnv8bUDx++VHDqCDPp+iu11USMHxCRkbw6X7uMN5jC/pO7/cpCL0lt1UmzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741893921531777.4119063950566; Thu, 13 Mar 2025 12:25:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoA3-0002rG-BO; Thu, 13 Mar 2025 15:24:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA0-0002oV-4a; Thu, 13 Mar 2025 15:24:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tso9y-0000tB-47; Thu, 13 Mar 2025 15:24:03 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo6Ja030511; Thu, 13 Mar 2025 19:24:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:00 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJLlQ0018299; Thu, 13 Mar 2025 19:23:59 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hmn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:23:59 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DJGFX4003131; Thu, 13 Mar 2025 19:23:58 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atstufty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:23:58 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJNt0O55443762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:23:55 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4609020040; Thu, 13 Mar 2025 19:23:55 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E9B1E20043; Thu, 13 Mar 2025 19:23:52 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:23:52 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ImNWkpaXEqwbMy5GC rrvtrhO9XfnFlcOfSdaOM9TASc=; b=kKs4xzV4py7ag27RZdsf2spyleIQWtuz+ tJmdRrnJfhmsfDk+mtyK/jrYRuVG1ymD+helLOp4yiDkiz5xN69zPeNnOK222E5D M5StLL2lw5bY8eZV8bvlWJl0y/NavPG8vmWvtjOqaci9CH+9yRcYu0uavvGdtB81 NVw4n9ZlyO4zgZJi1rl6penNFiWLW+2DR6qECgZMhSSlWWQp5fI1DYIDRDMd25l7 dyxzhDO4DpW5R6uj6XBrJ40OzYhA4I+eTaiGhINPsZbWRsu/9d8sG66a0vEYYoFJ s/5C7DdfkQRJvKK52cmKM5YigvY/pVIp2jgqwOqLb3F0sNZl+MGHA== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 2/8] hw/ppc: Implement fadump register command Date: Fri, 14 Mar 2025 00:53:35 +0530 Message-ID: <20250313192341.132171-3-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: L043ooWYTV3w8cMu08fdEk_xOxRu5Zb7 X-Proofpoint-ORIG-GUID: xPr2PFyp4ne4exwT_ZTURs1ieU8hjQOC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893924023019100 Content-Type: text/plain; charset="utf-8" Implement the register command of "ibm,configure-kernel-dump" RTAS call. The register just verifies the structure of the fadump memory structure passed by kernel, and set fadump_registered in spapr state to true. We also store the passed fadump memory structure, which will later be used for preserving memory for fadump boot in case of a crash. The fadump memory structure isn't modified (other than .dump_status_flag after the fadump is triggered, that is in a later patch). So if the structure needs to updated, the kernel should first de-register and re-register the structure again. Relevant section for the register command in PAPR is: Section 7.3.30: "ibm,configure-kernel-dump RTAS call" (PAPR v2.13) Note: The fadump registration is done, but triggering fadump on an os-term rtas call is done in later patches. Hence QEMU will just shutdown on a kernel crash due to no special handling for fadump in ibm,os-term Signed-off-by: Aditya Gupta --- hw/ppc/spapr_fadump.c | 111 ++++++++++++++++++++++++++++++++-- hw/ppc/spapr_rtas.c | 2 +- include/hw/ppc/spapr_fadump.h | 2 +- 3 files changed, 108 insertions(+), 7 deletions(-) diff --git a/hw/ppc/spapr_fadump.c b/hw/ppc/spapr_fadump.c index 20b7b804c485..9c7fb9e12b16 100644 --- a/hw/ppc/spapr_fadump.c +++ b/hw/ppc/spapr_fadump.c @@ -5,18 +5,119 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/log.h" #include "hw/ppc/spapr.h" =20 /* * Handle the "FADUMP_CMD_REGISTER" command in 'ibm,configure-kernel-dump' * + * Note: Any changes made by the kernel to the fadump memory struct won't + * reflect in QEMU after the 'ibm,configure-kernel-dump' RTAS call has ret= urned, + * as we store the passed fadump memory structure passed during fadump + * registration. + * Kernel has to invalidate & re-register fadump, if it intends to make any + * changes to the fadump memory structure + * * Returns: - * * RTAS_OUT_HW_ERROR: Not implemented/Misc issue such as memory access - * failures + * * RTAS_OUT_SUCCESS: On successful registration + * * RTAS_OUT_PARAM_ERROR: If parameters are not correct, eg. too many + * sections, invalid memory addresses that we are + * unable to read, etc + * * RTAS_OUT_DUMP_ALREADY_REGISTERED: Dump already registered + * * RTAS_OUT_HW_ERROR: Misc issue such as memory access failures */ -uint32_t do_fadump_register(void) +uint32_t do_fadump_register(SpaprMachineState *spapr, target_ulong args) { - /* WIP: FADUMP_CMD_REGISTER implemented in future patch */ + FadumpSectionHeader header; + FadumpSection regions[FADUMP_MAX_SECTIONS] =3D {0}; + target_ulong fdm_addr =3D rtas_ld(args, 1); + target_ulong fdm_size =3D rtas_ld(args, 2); + AddressSpace *default_as =3D &address_space_memory; + MemTxResult io_result; + MemTxAttrs attrs; + uint64_t next_section_addr; + uint16_t dump_num_sections; + + /* Mark the memory transaction as privileged memory access */ + attrs.user =3D 0; + attrs.memory =3D 1; + + if (spapr->fadump_registered) { + /* FADump already registered */ + return RTAS_OUT_DUMP_ALREADY_REGISTERED; + } + + if (spapr->fadump_dump_active =3D=3D 1) { + return RTAS_OUT_DUMP_ACTIVE; + } + + if (fdm_size < sizeof(FadumpSectionHeader)) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Header size is invalid: %lu\n", fdm_size); + return RTAS_OUT_PARAM_ERROR; + } + + /* Ensure fdm_addr points to a valid RMR-memory/RMA-memory buffer */ + if ((fdm_addr <=3D 0) || ((fdm_addr + fdm_size) > spapr->rma_size)) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Invalid fdm address: %ld\n", fdm_addr); + return RTAS_OUT_PARAM_ERROR; + } + + /* Try to read the passed fadump header */ + io_result =3D address_space_read(default_as, fdm_addr, attrs, + &header, sizeof(header)); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Unable to read fdm address: %ld\n", fdm_addr); + + return RTAS_OUT_HW_ERROR; + } + + /* Verify that we understand the fadump header version */ + if (header.dump_format_version !=3D cpu_to_be32(FADUMP_VERSION)) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Unknown fadump header version: 0x%x\n", + header.dump_format_version); + return RTAS_OUT_PARAM_ERROR; + } + + /* Reset dump status flags */ + header.dump_status_flag =3D 0; + + dump_num_sections =3D be16_to_cpu(header.dump_num_sections); + + if (dump_num_sections > FADUMP_MAX_SECTIONS) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Too many sections: %d sections\n", dump_num_sections); + return RTAS_OUT_PARAM_ERROR; + } + + next_section_addr =3D + fdm_addr + + be32_to_cpu(header.offset_first_dump_section); + + for (int i =3D 0; i < dump_num_sections; ++i) { + /* Read the fadump section from memory */ + io_result =3D address_space_read(default_as, next_section_addr, at= trs, + ®ions[i], sizeof(regions[i])); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_UNIMP, + "FADump: Unable to read fadump %dth section\n", i); + return RTAS_OUT_PARAM_ERROR; + } + + next_section_addr +=3D sizeof(regions[i]); + } + + spapr->fadump_registered =3D true; + spapr->fadump_dump_active =3D false; + + /* Store the registered fadump memory struct */ + spapr->registered_fdm.header =3D header; + for (int i =3D 0; i < dump_num_sections; ++i) { + spapr->registered_fdm.rgn[i] =3D regions[i]; + } =20 - return RTAS_OUT_HW_ERROR; + return RTAS_OUT_SUCCESS; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index b8bfa9c33fb5..0454938a01e9 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -366,7 +366,7 @@ static void rtas_configure_kernel_dump(PowerPCCPU *cpu, =20 switch (cmd) { case FADUMP_CMD_REGISTER: - ret_val =3D do_fadump_register(); + ret_val =3D do_fadump_register(spapr, args); if (ret_val !=3D RTAS_OUT_SUCCESS) { rtas_st(rets, 0, ret_val); return; diff --git a/include/hw/ppc/spapr_fadump.h b/include/hw/ppc/spapr_fadump.h index 45109fd9e137..6abbcb44f353 100644 --- a/include/hw/ppc/spapr_fadump.h +++ b/include/hw/ppc/spapr_fadump.h @@ -65,5 +65,5 @@ struct FadumpMemStruct { FadumpSection rgn[FADUMP_MAX_SECTIONS]; }; =20 -uint32_t do_fadump_register(void); +uint32_t do_fadump_register(struct SpaprMachineState *, target_ulong); #endif /* PPC_SPAPR_FADUMP_H */ --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893907; cv=none; d=zohomail.com; s=zohoarc; b=hIMBLqrco8+aTJjbue40sqJGFh/Y+GKUfnN6NYZZd0QLaHNwYxX7SCpzqR/rvAMyRBiWuzQu0pzspD832UBCR958oeb+jl1TN+bsKGR+xvtVSiW5mleZFbExIw2+wvl3BSynPZn754OtCzAI2bo08bRk5XE+ToN/HTCti3FESlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893907; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CsRkmO1Vp4BiSZui1A2a0f6Zu/Hfu1H5lF+KT5SGJQE=; b=JCl0G8LuCmcB9Xk78oQvdZbv+avty5XBCtQLkg/mWbNix5g4xdbrwkv+DLsN0ZGonSW6/tDEaDeYgY2U1QNz0FxJ+h3PTfwsoaGh7f46NzwfQvR7OzBhRZSW5LpaQp8lgQDmwV7zzc7+Lp39QMCw+7eO72E2yau9OTvD//Myrp0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741893907714674.256527018881; Thu, 13 Mar 2025 12:25:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAB-0002sO-Gd; Thu, 13 Mar 2025 15:24:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA3-0002rR-B6; Thu, 13 Mar 2025 15:24:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA1-0000tW-9N; Thu, 13 Mar 2025 15:24:07 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo6Jb030511; Thu, 13 Mar 2025 19:24:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:02 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJMtmg019938; Thu, 13 Mar 2025 19:24:02 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hmu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:02 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGDNJG003148; Thu, 13 Mar 2025 19:24:01 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atstufu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:01 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJNwEQ32440744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:23:58 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 093D520043; Thu, 13 Mar 2025 19:23:58 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B23D220040; Thu, 13 Mar 2025 19:23:55 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:23:55 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=CsRkmO 1Vp4BiSZui1A2a0f6Zu/Hfu1H5lF+KT5SGJQE=; b=VNJTacUoNYkSggcY92Qj4M /OwyDvL9Ma4NmYrvfyyRciPWiDFiM6VtHRoqEo1BN0roSI3tlGzt9EERNd3nCWQX pnP9llpHVLhMKqHBo6pFeuj74j45keCKaGOTgaVw7P3fYbw/LZ1hzhbDK/1IKfXV 7FipiebE74wv0jXWkXHt4s/6Zz9zU+gpurOiyGSBnvfPfpWwMtYcoCDvT5Ii2GBG f4BLh43VF6Ov70ajrKjaPQ1pvx3F2TW31EfmqWi2votJa1dQQ5XvcOVjRve8BnP4 1bOB5iz3tRZXZN/ekIrTnJ8aymJ3fp+8jQGUTENhVEjyliRR2q5fZ6zf+LISkpsw == From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 3/8] hw/ppc: Trigger Fadump boot if fadump is registered Date: Fri, 14 Mar 2025 00:53:36 +0530 Message-ID: <20250313192341.132171-4-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: QT-zvCRBykocb1jTwYirJ3C8sSjjeCX9 X-Proofpoint-ORIG-GUID: 1du_ZfjZ52Nff_uh3iUB5WdGSNMfq6zf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893908331019000 According to PAPR: R1=E2=80=937.3.30=E2=80=933. When the platform receives an ibm,os-term = RTAS call, or on a system reset without an ibm,nmi-interlock RTAS call, if the platform has a dump structure registered through the ibm,configure-kernel-dump call, the platform must process each registered kernel dump section as required and, when available, present the dump structure information to the operating system through the =E2=80=9Cibm,kernel-dump=E2=80=9D property, updated with st= atus for each dump section, until the dump has been invalidated through the ibm,configure-kernel-dump RTAS call. If Fadump has been registered, trigger an Fadump boot (memory preserving boot), if QEMU recieves a 'ibm,os-term' rtas call. Implementing the fadump boot as: * pause all vcpus (will need to save registers later) * preserve memory regions specified by fadump (will be implemented in future) * do a memory preserving reboot (GUEST_RESET in QEMU doesn't clear the memory) Memory regions registered by fadump will be handled in a later patch. Note: Preserving memory regions is not implemented yet so on an "ibm,os-term" call will just trigger a reboot in QEMU if fadump is registered, and the second kernel will boot as a normal boot (not fadump boot) Signed-off-by: Aditya Gupta --- hw/ppc/spapr_fadump.c | 77 +++++++++++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 5 +++ include/hw/ppc/spapr_fadump.h | 1 + 3 files changed, 83 insertions(+) diff --git a/hw/ppc/spapr_fadump.c b/hw/ppc/spapr_fadump.c index 9c7fb9e12b16..fedd2cde9a4f 100644 --- a/hw/ppc/spapr_fadump.c +++ b/hw/ppc/spapr_fadump.c @@ -7,6 +7,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "hw/ppc/spapr.h" +#include "system/cpus.h" =20 /* * Handle the "FADUMP_CMD_REGISTER" command in 'ibm,configure-kernel-dump' @@ -121,3 +122,79 @@ uint32_t do_fadump_register(SpaprMachineState *spapr, = target_ulong args) =20 return RTAS_OUT_SUCCESS; } + +/* Preserve the memory locations registered for fadump */ +static bool fadump_preserve_mem(void) +{ + /* + * TODO: Implement preserving memory regions requested during fadump + * registration + */ + return false; +} + +/* + * Trigger a fadump boot, ie. next boot will be a crashkernel/fadump boot + * with fadump dump active. + * + * This is triggered by ibm,os-term RTAS call, if fadump was registered. + * + * It preserves the memory and sets 'FADUMP_STATUS_DUMP_TRIGGERED' as + * fadump status, which can be used later to add the "ibm,kernel-dump" + * device tree node as presence of 'FADUMP_STATUS_DUMP_TRIGGERED' signifies + * next boot as fadump boot in our case + */ +void trigger_fadump_boot(SpaprMachineState *spapr, target_ulong spapr_retc= ode) +{ + FadumpSectionHeader *header =3D &spapr->registered_fdm.header; + + pause_all_vcpus(); + + /* Preserve the memory locations registered for fadump */ + if (!fadump_preserve_mem()) { + /* Failed to preserve the registered memory regions */ + rtas_st(spapr_retcode, 0, RTAS_OUT_HW_ERROR); + + /* Cause a reboot */ + qemu_system_guest_panicked(NULL); + return; + } + + /* + * Mark next boot as fadump boot + * + * Note: These is some bit of assumption involved here, as PAPR doesn't + * specify any use of the dump status flags, nor does the kernel use it + * + * But from description in Table 136 in PAPR v2.13, it looks like: + * FADUMP_STATUS_DUMP_TRIGGERED + * =3D Dump was triggered by the previous system boot (PAPR says) + * =3D Next boot will be a fadump boot (My perception) + * + * FADUMP_STATUS_DUMP_PERFORMED + * =3D Dump performed (Set to 0 by caller of the + * ibm,configure-kernel-dump call) (PAPR says) + * =3D Firmware has performed the copying/dump of requested regio= ns + * (My perception) + * =3D Dump is active for the next boot (My perception) + */ + header->dump_status_flag =3D cpu_to_be16( + FADUMP_STATUS_DUMP_TRIGGERED | /* Next boot will be fadump bo= ot */ + FADUMP_STATUS_DUMP_PERFORMED /* Dump is active */ + ); + + /* Reset fadump_registered for next boot */ + spapr->fadump_registered =3D false; + spapr->fadump_dump_active =3D true; + + /* + * Then do a guest reset + * + * Requirement: + * GUEST_RESET is expected to NOT clear the memory, as is the case when + * this is merged + */ + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + + rtas_st(spapr_retcode, 0, RTAS_OUT_SUCCESS); +} diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 0454938a01e9..14b954a05109 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -412,6 +412,11 @@ static void rtas_ibm_os_term(PowerPCCPU *cpu, target_ulong msgaddr =3D rtas_ld(args, 0); char msg[512]; =20 + if (spapr->fadump_registered) { + /* If fadump boot works, control won't come back here */ + return trigger_fadump_boot(spapr, rets); + } + cpu_physical_memory_read(msgaddr, msg, sizeof(msg) - 1); msg[sizeof(msg) - 1] =3D 0; =20 diff --git a/include/hw/ppc/spapr_fadump.h b/include/hw/ppc/spapr_fadump.h index 6abbcb44f353..071608cda088 100644 --- a/include/hw/ppc/spapr_fadump.h +++ b/include/hw/ppc/spapr_fadump.h @@ -66,4 +66,5 @@ struct FadumpMemStruct { }; =20 uint32_t do_fadump_register(struct SpaprMachineState *, target_ulong); +void trigger_fadump_boot(struct SpaprMachineState *, target_ulong); #endif /* PPC_SPAPR_FADUMP_H */ --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893907; cv=none; d=zohomail.com; s=zohoarc; b=K++gePfQ5/tP+wRMc7Yaxdh81Io0HJyrP/B/KYO1KngkjIAMBB8FdwTFHYS4tAsgv0atEGD6LyPszZw6esOokFeJpbsNx/5iMVA9NwNOlxyTboc15Ja/AKLvAG0qefEpp1YtuCjrwbDjYP15/nS4ud3zA+U+3Bkh5QONJVur610= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893907; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Uuw3/tigzX/MyyvAdmAPs71cWo8bjE7FB5tGCK9RVeE=; b=V8Sw2c2jFeM38fj8yRwOWG9XyqmUaR6IKZMdzz7FCV3n+KlcRmtaZWjN/lzUJxFw0a1XGnSqUXucafkbrNHkIl1G4kpID1kG3Qq5jdjqTvxVX396cAbfPX/L4reAGCBUkzs9vhFPlcf1Riu69oZ+GfhjBLwbgsTQx2FxwV0JVag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741893907061851.6119773513627; Thu, 13 Mar 2025 12:25:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAJ-0002ue-ES; Thu, 13 Mar 2025 15:24:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA5-0002s0-He; Thu, 13 Mar 2025 15:24:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA3-0000tn-C4; Thu, 13 Mar 2025 15:24:09 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo4ui030036; Thu, 13 Mar 2025 19:24:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45byd8tak8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:05 +0000 (GMT) Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJO5jT029735; Thu, 13 Mar 2025 19:24:05 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45byd8tak5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:05 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGBwIe015361; Thu, 13 Mar 2025 19:24:04 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atspkfnk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:04 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJO0Bf47710592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:24:00 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C34720043; Thu, 13 Mar 2025 19:24:00 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 76E9E20040; Thu, 13 Mar 2025 19:23:58 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:23:58 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=Uuw3/tigzX/MyyvAd mAPs71cWo8bjE7FB5tGCK9RVeE=; b=J9FLHJ3s6/Bmm6OhZRThSJUyTyMu4Gdo2 Wqr1BPrJuwv75K2g6m6/W9sr3KUGBgZ+uBU7AMG6rOofUbnbJX+0yLAs13osSv15 /UmrTanM8dvtGhY/WCyoIqcVirnP99I0nuS6+7MpODNmIehObVw8CrUdPKPBLogK J941K9gkgtnjMRUBg6hg+xLEw1apbHxiQ1VMcIO0rQy3d88MOKbHBEvo8HUlFeyF /wi7hsHLprFIjHe5JK2g3ZBf1WvSj6/i6VvTQRSthU4BpShpmNXjUEmKSE7EMiBg MUtWpBhHwVniD5KASZ0t9iEjQ2hY1zknNXPiQzzhJFk/ScQF0CzIw== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 4/8] hw/ppc: Preserve memory regions registered for fadump Date: Fri, 14 Mar 2025 00:53:37 +0530 Message-ID: <20250313192341.132171-5-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3LM7W_MoQhEVbK0KTzRTgV5tpw7Sbf-2 X-Proofpoint-ORIG-GUID: xW-bIu__NIW2qYZhVPAdqvJiGt-Tbing X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 bulkscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893908194019100 Content-Type: text/plain; charset="utf-8" While the first kernel boots, it registers memory regions for fadump such as: * CPU state data (has to be populated by the platform) * HPTE state data (has to be populated by the platform) * Real Mode Regions (platform should copy it to requested destination addresses) * OS defined regions (such as parameter save area) Platform is also expected to modify the 'bytes_dumped' to the length of data preserved/copied by platform (ideally same as the source length passed by kernel). The kernel passes source address and length for the memory regions, and a destination address to where the memory is to be copied. Implement the preserving/copying of the Real Mode Regions and the Parameter Save Area in QEMU Pseries Note: As of this patch, the "kernel-dump" device tree entry is still not added for the second boot, so after crash, the second kernel will boot assuming fadump dump is "NOT" active, and try to register for fadump, but since we already have fadump registered in QEMU internal state, the register rtas call will fail with: "DUMP ACTIVE" Signed-off-by: Aditya Gupta --- hw/ppc/spapr_fadump.c | 158 ++++++++++++++++++++++++++++++++-- include/hw/ppc/spapr_fadump.h | 23 +++++ 2 files changed, 176 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr_fadump.c b/hw/ppc/spapr_fadump.c index fedd2cde9a4f..db874fe13487 100644 --- a/hw/ppc/spapr_fadump.c +++ b/hw/ppc/spapr_fadump.c @@ -123,14 +123,162 @@ uint32_t do_fadump_register(SpaprMachineState *spapr= , target_ulong args) return RTAS_OUT_SUCCESS; } =20 +/* + * Copy the source region of given fadump section, to the destination + * address mentioned in the region + * + * Also set the region's error flag, if the copy fails due to non-existent + * address (MEMTX_DECODE_ERROR) or permission issues (MEMTX_ACCESS_ERROR) + * + * Returns true if successful copy + * + * Returns false in case of any other error, being treated as hardware + * error for fadump purposes + */ +static bool do_preserve_region(FadumpSection *region) +{ + AddressSpace *default_as =3D &address_space_memory; + MemTxResult io_result; + MemTxAttrs attrs; + uint64_t src_addr, src_len, dest_addr; + void *copy_buffer; + + src_addr =3D be64_to_cpu(region->source_address); + src_len =3D be64_to_cpu(region->source_len); + dest_addr =3D be64_to_cpu(region->destination_address); + + /* Mark the memory transaction as privileged memory access */ + attrs.user =3D 0; + attrs.memory =3D 1; + + /* + * Optimisation: Skip copy if source and destination are same + * (eg. param area) + */ + if (src_addr !=3D dest_addr) { + copy_buffer =3D g_malloc(src_len + 1); + if (copy_buffer =3D=3D NULL) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Failed allocating memory for copying reserved mem= ory regions\n"); + + return false; + } + + /* Copy the source region to destination */ + io_result =3D address_space_read(default_as, src_addr, attrs, + copy_buffer, src_len); + if ((io_result & MEMTX_DECODE_ERROR) || + (io_result & MEMTX_ACCESS_ERROR)) { + /* + * Invalid source address is not an hardware error, instead + * wrong parameter from the kernel. + * Return true to let caller know to continue reading other + * sections + */ + region->error_flags =3D FADUMP_ERROR_INVALID_SOURCE_ADDR; + region->bytes_dumped =3D 0; + return true; + } else if (io_result !=3D MEMTX_OK) { + g_free(copy_buffer); + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Failed to read source region in section: %d\n", + region->source_data_type); + + return false; + } + + io_result =3D address_space_write(default_as, dest_addr, attrs, + copy_buffer, src_len); + g_free(copy_buffer); + if ((io_result & MEMTX_DECODE_ERROR) || + (io_result & MEMTX_ACCESS_ERROR)) { + /* + * Invalid destination address is not an hardware error, + * instead wrong parameter from the kernel. + * Return true to let caller know to continue reading other + * sections + */ + region->error_flags =3D FADUMP_ERROR_INVALID_DEST_ADDR; + region->bytes_dumped =3D 0; + return true; + } else if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Failed to write destination in section: %d\n", + region->source_data_type); + + return false; + } + } + + /* + * Considering address_space_write would have copied the + * complete region + */ + region->bytes_dumped =3D cpu_to_be64(src_len); + return true; +} + /* Preserve the memory locations registered for fadump */ -static bool fadump_preserve_mem(void) +static bool fadump_preserve_mem(SpaprMachineState *spapr) { + FadumpMemStruct *fdm =3D &spapr->registered_fdm; + uint16_t dump_num_sections, data_type; + + assert(spapr->fadump_registered); + /* - * TODO: Implement preserving memory regions requested during fadump - * registration + * Handle all sections + * + * CPU State Data and HPTE regions are handled in their own cases + * + * RMR regions and any custom OS reserved regions such as parameter + * save area, are handled by simply copying the source region to + * destination address */ - return false; + dump_num_sections =3D be16_to_cpu(fdm->header.dump_num_sections); + for (int i =3D 0; i < dump_num_sections; ++i) { + data_type =3D be16_to_cpu(fdm->rgn[i].source_data_type); + + /* Reset error_flags & bytes_dumped for now */ + fdm->rgn[i].error_flags =3D 0; + fdm->rgn[i].bytes_dumped =3D 0; + + /* If kernel did not request for the memory region, then skip it */ + if (be32_to_cpu(fdm->rgn[i].request_flag) !=3D FADUMP_REQUEST_FLAG= ) { + qemu_log_mask(LOG_UNIMP, + "FADump: Skipping copying region as not requested\n"); + continue; + } + + switch (data_type) { + case FADUMP_CPU_STATE_DATA: + /* TODO: Add CPU state data */ + break; + case FADUMP_HPTE_REGION: + /* TODO: Add hpte state data */ + break; + case FADUMP_REAL_MODE_REGION: + case FADUMP_PARAM_AREA: + /* Copy the memory region from region's source to its destinat= ion */ + if (!do_preserve_region(&fdm->rgn[i])) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Failed to preserve dump section: %d\n", + be16_to_cpu(fdm->rgn[i].source_data_type)); + fdm->header.dump_status_flag |=3D + cpu_to_be16(FADUMP_STATUS_DUMP_ERROR); + } + + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Skipping unknown source data type: %d\n", data_ty= pe); + + fdm->rgn[i].error_flags =3D + cpu_to_be16(FADUMP_ERROR_INVALID_DATA_TYPE); + } + } + + return true; } =20 /* @@ -151,7 +299,7 @@ void trigger_fadump_boot(SpaprMachineState *spapr, targ= et_ulong spapr_retcode) pause_all_vcpus(); =20 /* Preserve the memory locations registered for fadump */ - if (!fadump_preserve_mem()) { + if (!fadump_preserve_mem(spapr)) { /* Failed to preserve the registered memory regions */ rtas_st(spapr_retcode, 0, RTAS_OUT_HW_ERROR); =20 diff --git a/include/hw/ppc/spapr_fadump.h b/include/hw/ppc/spapr_fadump.h index 071608cda088..d56ca1d6d651 100644 --- a/include/hw/ppc/spapr_fadump.h +++ b/include/hw/ppc/spapr_fadump.h @@ -16,6 +16,29 @@ =20 #define FADUMP_VERSION 1 =20 +/* Firmware provided dump sections */ +#define FADUMP_CPU_STATE_DATA 0x0001 +#define FADUMP_HPTE_REGION 0x0002 +#define FADUMP_REAL_MODE_REGION 0x0011 + +/* OS defined sections */ +#define FADUMP_PARAM_AREA 0x0100 + +/* Dump request flag */ +#define FADUMP_REQUEST_FLAG 0x00000001 + +/* Dump status flags */ +#define FADUMP_STATUS_DUMP_PERFORMED 0x8000 +#define FADUMP_STATUS_DUMP_TRIGGERED 0x4000 +#define FADUMP_STATUS_DUMP_ERROR 0x2000 + +/* Region dump error flags */ +#define FADUMP_ERROR_INVALID_DATA_TYPE 0x8000 +#define FADUMP_ERROR_INVALID_SOURCE_ADDR 0x4000 +#define FADUMP_ERROR_LENGTH_EXCEEDS_SOURCE 0x2000 +#define FADUMP_ERROR_INVALID_DEST_ADDR 0x1000 +#define FAUDMP_ERROR_DEST_TOO_SMALL 0x0800 + /* * The Firmware Assisted Dump Memory structure supports a maximum of 10 se= ctions * in the dump memory structure. Presently, three sections are used for --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893914; cv=none; d=zohomail.com; s=zohoarc; b=eUMTXy36Mklf389UzaX5yweb6sjtPHBt0/mT0Sfk8yW2mQN28OU/Pe/+Fwy89461Bj4JkntMXUw1mLZPEVVK8srcFQjYxwOeSHWj7cXFBUC94aoUgjXiP+fk+YAePqZV12F7iDOVL9XNuT25wCVfbUjmYgFWzbD/OoLLz66VOCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893914; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p45XZPt6cyjO7tLyVDUdmlJeuN9UMUcDZJ8ahf4Xc8c=; b=jqnzIIFo1GbEsVlbn/xv30qj7RtG95SLUiqs0DRTB/3nQAc+Lk32ljOKPrD1qqTb72wRapiFm+ckbGmIxDu7ZLbU0G6H5YuAk7Cg5de+F+Us7JUm4XS516S8L/WdqDayysiuDp9V+4rUTDQiWCRa1BKxwJG5xLBAI9YFBptZ0+0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17418939140621023.5600795051333; Thu, 13 Mar 2025 12:25:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAP-0002xE-5m; Thu, 13 Mar 2025 15:24:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA9-0002tx-QI; Thu, 13 Mar 2025 15:24:15 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA7-0000u7-1X; Thu, 13 Mar 2025 15:24:13 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo4YS030285; Thu, 13 Mar 2025 19:24:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hn6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:08 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DIsOHp024720; Thu, 13 Mar 2025 19:24:07 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:07 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DG55HV026064; Thu, 13 Mar 2025 19:24:06 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atspkg28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:06 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJO3YF22872564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:24:03 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F90F20043; Thu, 13 Mar 2025 19:24:03 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 03F4720040; Thu, 13 Mar 2025 19:24:01 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:24:00 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=p45XZPt6cyjO7tLyV DUdmlJeuN9UMUcDZJ8ahf4Xc8c=; b=kAmXIcFHQc5CHZGr3chrTdd3luQD/RfPA rgV79VE7BkGK/AetXb3ZQrTg2teTcCmZFchcOEUqnLOKZhmvk/xcALWLWLTEz+CY 4Te4zdZgA1qbm2CgNpARJp6wLSWEYSndyf5PyFWb9T76vEWY4EKz3jmsYD3CAqo7 /Udr9X06mCu9YIJJVMZ9kJI0eBpG9nquYWdi4EYSUVTkINoMnyjFDxz+e/xDqSpk lTNdC2wsuuFBWr0miZUVfxn73CZm+kaxQhrgNbLefTGfwQL5aU/M6FKsB603KYCR L7X9qNWQGpjV+txMjqzj/vMvE07vA8AoDuPZrWqBixf+4L8XdxTCA== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 5/8] hw/ppc: Implement saving CPU state in Fadump Date: Fri, 14 Mar 2025 00:53:38 +0530 Message-ID: <20250313192341.132171-6-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: kAr6PgUSOBCm29akchGeE76BEVdCw3FH X-Proofpoint-ORIG-GUID: ehMVT3DeZCtnroHMWnQyzQd1bJQAdHY9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893916626019000 Content-Type: text/plain; charset="utf-8" Kernel expects CPU states/register states in the format mentioned in "Register Save Area" in PAPR. The platform (in our case, QEMU) saves each CPU register in the form of an array of "register entries", the start and end of this array is signified by "CPUSTRT" and "CPUEND" register entries respectively. The CPUSTRT and CPUEND register entry also has 4-byte logical CPU ID, thus storing the CPU ID corresponding to the array of register entries. Each register, and CPUSTRT, CPUEND has a predefined identifier. Implement calculating identifier for a given register in 'fadump_str_to_u64', which has been taken from the linux kernel Similarly GPRs also have predefined identifiers, and a corresponding 64-bit resiter value (split into two 32-bit cells). Implement calculation of GPR identifiers with 'fadump_gpr_id_to_u64' PAPR has restrictions on particular order of few registers, and is free to be in any order for other registers. Some registers mentioned in PAPR have not been exported as they are not implemented in QEMU / don't make sense in QEMU. Implement saving of CPU state according to the PAPR document Note: As of this patch, the "kernel-dump" device tree entry is still not added for the second boot, so after crash, the second kernel will boot assuming fadump dump is "NOT" active, and try to register for fadump, but since we already have fadump registered in QEMU internal state, the register rtas call will fail with: "DUMP ACTIVE" Signed-off-by: Aditya Gupta --- hw/ppc/spapr_fadump.c | 333 +++++++++++++++++++++++++++++++++- include/hw/ppc/spapr_fadump.h | 28 +++ 2 files changed, 360 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr_fadump.c b/hw/ppc/spapr_fadump.c index db874fe13487..e84f7338d82c 100644 --- a/hw/ppc/spapr_fadump.c +++ b/hw/ppc/spapr_fadump.c @@ -8,6 +8,71 @@ #include "qemu/log.h" #include "hw/ppc/spapr.h" #include "system/cpus.h" +#include "system/hw_accel.h" + +/* + * Copy the ascii values for first 8 characters from a string into u64 + * variable at their respective indexes. + * e.g. + * The string "FADMPINF" will be converted into 0x4641444d50494e46 + */ +static uint64_t fadump_str_to_u64(const char *str) +{ + uint64_t val =3D 0; + int i; + + for (i =3D 0; i < sizeof(val); i++) { + val =3D (*str) ? (val << 8) | *str++ : val << 8; + } + return val; +} + +/** + * Get the identifier id for register entries of GPRs + * + * It gives the same id as 'fadump_str_to_u64' when the complete string id + * of the GPR is given, ie. + * + * fadump_str_to_u64("GPR05") =3D=3D fadump_gpr_id_to_u64(5); + * fadump_str_to_u64("GPR12") =3D=3D fadump_gpr_id_to_u64(12); + * + * And so on. Hence this can be implemented by creating a dynamic + * string for each GPR, such as "GPR00", "GPR01", ... "GPR31" + * Instead of allocating a string, an observation from the math of + * 'fadump_str_to_u64' or from PAPR tells us that there's a pattern + * in the identifier IDs, such that the first 4 bytes are affected only by + * whether it is GPR0*, GPR1*, GPR2*, GPR3*. + * Upper half of 5th byte is always 0x3. Lower half (nibble) of 5th byte + * is the tens digit of the GPR id, ie. GPR ID / 10. + * Upper half of 6th byte is always 0x3. Lower half (nibble) of 5th byte + * is the ones digit of the GPR id, ie. GPR ID % 10 + * + * For example, for GPR 29, the 5th and 6th byte will be 0x32 and 0x39 + */ +static uint64_t fadump_gpr_id_to_u64(uint32_t gpr_id) +{ + uint64_t val =3D 0; + + /* Valid range of GPR id is only GPR0 to GPR31 */ + assert(gpr_id < 32); + + /* Below calculations set the 0th to 5th byte */ + if (gpr_id <=3D 9) { + val =3D fadump_str_to_u64("GPR0"); + } else if (gpr_id <=3D 19) { + val =3D fadump_str_to_u64("GPR1"); + } else if (gpr_id <=3D 29) { + val =3D fadump_str_to_u64("GPR2"); + } else { + val =3D fadump_str_to_u64("GPR3"); + } + + /* Set the 6th byte */ + val |=3D 0x30000000; + val |=3D ((gpr_id % 10) << 24); + + return val; +} =20 /* * Handle the "FADUMP_CMD_REGISTER" command in 'ibm,configure-kernel-dump' @@ -218,14 +283,222 @@ static bool do_preserve_region(FadumpSection *region) return true; } =20 +/* + * Populate the passed CPUs register entries, in the buffer starting at + * the argument 'curr_reg_entry' + * + * The register entries is an array of pair of register id and register + * value, as described in Table 591/592 in section "H.1 Register Save Area" + * in PAPR v2.13 + * + * Returns pointer just past this CPU's register entries, which can be used + * as the start address for next CPU's register entries + */ +static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu, + FadumpRegEntry *curr_reg_entry) +{ + CPUPPCState *env; + PowerPCCPU *ppc_cpu; + uint32_t num_regs_per_cpu =3D 0; + + ppc_cpu =3D POWERPC_CPU(cpu); + env =3D cpu_env(cpu); + num_regs_per_cpu =3D 0; + + curr_reg_entry->reg_id =3D + cpu_to_be64(fadump_str_to_u64("CPUSTRT")); + curr_reg_entry->reg_value =3D ppc_cpu->vcpu_id; + ++curr_reg_entry; + +#define REG_ENTRY(id, val) \ + do { \ + curr_reg_entry->reg_id =3D \ + cpu_to_be64(fadump_str_to_u64(#id)); \ + curr_reg_entry->reg_value =3D cpu_to_be64(val); \ + ++curr_reg_entry; \ + ++num_regs_per_cpu; \ + } while (0) + + REG_ENTRY(ACOP, env->spr[SPR_ACOP]); + REG_ENTRY(AMR, env->spr[SPR_AMR]); + REG_ENTRY(BESCR, env->spr[SPR_BESCR]); + REG_ENTRY(CFAR, env->spr[SPR_CFAR]); + REG_ENTRY(CIABR, env->spr[SPR_CIABR]); + + /* Save the condition register */ + REG_ENTRY(CR, ppc_get_cr(env)); + + REG_ENTRY(CTR, env->spr[SPR_CTR]); + REG_ENTRY(CTRL, env->spr[SPR_CTRL]); + REG_ENTRY(DABR, env->spr[SPR_DABR]); + REG_ENTRY(DABRX, env->spr[SPR_DABRX]); + REG_ENTRY(DAR, env->spr[SPR_DAR]); + REG_ENTRY(DAWR0, env->spr[SPR_DAWR0]); + REG_ENTRY(DAWR1, env->spr[SPR_DAWR1]); + REG_ENTRY(DAWRX0, env->spr[SPR_DAWRX0]); + REG_ENTRY(DAWRX1, env->spr[SPR_DAWRX1]); + REG_ENTRY(DPDES, env->spr[SPR_DPDES]); + REG_ENTRY(DSCR, env->spr[SPR_DSCR]); + REG_ENTRY(DSISR, env->spr[SPR_DSISR]); + REG_ENTRY(EBBHR, env->spr[SPR_EBBHR]); + REG_ENTRY(EBBRR, env->spr[SPR_EBBRR]); + + REG_ENTRY(FPSCR, env->fpscr); + REG_ENTRY(FSCR, env->spr[SPR_FSCR]); + + /* Save the GPRs */ + for (int gpr_id =3D 0; gpr_id < 32; ++gpr_id) { + curr_reg_entry->reg_id =3D + cpu_to_be64(fadump_gpr_id_to_u64(gpr_id)); + curr_reg_entry->reg_value =3D + cpu_to_be64(env->gpr[gpr_id]); + ++curr_reg_entry; + ++num_regs_per_cpu; + } + + REG_ENTRY(IAMR, env->spr[SPR_IAMR]); + REG_ENTRY(IC, env->spr[SPR_IC]); + REG_ENTRY(LR, env->spr[SPR_LR]); + + REG_ENTRY(MSR, env->msr); + REG_ENTRY(NIA, env->nip); /* NIA */ + REG_ENTRY(PIR, env->spr[SPR_PIR]); + REG_ENTRY(PSPB, env->spr[SPR_PSPB]); + REG_ENTRY(PVR, env->spr[SPR_PVR]); + REG_ENTRY(RPR, env->spr[SPR_RPR]); + REG_ENTRY(SPURR, env->spr[SPR_SPURR]); + REG_ENTRY(SRR0, env->spr[SPR_SRR0]); + REG_ENTRY(SRR1, env->spr[SPR_SRR1]); + REG_ENTRY(TAR, env->spr[SPR_TAR]); + REG_ENTRY(TEXASR, env->spr[SPR_TEXASR]); + REG_ENTRY(TFHAR, env->spr[SPR_TFHAR]); + REG_ENTRY(TFIAR, env->spr[SPR_TFIAR]); + REG_ENTRY(TIR, env->spr[SPR_TIR]); + REG_ENTRY(UAMOR, env->spr[SPR_UAMOR]); + REG_ENTRY(VRSAVE, env->spr[SPR_VRSAVE]); + REG_ENTRY(VSCR, env->vscr); + REG_ENTRY(VTB, env->spr[SPR_VTB]); + REG_ENTRY(WORT, env->spr[SPR_WORT]); + REG_ENTRY(XER, env->spr[SPR_XER]); + + /* + * Ignoring transaction checkpoint and few other registers + * mentioned in PAPR as not supported in QEMU + */ +#undef REG_ENTRY + + /* End the registers for this CPU with "CPUEND" reg entry */ + curr_reg_entry->reg_id =3D + cpu_to_be64(fadump_str_to_u64("CPUEND")); + + /* + * Ensure the number of registers match (+2 for STRT & END) + * + * This will help catch an error if in future a new register entry + * is added/removed while not modifying FADUMP_NUM_PER_CPU_REGS + */ + assert(FADUMP_NUM_PER_CPU_REGS =3D=3D num_regs_per_cpu + 2 /*CPUSTRT+C= PUEND*/); + + ++curr_reg_entry; + + return curr_reg_entry; +} + +/* + * Populate the "Register Save Area"/CPU State as mentioned in section "H.1 + * Register Save Area" in PAPR v2.13 + * + * It allocates the buffer for this region, then populates the register + * entries + * + * Returns the pointer to the buffer (which should be deallocated by the + * callers), and sets the size of this buffer in the argument + * 'cpu_state_len' + */ +static void *populate_cpu_state_data(uint64_t *cpu_state_len) +{ + FadumpRegSaveAreaHeader reg_save_hdr; + FadumpRegEntry *reg_entries; + FadumpRegEntry *curr_reg_entry; + CPUState *cpu; + + uint32_t fadump_reg_entries_size; + uint32_t num_cpus =3D 0; + + void *cpu_state_buffer =3D 0; + uint64_t offset =3D 0; + + CPU_FOREACH(cpu) { + ++num_cpus; + } + + reg_save_hdr.version =3D cpu_to_be32(0); + reg_save_hdr.magic_number =3D + cpu_to_be64(fadump_str_to_u64("REGSAVE")); + + /* Reg save area header is immediately followed by num cpus */ + reg_save_hdr.num_cpu_offset =3D + cpu_to_be32(sizeof(FadumpRegSaveAreaHeader)); + + fadump_reg_entries_size =3D num_cpus * + FADUMP_NUM_PER_CPU_REGS * + sizeof(FadumpRegEntry); + + reg_entries =3D malloc(fadump_reg_entries_size); + + /* Pointer to current CPU's registers */ + curr_reg_entry =3D reg_entries; + + /* Populate register entries for all CPUs */ + CPU_FOREACH(cpu) { + cpu_synchronize_state(cpu); + curr_reg_entry =3D populate_cpu_reg_entries(cpu, curr_reg_entry); + } + + *cpu_state_len =3D 0; + *cpu_state_len +=3D sizeof(reg_save_hdr); /* reg save header */ + *cpu_state_len +=3D 0xc; /* padding as in PAPR */ + *cpu_state_len +=3D sizeof(__be32); /* num_cpus */ + *cpu_state_len +=3D fadump_reg_entries_size; /* reg entries */ + + cpu_state_buffer =3D g_malloc(*cpu_state_len); + + memcpy(cpu_state_buffer + offset, + ®_save_hdr, sizeof(reg_save_hdr)); + offset +=3D sizeof(reg_save_hdr); + + /* Write num_cpus */ + num_cpus =3D cpu_to_be32(num_cpus); + memcpy(cpu_state_buffer + offset, &num_cpus, sizeof(__be32)); + offset +=3D sizeof(__be32); + + /* Write the register entries */ + memcpy(cpu_state_buffer + offset, + reg_entries, fadump_reg_entries_size); + offset +=3D fadump_reg_entries_size; + + return cpu_state_buffer; +} + /* Preserve the memory locations registered for fadump */ static bool fadump_preserve_mem(SpaprMachineState *spapr) { FadumpMemStruct *fdm =3D &spapr->registered_fdm; + FadumpSection *cpu_state_region; + AddressSpace *default_as =3D &address_space_memory; + MemTxResult io_result; + MemTxAttrs attrs; uint16_t dump_num_sections, data_type; + uint64_t dest_addr; + uint64_t cpu_state_addr, cpu_state_len =3D 0; + void *cpu_state_buffer; =20 assert(spapr->fadump_registered); =20 + /* Mark the memory transaction as privileged memory access */ + attrs.user =3D 0; + attrs.memory =3D 1; + /* * Handle all sections * @@ -238,6 +511,7 @@ static bool fadump_preserve_mem(SpaprMachineState *spap= r) dump_num_sections =3D be16_to_cpu(fdm->header.dump_num_sections); for (int i =3D 0; i < dump_num_sections; ++i) { data_type =3D be16_to_cpu(fdm->rgn[i].source_data_type); + dest_addr =3D be64_to_cpu(fdm->rgn[i].destination_address); =20 /* Reset error_flags & bytes_dumped for now */ fdm->rgn[i].error_flags =3D 0; @@ -252,7 +526,15 @@ static bool fadump_preserve_mem(SpaprMachineState *spa= pr) =20 switch (data_type) { case FADUMP_CPU_STATE_DATA: - /* TODO: Add CPU state data */ + cpu_state_region =3D &fdm->rgn[i]; + cpu_state_addr =3D dest_addr; + cpu_state_buffer =3D populate_cpu_state_data(&cpu_state_len); + + /* + * We will write the cpu state data later, as otherwise it + * might get overwritten by other fadump regions + */ + break; case FADUMP_HPTE_REGION: /* TODO: Add hpte state data */ @@ -278,6 +560,55 @@ static bool fadump_preserve_mem(SpaprMachineState *spa= pr) } } =20 + /* + * Write the Register Save Area + * + * CPU State/Register Save Area should be written after dumping the + * memory to prevent overwriting while saving other memory regions + * + * eg. If boot memory region is 1G, then both the first 1GB memory, and + * the Register Save Area needs to be saved at 1GB. + * And as the CPU_STATE_DATA region comes first than the + * REAL_MODE_REGION region to be copied, the CPU_STATE_DATA will get + * overwritten if saved before the 0GB - 1GB region is copied after + * saving CPU state data + */ + io_result =3D address_space_write(default_as, cpu_state_addr, attrs, + cpu_state_buffer, cpu_state_len); + g_free(cpu_state_buffer); + if ((io_result & MEMTX_DECODE_ERROR) || + (io_result & MEMTX_ACCESS_ERROR)) { + /* + * Invalid destination address is not an hardware error, instead + * wrong parameter from the kernel. + * Return true to let caller know to continue reading other + * sections + */ + cpu_state_region->error_flags =3D FADUMP_ERROR_INVALID_DEST_ADDR; + cpu_state_region->bytes_dumped =3D 0; + return true; + } else if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "FADump: Failed to write CPU state region\n"); + cpu_state_region->bytes_dumped =3D 0; + + return false; + } + + /* + * Set bytes_dumped in cpu state region, so kernel knows platform have + * exported it + */ + cpu_state_region->bytes_dumped =3D cpu_to_be64(cpu_state_len); + + if (cpu_state_region->source_len !=3D cpu_state_region->bytes_dumped) { + qemu_log_mask(LOG_GUEST_ERROR, + "CPU State region's length passed by kernel (0x%lx) !=3D" + " CPU State region's length exported by QEMU (0x%lx)\n", + be64_to_cpu(cpu_state_region->source_len), + be64_to_cpu(cpu_state_region->bytes_dumped)); + } + return true; } =20 diff --git a/include/hw/ppc/spapr_fadump.h b/include/hw/ppc/spapr_fadump.h index d56ca1d6d651..13bdd39a9ec1 100644 --- a/include/hw/ppc/spapr_fadump.h +++ b/include/hw/ppc/spapr_fadump.h @@ -48,9 +48,14 @@ #define FADUMP_MAX_SECTIONS 10 #define RTAS_FADUMP_MAX_BOOT_MEM_REGS 7 =20 +/* Number of registers stored per cpu */ +#define FADUMP_NUM_PER_CPU_REGS (32 /*GPR*/ + 45 /*others*/ + 2 /*STRT & E= ND*/) + typedef struct FadumpSection FadumpSection; typedef struct FadumpSectionHeader FadumpSectionHeader; typedef struct FadumpMemStruct FadumpMemStruct; +typedef struct FadumpRegSaveAreaHeader FadumpRegSaveAreaHeader; +typedef struct FadumpRegEntry FadumpRegEntry; =20 struct SpaprMachineState; =20 @@ -88,6 +93,29 @@ struct FadumpMemStruct { FadumpSection rgn[FADUMP_MAX_SECTIONS]; }; =20 +/* + * The firmware-assisted dump format. + * + * The register save area is an area in the partition's memory used to pre= serve + * the register contents (CPU state data) for the active CPUs during a fir= mware + * assisted dump. The dump format contains register save area header follo= wed + * by register entries. Each list of registers for a CPU starts with "CPUS= TRT" + * and ends with "CPUEND". + */ + +/* Register save area header. */ +struct FadumpRegSaveAreaHeader { + __be64 magic_number; + __be32 version; + __be32 num_cpu_offset; +}; + +/* Register entry. */ +struct FadumpRegEntry { + __be64 reg_id; + __be64 reg_value; +}; + uint32_t do_fadump_register(struct SpaprMachineState *, target_ulong); void trigger_fadump_boot(struct SpaprMachineState *, target_ulong); #endif /* PPC_SPAPR_FADUMP_H */ --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741893989; cv=none; d=zohomail.com; s=zohoarc; b=VcU4PIxfnOluEqrKHo39OzhUNDHxLzsaTQ86QclVpJn46LtVxt8+d1bW/qr8YVK/ZnakIM0C6N1Cx/5m2jdc5btuvZ0NgavVHfVp7eBX+fykkaPt3cXLIrf2lkIbwlNSFGUwaiyvImRCtd8azwB7XGdQ9qrjxhSmUDc+Fur1SbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741893989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ejNpIrZXudvJ/RDzRYoZF3epKTAm/W/xoHHPZJvePiQ=; b=KAW21b6YAfzRzBDERHU4SgEZS5T7JyMRR0f5GfIHwAcYz5Z4Q2NF/+bs7uBSmjVuHFn21nkVcms5HOOv6nGkP24vSz5CPlamNTqGvOeekusP8QsYNQG2tVmymFH/cYtk2U+90VmkUp+CVKzU3d8qdDSM71fZqkAtwrJz7cbjpzc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741893989527956.2610276253733; Thu, 13 Mar 2025 12:26:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAR-0002yT-R5; Thu, 13 Mar 2025 15:24:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoAC-0002uJ-AG; Thu, 13 Mar 2025 15:24:20 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoA9-0000uF-3O; Thu, 13 Mar 2025 15:24:14 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo4rp003361; Thu, 13 Mar 2025 19:24:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bhepnw73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:11 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJM3tu029392; Thu, 13 Mar 2025 19:24:10 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bhepnw6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:10 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DIoInt026010; Thu, 13 Mar 2025 19:24:10 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atspkg2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:10 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJO6XL49414654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:24:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 10C9220043; Thu, 13 Mar 2025 19:24:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A25C120040; Thu, 13 Mar 2025 19:24:03 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:24:03 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ejNpIrZXudvJ/RDzR YoZF3epKTAm/W/xoHHPZJvePiQ=; b=eIUZtyMXKMltj+O1K8UgZ4W8JdW/ykfI2 7qQb2kvt5bM1yeaG9cMi0TxfC64kmIvXAZn2xNpp3utSw980SsKdhqceT7fDNsFb ntXZUB/vj6EQSPFaooV/trpRWEToHkrgTNO6y6nTonANaXo/XBprdT8daQZhW0Hc 3isZZCtsbJXka3T5CBYthjDz+G5+kiHa9q2zH8Tl4YOju/i/hD5CPqcPCrHRbOuF 6fpaC8lKJ7ZdQ4i+5EPpogJ748I4W+cDMtxOxfSIvkgt45w2EXW7pZpvA6OR5/1C ECElNFwVWcccwD3hiKz2PglQjHB6gNtKbS957ylgtMuhUYK/DrZGg== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 6/8] hw/ppc: Pass dump-sizes property for fadump in device tree Date: Fri, 14 Mar 2025 00:53:39 +0530 Message-ID: <20250313192341.132171-7-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YwoGyIVvTaOaKuqn2Eduz22GaLX1FxkD X-Proofpoint-ORIG-GUID: H_6nwwzvtRwjSKdmIxIERN8bJZn5yPhl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.158.5; envelope-from=adityag@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741893990227019100 Content-Type: text/plain; charset="utf-8" Platform (ie. QEMU) is expected to pass few device tree properties for details for fadump: * "ibm,configure-kernel-dump-sizes": Space required to store dump data for firmware provided dump sections (ie. CPU & HPTE regions) * "ibm,configure-kernel-dump-version": Versions of fadump supported Pass the above device tree nodes so that kernel can reserve sufficient space for preserving the CPU state data Note: As of this patch, the "kernel-dump" device tree entry is still not added for the second boot, so after crash, the second kernel will boot assuming fadump dump is "NOT" active, and try to register for fadump, but since we already have fadump registered in QEMU internal state, the register rtas call will fail with: "DUMP ACTIVE" Signed-off-by: Aditya Gupta --- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a415e51d077a..dac9e4b3edaa 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -900,6 +900,62 @@ static int spapr_dt_rng(void *fdt) return ret ? -1 : 0; } =20 +static void spapr_dt_rtas_fadump(SpaprMachineState *spapr, void *fdt, int = rtas) +{ + MachineState *ms =3D MACHINE(spapr); + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + FadumpMemStruct *fdm =3D &spapr->registered_fdm; + + uint32_t max_possible_cpus =3D mc->possible_cpu_arch_ids(ms)->len; + uint64_t fadump_cpu_state_size =3D 0; + uint16_t fadump_versions[2] =3D { + FADUMP_VERSION /* min supported version */, + FADUMP_VERSION /* max supported version */ + }; + uint32_t fadump_rgn_sizes[2][3] =3D { + { + cpu_to_be32(FADUMP_CPU_STATE_DATA), + 0, 0 /* Calculated later */ + }, + { + cpu_to_be32(FADUMP_HPTE_REGION), + 0, 0 /* HPTE region not implemented */ + } + }; + + /* + * CPU State Data contains multiple fields such as header, num_cpus and + * register entries + * + * Calculate the maximum CPU State Data size, according to maximum + * possible CPUs the QEMU VM can have + * + * This calculation must match the 'cpu_state_len' calculation done in + * 'populate_cpu_state_data' in spapr_fadump.c + */ + fadump_cpu_state_size +=3D sizeof(struct FadumpRegSaveAreaHeader); + fadump_cpu_state_size +=3D 0xc; /* padding as in = PAPR */ + fadump_cpu_state_size +=3D sizeof(__be32); /* num_cpus */ + fadump_cpu_state_size +=3D max_possible_cpus * /* reg entries */ + FADUMP_NUM_PER_CPU_REGS * + sizeof(struct FadumpRegEntry); + + /* Set maximum size for CPU state data region */ + assert(fadump_rgn_sizes[0][0] =3D=3D cpu_to_be32(FADUMP_CPU_STATE_DATA= )); + + /* Upper 32 bits of size, usually 0 */ + fadump_rgn_sizes[0][1] =3D cpu_to_be32(fadump_cpu_state_size >> 32); + + /* Lower 32 bits of size */ + fadump_rgn_sizes[0][2] =3D cpu_to_be32(fadump_cpu_state_size & 0xfffff= fff); + + /* Add device tree properties required from platform for fadump */ + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-version", + fadump_versions, sizeof(fadump_versions)))); + _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-sizes", + fadump_rgn_sizes, sizeof(fadump_rgn_sizes)))); +} + static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) { MachineState *ms =3D MACHINE(spapr); @@ -1012,6 +1068,8 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, v= oid *fdt) _FDT(fdt_setprop(fdt, rtas, "ibm,lrdr-capacity", lrdr_capacity, sizeof(lrdr_capacity))); =20 + spapr_dt_rtas_fadump(spapr, fdt, rtas); + spapr_dt_rtas_tokens(fdt, rtas); } =20 --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741894026; cv=none; d=zohomail.com; s=zohoarc; b=h1quEvzQbnnq5yHYqBkoWxvn2u4Hj+pQ23VIWgYaw7hgUlKBEjhgJ6z3WK1yxTZNN3U6tokaXQgJD+TLUxoRKR+ZDXk5UbZ7udH40hEMzDm+zj5yNLA10LG48xqwInCKSVQ+RkfSlCjMgSsJjXFyVYt9awXxXP9vAhELh1V5o5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741894026; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zMbubV+AFg/iyDz3C1gVdjVYZ1rRLZ3u3aY3HiOZSNY=; b=L84F2i7fr4csmHEKIwy//pJqnZxAw49VLKn6m/PE9DSQeMg0IIJQKRhxpY53nAF1t6J3cRuE2Tnf97Fk7UKA+56D77hINcPHWaveatqc46+wIYehVH7MJUiKLcILaUoOqGUR64r/M1/srXVNfB75NRGe+X+oEiRIdMN2GFYQKIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741894026065637.1390915268329; Thu, 13 Mar 2025 12:27:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAT-00030Q-9f; Thu, 13 Mar 2025 15:24:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoAD-0002uL-0H; Thu, 13 Mar 2025 15:24:21 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoAB-0000uS-9T; Thu, 13 Mar 2025 15:24:16 -0400 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo5TK021764; Thu, 13 Mar 2025 19:24:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bhp5dvwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:13 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJNsnc013378; Thu, 13 Mar 2025 19:24:13 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bhp5dvws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:13 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DIpU9F026029; Thu, 13 Mar 2025 19:24:12 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 45atspkg2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:12 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJO8nG26346198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:24:08 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B852C20043; Thu, 13 Mar 2025 19:24:08 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F9AF20040; Thu, 13 Mar 2025 19:24:06 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:24:06 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=zMbubV+AFg/iyDz3C 1gVdjVYZ1rRLZ3u3aY3HiOZSNY=; b=sr/UqrM6cRFsSxHP0hzCAUnJC/599R7E6 fEcpv3yG9HHtWOTMOBhviu4QdrZbFlm+PrO5SlK2ap4sL2WqXy+LYIZrX+zR/HBN SSacgTNPjMzsBj3dRQv0aSNGd2i1uEPlXOaX1rqr+rragrdjFDc76x9cQig/5XLz EQywL4ZPA2acpnXQVtxHoKKwW52hwvkWnqDRGCtUMfArklwo4y6ZT7A47wFhgCvD Z+6za2BMtbeUMAVTqQg0Y6/05Pz//ZE5PzLOFub7qzOLrcpGu3A8hAqz6CrPeXIy Lkvv9ybgQtFxWQjFU/rTsgcFSBJzWHftQDn5zIV0PuHJO4Adq0UzA== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 7/8] hw/ppc: Enable fadump for PSeries Date: Fri, 14 Mar 2025 00:53:40 +0530 Message-ID: <20250313192341.132171-8-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PmgcIzXVHug428Mk0o8zVo0lJLwVgrSr X-Proofpoint-ORIG-GUID: hkWUTBu7gztzD6vo6J10FxjZyek6b0aB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 impostorscore=0 adultscore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.158.5; envelope-from=adityag@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741894028202019100 Content-Type: text/plain; charset="utf-8" With all support in place for preserving memory regions, enable fadump by exporting the "ibm,kernel-dump" property in the device tree, representing the fadump dump information, in case of a crash. Currently "ibm,configure-kernel-dump" RTAS call is already registered, which tells the kernel that the platform (QEMU) supports fadump. Now, in case of a crash, if fadump was registered, we also pass "ibm,kernel-dump" in device tree, which tells the kernel that the fadump dump is active. Pass "fadump=3Don" to enable Linux to use firmware assisted dump. Logs of a linux boot with firmware assisted dump: $ ./build/qemu-system-ppc64 -M pseries,x-vof=3Don --cpu power10 --smp 4= -m 4G -kernel some-vmlinux -initrd some-initrd -append "debug fadump=3Don = crashkernel=3D1G" -nographic [ 0.000000] fadump: Reserved 1024MB of memory at 0x00000040000000 (S= ystem RAM: 4096MB) [ 0.000000] fadump: Initialized 0x40000000 bytes cma area at 1024MB = from 0x400102a8 bytes of memory reserved for firmware-assisted dump ... [ 1.084686] rtas fadump: Registration is successful! ... # cat /sys/kernel/debug/powerpc/fadump_region CPU :[0x00000040000000-0x000000400013df] 0x13e0 bytes, Dumped: 0x0 HPTE:[0x000000400013e0-0x000000400013df] 0x0 bytes, Dumped: 0x0 DUMP: Src: 0x00000000000000, Dest: 0x00000040010000, Size: 0x40000000, = Dumped: 0x0 bytes [0x0000000921a000-0x0000000921a7ff]: cmdline append: '' # echo c > /proc/sysrq-trigger The fadump boot after crash: [ 0.000000] rtas fadump: Firmware-assisted dump is active. [ 0.000000] fadump: Updated cmdline: debug fadump=3Don crashkernel= =3D1G [ 0.000000] fadump: Firmware-assisted dump is active. [ 0.000000] fadump: Reserving 3072MB of memory at 0x00000040000000 f= or preserving crash data .... # file /proc/vmcore /proc/vmcore: ELF 64-bit LSB core file, 64-bit PowerPC or cisco 7500, O= penPOWER ELF V2 ABI, version 1 (SYSV), SVR4-style Analysing the vmcore with crash-utility: KERNEL: vmlinux-6.14-rc2 DUMPFILE: vmcore-fc92fb373aa0 CPUS: 4 DATE: Wed Mar 12 23:39:23 CDT 2025 UPTIME: 00:00:22 LOAD AVERAGE: 0.13, 0.03, 0.01 TASKS: 95 NODENAME: buildroot RELEASE: 6.12.0-rc4+ VERSION: #1 SMP Fri Jan 3 00:15:17 IST 2025 MACHINE: ppc64le (1000 Mhz) MEMORY: 4 GB PANIC: "Kernel panic - not syncing: sysrq triggered crash" PID: 269 COMMAND: "sh" TASK: c00000000a050b00 [THREAD_INFO: c00000000a050b00] CPU: 0 STATE: TASK_RUNNING (PANIC) Signed-off-by: Aditya Gupta --- hw/ppc/spapr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index dac9e4b3edaa..f6e666ad4344 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -905,6 +905,8 @@ static void spapr_dt_rtas_fadump(SpaprMachineState *spa= pr, void *fdt, int rtas) MachineState *ms =3D MACHINE(spapr); MachineClass *mc =3D MACHINE_GET_CLASS(ms); FadumpMemStruct *fdm =3D &spapr->registered_fdm; + uint16_t dump_status_flag; + bool is_next_boot_fadump; =20 uint32_t max_possible_cpus =3D mc->possible_cpu_arch_ids(ms)->len; uint64_t fadump_cpu_state_size =3D 0; @@ -954,6 +956,18 @@ static void spapr_dt_rtas_fadump(SpaprMachineState *sp= apr, void *fdt, int rtas) fadump_versions, sizeof(fadump_versions)))); _FDT((fdt_setprop(fdt, rtas, "ibm,configure-kernel-dump-sizes", fadump_rgn_sizes, sizeof(fadump_rgn_sizes)))); + + dump_status_flag =3D be16_to_cpu(fdm->header.dump_status_flag); + is_next_boot_fadump =3D + (dump_status_flag & FADUMP_STATUS_DUMP_TRIGGERED) !=3D 0; + if (is_next_boot_fadump) { + uint64_t fdm_size =3D + sizeof(struct FadumpSectionHeader) + + (be16_to_cpu(fdm->header.dump_num_sections) * + sizeof(struct FadumpSection)); + + _FDT((fdt_setprop(fdt, rtas, "ibm,kernel-dump", fdm, fdm_size))); + } } =20 static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) --=20 2.48.1 From nobody Sun Nov 16 07:38:05 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1741894004; cv=none; d=zohomail.com; s=zohoarc; b=hpNALxGMbu/WsMFPT3pN7nss+5agNqQH3x5aoB2TQTlH5+LS5fEUPdJr+YQtGVqwwNLywTRr1bfRirtUtFz5A6JO11sdUz0AcMh8GrT6hG7U9SOBmRlpehv0KPiIcaXKBghUcFyKK5JmSAJJxpNfiEMDNRAo6qTq5w1UbuLasxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741894004; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6Lk6E4QrCJqWLVjFcqXp1gtIkShuK1Z/fygXq9agrI0=; b=RBiE46j/aLBW9duXnbB/m5qX+DV8eRk6xZ18TNRyWxnsgqR2S1WbyrDWRP8Re26BWktIwKsq8pF1aKeiAgQP9iB51ufp8FEtxIqR6lA5LGmfbx64o3u9p0CS6wtuwDQ+lYrDreDRvAsILRjbIyTb95Rs1d26o8UynY8sX7TLcdE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741894004573976.113991674592; Thu, 13 Mar 2025 12:26:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsoAP-0002xe-PK; Thu, 13 Mar 2025 15:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoAI-0002v8-R0; Thu, 13 Mar 2025 15:24:23 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tsoAG-0000uo-CP; Thu, 13 Mar 2025 15:24:22 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52DGo6Jc030511; Thu, 13 Mar 2025 19:24:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hnm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:17 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 52DJJvnR014484; Thu, 13 Mar 2025 19:24:17 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 45bqr94hnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:16 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 52DJ2Skc012246; Thu, 13 Mar 2025 19:24:15 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 45atsrkf3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Mar 2025 19:24:15 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 52DJOBvF47186238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Mar 2025 19:24:11 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACD3120043; Thu, 13 Mar 2025 19:24:11 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DEEA20040; Thu, 13 Mar 2025 19:24:09 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.ibm.com (unknown [9.124.223.53]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 13 Mar 2025 19:24:08 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=6Lk6E4QrCJqWLVjFc qXp1gtIkShuK1Z/fygXq9agrI0=; b=k7RyIPvEpMb7Zc3F5NcqSSc4y6r4DvG3W 7Oi2LdMk2Mg70jeY+LigYVIk8oFeuBtCZe8scJ4BvC3YWRyBDl3I8qS2GGmArU/x O5s3BML2JgTJedKHLdN/y6zjBBb5hk5tPC9vtKxHZScLhS86BLc1UaMldsp1UxnS hv6QS5u6aJbrXGByw67O9vmbHF7tMeEB+VhiiC3UWSJVaruaQ50CkJfYranGX/sA 52s/ODM0womASoX1/ONBCjESGKU9QRpv4S9LThQxSKLYCMhJi1NiQxIl/smmL2kp CraNMS/XPlY+Ogf6O9f5+E1PEoDUg9Rg80R1/igiRMQ2QKf10HMyA== From: Aditya Gupta To: Cc: , Nicholas Piggin , Daniel Henrique Barboza , Harsh Prateek Bora , Sourabh Jain , Mahesh J Salgaonkar , Hari Bathini Subject: [PATCH v2 8/8] tests/functional: Add test for fadump in PSeries Date: Fri, 14 Mar 2025 00:53:41 +0530 Message-ID: <20250313192341.132171-9-adityag@linux.ibm.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250313192341.132171-1-adityag@linux.ibm.com> References: <20250313192341.132171-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jOnoWJ25U1Ivn7cxApwXweilojbfmSqa X-Proofpoint-ORIG-GUID: suXzryoroDiYCXNTQSmkruAmOnoxyAme X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-13_08,2025-03-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 adultscore=0 clxscore=1015 suspectscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503130145 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=148.163.156.1; envelope-from=adityag@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1741894007636019100 Content-Type: text/plain; charset="utf-8" Add testcases for testing fadump with PSeries and PSeries+KVM combinations It tests if fadump is successfully detected and registered in the first kernel boot. Then crashes the kernel, and verifies whether we have a /proc/vmcore in the 2nd boot Also introduce 'wait_for_regex_console_pattern' to check for cases where there is a single success message, but can have multiple failure messages. This is particularly useful for cases such as fadump, where the success message is "Reserved 1024MB ... successfully" But at the same point, it can fail with multiple errors such as "Not supported" or "Allocation failed" 'wait_for_regex_console_pattern' also has a timeout, for cases when we know the success/failure should appear in a short amount of time, instead of waiting for the much longer test timeout, such as kernels with support of fadump will print the success/failure in earlyboot of the kernel, while kernel without support of fadump won't print anything for long time, and without a timeout the testcase keeps waiting till longer test timeout Signed-off-by: Aditya Gupta --- PowerNV also can be tested with this, will enable PowerNV tests after MPIPL patches go in --- --- tests/functional/meson.build | 2 + tests/functional/qemu_test/linuxkernel.py | 59 +++++++ tests/functional/test_ppc64_fadump.py | 185 ++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100755 tests/functional/test_ppc64_fadump.py diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 74f8414a0c74..465882aac972 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -46,6 +46,7 @@ test_timeouts =3D { 'ppc64_powernv' : 480, 'ppc64_pseries' : 480, 'ppc64_replay' : 210, + 'ppc64_fadump' : 480, 'ppc64_tuxrun' : 420, 'ppc64_mac99' : 120, 'riscv64_tuxrun' : 120, @@ -230,6 +231,7 @@ tests_ppc64_system_thorough =3D [ 'ppc64_replay', 'ppc64_tuxrun', 'ppc64_mac99', + 'ppc64_fadump', ] =20 tests_riscv32_system_quick =3D [ diff --git a/tests/functional/qemu_test/linuxkernel.py b/tests/functional/q= emu_test/linuxkernel.py index 2aca0ee3cd03..c4767527daf6 100644 --- a/tests/functional/qemu_test/linuxkernel.py +++ b/tests/functional/qemu_test/linuxkernel.py @@ -5,6 +5,9 @@ =20 import hashlib import urllib.request +import logging +import re +import time =20 from .cmd import wait_for_console_pattern, exec_command_and_wait_for_patte= rn from .testcase import QemuSystemTest @@ -19,6 +22,62 @@ def wait_for_console_pattern(self, success_message, vm= =3DNone): failure_message=3D'Kernel panic - not syn= cing', vm=3Dvm) =20 + def wait_for_regex_console_pattern(self, success_pattern, + failure_pattern=3DNone, + timeout=3DNone): + """ + Similar to 'wait_for_console_pattern', but supports regex patterns, + hence multiple failure/success patterns can be detected at a time. + + Args: + success_pattern (str | re.Pattern): A regex pattern that indic= ates + a successful event. If found, the method exits normally. + failure_pattern (str | re.Pattern, optional): A regex pattern = that + indicates a failure event. If found, the test fails + timeout (int, optional): The maximum time (in seconds) to wait= for + a match. + If exceeded, the test fails. + """ + + console =3D self.vm.console_file + console_logger =3D logging.getLogger('console') + + self.log.debug( + f"Console interaction: success_msg=3D'{success_pattern}' " + + f"failure_msg=3D'{failure_pattern}' timeout=3D'{timeout}s'") + + # Only consume console output if waiting for something + if success_pattern is None and failure_pattern is None: + return + + start_time =3D time.time() + + while time.time() - start_time < timeout: + try: + msg =3D console.readline().decode().strip() + except UnicodeDecodeError: + msg =3D None + if not msg: + continue + console_logger.debug(msg) + if success_pattern is None or re.search(success_pattern, msg): + break + if failure_pattern: + # Find the matching error to print in log + match =3D re.search(failure_pattern, msg) + if not match: + continue + + console.close() + fail =3D 'Failure message found in console: "%s".' \ + ' Expected: "%s"' % \ + (match.group(), success_pattern) + self.fail(fail) + + if time.time() - start_time >=3D timeout: + fail =3D f"Timeout ({timeout}s) while trying to search pattern" + self.fail(fail) + def launch_kernel(self, kernel, initrd=3DNone, dtb=3DNone, console_ind= ex=3D0, wait_for=3DNone): self.vm.set_console(console_index=3Dconsole_index) diff --git a/tests/functional/test_ppc64_fadump.py b/tests/functional/test_= ppc64_fadump.py new file mode 100755 index 000000000000..3d6d3734e243 --- /dev/null +++ b/tests/functional/test_ppc64_fadump.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python3 + +import logging +import platform +import os +from unittest import skip, skipUnless +from qemu_test import Asset +from qemu_test import wait_for_console_pattern +from qemu_test import LinuxKernelTest +from qemu_test import exec_command, exec_command_and_wait_for_pattern + +class QEMUFadump(LinuxKernelTest): + """ + Functional test to verify Fadump is working in following scenarios: + + 1. test_fadump_pseries: PSeries + 2. test_fadump_pseries_kvm: PSeries + KVM + """ + + timeout =3D 90 + KERNEL_COMMON_COMMAND_LINE =3D 'console=3Dhvc0 fadump=3Don ' + msg_panic =3D 'Kernel panic - not syncing' + msg_not_supported =3D 'Firmware-Assisted Dump is not supported on this= hardware' + msg_registered_success =3D '' + msg_registered_failed =3D '' + msg_dump_active =3D '' + + ASSET_EPAPR_KERNEL =3D Asset( + ('https://github.com/open-power/op-build/releases/download/v2.7/' + 'zImage.epapr'), + '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd') + + ASSET_VMLINUZ_KERNEL =3D Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora-secondary/' + 'releases/39/Everything/ppc64le/os/ppc/ppc64/vmlinuz'), + ('81e5541d243b50c8f9568906c6918dda22239744d637bb9a7b22d23c3d661226' + '8d5302beb2ca5c06f93bdbc9736c414ef5120756c8bf496ff488ad07d116d67f= ') + ) + + ASSET_FEDORA_INITRD =3D Asset( + ('https://archives.fedoraproject.org/pub/archive/fedora-secondary/' + 'releases/39/Everything/ppc64le/os/ppc/ppc64/initrd.img'), + 'e7f24b44cb2aaa67d30e551db6ac8d29cc57c934b158dabca6b7f885f2cfdd9b') + + def do_test_fadump(self, is_kvm=3DFalse, is_powernv=3DFalse): + """ + Helper Function for Fadump tests below + + It boots the VM with fadump enabled, checks if fadump is correctly + registered. + Then crashes the system causing a QEMU_SYSTEM_RESET, after which + dump should be available in the kernel. + Finally it checks the filesize of the exported /proc/vmcore in 2nd + kernel to verify it's same as the VM's memory size + """ + if not is_kvm: + self.require_accelerator("tcg") + + if is_powernv: + self.set_machine("powernv10") + else: + # SLOF takes upto >20s in startup time, use VOF + self.set_machine("pseries") + self.vm.add_args("-machine", "x-vof=3Don") + self.vm.add_args("-m", "6G") + + self.vm.set_console() + + kernel_path =3D None + + if is_powernv: + kernel_path =3D self.ASSET_EPAPR_KERNEL.fetch() + else: + kernel_path =3D self.ASSET_VMLINUZ_KERNEL.fetch() + + initrd_path =3D self.ASSET_FEDORA_INITRD.fetch() + + self.vm.add_args('-kernel', kernel_path) + self.vm.add_args('-initrd', initrd_path) + self.vm.add_args('-append', "fadump=3Don"\ + " -nodefaults -serial mon:stdio crashkernel=3D2G"\ + " rdinit=3D/bin/sh ") + + self.vm.launch() + + # If kernel detects fadump support, and "fadump=3Don" is in command + # line which we add above, it will print something like: + # + # fadump: Reserved 1024MB of memory at 0x00000040000000 ... + # + # Else, if the kernel doesn't detect fadump support, it prints: + # + # fadump: Firmware-Assisted Dump is not supported on this hard= ware + # + # Timeout after 10s if kernel doesn't print any fadump logs, this + # can happen due to fadump being disabled in the kernel + self.wait_for_regex_console_pattern( + success_pattern=3D"fadump: Reserved ", + failure_pattern=3Dr"fadump: (Firmware-Assisted Dump is not"\ + " supported on this hardware|Failed to find memory chunk for"\ + " reservation!)", + timeout=3D10 + ) + + # Ensure fadump is registered successfully, if registration + # succeeds, we get a log from rtas fadump: + # + # rtas fadump: Registration is successful! + self.wait_for_console_pattern( + "rtas fadump: Registration is successful!" + ) + + # Wait for the shell + self.wait_for_console_pattern("#") + + # Mount /proc since not available in the initrd used + exec_command(self, command=3D"mount -t proc proc /proc") + + # Crash the kernel + exec_command(self, command=3D"echo c > /proc/sysrq-trigger") + + # Check for the kernel panic message, setting timeout to 10s as it + # should occur almost immediately after previous echo c + self.wait_for_regex_console_pattern( + success_pattern=3D"Kernel panic - not syncing: sysrq" \ + " triggered crash", + timeout=3D10 + ) + + # Check if fadump is active + # If the kernel shows that fadump is active, that implies it's a + # crashkernel boot + # Else if the kernel shows "fadump: Reserved ..." then it's + # treating this as the first kernel boot, this is likely the case + # that qemu didn't pass the 'ibm,kernel-dump' device tree node + wait_for_console_pattern( + test=3Dself, + success_message=3D"rtas fadump: Firmware-assisted dump is acti= ve", + failure_message=3D"fadump: Reserved " + ) + + # In a successful fadump boot, we get these logs: + # + # [ 0.000000] fadump: Firmware-assisted dump is active. + # [ 0.000000] fadump: Reserving <>MB of memory at <> for preser= ving crash data + # + # Check if these logs are present in the fadump boot + self.wait_for_console_pattern("preserving crash data") + + # Wait for prompt + self.wait_for_console_pattern("sh-5.2#") + + # Mount /proc since not available in the initrd used + exec_command_and_wait_for_pattern(self, + command=3D"mount -t proc proc /proc", + success_message=3D"#" + ) + + # Check if vmcore exists + exec_command_and_wait_for_pattern(self, + command=3D"stat /proc/vmcore", + success_message=3D"File: /proc/vmcore", + failure_message=3D"No such file or directory" + ) + + def test_fadump_pseries(self): + return self.do_test_fadump(is_kvm=3DFalse, is_powernv=3DFalse) + + @skip("PowerNV Fadump not supported yet") + def test_fadump_powernv(self): + return + + @skipUnless(platform.machine().startswith("ppc64"), + "KVM tests require the same host and guest architecture") + def test_fadump_pseries_kvm(self): + """ + Test Fadump in PSeries with KVM accel + """ + self.do_test_fadump(is_kvm=3DTrue, is_powernv=3DFalse) + +if __name__ =3D=3D '__main__': + if os.getenv("DEBUG"): + logging.basicConfig(level=3Dlogging.DEBUG) + + QEMUFadump.main() --=20 2.48.1