From nobody Sat Apr 11 21:28:51 2026 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=1773146867; cv=none; d=zohomail.com; s=zohoarc; b=CA/Tad+y83Jp7+AgY07y+UmY/9UuksqCiQWEYhD510q+lFpwNVCAok3g0T/DifGatewlkfYDT1SRwk4+D1+fvGipTQoy6g0RZnA4gla+fW+El+bPSpBP/LID5jyJKyLy0O8HqWFUOcXMgS0cbn3kxW8ZQYScRbmUJnnnSR6Ef8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773146867; 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=05yWi1TQoGUqbpd6Rj7c/SZZDynmc7ZdELkxaSTnWCU=; b=BgbsFviiMBtcvMs+FNaVDqlDXIIgexfgaq74pCu6X3/PlxiaUIhhucbcndIRdtHksiLBLFFJ+OH+CKFsxCHdr2RjQruE02/7s3udAbgNOUwGPhH5TVwrA7qqtAuFFEtd+NGxchQeFh1lMTAcQAbcS/pI6UmQuhygMsUQVkK6Wr0= 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 1773146867417136.47752141044475; Tue, 10 Mar 2026 05:47:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vzwUk-0005BM-Tw; Tue, 10 Mar 2026 08:47: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 1vzwU0-00051e-8m; Tue, 10 Mar 2026 08:46:50 -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 1vzwTy-00038a-FH; Tue, 10 Mar 2026 08:46:44 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62AAThT91554633; Tue, 10 Mar 2026 12:46:41 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4crd1mjg7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Mar 2026 12:46:40 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62AB61Li015653; Tue, 10 Mar 2026 12:46:40 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4crybn93fv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Mar 2026 12:46:40 +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 62ACkaRI25231622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Mar 2026 12:46:36 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14B9820040; Tue, 10 Mar 2026 12:46:36 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA7712004B; Tue, 10 Mar 2026 12:46:33 +0000 (GMT) Received: from li-3c92a0cc-27cf-11b2-a85c-b804d9ca68fa.in.ibm.com (unknown [9.109.199.210]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Mar 2026 12:46:33 +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=05yWi1TQoGUqbpd6R j7c/SZZDynmc7ZdELkxaSTnWCU=; b=nO2ZT6+T1ylIEOhMtZ9BHS52NcHrJM6Wr LtxsI77NFjxcg7tSvYNVdNDw7U7N7Inu8VtjGKV8nTI2L7qPOZCRXZRd4vod7QC2 kpS++VztN8cq1BmvpPzaq1RH8FBlrB0nk2PNo5WAHc3UpyB9rRf5qkpeXMFyyDco HQau1Aro4k3ZkoPXvi0TpwzSEN8cj+QPck7sk/IWwMI4ArZNiMhPnwrb2XLMXtAf IpzQkS8SliGA89FToWEiPO4ANuL/HftevzhgvBPZADl33xaHR/Yq4FUpkL/A02C4 XhyHRYs4guSlmiUFmsd86gG1eIUBP7GAOaHN2dsqkq8rBoQV3Lppw== From: Aditya Gupta To: Cc: , Hari Bathini , Sourabh Jain , Harsh Prateek Bora , Nicholas Piggin , Miles Glenn , Chinmay Rath , Shivang Upadhyay Subject: [PATCH v5 04/10] pnv/mpipl: Preserve memory regions as per MDST/MDDT tables Date: Tue, 10 Mar 2026 18:16:11 +0530 Message-ID: <20260310124619.3909045-5-adityag@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260310124619.3909045-1-adityag@linux.ibm.com> References: <20260310124619.3909045-1-adityag@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=ds3Wylg4 c=1 sm=1 tr=0 ts=69b012b1 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=uldKd1TX8WFnlnzwhmkA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzEwMDEwOSBTYWx0ZWRfX1fD6yIN1ja8d xWUsTdtdp/ayfDA1jZwb7cL9ZURWfbD+dZUFRS8yMeor0F9GrzKB9QY+Y/4+DS4HLhDKB/0w4mc bKGemZBPTS9aVVjDf4lf/eVFUbzzERUYLBH6q8RAVby2Msl3a5x5lGRB+0y6l1WSiSZgBluZKW9 kFW8Ro0xv/p4n8PRn+HNW1/Rk56Pf5LOG9p0Mmm0FylemCfZ7QbxgHv9YGSFvyoSL8OqR8gzDVZ q3/w2JWax6ia2nbiLLvii9NzoQR3qMnnCb4HuIXRvCk9fEsxiUOoN/3Up+F6IV0La9792gD+vNB H7rrtr3jfeRK2JmahXp79WuuZVrd8vXxCFHgPN0D06K2OMX023cZp4JP2nzpmnhlejvZy+O1CAN pl74Wv6J+5WkZHB4s5oJIp1YpZk/vKvYE82CQVuomr8sbakXHaObEW1wlA2bzR2vn4ataElKbDw 8L7xz2Ow8mGVrv5AspA== X-Proofpoint-GUID: 8elbdCplVBn6vrFEd4EDzsG98b-VywE_ X-Proofpoint-ORIG-GUID: y1DsprN-FtqoiwsWjHbmfeI29DaFnnn7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-10_02,2026-03-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 clxscore=1015 impostorscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603100109 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: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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: 1773146869306158500 Content-Type: text/plain; charset="utf-8" Implement copying of memory region, as mentioned by MDST and MDDT tables. Copy the memory regions from source to destination in chunks of 32MB Note, qemu can fail preserving a particular entry due to any reason, such as: * region length mis-matching in MDST & MDDT * failed copy due to access/decode/etc memory issues HDAT doesn't specify any field in MDRT to notify host about such errors. Though HDAT section "15.3.1.3 Memory Dump Results Table (MDRT)" says: The Memory Dump Results Table is a list of the memory ranges that have been included in the dump Based on above statement, it looks like MDRT should include only those regions which are successfully captured in the dump, hence, regions which qemu fails to dump, just get skipped, and will not have a corresponding entry in MDRT Reviewed-by: Hari Bathini Signed-off-by: Aditya Gupta --- hw/ppc/pnv_mpipl.c | 162 +++++++++++++++++++++++++++++++++++++ include/hw/ppc/pnv_mpipl.h | 86 ++++++++++++++++++++ 2 files changed, 248 insertions(+) diff --git a/hw/ppc/pnv_mpipl.c b/hw/ppc/pnv_mpipl.c index d8c9b7a428b7..cef1fe2c4056 100644 --- a/hw/ppc/pnv_mpipl.c +++ b/hw/ppc/pnv_mpipl.c @@ -5,12 +5,174 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/units.h" +#include "system/address-spaces.h" #include "system/runstate.h" #include "hw/ppc/pnv.h" #include "hw/ppc/pnv_mpipl.h" +#include + +#define MDST_TABLE_RELOCATED \ + (pnv->mpipl_state.skiboot_base + MDST_TABLE_OFF) +#define MDDT_TABLE_RELOCATED \ + (pnv->mpipl_state.skiboot_base + MDDT_TABLE_OFF) + +/* + * Preserve the memory regions as pointed by MDST table + * + * During this, the memory region pointed by entries in MDST, are 'copied' + * as it is to the memory region pointed by corresponding entry in MDDT + * + * Notes: All reads should consider data coming from skiboot as big-endian, + * and data written should also be in big-endian + */ +static bool pnv_mpipl_preserve_mem(PnvMachineState *pnv) +{ + g_autofree MdstTableEntry *mdst =3D g_malloc(MDST_TABLE_SIZE); + g_autofree MddtTableEntry *mddt =3D g_malloc(MDDT_TABLE_SIZE); + g_autofree MdrtTableEntry *mdrt =3D g_malloc0(MDRT_TABLE_SIZE); + AddressSpace *default_as =3D &address_space_memory; + MemTxResult io_result; + MemTxAttrs attrs; + uint64_t src_addr, dest_addr; + uint32_t data_len; + uint64_t num_chunks, chunk_id =3D 0; + int mdrt_idx =3D 0; + + /* Mark the memory transactions as privileged memory access */ + attrs.user =3D 0; + attrs.memory =3D 1; + + if (pnv->mpipl_state.mdrt_table) { + /* + * MDRT table allocated from some past crash, free the memory to + * prevent memory leak + */ + g_free(pnv->mpipl_state.mdrt_table); + pnv->mpipl_state.num_mdrt_entries =3D 0; + } + + io_result =3D address_space_read(default_as, MDST_TABLE_RELOCATED, att= rs, + mdst, MDST_TABLE_SIZE); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPIPL: Failed to read MDST table at: 0x" TARGET_FMT_lx "\n", + MDST_TABLE_RELOCATED); + + return false; + } + + io_result =3D address_space_read(default_as, MDDT_TABLE_RELOCATED, att= rs, + mddt, MDDT_TABLE_SIZE); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPIPL: Failed to read MDDT table at: 0x" TARGET_FMT_lx "\n", + MDDT_TABLE_RELOCATED); + + return false; + } + + /* Try to read all entries */ + for (int i =3D 0; i < MDST_MAX_ENTRIES; ++i) { + g_autofree uint8_t *copy_buffer =3D NULL; + bool is_copy_failed =3D false; + + /* Considering entry with address and size as 0, as end of table */ + if ((mdst[i].addr =3D=3D 0) && (mdst[i].size =3D=3D 0)) { + break; + } + + if (mdst[i].size !=3D mddt[i].size) { + qemu_log_mask(LOG_TRACE, + "Warning: Invalid entry, size mismatch in MDST & MDDT\= n"); + continue; + } + + if (mdst[i].data_region !=3D mddt[i].data_region) { + qemu_log_mask(LOG_TRACE, + "Warning: Invalid entry, region mismatch in MDST & MDD= T\n"); + continue; + } + + src_addr =3D be64_to_cpu(mdst[i].addr) & ~HRMOR_BIT; + dest_addr =3D be64_to_cpu(mddt[i].addr) & ~HRMOR_BIT; + data_len =3D be32_to_cpu(mddt[i].size); + +#define COPY_CHUNK_SIZE ((size_t)(32 * MiB)) + copy_buffer =3D g_try_malloc(COPY_CHUNK_SIZE); + if (copy_buffer =3D=3D NULL) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPIPL: Failed allocating memory (size: %zu) for copying" + " reserved memory regions\n", COPY_CHUNK_SIZE); + is_copy_failed =3D true; + continue; + } + + chunk_id =3D 0; + num_chunks =3D ceil((data_len * 1.0f) / COPY_CHUNK_SIZE); + while (chunk_id < num_chunks) { + /* Take minimum of bytes left to copy, and chunk size */ + uint64_t copy_len =3D MIN( + data_len - (chunk_id * COPY_CHUNK_SIZE), + COPY_CHUNK_SIZE + ); + + /* Copy the source region to destination */ + io_result =3D address_space_read(default_as, src_addr, attrs, + copy_buffer, copy_len); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPIPL: Failed to read region at: 0x%" PRIx64 "\n", + src_addr); + is_copy_failed =3D true; + break; + } + + io_result =3D address_space_write(default_as, dest_addr, attrs, + copy_buffer, copy_len); + if (io_result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "MPIPL: Failed to write region at: 0x%" PRIx64 "\n", + dest_addr); + is_copy_failed =3D true; + break; + } + + src_addr +=3D COPY_CHUNK_SIZE; + dest_addr +=3D COPY_CHUNK_SIZE; + ++chunk_id; + } +#undef COPY_CHUNK_SIZE + + if (is_copy_failed) { + /* + * HDAT doesn't specify an error code in MDRT for failed copy, + * and doesn't specify how this is to be handled + * Hence just skip adding an entry in MDRT, as done for size + * mismatch or other inconsistency between MDST/MDDT + */ + continue; + } + + /* Populate entry in MDRT table if preserving successful */ + mdrt[mdrt_idx].src_addr =3D cpu_to_be64(src_addr); + mdrt[mdrt_idx].dest_addr =3D cpu_to_be64(dest_addr); + mdrt[mdrt_idx].size =3D cpu_to_be32(data_len); + mdrt[mdrt_idx].data_region =3D mdst[i].data_region; + ++mdrt_idx; + } + + pnv->mpipl_state.mdrt_table =3D g_steal_pointer(&mdrt); + pnv->mpipl_state.num_mdrt_entries =3D mdrt_idx; + + return true; +} =20 void do_mpipl_preserve(PnvMachineState *pnv) { + pnv_mpipl_preserve_mem(pnv); + /* Mark next boot as Memory-preserving boot */ pnv->mpipl_state.is_next_boot_mpipl =3D true; =20 diff --git a/include/hw/ppc/pnv_mpipl.h b/include/hw/ppc/pnv_mpipl.h index 60d6ede48209..e0518ef2e12e 100644 --- a/include/hw/ppc/pnv_mpipl.h +++ b/include/hw/ppc/pnv_mpipl.h @@ -10,13 +10,99 @@ #include "qemu/osdep.h" #include "exec/hwaddr.h" =20 +#include + +typedef struct MdstTableEntry MdstTableEntry; +typedef struct MdrtTableEntry MdrtTableEntry; typedef struct MpiplPreservedState MpiplPreservedState; =20 +/* + * Following offsets are copied from skiboot source code. + * These need to be updated if this changes in a future skiboot version + */ +/* Use 768 bytes for SPIRAH */ +#define SPIRAH_OFF 0x00010000 +#define SPIRAH_SIZE 0x300 + +/* Use 256 bytes for processor dump area */ +#define PROC_DUMP_AREA_OFF (SPIRAH_OFF + SPIRAH_SIZE) +#define PROC_DUMP_AREA_SIZE 0x100 + +#define PROCIN_OFF (PROC_DUMP_AREA_OFF + PROC_DUMP_AREA_SIZE) +#define PROCIN_SIZE 0x800 + +/* Offsets of MDST and MDDT tables from skiboot base */ +#define MDST_TABLE_OFF (PROCIN_OFF + PROCIN_SIZE) +#define MDST_TABLE_SIZE 0x400 + +#define MDDT_TABLE_OFF (MDST_TABLE_OFF + MDST_TABLE_SIZE) +#define MDDT_TABLE_SIZE 0x400 +/* + * Offset of the dump result table MDRT. Hostboot will write to this + * memory after moving memory content from source to destination memory. + */ +#define MDRT_TABLE_OFF 0x01c00000 +#define MDRT_TABLE_SIZE 0x00008000 + +/* HRMOR_BIT copied from skiboot */ +#define HRMOR_BIT (1ull << 63) + +#define __packed __attribute__((packed)) + +/* + * Memory Dump Source Table (MDST) + * + * Format of this table is same as Memory Dump Source Table defined in HDAT + */ +struct MdstTableEntry { + uint64_t addr; + uint8_t data_region; + uint8_t dump_type; + uint16_t reserved; + uint32_t size; +} __packed; + +/* Memory dump destination table (MDDT) has same structure as MDST */ +typedef MdstTableEntry MddtTableEntry; + +/* + * Memory dump result table (MDRT) + * + * List of the memory ranges that have been included in the dump. This tab= le is + * filled by hostboot and passed to OPAL on second boot. OPAL/payload will= use + * this table to extract the dump. + * + * Note: This structure differs from HDAT, but matches the structure + * skiboot uses + */ +struct MdrtTableEntry { + uint64_t src_addr; + uint64_t dest_addr; + uint8_t data_region; + uint8_t dump_type; /* unused */ + uint16_t reserved; /* unused */ + uint32_t size; + uint64_t padding; /* unused */ +} __packed; + +/* Maximum length of mdst/mddt/mdrt tables */ +#define MDST_MAX_ENTRIES (MDST_TABLE_SIZE / sizeof(MdstTableEntry)) +#define MDDT_MAX_ENTRIES (MDDT_TABLE_SIZE / sizeof(MddtTableEntry)) +#define MDRT_MAX_ENTRIES (MDRT_TABLE_SIZE / sizeof(MdrtTableEntry)) + +static_assert(MDST_MAX_ENTRIES =3D=3D MDDT_MAX_ENTRIES, + "Maximum entries in MDDT must match MDST"); +static_assert(MDRT_MAX_ENTRIES >=3D MDST_MAX_ENTRIES, + "MDRT should support atleast having number of entries as in MDST"); + /* Preserved state to be saved in PnvMachineState */ struct MpiplPreservedState { /* skiboot_base will be valid only after OPAL sends relocated base to = SBE */ hwaddr skiboot_base; bool is_next_boot_mpipl; + + MdrtTableEntry *mdrt_table; + uint32_t num_mdrt_entries; }; =20 #endif --=20 2.53.0