From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04973C678D4 for ; Mon, 6 Mar 2023 16:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbjCFQZm (ORCPT ); Mon, 6 Mar 2023 11:25:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbjCFQZY (ORCPT ); Mon, 6 Mar 2023 11:25:24 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D2046A4A for ; Mon, 6 Mar 2023 08:24:11 -0800 (PST) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326CxGKT013918; Mon, 6 Mar 2023 16:22:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=0sBOBhpEoQMqxX3CYrsQSHX/nxiAqsT/1UeBSsRmoY4=; b=DKwkiofYwMMGBDgGZLytpLBLwsrS9GkaUaLp9AXiEl9Qi4MlLbdYIaqZ+gSTXqp0kuz4 wo4k4DTBtN6snqohXKh/ghIwoPXfnsQVqj6FsbdcIZbfCvGAfK44KLzMZM7b1xsvdtZ9 uwEXRpUcgcK/QuZQ3AH0MFuzw6BjiNiM8oGKXBnwNKYollTnvfdR+ypXopCuEYLIHLWz u8IZWdW6Rqm9jXobaLUZNQsrkQtC20LpWhKKQf6jeWh3wHH11NvXmoidu1192bBQo1fK 6o5D/xA2O3nOLkaRJdbvqz8HJ2Z8Hxe/rTqhAYlK04jBQ+oEA+dbZFEh6lopv4uSWDkH 4Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p416wka94-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:44 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326G4u6r026640; Mon, 6 Mar 2023 16:22:43 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u1dq61y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SVe6Wcnfu4QQsEWIKpxqNyKRhT3hggvu68LwH/7tbCaQfFPjLUXBhSubIwu+HGpfPScMHjiXFpvClZUiDnxtVBW6ewex7yv/U4n7lxZp1pZbIDApzCX8/3nVwcpKp9O+ng0hBQEPWqr5DViIo1gSUx4rgRTHe9NJzNjEm4uKuar47C3ma8f14CBxdUM3+fmFp8+LRt4MU4bHWQPTDq2Yr5jMTwU4/kGJ1SGYfa25QOaUUeEURYWbXMl+AGA64G8sQnXcE+yyX3ld8A+Hb83kJidEM/mH/CRvRNDSINXS7QRuVKhUNWej9YC5xnIuj4siHNIs1dFXw1dufEa7nlDqcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0sBOBhpEoQMqxX3CYrsQSHX/nxiAqsT/1UeBSsRmoY4=; b=aZAQ0YggQTQ6SfW28sh8dcRV/mD7iSA2OkfCRGP6GgRChq0Sktuq4M4MLbgCpguqk93t6jiSMf/vOmOciofUomvDA9c/arM7RJ38n4EuhzGi1wbjSx7DhcFgyI+/0Edx/x60B0Epef44Uh8OP3Eo293ouuIR/qm7zwbeAVAp32VXoENb6Hu82mIJ+dhhoDBdevFwhDPAv70Wy0JbZ+eOulFfVm1AhL5DzhSxRwc0mDB7etugF56aKjJoKT8S0AVgxHj1L1eHqBWm5WTsI+ceTfoDxTTUenfFZo0cdhVF/WhlZc3zCLcP9jli0t2YPe29Ws0O7zC3dvJQKl9Jd+fRYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0sBOBhpEoQMqxX3CYrsQSHX/nxiAqsT/1UeBSsRmoY4=; b=PaJ8mRWIohRSp9dpEh7wzwi4jE+c7S7ElpE2Gg8wEPNB1WpPS1mEUHqFiNoNCMGvc2Dqs6RGjtAkbf6Fq7mMIarGkge1p5r9Xo3gcciVefQSEnsYm6QW7rv2vvO0kv3dmee30H9MV6NTSI69L+CGcqB9+K9vE7Oe8YggG5azf4o= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:22:40 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:22:40 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 1/7] crash: move a few code bits to setup support of crash hotplug Date: Mon, 6 Mar 2023 11:22:22 -0500 Message-Id: <20230306162228.8277-2-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: CY5PR19CA0073.namprd19.prod.outlook.com (2603:10b6:930:69::18) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: f8b5abeb-cb1c-4d85-eace-08db1e5f01df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PU+2sWhK41jY98KoFRmTzCfli7uHXrctrBfXo1Fhxu5jjX2kCnmKRqy+pHiq7GG5ld2SmfMcSHC2l1TkEswIzPjUw4v59vIOYCPOYVPjYtI+hYBxPvYplhmIn7gmpW4XF2ss9J/q+WJIk6XbIG/76tN3DBO6PJPWfyenZHrZowapUbrg15NQvet5EAVk38gOAft6hx4irZ8k+w/7L9kbfd1MeC19u5VXCSUoVuqXJNTVmWL1ELwQ2Wno06v8FNP21XE8cMdG6grKerlIbNWvew9UjN1rmevxH0W04zOsgt/sR6CK0WsPLQHh3C+m7Ic3QeRdEGb8UhJySip5mFM9eeQDDdrL0sad+vJfRIOU4Wttg+TmmhL4nMxmjXu4PZIxBy1kTtFZdUfZqsBXlcJ6UNUv73bOB2VpPy3Cg93KUk/3z3mDZ26gEEEVI1Cy/g7HoDrHvmGAlPaSjngI2Vsv+vQl5DW21X5sccOzNYYgtdo6n9blndeQiPVaQ7DX2dnne4FSsKZcnNP6zWAkCzr6nLTWTJ6NdzEPvYAuSAa4DeKN4I3CUQMStb6fVJeAUFQVeDjAX3mzNNM3KYbO53EfpfKDReTH8LpWmKKiXau0OLpzZRHYXWPA8K6xkIYJGrB7Cy/6R2xaBD7dx02fpZV39A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(30864003)(38100700002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?56H34vb0m5R0v1v2bSftnOKok8kE9a9ywjjGePOwDvb9N4YPmqqvlxd3BgFN?= =?us-ascii?Q?Ho88S0tCsV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5F11JNJWGyY/9Db?= =?us-ascii?Q?CxysKKU7swVRNFiX/EaGSNThy9LNIeo0jFVJfhHNi1g3dxYt1SkpmEAnPgr1?= =?us-ascii?Q?yiVTmbZZoJJULa1rnKtZjH98jJGkQsVf70IbSyG4sorlfXyXptSzmFLYRvkQ?= =?us-ascii?Q?Ioqb9U3tC4RVQBVDQhHJwCHmOg7S5kKhjM8TCvmOncRWqFkDs4l+AcY5aICk?= =?us-ascii?Q?eg6X3kRdYL6tIYBM56GpWmihZXKL7Su24mHBwTi8/4xAxFGv3JEUvhRH4Llw?= =?us-ascii?Q?bR6vJfKGzHg1bpWmgEkklt5f+qxTqAJhxaOAqV0i5YUBdQzCY3gcPI702nmE?= =?us-ascii?Q?ib4M/S/qntdPgsgi1Aldi0alW98KDdtWo7x4kDcl3zBhOibNFqycLJz+kl8N?= =?us-ascii?Q?2ls7rfhtGzoAx7qdcDCp9NIPLkCM5FR5rFQTvY4v6Ov4S5gJevUCTkV1o077?= =?us-ascii?Q?YBv47h6rygmhifz0Kw0f5q95Ql2BOS47XxWO2HEyLwFK6d01I0JWqAP2kGSP?= =?us-ascii?Q?KDyNb+gR0i+8DpVO2QTFgmMZjM1+xHfKCr1lMScLo3v1ESsB/nlvDhvdSfWR?= =?us-ascii?Q?G6wd+1bPp+rerNhkmCDMa2jtpkKtNykkOjlWjQoj8099iUxxUsZa95hIZaW/?= =?us-ascii?Q?0jM/6uG8yqIMSK3ZZ5m4+xaIv7fyLMbRa9yWTrwPBEsU3ol5SCAodW7FGVmO?= =?us-ascii?Q?TA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?I/2+7AzTfrLuqlrbWM0HjK1nhTk5RycDBqBFZq+aYR2Ky8+h1v+q1w5eaYuF?= =?us-ascii?Q?GaDiarmug62/lI7oohZkwOgnF/EarKppHudYjEl5Rb9eZM0QvZ0TM61RvHqX?= =?us-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jnV5JgKm1ECy0?= =?us-ascii?Q?ClUtJZKJzAg8NJulGDV9cDRNJ04QtLh9aP7LXZM1Sm0NNsllif+Nt2ss6eDx?= =?us-ascii?Q?3i/gDj8BKt4RmdYn25geKAn14/0vrs/VK4Sl6SyHSv4aapJzEYf2wIpF2dlu?= =?us-ascii?Q?EsqDydeHytZrAOn3THgtxTtUhs+vg9PYLmzmhaxdY4TMASLntmAPdEA=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8b5abeb-cb1c-4d85-eace-08db1e5f01df X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:22:40.7265 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u8WMgCkjmR0bv4G36ne3lqwVfb/Yjc2dn4Q8WMghoQDk03Kh3bcziHhbRSpSBQx3gqFr/0eHNWsp/oRFsvmzOmPQ2yPN4ByfasiNVbLiwM0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_09,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060144 X-Proofpoint-GUID: dxgu-m26yJTBGYJ1aKrcJLccxIgfmOxB X-Proofpoint-ORIG-GUID: dxgu-m26yJTBGYJ1aKrcJLccxIgfmOxB Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The crash hotplug support leans on the work for the kexec_file_load() syscall. To also support the kexec_load() syscall, a few bits of code need to be move outside of CONFIG_KEXEC_FILE. As such, these bits are moved out of kexec_file.c and into a common location crash_core.c. No functionality change intended. Signed-off-by: Eric DeVolder --- include/linux/kexec.h | 30 +++---- kernel/crash_core.c | 182 ++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 181 ----------------------------------------- 3 files changed, 197 insertions(+), 196 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 5dd4343c1bbe..582ea213467a 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -105,6 +105,21 @@ struct compat_kexec_segment { }; #endif =20 +/* Alignment required for elf header segment */ +#define ELF_CORE_HEADER_ALIGN 4096 + +struct crash_mem { + unsigned int max_nr_ranges; + unsigned int nr_ranges; + struct range ranges[]; +}; + +extern int crash_exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, + unsigned long long mend); +extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_ker= nel_map, + void **addr, unsigned long *sz); + #ifdef CONFIG_KEXEC_FILE struct purgatory_info { /* @@ -238,21 +253,6 @@ static inline int arch_kexec_locate_mem_hole(struct ke= xec_buf *kbuf) } #endif =20 -/* Alignment required for elf header segment */ -#define ELF_CORE_HEADER_ALIGN 4096 - -struct crash_mem { - unsigned int max_nr_ranges; - unsigned int nr_ranges; - struct range ranges[]; -}; - -extern int crash_exclude_mem_range(struct crash_mem *mem, - unsigned long long mstart, - unsigned long long mend); -extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_ker= nel_map, - void **addr, unsigned long *sz); - #ifndef arch_kexec_apply_relocations_add /* * arch_kexec_apply_relocations_add - apply relocations of type RELA diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 87ef6096823f..8a439b6d723b 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include #include @@ -314,6 +315,187 @@ static int __init parse_crashkernel_dummy(char *arg) } early_param("crashkernel", parse_crashkernel_dummy); =20 +int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, + void **addr, unsigned long *sz) +{ + Elf64_Ehdr *ehdr; + Elf64_Phdr *phdr; + unsigned long nr_cpus =3D num_possible_cpus(), nr_phdr, elf_sz; + unsigned char *buf; + unsigned int cpu, i; + unsigned long long notes_addr; + unsigned long mstart, mend; + + /* extra phdr for vmcoreinfo ELF note */ + nr_phdr =3D nr_cpus + 1; + nr_phdr +=3D mem->nr_ranges; + + /* + * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping + * area (for example, ffffffff80000000 - ffffffffa0000000 on x86_64). + * I think this is required by tools like gdb. So same physical + * memory will be mapped in two ELF headers. One will contain kernel + * text virtual addresses and other will have __va(physical) addresses. + */ + + nr_phdr++; + elf_sz =3D sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); + elf_sz =3D ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); + + buf =3D vzalloc(elf_sz); + if (!buf) + return -ENOMEM; + + ehdr =3D (Elf64_Ehdr *)buf; + phdr =3D (Elf64_Phdr *)(ehdr + 1); + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] =3D ELFCLASS64; + ehdr->e_ident[EI_DATA] =3D ELFDATA2LSB; + ehdr->e_ident[EI_VERSION] =3D EV_CURRENT; + ehdr->e_ident[EI_OSABI] =3D ELF_OSABI; + memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); + ehdr->e_type =3D ET_CORE; + ehdr->e_machine =3D ELF_ARCH; + ehdr->e_version =3D EV_CURRENT; + ehdr->e_phoff =3D sizeof(Elf64_Ehdr); + ehdr->e_ehsize =3D sizeof(Elf64_Ehdr); + ehdr->e_phentsize =3D sizeof(Elf64_Phdr); + + /* Prepare one phdr of type PT_NOTE for each present CPU */ + for_each_present_cpu(cpu) { + phdr->p_type =3D PT_NOTE; + notes_addr =3D per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); + phdr->p_offset =3D phdr->p_paddr =3D notes_addr; + phdr->p_filesz =3D phdr->p_memsz =3D sizeof(note_buf_t); + (ehdr->e_phnum)++; + phdr++; + } + + /* Prepare one PT_NOTE header for vmcoreinfo */ + phdr->p_type =3D PT_NOTE; + phdr->p_offset =3D phdr->p_paddr =3D paddr_vmcoreinfo_note(); + phdr->p_filesz =3D phdr->p_memsz =3D VMCOREINFO_NOTE_SIZE; + (ehdr->e_phnum)++; + phdr++; + + /* Prepare PT_LOAD type program header for kernel text region */ + if (need_kernel_map) { + phdr->p_type =3D PT_LOAD; + phdr->p_flags =3D PF_R|PF_W|PF_X; + phdr->p_vaddr =3D (unsigned long) _text; + phdr->p_filesz =3D phdr->p_memsz =3D _end - _text; + phdr->p_offset =3D phdr->p_paddr =3D __pa_symbol(_text); + ehdr->e_phnum++; + phdr++; + } + + /* Go through all the ranges in mem->ranges[] and prepare phdr */ + for (i =3D 0; i < mem->nr_ranges; i++) { + mstart =3D mem->ranges[i].start; + mend =3D mem->ranges[i].end; + + phdr->p_type =3D PT_LOAD; + phdr->p_flags =3D PF_R|PF_W|PF_X; + phdr->p_offset =3D mstart; + + phdr->p_paddr =3D mstart; + phdr->p_vaddr =3D (unsigned long) __va(mstart); + phdr->p_filesz =3D phdr->p_memsz =3D mend - mstart + 1; + phdr->p_align =3D 0; + ehdr->e_phnum++; + pr_debug("Crash PT_LOAD ELF header. phdr=3D%p vaddr=3D0x%llx, paddr=3D0x= %llx, sz=3D0x%llx e_phnum=3D%d p_offset=3D0x%llx\n", + phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, + ehdr->e_phnum, phdr->p_offset); + phdr++; + } + + *addr =3D buf; + *sz =3D elf_sz; + return 0; +} + +int crash_exclude_mem_range(struct crash_mem *mem, + unsigned long long mstart, unsigned long long mend) +{ + int i, j; + unsigned long long start, end, p_start, p_end; + struct range temp_range =3D {0, 0}; + + for (i =3D 0; i < mem->nr_ranges; i++) { + start =3D mem->ranges[i].start; + end =3D mem->ranges[i].end; + p_start =3D mstart; + p_end =3D mend; + + if (mstart > end || mend < start) + continue; + + /* Truncate any area outside of range */ + if (mstart < start) + p_start =3D start; + if (mend > end) + p_end =3D end; + + /* Found completely overlapping range */ + if (p_start =3D=3D start && p_end =3D=3D end) { + mem->ranges[i].start =3D 0; + mem->ranges[i].end =3D 0; + if (i < mem->nr_ranges - 1) { + /* Shift rest of the ranges to left */ + for (j =3D i; j < mem->nr_ranges - 1; j++) { + mem->ranges[j].start =3D + mem->ranges[j+1].start; + mem->ranges[j].end =3D + mem->ranges[j+1].end; + } + + /* + * Continue to check if there are another overlapping ranges + * from the current position because of shifting the above + * mem ranges. + */ + i--; + mem->nr_ranges--; + continue; + } + mem->nr_ranges--; + return 0; + } + + if (p_start > start && p_end < end) { + /* Split original range */ + mem->ranges[i].end =3D p_start - 1; + temp_range.start =3D p_end + 1; + temp_range.end =3D end; + } else if (p_start !=3D start) + mem->ranges[i].end =3D p_start - 1; + else + mem->ranges[i].start =3D p_end + 1; + break; + } + + /* If a split happened, add the split to array */ + if (!temp_range.end) + return 0; + + /* Split happened */ + if (i =3D=3D mem->max_nr_ranges - 1) + return -ENOMEM; + + /* Location where new range should go */ + j =3D i + 1; + if (j < mem->nr_ranges) { + /* Move over all ranges one slot towards the end */ + for (i =3D mem->nr_ranges - 1; i >=3D j; i--) + mem->ranges[i + 1] =3D mem->ranges[i]; + } + + mem->ranges[j].start =3D temp_range.start; + mem->ranges[j].end =3D temp_range.end; + mem->nr_ranges++; + return 0; +} + Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len) { diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index dd5983010b7b..ead3443e7f9d 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -1135,184 +1135,3 @@ int kexec_purgatory_get_set_symbol(struct kimage *i= mage, const char *name, return 0; } #endif /* CONFIG_ARCH_HAS_KEXEC_PURGATORY */ - -int crash_exclude_mem_range(struct crash_mem *mem, - unsigned long long mstart, unsigned long long mend) -{ - int i, j; - unsigned long long start, end, p_start, p_end; - struct range temp_range =3D {0, 0}; - - for (i =3D 0; i < mem->nr_ranges; i++) { - start =3D mem->ranges[i].start; - end =3D mem->ranges[i].end; - p_start =3D mstart; - p_end =3D mend; - - if (mstart > end || mend < start) - continue; - - /* Truncate any area outside of range */ - if (mstart < start) - p_start =3D start; - if (mend > end) - p_end =3D end; - - /* Found completely overlapping range */ - if (p_start =3D=3D start && p_end =3D=3D end) { - mem->ranges[i].start =3D 0; - mem->ranges[i].end =3D 0; - if (i < mem->nr_ranges - 1) { - /* Shift rest of the ranges to left */ - for (j =3D i; j < mem->nr_ranges - 1; j++) { - mem->ranges[j].start =3D - mem->ranges[j+1].start; - mem->ranges[j].end =3D - mem->ranges[j+1].end; - } - - /* - * Continue to check if there are another overlapping ranges - * from the current position because of shifting the above - * mem ranges. - */ - i--; - mem->nr_ranges--; - continue; - } - mem->nr_ranges--; - return 0; - } - - if (p_start > start && p_end < end) { - /* Split original range */ - mem->ranges[i].end =3D p_start - 1; - temp_range.start =3D p_end + 1; - temp_range.end =3D end; - } else if (p_start !=3D start) - mem->ranges[i].end =3D p_start - 1; - else - mem->ranges[i].start =3D p_end + 1; - break; - } - - /* If a split happened, add the split to array */ - if (!temp_range.end) - return 0; - - /* Split happened */ - if (i =3D=3D mem->max_nr_ranges - 1) - return -ENOMEM; - - /* Location where new range should go */ - j =3D i + 1; - if (j < mem->nr_ranges) { - /* Move over all ranges one slot towards the end */ - for (i =3D mem->nr_ranges - 1; i >=3D j; i--) - mem->ranges[i + 1] =3D mem->ranges[i]; - } - - mem->ranges[j].start =3D temp_range.start; - mem->ranges[j].end =3D temp_range.end; - mem->nr_ranges++; - return 0; -} - -int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, - void **addr, unsigned long *sz) -{ - Elf64_Ehdr *ehdr; - Elf64_Phdr *phdr; - unsigned long nr_cpus =3D num_possible_cpus(), nr_phdr, elf_sz; - unsigned char *buf; - unsigned int cpu, i; - unsigned long long notes_addr; - unsigned long mstart, mend; - - /* extra phdr for vmcoreinfo ELF note */ - nr_phdr =3D nr_cpus + 1; - nr_phdr +=3D mem->nr_ranges; - - /* - * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping - * area (for example, ffffffff80000000 - ffffffffa0000000 on x86_64). - * I think this is required by tools like gdb. So same physical - * memory will be mapped in two ELF headers. One will contain kernel - * text virtual addresses and other will have __va(physical) addresses. - */ - - nr_phdr++; - elf_sz =3D sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); - elf_sz =3D ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); - - buf =3D vzalloc(elf_sz); - if (!buf) - return -ENOMEM; - - ehdr =3D (Elf64_Ehdr *)buf; - phdr =3D (Elf64_Phdr *)(ehdr + 1); - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); - ehdr->e_ident[EI_CLASS] =3D ELFCLASS64; - ehdr->e_ident[EI_DATA] =3D ELFDATA2LSB; - ehdr->e_ident[EI_VERSION] =3D EV_CURRENT; - ehdr->e_ident[EI_OSABI] =3D ELF_OSABI; - memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); - ehdr->e_type =3D ET_CORE; - ehdr->e_machine =3D ELF_ARCH; - ehdr->e_version =3D EV_CURRENT; - ehdr->e_phoff =3D sizeof(Elf64_Ehdr); - ehdr->e_ehsize =3D sizeof(Elf64_Ehdr); - ehdr->e_phentsize =3D sizeof(Elf64_Phdr); - - /* Prepare one phdr of type PT_NOTE for each present CPU */ - for_each_present_cpu(cpu) { - phdr->p_type =3D PT_NOTE; - notes_addr =3D per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); - phdr->p_offset =3D phdr->p_paddr =3D notes_addr; - phdr->p_filesz =3D phdr->p_memsz =3D sizeof(note_buf_t); - (ehdr->e_phnum)++; - phdr++; - } - - /* Prepare one PT_NOTE header for vmcoreinfo */ - phdr->p_type =3D PT_NOTE; - phdr->p_offset =3D phdr->p_paddr =3D paddr_vmcoreinfo_note(); - phdr->p_filesz =3D phdr->p_memsz =3D VMCOREINFO_NOTE_SIZE; - (ehdr->e_phnum)++; - phdr++; - - /* Prepare PT_LOAD type program header for kernel text region */ - if (need_kernel_map) { - phdr->p_type =3D PT_LOAD; - phdr->p_flags =3D PF_R|PF_W|PF_X; - phdr->p_vaddr =3D (unsigned long) _text; - phdr->p_filesz =3D phdr->p_memsz =3D _end - _text; - phdr->p_offset =3D phdr->p_paddr =3D __pa_symbol(_text); - ehdr->e_phnum++; - phdr++; - } - - /* Go through all the ranges in mem->ranges[] and prepare phdr */ - for (i =3D 0; i < mem->nr_ranges; i++) { - mstart =3D mem->ranges[i].start; - mend =3D mem->ranges[i].end; - - phdr->p_type =3D PT_LOAD; - phdr->p_flags =3D PF_R|PF_W|PF_X; - phdr->p_offset =3D mstart; - - phdr->p_paddr =3D mstart; - phdr->p_vaddr =3D (unsigned long) __va(mstart); - phdr->p_filesz =3D phdr->p_memsz =3D mend - mstart + 1; - phdr->p_align =3D 0; - ehdr->e_phnum++; - pr_debug("Crash PT_LOAD ELF header. phdr=3D%p vaddr=3D0x%llx, paddr=3D0x= %llx, sz=3D0x%llx e_phnum=3D%d p_offset=3D0x%llx\n", - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, - ehdr->e_phnum, phdr->p_offset); - phdr++; - } - - *addr =3D buf; - *sz =3D elf_sz; - return 0; -} --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1293C61DA4 for ; Mon, 6 Mar 2023 16:25:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbjCFQZp (ORCPT ); Mon, 6 Mar 2023 11:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbjCFQZZ (ORCPT ); Mon, 6 Mar 2023 11:25:25 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB0339CE7 for ; Mon, 6 Mar 2023 08:24:14 -0800 (PST) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326Cx8M5009619; Mon, 6 Mar 2023 16:22:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=5RR+nmTV8tgATzAsxhlutWv9tznrbgyvKV40fB48SPI=; b=uVpXP1yMGBLYwdpVljgziZpud8eqbULPdQXNfMMmKm8+fW/+MuvuHIZ4vPPfzzgsgYEg j/8YAIPBzKwMDUGmqjx5xaiw7/C9g0bZl6DLg2DVm8x/AU6hTPPdIKDj3M0h2+WIBUeg /hgzfFnzJd3upVlrk3eHWkK6ukB2h8v+ySvh8b8tD9xIjcOCu2J3H1nY7ft0dMRpPLNP mcDdAo3HAm4qrFE4ubC/FUijkupWH7zeSjPcR1TpPx0u1k19uMda1mQRbc5J++zpiP+Q Y9++qCouMv17eOggXsFtS3KdAVu1xJcdnDq+MzUzScrXxKYBy/2bz1w/UslwRckQxXpm Ig== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p4161u9pf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:47 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326FJ6EJ037036; Mon, 6 Mar 2023 16:22:47 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2102.outbound.protection.outlook.com [104.47.70.102]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p4txd75uv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DL1rZrlAFp/y98cCHE2bQG1df0lvy1LVQA+KDsny+ZEDN7UfPAc+xXCclohB74bCp3ltFzQ4Vz3l4fGxgCGSpdF6cUbY0+E/5j0yDZRc+qqXZ166XIU7xQvN61HLDN67rJws9Fatsg9sWUgOepJQvK1iUf1luvSEZ2mtzMbEdnrqQDCZ1JoBjlJ24M0vTqPwtrAqf0i/2yONLz+IxJUjWktuid5vFJc8HJha/N/Jn1P6ewt+N8AEov9bV6+pCGzocFdOEEu3RVG4GzwcFzUNwJGrGffXbfaw6VO6vQ1i8Jyw9ZeoNyusdF9sEPSz6u7jURhByPIK9L+UVBe3NsQdyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5RR+nmTV8tgATzAsxhlutWv9tznrbgyvKV40fB48SPI=; b=JpgMxpRWrI8pby1FyyXeFblvy9leroWzL8dfrESz6egDphmdc0UE+4FNXfRtz1/BWdqB23kKI9kvfOH2diUN+uhopYbuFbicd31u5Hh39XGbsTdgKW47hwmMzkVg9lInEy8lWsuKBdlk3Ab0UDuVLIijsnO+dViPMn1AiG0PZ6Ycd2UCN87/3JU0XPIjojB2kOGyZj2SkAxOvQNVCX/PUg4nE7xkHK0HeGf0EOP6RWf4mliEU+7eMwJRPTOMtXCqaeG+f/gDbPfhY/OIK2EnVGVgl2lqDF6Id8ws6q2/lutp0KriuZa7z/lvCrOTSH3AZi+5m/oF1q0ofhXT2nW7FQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5RR+nmTV8tgATzAsxhlutWv9tznrbgyvKV40fB48SPI=; b=d2PQ22JyN67p7w6t3e1Cm4kII/SGiiR5mwjLJv+rJ1adHkVcHUK0oPe1aycO8jGETT2TGwQ8ojD2v3oqnqbh2ZHoH79gwsSufA4tRrQ12nvvBFKXOqqUky/oOfDwPfJQOqbEL4LL3vHxthaBqjO1BzlxzeWwItU77nwi6v7kCDY= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:22:43 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:22:43 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 2/7] crash: add generic infrastructure for crash hotplug support Date: Mon, 6 Mar 2023 11:22:23 -0500 Message-Id: <20230306162228.8277-3-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BN9PR03CA0477.namprd03.prod.outlook.com (2603:10b6:408:139::32) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: b20e1063-2285-49d4-eca4-08db1e5f03b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uf97XHhmlcu4mqDKMXWS5lX+60YzikqPd3vTricm9TyRTwFam4J0biZh/Ir6zfJS0SZfWt6Bkm6c9xlKOaoff+S7w99VB8RvfpQf0atDgJuhvmPKUZZfPTe6rIYhI+nNAH/rgke289b/gl5+D/pJj/q5P2tg/YnddP1EqZl4MIbTcSffGwFmw2BIAX77qoSDjd6MskNezRVmNdKLygUv/cVDAJ7RCM/ipq5ndRoZjampZ6AnVpDdz5zSFGsB8BsDLSzWQOoiv4Mmy8NkYO5gHnG5g1HUdwuzsKR7gXmXZsy/vryg0wjHcSAspY2jC8uZYSzGHMHJ0eLHN/+agWRyOlVj3qQ0e1FSEUr07U3a0jFTf8vXmg+iIFrSoMase1En+VfWcX5PtEVteKV2SioDPlyanhCTdiXZyuMJclRey/wK9esop1HaXxQWskLJqah3Zii5zuaaEy3iylf/IRDBeFv2tDNVr9j79tFNBfUGdccb1tVJtu41bmQ0jNv75hF/VZTx2AZXPoOO3Tht0WCv4ttG2zpyrtex60AJ03yamrWeqrvsboepzeVaFYGlKAEOpk05HkI3y43e2UZNJFTVa8pjyOQC2C0ehhqYchas/lbKOaah0T/Jjohbeh0h3fOprj3FnEePa8l4E8XHP0RNiUbJLChxkFqI16Nm2e9SwD/gITyivsXtFfsytUfSX9Pt X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(38100700002)(83380400001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/1yNF6iZZ7ADMWFmJYeNR4cE0Xf+FZUrHJeg6CGCYSk/6I02TS5c8cwGHuD9?= =?us-ascii?Q?Stj/fxsvl37e86G9C7uXjrY3VoEV8bsBuwg7kEiDhzJtQpHrczs5JqmsPeLF?= =?us-ascii?Q?pqLKmYAQtWbHbQo+mcEZ1oPWZcQw00RCt/RuolRZdG2dP6tZA95HraavBquu?= =?us-ascii?Q?jvx2AVoqQdPO50+17XkmkNaXMm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us-ascii?Q?HOzRqGwkZzHW5mBvm5MOSPfGcaKvJNo0I/gJ4HjdbRB7qflro2i7SzxeoPPx?= =?us-ascii?Q?asLhpCrA/9dSDSpOk1F3hxN2tJXbpSe72o82/TBHy09u/Whb/LH9O0+gQeog?= =?us-ascii?Q?XdO8mtki8X5W6qeZhSS+YEYepqxs3ut11hzYUoGBu85uLm8oJCDRypSwNGUh?= =?us-ascii?Q?NYCQeYtgV5Z7qHrof+PpxSGcxj8OltcHeU8qhWfX9fJ9YlYBfxJYC9TmgLmO?= =?us-ascii?Q?cOIRukIxxGTW+oir2pZ+J92fcyyC2mVMzwpyl3KEtr3UDaNEqVyL1N2zhTTB?= =?us-ascii?Q?gJ87SRlKbkln7+ENwSgeu5smywpxHV41QhIpBkhPPHYw8Od1BLRZ8B/ip5Eu?= =?us-ascii?Q?fLSKAXxWXy19KfwZOTNL/PuH+LXI94VUwtXAISJqpNqZeTPCY3OLb1v0/xFK?= =?us-ascii?Q?9kTuygQ9bJUqpowCflOd1Uh1ef4SDnEcxWrGWvZN/YuICjI2Sos2F5go5SzJ?= =?us-ascii?Q?rFiGULKLydRavmO6vJfZwHTq9hdzXYdh1Pl81MkQkUAXXTfzzSPbMCUkRljd?= =?us-ascii?Q?Bw=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?pK0idrH0q4a8u1SKpOTBlPxmwO5v+gr/jkIwDkdZa0tOH4HKmpETJfaD11yg?= =?us-ascii?Q?2x0x1oltmQYQDfLy9WYdHRL4F1Rml9U++e22eFU7dNBsH+1kdKRBNxxlI58m?= =?us-ascii?Q?r1kAt9nA2t5sdV9g5DgUov8EcuXoFAOBdzIXKaFMV3z7zV1UxchEPEVC5iqL?= =?us-ascii?Q?bjJEkI+FIM6eEoQICc8BEbgC+0MJQ7UNaEU/88R1VwWKVQbLO14wNDoYqx34?= =?us-ascii?Q?55C9JmGlU1m8yh/SGYxBo2oV4d8ZSigTAxUuZK2qJbw6+imzfkyuTBgxeF/D?= =?us-ascii?Q?eP4tynfoFZ5sfU3wtGgeQJ1870iznH32vqdQ/YlLFkxsokjUrdRmvY9x18pi?= =?us-ascii?Q?+fre7XYByEF+5G+U358kP1y9Y5P19GdjVyobZJPejmk1wiVErLmzsKAlILgB?= =?us-ascii?Q?oL0BEVSUUc1z2yCJpNxubdSIjBoHaIgdH7i1xkJjr63Rl7XjSSAaztm+o9bU?= =?us-ascii?Q?uVpcbe8ZpVxLQ1krTZWu6kwRCFuvORlMrJ7LWLbJXujhBHRcGb9C3Wg1qhFI?= =?us-ascii?Q?PpH5svPoShbopNgH8wDyuhD9barA9ZbZvrnJisnaBudosUz1oSBApGaeEJy9?= =?us-ascii?Q?4oYzll9McwCF1D984DY2tEHmVvYBzQy98BzL5R7FdMjIxq7szImgMUWOrwNv?= =?us-ascii?Q?xh5STZoPwSyoQOFN00XykSm7Tla+f+I5pKeHXfphMMhOTdV4WmbEXPEcfEMY?= =?us-ascii?Q?IP0z2xi8d5ViIjjvUOAK1D0C9i/j8KObF4hILpNZqYhp5/7X+6FZoym8Ge6A?= =?us-ascii?Q?Q4JILteq3un+xjyhWjDXiRk4W3iTldm2rzJdk94F8odyu4a5EYTSOL5dRnBg?= =?us-ascii?Q?FDvW314mVM5quGvMS8dJ3BH4xF/jt9mnkg5wSOK9kh5dcaD3tyzuWpdIJH8l?= =?us-ascii?Q?iyGS1qZQ81AytSN1jVmPx9r+Hibe80imuhkkYUU41Kx0xZIXIAX/kNQGDLLG?= =?us-ascii?Q?Q3cG+ncWmI13gIPzVF768ReZXqYiWoD/YApYrsLu88TjomwYv3HPbLje7RRY?= =?us-ascii?Q?SGy4HRtYJeuD2NUyxdlK9vrNltyTuQze438muGn4R9iTQljp+yzdCWmKrZC8?= =?us-ascii?Q?PpGCyq5wjzhgJi0zAco1m5RWE1B5Kvnf+hyItuHZ96pkrqyPiVD/E6I03kL5?= =?us-ascii?Q?v1HzoIcWUQJqnfRXaxB1CkoaQ4YurxjjgWs+fBYJCao4mFIQIDsvp2E=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b20e1063-2285-49d4-eca4-08db1e5f03b5 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:22:43.8068 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 76tKrDMlIVp6E4l5TWsPJOCCIn5FYGt+uwoZsv44kg8RV05xRbFiW+AIB9y7hWkni0IQtuXyrXg37WKJVRnlKLT+TMu7DvYIE6iAj1DABCk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060144 X-Proofpoint-GUID: hH7Yrzb8k6Y9HokLVbQm2WCLwI0MsFJ6 X-Proofpoint-ORIG-GUID: hH7Yrzb8k6Y9HokLVbQm2WCLwI0MsFJ6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To support crash hotplug, a mechanism is needed to update the crash elfcorehdr upon CPU or memory changes (eg. hot un/plug or off/ onlining). The crash elfcorehdr describes the CPUs and memory to be written into the vmcore. To track CPU changes, callbacks are registered with the cpuhp mechanism via cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN). The crash hotplug elfcorehdr update has no explicit ordering requirement (relative to other cpuhp states), so meets the criteria for utilizing CPUHP_BP_PREPARE_DYN. CPUHP_BP_PREPARE_DYN is a dynamic state and avoids the need to introduce a new state for crash hotplug. Also, this is the last state in the PREPARE group, just prior to the STARTING group, which is very close to the CPU starting up in a plug/online situation, or stopping in a unplug/ offline situation. This minimizes the window of time during an actual plug/online or unplug/offline situation in which the elfcorehdr would be inaccurate. Note that for a CPU being unplugged or offlined, the CPU will still be present in the list of CPUs generated by crash_prepare_elf64_headers(). However, there is no need to explicitly omit the CPU, see the discussion in the patch 'crash: change crash_prepare_elf64_headers() to for_each_possible_cpu()'. To track memory changes, a notifier is registered to capture the memblock MEM_ONLINE and MEM_OFFLINE events via register_memory_notifier(). The CPU callbacks and memory notifiers invoke crash_handle_hotplug_event() which performs needed tasks and then dispatches the event to the architecture specific arch_crash_handle_hotplug_event() to update the elfcorehdr with the current state of CPUs and memory. During the process, the kexec_lock is held. Signed-off-by: Eric DeVolder --- include/linux/crash_core.h | 9 +++ include/linux/kexec.h | 11 +++ kernel/crash_core.c | 138 +++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 5 ++ 4 files changed, 163 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index de62a722431e..e14345cc7a22 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -84,4 +84,13 @@ int parse_crashkernel_high(char *cmdline, unsigned long = long system_ram, int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base); =20 +#define KEXEC_CRASH_HP_NONE 0 +#define KEXEC_CRASH_HP_ADD_CPU 1 +#define KEXEC_CRASH_HP_REMOVE_CPU 2 +#define KEXEC_CRASH_HP_ADD_MEMORY 3 +#define KEXEC_CRASH_HP_REMOVE_MEMORY 4 +#define KEXEC_CRASH_HP_INVALID_CPU -1U + +struct kimage; + #endif /* LINUX_CRASH_CORE_H */ diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 582ea213467a..2dcc4d65f5a9 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -33,6 +33,7 @@ extern note_buf_t __percpu *crash_notes; #include #include #include +#include #include =20 /* Verify architecture specific macros are defined */ @@ -368,6 +369,12 @@ struct kimage { struct purgatory_info purgatory_info; #endif =20 +#ifdef CONFIG_CRASH_HOTPLUG + int hp_action; + int elfcorehdr_index; + bool elfcorehdr_updated; +#endif + #ifdef CONFIG_IMA_KEXEC /* Virtual address of IMA measurement buffer for kexec syscall */ void *ima_buffer; @@ -497,6 +504,10 @@ static inline int arch_kexec_post_alloc_pages(void *va= ddr, unsigned int pages, g static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pag= es) { } #endif =20 +#ifndef arch_crash_handle_hotplug_event +static inline void arch_crash_handle_hotplug_event(struct kimage *image) {= } +#endif + #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct; diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 8a439b6d723b..dba4b75f7541 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include =20 #include #include @@ -18,6 +20,7 @@ #include =20 #include "kallsyms_internal.h" +#include "kexec_internal.h" =20 /* vmcoreinfo stuff */ unsigned char *vmcoreinfo_data; @@ -697,3 +700,138 @@ static int __init crash_save_vmcoreinfo_init(void) } =20 subsys_initcall(crash_save_vmcoreinfo_init); + +#ifdef CONFIG_CRASH_HOTPLUG +#undef pr_fmt +#define pr_fmt(fmt) "crash hp: " fmt +/* + * To accurately reflect hot un/plug changes of cpu and memory resources + * (including onling and offlining of those resources), the elfcorehdr + * (which is passed to the crash kernel via the elfcorehdr=3D parameter) + * must be updated with the new list of CPUs and memories. + * + * In order to make changes to elfcorehdr, two conditions are needed: + * First, the segment containing the elfcorehdr must be large enough + * to permit a growing number of resources; the elfcorehdr memory size + * is based on NR_CPUS_DEFAULT and CRASH_MAX_MEMORY_RANGES. + * Second, purgatory must explicitly exclude the elfcorehdr from the + * list of segments it checks (since the elfcorehdr changes and thus + * would require an update to purgatory itself to update the digest). + */ +static void crash_handle_hotplug_event(unsigned int hp_action, unsigned in= t cpu) +{ + /* Obtain lock while changing crash information */ + if (kexec_trylock()) { + + /* Check kdump is loaded */ + if (kexec_crash_image) { + struct kimage *image =3D kexec_crash_image; + + if (hp_action =3D=3D KEXEC_CRASH_HP_ADD_CPU || + hp_action =3D=3D KEXEC_CRASH_HP_REMOVE_CPU) + pr_debug("hp_action %u, cpu %u\n", hp_action, cpu); + else + pr_debug("hp_action %u\n", hp_action); + + /* + * When the struct kimage is allocated, the elfcorehdr_index + * is set to -1. Find the segment containing the elfcorehdr, + * if not already found. This works for both the kexec_load + * and kexec_file_load paths. + */ + if (image->elfcorehdr_index < 0) { + unsigned long mem; + unsigned char *ptr; + unsigned int n; + + for (n =3D 0; n < image->nr_segments; n++) { + mem =3D image->segment[n].mem; + ptr =3D kmap_local_page(pfn_to_page(mem >> PAGE_SHIFT)); + if (ptr) { + /* The segment containing elfcorehdr */ + if (memcmp(ptr, ELFMAG, SELFMAG) =3D=3D 0) { + image->elfcorehdr_index =3D (int)n; + } + kunmap_local(ptr); + } + } + } + + if (image->elfcorehdr_index < 0) { + pr_err("unable to locate elfcorehdr segment"); + goto out; + } + + /* Needed in order for the segments to be updated */ + arch_kexec_unprotect_crashkres(); + + /* Differentiate between normal load and hotplug update */ + image->hp_action =3D hp_action; + + /* Now invoke arch-specific update handler */ + arch_crash_handle_hotplug_event(image); + + /* No longer handling a hotplug event */ + image->hp_action =3D KEXEC_CRASH_HP_NONE; + image->elfcorehdr_updated =3D true; + + /* Change back to read-only */ + arch_kexec_protect_crashkres(); + } + +out: + /* Release lock now that update complete */ + kexec_unlock(); + } +} + +static int crash_memhp_notifier(struct notifier_block *nb, unsigned long v= al, void *v) +{ + switch (val) { + case MEM_ONLINE: + crash_handle_hotplug_event(KEXEC_CRASH_HP_ADD_MEMORY, + KEXEC_CRASH_HP_INVALID_CPU); + break; + + case MEM_OFFLINE: + crash_handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_MEMORY, + KEXEC_CRASH_HP_INVALID_CPU); + break; + } + return NOTIFY_OK; +} + +static struct notifier_block crash_memhp_nb =3D { + .notifier_call =3D crash_memhp_notifier, + .priority =3D 0 +}; + +static int crash_cpuhp_online(unsigned int cpu) +{ + crash_handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu); + return 0; +} + +static int crash_cpuhp_offline(unsigned int cpu) +{ + crash_handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_CPU, cpu); + return 0; +} + +static int __init crash_hotplug_init(void) +{ + int result =3D 0; + + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + register_memory_notifier(&crash_memhp_nb); + + if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) { + result =3D cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN, + "crash/cpuhp", crash_cpuhp_online, crash_cpuhp_offline); + } + + return result; +} + +subsys_initcall(crash_hotplug_init); +#endif diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 969e8f52f7da..f2f9d41ce5df 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -276,6 +276,11 @@ struct kimage *do_kimage_alloc_init(void) /* Initialize the list of unusable pages */ INIT_LIST_HEAD(&image->unusable_pages); =20 +#ifdef CONFIG_CRASH_HOTPLUG + image->elfcorehdr_index =3D -1; + image->elfcorehdr_updated =3D false; +#endif + return image; } =20 --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB8F1C64EC4 for ; Mon, 6 Mar 2023 17:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjCFRHi (ORCPT ); Mon, 6 Mar 2023 12:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbjCFRH1 (ORCPT ); Mon, 6 Mar 2023 12:07:27 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E96A6231B for ; Mon, 6 Mar 2023 09:06:51 -0800 (PST) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326Cx8M9009619; Mon, 6 Mar 2023 16:22:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=6CqhGscKm+RbjxnqUALkbeSZPYrNnXQIJKdLT4wiIfg=; b=eNtPGeZbtyc7qgpNnD4PRFMSD+7fRzL5MR/nk5mJLfBfkiY9DR0EFtR3KY2SRHloYcN9 bmP2XgxWxBGfzxiKnCSuKcyME3CGjSzYLjoYcv4G31+PkdgpRXbGjKVtGWQbg5RWoneS AOc1O0FBNYwybLzKevxKFuOr4aSsCYLn0hddMMFT9RFR8LZdyzp1y1nXwEAGcw7Zt37j 7I/iO7zbcXVFJFEVCdI+79+9tmUXXOy37r2KS6YolA96DmEexclHf9K+PharqT4gkKUL scScLqp8Jjy30od7yO76IzGy641WMSEy8UFADV4VV83CJYmQKILpzwKNX0fQj/WF9NtG vw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p4161u9pw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:54 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326G2Ms8023373; Mon, 6 Mar 2023 16:22:53 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2043.outbound.protection.outlook.com [104.47.66.43]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u04xtjx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:22:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k42So/004rzwP/Rx+fO0Ur5Z9bUi7M+m8QLwtOlMdLoHCk9Sd82xrI/k2ZPKDR8GB0ZBt5Sg/G8jTtNfwQhOjWKElHxYEgsnceqe2DIw056Z+0J9RSgrZfNNbu9z3lVjbjmwKoRzfycBHpEaFscXdc0oKK30glB8ZF0Omw0Wi+oMyRox9geVl5N9KRgSK+l9MLmxc8uxVZwyPXCbQM8Zf38xvOcsXarv49zM7kVqBFUzRWixU6ikiRSV2goTWi4om4V9o3mzb0v07mxteizkD/sOOiW4OFgszPig2N6b/JESFkhRWXN09PenA6eWOCjcPxpLJZntn5ntebznrPsVoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6CqhGscKm+RbjxnqUALkbeSZPYrNnXQIJKdLT4wiIfg=; b=hKdiykFuzTgSyhfocvhqWDF/myan+Df6NOJ4PsyQ2sqMROYqyelRsmw+ziQOclNuDRN+gn37YCrnvlPcWrUrZgeoxZABhQe5uO1ajhZKOe+9zCUyVYum/wxdCmJAiaa7ZGixGZRRsycUCuX/GoGR9rdHtty3HRayMR7oZGMqvtTHZUWaTKlcbWvpQmz/RNodfbUy/iG+5oUCPzL9BWqwFhQ1LU2oyWN+SM19OzRebrrJ99/bJ4ZHIj6W133fht9eKcNtQp0wpSCpT4ZNTiNks9z1M6JxORfKnIpSZJ5DGaaq/Rmu/LpFN5WpzhAAkloUntCGRgtgjCTOl/w53lRBhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6CqhGscKm+RbjxnqUALkbeSZPYrNnXQIJKdLT4wiIfg=; b=p/u0kX0DEmengz/lWudcpzOQIweADsRmAmrVxBUVmBnuIp5kdKOBdUXo/IcBQcjdY95lOHHwhkoVWwrUZXrJru33q78Ac01SYTCjMWzVo9ZiQQGdfHP+3Khxk0yJUW1AP9OyliYoIHiCqgr63zKM4zsUGyYUzGJ6/YsHkLDH3v0= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:22:51 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:22:51 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 3/7] kexec: exclude elfcorehdr from the segment digest Date: Mon, 6 Mar 2023 11:22:24 -0500 Message-Id: <20230306162228.8277-4-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: GVAP278CA0016.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:20::26) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c23c744-bb18-4dba-7814-08db1e5f0828 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eIHDdnm9Ioum+MtGOsO3ObNVmKA/d3Gp7hwOoXV3vCUT9AjokTQ77pvy/sNS4HcT8XTDEjlgNeoheqO82gkknxT0AtWWma+k3icArgTCxq75Bc1691ZB+lOFTd2eMmzNFlrc9LuHcY2lukpZpnG3CaVQLuI1hUuTyzgCGrgxyzizGnZnoKfyiHuVQLRgNj+fQrQQXZnv8nOSQz2BT7O9smtLzHdoIhXYh8r4ctYyScWuNBTrSiL9xid66EsQIr+gTr5GzMA6luHK8lPaZxAUl2PJ6zsqmaO7UsUUsQcTTRdz5b1HmnS9rOGFBqIYuHmHYUq0xdfGLeQFR5fHeuzvdYVpW/4B4QVoPmB+MIwJs6uXcQU3gRxR67QWkV0WoDLqyK1WVLyhHijfluLRnsMMmpxJYXvIRkGjNPAVrwjUtawVPvlO11oxpl5tPAs50d4V9MRQ1sJWXY5LWumfcoI9P/6nQC4u0K95B5iTVjrzmlwYBhZMdRBiiaKBlFFZevKCRAgk8OuvvJnOzb0wMYlLa4P7oQig9DH6H2Ft/IUR+WhiDZ1RG1f9cGeXW8C0typES5Ph492ziYRHJlXxGHbMLnBKG/WEtH6FwPOy1kh7H+TDONjRIafypbSBaTSt+VPf5Z+hakOKm0eZrFCD7O5OOw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(38100700002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Dq3aVG/6nch6PNj1bw319vgaD7ihAIUjDanKcS3/NDZr6rNUGyKB0+1H2TpO?= =?us-ascii?Q?kyKWZ8RIdmkXnOWLfu6/Kd+Z7vALUIYZK9+e8vCHqga209YXdy9QsUnILoqs?= =?us-ascii?Q?zPtNgWzxuu3PxHlvPH57bjHsEx2MSQ3WJKIE65S+AyA1MGM/FjRrASEIiZEh?= =?us-ascii?Q?EFWJ7ERZi7sWIgOVFiqsVDzULzKQv9l3ji5Rx6NX0ByVUC0hJE0pRW1KJvAk?= =?us-ascii?Q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+AAZ1M?= =?us-ascii?Q?N5ew1d1gGELpXp0nCkkMsyDl34wPoS6Kz31a8NNwcrbraQQs0cJ5i5YOESc7?= =?us-ascii?Q?UZTszJRgiE9NSurwM+W0XaPR2BsINuMKd/fOwGGJ5NL/d1/whT+qBpgRmiUV?= =?us-ascii?Q?Yof4JF15Nu5kwYGu5/LVTrUtK70MzCUDsPWGM8Y7jmLL8jcawyMkoZPxHYRi?= =?us-ascii?Q?4EfRYsE1UXzg8O8XapNDNwYmFVj/zAM3ziZK5MW9Fs9gH/pnYjKjXCyctRji?= =?us-ascii?Q?+C/6ZycmaveqzfGPWWn9yvARsnClvUMipWM/cMj+AzctKW0gOX0hQWVKxWbE?= =?us-ascii?Q?z9peJILXlxiDccsd4iXDImIu7k45fJAMBBM9SBXg+l545FTmXYObXT76CRMU?= =?us-ascii?Q?/ug294Css4HvllS6/nes1M8p40Vn1+0Gx+kdST/qBFEH1tCLq+MhtBqeAm1/?= =?us-ascii?Q?Vk2xZgiCQjlIVO9kBprDnYjdCPA/8CyFuX5mwtYE/9FCTMKwXuX1g14nYSzg?= =?us-ascii?Q?cA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?VLLCvpfKsyebRb6oFrLu50lG8wlz/dZr2oCauHFhoSU6LGFXXkFBkaaQY4b+?= =?us-ascii?Q?Qi++rGueNm8eh+XeNRrT6JY9fmsWgTT7eMQEFwwz7rN0ESQrtAx/mNpwh6hJ?= =?us-ascii?Q?bGzprvYchaReRyFcQbbP6pmIZ2vyDZ62WAjLkuqmR1tvDcvjtc/5rcLkTm9x?= =?us-ascii?Q?Ka24fO7mtD53Y2hM+8gPNwnGJfdGb0LOjMezzmDXO+E1goejA6gVi/7vXmv8?= =?us-ascii?Q?bVnxwCRbxvWwpn4Lc3lhvsfZK6in98AfZ+TG4TFn3tw8u9WxtfBnEEfLDZO7?= =?us-ascii?Q?t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HVZY1zwQyQcAAr+aPLM=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c23c744-bb18-4dba-7814-08db1e5f0828 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:22:51.2528 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /tiCyj6jx62GpkVBPh3PlTl8QMstGzTxMR+/kYX/BjtJj4mBdgNGvh1g1E1HvE7U8ZTmncAaYTgLIIvydZg1SwUpcARkIA2tQXu/a7/3M7s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060144 X-Proofpoint-GUID: h59y_Jzw1KzktcExkOQbg5HzXgKko7Fq X-Proofpoint-ORIG-GUID: h59y_Jzw1KzktcExkOQbg5HzXgKko7Fq Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a crash kernel is loaded via the kexec_file_load() syscall, the kernel places the various segments (ie crash kernel, crash initrd, boot_params, elfcorehdr, purgatory, etc) in memory. For those architectures that utilize purgatory, a hash digest of the segments is calculated for integrity checking. This digest is embedded into the purgatory image prior to placing purgatory in memory. This patchset updates the elfcorehdr on CPU or memory changes. However, changes to the elfcorehdr in turn cause purgatory integrity checking to fail (at crash time, and no vmcore created). Therefore, this patch explicitly excludes the elfcorehdr segment from the list of segments used to create the digest. By doing so, this permits updates to the elfcorehdr in response to CPU or memory changes, and avoids the need to also recompute the hash digest and reload purgatory. Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- kernel/kexec_file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index ead3443e7f9d..14e55fbc1ad7 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -723,6 +723,12 @@ static int kexec_calculate_store_digests(struct kimage= *image) for (j =3D i =3D 0; i < image->nr_segments; i++) { struct kexec_segment *ksegment; =20 +#ifdef CONFIG_CRASH_HOTPLUG + /* Exclude elfcorehdr segment to allow future changes via hotplug */ + if (j =3D=3D image->elfcorehdr_index) + continue; +#endif + ksegment =3D &image->segment[i]; /* * Skip purgatory as it will be modified once we put digest --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D366EC64EC4 for ; Mon, 6 Mar 2023 18:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbjCFSPU (ORCPT ); Mon, 6 Mar 2023 13:15:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231302AbjCFSOx (ORCPT ); Mon, 6 Mar 2023 13:14:53 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0722932CF2 for ; Mon, 6 Mar 2023 10:14:19 -0800 (PST) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326CxG2B017856; Mon, 6 Mar 2023 16:23:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=qHm4Qdh/f5x/LfFaP6306ySB97O/QRQxfBSmKTnF90o=; b=OAHwFF06UUoX6W6pTky3mqRoAjH9o6RRKMcvwqt5W3EvE4ZVJKh3CEZMaKFTD2qocRti PgGF8BgXsN2zMLDC4nq1sbSyz9IEoarXc4h7BWt8QacsCvCvkmnBCHvGhSXYPQrESnX1 ZKcYgm3g8VHo1RgaHXxE1m+dcD0bAtNWn7Hk4XmWgNgR1yVVEd8J5zy7Nw3s3tb7+xRA Vswgtm3hTDYwC91utDfyKB/T/cHXJsTOAXFR+IDiuM6o1KHkPFAucFAMJ+JYJnfPQWDK Gi5hP97sS/WfFv3rifss0LLoC6tTwSCl14+d5g89BHnuo5+RTsDq7jjMP1SPqOx4c0FE Eg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p415639yq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:04 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326FmI8f028608; Mon, 6 Mar 2023 16:23:03 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u1dq69t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F1k9CYMomCezSxR0Uhks/6hU9xQEAous7CP4K1n+Bt7PFAPutUfeub205AnPyFHiqH70FI9siNckemKTQpmH7YKn+od1qRKj5Hzr7t4dl8bDreNq02aBhqf6hWBPMdwpn9hDRmn9j8NlcAQC43XptQkJ3/vwMv9Mln8zYd01rir21pV2wNiyN684xa1iCeS/CEiNFiFWdEf3288HyxUkSsNUvvbnYMv+UpBz80Nxl6/nZufQI3Y6iGy+k/gFEVkqBwXX6Z9QLZ3D/E95SU5LaGLXYeC/wsW1SM/Lvw9KgF2XLMPcKWV53Tlhk2NVeJqvpCBWjOezS86KPy0+qKo+eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qHm4Qdh/f5x/LfFaP6306ySB97O/QRQxfBSmKTnF90o=; b=eoOpuSHaFRbGREBG7Hz6tkJOoNkS6U2JiJUj3WDpSF7TQLsYCndGn7rEwS2KbS0+xRpatAKcX4h+LBRtjAENxF3+WPzx26fL6hPMJdLfx9bJB5YyMGRnQtxGXv1vCpTR/QDS92Jp2HlfwF2HFJUfIowjAdZPHnkCRB7ecTBxpcyQSbiGFUaGWDabErLk7CgeWJ0UdFUchitT4jIapgIz5/q+Eq8dgHwiDtW4IJnbeHN6Pbiwo9DkGSClDA+ZWyk7TaB3pQOoivDvrKBB0xzN0q1xibNii3w00g+3yF33QFj+X50sAH7wnVSQGSX9RsxV9FkyiEwvRGVaqNGSb7zrNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qHm4Qdh/f5x/LfFaP6306ySB97O/QRQxfBSmKTnF90o=; b=GqV6Bilty2QeAf1yufDQblAwLBvdpmx17wURGbkAImfYllf/Ds2eeRHtSClMXVeZwBVk1MEFquk8ue2ibSdDDG8hslWjiw2s5oecAlFIKsAqsNU4J2PZtPgQQ3+3hKeK81sPeaaeBz6slIzKYRqOclr6ebLR/WSPagmxlj59pwI= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by CO6PR10MB5537.namprd10.prod.outlook.com (2603:10b6:303:134::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:22:54 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:22:54 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 4/7] crash: memory and cpu hotplug sysfs attributes Date: Mon, 6 Mar 2023 11:22:25 -0500 Message-Id: <20230306162228.8277-5-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: BL1PR13CA0120.namprd13.prod.outlook.com (2603:10b6:208:2b9::35) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|CO6PR10MB5537:EE_ X-MS-Office365-Filtering-Correlation-Id: 15a7571d-70f8-4c4f-4b8c-08db1e5f0a03 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0wlmUdRp8XOB4gTZlYwH9mEgPvl9k3siizImAeyZrVl851dsqDMgcFT/Mk92R64edkl5fMhB1xg0VpYEbcWecmOdM0bd25jL/8zIqkQc9FFo4/3rJLiKvyjjzOIESQleHfSQMKGgU5LUSWlJV9LYU2FdBBmqLz+nqwla30klGZkvJqSZJP2DzsJmRSUiHGV/7h5lV9+/B/gjBiE+vsRCUnbMsRexXVd5q5jASErQyMEIZAPw/IDBYKAjK+I0xDIqUAKIjdij4OrcJ0ObL6i8Um+A2YsJGHvGA2wb4B8iPzSrpqfRXwnGaOfqelRFw20EAnxLGXk2zBUOCcb42/4w0vUeoDYLtL1H8vqume4S0MDEh7YmFvFIvJfDGEYGZfU2GXsf987hE584huafxnGtH1TZwoYrdtQR7MAQBMiJmWg4dHJRMu7023sS4E1B99zoxsq3BRVfI497Jytw5D9nMVK0yZ360lJM6zZ1EPjFUy+2YWpjL4O3WbWcsdzFKbPS7JxVf9wb+yYpV7V6b6uy1nUR131Bpn4UWq0svH23eK5AFIY/J/Yuin6AKsZY1rgSnEk4WJvVX9fnigLW9eKyjUlGfvI17cIsb2hsLXRlhkGxCq9NoJcwNt35ddeV1dX+8npZzqSt38cDh0M68dPTDA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(366004)(396003)(136003)(346002)(39860400002)(376002)(451199018)(66476007)(8676002)(66946007)(6486002)(478600001)(316002)(41300700001)(5660300002)(66556008)(4326008)(86362001)(36756003)(1076003)(186003)(26005)(6506007)(6666004)(6512007)(38100700002)(107886003)(83380400001)(2616005)(8936002)(7416002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?EB5r1YBlgaOYH+KJALotwjPROspzEXzpEojjF1qgnsLV29kQtrqbe7OrO4Ii?= =?us-ascii?Q?VnLsbVBt6eI1iDoXyukIEEjD80u5jM0x4gXAxWw8FjtjnJK7L03zNp4i9Deb?= =?us-ascii?Q?AneODzOCtnLTR2LySgKdzjJybzludiSRCE1/vauETDf0L2wv1K4rdcdQMDaa?= =?us-ascii?Q?CMIZWNVm61UuzDnPyzF2M4A+iT89oMFpJrOOv60KVk9aXr9c0MwAYt9MFgpr?= =?us-ascii?Q?owyaz9ymCVrVEKlWfSiiQS1C6ePy80UJWIDROUHUDcMsz1HD/d8GztFZ+08C?= =?us-ascii?Q?3L7NS6i8lYqi+q+s77aMKsXWaw+mdTKwEXmh68WBs4UuiCGRdSVyiEtDyCJ3?= =?us-ascii?Q?3yVoQyQNyXasm7IzlVaBP5n7WsahFAgX4E2mhlDqLNI9xaWvDlcCCs/0pRTA?= =?us-ascii?Q?besGrZt7mxTPam8hnb0mebqMhRMxM0bIFV+u1juZc0tWw4X/0BU7bBEM5syv?= =?us-ascii?Q?8BKdhmASjMCeGZyahgw36r/Mdzcm9BHF9gDDAlMYrzr3ncTwix1RlqJvMmZh?=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8BDQtQ9G314q95nkfbVTq?= =?us-ascii?Q?UwDGsUl+rJWJSc4p5lgNFyeYJMv8I0DKbsSKCFGkgI0ac29sEqdc1DHPb4gP?= =?us-ascii?Q?ACYKDIvt8w9z5Gb6Wd3UPKLWUQthmdkUSyrPjS8E1yQxBA67/+5tcub/mggs?= =?us-ascii?Q?GJinG2bWJvmYLMrNnExjRqWzxoCiLWupFLHBneup0OgQyFcThRRFdL/yf1BF?= =?us-ascii?Q?Yg=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?60MAULtsSWBlVnjZQSL4MdlVDcp4iKSfm7o8TZhkqPPGn9iXKdMhKX4k29Qi?= =?us-ascii?Q?0lFrUNizyPBHcGRdJx5zXblG801ODSW6c0evx7Yv9sECXLL8nuw/Spc57WEA?= =?us-ascii?Q?uuEMyidY/0zOzj544sqeIeSVIjVKT52eRrRox/MUxHVEmrp8h3g72NAv9qAz?= =?us-ascii?Q?OqdsUwBD2+IvKjRZY7XKG6XFWimXsyicPrYarvVvNBWqSG/z/SZEyTwxDNru?= =?us-ascii?Q?bgAHGz1lTwgYRmB+656W4D/cl0mY4nPTBf6MejiBKzOQBpwjehd7gJTr+niM?= =?us-ascii?Q?XptxO0rZguEBchQnoc5LxlCYYqRRVNHhSeo7L+yrxiMljvMXRImmds5laBX2?= =?us-ascii?Q?PYkIqL6CCbuc88wFUzSewbkttXPJ6QNi5GbSjkw5TC2PlrFdvVpyGX5160Ii?= =?us-ascii?Q?uJ/BHiLgHZKUqBShOLliV4uWwZ/q2sr6PZVd/J9fSCATSex9WAynCdsYSTXY?= =?us-ascii?Q?HGEvGudauybD4VZikf6A1tWh2pbgiZReUv0HsjstRZrQV7q0mKjaPJWNYHnR?= =?us-ascii?Q?R5wVrCik9FY66cH7VVVOhSu/vxXUYpf5lXb3+vuiMcQ8hQexeQDtPTkYIj39?= =?us-ascii?Q?380j416DTpMkgulMsTK09ZcIMWEkL3onslGDZ09S7bTgfOHNr/UvzitBorhw?= =?us-ascii?Q?ttaC+1uq3r95BpRU3txGkFXVRvN1RnHuN9WGQ+KT+UgrjmrJsSLDKIKA24F5?= =?us-ascii?Q?vqOQGPCvRQVbEmZCCZ4V/8SFjiV4OREdf57sZwcC+CkmuiTHQaUrmXa9fW4Y?= =?us-ascii?Q?IpxSecJpKkrP+r3bjjwYovzf2LLguC9naI+PbmegkIz6GjSNG7X7EVu+/sjN?= =?us-ascii?Q?i7D6uwmzgXg1eEQi45dx3acIdfMv+JyIl9YH+YaBUFNtjaLaayXHHdvWZHy/?= =?us-ascii?Q?WyYnlYDvJ6flT2bUphEtApUi8EN/IIHrl2yJe5RUt5bRXAV9yNocXUsUM26z?= =?us-ascii?Q?+D7wdycxnmIsEIqSaP0nYr2ftL5nH5EFzQMqSX0Ev45eLoDNJh4YkP/9wX6m?= =?us-ascii?Q?qa+8zNBA2xZ6wLF3jO8Ug9IvtXjdmmiCSm+eWBEDnUKlsFWwdGN6CA4GxUlx?= =?us-ascii?Q?8+guGwXPb+ytS3LMEbay0wxrswPwTDo76Uq//Xq2j25z1Sz+ffgdTjpJZ9Bp?= =?us-ascii?Q?ynv09WjsZEE82d4aN4jEMiEURG9W59XZXGuRaYHdnBWfQhkA3m0synY=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15a7571d-70f8-4c4f-4b8c-08db1e5f0a03 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:22:54.4583 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NWzXnXJC4PF965AVGQeKykPU11FLXxvSZnF4CfdVN6aBjFH8GstuY0Q1QlCBszm2GFnH5WU9qktvrz2AbaZxJPDLN7PQteCjvGOn/L76PY0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR10MB5537 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=965 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060145 X-Proofpoint-GUID: gZTZcFJKDafMaPLIYcz36hJ4-YOOaTM_ X-Proofpoint-ORIG-GUID: gZTZcFJKDafMaPLIYcz36hJ4-YOOaTM_ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This introduces the crash_hotplug attribute for memory and CPUs for use by userspace. This change directly facilitates the udev rule for managing userspace re-loading of the crash kernel upon hot un/plug changes. For memory, this changeset introduces the crash_hotplug attribute to the /sys/devices/system/memory directory. For example: # udevadm info --attribute-walk /sys/devices/system/memory/memory81 looking at device '/devices/system/memory/memory81': KERNEL=3D=3D"memory81" SUBSYSTEM=3D=3D"memory" DRIVER=3D=3D"" ATTR{online}=3D=3D"1" ATTR{phys_device}=3D=3D"0" ATTR{phys_index}=3D=3D"00000051" ATTR{removable}=3D=3D"1" ATTR{state}=3D=3D"online" ATTR{valid_zones}=3D=3D"Movable" looking at parent device '/devices/system/memory': KERNELS=3D=3D"memory" SUBSYSTEMS=3D=3D"" DRIVERS=3D=3D"" ATTRS{auto_online_blocks}=3D=3D"offline" ATTRS{block_size_bytes}=3D=3D"8000000" ATTRS{crash_hotplug}=3D=3D"1" For CPUs, this changeset introduces the crash_hotplug attribute to the /sys/devices/system/cpu directory. For example: # udevadm info --attribute-walk /sys/devices/system/cpu/cpu0 looking at device '/devices/system/cpu/cpu0': KERNEL=3D=3D"cpu0" SUBSYSTEM=3D=3D"cpu" DRIVER=3D=3D"processor" ATTR{crash_notes}=3D=3D"277c38600" ATTR{crash_notes_size}=3D=3D"368" ATTR{online}=3D=3D"1" looking at parent device '/devices/system/cpu': KERNELS=3D=3D"cpu" SUBSYSTEMS=3D=3D"" DRIVERS=3D=3D"" ATTRS{crash_hotplug}=3D=3D"1" ATTRS{isolated}=3D=3D"" ATTRS{kernel_max}=3D=3D"8191" ATTRS{nohz_full}=3D=3D" (null)" ATTRS{offline}=3D=3D"4-7" ATTRS{online}=3D=3D"0-3" ATTRS{possible}=3D=3D"0-7" ATTRS{present}=3D=3D"0-3" With these sysfs attributes in place, it is possible to efficiently instruct the udev rule to skip crash kernel reloading. For example, the following is the proposed udev rule change for RHEL system 98-kexec.rules (as the first lines of the rule file): # The kernel handles updates to crash elfcorehdr for cpu and memory changes SUBSYSTEM=3D=3D"cpu", ATTRS{crash_hotplug}=3D=3D"1", GOTO=3D"kdump_reload_= end" SUBSYSTEM=3D=3D"memory", ATTRS{crash_hotplug}=3D=3D"1", GOTO=3D"kdump_relo= ad_end" When examined in the context of 98-kexec.rules, the above change tests if crash_hotplug is set, and if so, it skips the userspace initiated unload-then-reload of the crash kernel. Cpu and memory checks are separated in accordance with CONFIG_HOTPLUG_CPU and CONFIG_MEMORY_HOTPLUG kernel config options. If an architecture supports, for example, memory hotplug but not CPU hotplug, then the /sys/devices/system/memory/crash_hotplug attribute file is present, but the /sys/devices/system/cpu/crash_hotplug attribute file will NOT be present. Thus the udev rule will skip userspace processing of memory hot un/plug events, but the udev rule will evaluate false for CPU events, thus allowing userspace to process cpu hot un/plug events (ie the unload-then-reload of the kdump capture kernel). Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- .../admin-guide/mm/memory-hotplug.rst | 8 ++++++++ Documentation/core-api/cpu_hotplug.rst | 18 ++++++++++++++++++ drivers/base/cpu.c | 14 ++++++++++++++ drivers/base/memory.c | 13 +++++++++++++ include/linux/kexec.h | 8 ++++++++ 5 files changed, 61 insertions(+) diff --git a/Documentation/admin-guide/mm/memory-hotplug.rst b/Documentatio= n/admin-guide/mm/memory-hotplug.rst index a3c9e8ad8fa0..15fd1751a63c 100644 --- a/Documentation/admin-guide/mm/memory-hotplug.rst +++ b/Documentation/admin-guide/mm/memory-hotplug.rst @@ -293,6 +293,14 @@ The following files are currently defined: Availability depends on the CONFIG_ARCH_MEMORY_PROBE kernel configuration option. ``uevent`` read-write: generic udev file for device subsystems. +``crash_hotplug`` read-only: when changes to the system memory map + occur due to hot un/plug of memory, this file contains + '1' if the kernel updates the kdump capture kernel memory + map itself (via elfcorehdr), or '0' if userspace must update + the kdump capture kernel memory map. + + Availability depends on the CONFIG_MEMORY_HOTPLUG kernel + configuration option. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 .. note:: diff --git a/Documentation/core-api/cpu_hotplug.rst b/Documentation/core-ap= i/cpu_hotplug.rst index f75778d37488..0c8dc3fe5f94 100644 --- a/Documentation/core-api/cpu_hotplug.rst +++ b/Documentation/core-api/cpu_hotplug.rst @@ -750,6 +750,24 @@ will receive all events. A script like:: =20 can process the event further. =20 +When changes to the CPUs in the system occur, the sysfs file +/sys/devices/system/cpu/crash_hotplug contains '1' if the kernel +updates the kdump capture kernel list of CPUs itself (via elfcorehdr), +or '0' if userspace must update the kdump capture kernel list of CPUs. + +The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration +option. + +To skip userspace processing of CPU hot un/plug events for kdump +(ie the unload-then-reload to obtain a current list of CPUs), this sysfs +file can be used in a udev rule as follows: + + SUBSYSTEM=3D=3D"cpu", ATTRS{crash_hotplug}=3D=3D"1", GOTO=3D"kdump_reload= _end" + +For a cpu hot un/plug event, if the architecture supports kernel updates +of the elfcorehdr (which contains the list of CPUs), then the rule skips +the unload-then-reload of the kdump capture kernel. + Kernel Inline Documentations Reference =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 4c98849577d4..fedbf87f9d13 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -293,6 +293,17 @@ static ssize_t print_cpus_nohz_full(struct device *dev, static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); #endif =20 +#ifdef CONFIG_HOTPLUG_CPU +#include +static ssize_t crash_hotplug_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%d\n", crash_hotplug_cpu_support()); +} +static DEVICE_ATTR_ADMIN_RO(crash_hotplug); +#endif + static void cpu_device_release(struct device *dev) { /* @@ -469,6 +480,9 @@ static struct attribute *cpu_root_attrs[] =3D { #ifdef CONFIG_NO_HZ_FULL &dev_attr_nohz_full.attr, #endif +#ifdef CONFIG_HOTPLUG_CPU + &dev_attr_crash_hotplug.attr, +#endif #ifdef CONFIG_GENERIC_CPU_AUTOPROBE &dev_attr_modalias.attr, #endif diff --git a/drivers/base/memory.c b/drivers/base/memory.c index fe98fb8d94e5..a3f37cb57d79 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -495,6 +495,16 @@ static ssize_t auto_online_blocks_store(struct device = *dev, =20 static DEVICE_ATTR_RW(auto_online_blocks); =20 +#ifdef CONFIG_MEMORY_HOTPLUG +#include +static ssize_t crash_hotplug_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", crash_hotplug_memory_support()); +} +static DEVICE_ATTR_RO(crash_hotplug); +#endif + /* * Some architectures will have custom drivers to do this, and * will not need to do it from userspace. The fake hot-add code @@ -894,6 +904,9 @@ static struct attribute *memory_root_attrs[] =3D { =20 &dev_attr_block_size_bytes.attr, &dev_attr_auto_online_blocks.attr, +#ifdef CONFIG_MEMORY_HOTPLUG + &dev_attr_crash_hotplug.attr, +#endif NULL }; =20 diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 2dcc4d65f5a9..5a0369b14d09 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -508,6 +508,14 @@ static inline void arch_kexec_pre_free_pages(void *vad= dr, unsigned int pages) { static inline void arch_crash_handle_hotplug_event(struct kimage *image) {= } #endif =20 +#ifndef crash_hotplug_cpu_support +static inline int crash_hotplug_cpu_support(void) { return 0; } +#endif + +#ifndef crash_hotplug_memory_support +static inline int crash_hotplug_memory_support(void) { return 0; } +#endif + #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct; --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 408A1C6FD1E for ; Mon, 6 Mar 2023 18:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230267AbjCFSNz (ORCPT ); Mon, 6 Mar 2023 13:13:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbjCFSNc (ORCPT ); Mon, 6 Mar 2023 13:13:32 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CE2F2707 for ; Mon, 6 Mar 2023 10:12:51 -0800 (PST) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326CxF3l013883; Mon, 6 Mar 2023 16:23:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=pwFHmqjBVzoowkQPsGI32YFDgdwu2nct2hyJC2lNrWY=; b=n/LPHOZey9T+RiyYvxpCES5sc9Cv4vaUTHlQ73eaUpC6KBNhWSjh7sM5WpRjbvPY4Bj3 Ju2uD40vZDam3WlKGNeN879cC41YFu9jojpWIxV4nS5cPfw/Nlu/IEzBzzWj2f4xr3NX plcSxdlad2Lsy3vyuHNRyxocmlh2lKn2pN+Y2sJuIIpUxoc+pNJgL8U6LHnc67PbuNsm kRR7KdXaxqFuPbqxfg1RCqsSWkHoDYqKV05eOQolc3cUPbUaHoEY4n9jupFT+4vkz1S5 z4TiXeDfli6ykZZlZyoASTW6LcZlQyAHC2baTghTPiZj3cpdhDIV8UNzcJs//FTFnU4s IA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p416wkaab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:04 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326G0Fsc011448; Mon, 6 Mar 2023 16:23:02 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u2gfbc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mHFIKtQLU0Cq4IniI94sWI2qB4Wu+jM/QQfBkmqaMsWl3uO9fhUaqOs7gMFw1ksOCpKgyHzRWO/t62zXRnkoiH3Z+1BBAeshPzC1v++HWCpljbeXJo1Ssfep4cugo8ZO4U1zvFVkjY7uFPQSzaADe8UyvGWkjI54yW8g5227Lej8RDUgBRWqj9PR5Oz86ipnABMRV0ZYUHvfhsikafVQ42rapD1kt9TayXSklDFL4PzZRBCJbrZxOjctCKqHRH1AdhMQKYneOWyuNfwnT/I8WLAvDcdt0gIqnV5uDvpjUCFsGO/EohvRlceh8+fJbPlm5lqgmYvwQ28/KcORMniUyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pwFHmqjBVzoowkQPsGI32YFDgdwu2nct2hyJC2lNrWY=; b=ZeJkzaxm4WzTc1HMgRmS1MXVOG8IisIp++giOt+t3c46utlJnqD/QMVsC45tXBX/Os3Sp05nz7A5ATQGCSWUeqvepxAWoRiC5ByFJA1StpvOmVR3YWgFn5JYPiMR+ptVLxLRvWU7sZv5wYPDAanEBSTwluVs3e+YUit1TfFECMONCXvpcn+8mbWnRjK0Xf/poHSDNl+xDtStXIy5E+tORp+80WeaH1oLgSjOxSKX7uvTTBgfEDauWx1X7sMp+uaJ5PMwFwhPhg/VpMEeu1pUrgSc6FWzzoxgkDwT+DS1pYcogXi+8WdFVh1FI9YpjVwc+xfxRLgaCnUUKX/HHNnrvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pwFHmqjBVzoowkQPsGI32YFDgdwu2nct2hyJC2lNrWY=; b=IVZEuWmeTa0PTwKa5eKPlBK+FnHCnvwz0qyBLPfH5NQubfO9tuwMeu+2wxefrcRVBOTjqoZOPtr4WQ6E2OMAZEdyhhrjrEc4nFm3f3uhn439USu/6eqHCqEWJJ9pVz77ktR6Otkx3Ouh7I64k1a9lAfxa4CGYx27WlZoFeTBuK4= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:23:00 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:23:00 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 5/7] x86/crash: add x86 crash hotplug support Date: Mon, 6 Mar 2023 11:22:26 -0500 Message-Id: <20230306162228.8277-6-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO2P123CA0073.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::6) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: f44a9081-e8df-4f30-0bec-08db1e5f0db1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JmVLaYWPid2WFKPhGw30PuPEGIvLabrdGYFQ6n1IoXJ3qSw4ke1G6J2H8LhPbXEQCSyd9sSlLF9NQxkJAv8n+Bp02LxKB3k9Qb6d5+Drh47khsKjoaoSwNKsKhJxwdPKyCzOWHLtfWnxWIY9UOatGsmyDIZt+MfRo5+XtXwvIoi4scX+G4zixZCc1qFaOJYGR1X0RNcsb7WyvTtxc5eWqG1lRr82k7/Qsi7KUDXFfrzOjp9lbPvAbWsFz+4Rd4tBsb6aJOTEmgO3I+WFXYttBaPhx/0Sif7Pqh2/jMm+rQpfd76BvNX5FdjwfOgQEPrhzOtHpKYCpfujiIHTIMArzQyuc5ftNxXzie80WOg8X3PKWx9Kra4f8oFC5akbBVU8CKv4IxOY4JRW89BrvJXFVPCM8KOdlPX4RWSBNpJgTLJ8gYIVTWz0HaKEnxkf02kl9Ip+XBEqkpQ2+0fL/YbI4qwd+V5DHGgQVy5tS4LMOr5T2Jcl9pRLnjm7LlVLZ1jqgy6ltwVIYA6jonMsPEehwDwsAWG4U7DbCMQXvtKMKA+lZ+231Fbj6yGz1BjWChKj1kEzIV0hBaYFrG3pHWMIcPtJdbuKEtZcIbFdI5PaTvzih29Rqd4qHDm1dIF8aPirN/ypZM0Gbe8JUFrvrB0Czw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(38100700002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?eZ/SypIwtAAaja05VH7uMm7oZCvJgIRy5RV7BZq+qnH9UJPzzog/IDIYsP5x?= =?us-ascii?Q?0gtMFySPBRtfhMnZdrrlwxARi4pb9AKqahkIIZDRApBZJNTfn1Oc64qbOciK?= =?us-ascii?Q?phUzgZJdmHSDOOdfqxCs9x1akcHxAcQb2IV9sRlh2uy9dPfNU498+zAqiZdD?= =?us-ascii?Q?B7Rh1Zyw0RYQJgalWxaF9ZJyO0UvKUhinx7BWSIHN5wYAjU51eB4V4xMub9F?= =?us-ascii?Q?SvBj4lkINeXk2EWBqsG1f3S53ez1xS25wmMV2jgBMZCQOHbENxies/WSRsJZ?= =?us-ascii?Q?USMiXOeroJFi7YTpBmo3iKD1+kd6id2jkZgLNyBzfGrh0H2E6T/X14EKiju7?= =?us-ascii?Q?EzcWwYCs/J3A7/9Q6sayLXCWnZLwtP/cOZvcBc9Se28ac2nWmpakPaEsrsFR?= =?us-ascii?Q?vheVjpV+4GUW3jWSq3v3edAO9WzGBugiT0yUO/U7y3SsLWQl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n51xoY05/xA3ak9NBQyRaeZnc+x7/Bhz9/ZkfTeAP+rADpXC?= =?us-ascii?Q?+1OsT6Alf/p8A8MK269jVG88vm9PXJPUiiYKO8gWs+f+bnZaTUekUJLdM5DS?= =?us-ascii?Q?V2yEVOH9ZRmF05eD93NM1oueZUVygC9TX4Tp5zK67lYUtp+FmwGWkNXUBJv3?= =?us-ascii?Q?BV6qU4mk0XAkMLL7lFFuBnICL4EpcFHpUplpohMwQSjL5ih54SXfYIJgqy5E?= =?us-ascii?Q?QnAOp2Hd1VpX0PtfX5xLjU1cqYIUOGvKua9O5c1QEWvOfAVcXSUKja82co/a?= =?us-ascii?Q?/Q=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?JaGWHsthGSjSoiuc4xxAgiulNjVCaROchFJHQ9iTHF5SwXRUkXSRQQqV+lZs?= =?us-ascii?Q?1WXY/JDI0OONlP0X3yWJOmSzaFEAuJiXeJeyz4e7gBNXF4NyTKjmcpU/yJvK?= =?us-ascii?Q?eofMZitBE4Ao1zcaVds1bxu0HhfYuFS9v87aDZ1eI1ppCrQzfGGp01qDsf4E?= =?us-ascii?Q?mCCOMZVvIZBwhhC58bbOhnyU7ZnrygDoppt/7nlWJ9sHGU9Otyzvkx/Cu1lT?= =?us-ascii?Q?e3zZBOEIvK9iryxisa4mxsnSZ6Y5shC32Xe+zAdyla+30J6SY+U6cZa7esjO?= =?us-ascii?Q?BNnJvN0nUt1kdhVcBDKxpY0lNNhCm2ZLI+DVKUA2IPMo1TEk8awf6Z+zLGUp?= =?us-ascii?Q?MKM0nfFAdg/56fkCdExnu/pg62CFbH/NJOET/FsqYdbpR4heytKjRhtrcdir?= =?us-ascii?Q?ua15CleLvD63iIUkeLBtZdxwhPgegvOlexooenq5gttYzu3ka/fgogA1sGxJ?= =?us-ascii?Q?Pacij3HcNE3hVOY2m6pioHJ0K9Az40enWtBYkeFLBWfFgNSs8rx36f8+S7Oa?= =?us-ascii?Q?av7muGYl9LIyguRCE6KFHPYKwANb+ZmT9CpakMu0kLcPPAlAmiX7xLGRx4SW?= =?us-ascii?Q?nSXqr2roevgfkSQ0qD0RGF1XyaMheT8tXJ3j6/HrWjx8n6rqtLmh5nfnJWev?= =?us-ascii?Q?SVRwNsqTggQ10aKnxMK3GcLFcvGKk39S5Ly1At1Rh8MudlNIZFtQxbsBIyMc?= =?us-ascii?Q?cxTsco8dH6SNdeywZMwT16JyOzITFmtHq8B0DN5oCZZg1jkU66MUauvfElHT?= =?us-ascii?Q?o9OFVjv8DvqltAbgwiL5Bg3qiVElBkvwbsId7MqrIxQiDPuHiueqwQgU2AZm?= =?us-ascii?Q?UF0hplfqq1GzMujiOQskeN9+uyDqFXIt/HLOxDSSiAAUdSwQYPvH7l/9JZvQ?= =?us-ascii?Q?NH73eNl4gi0om4j/czmjiEPAHhJUc496hKTMYnAolvZThEC1TAZ3NwW9IY63?= =?us-ascii?Q?i6VDzVZOja3VLGZgjQnLbgZRsTDMPNoQVRk9TU5sNwUhe3quDXMHJn7HQ/l1?= =?us-ascii?Q?LAxhxE7tNn/6csPjARbtIOITOO4gXY1R8p4i9UMeea5pnlBpNWz9xB070Lxu?= =?us-ascii?Q?dzlDxSG81zn+m8YRhAnaEBWnKIli52qghpITxjAJ0WwkeSHItWCJ2ofZwOZW?= =?us-ascii?Q?2w1x7S3ynPRjWZcCkMRY4xSPpUjP1XMjhL8CMTDx/U0dl5W0sseAZM8=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f44a9081-e8df-4f30-0bec-08db1e5f0db1 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:23:00.6927 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KMIo/bgoyNsTZ1lgo/43aPP8sfgaPpB+LbRV0FqIUGHFofgRqLPLGZ9URpb2VjKUGR/WcN4YSZ87XG/loYgZYAinxrTJCSr5uF0E30jutH8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060145 X-Proofpoint-GUID: kMkOYiVsPQWLEPLy29RjK4JRFOxL9poZ X-Proofpoint-ORIG-GUID: kMkOYiVsPQWLEPLy29RjK4JRFOxL9poZ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When CPU or memory is hot un/plugged, or off/onlined, the crash elfcorehdr, which describes the CPUs and memory in the system, must also be updated. The segment containing the elfcorehdr is identified at run-time in crash_core:crash_handle_hotplug_event(), which works for both the kexec_load() and kexec_file_load() syscalls. A new elfcorehdr is generated from the available CPUs and memory into a buffer, and then installed over the top of the existing elfcorehdr. In the patch 'kexec: exclude elfcorehdr from the segment digest' the need to update purgatory due to the change in elfcorehdr was eliminated. As a result, no changes to purgatory or boot_params (as the elfcorehdr=3D kernel command line parameter pointer remains unchanged and correct) are needed, just elfcorehdr. To accommodate a growing number of resources via hotplug, the elfcorehdr segment must be sufficiently large enough to accommodate changes, see the CRASH_MAX_MEMORY_RANGES description. This is used only on the kexec_file_load() syscall; for kexec_load() userspace will need to size the segment similarly. To accommodate kexec_load() syscall in the absence of kexec_file_load() syscall support, and with CONFIG_CRASH_HOTPLUG enabled, it is necessary to move prepare_elf_headers() and dependents outside of CONFIG_KEXEC_FILE. Signed-off-by: Eric DeVolder --- arch/x86/Kconfig | 13 ++++ arch/x86/include/asm/kexec.h | 15 +++++ arch/x86/kernel/crash.c | 119 ++++++++++++++++++++++++++++++++--- 3 files changed, 140 insertions(+), 7 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 3604074a878b..2ca5e19b8f19 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2119,6 +2119,19 @@ config CRASH_DUMP (CONFIG_RELOCATABLE=3Dy). For more details see Documentation/admin-guide/kdump/kdump.rst =20 +config CRASH_HOTPLUG + bool "Update the crash elfcorehdr on system configuration changes" + default n + depends on CRASH_DUMP && (HOTPLUG_CPU || MEMORY_HOTPLUG) + help + Enable direct update to the crash elfcorehdr (which contains + the list of CPUs and memory regions to be dumped upon a crash) + in response to hot plug/unplug or online/offline of CPUs or + memory. This is a much more advanced approach than userspace + attempting that. + + If unsure, say Y. + config KEXEC_JUMP bool "kexec jump" depends on KEXEC && HIBERNATION diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index a3760ca796aa..1bc852ce347d 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -212,6 +212,21 @@ typedef void crash_vmclear_fn(void); extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss; extern void kdump_nmi_shootdown_cpus(void); =20 +#ifdef CONFIG_CRASH_HOTPLUG +void arch_crash_handle_hotplug_event(struct kimage *image); +#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event + +#ifdef CONFIG_HOTPLUG_CPU +static inline int crash_hotplug_cpu_support(void) { return 1; } +#define crash_hotplug_cpu_support crash_hotplug_cpu_support +#endif + +#ifdef CONFIG_MEMORY_HOTPLUG +static inline int crash_hotplug_memory_support(void) { return 1; } +#define crash_hotplug_memory_support crash_hotplug_memory_support +#endif +#endif + #endif /* __ASSEMBLY__ */ =20 #endif /* _ASM_X86_KEXEC_H */ diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 305514431f26..c9aaec9de775 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -42,6 +42,21 @@ #include #include =20 +/* + * For the kexec_file_load() syscall path, specify the maximum number of + * memory regions that the elfcorehdr buffer/segment can accommodate. + * These regions are obtained via walk_system_ram_res(); eg. the + * 'System RAM' entries in /proc/iomem. + * This value is combined with NR_CPUS_DEFAULT and multiplied by + * sizeof(Elf64_Phdr) to determine the final elfcorehdr memory buffer/ + * segment size. + * The value 8192, for example, covers a (sparsely populated) 1TiB system + * consisting of 128MiB memblocks, while resulting in an elfcorehdr + * memory buffer/segment size under 1MiB. This represents a sane choice + * to accommodate both baremetal and virtual machine configurations. + */ +#define CRASH_MAX_MEMORY_RANGES 8192 + /* Used while preparing memory map entries for second kernel */ struct crash_memmap_data { struct boot_params *params; @@ -173,8 +188,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs) crash_save_cpu(regs, safe_smp_processor_id()); } =20 -#ifdef CONFIG_KEXEC_FILE - static int get_nr_ram_ranges_callback(struct resource *res, void *arg) { unsigned int *nr_ranges =3D arg; @@ -246,7 +259,7 @@ static int prepare_elf64_ram_headers_callback(struct re= source *res, void *arg) =20 /* Prepare elf headers. Return addr and size */ static int prepare_elf_headers(struct kimage *image, void **addr, - unsigned long *sz) + unsigned long *sz, unsigned long *nr_mem_ranges) { struct crash_mem *cmem; int ret; @@ -264,6 +277,9 @@ static int prepare_elf_headers(struct kimage *image, vo= id **addr, if (ret) goto out; =20 + /* Return the computed number of memory ranges, for hotplug usage */ + *nr_mem_ranges =3D cmem->nr_ranges; + /* By default prepare 64bit headers */ ret =3D crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), add= r, sz); =20 @@ -272,6 +288,7 @@ static int prepare_elf_headers(struct kimage *image, vo= id **addr, return ret; } =20 +#ifdef CONFIG_KEXEC_FILE static int add_e820_entry(struct boot_params *params, struct e820_entry *e= ntry) { unsigned int nr_e820_entries; @@ -386,18 +403,42 @@ int crash_setup_memmap_entries(struct kimage *image, = struct boot_params *params) int crash_load_segments(struct kimage *image) { int ret; + unsigned long pnum =3D 0; struct kexec_buf kbuf =3D { .image =3D image, .buf_min =3D 0, .buf_max =3D ULONG_MAX, .top_down =3D false }; =20 /* Prepare elf headers and add a segment */ - ret =3D prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz); + ret =3D prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz, &pnum); if (ret) return ret; =20 - image->elf_headers =3D kbuf.buffer; - image->elf_headers_sz =3D kbuf.bufsz; + image->elf_headers =3D kbuf.buffer; + image->elf_headers_sz =3D kbuf.bufsz; + kbuf.memsz =3D kbuf.bufsz; + +#ifdef CONFIG_CRASH_HOTPLUG + /* + * Ensure the elfcorehdr segment large enough for hotplug changes. + * Account for VMCOREINFO and kernel_map and maximum CPUs. + */ + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + pnum =3D 2 + CONFIG_NR_CPUS_DEFAULT + CRASH_MAX_MEMORY_RANGES; + else + pnum +=3D 2 + CONFIG_NR_CPUS_DEFAULT; + + if (pnum < (unsigned long)PN_XNUM) { + kbuf.memsz =3D pnum * sizeof(Elf64_Phdr); + kbuf.memsz +=3D sizeof(Elf64_Ehdr); + + image->elfcorehdr_index =3D image->nr_segments; + + /* Mark as usable to crash kernel, else crash kernel fails on boot */ + image->elf_headers_sz =3D kbuf.memsz; + } else { + pr_err("number of Phdrs %lu exceeds max\n", pnum); + } +#endif =20 - kbuf.memsz =3D kbuf.bufsz; kbuf.buf_align =3D ELF_CORE_HEADER_ALIGN; kbuf.mem =3D KEXEC_BUF_MEM_UNKNOWN; ret =3D kexec_add_buffer(&kbuf); @@ -410,3 +451,67 @@ int crash_load_segments(struct kimage *image) return ret; } #endif /* CONFIG_KEXEC_FILE */ + +#ifdef CONFIG_CRASH_HOTPLUG + +#undef pr_fmt +#define pr_fmt(fmt) "crash hp: " fmt + +/** + * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes + * @image: the active struct kimage + * + * The new elfcorehdr is prepared in a kernel buffer, and then it is + * written on top of the existing/old elfcorehdr. + */ +void arch_crash_handle_hotplug_event(struct kimage *image) +{ + void *elfbuf =3D NULL, *old_elfcorehdr; + unsigned long nr_mem_ranges; + unsigned long mem, memsz; + unsigned long elfsz =3D 0; + + /* + * Create the new elfcorehdr reflecting the changes to CPU and/or + * memory resources. + */ + if (prepare_elf_headers(image, &elfbuf, &elfsz, &nr_mem_ranges)) { + pr_err("unable to prepare elfcore headers"); + goto out; + } + + /* + * Obtain address and size of the elfcorehdr segment, and + * check it against the new elfcorehdr buffer. + */ + mem =3D image->segment[image->elfcorehdr_index].mem; + memsz =3D image->segment[image->elfcorehdr_index].memsz; + if (elfsz > memsz) { + pr_err("update elfcorehdr elfsz %lu > memsz %lu", + elfsz, memsz); + goto out; + } + + /* + * Copy new elfcorehdr over the old elfcorehdr at destination. + */ + old_elfcorehdr =3D kmap_local_page(pfn_to_page(mem >> PAGE_SHIFT)); + if (!old_elfcorehdr) { + pr_err("updating elfcorehdr failed\n"); + goto out; + } + + /* + * Temporarily invalidate the crash image while the + * elfcorehdr is updated. + */ + xchg(&kexec_crash_image, NULL); + memcpy_flushcache(old_elfcorehdr, elfbuf, elfsz); + xchg(&kexec_crash_image, image); + kunmap_local(old_elfcorehdr); + pr_debug("updated elfcorehdr\n"); + +out: + vfree(elfbuf); +} +#endif --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 963C8C61DA4 for ; Mon, 6 Mar 2023 16:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbjCFQ0S (ORCPT ); Mon, 6 Mar 2023 11:26:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjCFQZ5 (ORCPT ); Mon, 6 Mar 2023 11:25:57 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18438CA09 for ; Mon, 6 Mar 2023 08:24:46 -0800 (PST) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326CwrCj002568; Mon, 6 Mar 2023 16:23:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=y9RXT6YQI6qfXYeSiTIBV2erHTqpwWSMOfMIqjcVYfA=; b=A2w241elpR2eE5PFGau6bpO0ip1nbu4qcAU6VYXwk783Dhwjt3DeS8cWnbqOvwayiUr7 HIDl+RrWNo/IbqzZz2b57E7w3VOUCtUEWCwx0xxnmpDky+9cajfdC0XQIbgsi6Vsh+L4 B11RWuBj3e1RCAz3Pz0OJxC/CV/gyrEvEDyn8vFSLpV40AFEcTIvv99sHLsXZmXGXNkG fcMfVb/8LP9RjCDqpInGXSA5qhH36XHBXJ85hR7XPZgiq0U6QIUlS1ahGOHpYLrT00wO Attc69jdvnhQzINAa8MLC923qnmEIFxZ01YknxsV55mnizND1IKi3EZEw0QxZEmW95P/ kA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p417cbavx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:10 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326G3Xj8012362; Mon, 6 Mar 2023 16:23:10 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u2gfbhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eps/GSjvs6r9YUQmmhKHfJhdP7ZfNPcv6DmIZuW7UufnOyI0erGBKNudG2dSH+WSuDpdnvVPB4e3zCQKTYfjwQqp2uJwYG09hkVFKMx7cdFreLxz7s01TwsBr8yM8dIufKWgfWVfOvT9z2kxYispkWmFxc3n0rQM/O03XoZt1OSZWadLoPNKdlnp7POOO2D5HuWV9aybaXUS+Nl5sgjTHXufjXrNf7epFiIGFitxKMqUa3vEEnCIOu37OHel6cPAcG19oQcHE0rrbbfuwNOs/nrmKydQqblYrzvxVjO7BGoAqTo7TjCLCI3QWDYvtkBYRUKojgUKhJ4+VBDyKZSsIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y9RXT6YQI6qfXYeSiTIBV2erHTqpwWSMOfMIqjcVYfA=; b=Hd7UJmQY1Mgt6iO3919Nn7iiWP5wsks5H6+/kjIFTDP/OioHJv5LL9A6OYGkn8VIshNbNwEfMRpmqVkpIpsAw+Iurqa+1xghDyKDK7mdCsoodqcV7Lu+uJLcP+oZkT0CxfY93VKhUNqv9WbRmZ3syv6YnxlmjGNv/NgbjkfeO6yIkzMk/f1QqZF4g86X/INmkBr6w1bKueE5jYyu4tivMEtodYMyceXtFrl/iMSezwC/4xQ5Xm+8Y8U7KCCwlJc9VBhumSYWSpLI94f4rPK8d3PJV6v0MA7DU0qZN2UKtKh2c5iQpFsWa9wyLZF/phYVWe49Ze4izqD0/JDM7Id2Xg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y9RXT6YQI6qfXYeSiTIBV2erHTqpwWSMOfMIqjcVYfA=; b=z+uEfA0xqqKV9SMomjnU4DE3slae7v96B3RooJEk4qxCxxN9VJysax9VibcQOOFoa4Dk78+okKqVbsTCp1XpbxBqS7WA/OrFsZdkIQA/m9Ro2WtOTrIasKLyzJSR4dHvcqtZ+wQSI4fy/tzm6UkruHBFzXkaFUiAdDplZha0qPs= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:23:07 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:23:07 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 6/7] crash: change crash_prepare_elf64_headers() to for_each_possible_cpu() Date: Mon, 6 Mar 2023 11:22:27 -0500 Message-Id: <20230306162228.8277-7-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P265CA0162.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::20) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: be4bee16-8bc0-4d7b-403a-08db1e5f119d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I/CIBurnTVBm16WDeY6kMnPIf4P78GiZZfnRwW86Kp8Sd/eDtZVCJVqjePpycUn/tOeMGSrUR6teBjWoEvojOjTX5DIQ4KIzAJbOHtc1Dbi+EiOaF/G6pwARhVcE3qcLXDKcjP0T1EJVhAP4oIp97FMtBR4vqtYpl+BDucN3JjIMQmBJ2trJeggfzN6Rv8CJmEZLqMyH/DJMnNnBQ6jpzh+HwGgg501IAaR869o+K1IWmuCaPQuZBT1oF6dN1aFZRr5xy4bzV4Yqv0hETfRd81Y46LmmGtdHzLGzSlkIkWRSl/BVhezLRoMSL375yQkZNMqOK1MBv05D4AnllpTfQU9u0yHCxEkWtjwJJCCw4alGRYOx4vXqq5TMSh7uZN+G3v72B8lpCqUNMHK6EoT6W7XUPIoMssFnPSwwoSMRqP2ZnTflxXNjoi/SM6lj+oeSomqHwcsDXu03L8FBUYzgydxLwIbR6Kv9YvSP7t3CB8sx4Ecy7ZOQY1zNRZGcub6efCyj6ILeAasMl5QcI7Lkrdf/XnSvmD/5DYb4h5tSoJc9mfr+rJSzUuWobMOCZyEksrKpDLwvTquXk41D69cdvlrK01SgllPYis3QeVCIhqeAASUX6Vkol2kJpFcdElZke+Zoe3hZRo9IWQDulLhbDw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(38100700002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?nTCNfA8ukLpcaviO4FVWpZspORCf6G1YzfTDf2xhMaDlzyL6jVbhl2/L7LZ1?= =?us-ascii?Q?0atIjiAkcnITK1+dMM9b/JInI4SxmgtSg8kx5PWIaifp8reKNiIk/hcPfPjN?= =?us-ascii?Q?aexj7i1bwnQNQiyHJQp6jStgRb0gBCIbRx4vaAApBuKA4nE9xP9tW8CioOCW?= =?us-ascii?Q?z3BliQONXUaMoK3ZHDSHy7lP49t86mh97qNVTCVA4E5dKPzO0gjSOTRj2qmn?= =?us-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MUBws4GddknHVKFojY2YcGNaHek?= =?us-ascii?Q?cO4LPdJhkxYE2kdVxMeqgtL6/N3E7TYb2dd3byxQJUt/ihl6KfdnT+Jy4XCA?= =?us-ascii?Q?NWPe9wHufVSVmRiJ19Yjud2C3BvCwyYSuEY4dCTnguJajOnnQ54wY7M05Llz?= =?us-ascii?Q?nPfhuOehsy10EYzu+VGznBPWiuZa7LHDHNjw25/ptqOznZ/vzJvNibgfYFiz?= =?us-ascii?Q?lspdeFjXSYrAi+MolJ+h1qJNTt3gayjBLCUC1ieLjAiM7maVvLo5fulU3OGq?= =?us-ascii?Q?ah/xdZ3gLTWxjcFcLfMGUaUqtELz9elv6mA/li0mc/JNsnn1/GKMkc6rD7Q8?= =?us-ascii?Q?Kf9Mvc9+8x5XxAVEO8sEIwX80fZgz9xfe305zNwilhu4iaRts92IVzTZXz55?= =?us-ascii?Q?GmkscRqKqx6P3ksAgSxfR6pD9R0dpWWgqbwzoBeGM6tN20Y1dURvwZl7qM1F?= =?us-ascii?Q?7i0ooqUNez6HzWeXyRjSIj5OIQ0HsPTwV58XFfmowxIkhX91a/k4ZfCbGQJK?= =?us-ascii?Q?/Q=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?mRxK+B/mwAK9LUFDb5eTm4rJyGbQnkEgiYWeMqKOpnxBxVxBTtl9hr7+4ROt?= =?us-ascii?Q?wS6PjQ4VMPWJtsvazc+kfB7X6oJGhRXwEMdmlTeFVFyTvnEIOnQpyAwDrRgg?= =?us-ascii?Q?1uGK9gSFakBL6sHofdGIQ6np6AjidfeUVPhc+BqimHeZ7I5ZvzoSvSh7LdXs?= =?us-ascii?Q?kl7/BytwYx9LkMYSIi+qMjSoD+4cFsoA1qMYGhRteIkIvw4/i3Cw/5+eK+ke?= =?us-ascii?Q?kGrzvY/geSWJCGD2VimgSa7OnA2Xv1X/8SCzGquqZaG7D4Bjig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+Lfd3tfPkRsxaw/3qyqaBMjaiVIK9oY=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: be4bee16-8bc0-4d7b-403a-08db1e5f119d X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:23:07.2270 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UZIGccj6M/chIdIANF/Py6H6koa9Vb2oU5ypbH3zgG62sdWKtuuVol6/IzRj7cjJai/Qf/73EJxNmcgEj+uFs6W+YEp+nLTDvoILvi88APk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060145 X-Proofpoint-GUID: ewlG8ZhyAzFce90EDH26uJe3U8OS8hNV X-Proofpoint-ORIG-GUID: ewlG8ZhyAzFce90EDH26uJe3U8OS8hNV Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function crash_prepare_elf64_headers() generates the elfcorehdr which describes the cpus and memory in the system for the crash kernel. In particular, it writes out ELF PT_NOTEs for memory regions and the cpus in the system. With respect to the cpus, the current implementation utilizes for_each_present_cpu() which means that as cpus are added and removed, the elfcorehdr must again be updated to reflect the new set of cpus. The reasoning behind the change to use for_each_possible_cpu(), is: - At kernel boot time, all percpu crash_notes are allocated for all possible cpus; that is, crash_notes are not allocated dynamically when cpus are plugged/unplugged. Thus the crash_notes for each possible cpu are always available. - The crash_prepare_elf64_headers() creates an ELF PT_NOTE per cpu. Changing to for_each_possible_cpu() is valid as the crash_notes pointed to by each cpu PT_NOTE are present and always valid. Furthermore, examining a common crash processing path of: kernel panic -> crash kernel -> makedumpfile -> 'crash' analyzer elfcorehdr /proc/vmcore vmcore reveals how the ELF cpu PT_NOTEs are utilized: - Upon panic, each cpu is sent an IPI and shuts itself down, recording its state in its crash_notes. When all cpus are shutdown, the crash kernel is launched with a pointer to the elfcorehdr. - The crash kernel via linux/fs/proc/vmcore.c does not examine or use the contents of the PT_NOTEs, it exposes them via /proc/vmcore. - The makedumpfile utility uses /proc/vmcore and reads the cpu PT_NOTEs to craft a nr_cpus variable, which is reported in a header but otherwise generally unused. Makedumpfile creates the vmcore. - The 'crash' dump analyzer does not appear to reference the cpu PT_NOTEs. Instead it looks-up the cpu_[possible|present|onlin]_mask symbols and directly examines those structure contents from vmcore memory. From that information it is able to determine which cpus are present and online, and locate the corresponding crash_notes. Said differently, it appears that 'crash' analyzer does not rely on the ELF PT_NOTEs for cpus; rather it obtains the information directly via kernel symbols and the memory within the vmcore. (There maybe other vmcore generating and analysis tools that do use these PT_NOTEs, but 'makedumpfile' and 'crash' seems to be the most common solution.) This change results in the benefit of having all cpus described in the elfcorehdr, and therefore reducing the need to re-generate the elfcorehdr on cpu changes, at the small expense of an additional 56 bytes per PT_NOTE for not-present-but-possible cpus. On systems where kexec_file_load() syscall is utilized, all the above is valid. On systems where kexec_load() syscall is utilized, there may be the need for the elfcorehdr to be regenerated once. The reason being that some archs only populate the 'present' cpus in the /sys/devices/system/cpus entries, which the userspace 'kexec' utility uses to generate the userspace-supplied elfcorehdr. In this situation, one memory or cpu change will rewrite the elfcorehdr via the crash_prepare_elf64_headers() function and now all possible cpus will be described, just as with kexec_file_load() syscall. Suggested-by: Sourabh Jain Signed-off-by: Eric DeVolder --- kernel/crash_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index dba4b75f7541..537b199a8774 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -365,7 +365,7 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, = int need_kernel_map, ehdr->e_phentsize =3D sizeof(Elf64_Phdr); =20 /* Prepare one phdr of type PT_NOTE for each present CPU */ - for_each_present_cpu(cpu) { + for_each_possible_cpu(cpu) { phdr->p_type =3D PT_NOTE; notes_addr =3D per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); phdr->p_offset =3D phdr->p_paddr =3D notes_addr; --=20 2.31.1 From nobody Sat Apr 11 11:41:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE115C61DA4 for ; Mon, 6 Mar 2023 16:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbjCFQ0N (ORCPT ); Mon, 6 Mar 2023 11:26:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbjCFQZk (ORCPT ); Mon, 6 Mar 2023 11:25:40 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5EEA38B7C for ; Mon, 6 Mar 2023 08:24:42 -0800 (PST) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326CxFvT031462; Mon, 6 Mar 2023 16:23:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=TMa2NJx33yIc4VOtYE8TqZmk60QFOgD8Z7Kqzm24ldY=; b=G5pi+9WnJnqHD6ZXpdoEf+pOOASWbl3NiQN2REyDkkOmXytYmB6EupjxmTRlSOtYZChq Fe/g/PjuhG7H4u+5e5iZaZqNai8TbtW/g/BHhrF9N6PiGPnXc8EG/OmZ1NxHthFKK0+P qwpNayO1e1qgDi5yHVHZWutv5Z6Q7Gfq9hfLkqiWRAVzcIX/CkDkBGmErGLcO30XYoCx +Q71FY/sQJeU1zXUHGQZhG5MmJeMSRZPVRCcyUGkdKQbp+FKXq0avPCqUEjM9wz0RfmY Nbu38m8gmwkApPH9ypXkYppishW4ea4aL0sxfRxJ939WviK6dZLLAp+2rB9g+fCGuWWi iw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p4180ua5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:16 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 326G50X7026894; Mon, 6 Mar 2023 16:23:16 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3p4u1dq6n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Mar 2023 16:23:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=coLXWh+jLpuGw5ayQws+70TLdatPujd5jvb+yEboChoz6KqtJt+8Xd1zFp1Lxk/FxRmUoKaFi/E0T8YnUSVrCI7jHAWZyWcch8FvFGIrbZjrLBtrWc60DTJ/zca0qZXZ6OaLKURjwu4saGTHtEAmXxp8gcLIhBGc13/UWC0q4aJiZJtzA7X+eYVE/nuD8+/edtUgNUB/6HK6dNs9502OKXZzFfvNFjIm9n3ClfHsFDuzq7R2W3g58eA3vdZeclEAFPBW71goPaEXgu35c2IIZH0oK3/l2GXNOeiZpolnpP3CZUGfO64WCH2M5PMoVMQJh+bB2pMtBGxdf81l4S4uTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TMa2NJx33yIc4VOtYE8TqZmk60QFOgD8Z7Kqzm24ldY=; b=BW6WSJ0k0Uzqbiq8VOwdSpQmHiy9Dk0HL39VjSZKTG2/bYk4uvN/Pn1YlbSAMCLYNmjXwd8+S9plciYQZEIZXaBoVPN6crnkbVAKiwcQNr86aCVKUEZT+rf3u+JFGlXVK4YLj3eVWLx9fZ9Tv7GrPAYb2PJijdwkpXDH4w8I4395TxFob2ZZq0dBup/dM4KchrB4lGSwQ7jXZal0GDg8I2Y5F8KFT/4Kh7+S/KRKFS7OES0ILNdr6q/aE1mUrgxA0Q71wlT9Pd1pZwyK8sEq9YB+i/CF58WdU4y50q6Zy+s0hWthuOYNOsloy9CG/iGfU4KA7N+/+FcZYqlncTNnsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TMa2NJx33yIc4VOtYE8TqZmk60QFOgD8Z7Kqzm24ldY=; b=gTEI+YagtEL2JaITbebpn9YvNlrPmPl2wyew9m4hCyuw0kPolBny90twPuj6GgS37qj5GfvaKmJFfdCnEGrIuMqciytZfDB2xluSWja7FtZrRTl0xdza3gPzF3EBtqMxarlj9L+Z8L9/D2b3vBLN6CWVhnx7O1xsBfLjY8Umo3U= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by PH7PR10MB6530.namprd10.prod.outlook.com (2603:10b6:510:201::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.28; Mon, 6 Mar 2023 16:23:13 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::671e:6486:6996:c38%8]) with mapi id 15.20.6156.028; Mon, 6 Mar 2023 16:23:13 +0000 From: Eric DeVolder To: linux-kernel@vger.kernel.org, x86@kernel.org, kexec@lists.infradead.org, ebiederm@xmission.com, dyoung@redhat.com, bhe@redhat.com, vgoyal@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, nramas@linux.microsoft.com, thomas.lendacky@amd.com, robh@kernel.org, efault@gmx.de, rppt@kernel.org, david@redhat.com, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, eric.devolder@oracle.com Subject: [PATCH v19 7/7] x86/crash: optimize cpu changes Date: Mon, 6 Mar 2023 11:22:28 -0500 Message-Id: <20230306162228.8277-8-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230306162228.8277-1-eric.devolder@oracle.com> References: <20230306162228.8277-1-eric.devolder@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0076.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:190::9) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|PH7PR10MB6530:EE_ X-MS-Office365-Filtering-Correlation-Id: f3d214e3-49c5-4c58-dfe9-08db1e5f1530 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9lW092tEuXsdOVAH5tctvxC6JfCADRJXCuuRAU0HGJGjgiuu6uhit6NsN7IpHz5mrCA9kYjRPL+R4hoav35k/drvUmW7EaoAMdYqJOiZfS/uFiA9+YOlFh+zFu9kHufchbfUYnyNenEeIqz0e7Rtq8S8cu6etgZbly0/opMOgNFQtHLftxncPlIwbWdZDxYjoOTOU2u7CU28pl/HXADhsuXgnknUoqOHyOeq1236J7YOzg5tdid8Z4HNenz8Ustv6o1aJVxPGcWe83qj9IDWvQcvPJsBMTqDC0mfH5RZNne55jvy7s5yaqW2YzRzzfeS1dnRIqzP9EO/KtioCbU6z2uLS8kCZkcNBaXNANctAv0YGFQKX+WtXWsqZzAVcCyq3AZOE5WflnpxpJxZYzsgiB4xWe6fZjtOVnHRf3a/hGZnTtZIf4kcAxmNL8G4uPMU9cQLCL2RFvO/hh5mwwTQvwK0Kqha701/7nZqIRUAiCMjHE0czNJGO4ozUOl6okNy6ArxU8NfsFneDiLeeZKukDpqiFuE3xUYmHqjsB1x5PgFryNW4gYc2bF8EO931PbeaUSRlhHSapO7zHEgDV9YjNEES7yjPmfgxjhnd9lqRTNn0Jr+oxP8PEKicGWHF2Kavp8Vd9pZVoUhiIvEkj1uug== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR10MB4531.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(396003)(136003)(376002)(39860400002)(366004)(451199018)(66946007)(66476007)(5660300002)(4326008)(66556008)(41300700001)(7416002)(8936002)(8676002)(86362001)(36756003)(6486002)(478600001)(1076003)(6512007)(186003)(26005)(107886003)(6506007)(6666004)(2616005)(2906002)(316002)(38100700002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iXuTQr0+5Uw/Ms1EjhBNOYjAeNSYvHaZmA2jaTiUsfENsqaunp/1iVD6+kQJ?= =?us-ascii?Q?yWSA91sX2qHYZTprP69kfr3V28J6bu4qVhlWG1I1xURTy41KMDAwrFlv0bVU?= =?us-ascii?Q?Th/lUT+DG8S+LGXC3sId+amYNbEC1zG8aNa23ePeTFWqybvSzBcOC90XoE+r?= =?us-ascii?Q?zJaldCgoLQCcRo+/oymKAJX0Tvp/w41hWclcwfwi+7JKPSupCGEbWvNsLXsw?= =?us-ascii?Q?wKPQuCSoua5wVUohEoudPtediHcrQFKGSPm5nLSfSEP8InXSmLWYkGf5Jge5?= =?us-ascii?Q?Tv4d2EHdYHcpVuU5UeuODIlvUySI/BTjuj3+aCVvbezkLz824ooiyFRyqh+B?= =?us-ascii?Q?uTP/FPwydChPrO5d790ywQqUMcikyygnIcC4F26JVIykV6EsIR/nr15nF2VQ?= =?us-ascii?Q?BtSpN1NH6tcoMe9fL9BPFnIJxc2Da+VT2LOynN+4wkbyXanjGUCx9gkHA0uT?= =?us-ascii?Q?4LZDZhvUAnIGGTA12Z1lKZi7/pismtkExE9MhNKFgftX29S1c/HEnBb0MYWT?= =?us-ascii?Q?yqZEiT31QGmV6VkCAtasRYhH+9EZ9lhCclpIYUpFdigU4HFLHPJXs6cv+NZe?= =?us-ascii?Q?rmvV2tu3NuKDSBbW684D2Qtd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gIgMgqPvRWij3H67R6b2PZj+xJX3Ve+DfkKsILxDgSiD7lMUK3MadLdB+?= =?us-ascii?Q?OQqXgJrZnF6t5oz3yXCKJDaHMtK+Sjf1EPrACGdF4PU4m3Hqah+lUu8bvJ9E?= =?us-ascii?Q?9Q=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: =?us-ascii?Q?EVMKuulZ/g0wuul/IXV7OUe+hHptEGg1KIk8t4gDbhZoajbgw4/yyKMPbyWC?= =?us-ascii?Q?o1ct/OztRvVB6HwBeNtoF+BOKKOQCeMec5qEqp0xj53hU8qvtRVxnXpWkLHw?= =?us-ascii?Q?uh3mL5jfx9lMJngQeikn8SIg7DYQv6eCPy/2czb881ipMcNBbLvZR7QZEBOP?= =?us-ascii?Q?Iiv2GeUZgIq3vgpBP8n9s8bBXMDuxlLwzZM90CTjVHDfMoeBbCpyAQ8sC6OJ?= =?us-ascii?Q?nwkZHx+Ea/iH4q7d/8iOzFEQkyU4r3s5vhQDH3/uWKf+Brh0GaIWt134tMA8?= =?us-ascii?Q?jWrot+9wkUyXNcDYO9r4hNwWGCb9QHeUMuODA+0yhWgOezJ0FmuVw52SlMgD?= =?us-ascii?Q?+E5PDXhbwPgzlSBIOfbGAMaonhKyIBYi2tXGs4it5loiHrlv32szoFFNpABD?= =?us-ascii?Q?JMjKFR8OmOT1m6u9XsviYcLc6b6qv/5ISMLPSKlPSmNlmawUKJrgFcMqkjLg?= =?us-ascii?Q?Z2ajugRyCCstLmL98m923HubB4yA4HNDB4VaxWHT01LPKaLhAUT8NCh2ZO+D?= =?us-ascii?Q?WBJ0ef7gMOmoe+ISLjeeudyd0yM0Qq9YLiAJ8/W8dEetCVEuWv2gs4ZzpsU3?= =?us-ascii?Q?0lTKBRDWnJXC/ouMMo3q2DmiCiWYkeqpH1nQ0JcIN2COE5lxtCNEUft6IOnv?= =?us-ascii?Q?YA9a8LvG9bkA5kg2u8xqODoQDwKOr5sUDHRGfrOaB4CQcIdHiCfrA1rM2F2F?= =?us-ascii?Q?GFs3M4gQEIkaRejKD3rCbL53FYHqM4r70II+x3NEu6JJpJ33/OMB84Z8YpP1?= =?us-ascii?Q?+mBR/LPhBBcTSRSq2rVh1VQZbvtL8g3JK78yCUguYi+lWzf+zabCW2FY+U9t?= =?us-ascii?Q?J/eDgjiFpyrVKC+TXRUEOVW5oUuXp23MupMc+B0Rnzsf0RB+3ICHztAczaMl?= =?us-ascii?Q?BTpPirST8erlMxJOsAL3IFHebCGP69GJTeHw7deO3MN7rKn7wwEKX5k4wFz2?= =?us-ascii?Q?DbAjrqcg+qH6VZjqdax0z+JSgho/9FJ39wwFzzwn5dy4kKCd9Kzl+6MCVhcq?= =?us-ascii?Q?Z/AzC3DcB8QdOQNTZqqguN1yjFmSq2K+8tBfe+Uc5m5B/WQdT2Zv3MqpmbOJ?= =?us-ascii?Q?OzQ8rNR9SA47PlFB0QcZDze7hHS4heyQ+7C7PUXZ3g4jZjOZjnEijXRSG6y3?= =?us-ascii?Q?5ingZV0zOOrcg0xwtwFTriZEXKKvtWDEaFvWyrNAO0hrDcFuQQV4cOs=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3d214e3-49c5-4c58-dfe9-08db1e5f1530 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2023 16:23:13.2276 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fol9016Zr57xA03kCyhP8Prbljwit4J1TILAcMNHfZlqGh099HEs/vJeIZP2++ceaxDZd9v5pP7dRvKtz2YgdaRgcmbgcLy7fBO7dHLnpG8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6530 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_10,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303060145 X-Proofpoint-ORIG-GUID: 5ieTIlNYOlekrNhT-pNfW7FgT5wQo6KA X-Proofpoint-GUID: 5ieTIlNYOlekrNhT-pNfW7FgT5wQo6KA Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch is dependent upon the patch 'crash: change crash_prepare_elf64_headers() to for_each_possible_cpu()'. With that patch, crash_prepare_elf64_headers() writes out an ELF cpu PT_NOTE for all possible cpus, thus further cpu changes to the elfcorehdr are not needed. This change works for kexec_file_load() and kexec_load() syscalls. For kexec_file_load(), crash_prepare_elf64_headers() is utilized directly and thus all ELF cpu PT_NOTEs are in the elfcorehdr already. This is the kimage->file_mode term. For kexec_load() syscall, one cpu or memory change will cause the elfcorehdr to be updated via crash_prepare_elf64_headers() and at that point all ELF cpu PT_NOTEs are in the elfcorehdr. This is the kimage->elfcorehdr_updated term. This code is intentionally *NOT* hoisted into crash_handle_hotplug_event() as it would prevent the arch-specific handler from running for cpu changes. This would break PPC, for example, which needs to update other information besides the elfcorehdr, on cpu changes. Signed-off-by: Eric DeVolder Reviewed-by: Sourabh Jain --- arch/x86/kernel/crash.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index c9aaec9de775..82ea2b1bdc61 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -471,6 +471,16 @@ void arch_crash_handle_hotplug_event(struct kimage *im= age) unsigned long mem, memsz; unsigned long elfsz =3D 0; =20 + /* As crash_prepare_elf64_headers() has already described all + * possible cpus, there is no need to update the elfcorehdr + * for additional cpu changes. This works for both kexec_load() + * and kexec_file_load() syscalls. + */ + if ((image->file_mode || image->elfcorehdr_updated) && + ((image->hp_action =3D=3D KEXEC_CRASH_HP_ADD_CPU) || + (image->hp_action =3D=3D KEXEC_CRASH_HP_REMOVE_CPU))) + return; + /* * Create the new elfcorehdr reflecting the changes to CPU and/or * memory resources. --=20 2.31.1