From patchwork Wed May 3 22:41:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1664393vqo; Wed, 3 May 2023 16:06:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VMtUj7NNgFLhZJ9pULya3NqWu+m136/S0dioxqCe6vq5+3G7J2HbODcFjqJ5BlVzGFJ9G X-Received: by 2002:a05:6a20:7347:b0:d6:7264:f44e with SMTP id v7-20020a056a20734700b000d67264f44emr346952pzc.3.1683155185451; Wed, 03 May 2023 16:06:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683155185; cv=pass; d=google.com; s=arc-20160816; b=h/yVFzaja7LatqfXQoVJYlTvmm7ku1QwJIa8WdQboZInFFHt8vYL7N8YptJeWX5LEF srxSHLN9Y8PxbkzDnFRSnquaEkRZCtsjdL5w2JPswgXUqxlevThyCcsKq2wKDBD/2Oh0 f8IqTszHI8w1b1Qpgty8Ps4LuEf9Qi5MNOzrKXfik7Bt5TljZQFH0InYEbio7fnMVRqm ymzGmYc1gABZ8oUsa8YTNBM/F5B8VVQ+h9bOqtMF0G4Hoknnsea3/NCRc/5hehnExq9U f+goIHClgfPvNjYgQBQG22Tzg+E8vL07IKG8s0z5lhXx6VyGuQo0VfnUicC/2KzYGQTo I0nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=xX7GqRjv0l8rGlzfC1g8FDMs0/47L6KjM6D/7AV654E=; b=MHd5W+209r9hsTV7rLEs++5afKrRY65f5qxN9euvYELujGwoiBOxL9tPJ16qXzrmzm bAY+Ds9q8nvSOhxAJEF+kEG+bSPVKqotFzYkQkC/tse+kolhMY4WVbk4ayGL3EyG8Sce MEl3GZjSlKrdFNedBN4eNREVtp1C63fKBR9c3K/yzhczuEEbynL0LYxphSIEIAY35jqZ nEIHtwKgLwNhH0eTvMpQKRX4H7/9KBK6L8EaZcZpy46UMzxQV0fUC+8kFw5i37tUxAIl 8aYJzYTZ34BPqjGxxkR4EuxLxMGIIjpRWwMHc7SGqG7wa83BbONeR2oFm7wlgqIMHCXi uIbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=JjGjdSw1; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="BPI/w1Xs"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r20-20020a63fc54000000b0051b8ec45689si33570217pgk.520.2023.05.03.16.06.10; Wed, 03 May 2023 16:06:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=JjGjdSw1; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="BPI/w1Xs"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbjECWnp (ORCPT + 99 others); Wed, 3 May 2023 18:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjECWnb (ORCPT ); Wed, 3 May 2023 18:43:31 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 443308A68 for ; Wed, 3 May 2023 15:42:53 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HouHj016633; Wed, 3 May 2023 22:41:58 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-2023-03-30; bh=xX7GqRjv0l8rGlzfC1g8FDMs0/47L6KjM6D/7AV654E=; b=JjGjdSw1iphk4Fh1geXACXaKZZQeu/37EuzqmY6z0AD8Eumj+tIscJpRk2AlDgBogUK4 W+OeUNwglUDsmUs1+dcBl1xS8uZ3ipbspVuUW2ChQyzBtCKyUvu4Yeyr+e+kU9koHkk1 CjkK32zZM4twZh9prL6hE3DcYrIrxuJVy3+H3B2GlDLyU61bM/1v4dpa5d1/LY+NQ9PX E0xaTrxSl7t67TaewJg5vmI3++T81O1g8W9u+r2pQvKh9Ah+5XzgBHagAkTHFjLOhEMo 6dKeWYbAnhqJKR95i21R5yZmCo8ykfoup1VOj/17lLczvLdq5nbDmln/k7GF2lg3T5FW 4g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t5frj7x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:41:58 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343LBtBX010262; Wed, 3 May 2023 22:41:57 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp87sg3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:41:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mMb6iCy7CYYcGkQluTDNgzr53Mt3N/u8yg7WUVRbXhOiB/xP3Ckz0qI66glCKZIJwWpD2fnhk6Upsfl4e3HVjNUI/cGNWJLgvXFcsxmmDrycakiinv08BcIa5PFM3wOO0eszqL1eN9ANYMNAY5xaP8qXVeiVSQtLkRPTMuke5FDCuIaYsi9/W6PNikhOrBdz0VHY8tLxf8z0XwQj0IBeUvv4Mqmga0WvgPEbWlsHkOODhXcR69xo/Rd25zun0dR7IRdcAmOmHgpC+v9sj8R1fD0KU8W/EkGuIvdmVKcybaJwdl5zO7vjOJFqiYhGTkwFd+F4/HEXiYcLG47UhO2EKA== 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=xX7GqRjv0l8rGlzfC1g8FDMs0/47L6KjM6D/7AV654E=; b=GDg/GnVwa42janl3ARoH3LLlXdqFQFQ38a5WoaFR8hKzh6vKRm/E9D6J3VpqX2fs21Ng6qmz/tP5KyoVPy78awEq5/Y/JDtHyhTuSw5m/PqPT+xUsWSKriBucJE6Lj66X0f2QL6+487tpwdvLqpbNgrWkGpnskJx139m9VfVfjg/Achz9sMpYe2o1Nfbe+eODWdTdCzhdw5QfG89k3tZBgtRzikkMZznYZzOFMsb02ewCj58MT5nguMoqtdPAdUyaFtxdThcL0yhUmu7ExmOQGsRXkuWFmyemBy/9XQha+LmV2DNoPRdyScs0xstNdM/U7H8/8gi2b74NCnM2u1Rmw== 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=xX7GqRjv0l8rGlzfC1g8FDMs0/47L6KjM6D/7AV654E=; b=BPI/w1Xswahd57VDAMtSeRsH1Eq1uQLX6BeLU+rwIdvJvbwcG+EWLWWefcfW9H5BIj0H2jBN+PNK2Dlfo+vZ7zEkZsKYO5Ct/5B+3LlVRER2lKyESnqB2QDDlnmyI3HzHFyt5j4GcGhGpyhlGQKBgzS5M6NyNTk1Bs0n83E2lE0= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by IA0PR10MB6890.namprd10.prod.outlook.com (2603:10b6:208:432::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.22; Wed, 3 May 2023 22:41:54 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:41: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 v22 1/8] crash: move a few code bits to setup support of crash hotplug Date: Wed, 3 May 2023 18:41:38 -0400 Message-Id: <20230503224145.7405-2-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA9PR13CA0081.namprd13.prod.outlook.com (2603:10b6:806:23::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_|IA0PR10MB6890:EE_ X-MS-Office365-Filtering-Correlation-Id: da01ac87-5e95-4236-f022-08db4c2797f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +FBYnCcpqX7fSFLRkkliwlExAizIr7bffom9K978+aQeO22iBVZ9cYXwBkHATAdjRxdMjHozgS0aISWvzB6M8EpgS3hwyfZlfOAh5yrxDVgZShidQogGktjSquHu4zPtynPcjx+976FZApzPrq40o6SL9ldiyoBd10fBSuE8uyFFCaONkHaTeW5aF8YQvbytTk9vdnMfFfdcNMmN93nsEtvSUBSp2ety2K8t+guwYUvcKwWClP26+Hp1U+JfLv83c28H+WLPGpfxG1AsGNevd4p0LwDbzkw4pLL2j2+SMnKPRfojtKibzG1CvDoC3846KEC2uB4WUNnW7qYgH9ZOyYFf52z/Z0mnrWhJ2vo+vi+2DM1KU66pD+C2Ge5GZFlwyBbo5dHDCmcNOMClxCvO2FzyHQUqWZUASOwWoRDTDXPxRMSak2ry+cdVFoZrkwRqoMmVQmUjDDo2nL6lnu2//BsdowDKHNA8pD7rhUlX81uCct/pJfyQrG3ut0qVz/4qu/nwuGdHq3jXmEZKI4xfmpmTd5NuOS1x2RFTZ9WjbIt5nJMeFzRsDTUVOO7HJMuF 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:(13230028)(39860400002)(396003)(136003)(376002)(366004)(346002)(451199021)(30864003)(2906002)(107886003)(38100700002)(83380400001)(2616005)(6512007)(26005)(1076003)(6506007)(186003)(36756003)(8676002)(8936002)(66476007)(5660300002)(7416002)(316002)(478600001)(4326008)(6666004)(6486002)(86362001)(41300700001)(66556008)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9akAKBlu9wmDCYaN1zW0uCafF8fl7ReGmC5MVOaJ3FhSxhGiZylsGSeVXyQuc+pZC5b+M9OzxVWmulgFvWj6jEmoBu6Hb9x0ILoKqDHvWd/h2Eh9t9MIMHjNvzUUv6wvU8VoA9q5Cz4FyWtD4ASTpUxdY5K7+O66n5yl16p0BIKFqdJo6y/gaOJ1BhPtHMkNdCeNedwthboCLR+figmyoFwifPa8WIdUPN70/nFoEGC2ldx3HOuiZCxB20Q9EN1EMnF3QoaPiAiq6sh47i5kgYz7670+BdRFIcbU3Mr1kV82d3jT6oqaPFxlFJMX5AOGmhrD88fot7lJ9LVoofdjyTUSRHCgOYYBbPqwLDkW40pnfFSn9j+fQaLu5lpMVcYSfd+GPBFiBbyjnKQVQltZdz7jyhAXpAzzUX2ixElaQ9nhGL9M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20Q3gFHlZDr5g8nNzzafpnk9iPW2YacqmdTTnpa85cG70BHuFkCjAehvfEO2cN2wclpNc4+34ww3K4T/4+dOWw+mFN8odYv3DzYtM823WPLjdRDrxt15cUlqbDd28bxhFGDiGmJEqNf0B39nj8JgMRsN9mqdkGhFBYvKFcAuGgswBdRJTxvlNMsGAUnqysp5vVZaQiQa7682NuqXAUZjcj9/hey477beDnyVEzOWfPEu7VNy0fPx1mJz2vj/u+9d7glHIJ8RVB4l9Jj1CyafZPmu0C4UlTKO0EMYZIV3MAQ3RfO8eLox4dMiC1KQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da01ac87-5e95-4236-f022-08db4c2797f1 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:41:54.1902 (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: XMwgYXgccLQjXz5LnaAPfQ1ryMhOgtC4oBZp0dnMRcYAMrl3u6yWfSLquygm++Z/0viVnw7W7Odvx9of8Ap2mu2V7o/pgrGIb3u/qie8/Fo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6890 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: DIHwfYpJNtbv7xZd9c4Aj4lRvle_ODH_ X-Proofpoint-ORIG-GUID: DIHwfYpJNtbv7xZd9c4Aj4lRvle_ODH_ X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764916131674905754?= X-GMAIL-MSGID: =?utf-8?q?1764916131674905754?= 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 Reviewed-by: Sourabh Jain Acked-by: Baoquan He --- 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 22b5cd24f581..811a90e09698 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -105,6 +105,21 @@ struct compat_kexec_segment { }; #endif +/* 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_kernel_map, + void **addr, unsigned long *sz); + #ifdef CONFIG_KEXEC_FILE struct purgatory_info { /* @@ -230,21 +245,6 @@ static inline int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) } #endif -/* 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_kernel_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 90ce1dfd591c..b7c30b748a16 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -314,6 +315,187 @@ static int __init parse_crashkernel_dummy(char *arg) } early_param("crashkernel", parse_crashkernel_dummy); +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 = 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 = nr_cpus + 1; + nr_phdr += 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 = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); + elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); + + buf = vzalloc(elf_sz); + if (!buf) + return -ENOMEM; + + ehdr = (Elf64_Ehdr *)buf; + phdr = (Elf64_Phdr *)(ehdr + 1); + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASS64; + ehdr->e_ident[EI_DATA] = ELFDATA2LSB; + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELF_OSABI; + memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); + ehdr->e_type = ET_CORE; + ehdr->e_machine = ELF_ARCH; + ehdr->e_version = EV_CURRENT; + ehdr->e_phoff = sizeof(Elf64_Ehdr); + ehdr->e_ehsize = sizeof(Elf64_Ehdr); + ehdr->e_phentsize = sizeof(Elf64_Phdr); + + /* Prepare one phdr of type PT_NOTE for each present CPU */ + for_each_present_cpu(cpu) { + phdr->p_type = PT_NOTE; + notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); + phdr->p_offset = phdr->p_paddr = notes_addr; + phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); + (ehdr->e_phnum)++; + phdr++; + } + + /* Prepare one PT_NOTE header for vmcoreinfo */ + phdr->p_type = PT_NOTE; + phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); + phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; + (ehdr->e_phnum)++; + phdr++; + + /* Prepare PT_LOAD type program header for kernel text region */ + if (need_kernel_map) { + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_vaddr = (unsigned long) _text; + phdr->p_filesz = phdr->p_memsz = _end - _text; + phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); + ehdr->e_phnum++; + phdr++; + } + + /* Go through all the ranges in mem->ranges[] and prepare phdr */ + for (i = 0; i < mem->nr_ranges; i++) { + mstart = mem->ranges[i].start; + mend = mem->ranges[i].end; + + phdr->p_type = PT_LOAD; + phdr->p_flags = PF_R|PF_W|PF_X; + phdr->p_offset = mstart; + + phdr->p_paddr = mstart; + phdr->p_vaddr = (unsigned long) __va(mstart); + phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; + phdr->p_align = 0; + ehdr->e_phnum++; + pr_debug("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", + phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, + ehdr->e_phnum, phdr->p_offset); + phdr++; + } + + *addr = buf; + *sz = 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 = {0, 0}; + + for (i = 0; i < mem->nr_ranges; i++) { + start = mem->ranges[i].start; + end = mem->ranges[i].end; + p_start = mstart; + p_end = mend; + + if (mstart > end || mend < start) + continue; + + /* Truncate any area outside of range */ + if (mstart < start) + p_start = start; + if (mend > end) + p_end = end; + + /* Found completely overlapping range */ + if (p_start == start && p_end == end) { + mem->ranges[i].start = 0; + mem->ranges[i].end = 0; + if (i < mem->nr_ranges - 1) { + /* Shift rest of the ranges to left */ + for (j = i; j < mem->nr_ranges - 1; j++) { + mem->ranges[j].start = + mem->ranges[j+1].start; + mem->ranges[j].end = + 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 = p_start - 1; + temp_range.start = p_end + 1; + temp_range.end = end; + } else if (p_start != start) + mem->ranges[i].end = p_start - 1; + else + mem->ranges[i].start = p_end + 1; + break; + } + + /* If a split happened, add the split to array */ + if (!temp_range.end) + return 0; + + /* Split happened */ + if (i == mem->max_nr_ranges - 1) + return -ENOMEM; + + /* Location where new range should go */ + j = i + 1; + if (j < mem->nr_ranges) { + /* Move over all ranges one slot towards the end */ + for (i = mem->nr_ranges - 1; i >= j; i--) + mem->ranges[i + 1] = mem->ranges[i]; + } + + mem->ranges[j].start = temp_range.start; + mem->ranges[j].end = 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 f989f5f1933b..f8b1797b3ec9 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -1138,184 +1138,3 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, 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 = {0, 0}; - - for (i = 0; i < mem->nr_ranges; i++) { - start = mem->ranges[i].start; - end = mem->ranges[i].end; - p_start = mstart; - p_end = mend; - - if (mstart > end || mend < start) - continue; - - /* Truncate any area outside of range */ - if (mstart < start) - p_start = start; - if (mend > end) - p_end = end; - - /* Found completely overlapping range */ - if (p_start == start && p_end == end) { - mem->ranges[i].start = 0; - mem->ranges[i].end = 0; - if (i < mem->nr_ranges - 1) { - /* Shift rest of the ranges to left */ - for (j = i; j < mem->nr_ranges - 1; j++) { - mem->ranges[j].start = - mem->ranges[j+1].start; - mem->ranges[j].end = - 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 = p_start - 1; - temp_range.start = p_end + 1; - temp_range.end = end; - } else if (p_start != start) - mem->ranges[i].end = p_start - 1; - else - mem->ranges[i].start = p_end + 1; - break; - } - - /* If a split happened, add the split to array */ - if (!temp_range.end) - return 0; - - /* Split happened */ - if (i == mem->max_nr_ranges - 1) - return -ENOMEM; - - /* Location where new range should go */ - j = i + 1; - if (j < mem->nr_ranges) { - /* Move over all ranges one slot towards the end */ - for (i = mem->nr_ranges - 1; i >= j; i--) - mem->ranges[i + 1] = mem->ranges[i]; - } - - mem->ranges[j].start = temp_range.start; - mem->ranges[j].end = 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 = 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 = nr_cpus + 1; - nr_phdr += 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 = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr); - elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN); - - buf = vzalloc(elf_sz); - if (!buf) - return -ENOMEM; - - ehdr = (Elf64_Ehdr *)buf; - phdr = (Elf64_Phdr *)(ehdr + 1); - memcpy(ehdr->e_ident, ELFMAG, SELFMAG); - ehdr->e_ident[EI_CLASS] = ELFCLASS64; - ehdr->e_ident[EI_DATA] = ELFDATA2LSB; - ehdr->e_ident[EI_VERSION] = EV_CURRENT; - ehdr->e_ident[EI_OSABI] = ELF_OSABI; - memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD); - ehdr->e_type = ET_CORE; - ehdr->e_machine = ELF_ARCH; - ehdr->e_version = EV_CURRENT; - ehdr->e_phoff = sizeof(Elf64_Ehdr); - ehdr->e_ehsize = sizeof(Elf64_Ehdr); - ehdr->e_phentsize = sizeof(Elf64_Phdr); - - /* Prepare one phdr of type PT_NOTE for each present CPU */ - for_each_present_cpu(cpu) { - phdr->p_type = PT_NOTE; - notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); - phdr->p_offset = phdr->p_paddr = notes_addr; - phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t); - (ehdr->e_phnum)++; - phdr++; - } - - /* Prepare one PT_NOTE header for vmcoreinfo */ - phdr->p_type = PT_NOTE; - phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note(); - phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE; - (ehdr->e_phnum)++; - phdr++; - - /* Prepare PT_LOAD type program header for kernel text region */ - if (need_kernel_map) { - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_vaddr = (unsigned long) _text; - phdr->p_filesz = phdr->p_memsz = _end - _text; - phdr->p_offset = phdr->p_paddr = __pa_symbol(_text); - ehdr->e_phnum++; - phdr++; - } - - /* Go through all the ranges in mem->ranges[] and prepare phdr */ - for (i = 0; i < mem->nr_ranges; i++) { - mstart = mem->ranges[i].start; - mend = mem->ranges[i].end; - - phdr->p_type = PT_LOAD; - phdr->p_flags = PF_R|PF_W|PF_X; - phdr->p_offset = mstart; - - phdr->p_paddr = mstart; - phdr->p_vaddr = (unsigned long) __va(mstart); - phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; - phdr->p_align = 0; - ehdr->e_phnum++; - pr_debug("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, - ehdr->e_phnum, phdr->p_offset); - phdr++; - } - - *addr = buf; - *sz = elf_sz; - return 0; -} From patchwork Wed May 3 22:41:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1654677vqo; Wed, 3 May 2023 15:44:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CMVhf1tkUTwbcQprNe/9PVd7QsbESAoy/Jjh31IUJwzwexA4lukjqV/iC8KDihYIbUoBX X-Received: by 2002:a17:902:e810:b0:19d:297:f30b with SMTP id u16-20020a170902e81000b0019d0297f30bmr1998189plg.19.1683153846706; Wed, 03 May 2023 15:44:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683153846; cv=pass; d=google.com; s=arc-20160816; b=xa4aWiYZ4V6Dp9zRb1jADMP9PoSQOXMv7HW3N5x6ZAXt9CbHLkvwfILu2rMFwP+ps9 0excJ4MFN9gXMuMFHcYt5X1AuqCwn1W6pyUFgF2H5xa4L+IiPpjawKOvvpyiJAh/UQV8 97Z9rBIYYEXqzeKAyOrgPIksLmEquyNXLxztQQOuPLRfFizaR0DuGW1Xh4fO+RkbifMI PRPJmSewX5+ncHcdEY/gmCgyDA70qPbfPhfRSBahJk903hVbwMoJvVkahl6orckPt1VB Ttyir/RP9AP70/cH81L36f65gp1uPXxgGOIokBcF6JA4sB8o8HcIAsQDap9d7faKKIMJ /Qng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=3oNs7VjZoRQtLk6+NTns46Uuyq7OZDe54A7/naaX6YQ=; b=qQIrSq2eRFxFBKpB4AyzvlhfwfoeinjGDktS75eDt1epmShGPL1FVvavnmD0LbHoNs xopM4oDFUI01CNn5XHhWgBLvgK/UJO2R6YmBlFkt1dAsfsGDpdXZA8tuh4XKAxQIkcFe ut8CWpuh0zweEwddwNPzYBlJ285jOosCKdKrFbkxzFa/+0nvyFTkRKXl9MsKXiDAuuww rrhv7ET+ZrAGgAKIUgvWsTC3k0mWYGBCSzWaNc3MJST6tAnwO7Ibz7S8iYM9iKv83TGc K8bAB9KXV+Nrr1p7kZLslPBNu04t0M1TCKTUVpO7MtczWJPDopK5XlgVyEaw1uCd1RV9 CB9g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=N94HDfEY; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Cwjxsb34; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b1-20020a1709027e0100b001a956801791si28654438plm.119.2023.05.03.15.43.52; Wed, 03 May 2023 15:44:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=N94HDfEY; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Cwjxsb34; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbjECWmf (ORCPT + 99 others); Wed, 3 May 2023 18:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjECWmb (ORCPT ); Wed, 3 May 2023 18:42:31 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49445268C for ; Wed, 3 May 2023 15:42:29 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343Hoq2v014461; Wed, 3 May 2023 22:42:01 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-2023-03-30; bh=3oNs7VjZoRQtLk6+NTns46Uuyq7OZDe54A7/naaX6YQ=; b=N94HDfEYBfh8QfZiGYgOzO+PKG7uvUnlTQjGmq/DPfuW1d/ySHn8V1lyO8bk6uZgh1Ej M/gc9xaZtvlH4ssXcyowqCFVwM4AL44T6sM5ADMTfe9f5e7TrGHM4uh+1Ok5b8nSMkk7 Y0Bp+ciVKiMTf7JSfkX6I1m9eSIioFBPQlr3mSbzrYYIAmAJsKvzrmIypkc48NaOuJNq wbMj0fynulk9zi5d/mEWwofeWO06Hu1UGC78qvvbXMhVgAbTzHBHg20kS53CC+ioBZxo 9JNJi10Lxe/tUPsoqQHakh1vpDLXNLacHzN9PAVmn69zWUrXnJCpVLFD2ovi1pZ8TeP5 8A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t140mm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:00 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343MDhMG040507; Wed, 3 May 2023 22:42:00 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7rs86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZiW6Gjx00Js76fqIKGKRUsPq60fZUWFpwJzrV6c37f7HEsF2ZZuq2OMmzI0Vh+P9hxLVeOJApIA+vf+vNIfo7ULGAHY7kZlrkEt3xhSM+aGEIf9EiPNo+W58zZ4I/0L8ZCP9gQXMNpGqRlrBZBeyJf6LuLTo2w8SNrz6Ae/Pvf5FAbT0z4/VySBPeeGL1CYsZfQjE5riWDYg+tA9M6psx+GcOgkXPmDyi6m2ErhQptEo4SUWPK1T9UXkyOLJqRasUl7lwamhqXbmc3vD5khBPsBhdTps2QeZIQW+lRbtyvPu70m5SHDGJvkghF4M64U+683ldld5o2Lm2bNGlzzng== 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=3oNs7VjZoRQtLk6+NTns46Uuyq7OZDe54A7/naaX6YQ=; b=RQgj0Ca6gctJ/QLrDXsp1s5H1sZdcoTQxVPTVqevbJaccr/Rwg4DU8NBgcoSb7PZ28teMSSkNxbsk50937/APXqpswvAzQpCNZ1jJNsk76l0wl430AUmgeSVHfl2RsnvrjwhLiarupOjOfNPKuty0YPRwBYUpIhR4bm3GRBXLXKlB3P9Qyv03MXnZ/ICQzCvobzqrglICuLXlO9CG3O811M3eiBnAdURL0GGorPOjN1NGyRS6v6d6KgluNkbminPxgMo0GjVDdxTGmh1VuX6RjqfUDYKntOcrHarhp+bnU8xWx1Wy1xzw5zRorepW/gsk5exbdqCSjFoQ+0Gba1mkQ== 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=3oNs7VjZoRQtLk6+NTns46Uuyq7OZDe54A7/naaX6YQ=; b=Cwjxsb340AriqPU7MhFnveqbOza6SYkJSR6Y1IkruMF+k2oAAgaSfAxgUFxC7h3ekdI+WxyBAxZY+rvg6fGS0M2ygA/6I7/2PHlNiKl18KBdCtyiRW2RtLI3g4rDQBLc4oa3ceST4P7KaIZ7g9C3OkbIvtAMOq6VSCqeqoS2k8U= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by IA0PR10MB6890.namprd10.prod.outlook.com (2603:10b6:208:432::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.22; Wed, 3 May 2023 22:41:57 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:41:57 +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 v22 2/8] crash: add generic infrastructure for crash hotplug support Date: Wed, 3 May 2023 18:41:39 -0400 Message-Id: <20230503224145.7405-3-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SN7PR04CA0231.namprd04.prod.outlook.com (2603:10b6:806:127::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_|IA0PR10MB6890:EE_ X-MS-Office365-Filtering-Correlation-Id: 22761ec0-fecb-41ee-2397-08db4c2799e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lLquuHKGCqPIPuLJUyuZ0CFod26e8TZA/FspGrTLqpnwFuidrYS2UaA1hJSFNpWjuR1+Uq+S8C0Wi8rCxlRCygK6wUZcC0sP5lxHpNKk/8wpRw/XlP/n2Rfkfi4HoYsgPIKaWsxKcKx76dA66A2JV6uIv0j5PROuBVaPUB7d5g3wkF/23gaQwmJ0/7cHAvMvhyZGM3D075LaWoIzz0CPe052lSR31POsqNHuNvGziVb4KaHURfs7gHkb8APM9cgbsodwnuWqEM1kfvc4iuykEGyra0xeGoJJo+HB/pYCz08BcQC/K9c6t97/yVbNjgB9R4fYN+hNAuuSvfSgvM+6YeORojR6aPBzh5EUJf1HMZmNZxEMtZecvFj4VfsJiVMFEUAoG6hrRvZ4LzLxEhXuPmnIpoD78eJ52kr62M81yLHxDd7QEN6dz4GPciRcTxq5//tf79d/50upcryhzgJ9wwiXaGuDUaESo0SfopQVtYTaamh1sN6WfOVzjLnq2r7cEVHxoFk+N9Sz6tMLg3CzItBAzrPsQLRQU/3MYTo30Xwp/FNOWMCBOlxQKcANhA5C/uf0Rkvk1/KqfqhtvHIZadTUoIfks3oVxd3qh7mRG34= 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:(13230028)(39860400002)(396003)(136003)(376002)(366004)(346002)(451199021)(2906002)(107886003)(38100700002)(83380400001)(2616005)(6512007)(26005)(1076003)(6506007)(186003)(36756003)(8676002)(8936002)(66476007)(5660300002)(7416002)(316002)(478600001)(4326008)(6666004)(6486002)(86362001)(41300700001)(66556008)(66946007)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xTZCul1d+BvB4+Q0bo5kzGCIMyOKXAk4OZ7UtH6EZzGbT640buZi069nc4bfpqG7ioJxYwykDD0uUWb2nt6lsA5MR0/H8GC7n6cbqzv0Q4hIPmPuHj/yUw3r3WKInpVupPGeWyQ10T6ds+hHZ2Ohn7jxzDZGs5ia3kpgbhmWNbBcog7cxMYdp1tluAbK/7On7QLq9oTo0jh4LBCc6a+gLAGGTk80KFHpRviOigpyCkf1uVmCzU7gwuH4G2TQAMb+1BdnS+zBMInngQs3+Dg333c7O4vrvT+b2Kioi5QKRBfPbx/qg5aoN8S9A/AFh1NLx8zoR5tCFRGGesleWdD+uv7SzbcLwOKJlSYi6M7hYRjgDfiIJAi63A1LXVmCGbAtkwz/KbYUGZxhdrlSpxfP7aafpkjHNYY8hoM/UyNSUREiSJELfdayCAfskgZLISOyaalqpspNlqAqnJAJa8RoErSgKrGQL/Wz8xZjG95P5SNVs/KDXg4ZgSJTHZ65scQcGN7MteywtxpVjuH5BCIjbU0rv77Fr5712gF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GG6LRRh9DW1Cd3L3gYE0PHiq+KLd58yVhK3K19pyoc5B/aacU3zwQzgde6w1Y/TSlKQS4qA1VpMxr+fcarLMrrrThjoTGdRz0mwJrjdpsDhvPMymNz7+kcmFY1nKuub/IUzTTeXzzTw/0lg+0kADcbiOiUk3y4LiQgxe63R15CfouW/DvjNp+1g= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22761ec0-fecb-41ee-2397-08db4c2799e4 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:41:57.4436 (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: zzJ58J4332SaWfPO7OrQyUX4BBgMSLNxgwzHCXlGC5t5ISEg1wXvXasFMEqIqNz37phhCj+IGpjAge4NeitMJLvQKARgFUPW4wmnRscZ74I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6890 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: mxBkNIOZ2XcNnRSJYm8mZRSXL2k5NIH3 X-Proofpoint-ORIG-GUID: mxBkNIOZ2XcNnRSJYm8mZRSXL2k5NIH3 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764914728008285507?= X-GMAIL-MSGID: =?utf-8?q?1764914728008285507?= 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 Reviewed-by: Sourabh Jain Acked-by: Baoquan He --- include/linux/crash_core.h | 9 +++ include/linux/kexec.h | 11 +++ kernel/crash_core.c | 142 +++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 6 ++ 4 files changed, 168 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); +#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 811a90e09698..b9903dd48e24 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 /* Verify architecture specific macros are defined */ @@ -360,6 +361,12 @@ struct kimage { struct purgatory_info purgatory_info; #endif +#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; @@ -490,6 +497,10 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, g static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { } #endif +#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 b7c30b748a16..ef6e91daad56 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -18,6 +20,7 @@ #include #include "kallsyms_internal.h" +#include "kexec_internal.h" /* vmcoreinfo stuff */ unsigned char *vmcoreinfo_data; @@ -697,3 +700,142 @@ static int __init crash_save_vmcoreinfo_init(void) } 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= 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 int cpu) +{ + struct kimage *image; + + /* Obtain lock while changing crash information */ + if (!kexec_trylock()) { + pr_info("kexec_trylock() failed, elfcorehdr may be inaccurate\n"); + return; + } + + /* Check kdump is not loaded */ + if (!kexec_crash_image) + goto out; + + image = kexec_crash_image; + + if (hp_action == KEXEC_CRASH_HP_ADD_CPU || + hp_action == 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 = 0; n < image->nr_segments; n++) { + mem = image->segment[n].mem; + ptr = kmap_local_page(pfn_to_page(mem >> PAGE_SHIFT)); + if (ptr) { + /* The segment containing elfcorehdr */ + if (memcmp(ptr, ELFMAG, SELFMAG) == 0) + image->elfcorehdr_index = (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 = hp_action; + + /* Now invoke arch-specific update handler */ + arch_crash_handle_hotplug_event(image); + + /* No longer handling a hotplug event */ + image->hp_action = KEXEC_CRASH_HP_NONE; + image->elfcorehdr_updated = 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 val, 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 = { + .notifier_call = crash_memhp_notifier, + .priority = 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 = 0; + + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + register_memory_notifier(&crash_memhp_nb); + + if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) { + result = 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 3d578c6fefee..8296d019737c 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -277,6 +277,12 @@ struct kimage *do_kimage_alloc_init(void) /* Initialize the list of unusable pages */ INIT_LIST_HEAD(&image->unusable_pages); +#ifdef CONFIG_CRASH_HOTPLUG + image->hp_action = KEXEC_CRASH_HP_NONE; + image->elfcorehdr_index = -1; + image->elfcorehdr_updated = false; +#endif + return image; } From patchwork Wed May 3 22:41:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1658133vqo; Wed, 3 May 2023 15:53:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7fV9T6LwhsHjMGC8dfShbERjDUxLnVGCwIqgi+mwiVJ4lVyCGbSVIjDXtf2IVD7YyfI1QZ X-Received: by 2002:a17:90b:4f8e:b0:24e:29ed:af07 with SMTP id qe14-20020a17090b4f8e00b0024e29edaf07mr163166pjb.31.1683154388363; Wed, 03 May 2023 15:53:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683154388; cv=pass; d=google.com; s=arc-20160816; b=Zo8cccep56WqQVWw2ujzWTgcr7ygeZ3x2ncwwZSW5UsyDqs/Kz9/xuRnZnpQZ6ob2p 71NQ5SjSGaxsOhaSasQW4CADsD9f95T78rJGMyZNcf1Cgl7je2n/erV2QcOpHoPPbPTu Yj9vtlxy/GB2CVFUGCSrYrVNXR6ibVKF3Ss1XApvOEpwBAPu9lTYns5oGwT8Am3xOaax +1VGq7M7jj05XrqymaWxwNnfoKHE+qWpocQFFHuevGd9JJeEuPV851xw2u6GGlypZOai 7n56q6oxyEbYeEMXwMNGcLlaZdz2aLJuGWB4GV/5gxZv/nupXrgUacsZ43S7WM6aU0tu 35uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=iZA542S+AX/9nADOINVgca1jAHuZ63qloYIKhy4+3U0=; b=NIFDid6byrs8uxDNeZrBzSZiCQvWJrLwplIY8TP4i3SPMjcdG86tAVmjCggsyRoLUS 5iI4yA3IQ8xFe3lPT5ZkSLhTM3gUXFIf9mzq7ct3QkDfb42MYNylFXDj7visnHqynYtB 0W3loxoRxb3tH4nE3bf+etioDx5JUVT9E6VLHemQ1hPwByydYFST/S2N8U1rmsm9W3Fp C4eHGSZnos+doF4gfYDaGs80UDMLwxOd3Vl3gDfk/uZUwsaSS3dX+kbYg+ZU5QkzprBy WAU3MA4Dot9z2uq2jpz+xJMfHif6W1Due4sdq/wkpzgwSaY9ZfpnCpmsXXFK0/QCLzCz JJrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=Ou0V384e; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Mq4yFNlt; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n65-20020a632744000000b00514329f7ebdsi35555111pgn.344.2023.05.03.15.52.55; Wed, 03 May 2023 15:53:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=Ou0V384e; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Mq4yFNlt; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229692AbjECWnV (ORCPT + 99 others); Wed, 3 May 2023 18:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjECWnS (ORCPT ); Wed, 3 May 2023 18:43:18 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A87A901F for ; Wed, 3 May 2023 15:42:50 -0700 (PDT) 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 343HoZ8N024252; Wed, 3 May 2023 22:42:07 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-2023-03-30; bh=iZA542S+AX/9nADOINVgca1jAHuZ63qloYIKhy4+3U0=; b=Ou0V384eMAKDk7+YetVGMGI+vybS2Sdq9Ggq98GIglPJA44oMNdHNnlYScFuQxT0cfpo NK6W0OtDYh1apsvYMyljscVDzkauMlK/0lEreMxo9G8u3CpidRtSARP9rH7xteMGplcc nXBAD45wt3SJTUzZ+xEZqMcHbyYnz0gUxVf7N5CFDK6iJmuKZ9ZBZixayEYQ4Jy0Uebz UhCoxDHgL+z+2gwRAYLPMJ5IL/Ksgj15jCPXdl/B2EKUw6xF7XBvTF1oV7K8Rdqa1PRr MGygpaFxyCo4gTy1BSKJzRcTowTFCS+4KC1NACZbsYlNu1x9NBv1Z3b/OPg+cLo7I7Mv lw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8su1rj0r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:07 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343L4mCm040517; Wed, 3 May 2023 22:42:06 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2168.outbound.protection.outlook.com [104.47.73.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7rsc9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SsPd6D7JMdrMUHZLMpvsNGp/xP+eoUUEVmdLXfUM8UDEDVXiIMV8P53f2Ui9AHdO82UWoVbYlgfBc0H9bas+V40qC75Gar74PXv802APd4MuCds5sUrT0Et/a4deN6e3rR4T+RIMfPQYgAkpBq5PW3oyd7ENMn2Ux+q39bELIvV5/u07BXKTHdmNCWH0E4T/t8I12JfUA09tHuYaSqr7bk026F72QfbIwKCz3+WOfoYEpNljVPbvdAAenQYIdBLNCHsPGKANJQkBtWokOIOG9ekuNUGgK6oRF/nvpKiLht7bGaFfToD83euKtS5I07fSxIzwJd31E6TS2WJ3EoOltA== 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=iZA542S+AX/9nADOINVgca1jAHuZ63qloYIKhy4+3U0=; b=nSnFgiAHEmUR8IxDMmzAkoviW9YH4nbojqOpkSFpH+yNOlIDRBYwyoA6xBCZZTmP8FQsJiL1E/sXonIeytkPE+yANXgCpz/3D900gOwCeenyMy3SRaWhcrI4dnBvPCGxZnnj6T1czeLiE5+tQsgt+aktbpzAnTRCjHi0nqpq3Z3B2a5sE6CX0ND+sh5Kwo/3q4IDLUzWVFNmWZrAsWjXCAJxrAZdVc8LMri7KuQqwyn2gggG+gLcd6oV5g7c6MU1T1CxVMuR0entgpawwD3CoPNqoPN/ggXvp/t4x58uY0QzqpMRZeUZO7nzaGBi5haZTJDr/EwkLSt67asMd/qj7A== 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=iZA542S+AX/9nADOINVgca1jAHuZ63qloYIKhy4+3U0=; b=Mq4yFNltsGA/qKoKZeuHS2P2HCz2DihoKYvV5BiKV5cwLp+4CgT8K8TQo/ZmSywVSNS56ojOS4v1SDUph5rPWQCEYvqcJBOj7+jCn6NpRQm/cUYkAH/mJ9Diz3AY00/G5qWRDp8/RlJFcxWRzSMMn/eoTCQW7fZjLwJAXvXjEoY= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS0PR10MB6846.namprd10.prod.outlook.com (2603:10b6:8:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 22:42:01 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42: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 v22 3/8] kexec: exclude elfcorehdr from the segment digest Date: Wed, 3 May 2023 18:41:40 -0400 Message-Id: <20230503224145.7405-4-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA0PR11CA0164.namprd11.prod.outlook.com (2603:10b6:806:1bb::19) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS0PR10MB6846:EE_ X-MS-Office365-Filtering-Correlation-Id: 6237b4e8-b2c1-4995-acae-08db4c279b87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +EeOgHDMOehFnyoJjrnzHgSqQi7RvTK+QkjhCp2gRApbPw+OOAvCPN4VmzRqkIHpepyjB0AgGiNCUJB54bs15JQ76GYifTwaLDUusf8qlvXKAnLlEWqyVznBicCzOrB7QWPoRzJIuKaBr1iHeAXHp5Ij3PFMjDql9H9w8xnU/l/RSrRJtYseQ2OdFR6EG1HR75k8WMgK8HQ2we3PXHnPsK3FNPX8JMvayOdCwQyEgfoSo7cVqfR8doR5QuaYUXlVIX9ZzboKt/icUC2D192RSxmL6AfrxKo4YiMQsQR3R5OPcePGD0IJWzhr8tYvAVNHqQS0JKllD7EspqMfoGDYA831MyZSAUKblfRVopPRI5ZG8oj44FMQIhk/zHjd+28vm4w0J0tNuA3+t0StCnG5YjHDUmXNtJm7r6zzL4wvYeju8Oj6J16w73uAZsk+rY6709gZk0eaDWtKw/Khh0JgfceIE/wugyJusn99Lqq2cc7BvnlhtliQhEy0sImDgdpdFm6uGWLnieMWIGEmc8dHz79aI7vkjcqDCmfK4t9Bto15Dko2SJW4R6iNxCMS/zWa 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:(13230028)(396003)(346002)(39860400002)(136003)(376002)(366004)(451199021)(1076003)(6512007)(316002)(6506007)(26005)(186003)(4326008)(66556008)(66476007)(66946007)(86362001)(5660300002)(478600001)(7416002)(107886003)(36756003)(6486002)(6666004)(38100700002)(8936002)(8676002)(83380400001)(2616005)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PomH+9eBxLMn/VuOs02VBDDSeEOaqw7GROntP0n1ecI5w5lU1/EVBAw76hPNiHec1obBT3BxYj1vMs0lcV8OJOi2dbWCFvUcRcqPNCZEM9rBSVfL+RaS0HEjiQlCrqx0JA4UgbDWo1gBojDMuu5V7gvrKfhsqMt0Gu/vAL1+CRAT8rrXqhgTDDF5RYYsUVql7SnaOaMtxxIqpv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+mK374lXQA/DjtAafU0RPueQHG2eSzmjIQLHxln7IRhg1u+Y1PLrarlGhBVERd4J7gMMbOLp5GV51bgIgfhautpGMgDklADL9NsMUWti9nLLjWJI/0Pra/jcdNFOOzVh5gfPGJZIIiCXOgNRQMFU4Y8LdKZwU3t9q16XZyHpzleDS3iryjBdOeuuwwxFRbmWnFQM50xjlLpSwUNd41cpyHL5e28HiBFt2B2iNtn41sPK9iyuXHPRFtWvBx/PUUUeFYxUbwrjaXW5gtl0rPUofrVFJTUzrifIxmAdMd7SKankmeBS3Fu2vhy9jJ/NGSb106rBv4FrqVw8lngNyJWD2XmDBq2X2mVn7J0gk39h7TTvD/KdTzfIi0p2CSl/7r8zmTelki0H6+YMiM/uO5tuuiPg1vmcL/pfDPwAvKzKliOPXJndK7S5kYyfilYlpZzb0O2VDDcaoZgEOkvawx9C05mgL6ASHHSey7a12Hy1/C4c8waoy2IKefJUQsg91IC5k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6237b4e8-b2c1-4995-acae-08db4c279b87 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:00.2478 (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: X9a/mh41fiteFPhV4nnSjLhgWe3Ym5iKIJCkNT41vSeoSJsDBYpC5nFCNjwmFZoAnYvTA3MqmOqvsmPO3r4YA4V1yE750JIDXKOXIB6VQZc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6846 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: wbSM3OJjngqUbsQKSlk6MzeHxoosZ0uc X-Proofpoint-ORIG-GUID: wbSM3OJjngqUbsQKSlk6MzeHxoosZ0uc X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764915295757944120?= X-GMAIL-MSGID: =?utf-8?q?1764915295757944120?= 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 Reviewed-by: Sourabh Jain 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 f8b1797b3ec9..1d2cfc869a75 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -726,6 +726,12 @@ static int kexec_calculate_store_digests(struct kimage *image) for (j = i = 0; i < image->nr_segments; i++) { struct kexec_segment *ksegment; +#ifdef CONFIG_CRASH_HOTPLUG + /* Exclude elfcorehdr segment to allow future changes via hotplug */ + if (j == image->elfcorehdr_index) + continue; +#endif + ksegment = &image->segment[i]; /* * Skip purgatory as it will be modified once we put digest From patchwork Wed May 3 22:41:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1663918vqo; Wed, 3 May 2023 16:05:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44j/HKSilcCPYdQDHHrBmwPQ6m7pnxTu0iPFYRzMs6LYVwVTNsO1VKLuXsmUQfBIs0Z/NO X-Received: by 2002:a17:902:7688:b0:1a9:8769:36bd with SMTP id m8-20020a170902768800b001a9876936bdmr1711795pll.36.1683155137476; Wed, 03 May 2023 16:05:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683155137; cv=pass; d=google.com; s=arc-20160816; b=HchtHAmr+WFPZuGmS+4lEG40YgwVhLIasA9Lq1bivJLx9h4S84KOwI6BMdO6IHd4Sm Y+ipOFE6/fgjKkVnzgmNHXLAkq0vTC3547NKOlFgiSXuvXbxXeOpvhul4ciptuo0pTnJ IsRbIZw7yHVi/cepOoMYnFu7+4bvYTyEWt24bIXTdWBnmKxaUSzUKtbipnw+YSbNKLTW CxDeTkDD2xMlGoRRdD0zrkJ6uamEZDrb4sdn0g7SdwRvAWFw8kSGd1IGVoGkxKwd6c1Q 95ZwFFcJMFjMOdV4Z4r/nTfrU2EAeLS58Xe3tVlS9/pvzJaN8VbnHJwUblyAnqB0amD3 px5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=bKJ02U1bUFpGiRLgIB+zj/k4wi8clNbcfvgzbpYe4ak=; b=mgBbTpdQBftkEZKxgF6Cw3gBJ7rESo7hTJDDxBxDfBVlFi1o3JaoODOdACvQlnR3cT WjpCY7yQpyrRt9LlFOPUU2T+wLpC0RNfArUM1qZPB8lxplibDbyTjyYTcK/YEtdcWjw8 UVeBgtz0MVKp4jrYcwZ+8k8G5k2yey8qEADRh/etmSS+638HbEKXM1VQb+WjaWIZzrrj 9tSlaUOsMAau+200P2RjWuh5ZKikuJceL/UjTCmqlKvpQcvPvLQ+ENOoB8tIKIrW08xv lknNMIDHuamtAanCJcDBduKQvGXWLQQvm4ZyVq2tSkT2JO/2Hdi6pAaBusrS4jk9HCb4 l5Sg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=NAwxeY3v; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=HfJMRDHc; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a170902c1d400b001ab089f7319si5593556plc.52.2023.05.03.16.04.52; Wed, 03 May 2023 16:05:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=NAwxeY3v; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=HfJMRDHc; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbjECWnd (ORCPT + 99 others); Wed, 3 May 2023 18:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjECWn0 (ORCPT ); Wed, 3 May 2023 18:43:26 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6369193C1 for ; Wed, 3 May 2023 15:42:52 -0700 (PDT) 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 343Holfk017443; Wed, 3 May 2023 22:42:09 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-2023-03-30; bh=bKJ02U1bUFpGiRLgIB+zj/k4wi8clNbcfvgzbpYe4ak=; b=NAwxeY3vk1Phq1OCgxYWduiIaCUWMo+5MW/Ued6gUYFiIXMG6xNiMbuj72MuuN7Xuotm wXf7ro8Re7I6WEOXATiMVo7d6bkh1IFom+oAmDzQMDi9n9YONrb8csmGdBEu8S3Z6RZU Ux+vBU6bIe0uiRNb5RmT1wqTmpcg5pKk3XRg9rAtrBUargQJbXcJtefM79+jZ+zyosgU zHZgHOO/NWnjtTqBYdjjkNSR+cpGiY6OIBM0MLeo+afc43Max6EjjgOuvaDEIle6YVVS 2SwgQZ/G6nq8pmuI8NRSyEUbj8S9WhyFgOPWQALhUJw0iFvHzMrT2tDp8GOoIDTerinA +A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4ardva-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:08 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343LgGhG024871; Wed, 3 May 2023 22:42:07 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2175.outbound.protection.outlook.com [104.47.73.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7y5wn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KPrY5ExJYQc+nIYMAKPfXBE4kliQkUp6+yN3ZxVwT80xR57i4EGISkO3r3V+myxtnkVX5QoXYuK5STNv9xUzb8q4HRl9ZXFhARK1FDug0N+Cf1pusAMP6qPHzoTW/74VJNWHzHmyiXzfNSBGNe1s0jA0E7eX7fT2dcnHnjZVAAX1KROUT3D0uvtD9+vvXwPb3NfGCHA3pNS+IW1pJYMljBeHTwDvsVSTCQsG/20/cbo9voXFEqc8Y5wwtyAVmmRd8Z3JCI7m3jkQmcND/VL8UFDLYW2S9jxwClxCtqqyDeOclR10/KPJ0eiNoIJtDNB3e+CZUPHkB/t8ysUREtIP6g== 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=bKJ02U1bUFpGiRLgIB+zj/k4wi8clNbcfvgzbpYe4ak=; b=bBT0cGXu1BF1o4gE75lMpiuyAOMDeKKMznfc0iY7ZG8fQ8a+/Gs9CGy5K9BVsaCAp8SbCxagkZRKELO8ElsDhHR0oJEhae7a6OTz0ejL29pwp71KDDsn2TonHmPxUzLvobgYjXsqV0L6uUhnVoe+A2+EvWIk1R6GzkgYW0dd399EC+SSPiAhYKp2imbyzyYu16KeNAFhzQIUVba3Yei9TaAH8nvXPzAjrD9ZMi09ZSgY+CmxWV/W9ficEvyqG21LbJrhWIz3+4yf3RoIKEfLjMPM4lxTUS1K3j/zHQ3Y6EGWbNvf0jUqyAVZc48isay4nnogi6DiVJQnfASR3lz5xg== 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=bKJ02U1bUFpGiRLgIB+zj/k4wi8clNbcfvgzbpYe4ak=; b=HfJMRDHcxcawu8qfpCKLv+Z7neT6DcR/iuS123g/jJhs5Yfd3t72TOEpNwzuAWHtYSdVcSwe796yhS/EfhwUMuqEw8+x/DYl7faxt+oX2ojRp2WkYBwxaE57i5CHZ7UGKhabW38tJ29fsVGAgspekdXDJw+nnsmUzW0dg6hb/yM= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS0PR10MB6846.namprd10.prod.outlook.com (2603:10b6:8:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 22:42:03 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42:03 +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 v22 4/8] crash: memory and CPU hotplug sysfs attributes Date: Wed, 3 May 2023 18:41:41 -0400 Message-Id: <20230503224145.7405-5-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: BY5PR04CA0028.namprd04.prod.outlook.com (2603:10b6:a03:1d0::38) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS0PR10MB6846:EE_ X-MS-Office365-Filtering-Correlation-Id: e72f9e1e-bdf5-4986-6e95-08db4c279d45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pB5ZLcB2VkceIKO3Z3FM+ZuEhBYesRJGzFeKemYBRilQEl1JDB0VrJAbECleczx2GkmCNcdouXeu4Xgeyv+/qhrT1l1yTnG4UQToKiHpRRk6j5gRi3MhlFvlO1q+/Eji4P26kQzzNkwwVEdZc5piWPMybcMD3k6Boq+VJoYGKXKRYveqR0R0N/YbDbHH2qY6GwSZFVFG3vUYLzHVKsMvjIoBUgcjRk1jNSulJja3php6XbuBEy6kmKfv03K+7gQ2rac0eliKk5rVhZaSjL/Va7FeRhdtyAgdjeERdljHLej8YEzGrz3LCQIzrTCI4xpxy7OpVY9tjR6rtcPjTmvhKsh/6+o3JR4lx8HHQWc0TtHHXwoUYnic1Cu6Fs5NGs9iTKagk3IkHBjydafOqcKBET70QzPTqVjZplzC6mvDHZEEUTjVAZ1Eivd1NA3qpuUswoqhMIRfVTdp21YpZQ060RCXOgFnDm5+mj2vOhAtyXwnVfTp7P1yuu63XJbi+HrKjTjukWN53RcoCwCuSIEr/kINgKFqgWmKin61dJ0XbA+q+P0Hm+8fZUEFbxcRj20z 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:(13230028)(396003)(346002)(39860400002)(136003)(376002)(366004)(451199021)(1076003)(6512007)(316002)(6506007)(26005)(186003)(4326008)(66556008)(66476007)(66946007)(86362001)(5660300002)(478600001)(7416002)(107886003)(36756003)(6486002)(6666004)(38100700002)(8936002)(8676002)(83380400001)(2616005)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pqOmdwhRrm/CHT7CADxvjb+g2nk9mZ1iseM8UkMbMRGgkRj0K6wc7G5Z5+WCpEYwaNQiQRyxMdnt4u4jOF0Efnv4KYbaQp09kBwKEH7jgGzTEIrB9NsRoCF0LFxxMZnec/NlSErmF8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rWuHEbvZPcxIA+GZeNwPwjGKQApmpiiIpEU+rgmhCve8yJk9yXBWptJ3io0N4J6Gl/S1ykDHXutvztoa/SFK1UyO9ulAtEmxE4W6kyCOIyhecRZRO2nALKWkRi59KEkv5szWHEGjwu9HwHYIWDbiM3hVVJQ+pTXXZUngq4thgxjuLFPWt8LI+hGnntCwRSD3Ys52lmHr7uolPVKyiXbIcUfuAZeE3BvkQVMgF9qxBgih5lsIWtBCOHdNBgAm3Tf8zHCgHA6aGVoe6M/U87syV+bHHCUUxnrct8DlunNGYdg4l2U1ue1wvNyXxT4EH3+mJ/67IWHzrz7cJx/qm5fp/WkLz3BwZVyjLPUHYO0kGPM2aqBaNioYvkkpH4uINM3X3NJ2tSuE46iJbnjQSfuf8HJqBvOlWdeneHPnWk9JgL8/mWijjyfU6cjyzrgbIyfYc7FhJWrUT/PqEvFQco8/hn0vRdcVdkzD/Y+ohax+zXS3K1oMD+Cp7TS/Okb/qxkzrq6I2ZrIH0ezDGWNY/l3KZN1whsCtLQu6ndo/7Z7alxI1ZtWPlJ1EFsKckqm5w2joljQu2G5MhC3vIwLp+/y8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e72f9e1e-bdf5-4986-6e95-08db4c279d45 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:03.1079 (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: 8+tXAh5m+q1YXby606ZQv4nZ/zR6YsRvYTCiQUt7gzsYpXF5EiRWGOuleHyike0cKNj2Jc4/OAXG0c54cDcLoLCKv3V6O9ulryY3qVKkayw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6846 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: xx5uyqdO2KMql-xU8UOP7mEmyrK7u4hK X-Proofpoint-ORIG-GUID: xx5uyqdO2KMql-xU8UOP7mEmyrK7u4hK X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764916081278781796?= X-GMAIL-MSGID: =?utf-8?q?1764916081278781796?= 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=="memory81" SUBSYSTEM=="memory" DRIVER=="" ATTR{online}=="1" ATTR{phys_device}=="0" ATTR{phys_index}=="00000051" ATTR{removable}=="1" ATTR{state}=="online" ATTR{valid_zones}=="Movable" looking at parent device '/devices/system/memory': KERNELS=="memory" SUBSYSTEMS=="" DRIVERS=="" ATTRS{auto_online_blocks}=="offline" ATTRS{block_size_bytes}=="8000000" ATTRS{crash_hotplug}=="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=="cpu0" SUBSYSTEM=="cpu" DRIVER=="processor" ATTR{crash_notes}=="277c38600" ATTR{crash_notes_size}=="368" ATTR{online}=="1" looking at parent device '/devices/system/cpu': KERNELS=="cpu" SUBSYSTEMS=="" DRIVERS=="" ATTRS{crash_hotplug}=="1" ATTRS{isolated}=="" ATTRS{kernel_max}=="8191" ATTRS{nohz_full}==" (null)" ATTRS{offline}=="4-7" ATTRS{online}=="0-3" ATTRS{possible}=="0-7" ATTRS{present}=="0-3" With these sysfs attributes in place, it is possible to efficiently instruct the udev rule to skip crash kernel reloading for kernels configured with crash hotplug support. 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 updates the crash elfcorehdr for CPU and memory changes SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_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 Reviewed-by: Sourabh Jain 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/Documentation/admin-guide/mm/memory-hotplug.rst index 1b02fe5807cc..eb99d79223a3 100644 --- a/Documentation/admin-guide/mm/memory-hotplug.rst +++ b/Documentation/admin-guide/mm/memory-hotplug.rst @@ -291,6 +291,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. ====================== ========================================================= .. note:: diff --git a/Documentation/core-api/cpu_hotplug.rst b/Documentation/core-api/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:: can process the event further. +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=="cpu", ATTRS{crash_hotplug}=="1", GOTO="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 ====================================== diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index c1815b9dae68..06a0c22b37b8 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -282,6 +282,17 @@ static ssize_t print_cpus_nohz_full(struct device *dev, static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); #endif +#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[] = { #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 b456ac213610..24b8ef4c830c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -490,6 +490,16 @@ static ssize_t auto_online_blocks_store(struct device *dev, static DEVICE_ATTR_RW(auto_online_blocks); +#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 @@ -889,6 +899,9 @@ static struct attribute *memory_root_attrs[] = { &dev_attr_block_size_bytes.attr, &dev_attr_auto_online_blocks.attr, +#ifdef CONFIG_MEMORY_HOTPLUG + &dev_attr_crash_hotplug.attr, +#endif NULL }; diff --git a/include/linux/kexec.h b/include/linux/kexec.h index b9903dd48e24..6a8a724ac638 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -501,6 +501,14 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { static inline void arch_crash_handle_hotplug_event(struct kimage *image) { } #endif +#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; From patchwork Wed May 3 22:41:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1654658vqo; Wed, 3 May 2023 15:44:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SyeNRZ8jA3vB7N0lF8Xlm0r1CD9GyoMjz5UmAXcEGcJ0ITNy19FkjG6s2Mms1+H2VnpX9 X-Received: by 2002:a05:6a21:999a:b0:f2:9161:d4de with SMTP id ve26-20020a056a21999a00b000f29161d4demr110839pzb.49.1683153843747; Wed, 03 May 2023 15:44:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683153843; cv=pass; d=google.com; s=arc-20160816; b=OxrgesqZZ5rth31g0bKHkhgoD/8TIVq4qlD3Xl886v3+VZxIpZV5e2TVNxFS9cwZdV X40m0pfigN5nmY6cEUg7um8gi6IQJ3lc8ETI3D2ggzCtQO2fdXLgEZ8W0dNVb3ZA8+// 0cAJZiaHMbXEkB0XqqMLGnkoBc7HC13DUZRltq0mimT071Rmmz6071H4HMxp3NU+jzje 6Rcl4En6rylcMzijf3YZnCin4xFhOcd+0zeKMRWTDc9WwrYO6nLLrexwUBH9Yzi6/21w k4f3QmMKFFnL3TPf8ve6kXL7vNrV8reAW5PzD/QBZtojTcwiyl4GxQpd2ISyTjbxfM3T hM5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=NmmKd2b1yuke7bdbTP7cX6qWkLEUh6jMStkliaGr0cE=; b=VMXV73rm8faO541EVdRZvlG3pI+iTNVBi75tDMSJyKcF0g4xDRAI/8ovSUN2qu/bcN cEjTdJup39uyI0AKbBFIzi+EXqLo1Cuw/845RMaBSrVnobUvxeq0SBWOJ2gZ+4FPK6T5 n/LTIRp8XR14RuLjptUvTZ6qPVgbDICM/oIPgqjsi47B+tTzhgQUdMILedsOGRZYzg1/ 9AvN3/tNSFViC2JGLEP8IKJ+e6lwZEpFsYMkYtTVo50R7v0FdjyMRtGiIsTtAd43lEpx HHNjyINlEtrSpoMT6fdAaK7/85RFHaN6fGvDXH4fpHDRTPhp/nC50LPyaeNzyDljO87C rl1w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="1DIJQ/d5"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=JL0wRNOX; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m187-20020a6258c4000000b00640f209d54fsi21219801pfb.11.2023.05.03.15.43.49; Wed, 03 May 2023 15:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="1DIJQ/d5"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=JL0wRNOX; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbjECWmd (ORCPT + 99 others); Wed, 3 May 2023 18:42:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjECWmb (ORCPT ); Wed, 3 May 2023 18:42:31 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BC565FDF for ; Wed, 3 May 2023 15:42:29 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HpidD015206; Wed, 3 May 2023 22:42:09 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-2023-03-30; bh=NmmKd2b1yuke7bdbTP7cX6qWkLEUh6jMStkliaGr0cE=; b=1DIJQ/d5pGzl0YbGCiridSjEoUaxl15Z2bAhwxyDX7KcZUZGLFjxo1YK1HgtQKLHRgTq 90vhBUlC5ZVSW/y852DmG2pgEV5OC8VOjOVBkaCBS5byDqVAfzZ7HDwuNdYRCE0Vju3Z YZz8vzibRXMlKLWkW6qwwNlkEnO4PrN+gAOQG2UIRZeBWxwe3hWyKD43vg07BSZjzbn6 uQf3/rDesZHAUumYsTwLbhYztTXLsA5ZdKcwGFeeDmoYE2YNTLVK0aQ6TZciXMAoybqr lfXjcOl5R1N0l8HiwBy7QDA/V7z2Yh44rLpnyBafZ7VYp93L7Mc+G7EmMx37ogXJFROM 0A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t140mma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:09 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343LgGhH024871; Wed, 3 May 2023 22:42:08 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2175.outbound.protection.outlook.com [104.47.73.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7y5wn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JYk92/n8G/9HeayEIuL8UDimLiKJ0Lzip/xc0+XWS34foaM8GJsC3OTJ6eUi2XD2NUNUIDwQ+X6EWldPcYBsw29+ljIYFfp8/SLBmxTx/4cHCG5fhFY4NyA9jVRAWybPg9PerLQIP1I5BsfAlZZ0YmM2Dm74ZGz2NJUohAEhxBCRRCVMzFRsAgz4jRizc4+/olEfnKR3W8iFIWRhT7E/qbZEbTaxIfTQ7GsOm3XpE2ZpS8DUTJBkgJYls0sDSV2AVOqxY9HoOuaUYObL747jk9vqUwB2VQo0Vs97ufVcZSWbMEe6w8zq85yQAsCLFnEo8KoResAnUUEifojcWpkPRg== 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=NmmKd2b1yuke7bdbTP7cX6qWkLEUh6jMStkliaGr0cE=; b=XrarupYtxh5s+4o8FHNCf+57HgkobsW8DZmoZpg3PNSPj1r965QxyIICqs2VdmgZBBBzlGAMbYTMvOV1ZnG5pkiYJe1O/ENfzsO1MmWartGhKZm4wfOAPiCf0NnN/e7iGOwc/sBLHRU3gSe/TtLQLTAohstc4rQFJbDxncBJxJazwfwEK4uolQV5mgoDg2sZw+UU94Eg0HUvh7cczlYRfEYlLpH49BCAdFS56DdWvxnHaW8y2H10tA8I5jn9eCqHTNst3qWRea2eYlUp8qGtozbJnbmUkqr0HTdq9y/ixItAhyAaN/YsBejvOGZipMVqL4iIJ+8BJbrIxPgoXc+ZBQ== 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=NmmKd2b1yuke7bdbTP7cX6qWkLEUh6jMStkliaGr0cE=; b=JL0wRNOX/WqKm7VFk0IrlBEFuRyerdLzIbPCj7k/cC5rO4e8BXK1+cNBjGWgJYbfOenSF41auWep5YcbFu4jnQE5aNJcn8BN3o/Lt4PxLwHH0YcsM/q6+Nn4Sgb3A4rOAe7H0/tHhB9xj5W0q598SzknUml6cWyYAZzGHiKExyU= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS0PR10MB6846.namprd10.prod.outlook.com (2603:10b6:8:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 22:42:05 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42:05 +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 v22 5/8] x86/crash: add x86 crash hotplug support Date: Wed, 3 May 2023 18:41:42 -0400 Message-Id: <20230503224145.7405-6-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SJ0PR13CA0220.namprd13.prod.outlook.com (2603:10b6:a03:2c1::15) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS0PR10MB6846:EE_ X-MS-Office365-Filtering-Correlation-Id: da11d856-286e-4af0-faf9-08db4c279ec9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cgqozrX1KNhT37Nr+xxq7Q4D7KlBR8wrnKyXDt9D3I0ivlhxF8b9wqXqTkZZG+7AS7BLZBbJKWf3NPlZaarOz3wex8HP52mcMloig1NeCwAFnuXFeoC3osPs/n0jJQwJfedk7VrGGcuObX3uczt2BHB5LypdOuAYTQV5yg1t/jxWPtsrWNrqDZreJvtXwxHz/5Rw3owCV2KMHLRvsZTGgJSpURt1pEjvamnKzjg4QiuK3LU5I2IOX+hUM1Ty77AWsv/CsUHJd/X/eZ2oNI3c6+Bu140N7ZO0oOWck9C5aD7c0aZgNp2WZtL/VKIadRWzMUHuj6HuEmLs0O+cNlbjvkv5vIGrGcV0J0ISqyfyi8csYtlAAO+WVin/k0S6gZ7jxTQoHKw+CoF29wm3q6I3/C42FuamSS9zNFoDJ0nN/TEO+i+GMP3EMpJwkwvV5rN4gzZk3DcHqsDRnWZvq1rbvP5fpYxORc70y9rI7phbACmvjTyty0dPg8vySxNpfnufN4VU30FycVwtCoyOUrTl9ixJtFxdEy6yFUJkjv4qfEDVMzvJLL2dN8MQH7du9KP6 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:(13230028)(396003)(346002)(39860400002)(136003)(376002)(366004)(451199021)(1076003)(6512007)(316002)(6506007)(26005)(186003)(4326008)(66556008)(66476007)(66946007)(86362001)(5660300002)(478600001)(7416002)(107886003)(36756003)(6486002)(6666004)(38100700002)(8936002)(8676002)(83380400001)(2616005)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WKbORwh3TLBYRMvHWgPYaRBEd7kLkDcgUK10vicYBQCcQ/6mjBXAuIOpjJklqH4zyktOSXDb1yBUtLN56jjkPet7IdxV5YO4NVPN/R8eeIEC3cHeDOrxiasOXWgsKKs+nwckbS+AvAFIA5lF7E+z83B3ZZEeTtqFsJ36VZ5eoPk9ALHzFCZ5XPGsxS28pukBbzZNy4Z/O+NQPlQYei/CxVZmWnRyb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N1zkW1joK9IK0LkXlspIDTZ0VFDUDjgv8OL/oAo50crY+A/w8HV7DCud9e87X0RIgqJa+EKHvbECnbqBb3L3NUGJzomrav4KqIEJfEnY5ysKjlqvNAYbAEJ7gPGNfFdZTAQLPoSjcZHAHhQiRZGqrYoGBBzonglL6ONZxBgKIwwXfsGysFrD9IK+is/aKMRpzP6J1pjjcZO4ksJKL5mc5jAh0tLr1hTsGbXP9E39zXNBcE7GzoDHiwVYQdKnVQTjWggTRWvA8CjhNmz8j2RXrFA3UGVopaSQ+Kv1G/dtKbL0w1LrZ0nnE8jvStKIl2IMNNMmCrkP/1/WgdavxQx7GhMjrgPk8RhuYs9mYc4LBQuqHEnL1YE8xP8Cq+gs+sfKyaL7HdduS5GIzjugKblMkwLatyDXeuNoQ4+rTknw8/Jpiw4+GqpWv6Eq7XoyCkJFfg/hvDhjaBzsYOcrTXtMGQWkwGj+kXVXGR4oIy+p/n0KabjsmGp8EMAgK9S4Hj+HIiQX7jE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: da11d856-286e-4af0-faf9-08db4c279ec9 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:05.7200 (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: hJGbg9UtIFV0ehSKdUSDmNYpbG2EAihg4CzH0otNBjnaaefZnhhumL52FVDr2mGLr4gmrlgiw71a/wy4xxO32B9bCty1F7KfmyVy47ffwMU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6846 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: j_jemY3WbOcLRBnSZd7GIoZ_xzV7scXi X-Proofpoint-ORIG-GUID: j_jemY3WbOcLRBnSZd7GIoZ_xzV7scXi X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764914725311208333?= X-GMAIL-MSGID: =?utf-8?q?1764914725311208333?= 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= 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 Reviewed-by: Sourabh Jain Acked-by: Baoquan He --- 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 53bab123a8ee..80538524c494 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2119,6 +2119,19 @@ config CRASH_DUMP (CONFIG_RELOCATABLE=y). For more details see Documentation/admin-guide/kdump/kdump.rst +config CRASH_HOTPLUG + bool "Update the crash elfcorehdr on system configuration changes" + default y + 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 5b77bbc28f96..9143100ea3ea 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -209,6 +209,21 @@ typedef void crash_vmclear_fn(void); extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss; extern void kdump_nmi_shootdown_cpus(void); +#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__ */ #endif /* _ASM_X86_KEXEC_H */ diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index cdd92ab43cda..0c9d496cf7ce 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -41,6 +41,21 @@ #include #include +/* + * 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; @@ -158,8 +173,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs) crash_save_cpu(regs, safe_smp_processor_id()); } -#ifdef CONFIG_KEXEC_FILE - static int get_nr_ram_ranges_callback(struct resource *res, void *arg) { unsigned int *nr_ranges = arg; @@ -231,7 +244,7 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg) /* 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; @@ -249,6 +262,9 @@ static int prepare_elf_headers(struct kimage *image, void **addr, if (ret) goto out; + /* Return the computed number of memory ranges, for hotplug usage */ + *nr_mem_ranges = cmem->nr_ranges; + /* By default prepare 64bit headers */ ret = crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), addr, sz); @@ -257,6 +273,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr, return ret; } +#ifdef CONFIG_KEXEC_FILE static int add_e820_entry(struct boot_params *params, struct e820_entry *entry) { unsigned int nr_e820_entries; @@ -371,18 +388,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 = 0; struct kexec_buf kbuf = { .image = image, .buf_min = 0, .buf_max = ULONG_MAX, .top_down = false }; /* Prepare elf headers and add a segment */ - ret = prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz); + ret = prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz, &pnum); if (ret) return ret; - image->elf_headers = kbuf.buffer; - image->elf_headers_sz = kbuf.bufsz; + image->elf_headers = kbuf.buffer; + image->elf_headers_sz = kbuf.bufsz; + kbuf.memsz = 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 = 2 + CONFIG_NR_CPUS_DEFAULT + CRASH_MAX_MEMORY_RANGES; + else + pnum += 2 + CONFIG_NR_CPUS_DEFAULT; + + if (pnum < (unsigned long)PN_XNUM) { + kbuf.memsz = pnum * sizeof(Elf64_Phdr); + kbuf.memsz += sizeof(Elf64_Ehdr); + + image->elfcorehdr_index = image->nr_segments; + + /* Mark as usable to crash kernel, else crash kernel fails on boot */ + image->elf_headers_sz = kbuf.memsz; + } else { + pr_err("number of Phdrs %lu exceeds max\n", pnum); + } +#endif - kbuf.memsz = kbuf.bufsz; kbuf.buf_align = ELF_CORE_HEADER_ALIGN; kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; ret = kexec_add_buffer(&kbuf); @@ -395,3 +436,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 = NULL, *old_elfcorehdr; + unsigned long nr_mem_ranges; + unsigned long mem, memsz; + unsigned long elfsz = 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 = image->segment[image->elfcorehdr_index].mem; + memsz = 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 = 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 From patchwork Wed May 3 22:41:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1658000vqo; Wed, 3 May 2023 15:52:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6LN6iNDSoN+eFYj8Oo2lkBT4uR8fBRsrvW+oWMX8PyB1ZlRr3p2ZP1Y3onVQtPLvhmhLt7 X-Received: by 2002:a05:6a20:389:b0:ef:c4f6:9122 with SMTP id 9-20020a056a20038900b000efc4f69122mr183098pzt.24.1683154363811; Wed, 03 May 2023 15:52:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683154363; cv=pass; d=google.com; s=arc-20160816; b=jUouyjAlWgRF950I6NN5QpdSxYCv0zTFEKl7lTrg8fpxb/BF+R8zlUE0Hp8hErBkfB m3cFk2nkE/HCHlukb0lXNtDk2EJycmtbmQOcI36dUrxpMuVGNX2lzryx+yw3ug3Yr6FT hYf8ckPiaR7IXVVlkCa+fciqbJ+xSwAnW1pOP+W9WJX43yJrLafhasEdG1tjnwzlm181 30v1PYUxi82YHz8VO5sIbFQmlTqHBuYPdigtbpzKZZr7ZefM7qeQrslJ1N6TXvONe7A/ ZWhLo10G3qyapwr8EpqpysYy/MZ3tqoDw2uc7EPsRk9W6WYYg/iwSclN3L9fCZ7q7x3u NUYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=OOrvwsmep8wFKht21oGhx9r49suR81kX+IFpmgNQfBs=; b=u4+Q4HtatjP3EWQ550Q8LVBa1xUBOlfuHvfWP1+q40j7t9wWojYIZ2wJB8bWuzyaG8 HJ60bkN3LD7yaQqIk1V1viF8djJeXvORScsg4pjqkk3QriFTJukIwSaNGMJ5E5bjpbTg sj4CEJAoTC/Yj6e2ZYkn//2wOJwoOEr+wFlIF50avNpPOfq92lKMJKmdNiA7YQLYmxIW jG+d5JlHOqiq/DsLXDbngErKOY6gSPxT/lk3IlWJ2kZUF3aG5WBbFjVWMJiWM3khkdlM il53AFvEnEZm14NaX+lo1CXxiFlsIG7kv4asJUvt1b9Z7mnuQEeYxr3XY3/bRh3lAc6k t18A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=2H3hFDKY; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dAKZVymx; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n65-20020a632744000000b00514329f7ebdsi35555111pgn.344.2023.05.03.15.52.30; Wed, 03 May 2023 15:52:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=2H3hFDKY; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dAKZVymx; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229515AbjECWna (ORCPT + 99 others); Wed, 3 May 2023 18:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjECWnZ (ORCPT ); Wed, 3 May 2023 18:43:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E3893FA for ; Wed, 3 May 2023 15:42:52 -0700 (PDT) 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 343HomTN017459; Wed, 3 May 2023 22:42:15 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-2023-03-30; bh=OOrvwsmep8wFKht21oGhx9r49suR81kX+IFpmgNQfBs=; b=2H3hFDKYCzd6Q2rhlxL89tCNXScXt37cSqZuxmvw6H5nsv/4Rsw2/RtI5mOpDvd8+71G uMJcWy3HqRsrGiykah5tnEcJrdzYDmV1hbXdxZPJY5cn6srpw7jfMGAkw1a7N7tRqjaq /Y0EUCSxX5Sv+lvF65UT4Rw5kXRN9mbxeWDewr0OF832pfxrIAUDYr9cHc8l2EFS2M/3 Tw5WEuOYhZf4EmtTGae91gbHInBLu3h4P0OAun5a52BGJ4RfrtobGwOIXDC8N/KE9IOm cs3wu5DWyP7FTILph5lIQo+dVjZmUryTZPKJNP1sZKCT5Kh7Hxn4pKhyXbtDspK7ERqR 5g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4ardvd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:14 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343Ln8XS020789; Wed, 3 May 2023 22:42:14 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2173.outbound.protection.outlook.com [104.47.73.173]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7qt2h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jsFeCZqos2ADs1QYkeYFaML/dJyFeyGY6MnqroEUobZOXZUDz2Y5qe85x40Tzzb+QOS9chdUzeTSS5csHYErubVq94112xg3bzFqjHqbhAekNKFVohLbTguxTk6ko2G74Snr8rlpqJCNUgvFF2tPm3fmp1ObdkpMEFYU2EaXhqwunNCbdXrI8u6YDvRbFhYKltpw3oXskFBFrY+/CcZNnFUbsI/slsQQlJiFSjLJJ4ncGC4uB8SUWhkn4EzS0ovlBbFVSazEsPGqKZQDoupqhQ8G5t7h6wRnycgzzURN48J2N53MRvYlyyCT3kpBsc8uGegPEdEVBC05SmYQmluLjg== 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=OOrvwsmep8wFKht21oGhx9r49suR81kX+IFpmgNQfBs=; b=ZdajVhLHDX3W2HdIivAfQlEX49q+FgSBHKXfwjqXU4+eYmebJ1PlQ0EEJh2R+bhQgQo250d4c+KnX5yCF4Iqlo0wknr2IW37SdfXiVsfboIA894AheUoHbacA5be2BVVuSMMLFNSD7al9BYQS22edSvVrvM1KSCF8BQj+R+FTfDnQjs3zEhBdGHXZQkkQZaUGWpOOIkJMeICS2M/Ns++Vw/lcfVr2H6XNdh6+gCKmN1XJmf1e1Gg3SxPfpemK/MfbuUlYTCIZ09EtQ8ztdDiIeYRMy+OwHR3NDrzECuckIO6hXWXI47iE56JAORLtf/4Fb9QGbi5AHhja/ECmnN5rQ== 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=OOrvwsmep8wFKht21oGhx9r49suR81kX+IFpmgNQfBs=; b=dAKZVymxeQqgL2vXAOMSNWcZ7BO/ZM9l89itxzTrSBmj/0l2/HHQ4ZkBmqKjOGwT3Ss+OybnVXcgzCoW2GbvWsohIPTEDjvWMYCBhPF03S/xcB0ZFKmXvQVvWdGhB+ZvSCv+EcGyG8mVVYrX47efDwqOvwC+bcr8lkRVJr4/20k= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS0PR10MB6846.namprd10.prod.outlook.com (2603:10b6:8:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 22:42:08 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42:08 +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 v22 6/8] crash: hotplug support for kexec_load() Date: Wed, 3 May 2023 18:41:43 -0400 Message-Id: <20230503224145.7405-7-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA1P222CA0056.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2c1::8) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS0PR10MB6846:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a039720-3c7a-4eb1-33f9-08db4c27a07e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UD69SbbahIZWcG9C62lgu/8Nz16Bc6IcrCDZv5+eG/QmROPbSQsVNh95LvcjFucDJb2CXK2la7xxt68nP2vuM6yMkxBj+49oyEx2EFAhJ2s1dTcKPcB6uKi2pYbbJE1vL5PEaSMgFToExw1rEumFEFrx84Jlpj0Omd8zCgwx8wiC5ubE3I307C2GFzwD2lt/8C9DweTm5oLtxi1vcuSfyzjqiEMWQa+nokVuAlWeeNUG13/vQ1ahwP+dkg3IqFzAOalCQBhzTkgBFURFMUUiqycZjutdhLr/m7y0UzJa1ubmCdZBbOSULujmd/cIk2f1uU6WrMli8lqwwdGlFaz+ZPSd9vXbW1oJY1fFKbdm6r1gnYC7UVoNQ++e8pwbbE58TE35LV9xqy1IB7xQ8RjZwR4KkJrnMIiMuLMwEosOsDB02JrZzfm9Ue8o0lfeR+VVBar3YCmVn+wsdicmuI+YQ4KWU4/NcguGhsX4rNdIMZif6ZcxfEO74SgIoYUFip534zB1DB04yXLLNE5YSaRCk4r/WEg1toSNwfulaOcxCj40L6sAiGl/62FEtGklyrzi 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:(13230028)(396003)(346002)(39860400002)(136003)(376002)(366004)(451199021)(30864003)(1076003)(6512007)(316002)(6506007)(26005)(186003)(4326008)(66556008)(66476007)(66946007)(86362001)(5660300002)(478600001)(7416002)(107886003)(36756003)(6486002)(6666004)(38100700002)(8936002)(8676002)(83380400001)(2616005)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w0Gb2IIaaIosCRJzERu9Lm5AmE3md6o+HDQ+kYGb5aTJHGWiHzpudrQJX5NGZu1MAEI3nAetj/1emozKSFCZLSEmUfIYBSdMJH5fnAlifiDWoXKXLYupfh1w4hmI7WDJdssrs1wSVxGg3WxLUVEj63TsKK1yok1uoIeCPxxWPuutcQQS9Cjs+zo9atvhkBJwg9yZ6u2etuEgLEeL64oIiBRZ1uQwtvjIHkgmVPV2+IiWbAVY+/ntDY1qIWyhfuZXkVgrRytylxbO1REA60oT2t47hxVhw1sTEkvJ6/8oOz6p18sO6GlZHqURQ4MkrCLxKi3oVwQUpxnlsTe4TsWQxFk3Us2rOhSYxSelQ8ZHEGBHVF7zdvU1uagEb0VJBkDFCjtqVW6ETRlXbiX8497zu5zK7jvVO7PPog3qQ1rDLQqG5G7YYhgW61I6srFOL9IqhCkcrsaYfYYGXzl3zyAFVDRsWn1SKvmlYL+OEvS2wyqQU3vHcv/ZlE8mDAoroy3uhG/4kQNwULrjYhwJS+N3BxV1nhYKMMmmVZ+nzzfMi2ookfDi8KySgR9FVqS31Ho91fKIUW8dFDq1LPIqgaMdMPRTPJ3c1t4Bw3OMZcRQTiu1IgVClODmk4UfNQoNOORH9QZMJjFjIjpermEZHubmRaSv9iez16LfF7DRa81CNwBpnGvazYY3naWE9A+ZhD5MtgN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3h5TW1HfyY1JNfCCZoXfQT4FEA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a039720-3c7a-4eb1-33f9-08db4c27a07e X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:08.5788 (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: RxQnOjNLdIuBS+17SKLbn1UhNQdt+ES4uPoVRWgs4oQTzCB5CZ4hmmWA5eoilLHfgzrxMEzIo1JHA2fCtIsEPvoqzlA49pyBkuekpPhufV0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6846 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: 7nMNUGutix53MXBxLx7JbdfFRvTuQuSy X-Proofpoint-ORIG-GUID: 7nMNUGutix53MXBxLx7JbdfFRvTuQuSy X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764915270137019157?= X-GMAIL-MSGID: =?utf-8?q?1764915270137019157?= The hotplug support for kexec_load() requires coordination with userspace, and therefore a little extra help from the kernel to facilitate the coordination. In the absence of the solution contained within this particular patch, if a kdump capture kernel is loaded via kexec_load() syscall, then the crash hotplug logic would find the segment containing the elfcorehdr, and upon a hotplug event, rewrite the elfcorehdr. While generally speaking that is the desired behavior and outcome, a problem arises from the fact that if the kdump image includes a purgatory that performs a digest checksum, then that check would fail (because the elfcorehdr was changed), and the capture kernel would fail to boot and no kdump occur. Therefore, what is needed is for the userspace kexec-tools to indicate to the kernel whether or not the supplied kdump image/ elfcorehdr can be modified (because the kexec-tools excludes the elfcorehdr from the digest, and sizes the elfcorehdr memory buffer appropriately). To solve these problems, this patch introduces: - a new kexec flag KEXEC_UPATE_ELFCOREHDR to indicate that it is safe for the kernel to modify the elfcorehdr (because kexec-tools has excluded the elfcorehdr from the digest). - the /sys/kernel/crash_elfcorehdr_size node to communicate to kexec-tools what the preferred size of the elfcorehdr memory buffer should be in order to accommodate hotplug changes. - The sysfs crash_hotplug nodes (ie. /sys/devices/system/[cpu|memory]/crash_hotplug) are now dynamic in that they examine kexec_file_load() vs kexec_load(), and when kexec_load(), whether or not KEXEC_UPDATE_ELFCOREHDR is in effect. This is critical so that the udev rule processing of crash_hotplug indicates correctly (ie. the userspace unload-then-load of the kdump of the kdump image can be skipped, or not). With this patch in place, I believe the following statements to be true (with local testing to verify): - For systems which have these kernel changes in place, but not the corresponding changes to the crash hot plug udev rules and kexec-tools, (ie "older" systems) those systems will continue to unload-then-load the kdump image, as has always been done. The kexec-tools will not set KEXEC_UPDATE_ELFCOREHDR. - For systems which have these kernel changes in place and the proposed udev rule changes in place, but not the kexec-tools changes in place: - the use of kexec_load() will not set KEXEC_UPDATE_ELFCOREHDR and so the unload-then-reload of kdump image will occur (the sysfs crash_hotplug nodes will show 0). - the use of kexec_file_load() will permit sysfs crash_hotplug nodes to show 1, and the kernel will modify the elfcorehdr directly. And with the udev changes in place, the unload-then-load will not occur! - For systems which have these kernel changes as well as the udev and kexec-tools changes in place, then the user/admin has full authority over the enablement and support of crash hotplug support, whether via kexec_file_load() or kexec_load(). Said differently, as kexec_load() was/is widely in use, these changes permit it to continue to be used as-is (retaining the current unload-then- reload behavior) until such time as the udev and kexec-tools changes can be rolled out as well. I've intentionally kept the changes related to userspace coordination for kexec_load() separate as this need was identified late; the rest of this series has been generally reviewed and accepted. Once this support has been vetted, I can refactor if needed. Suggested-by: Hari Bathini Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- arch/x86/include/asm/kexec.h | 11 +++++++---- arch/x86/kernel/crash.c | 27 +++++++++++++++++++++++++++ include/linux/kexec.h | 14 ++++++++++++-- include/uapi/linux/kexec.h | 1 + kernel/crash_core.c | 31 +++++++++++++++++++++++++++++++ kernel/kexec.c | 3 +++ kernel/ksysfs.c | 15 +++++++++++++++ 7 files changed, 96 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index 9143100ea3ea..3be6a98751f0 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -214,14 +214,17 @@ 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 +int arch_crash_hotplug_cpu_support(void); +#define crash_hotplug_cpu_support arch_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 +int arch_crash_hotplug_memory_support(void); +#define crash_hotplug_memory_support arch_crash_hotplug_memory_support #endif + +unsigned int arch_crash_get_elfcorehdr_size(void); +#define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 0c9d496cf7ce..8064e65de6c0 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -442,6 +442,33 @@ int crash_load_segments(struct kimage *image) #undef pr_fmt #define pr_fmt(fmt) "crash hp: " fmt +/* These functions provide the value for the sysfs crash_hotplug nodes */ +#ifdef CONFIG_HOTPLUG_CPU +int arch_crash_hotplug_cpu_support(void) +{ + return crash_check_update_elfcorehdr(); +} +#endif + +#ifdef CONFIG_MEMORY_HOTPLUG +int arch_crash_hotplug_memory_support(void) +{ + return crash_check_update_elfcorehdr(); +} +#endif + +unsigned int arch_crash_get_elfcorehdr_size(void) +{ + unsigned int sz; + + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + sz = 2 + CONFIG_NR_CPUS_DEFAULT + CRASH_MAX_MEMORY_RANGES; + else + sz += 2 + CONFIG_NR_CPUS_DEFAULT; + sz *= sizeof(Elf64_Phdr); + return sz; +} + /** * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: the active struct kimage diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 6a8a724ac638..050e20066cdb 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -335,6 +335,10 @@ struct kimage { unsigned int preserve_context : 1; /* If set, we are using file mode kexec syscall */ unsigned int file_mode:1; +#ifdef CONFIG_CRASH_HOTPLUG + /* If set, allow changes to elfcorehdr of kexec_load'd image */ + unsigned int update_elfcorehdr:1; +#endif #ifdef ARCH_HAS_KIMAGE_ARCH struct kimage_arch arch; @@ -411,9 +415,9 @@ bool kexec_load_permitted(int kexec_image_type); /* List of defined/legal kexec flags */ #ifndef CONFIG_KEXEC_JUMP -#define KEXEC_FLAGS KEXEC_ON_CRASH +#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR) #else -#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT) +#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR) #endif /* List of defined/legal kexec file flags */ @@ -501,6 +505,8 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { static inline void arch_crash_handle_hotplug_event(struct kimage *image) { } #endif +int crash_check_update_elfcorehdr(void); + #ifndef crash_hotplug_cpu_support static inline int crash_hotplug_cpu_support(void) { return 0; } #endif @@ -509,6 +515,10 @@ static inline int crash_hotplug_cpu_support(void) { return 0; } static inline int crash_hotplug_memory_support(void) { return 0; } #endif +#ifndef crash_get_elfcorehdr_size +static inline crash_get_elfcorehdr_size(void) { return 0; } +#endif + #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct; diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h index 981016e05cfa..01766dd839b0 100644 --- a/include/uapi/linux/kexec.h +++ b/include/uapi/linux/kexec.h @@ -12,6 +12,7 @@ /* kexec flags for different usage scenarios */ #define KEXEC_ON_CRASH 0x00000001 #define KEXEC_PRESERVE_CONTEXT 0x00000002 +#define KEXEC_UPDATE_ELFCOREHDR 0x00000004 #define KEXEC_ARCH_MASK 0xffff0000 /* diff --git a/kernel/crash_core.c b/kernel/crash_core.c index ef6e91daad56..e05bfdb7eaed 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -704,6 +704,33 @@ subsys_initcall(crash_save_vmcoreinfo_init); #ifdef CONFIG_CRASH_HOTPLUG #undef pr_fmt #define pr_fmt(fmt) "crash hp: " fmt + +/* + * This routine utilized when the crash_hotplug sysfs node is read. + * It reflects the kernel's ability/permission to update the crash + * elfcorehdr directly. + */ +int crash_check_update_elfcorehdr(void) +{ + int rc = 0; + + /* Obtain lock while reading crash information */ + if (!kexec_trylock()) { + pr_info("kexec_trylock() failed, elfcorehdr may be inaccurate\n"); + return 0; + } + if (kexec_crash_image) { + if (kexec_crash_image->file_mode) + rc = 1; + else + rc = kexec_crash_image->update_elfcorehdr; + } + /* Release lock now that update complete */ + kexec_unlock(); + + return rc; +} + /* * To accurately reflect hot un/plug changes of cpu and memory resources * (including onling and offlining of those resources), the elfcorehdr @@ -734,6 +761,10 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu) image = kexec_crash_image; + /* Check that updating elfcorehdr is permitted */ + if (!(image->file_mode || image->update_elfcorehdr)) + goto out; + if (hp_action == KEXEC_CRASH_HP_ADD_CPU || hp_action == KEXEC_CRASH_HP_REMOVE_CPU) pr_debug("hp_action %u, cpu %u\n", hp_action, cpu); diff --git a/kernel/kexec.c b/kernel/kexec.c index 92d301f98776..60de64bd14b9 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -129,6 +129,9 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, if (flags & KEXEC_PRESERVE_CONTEXT) image->preserve_context = 1; + if (flags & KEXEC_UPDATE_ELFCOREHDR) + image->update_elfcorehdr = 1; + ret = machine_kexec_prepare(image); if (ret) goto out; diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c index aad7a3bfd846..1d4bc493b2f4 100644 --- a/kernel/ksysfs.c +++ b/kernel/ksysfs.c @@ -165,6 +165,18 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj, } KERNEL_ATTR_RO(vmcoreinfo); +#ifdef CONFIG_CRASH_HOTPLUG +static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + unsigned int sz = crash_get_elfcorehdr_size(); + + return sysfs_emit(buf, "%u\n", sz); +} +KERNEL_ATTR_RO(crash_elfcorehdr_size); + +#endif + #endif /* CONFIG_CRASH_CORE */ /* whether file capabilities are enabled */ @@ -255,6 +267,9 @@ static struct attribute * kernel_attrs[] = { #endif #ifdef CONFIG_CRASH_CORE &vmcoreinfo_attr.attr, +#ifdef CONFIG_CRASH_HOTPLUG + &crash_elfcorehdr_size_attr.attr, +#endif #endif #ifndef CONFIG_TINY_RCU &rcu_expedited_attr.attr, From patchwork Wed May 3 22:41:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1658517vqo; Wed, 3 May 2023 15:54:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7e0W9WxYNQUqBwOOfjhu28DpaxNcFQxHs78VVMPQBOF4IcXxyO1wMjvt0y4tBW/hBUrdsj X-Received: by 2002:a17:90a:800b:b0:24e:46ee:e30d with SMTP id b11-20020a17090a800b00b0024e46eee30dmr212377pjn.15.1683154455461; Wed, 03 May 2023 15:54:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683154455; cv=pass; d=google.com; s=arc-20160816; b=UjE6j4jI6If1RdkIapwqTK31snBL5/Bncq+kP/HgDqTBtFwSW9taqQ4ejfqXHjWKsN +Blz8jN+xs8JVq8CY2d4Ow3/SVJR1m98Tl0OT+Q0srrUAYgKckI+C2SSbIFek78MITcz kotU5TUcnat+UIZEFHMtZvaGJbeeYse6c2420qIRgGekedjV0kuJexZp1DsUQxQHknul 0f5PuFKKndg8SnJV9VFYq2KUL8pg0ygL0mDyOgwQ1vIadGNTQ6I8+tJPMPfPnQrMK3gW Zvy6/tXPIkyXZDX7OxzVkI8kzsbAZfy5B1YkCdfy63lF+M0LD4MP6rcmXniLu/dMf+IE Kofw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=pYQ9YTHJttRtfWQfKeEO9ztZhwycCF8FJtcgSwpwf/4=; b=h45jD8pkmgAcoXkJtZB8FfXZwFTzRpZShpnROJxcyiHYwGIiXN9kA798Fq3wLcI037 kTCyqXfsxl5e9pd6Zp1bvgJL89ZurVY6mFBBALyWEcuLfdKBPc1FmXyKmBA/Hp3oDwUM /9t8d8fF7L6MwZOjzHPq3r+oAMUDc7cDTlMRFJo1k8hmWtz+GsNPzHeWiE8el/vNnXRq 5iJsKkhoDsG1RtfzrkCXlFORSwVDe1TwY0MKk8B5zjQtqsKnJcs/ApZGRIovE/Lnqy2U DD5Uz+LzoSac/ydhsoPz0Dndv53ggIBF8QtrOvoMUT/hVVmSR85qlxVg46GbPAMPg7Ah MVog== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=rbZuznYN; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vVDqubV+; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np10-20020a17090b4c4a00b002477dac5834si15726089pjb.95.2023.05.03.15.54.03; Wed, 03 May 2023 15:54:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=rbZuznYN; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vVDqubV+; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjECWn1 (ORCPT + 99 others); Wed, 3 May 2023 18:43:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229515AbjECWnX (ORCPT ); Wed, 3 May 2023 18:43:23 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37D893F8 for ; Wed, 3 May 2023 15:42:51 -0700 (PDT) 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 343Homsu017456; Wed, 3 May 2023 22:42:15 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-2023-03-30; bh=pYQ9YTHJttRtfWQfKeEO9ztZhwycCF8FJtcgSwpwf/4=; b=rbZuznYNwRsfG8K+5SRZMD5hEWrPbAifXQaVjPW9NjbjZhYdjTN+Pag6ITAmT7lihNbJ AbN6h7jo2JpstQ11tZepU8/US0I7UARqsY2jaU3PsDDN2CW1gggnzeRjlrt90K+6jrzl IlSDY3mwilp8N5+ApLKvuFQtp48ygYam0dJ6RH+LDoJOcv7MxQMitejKiuEgdB1QT70Y C1sPch9RN7kEg1aGTSymgZh7/IWK4eLmEdfiw/ssoUlo7pGrIEVhwesL74YCAsli/yss si4eczR2KTI9iH/Vgls2j2DHEU20NfsYCoCf1mxuUjD7I9vMPpogA9CoYLDMme0M7zRW Lg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8u4ardve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:15 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343Ln8XT020789; Wed, 3 May 2023 22:42:14 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2173.outbound.protection.outlook.com [104.47.73.173]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q8sp7qt2h-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ia8dsgWUCmryAKJQrMg605Ce1v4h57k0AkqeFOOFRp0ROzVVFDcKvaK6Ulh+lOTT88FWP+unSa9VnLdkHT1Y1zzKv60lZE+2rT0ZTR0jjDqcEUcAEpPrbSut5W5r9GFna4s5dND/ruDPTxI1X/0rTyZnhMLUCT+V/Ibi1CXl87QouGjNbe6VwlI9CEJ6rAMiqRqdsM7ETgVlwYr4H8vvLzkogivut4GkHVgOJmhZQINJ6ywAdlk2zTa4+yTvv5K0ot2RYIJBhjrBPtKrwOk0imxFnexqp+bJNBiSvtooOX79vYMEafPLXRz6M85CW7086Ogs77udZcYMa5nlmEg4lw== 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=pYQ9YTHJttRtfWQfKeEO9ztZhwycCF8FJtcgSwpwf/4=; b=U4uT+dHKQYvGARjPMhMRQeDvZtRvResSDt6aTuZh1U6w/TFZ+OViSjtVENs3gfBkrAN1hFuM9SKLsfsmGx8TZwWAY4nnMzXMY3sPsndujawY4oU2rO8KVSOn7mO6o0q5OklwahlA24owggni6kqE/DHlFCqbI775wscrkFloHCdo7ZpYLfRfS19bmVDebjiRdmqa8cux/TGOvZhnFDp+EJ/t02kZPDn90K5dPxR1mHf1qlyXcpNSdu6+s70LDcK7pNL+Jy9S5ZrcqmLFbE6SmLxU0FibIhWHdM2VMhcfIVv+xrOIcNQkZYt3VM528+FwzaM1EyWeITJ8Jd9YAGx4qA== 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=pYQ9YTHJttRtfWQfKeEO9ztZhwycCF8FJtcgSwpwf/4=; b=vVDqubV+yklDRu5meC2HAiaA4/6mlwLrwTIzTjZ7g6Vf47GKhmxZkrqyoiYJrcLgTj6w/wpoTcJ8+yPJSPXTGGCj6Rg6AULAxKva7I7Ns7Ieq3KoeyMfq8cRaxo9WBHlPDycA9+HDR1WiGKS1IUR4q5/9ThN7Z4tY9T4d3ffaEM= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS0PR10MB6846.namprd10.prod.outlook.com (2603:10b6:8:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Wed, 3 May 2023 22:42:12 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42:11 +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 v22 7/8] crash: change crash_prepare_elf64_headers() to for_each_possible_cpu() Date: Wed, 3 May 2023 18:41:44 -0400 Message-Id: <20230503224145.7405-8-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA9P223CA0008.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::13) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS0PR10MB6846:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ad639ce-f78e-47a1-9396-08db4c27a239 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v3QhJiUuF+/xAFa5CSnKc/Bf+/BrZmMwD89QoKZUj69GtYXraSavDCt/MIKtTKM1GtV1jUVk4QtvuU6bo75AFOXYXgWDd4jqma4PS9JgMQetApd5TfH3a/aqODebJHtBLf9Oz/lrEzL52245ofdl3IlIim2BcKaZ5mxCkLH2GC+xcLYJqejIRPQtCBbGG57ptuBAgcRkHnfalGaDiD8vyhq4wZTcK6N5pwzhqXcpKHZIYG3v1eCyxY74c9kO00WLb4S8fLGn98NoET793LqwTRRLPzMLf5LuSRmvQy8ord1jD+W/da8L986iH5A1A5GI0fhwi3LqP0HJfvWpiea3fo38qiOgxnMn0JC6WWK9vgSC5j6d54GAKc+yGdtdyym1ZxUfgbv0pt9L18sz8l/AlNXtpaQUGRkkZ2Y2cy/KJ/GKgErOLCX9liV0byNKY8Soi0dMJAUyFZtteZjpqDc7GHqhphP1D+d6tu+3Z0rrasIUtrYKafKAItigup+fQkhoCJVnbxQ7M8JVH4RMy3+X6816S80Q6V2rtG0xY9PSz3s1m9bzXpQKzsyzd474zGns 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:(13230028)(396003)(346002)(39860400002)(136003)(376002)(366004)(451199021)(1076003)(6512007)(316002)(6506007)(26005)(186003)(4326008)(66556008)(66476007)(66946007)(86362001)(5660300002)(478600001)(7416002)(107886003)(36756003)(6486002)(6666004)(38100700002)(8936002)(8676002)(83380400001)(2616005)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /f5L4uY0L4eFlGgohPKtkIgsruHS+k/nuMvrxS8m/bJzA7JW9VABFyQB7jEMQgmgq0k+x+Tn5NR/ixeUAk4uugu2rkTa/uQXG+JET32cv3r23GPLu7dCWiFxUS7aaakLKvl14MZJVMctiUoQnGQ6t31ZCUvp8+NMUzbNR8M5Gal0uJ3Qb75JHlkMsiiXXsjSCSJOvRo7AUrAQUnKRim3smjgPfHTfDyw6Oiv5FnbeiRPbMcvwYWOy34qzu1MdY/NUk4qk+ArOyM4BpyvwQB1gxjGKpyGR1A0XsM/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vcGCIxOIZ5CKxYPseMe2p4AHa68Poko+7fMw2PVBxACaX+auAfCCLouSQY/8+mFpjMBOA9Btl9Aj4F7rj9aUAP63eN3gR1x0kEEJzObr8Q7Fjtc/38K36q3rkqZEtH2VKWioqefkH6jDPJwf5RXNJfbbLrLDnpkHXw3upvTHPhCCMHVCIDQe42Hu3Eqsonpn1JIYMED0l/jKRQWlRO+h06Tu8FcbGpVsWH/OEI4gaUVwXO52JQi3U/Fonw+g== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: WL5iPOhBnuMo1lwmoE7bIKsws03wQ31B8K1/pNSJoSsmebMQkgH/3h/i/xEtA3iKEOR7YiQz+aId7LhmdQlJVDMlxFxYKNWcMXgdg7yi9Iwq/JHvwltyI3SPP10tWFjdaw7D8KEe3aXe/enpddVT6eEMJtB+Xfytsn28Sbz962N60dA711eZlAKRKy8MC03/oB1L7wt27H8CJ8fFzV0UftT+6eSED/6tdVV/9IJLMuH4zSIlwUiMEblCNwxOxkEVfmqgDJfPBj9I79K9DmI4L5TmSQkgwEkZIh01CnWPgX0KbdVSY+ooM3H3eNXff6xRppa7Tejk8hgayC58L72fkwPuUOf49JWQ7S+dOSonn8T+aM3QNVOPUj06mj3snDtNGe/qftq+1O0kua2tyyXmD4sq663gZf+lJiBZSThMCus8cZikypFdfAzeeXZEDO4Jua7fTU6eUDQdtmPdt1Q7qTToT60p0JRGvxu9oHt01/tVOZT9VO3RVZigyWl5CKMUqjcrG+JDvroKhtdySNQt09r9R3v/7p/obLj1EMa+Q705R5XGMHKSQ217m2WHTCRF4Pv74hFwqlADDWVxn6TGw99EzONMCwWazLJFNyrmKVJ5OX4pYBvVItLKwSGYvNYpWWhWroQxPANImnXc5qvZvOPBSoKVHCFpgNdEOY7kpLoEO5JqSGnLkK+Kmfk53qdd3O0kYpUqW1r8ZM65o0cYSi2UfTYbyUAKBRiL0AWOWSxYaFGAvMOtXUH72yV+1A38pjdlfkU5gd4vTpIcqTnBbAcr5HyuUnE70ZspiC6L6zGxCR1xeoApfiWeRaYyHF+bruORP0H5HXyEB9g5zJcpdrFuNWjqF9i6Ejqqu9oxANQtHUlYMcxMgfcBpLEOamnn/9bmXN7D1RMl2KaZlEmIVyXv8SRNE0BOnie9WrIY3j2X+OyLD2rlz3GOnqBujWMiZzvKQpJ/C70monFJtl4XCbtPB9rmpqs0u8OEkF4n3IjoNaM9VbSrJq6HXgKujHT3FYTCWvVzFi5imq91k4bToVAnSNdmuFkUroW0pCqcLjqKO0LZf4lm8/4rBmLxU2blfFd2WBhCDLa6EkD0c4MPa2l/riGSrR7miwQb5dEvU/AxI2/VllxB9Zw1UMqCHoZzsHxKAM7DUSyNLd/7ipCBn31yMhVNdNPdSskHblKL/Qw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ad639ce-f78e-47a1-9396-08db4c27a239 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:11.4304 (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: v+eF1mha4pg1QHeVWhkx2QzuXwLhOhrzipiJ3wYX5kO2bK458cl9j/CVVuXZxcswldnSOkcQqQpOx01iFsSH2KshjFylwQZQW5QF6af1G7M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6846 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: U40JdNNQj_bwDfUISGu1TIH_kTnqdBqQ X-Proofpoint-ORIG-GUID: U40JdNNQj_bwDfUISGu1TIH_kTnqdBqQ X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764915365879419099?= X-GMAIL-MSGID: =?utf-8?q?1764915365879419099?= 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 Reviewed-by: Sourabh Jain Acked-by: Baoquan He --- kernel/crash_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index e05bfdb7eaed..26262789baf6 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -364,8 +364,8 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, ehdr->e_ehsize = sizeof(Elf64_Ehdr); ehdr->e_phentsize = sizeof(Elf64_Phdr); - /* Prepare one phdr of type PT_NOTE for each present CPU */ - for_each_present_cpu(cpu) { + /* Prepare one phdr of type PT_NOTE for each possible CPU */ + for_each_possible_cpu(cpu) { phdr->p_type = PT_NOTE; notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu)); phdr->p_offset = phdr->p_paddr = notes_addr; From patchwork Wed May 3 22:41:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 89865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1658337vqo; Wed, 3 May 2023 15:53:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NaSfiokIDqFtxDhQ5pDEw6m8hbSTcW5hN55sH6MVB59tDgoYsctWN7LiYpo5eHyOuOl6W X-Received: by 2002:a17:903:11cf:b0:1aa:cddd:57d8 with SMTP id q15-20020a17090311cf00b001aacddd57d8mr1981770plh.30.1683154428234; Wed, 03 May 2023 15:53:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683154428; cv=pass; d=google.com; s=arc-20160816; b=eKxu9BBJ27RDAab99cagapjDH0WyfFovJdWYvpxkzUshSa2CJ/Oj8CxU1TQlMeDMic Nd+7ZoPNR3gwUkACaIxlWygP0B6fV+s3PA4Cl5BJI7TfRnRo96/sJ8n01IhxrPyHnwUR bc9X1YITKEn1jw/Uc4HamFdxqKTtspawkU3k2lIQ0cu7UJyd5/qExMg05eGqOx6vCaEp 3YfoKfMcydI2v7OJ47euxlI/kr9MBy7XbgJDDx/3Dk7JnWC4SPAQ5Kt4E+NpYxSvuTZu P951zSRf5Fz/Rtsu/QmbO65HG8NAasf6iGNPeYFXHzEF0gOtLRryx4yHQGUwmwCUUMa8 H1ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=bMpFfL660RmRGt9oa4pscrj4Gs/dqd6VgnJgCSKGmpM=; b=OhUjmF6K04PBCAUQHKX8y58G4b0AVA7+vvEjkHzENBO7urKzzFL+lg1Ho7ZUzUAuN+ e/TyGrgLEYi4tBNqbV6D4yhpY52gDUFT/Wam2ULQe7MpWSV6dDNLaDybzCtsTgt2VFog 65VIZ4q0aSq57l6PI0h1PeoDxAbSDGQ+ZSSZdklq0Kso6akreQ1l7RBHZly44rQkZqXx gd2QthOR+rjZmK7bhueoXDAvXksPhGg9k6qqshf4zpL5zlQiMMbf/IjZBCYFV4mqsgcl XPxuis+YIUUij4kPm0/8G7zPVdBo+Ar93SFZgF3xWCXeON6N2MjjBraeHaGaymhoZUyt 35Kw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=w2Yd7SmN; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=YBhq0dQ+; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a17090a930800b00247ad6e4188si2474222pjo.51.2023.05.03.15.53.36; Wed, 03 May 2023 15:53:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=w2Yd7SmN; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=YBhq0dQ+; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229664AbjECWnT (ORCPT + 99 others); Wed, 3 May 2023 18:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjECWnR (ORCPT ); Wed, 3 May 2023 18:43:17 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D85493F1 for ; Wed, 3 May 2023 15:42:50 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343HosBH016626; Wed, 3 May 2023 22:42:18 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-2023-03-30; bh=bMpFfL660RmRGt9oa4pscrj4Gs/dqd6VgnJgCSKGmpM=; b=w2Yd7SmNJz2GaxVHYgeJEI5Q/bsOhly9d5wrFdFeYh9BaDijAZ16nAUDDoUZLEZ41OKR FvYgvYahBXoXtUwfKIfha13AEZUa3fdVRTz+gSdMmk2SDZE69i3GpfPjHvPY1agj308w z8+8JXWgb4O0Pl03qKEP5tuO5ligxsbA1FGEHx723Goyt2988fJNhRB3wimhBRl0TmVd vmYGOc8RYTw3E4U5iiLDKCev19Mrj4EzzIKa3fANjtB3P2Ys7U5j2l75yQKA1R3ZPHzv KKsQ/fNtfsyd0ezBptGUWa4KfmMzM8yx8+PQF5nDFkbxKF9TEn/t6A8Qdax5SzjKbFFm WQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q8t5frj89-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:17 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 343LBq43026812; Wed, 3 May 2023 22:42:16 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2106.outbound.protection.outlook.com [104.47.70.106]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3q8spe10ve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 May 2023 22:42:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K0V1mhmR2uXo2ybh0MQs97SJmT2h/ZmYiZh79xTQFOBjoLwBQgYzG+sBvMXYQQpMgF2ATKq1npiWYmhstrX81ghrjvER7jpztJReeI/tsiiomD/nenD7NYK0ZtebjtAy2TayAU+QqkIAn0PyBJvDyTDRyP/gMsvf3uPZg5QnWUmFke8FRD0Lgrw4rHL6qkcxtscVpdYMynlFnZRld5tnFpKqt37DIV9PhFdZF8UaP6bDLBVB2eCTMWBQdprHMnH2hzU2xQ0YGNMzW0OqKKZDPjzrsB0/Em3v6NdvKjgdoOQHyHIxBFEv0IcWD6YwDKhtv4GAGV3bJhjSQ4/9t7QHGA== 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=bMpFfL660RmRGt9oa4pscrj4Gs/dqd6VgnJgCSKGmpM=; b=Ss9CJW6/kKnb4jMRHnv3GtV4q4RsDBmsC8vMjboXVrs2ws/+wrrPSytfDX6/ttB8kXYjkdbiP2G+f8ZkEUmbFYkp/eo1o/MEoVHXdFyrnZQbxBXTqS+couDQWJjoWYT7QhL4IYSOKO1sNuAXfy6Vu2PWFcLaqte66+oPr8vH5qmlOjD5O90p2wYeDQRaRaQpSBwWwejPVsIPzRkRntvknpq3vDmF0eeZwQgkfBI9XgnKHQAJEDMRdKaVIzvF8f1DzwtmfuIePD3Pxbt4Z4mYySgHOPXzuvb9OxgdYtJkuhIF2z+f7UBMQaDNW0q5d7Q9jRsZL1XJkyd9N/LeQ3AzBQ== 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=bMpFfL660RmRGt9oa4pscrj4Gs/dqd6VgnJgCSKGmpM=; b=YBhq0dQ+Nfky+xYWWv2PEMQiH24C8B6K/iNYcveKtpfDIy6hVx0FIzuy5LsyWgUCgqFX3kMdRuHHKOgVZo2LfVk16VAy+gVeXYTIYc4RW3lWoQnlN5evH/4MoFO1GWW0KuDJEnnMUa2N6Du7iNmOD3My4z8MgeR2YvjyxywVD1c= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by BY5PR10MB4132.namprd10.prod.outlook.com (2603:10b6:a03:20b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.22; Wed, 3 May 2023 22:42:14 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::ac1a:bf88:bdbf:2573%5]) with mapi id 15.20.6363.022; Wed, 3 May 2023 22:42:14 +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 v22 8/8] x86/crash: optimize CPU changes Date: Wed, 3 May 2023 18:41:45 -0400 Message-Id: <20230503224145.7405-9-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230503224145.7405-1-eric.devolder@oracle.com> References: <20230503224145.7405-1-eric.devolder@oracle.com> X-ClientProxiedBy: SN6PR05CA0016.namprd05.prod.outlook.com (2603:10b6:805:de::29) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|BY5PR10MB4132:EE_ X-MS-Office365-Filtering-Correlation-Id: 5be0d5eb-bdd6-4e5b-8215-08db4c27a3c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gBfD1A2i00nIRpUtq38KlZAqNFb/0S5+XtePr6Hkl1T3L11yN5Bdd9TyUFaW3zH0oR6nECIJD85q1JJcmG4WyWmF55ZlR1X6tOZquT3IP9s4lzzXPLyd6G2PXWssY3lPchhgn/LWKdSIh55DRIHeu5HrNQjDJnYIUk5y+JfvtdJcAp5TdvDRhcTgfZ6ydS9w8h8UjlgSOamyU2YAs/DPFD1PTVhxuBw8R7zSN2cbE/uQ4wh0YGtXtKMyLpsfCwwhTsSGKEHVdI3QaqUy5kfuh+IQRpShrfGxO45qsZgvytnMm4oB3aPK0XqZwm2mX+FqT0bHvM5g5hDUXZB2WvYuxpAo96bFD/5+UdadVaKMIVsX+WoWgpUotd7C7VSw45jWVmuAzR9Wf4zY5TUqPERn+lzbBi1NgVYePznGvOjwUlaghzo2pds03p0FrCGujWgoMd4mYGszoRIpfLGzAN3ZIgHCvQsknC39UvING2MTPJRtZ2WOzksbAPj9JFciZSj07J8P43usc+T+oJ7/AYA9kuNvzm0ykRHr6csg7H0GBmWnOJcYh8+riaTrWSkKs2Zr 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:(13230028)(366004)(136003)(376002)(346002)(396003)(39860400002)(451199021)(6486002)(4326008)(66946007)(66556008)(6666004)(478600001)(66476007)(316002)(36756003)(86362001)(83380400001)(107886003)(26005)(6506007)(6512007)(1076003)(2616005)(8936002)(8676002)(5660300002)(7416002)(41300700001)(2906002)(186003)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d01wGIuVhby0ILFsqvLQBBYdgqly1GYIsJfSXu1APGPOHhdkPQ9z2+1zOoU6NqaQrNHAiTA/qCi0Q0nC3UniXW4fz/fa6eI52AMZfW62TijUSt23lVC4inPSbWcKFD+1TLQbmd5VjOHzfNdN42RbqxOqSaNfucmB/lq7cQGEQ/+J881FxWphkHJGEEhOEeOhUb0ao3c7CnI7FUmw4xNx0qAolXo5iqbwTsw9uDoHcZmPv2iy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tx1rCAmyoQOvtofV4UBBGQl+J9PcpKn573WfQ9SLfSvFwE9K8A7uCCyGLIrzfBx9bwerkwyXs73FvYEkOk+hHKm6m4bS3l+tEvLrSAeOBy4qzFp27Vkufv+D09Wx1AQUtDPPrPg08y3BU8XlhItkjIjalcUxg6sj21VuQ8ncFijYf2QyxSH5V1ENTkK4zVkKbZva29fuSvyqGiMKY/acZkv/QfwFgQIwwDBek2huMSX2uFaem1/7LbuXP/wxDWScuzjIKbPVrM7SAcHVk0ySQdFgj/JzxbvifqsN3fk1/TvDJQctfNvA32FvdR18wjQb8dHfETJ7N40VUG8xHEfK80AlchcxP/lEbn0vJhQYE8QrSbhc+4SvQMbUMOF1woRsyExxinTlrTe7zIiVViufQyrlh5uULZBN6vTSwUgkMq4+yHLP+z5ZGHP6IwQucHJ/B9lnhsG+q0aQSngYxy6PEPSj0Iw5AtaOdZrMiOKLfMjVZJoE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5be0d5eb-bdd6-4e5b-8215-08db4c27a3c0 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2023 22:42:13.9606 (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: UcnmfpSDOsDWyOGoc6NmctjX2iWfD/ICBwgYRDCK9oasklMYk1C2HXvGb2lnPTqUS59Kjh6WVDkEvd6Z7JqAsHMjrs/i6tHULdaSyHjHw1I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4132 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_14,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030195 X-Proofpoint-GUID: U4GJNtjxxsXBv4_BXR_TFws7zEx886c8 X-Proofpoint-ORIG-GUID: U4GJNtjxxsXBv4_BXR_TFws7zEx886c8 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764915337455169881?= X-GMAIL-MSGID: =?utf-8?q?1764915337455169881?= 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 Acked-by: Baoquan He --- 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 8064e65de6c0..3157e6068747 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -483,6 +483,16 @@ void arch_crash_handle_hotplug_event(struct kimage *image) unsigned long mem, memsz; unsigned long elfsz = 0; + /* 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 == KEXEC_CRASH_HP_ADD_CPU) || + (image->hp_action == KEXEC_CRASH_HP_REMOVE_CPU))) + return; + /* * Create the new elfcorehdr reflecting the changes to CPU and/or * memory resources.