From patchwork Mon Oct 31 19:35:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507340wru; Mon, 31 Oct 2022 12:42:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM697qaKy29hK02YywoBEAY67HmrKaqRkqtPevgmyeMrolpXQba4E+4g041M8CupThjwJUA/ X-Received: by 2002:a17:906:8a46:b0:7a0:b8ee:ac06 with SMTP id gx6-20020a1709068a4600b007a0b8eeac06mr14612200ejc.42.1667245322519; Mon, 31 Oct 2022 12:42:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245322; cv=pass; d=google.com; s=arc-20160816; b=mKMr/VGw6xyL2kIpugxSS78Os3p7DLVeszkCCEgmW4JX37V7ufBtyHNuGuXFkGfzLC OEQ4nSYO8t6jL6c71zfjc7BF5VcZ5DBX9pSeU6wbV7YDKZyYgJDfNngwxRadys2VPnll 2c3AU12hZkpPOOFvkobqU9Zmu7FMOvnWzVN0ihsqnGI34cUbaWziv3PJqRw38TS6PBm1 PaiKfNVWRYWU/ischV8Ho9IuwHqm/oR9Ada8Fn1d05Ws2Y3EWYb+ZMWumTv09EOFR4xs T8cQxAehmNQy2gMmDylf4CfO523sh+yXnzNERu1qijah0xd4Fx+3fcIgPpt3AY/EBbf0 7tZg== 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=yMEg29W3sMLUXgMiy8fBRbgWQt1x97oMT+MMk1QNbdw=; b=Ji3N73sszL3c33X90VN+5EW1EXMyPQO/dE2+JLiIW48zeY7UUwq2LE2bBwJiwRwq4w FhNilMhK9mnMOPogpTnxKWcBb8Ct8xA3Kkn/bfoFjuswngUr7URq2VNRGYjDGT1ZZJmh 1vA8bQvJQpW/qxN+3ahtgHTKHGfvhuWqP0IVXKQ2bk1pHYshzL81fouXm4jiAhjN3z/X W3VfvjWtz/ThssLlzm1/XUzhIIGWVA5hsXe8d+K0JKX4etzNhh+zO4rYvOvCW0+BAub3 qb+Pg8xFfKqZLUY8pJAU6uAQMDwGijOnpa8kIf8VU+YiCgsKq95+ceZ989illCsRtQZk 0e7g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="Wr/p11WN"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TtlImhyr; 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 dz15-20020a0564021d4f00b0044f2fb68fe6si9830542edb.495.2022.10.31.12.41.20; Mon, 31 Oct 2022 12:42:02 -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-2022-7-12 header.b="Wr/p11WN"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TtlImhyr; 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 S230116AbiJaThC (ORCPT + 99 others); Mon, 31 Oct 2022 15:37:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230057AbiJaTgx (ORCPT ); Mon, 31 Oct 2022 15:36:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6387D13E2F for ; Mon, 31 Oct 2022 12:36:52 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VGx08m014808; Mon, 31 Oct 2022 19:36:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=yMEg29W3sMLUXgMiy8fBRbgWQt1x97oMT+MMk1QNbdw=; b=Wr/p11WNfzIlLNdia6i4gN+IVMKMrEhV3u49gUR214YY49kB49bnUDv4wL5ev/PwlG2/ DYmX/WDs/rAQkDJIJg0wt76wpD6qx8a27D8qGLgnKcWigBhebYNN45A7UVPfC6vuWJKR sz0qhLk49cLd1RtYDyPnf0BuJBoH2bnvIvSCLgu+sqiuHM+oqidgP/uvN/3efCYNam+N c9iBmJ3liS0ZztmgqH3vEfiLVMbpxiDpBGtQYR5c2QeVX0I41ASd4EHE0BMW/llCv/AN luWCE5a3cAijoJzXFDOqaTHEYzwdcMYImcr/gRzN+zTP07qSUTx0GHAFHkBQRKptbPJy Ww== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgv2acn79-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:18 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VJYPkm033096; Mon, 31 Oct 2022 19:36:18 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3nkaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWlZRHVybm64yul1dMd20iWrsyJERDkfsMvFPgotv/yNEbfGkgZL+uNzSCTGCGi64HRNp2+OJmYjDv69fhBWLQI6Hm3WdW6doDy6zmimjJ/dPYAXNfn4GV+oDv1fZYFe4ODSPwAuvd1Vx039xevp9L6ufyGfPPYlsLl9xaeAy5WDNV/hFKNiHHmpczf8ikdfaBSxQRVb0VsGTMNiNWL0Db1GPzFK/yKi5tGQ1KVAy9WM75PckifEmLy7VRydX07nvjYokWnueIbKFpihQQmqmszQXxhkKFGl/juWYsrjGJw4uRx8ZR2bLKswNvcIa4cePryKFl09ZKzST70Y7KGm+g== 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=yMEg29W3sMLUXgMiy8fBRbgWQt1x97oMT+MMk1QNbdw=; b=INmot3dNzDF9xUs9sv/qepfDYUE2UQ3OwRZXMSsoZGnPx38bprk6FDvO3FRCQQh7FGV1PRMnQRo0ANaCpKFc81IP6wED8/Wv3ISjUf3kRFHrSxaKaLahdprRj42tMy1TaSJph04D9wApZP0HadkcfIHbuvsLwZ00lJBN8MJ3p1zPl/u4zFYotRjPxABpGrsJSnR3RmArNHJjGnrsoYbUTbHY2dODiFzStmBs+NlKsJG5Uz4Qa/Uh2hCAIHzMSNIsdj1WPoyoodDzKADj33taUH5XYYA6RhUPnLWfrKF9j+r04Of2RlGLc8hQQa/YgHGuf2v30V+04AYyKgR45EGZoQ== 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=yMEg29W3sMLUXgMiy8fBRbgWQt1x97oMT+MMk1QNbdw=; b=TtlImhyr41FNmMCln7cVA/vC7QDefiu+6rzPKAhf7dyPgvl3bKWeAmMIsHl4LHx05vE3jniy19GdgFxrM4GxkPYxZ361TQ1obemBdtyYsV2nrQaz4AKEmDhd6KLnkZLsu+52aLjdKNPVaqVSSPEA2c51RBI1Vt/NpOKhwVDQMrM= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by BY5PR10MB4228.namprd10.prod.outlook.com (2603:10b6:a03:200::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:15 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:15 +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 v13 1/7] crash: move crash_prepare_elf64_headers() Date: Mon, 31 Oct 2022 15:35:58 -0400 Message-Id: <20221031193604.28779-2-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SN7PR04CA0174.namprd04.prod.outlook.com (2603:10b6:806:125::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_|BY5PR10MB4228:EE_ X-MS-Office365-Filtering-Correlation-Id: c0bcf738-43c9-4c92-1d15-08dabb772cb3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AaUHiE2VLHqOnYX/fBXYxomln15I53EJMS7qwIntNnUsccbfi7iAl9w51CZabaq3yWP47NFsjoafWL/45LBhLMK2DWM5SDCz1SyGPaGR+/2WKzrQPDwATp2VCgrAMdWACn4SbBfr72f26dcMkw1dntTZXxCAd8DK4QSNz+gA2qlS587921PJWs5p8Rb10rppiEuobM9vcKoBi3CIngf6v8Eki7nEyOC5bGjnohBY+HY/nPqhHQMXNGvkeOfMamkwXuVCwFyA8ZN8Ragxgo5cbI1tdgrlQcCkSyoacAi+7b162cO4hsEYYkudjkEl/MjeBifA87k8kEFduCcJ196eIqaBJC4c+4Cx5m9qoSXJs4nYHNxKE+HlW0pp1ALSVQwKiUnekEc/wqY+aX4aUgoMx+cYICeDFXZXaD5W+f+igDp8sZcYu5GszMRoljNjU6Sr1Tq7tgd+Mml5l8R2dhN0Ay/RyD60t7cKe475c5eEDxlcXG23S9BRH9ugG36+Een318n7LAeRbvmq4ZJcLDJKUiHrT9GZqpLO/xbK3SzaD0qcvSCy50iW4YyNowLM4y8VBQlR1H6DiyDeD4dm75h35eztdpPHcVedBcfPlqexiqQ7NA6MZmy7ar9wf6XcDb69TmHDSkyGJW86u3LPeKK0VD5BDUJQoWKNadj8wtRmNBpH6KgGGSjX51y+1UHLVuQV0GwlQieqgRuzvjfP4Q++5A== 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:(13230022)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(36756003)(2906002)(86362001)(83380400001)(6486002)(8936002)(41300700001)(7416002)(5660300002)(4326008)(8676002)(66946007)(66556008)(66476007)(316002)(6666004)(107886003)(478600001)(2616005)(1076003)(6506007)(38100700002)(26005)(186003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JRM4fvx1NS6Pg1S8K86mw0FmEHxxgq2UCbX9/vTQbzM+4AsU3av3A5cAK909FXhIQV3SuDAPqWbvmvceS4tFdy7J87eMTf8nVykGkVJTKq8xkdMBdzVVfLKdWjR5FBKrnRBqzJBtomyNXb/uWyLKdfYAIa8vZ5ctm95Ga6brWA7gdBb/apf9DNHB5JMhF4VM7u0Zo0SP3OSVIFuoGXm2JePFPG+frSByHPyYqxwVTxVY9UDOywzR+VCWd2KUMtXKyEZEcCzg9qA6L8MYaHav+u6HgYG4ku9XN4iovEs5zQJ25A4dQOFFol+8JvoGhZMaNCGfr8UdI7S+bVmHHQ3x/agVbOhlmiF+gn//lwFXt5Vj1ALhG9KLCOnHQ1VmDjt558av9wrpdz5BwOHLLpCZCPj9nSHAMradtRdV70MSA+XP6NtG8evCzYMfuym1fMjHbdG1XsYae7S/tw2rfo9yj+mdcrjNAgds+qNSMfJtbMS+95P02rh+MnvfX/ipv8UDPMUY2f+TezzLrqDMzG/yH+CiIden8hEqI93LKJy4EVdB6CFXfVOAfgswf6kFAW47KPfyLezi1x8a9pBl2r4sR06kEpsqBjAQOsHgDvF7A2dVoC2D82mwi6lm+qkZcwrgsZa75ZPpJ+Kj1LDRXCaeFsT4sLPrYVJ/Bg4RBhXU8xmylpGnI5bCZgeigKePwKfe3TLQ9zG48FMEcvlOL9/+ZUJQ8dEwrSmbpTqmziojaGBtjPZp9X3nCxFgaLo/DRRZW1Nh0zOrPP3nAmN+XHROG0iJVzNDuTYIgwGhtFd8RHXKPVp/c1egMW0ZvoT3gB/q4cUxvXXpV39c3TuiMTsHGh4BRczEoWLYzJJGYV+01iNDkP13JAbXuKbkIGVieO59eT2ut+mVKZlW/T4cjPtr3WdA3mNnmVuppDZAarkx2TGPeotyiPcKk4c9jyBfgDOCrmYVKoFoggdckeJuaBusaUMJV330qdTQ6OJsN+jHqsxHTh5IFIimc+XKBTrNksWpFk1Rkt5zBTo+DEVuHpYVGRtPebQ7+JOjJqPvGm1nfUA9boaAwi3x4oHLl3tgY3Jj2atNCL+O7a0D4pfFxlICdP09FmDx79eL2q9KHtiBzhC0R6cNxK5HIDzoTVEU/y/1neR8DUnzDFGhBO7G3jN/lZtnvi26hv5UK6yBdRM0za32ErejM3ijmR+VfrY8poXdIHG68ytBndOELPM1QOo3AkP9DHCHVi6NqbVB45htOhHjMY7NiPV1s2iaGTxZNlCQeakLiT5E5Bf2TVBV3uwgVtwXIDc56CcPC6t7vF4nf47+GmIrNdSQhGwrXqk5NdQ1GGofHEPX8NVlX6CptGDrhYF3MXQV32u6TWSbDYXtGviXmbe4s0jTwdNu9nEre3NYTSP1eslu8A7KFfY0RSF9xKe/07KSe2MXdeYGCe1kwXye35cTDWjBMtJ7WTGBUOZ2kWUuo1cJNP5XvRSeUdoOZh28QWS+igK6eVRXildnumFY7UZfBFmgrnhi3Lo+Jb09aMkrd5EpjywSl3a7vBj40UatErf3Gr6azHYYqApia5cbDgRFxHMGGK+ZNIQGso/xEcBYtoQF0fr+RwuZd1jHPw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0bcf738-43c9-4c92-1d15-08dabb772cb3 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:15.4909 (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: g067JIt6c+CP+7PeAQlaorJJJyIKwgnbk06p8oBtFURhjjXd29i8CsSqEST/0arIdEvnO7TXEnuzMSQBKH9X8QigExPR4OvQfl+tv37ilJo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4228 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-ORIG-GUID: lH8G63eDG7QIKhlo7ymJq2z5uHSK3DRa X-Proofpoint-GUID: lH8G63eDG7QIKhlo7ymJq2z5uHSK3DRa 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 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?1748233431411967590?= X-GMAIL-MSGID: =?utf-8?q?1748233431411967590?= At the outcome of this patch set, the crash_prepare_elf64_headers() is utilized on both the kexec_file_load() and kexec_load() paths. As such, need to move this function out of kexec_file.c and into a common location crash_core.c. No functionality change. Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- kernel/crash_core.c | 100 ++++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 99 ------------------------------------------- 2 files changed, 100 insertions(+), 99 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index a0eb4d5cf557..46c160d14045 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -314,6 +315,105 @@ 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; +} + 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 45637511e0de..f98d1742872b 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -1217,102 +1217,3 @@ int crash_exclude_mem_range(struct crash_mem *mem, 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 Mon Oct 31 19:35:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2508186wru; Mon, 31 Oct 2022 12:43:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM711qbun8TySva0NS95eWse4/+UmV3ANK3MulO6RYICObtIoja2Cd72xfmI/qj9rk4TLamp X-Received: by 2002:a17:906:8a6c:b0:7a8:2f09:d88d with SMTP id hy12-20020a1709068a6c00b007a82f09d88dmr14343820ejc.49.1667245436847; Mon, 31 Oct 2022 12:43:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245436; cv=pass; d=google.com; s=arc-20160816; b=xpNAxDTMcF8N/plyGuj79ly4+lG297wad1KUSQ94epDDPR3BBkwAkuhwu+eQQbdBNH 9AiR5uqIw8/lzO5KOPA6irdrIoRCVV5x8aT7/i1LtpzQnzMNI/q5zT6vsI+S+KM23HEY 6rC1qbjnODqp1J3WScZj4z16cB6+qcVzWMzozL/qY4Bo8amFQfYSfqm/gOyeUapYPhCZ msFSz+IbDiUgcysCIEz0uD2JeFBZqLgu1cm9d3bLLlCDFSrmxFKonRT+JPoeVAujP9fy r1K4uLRpOTwYLzWBUVbOAklKb2H8Tt0FRCznlyC4J+Qa5VqZup7GKWx+Q0NCOVdoC+FI ndKg== 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=yO1Bb8EkmaYNrUwXwWRdRFTo+nQ8wWUK08fUE02PIV8=; b=IQbYAkXvRhlR0fIIdr/Bo9Ry1k1yC6gfa3hYt3XSXXIsz/HIM+IMf5dJDMnkZbwykO g+rJISHVV3YA4o546b5ZjMgEYJ5lyzM86qmUnCJrlqSO0ItBTps0yYUxixgI7997gQAM khzeenSn/GB4ZOw1S0WjMJ52RywDJFqLEzfeOwHebFVwDV6kKi1jomVfB1KLzo9CbcRe DTecRwMexu57TtbuXA/N0JGNk2VePrx4aYrOsVa7IBaCC2Vl/wPLc1xfXl8/v6ljtm/L ZhGktthJ8OLD6rPPQCKXOWoQNVo72rRbi3ZirjHO2vA2mI5prfZRCLA86xANMm6VSlUx VI/A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=23obFGan; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=YG+RLC8I; 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 dt5-20020a170907728500b0078da3218b54si10126308ejc.171.2022.10.31.12.43.33; Mon, 31 Oct 2022 12:43:56 -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-2022-7-12 header.b=23obFGan; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=YG+RLC8I; 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 S230022AbiJaTiY (ORCPT + 99 others); Mon, 31 Oct 2022 15:38:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbiJaTiJ (ORCPT ); Mon, 31 Oct 2022 15:38:09 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86D8413F2B for ; Mon, 31 Oct 2022 12:37:46 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VJZ74f001187; Mon, 31 Oct 2022 19:36:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=yO1Bb8EkmaYNrUwXwWRdRFTo+nQ8wWUK08fUE02PIV8=; b=23obFGanWIf1ZiC2x0/nFA6E08sZJ6pf90MzEB6KJ5ES00000/NRINOsU6EfTiM0iXbY AWk+P+UhDOR27EaRRy+WUXW15k+ianjY31sa/S9nFi6Ul/JHWXFu1vP4iTXFA3kU2jiR Z632MAYm4mJ6G00yrW7w1FcVjz8zA6VbIiPv3KbVUtR3U3D2EzXmSBpuq+JWzYaVpd3O 9EYL0mJ/knhZMeIfNi+IeD4f+xOrLipWTywm5zxPDB6kAa0H9uobQgoLl3/jnxPrCCZm xHkfiD5pSzlT0gOacIGp5j2uz6EXZ430yHjNtIcbpfiTfOndmXR+xcre0R/0orv5VV+k bA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtcqu5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:21 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VHTitl032833; Mon, 31 Oct 2022 19:36:20 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2104.outbound.protection.outlook.com [104.47.58.104]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3mptu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A+coDbCC6a13hFzRj96hzwHZImcpgNl9/e1tOdaMDwzHxNYxAn8AiSQWKcmXVTX2uc88EKlFFNEAnOwH4T/POhg7lrywTllzW4QyTwwsOQc8/ZdqpphjIUf9zL2871yKILOPusaMhtMGzceHaR8/nxNcZykn2/ZTwe7QEV9QwRlWyyTnr47DWbxSSpHkoB6A9cMS9lvUCTDtQtKmo1u9pKnL214MI39eEZHEOsjTwd0bDFEdaP2cC9qw0HktIBTec1l8ElQ8R4iXbO0LXvO1Fle7FD5THCUCLmn6PbANou2/Bx+t8cQbKaehr4f7lXuPvTW03AWNRVQzBZm8vfkOTg== 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=yO1Bb8EkmaYNrUwXwWRdRFTo+nQ8wWUK08fUE02PIV8=; b=DwI6qSuJ4s8U78WBvTJb0Q0zkvAcdiZrr+Vuf29qx/v43lFkbh7sjXVBdPTXkGia4PzvCP+tiOrIR35+SolMRc8c9gm1GsdarU1sQGWFrTz/jO/2LLc5+e8HUZzwPfcUHUB/X3ftogjhiiWrDCrm12HDt6kO7k5evBc5VNMf/ucwMcdQWgcWXrPkb5rS4SZf2ETCL5f3clldq8ViYNanfFpXB+Swgx87Y3O2PROJ+IzEeErrO4YNZAFVZl8fzWVytsBUvXWMRPHLH18E4MCcMvpIVo3rojaX1hFraG26BXw2Vhb0w0THirK1I5INF+vjUbYF/aM6X+/PxoevngmxzA== 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=yO1Bb8EkmaYNrUwXwWRdRFTo+nQ8wWUK08fUE02PIV8=; b=YG+RLC8I4SyKreKRaemiiwj22NHUgbXrOPveg6t8tZYj2F/VfvgZ25PrVPX4fQYEHiMsQGyGZxmzlZhAEL0rdhuWye2ueAGDaMvocYPBCkCTjoIBcSD5MaJE+aatjWEMvDtZJ+wL4bTXY7AxkJ7kNvjgItsIiL3r1yPMsupVGJE= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by BY5PR10MB4228.namprd10.prod.outlook.com (2603:10b6:a03:200::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:18 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:18 +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 v13 2/7] crash: prototype change for crash_prepare_elf64_headers() Date: Mon, 31 Oct 2022 15:35:59 -0400 Message-Id: <20221031193604.28779-3-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SN7P220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:806:123::14) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|BY5PR10MB4228:EE_ X-MS-Office365-Filtering-Correlation-Id: 917ebe1a-f296-46b2-b772-08dabb772e56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pa3OMbucjo5Hxez5ym+MOpKLddQ+LMgJCTgSb1FcrXjACs9Nam33TwXBYg8jfZb+KXDgp2Xh5gj+MTlZVTNC7crRruu9L5C9mSIOKJooUwnqWXK4z/RyVE6BSp/a7FPFSRrmxx2OJbWozWVg1ps+zMgyUFHFXYkAIT20Gje8GNn7eg4n5uJjzXfDU5jP8nFRRuIq7D02BvqUGG9QubgxhC4XjgLmy1R0F0GycKRW2D5JyEV158UTVsMY1Sb5ODYEBcJ4dtkWN2pSY7OrNAtv/KsWDRaXoO6j4XCXtDZXaph0Zt7bUiW1z45OKXxUi9ZAATSYdXoC1glbCLBqxOI2hDlcjlLRaSHM1SjhR87ZfsAYRKmLRBrolqebZ/UXjum7m/6cL8THVTB9Rp9d7zykH5LYRiMyrd5me/NGSpIrLGmRVo4adGzkH5BDkFlhXxPXRvC0EsdXYqqIIi0IewbwQI69HvfuidAmhqYoHavNP1xXLozsZdK5GigtrTCCOuLOdVPBhxhPsLTZxZQgBHRgzGJeuKX/Zp+KXCGH6F+wOgJvamlXQ2FloayZVFXN4FX7BVToyxiSqzw0bOWNk0SBq2TnLOytHToHOFpom1iAAdcvomVuh/Sg+/QWQs6xPNkS6KPc71z8f6eDNVU5fXdLFVxWtZC6gofDfTrE80HnC9LztQOPWmuww8BAsbbjx6VP8mM2OR8eA1rkaoI6iijkiA== 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:(13230022)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(36756003)(2906002)(86362001)(83380400001)(6486002)(8936002)(41300700001)(7416002)(5660300002)(4326008)(8676002)(66946007)(66556008)(66476007)(316002)(6666004)(107886003)(478600001)(2616005)(1076003)(6506007)(38100700002)(26005)(186003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6LQbwsjRXFbbyo8ON5SmZ6B9KkuEC8dNeYQQbsa2C2NqoYje7p5ESOoI9t9Cq7IzrEN49jqxDQVEBmTBWr7uu05jvk6Qo+mJakGhkHFEM+jifo23xjYFNHXB7tipI5T2NnDgI2gAVhsT9r9JLBdlR4TtqNYiTUkRkZm+kWZqtilivrpjvWKpMVzT2tt3j0MI4iLywtM/RYRUxJD8GfMSIIovsl7Jl/7rjPaR9ATlGOQ0wznGBD+IxJY8bWtEwhK3FNIIHO5hrRJV73z8ZQv5hU/pZPMXboROExSwQZSgZ7nIJfl8mYqe+Cldi/Ox6bXlU06y+X/R7qJalLVpNaPp3jzSNAdwIvgg+2Q0AdLSyi7/4++trgn0gkuKjYViaxTjTHBya1edhgnVX4KHUS/sv1xJVajJRqO01aY339qPUTXNDWGOT3IrDDqz6dGj84YY3Y746iNiEiaJJw/c7DL+Gpry0OfhRcAYCri8+AuyPnOVzEro16RilI7aXDYWWnmPTdnDkxLGeeGSeqj9dOPwpyq80BQLs56Rgz85dg7wtDvVEKdBxn9FFVxEvCrUwXwtBIBiu4sQD1MJdDqIFJSlt+GsQ4no1fWTrWdCG7ZCsly+fKXNjT+dU/7jkidBIae6YAQHnCe1Jhgxt/rN/eJDPjTr1mpFFaV3yEIoHR/CdmRITY7rQlwOgUbgz2o0Lwr4j1vfRvrJDWxav8/e66mWvAvzIO+yTyLB7G2wEJOYlQ6i/vAvZXvW9KlnhSl8maRkD7gWUiZ50Uy9SCXDDtFIYH+0CkDxFxzQHppnHbc043zO7fQmjzk2a7D7hnnkup7O9XmsQB+/rkJrMLZZHssQiRg8aA7DtymlheE0eb/8CkIh2DCATDDydO5vyHhnO9AwoqMnRY59XC+H83wytfJTZWSG9SYEozgfeHX3QRl5lrLnT0NfxuQKs/rI80Q6PZMARYv4DXmvsNHndLOWcgrB8LrhPLYwvDGwpPL5OHgHuIUMjbDiXt3HlRWij85Spn+rVUNv8a8TxP+6EbCiSMZfSskPGOl9+hc4Tj05rm9H3Y9oJXHsQ+TojgzFyx07j6l4QSaD51HnIjgwxOxPd26sDzoskGSUrKJI8BH7n/nDz7PD3kSOkNbvTV2uW/wbuMcq3ZTO3zzW7AxoLp6nvmYjtqdNshhatdpuv+jAzjh3U/cgkBbrdNvCl+BWsyHtflhMfRlLwt6E9vRGbysfwZW29pxU7rKXNKR/sKdUq8Q/oIrvlmLJUijHL4gUOi86BJU7bk/Kuc2BipdlJhF8AbJohn7F0fXy4rB5AVIJeKYU/gXIywPjLAc0pHduXs/uNlo+wLeTFbG2sYK9Q9FL6v8tMTERjFYyHoLV6TmRrvrSZilBqQc16iFYDkOUE9/KGZWpFqwgLr303ZGGPeHmcPMtYioQ6RQOc75n3Ze7rQrz4LdF7D7uEpXmXhgMiL9lfbu95cfEhu4aDGOTetWLFSKDLAtUTvrcOWIAoRHnAbCPE5hibVg2YkoU1XvJyv7KcfjYUwo31JzKZ60WGUm3v86eFuMb9DEs5pBrmUkGHHpjfb+MFDmmwW4z7pm/BDNUtnqs2bGZkxsekfAsuk1Ci4PGJA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 917ebe1a-f296-46b2-b772-08dabb772e56 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:18.1002 (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: DGP0WBtnsc3YmvkVBO36QM2EYY+Pl6zPr8j2sqjxP1WFbqIeY0x/qEw49oxr2Te5OpuW5AhcnIEHDFzdmhqFehDt90HZpGjsXm1zCpBiqmM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4228 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-GUID: xDLo5f19KfEkRHxxD1Q_EuYP6ZAltvik X-Proofpoint-ORIG-GUID: xDLo5f19KfEkRHxxD1Q_EuYP6ZAltvik 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 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?1748233551203564934?= X-GMAIL-MSGID: =?utf-8?q?1748233551203564934?= From within crash_prepare_elf64_headers() there is a need to reference the struct kimage hotplug members. As such, this change passes the struct kimage as a parameter to the crash_prepare_elf64_headers(). The hotplug members are added in "crash: add generic infrastructure for crash hotplug support". This is preparation for later patch, no functionality change. Signed-off-by: Eric DeVolder Acked-by: Baoquan He Acked-by: David Hildenbrand --- arch/arm64/kernel/machine_kexec_file.c | 6 +++--- arch/powerpc/kexec/file_load_64.c | 2 +- arch/riscv/kernel/elf_kexec.c | 7 ++++--- arch/x86/kernel/crash.c | 2 +- include/linux/kexec.h | 7 +++++-- kernel/crash_core.c | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index a11a6e14ba89..2f7b773a83bb 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -39,7 +39,7 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) return kexec_image_post_load_cleanup_default(image); } -static int prepare_elf_headers(void **addr, unsigned long *sz) +static int prepare_elf_headers(struct kimage *image, void **addr, unsigned long *sz) { struct crash_mem *cmem; unsigned int nr_ranges; @@ -64,7 +64,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz) } /* Exclude crashkernel region */ - ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); + ret = crash_exclude_mem_range(image, cmem, crashk_res.start, crashk_res.end); if (ret) goto out; @@ -74,7 +74,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz) goto out; } - ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + ret = crash_prepare_elf64_headers(image, cmem, true, addr, sz); out: kfree(cmem); diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c index 349a781cea0b..a0af9966a8f0 100644 --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -798,7 +798,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf) goto out; /* Setup elfcorehdr segment */ - ret = crash_prepare_elf64_headers(cmem, false, &headers, &headers_sz); + ret = crash_prepare_elf64_headers(image, cmem, false, &headers, &headers_sz); if (ret) { pr_err("Failed to prepare elf headers for the core\n"); goto out; diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c index 0cb94992c15b..ffde73228108 100644 --- a/arch/riscv/kernel/elf_kexec.c +++ b/arch/riscv/kernel/elf_kexec.c @@ -118,7 +118,8 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg) return 0; } -static int prepare_elf_headers(void **addr, unsigned long *sz) +static int prepare_elf_headers(struct kimage *image, + void **addr, unsigned long *sz) { struct crash_mem *cmem; unsigned int nr_ranges; @@ -140,7 +141,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz) /* Exclude crashkernel region */ ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); if (!ret) - ret = crash_prepare_elf64_headers(cmem, true, addr, sz); + ret = crash_prepare_elf64_headers(image, cmem, true, addr, sz); out: kfree(cmem); @@ -212,7 +213,7 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf, /* Add elfcorehdr */ if (image->type == KEXEC_TYPE_CRASH) { - ret = prepare_elf_headers(&headers, &headers_sz); + ret = prepare_elf_headers(image, &headers, &headers_sz); if (ret) { pr_err("Preparing elf core header failed\n"); goto out; diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 9730c88530fc..9ceb93c176a6 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -265,7 +265,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr, goto out; /* By default prepare 64bit headers */ - ret = crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), addr, sz); + ret = crash_prepare_elf64_headers(image, cmem, IS_ENABLED(CONFIG_X86_64), addr, sz); out: vfree(cmem); diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 41a686996aaa..ebf46c3b8f8b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -253,8 +253,11 @@ struct crash_mem { 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); +extern int crash_prepare_elf64_headers(struct kimage *image, + struct crash_mem *mem, + int need_kernel_map, + void **addr, + unsigned long *sz); #ifndef arch_kexec_apply_relocations_add /* diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 46c160d14045..8c648fd5897a 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -315,8 +315,8 @@ 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) +int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem, + int need_kernel_map, void **addr, unsigned long *sz) { Elf64_Ehdr *ehdr; Elf64_Phdr *phdr; From patchwork Mon Oct 31 19:36:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507080wru; Mon, 31 Oct 2022 12:41:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM73ORrVGD0g42Stu3xos/2AZDahsoM6yBbaXliS+/QdFZSTDV0B1vPwTlpgs3y3stzbmMeM X-Received: by 2002:aa7:c913:0:b0:462:e375:a1fe with SMTP id b19-20020aa7c913000000b00462e375a1femr15274361edt.156.1667245290885; Mon, 31 Oct 2022 12:41:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245290; cv=pass; d=google.com; s=arc-20160816; b=rYIEeky7vQzYio5ge9o5linWoXB5oUmn0vfqmdN2OCAsLH0alGiV0gv9x7a4UdXQgK CWf7ObP6VcIrlq3vyTZARLX+6w3MCbhX9ugBM5EippsNfhNDr0rAnaKGuI3gok8iEL9w +OiOB7uBCOwsvt9rgoePr2xuqiV/yPpyMvVvxYWMOZm4VnrXuFcJGqx8tT54JjRrOCrB wEG2DssPjBWRT6XjNM01pNhkZ1530+EFSm17QyLRqz9pBRyXWJI6x4zkTgN4xZltFVFz 7RKfjpVHGPpZ2FXIWDU/oXkb03Q351cXI/t/FMbM1TUrtvtRbPbtR6JM5JnwRjtNzo8F BeVw== 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=hmA4GSvFTgTJJl/gPNh7nMMFy54MQfbhCnRP+0SL2a8=; b=N15hFOcJGADaG3cuPxjeshg63BHy+XIolYQO1s+1jn56GYKZvJpZnUXCFa0S2QdTJy ZKUyf5Ag2JUtWlY8IMlN6ZOnvO0+CrvZadSotahYZzSNnYfpH5mTBId4Y+xiKr01bJbb /keF5Y4xN3LOLmj4up9zTp0Di2J1FEZJ1w6Ir+I/QzLVcHYjFXzpHd//KOMKozKGt1HF lL9QoHlkMZRC/k1S57OMgxMA4xH5UlgoxmeEGYRHywBlDpYXu5zDwujK+PW+Fthu6h3o gPIOsfPSoMHzW6Cayvoe3ycMSj8LQu14xW8CKNWpfTv2mDUqpKcLIGnyeWwcQelZJhhW /MBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="avQK5e/L"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=f6XaAfO5; 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 e14-20020a17090658ce00b007aaacf9c0a1si9693157ejs.129.2022.10.31.12.41.02; Mon, 31 Oct 2022 12:41:30 -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-2022-7-12 header.b="avQK5e/L"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=f6XaAfO5; 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 S230074AbiJaTgz (ORCPT + 99 others); Mon, 31 Oct 2022 15:36:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiJaTgw (ORCPT ); Mon, 31 Oct 2022 15:36:52 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CC9113E1F for ; Mon, 31 Oct 2022 12:36:51 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VGx08p014808; Mon, 31 Oct 2022 19:36:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=hmA4GSvFTgTJJl/gPNh7nMMFy54MQfbhCnRP+0SL2a8=; b=avQK5e/LptV4Pp/HH/gnekAV/rGrpoRpCODeKbGcDV8ZZlGXl72iXtH1vfIgMLUEzZ4X 0+MXvtL8dWjJnLiLkpqTyO1LMdpTEvxMmmNpTWnkoGELQAuKLdsRoflt8OukQxt6lBnc Ba6CracgFkq5+RSRe55s45K3KB8S7CpsC4p6G6wbsdoqOEq/G1/V9EYlrBBE3942/lUc epVQNlLWoDM/3OewMV/aKosGLU58PQA0Z+3oryrafnImZPV95GmV4mIPDpNaCEMZqy9r 4MHtLuz97ckdA/sh8gHtW4VnzrnTPcCNSzAL8xJD2ZQSTmD3dGhsSNJCX+KolMyujYui Mg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgv2acn7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:23 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VHTkoA037354; Mon, 31 Oct 2022 19:36:22 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2109.outbound.protection.outlook.com [104.47.58.109]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3nqbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aLslLcAnKZsi4bn7VWwE64OqWaKh81lmtx4uw9hlkCG/f6souUEItznInRkAVqK+KQqrV4DQVDKY4MgocGV3xA4KGgOrr6qhaYzNyZykZU21mNNFjaqnxWB0LqQBzo+/suY3/P9ieiZIjnMZWiRO99uluTJCaHjR/u2cHr6n8ZF67T/fOmRm63YBMsEZA+61nRG+Xn9FfdsTu8hIAJGV+XAT8H31s/JMvmVwYYUSvV5xROlaiCLaHSwJTKcG1e9Q6P0aQOmOXS6ff2X7lpfd2Ow67o9BR+mx76yoQd+ddY5P6SLys66qrrbUYHTGNdF1kU1WoQF0ZLK/LgJrInunNw== 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=hmA4GSvFTgTJJl/gPNh7nMMFy54MQfbhCnRP+0SL2a8=; b=VHPmWxl9fSydxVd0XEo6p0ZMioB2slWXcbZEE3OGWboZNd3GVouWuhGCK2LMAYk2uu+o7t0Na4wNUy9bmJhZkg4R92RXIwzPMd6rUpmFJ7xvwKzAsOnaXB6+pU+hZZ0gIKqyu2+0ICtaduJyr0Y7qWaHCv85o2e2u2jLU083sH623VkWtsj6hjdTObVSFqnsTjI2GKSLFqb5r7kXbk5NxAoRpuA9L8XunFUtI1t+2FHNigdGv/csf5OuovOCZ1oX1pbkFFGGUh8etyeERUveyT+WBzAjAk0BaAuiC3/oNKkB+Yhpqj5s4flkKXVkh/RGps0LL8zynuohSrhBMmL1+A== 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=hmA4GSvFTgTJJl/gPNh7nMMFy54MQfbhCnRP+0SL2a8=; b=f6XaAfO5yWrfvjc9k0ztLyPezUW9ENC6maL5Fs3CSV1Me0x96IWlDuLWveVEqB5Sh1MYCv87HMGRpwHaPevoKYQwuOgzS3Q51jj6ZGGsRsRd6zYkzeMEatGPGFsltheQoCZuFV5nthMGxlGu7dcHt9PnNI2ee0EgUkozPRddN7U= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by BY5PR10MB4228.namprd10.prod.outlook.com (2603:10b6:a03:200::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:20 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:20 +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 v13 3/7] crash: add generic infrastructure for crash hotplug support Date: Mon, 31 Oct 2022 15:36:00 -0400 Message-Id: <20221031193604.28779-4-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA9PR11CA0027.namprd11.prod.outlook.com (2603:10b6:806:6e::32) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|BY5PR10MB4228:EE_ X-MS-Office365-Filtering-Correlation-Id: a378924a-481e-4f71-6f3f-08dabb772fa2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 18e6NO+Fm/eduTwW1l00MW/E4KpnZOjMxxZKeEwt2Bw4j+VfH88Q1HcMaDI2UbUPgVs6MdYJd5yG4KsKtEyJm0DJ3Wngi7JtWEoobtvlhuE8yQBRglL7c3n2drMwSCkBVU/+041s7kdQRzdUU3RFa5YzmBuvtPO7Bf73qQWjVhxTela34lwDxfw+THRK6Zaeqt/TSwrNZ1TNqEhv5CEUxxfCWqNemxCUc+8AGWfK3Rr9RSnwpaxNRGWLuvyjVKIuJ1sJpOqTdJCKK1ElfLKN2i4SPkckGEslbl0GruOB6u+SwhpqoxnRUv2yUi4oVZGsb8e075HgeKdDLK+/G0MGlDVf15pvqoFvRq6ggxbfom8TdzkYCKRE7NcytOkGUzh/8bRqelChfysv8a0fgnxUWkuSh05sVkRcnxW6z8AA481do5TbOfvwL1Zsk5hUWONkwZ7ucM5Yil5QK3lsKCenwp1g2PuYDfatzeJ1Qq3MkYqZB1B2vawFqPAbozacg+EcUXxj2LixZS5gDatD9eePW9r9asxYEoy1AyC6FyplspVeu9yeAZzLZAFB0ylxjE7W0ocDlZ6drqS8wsB5nEt4B8SNY6FpTNH7GZAaHigMqp7rWUYZG5AMhh69vb0mcgOZd1kqt7tTzCuT+zePRLgyan+9Ax/GAUr6kzEHjOevemUHN1m7oZi7sngZV7AmTLf5Vg+9PuLjcg8sqXVCUSil1HBOSgNSX5czAcOrdZrTAZ47Ztv823/GbsVoKajIBXzc 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:(13230022)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(36756003)(2906002)(86362001)(83380400001)(6486002)(8936002)(41300700001)(7416002)(5660300002)(4326008)(8676002)(66946007)(66556008)(66476007)(316002)(6666004)(107886003)(478600001)(2616005)(1076003)(6506007)(38100700002)(26005)(186003)(6512007)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o1qnBb+gcKiuwQawCOZIPN6jkq9N3ZqrWOvfhDl48/BHi57/dGYvYgswGt6qe5Ioa4tCm7nsoa2Y7klKdjNhnZfi/L/8f0tQPO8JF9Irp3qucAKBh1tO8YiCwOjKKl1hXEXV0dkD9DAfMv24MotRxanUSp36JF1lTnriXkX/VPCsbpGwo8jdjzlX5v6YMwzjYLWNh5Y0z9d0vYbOBFkmQ5ROeTYOZKDJc9kFamx6kvLC9eSOZTyjlk/z+7+Jao7WsCZ8EpacB0aPfTR6t+YdCOjP03OP2twJWoAOapsoOtvqSaZ+5oOTVCX5ERjKrVmLLtEDnZwG+k7YLPSUkBn7tDZrGf7M0/bfkqpj2n6gzk97b2aWpctkGOgsD+M41EsuTh5ViXruQ1F761qN6tgtVKdLXKtAb7q2QthBEPlr4m4IPARbJOnCU8PA0yeW6qqOZTBejCko/QpEA9aPQz4ZEDGVo7YZ8WLFwXcUJyoYo9USJ1HaiNVjbBNVPbjR5uq/JDiuk5nTZmdvBrIYcSPAjWgCuUNL+cnHXU2+bQcppsXXg6WacBOhODDXVy+icD4eBclo+5iBXMEUbTs8kQcLVnPFFAgc6e+GaJq8z+awutqe9Pb4G2AelXDSzbixW6dYwyxdRk1i9VREEaCYX6lnChftAFARs/kuwdG1BTQpsmEeQrKKGme1xH7y/cylDIoF+S9zzQ9IiGwyF/OJxUlXm0GyuOyKEF/J4ddK9KX8YwzqiTwBIfLxPkw7+pNkmPsl+IvLsMtalxJlg3AGU6T62P8Hl9kQnd/q3+M08rD7WXEDJmsgvOv2Pwu70xlHW+gGBVaexb7xr9RABhSL92Hswv2v4muAI+Rq9/i62wlhHnCshbpl6V0X5qlqasHOfuWDANU0BT/IDIq3JuzRF0SRjcSYbSG+ETQ9HsfX/tBCv/OKmh5N7CDMcbjkl5PSbtYGOQZQXK2SlD3VGi10HHZZBVRIr17utIs/7GQjlGId2BY52rgPxQ8se9p6B3vnq/dcNpPnSqWhVElJyUIchg2AJy2EBUh5CdjnjAxzsRYl3siKjUyPueubAbmTvBrssWHwj2YJRUM0G3ohR3XvrDPfIuW5t8EpspBR1yhGgUSQTHUAN7hz9Iafw1F+qTAxsD47zFGEtBSJUr1aumuPfFp47pdE8fjVY6Xely58K4mKsS1WfDJ/aPHBjL9hgDJJGwW8MSRMPgPJIBsVbFHl8FYcHvtiCPuDM3dN/+4Nujg2xpL1CgZbAnwBxKrsBNkgvGRdwM98c4b0uNpXb0mR/FUWaiNkgVs/nU3XpiyJEYM3FbwfuTwCYuiqqYF7fZ90/+HdDoxMcASfZgT9xLfwKGaEwTaCD/pjuBAk9mjymjS37unoJlGqW5IRlPq8xaUHUTUtohcXqCHoRxGiO+W7VKiCJcHPBpmVHYWW0i7/mYUCA3KRGIelM11BmP2/gHjbwXzuk51B3QdXjoOOiwGO8ItEMnCe9IVUh2yiPpy2mTijmlwOWTD2Wf5IUmIkjGLwAM4rMYAxQ9kscuRp1AtGQrmc0BbahDA+Se5Zq/mM12WqUs9LZL/nYhQjffGMiix5VPF3DDt/Ym5nFIsEjPuO2QQZQA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a378924a-481e-4f71-6f3f-08dabb772fa2 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:20.3210 (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: 9ZV+n+Xcp473EU+PcHZMXrkdvNjWPD4lYtGBDF4Bc/+xTBFgbUo2flmt6M5YhG4TqGqfSSrYI1FETJkrEIav8RhuMuu0FDeQiMxeADwlLDs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4228 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-ORIG-GUID: GO1nygFXLPpWM64TGyEZ4ImdER3JqKyg X-Proofpoint-GUID: GO1nygFXLPpWM64TGyEZ4ImdER3JqKyg 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 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?1748233397848563480?= X-GMAIL-MSGID: =?utf-8?q?1748233397848563480?= CPU and memory change notifications are received in order to regenerate the elfcorehdr. To support cpu hotplug, a callback is registered to capture the CPUHP_AP_ONLINE_DYN online and offline events via cpuhp_setup_state_nocalls(). To support memory hotplug, a notifier is registered to capture the MEM_ONLINE and MEM_OFFLINE events via register_memory_notifier(). The cpu callback and memory notifiers call handle_hotplug_event() which performs needed tasks and then dispatches the event to the architecture specific arch_crash_handle_hotplug_event(). During the process, the kexec_lock is held. Signed-off-by: Eric DeVolder --- include/linux/crash_core.h | 8 +++ include/linux/kexec.h | 39 +++++++++++ kernel/crash_core.c | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index de62a722431e..a270f8660538 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -84,4 +84,12 @@ 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_REMOVE_CPU 0 +#define KEXEC_CRASH_HP_ADD_CPU 1 +#define KEXEC_CRASH_HP_REMOVE_MEMORY 2 +#define KEXEC_CRASH_HP_ADD_MEMORY 3 +#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 ebf46c3b8f8b..04ef5172c4ba 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -32,6 +32,7 @@ extern note_buf_t __percpu *crash_notes; #include #include #include +#include #include /* Verify architecture specific macros are defined */ @@ -374,6 +375,13 @@ struct kimage { struct purgatory_info purgatory_info; #endif +#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_MEMORY_HOTPLUG) + bool hotplug_event; + unsigned int offlinecpu; + bool elfcorehdr_index_valid; + int elfcorehdr_index; +#endif + #ifdef CONFIG_IMA_KEXEC /* Virtual address of IMA measurement buffer for kexec syscall */ void *ima_buffer; @@ -503,6 +511,37 @@ 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_map_crash_pages +/* + * NOTE: The addresses and sizes passed to this routine have + * already been fully aligned on page boundaries. There is no + * need for massaging the address or size. + */ +static inline void *arch_map_crash_pages(unsigned long paddr, + unsigned long size) +{ + if (size > 0) + return kmap_local_page(pfn_to_page(paddr >> PAGE_SHIFT)); + else + return NULL; +} +#endif + +#ifndef arch_unmap_crash_pages +static inline void arch_unmap_crash_pages(void *ptr) +{ + if (ptr) + kunmap_local(ptr); +} +#endif + +#ifndef arch_crash_handle_hotplug_event +static inline void arch_crash_handle_hotplug_event(struct kimage *image, + unsigned int hp_action) +{ +} +#endif + #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct; diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 8c648fd5897a..3a0ed4168fcd 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; @@ -612,3 +615,139 @@ static int __init crash_save_vmcoreinfo_init(void) } subsys_initcall(crash_save_vmcoreinfo_init); + +#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_MEMORY_HOTPLUG) +#undef pr_fmt +#define pr_fmt(fmt) "crash hp: " fmt +/* + * To accurately reflect hot un/plug changes, 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 handle_hotplug_event(unsigned int hp_action, unsigned int cpu) +{ + /* Obtain lock while changing crash information */ + if (kexec_trylock()) { + + /* Check kdump is loaded */ + if (kexec_crash_image) { + struct kimage *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, it is wiped to zero, so + * the elfcorehdr_index_valid defaults to false. 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_valid) { + unsigned long mem, memsz; + unsigned char *ptr; + unsigned int n; + + for (n = 0; n < image->nr_segments; n++) { + mem = image->segment[n].mem; + memsz = image->segment[n].memsz; + ptr = arch_map_crash_pages(mem, memsz); + if (ptr) { + /* The segment containing elfcorehdr */ + if (memcmp(ptr, ELFMAG, SELFMAG) == 0) { + image->elfcorehdr_index = (int)n; + image->elfcorehdr_index_valid = true; + } + } + arch_unmap_crash_pages((void *)ptr); + } + } + + if (!image->elfcorehdr_index_valid) { + pr_err("unable to locate elfcorehdr segment"); + goto out; + } + + /* Needed in order for the segments to be updated */ + arch_kexec_unprotect_crashkres(); + + /* Flag to differentiate between normal load and hotplug */ + image->hotplug_event = true; + + /* Now invoke arch-specific update handler */ + arch_crash_handle_hotplug_event(image, hp_action); + + /* No longer handling a hotplug event */ + image->hotplug_event = false; + + /* 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: + handle_hotplug_event(KEXEC_CRASH_HP_ADD_MEMORY, + KEXEC_CRASH_HP_INVALID_CPU); + break; + + case MEM_OFFLINE: + 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) +{ + handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu); + return 0; +} + +static int crash_cpuhp_offline(unsigned int cpu) +{ + 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_AP_ONLINE_DYN, + "crash/cpuhp", + crash_cpuhp_online, + crash_cpuhp_offline); + + return result; +} + +subsys_initcall(crash_hotplug_init); +#endif From patchwork Mon Oct 31 19:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507685wru; Mon, 31 Oct 2022 12:42:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6kQRz1a8gBTlS0ACI/mDC6z+yxZdiZuNuruFy5lopJCIXZqAbSHK4d3l/DvjVvyJdcPolJ X-Received: by 2002:a17:906:db0c:b0:77b:7d7d:5805 with SMTP id xj12-20020a170906db0c00b0077b7d7d5805mr15114357ejb.726.1667245368804; Mon, 31 Oct 2022 12:42:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245368; cv=pass; d=google.com; s=arc-20160816; b=ikmG/vOZY0mqGmYGmZaA5ZV7M1BpjKKdz4jOQfyzFFohfcqTktzK2w9gemPskVvwwi 7Q7KV6fBhWWSMTIYwqg3G/AnAariDN46+wBwNe+MMMHCH5OMDrW5M04/f1NgNo/b+7No 2JbWtdZzguXtsZU2jAAbUoOVHIXUSIeqVwELAudHvuOCuyXdVBJm7V7Mb03HRSY0qCN8 5tozkkG1ZVCa/aBxUaFNowiRLiIhpG/UFMA21v3xtYUuVAeTTPkUaPGPaQQ1R0rdBKi1 4tUfp6AKKqeg6UuS9A1mYJcdZEliG5XsA6lrfpN5gcj0FNh/a/uzAVd3CwA5EgV1paTd Qh2w== 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=MgHZ5FjOepLu/BslyLNPE49gEH6Ji1IVwBbpMqjwKeI=; b=aNzo6I1F3EpHvLD7OO1nRQbXFHAwLQjJhiiGXX0v9X5Xd7lg+9OpdHZqdMWWFF7ZB6 bXENcHmEsNNjGdIwOb5kT7nmiWuQZKrNU9447FV+54cZ5QEmBb+D8FRiybZ6zqNaCtJ2 I15kSC8lkLArNRBFBrQRx7KIRviYCCQZR2DpK0PLs5weaoHWi4oXN6QHCcHTHJeYDzcs OJI2bLj+k3FwyJbncWtnZljn201N3u3jR5Cwzh2cutauBDiFDSuGr0JA60RhDrnU2e4q kj9JpegHHmQIIIgcSYdgn8cFY4OKZn0jC6gvFrb5nlChIldtENpJNUQrr1UOmUEwUgwF u8IA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=n72O2pUk; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=pq+bA9+H; 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 h11-20020a170906854b00b007ac8e6a4377si6940518ejy.219.2022.10.31.12.42.24; Mon, 31 Oct 2022 12:42: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-2022-7-12 header.b=n72O2pUk; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=pq+bA9+H; 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 S229889AbiJaThU (ORCPT + 99 others); Mon, 31 Oct 2022 15:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbiJaTg5 (ORCPT ); Mon, 31 Oct 2022 15:36:57 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B72A13D2C for ; Mon, 31 Oct 2022 12:36:56 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VJWZDf010794; Mon, 31 Oct 2022 19:36:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=MgHZ5FjOepLu/BslyLNPE49gEH6Ji1IVwBbpMqjwKeI=; b=n72O2pUkStLgoM2KfWOJN6GS5gE6DqjwGyj4jKPbIN87GfpFcxBMibd4hQRY2eADn9oi ggNcrHXqI1mzlIWA/cWOo8AzrIHwU9hqIr+ZlZf7oPFhcDpRYE0c/j9raj2e86BfBNVN dPk8f+xy7avMQg8hwQGm/fmePGaZYeBY9MINEdaTW4dkBT9wObGqfq54Ae2U7jzdsMxb PtGQH6zyGTw2bmxexMGBg5C5qUvcTNi2pOlRsqZsS0YIqHx848jySrt6QYbOSyzdE0R9 X5p7lTWjPNQP3f1ajIstWMVpuyIWpd8dWwtWGd9SPF1oRbr+bNAkzVqgZzaGbkAVcrgX Aw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgussmu4s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:26 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VHTiY3032881; Mon, 31 Oct 2022 19:36:25 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3mpw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kBL9MvbIL7h2RVO7ZwG+yzWlg6rNPvJKTV3UspWZXhr1xkJ6uuP9U45WXJNf/AkWfyoaO8EEvEVJ1oAc8Y+9sch99EydhLQnIbLRuy7fJyJLy3jNp/bLfaMWA5Og8JnsM82I58YJ8XJBpIPTtLIToizQoEk97pQ0YYxgEFiPFYtrv7TtqvYZst2nnB7YFxF8V3Nf8IX1mg5a658Jz7WtCccz6Imwpu1npFGVsE1twR8FHLpYTsoOJo2quExEzmE42K4XdoY9xe1NvEGuTyFvmClSc+AS34ht4wpttSd+qEAJ19CWyDPpN4nQ+qa6Up3FomlCB4A5/qcjrhHFf4R9PQ== 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=MgHZ5FjOepLu/BslyLNPE49gEH6Ji1IVwBbpMqjwKeI=; b=a/iUtKZJekvws/DRDofPuTP2IFozkRPXqS3/iD4aBXCCr2+IalwKO/0GNUC4udHH3i/dJbeOENDUJT8lEP81V+YYlUe+4aeOVigWwueacfoG+xEPH/ZfOsgT91iMjHWGoQvPGCyaeXZ1XakdimJilFmV0dY3dKxp4Mnry1qUduuaNeKCoaHnDsmCsqv7ZmswwQEoqlQJ93jQKitzpdogW3+c31tYNgNN86NbWJxDlvcjaKVAehmE+CZmxBm6yXskA+6PJZj6MzxdNbI7Jf1d9RBfZzaEnkeECN3zYtCNVhcqgnOlGpQFecG/OGvsVadjnm8YjMcOWV56weYldmBnaQ== 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=MgHZ5FjOepLu/BslyLNPE49gEH6Ji1IVwBbpMqjwKeI=; b=pq+bA9+Hn3UYOGW9F4L6NjfJK/ZO+uHaXCDIUpJ6YackYSEDmp5Y6Vw2a+itKjhMiodiBSppwBT8P7KzXueMo8GtDkC4Au09LBclSJ97h3zdlbmEk1KlGEOrL5oVTpcJNDU2E2mxgzjk5mO/GV4sv5RJm7T/ymKMQ5YFF90lH3k= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by BY5PR10MB4228.namprd10.prod.outlook.com (2603:10b6:a03:200::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:22 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:22 +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 v13 4/7] kexec: exclude elfcorehdr from the segment digest Date: Mon, 31 Oct 2022 15:36:01 -0400 Message-Id: <20221031193604.28779-5-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA9PR11CA0013.namprd11.prod.outlook.com (2603:10b6:806:6e::18) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|BY5PR10MB4228:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f686fc6-37df-4ea6-fa45-08dabb77310c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GE0KFhpHrfd6qY7YB7tNoJmYwNjnHvmrPgYKLJsfkv1aFlJuiYyOxeJb3eSryiCivXVfDA2VGULOJ3J78I2jRAHPFR6+cRHivQ0AJiQBvCbeJBnTNbugBA+RE9Gl7XitroznV4hCTp9poL/i3fwOcdYsvhx4WfvmFm+QvUykNbwmJ1fgEnSxqN9RfQ4tBtUqAYg+G3MY7bwwN4lUUrWWjBFXNnf+ak2D4g+PxJYmOa5MSZBn/of2DjYyggZvjQZUjvhbdgvWGvoUp8lzMoxduN7duDWp+WlyEy1CCALfrgmIvA8C24lM/FSngbr60lwkcnfRWIb+aWx+1WuJCFJxJ+HIMhzIrhMxZg3OnzfqQ0lSRZFJgOZRuJGMCFbDkVWfMrKfoB31bqvbNzZ7srGqZHGwy7s10iVmweBrERpOW0AHabf57TJPb4OyW2EXkZJAKJL5JKH1fmjkfHV2SMd+AxkrLFjxUcj7KXywnczpZ2Hc0xhtOTTK7p1Csg2oHHAp9ADFAhed9OZqP5laGZF9UloCNnfWSKVSZb06ESz9c6BFznN1q2NLQD3Jr5g1tqoE+Ghz22ie1J4AjpaKGFNdw3ZjSgSb5DdM589EY08P7T09QfHa3CIR+Urlh52RIqYLv3Osmy31ql+gUR3amQeYdttHvhtZ9gygyt2D/OqnopkGbHid4OUR7tTT+pI2Jx1S3ynj0HdCGs78StPkEYPsNA== 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:(13230022)(346002)(136003)(366004)(39860400002)(396003)(376002)(451199015)(36756003)(2906002)(86362001)(6486002)(8936002)(41300700001)(7416002)(5660300002)(4326008)(8676002)(66946007)(66556008)(66476007)(316002)(6666004)(107886003)(478600001)(2616005)(1076003)(6506007)(38100700002)(26005)(186003)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eTWiOkdi6Z91f32Kku7E7kIf3655dWJ6eJKt+nUS2FBXom11PO8aeSjkFeo3QAOeT6NhZlwS1I6pB+4/EfMJ2O9Fmb19izXSX5TcEPGKjgRIRXFNr7Ev+fE+MtQ+21NEGqDtP4lfeOxN5YR80tmAxO00+z6eKC+ojj2f1xpKNVdK0vi9OKh2ixoPEGgZVak15bAi7NZw+mbjQlc45lFLK+prZ35+tMfXWKyooq9xXmTST36kb6aM7OctkaK1BAwhumAzK+wHcVVBxOWQYHl1CD21pUh7u3CLmvhUt31b2wd1nLBwJhQrj6t00oOi4UUeVpXHHN3jVAIVoFKLUZUILXLOVbg+lZOO0pJ1yFamhzyGLxpW/XhohhSMsnPFF5QUd0H0jOtdATwP6hPhTaWo6HToh+euQJk+m1dSq5dzPJwRRMryUJ6VjVnCK+ghiH5HKmFWZoTPjzhI1mV4jnStXOQjtcFm2PLg6yG5bmARiJXL2GWuj6s9Tn36/U1nHvWFoqRQujoa2Bg7UXKcPzkkmkM4kZTA3JbT4F0skGE/btPQ1bNOaduVHMOEkzmJkI/vd0iJ8yaa+Kc0wkHZvksG8Q3x84D7wpkSUTmNgiVYbhiBpplJXYwno8+tajufbUHsKSsTlKm90nwf3/UAsv7+krmaDEMja5VaUubZxoUDxX5nThDza6sXNoJZqDVLA6aBDl8obQefsyNAS/D1KWR0oi7gY8Yq/F8BvE4eTrb3n/95kJIqI/sENu0UcyzI2Jr5cUlOxgpOuzKvgbs6nK1ZQ/IfkSNuTcICRuusB1IrMq68O25EUcYwsHwHae+h6FAB8LtCDf/1U0owS1D7tgU71YTUo+E9ctVfFk6oI6m/Livi9O4yomaYHuNq3p/wNHvcdQ5OgfpFfzDHh7LboR6vWfkIO+c/2KEsEuPAhMnb+ewppqfwMNnGOVDPpbE5i2jC0uVJL04JocMOjklVjTVvm+5ZpoCcekY+f6ZYC9grRBIEvD898568Uun1Uqc0e1Z6oBm4ChX9uq8Kiy3yAZolxOwyUEdag4VIr25iBqod9ocpzrmrWEfKG0LBJYXdqEoRCbYPSg3hpxSgOS8fKl+SPtlkufYSxW8Vy7/GyMagDKUITEU9XHJXUG9nFMrIdeOUOiBs5Xy4GbyHqf9sRwXvmVXpADfu0QJV2fY0K+mUkabk1nxJHLwlfkz+OPhsFLAOcR8u9iGkp31u3E2fnBZ91SajF57NmbQtTXzrDuWr7iU2wd3RyTtfQl9KwK7L7VOFQ8djCC2jXyOWngkiqkApM8oQkoRSyddHZuFBR9EALZ/54kj+RzmwESx648gI3ppjL1BInSy9LlAW+Nyy9e/qaYV5b5y3plol4hp4pgUBU0/8ePQkw9zqVAej9DN+yS3mVgOWJVlJMgsQ8VSC1Qb6UAIuSCFoEYGVKDUD3TUTNMkyBKoAIiGVDH6Ek8wwoZTzeiQHwNIRue8y0n93WiYLBHSm2PGj+ms7zkJFCuYxqSYgg/TJ4nXDvbBxzteDXixOJ2wAXy4vOrKY9RsqRU53b6w8noQia3selfYQiDVTQKc+U2VLhKRgv3sTpqUusCvCTwRJVuG51Vum4YlDEj6Ifg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f686fc6-37df-4ea6-fa45-08dabb77310c X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:22.7271 (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: iMR4y52lrXdheuiNaEfgl0jABkHwEneeYbiHGSWQK/Mqk7zQ0UWDnUGddHHk7mVDgBfrOEYx5uM7628hB06EvTfLhdZTKaE8mwbQfQopIqc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4228 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-ORIG-GUID: H_eQ0N7lDN9fwgbf_ensSii7eJ15xs8B X-Proofpoint-GUID: H_eQ0N7lDN9fwgbf_ensSii7eJ15xs8B 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 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?1748233479708698655?= X-GMAIL-MSGID: =?utf-8?q?1748233479708698655?= 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. Since hotplug events cause changes to the elfcorehdr, purgatory integrity checking fails (at crash time, and no kdump created). As a result, this change explicitly excludes the elfcorehdr segment from the list of segments used to create the digest. By doing so, this permits changes to the elfcorehdr in response to hotplug events, without having to also reload purgatory due to the change to the digest. Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- kernel/kexec_file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f98d1742872b..4d3451cf9f0c 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -723,6 +723,12 @@ static int kexec_calculate_store_digests(struct kimage *image) for (j = i = 0; i < image->nr_segments; i++) { struct kexec_segment *ksegment; + if (IS_ENABLED(CONFIG_HOTPLUG_CPU) || IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) { + /* Exclude elfcorehdr segment to allow future changes via hotplug */ + if (image->elfcorehdr_index_valid && (j == image->elfcorehdr_index)) + continue; + } + ksegment = &image->segment[i]; /* * Skip purgatory as it will be modified once we put digest From patchwork Mon Oct 31 19:36:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507663wru; Mon, 31 Oct 2022 12:42:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WmctV4miC4tIgVwTYTJ3+lqdqK6C5zw08fJVbbM7RBwl9SztjlqeAh78L5MdFNGN1mGr0 X-Received: by 2002:a17:907:aa1:b0:7ad:cd92:a48f with SMTP id bz1-20020a1709070aa100b007adcd92a48fmr7750675ejc.369.1667245365709; Mon, 31 Oct 2022 12:42:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245365; cv=pass; d=google.com; s=arc-20160816; b=LE+vkkrVszkYpxhF64pbqFXLtroq0ilPiLomlkrXwN6kbjZCtrQcdWS4NCKU7bG5xO S+hrQg/OWkNl1sPzbbvehHGV2RtN9PNtY5qrSuN0sk1DKJO0LWtebNIOUOC9fYInYLII XWKyU7Ptn2JzSsZaEVW5nYnybMg1gienaGdFc+jP4XHjhOFR/sqgdaM8Iyc+yXJ/Gyd3 mbzuR/iJ6XQoy9NhjWdTQk7705Fx+MufhQTRKiTKosPJH4hrCc31ehN85hq/oociz18o muCXGLD97+007p5bW0FFYo9QIIDzv5/VbNGfNkTyhiIVJV9hyRqCCxCvZ+xsMCZqPz6Y FP+Q== 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=4FuJFOdktghNoyHGaLWoA78CkTP8gKQRefEyDrRVWis=; b=noyHsw7cyl+a3CMRFtrRblcQgK4I0oT6f9msatiuvczSd8OqsLAat62OrPBzJD3i6u b7t6vtJYMyotgVmG8YD6BIUCUS1VE7qGGFdTvaQadaqnzaFMbYs+ZoQEPxX1GfUUxOZo h4hSMp+JK2GlhAGRxRb0MW7nxi4AMITmh+tkKXRXTmuSODWOMLPTbn9xmKkdeM/TnA0U 3uyDWNJDao8AGrwAGQ2+pQ/KQRDEt1+r/UO+6r/7dn4nFN1BLroKh2Hd4YQtZlfMDM7u hvIa2LqqH09TumEk6eKrz67BawyS8v/yfj12W+i/k6os2XyTgytqOZvwuLAK2o0EPNYp YtPA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b="k+1Id/uN"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=rvdiCCSY; 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 h15-20020a056402280f00b004635f094565si5519969ede.535.2022.10.31.12.42.20; Mon, 31 Oct 2022 12:42:45 -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-2022-7-12 header.b="k+1Id/uN"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=rvdiCCSY; 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 S230111AbiJaThP (ORCPT + 99 others); Mon, 31 Oct 2022 15:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230072AbiJaTgz (ORCPT ); Mon, 31 Oct 2022 15:36:55 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A74C613DFC for ; Mon, 31 Oct 2022 12:36:54 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VGxI8G001214; Mon, 31 Oct 2022 19:36:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=4FuJFOdktghNoyHGaLWoA78CkTP8gKQRefEyDrRVWis=; b=k+1Id/uNZf92wKS+yrcxDa3Ro8rN9jq5NtMVkB1Ywc/Y6KIdKUMo2pSU4INW2qF9EW9K 3UAoLzhC5Ej4OqBNLMa10wKacnaOWA8WvTLF1kMWP44jyn9dhkNTkyoC6y55KlsNAcTM Qfva0I4DtvgnAn1Ss+OqnevK8C+k0cPGBbCh38L6HosJ6nDtz9dGuIGfSBdN3NJ3lzp/ 6bhGcNCf71QXUoaPeiOYBry1zKXUXq6u6scNxiaf+OnIX0tTUlyBdYYSnRq43uIftE93 InYhrKBnWlfRxVwX6nNpy8bb5hmuk2hnzBO5B8WMTL2Z2fNklhSvMG3+jsz0htu8B5Rw Ig== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgvqtcqum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:28 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VJXEkd033125; Mon, 31 Oct 2022 19:36:28 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2106.outbound.protection.outlook.com [104.47.58.106]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3nkfg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jHxglbmK+mTVOZnUxaXIzgAIwZQqMVDEDL1HVKXC5viy0hupd/ATY+Gt2vIo6uBVAsnMYx1jG12dJFaDs0uWfYsiOmwE1XzZig0XQwnR5eFrZ1fs9mBEZULKyxjbrtxEglsw3dAZ2dnFIBP2KIxuguM7g6ieTL0lW/oXiwCqHj89TSCo83GweIG/H0R6CQqjDpalXR4DlTi1avGNJVlnTSSOMGADUbL482e/MpRwblSJp6ybqZITjLpMf7F8ShbPvCs5rwdBK4rhf0omu63FzQpEeD/YySMC6Y+MB11770mfmsPgZLwJ4mgTf+cDLc+LjnIDtR/6zWfzYwx0811SSA== 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=4FuJFOdktghNoyHGaLWoA78CkTP8gKQRefEyDrRVWis=; b=SBtHW0kkJZF41D1sHr/AGcKQbFJXxzIpZ91U0E2sRdN+NffkmfYbuBJusu3L/muTIB/3D1gec3dOFO4boSPDLicLdxH3L50m+1Y1MbNAAKFv7rodIRkRCEuiI5nF/IOtHxbJHQDcI2pDRbSiR392f0GbDP/D58CgM2jibQDEBmNkc57xR80exJKK0Csjbe++SuOFeOUDqA4pAci2jtzvyI4b6Dq9NX8kly4/d1luVKbUKlAGTlR1RdC5Gbu6DE5OE0r2XGwIso6JToYjL7G4FJYsMvLSiMpj3CkqW4IhGpUhruvE+y0z13pFhnHkZNkzmAxtBAZMXdGdRWgHyj85YQ== 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=4FuJFOdktghNoyHGaLWoA78CkTP8gKQRefEyDrRVWis=; b=rvdiCCSYdsYG31eNkg7KXKlDbgl4cGiVNOFaWEHhRAX7KdtM5Au7bc70f8zYdaxLZBsCFOx9yolUCzUyNPUT8zvWwdL95cwiFFMKTO72mxyRaC9RVHJl5t6pDd8frgAlZchWzgay8E6pu1JTQaBNSLCVuZRB57we1kFi6esyLW8= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by IA0PR10MB6793.namprd10.prod.outlook.com (2603:10b6:208:43b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14; Mon, 31 Oct 2022 19:36:26 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:25 +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 v13 5/7] kexec: exclude hot remove cpu from elfcorehdr notes Date: Mon, 31 Oct 2022 15:36:02 -0400 Message-Id: <20221031193604.28779-6-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA0PR11CA0194.namprd11.prod.outlook.com (2603:10b6:806:1bc::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_|IA0PR10MB6793:EE_ X-MS-Office365-Filtering-Correlation-Id: 29e334e2-2239-44f6-91fb-08dabb7732e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Uy8IZSt817Bk+cOHtitjaY+BH0c9+h2diw0+aGHLwkPdmJ6tEDP9qZpvkqRTnoT8WlWmjm+6it8rSxcgGqkiX7IEvpLyO0vW4ZqCEJfl7+MHkdyGPNQwlpJSUWnTTe5BfnvPw6dl2MZ3sE9whn+eOcpLxL94pbrKC3pcRmfJi009kah/oSnWNfNPZEd1rh5sQLTNnNsG7Il4/Wd1Hqc6+/0FK4QgDl1SloMSaAvUVwMf/8ixIEYLVMRb9XlEaRYnWlWArisZawzBG8P2622Ccqmh9RBPdDgUZqzhYx2W0qoraeKL30EscHNAJKxIYHC4RTzhD0SPdP/fSmg+x0B8KnNkwjE2cGJM+bD7D32Ne4G32viOhOxi3YTQEQBqDIW7PvsgoEJYNF+1ssr4M7mFeruHAV22QB3SgNlBjIfIWolQUyOtgPR+aRd4lNj+YuhnH4Cfv45/TNpwc2lVmPROMYkz+tm3wShCrkGR4NVOJh+DgnozWhV73xyRCsgK/gobGZaCHf+eyxppnIpoQO7J7hrBrQ8jtOa9cqyg76aMqI1fscMM+RH5vQWO3f91hjYuAQamqSqrEpNcl2GFQOMHP+bsp9JLddZ6p8OKpmVnZPocu6w6X2i2p2kMMfPaXjoTTdiZyqAZkFGlpRYAU4W9IaAXL7gVM72DiJndTl8sKqo7X8v/LfuDPo3YVtUX5VAfXGQ2NtiKaLkG0ePWo/lew== 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:(13230022)(376002)(346002)(39860400002)(396003)(366004)(136003)(451199015)(186003)(2906002)(1076003)(6512007)(6506007)(2616005)(6666004)(83380400001)(26005)(107886003)(7416002)(66556008)(66946007)(41300700001)(6486002)(38100700002)(5660300002)(478600001)(86362001)(4326008)(316002)(66476007)(8676002)(8936002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jrHVU+0zayFPw5PodpnqM2TMLnUTS14P5ecG4XMBzxiJ2Qtc+lPtnmFTJgiBhsU+/E4vfnzOmY72aaAS04nBBMjjuKPGL8jLBFLaFFE0veYkS0aCQIHg8i7pJX5rzP9c2Sz8zp0hl1rt0481lIN3iBitctjrUr83DHFJbwap5ko0bJJruLX1IOjRA+CinY3tTmq+Dkv8InXYwYs3jt98PUYDwKjEZVm0ssarAMudJW+hcNLZnbVx0uEf6vYv/w+di2Q7LKcbu58X2bI6I/9lO0OgmplBionEbDHBY4vnuqMemo8iw6yTk5ZjZb79Ag1e22o0di7mIJ3dHF6TB8iAyzg9DBIEMY3QQSWuLVzNtYZn0NcaYaTyHzJRjjJBzpPzVZPtXoPAHjvFvkZjzxX03bGdHco50zx16tJRkDlcpk0hRj1Fa76ANjuHnym+AVi8zMBJGilvO4MjlOzpqCXQwDocMp2sTnssFfmyfAwaipF2iLCopmiBRlieXCLbfIJTrqn3DdROM7yCUYLwcrsAFbPYGk9d6StaFZeNCXSN6aCK9vsaD7SfTEgiOdnGZTUkWRaCeiX0CkbFPALPyc3a9uVNkwywhvYrGrTWl4fbI7ZgSE3eyanhIEILAhld4Yzu9wQR1SgOOszybuaxBOSmpPvgpk6CtjKrdEDp9f5vCkIBGMVZuuxmQKKyCakAJHh+5Fnq71Ez3x4vC40WNGFREFA1+XvzNdWaY+MEDNSitBWVQRcNS/oBDGOXoCScYOvy14MSJBjKuTqFTQAGEmDdmYCqzkb6jXT6uEOkBTJKNyFOsYxZjH0XD1NNKAV8kLpuJyBfVWxvBu4k3AZ5SqNmnNlsK5+HjWTQ39yFMMpB2BOi20Hs1sCWSUn/3jqJc4VUENHGmW9EX39Fs+HCzb6Hzw2M6lNinXgw2t9yuR7JJpGMozF+TeJC8OkJ3nSWi60ZdU3pg0nMf2OeNb88NrvxEVCRzIL3UF7VZM9tl3DsunI3Rmpc/LdulqaNpCW/zEDFNz+Pc+pyv8KwALZj7tuW00S8mV/nt+hM2LjALbLSRLEblp4eFSeBOjc51T2lfYBS0PwS9F11b6O5AsKzHNQcwT38CeaIRex1jKAgQ6d/BJiF0SMzklRLen9OlEyBPpTlG3+Vm15VGPvLXTNLEAw5iN3dAchdmCSC8lgiOMwmOp+7cH3t3yAufCCbhq3cxvf+2fDIs0cXP4s4I7mHeSfzApIztHA1diBi10E4VE6r3o9MfO9WROXAjVgy8JEaDm3tWs47MmPI5CY9WqyA99rRy9uFLUycUNEJPaxdFW/0D6rrR5NZhdXUZE+FpdVhCz6D/qv4o9YMTWAR69RhGBnvOddS3t1e6+rM95e+4swLAXvxfDwnFTWAWKQ21aolz6QQHB+QEkZLdKxojsiJ3kn/d7yw5wAVN6lzdXAbTVF/SqwX3hdRigMTdVcC8lKL0YC47Tn3Tr6uM4dY/tiK78Hw+2ozWOetXzwEGD1cAlmiwjYp9rfzBt0qiKn4jimNqSSBLm3lpUu0/dXL9eqXHae96mp6lxfYzaJkELwvSq0KGf1nsv1VRWySiQOv3EsMQmScDtNwYKpQcj5/dgJe747ylg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29e334e2-2239-44f6-91fb-08dabb7732e7 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:25.7916 (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: 80CKNwEbECAYYIzBT/A0AOtconFurazWrzzfmblwjTlZ3pmqCLWYqDn7c+fArXOcdaHZvrc7z36lftn7I8LdVtjlYGUZemxtGlVP2vnqWwg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6793 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-GUID: 1wypTOrUMJNi4lIKITGoEIEEdk2rWfwY X-Proofpoint-ORIG-GUID: 1wypTOrUMJNi4lIKITGoEIEEdk2rWfwY 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 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?1748233476541607166?= X-GMAIL-MSGID: =?utf-8?q?1748233476541607166?= Due to use of CPUHP_AP_ONLINE_DYN, upon CPU unplug, the CPU is still in the for_each_present_cpu() list when within the handle_hotplug_event(). Thus the CPU must be explicitly excluded when building the new list of CPUs. This change identifies in handle_hotplug_event() the CPU to be excluded, and the check for excluding the CPU in crash_prepare_elf64_headers(). Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- kernel/crash_core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 3a0ed4168fcd..bca1b198d9e5 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -366,6 +366,12 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem, /* Prepare one phdr of type PT_NOTE for each present CPU */ for_each_present_cpu(cpu) { + if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) { + /* Skip the soon-to-be offlined cpu */ + if (image->hotplug_event && (cpu == image->offlinecpu)) + continue; + } + 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; @@ -684,6 +690,16 @@ static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu) /* Flag to differentiate between normal load and hotplug */ image->hotplug_event = true; + /* + * Due to use of CPUHP_AP_ONLINE_DYN, upon unplug and during + * this callback, the CPU is still in the for_each_present_cpu() + * list. Must explicitly look to exclude this CPU when building + * new list. + */ + image->offlinecpu = + (hp_action == KEXEC_CRASH_HP_REMOVE_CPU) ? + cpu : KEXEC_CRASH_HP_INVALID_CPU; + /* Now invoke arch-specific update handler */ arch_crash_handle_hotplug_event(image, hp_action); From patchwork Mon Oct 31 19:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507137wru; Mon, 31 Oct 2022 12:41:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4yS8Qx48vvs3/cw3+kZzgmUsLb/atzufpVIUffIXkr7vWuVVGtQgW5L/9NRbG+pL4r/y8B X-Received: by 2002:a17:906:9b8e:b0:791:8f57:6845 with SMTP id dd14-20020a1709069b8e00b007918f576845mr14992056ejc.174.1667245299328; Mon, 31 Oct 2022 12:41:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245299; cv=pass; d=google.com; s=arc-20160816; b=zF3H5g3fQ6Vzki3J8D/67CTLbxRPKVCoW3nlM8kF/2IaubpG4irl4RlP8Y0YqbMboH C4Vp1RZqaYnY/FICC1lB6Msdk6JH+WFsIGeLMkS2QJTTPQznSZKVCKTJFwNJHIEm0dhL sto2vv/sjhSohN7OMGRMy2MK18EZ6WGIRGRXpz9JRi8hXtTYZeQFiXezDOJpIhyqUt+q 2AZSEDQNkdg5kyIoV3FjVwnlxsTB0+I+QW6kcsgvvvskU7nbo8nj+x3E8CAgkF4CVeem Kw94Da+JHtCV6KXasA0KusNNaFe8/6pFv0yvmREtLL3pDuwUYsGHiJ/gi0WAKOiMWFVo RuFA== 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=qpHNkl7oKOlGdHK/zehSz7eT7IweqVljWH+57bbI55A=; b=ylWcG54F/WYml+FhVmIidqPps//agGWmXZ2Bl3m3z9DMS4npDHL5nSMB9fSKeQz6zO 3tkxaIQStK4sZ9zjhg38N9RC+Vz/EKv31ssJV1HO6Fxo97U8VL0rn7K1JAYXyEw+GJLK L38SBpuqURQTAsNF2B2MjZUEYV/ZZc6h/2H0mCEJ91MRO1n6Fi48d12CG8awiNbbf+CT sjMq8ceu2gspm4xKxhqnuSYGVO0SdfcksM4GOovARWJ901e1A+hWbL2ajYEVYCqtWB1T EVSePLil5llhji6mrTqFHD/RgQlD18Yy4KpyG+O3tqTmgw+gqmy3nLULpey+tm+y0+cx seeA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=Qje6cT2K; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=mbLVpqtC; 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 d11-20020a50ea8b000000b0045d5e3c7f44si7599050edo.180.2022.10.31.12.41.10; Mon, 31 Oct 2022 12:41:39 -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-2022-7-12 header.b=Qje6cT2K; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=mbLVpqtC; 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 S230084AbiJaTg7 (ORCPT + 99 others); Mon, 31 Oct 2022 15:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiJaTgx (ORCPT ); Mon, 31 Oct 2022 15:36:53 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B56F13E21 for ; Mon, 31 Oct 2022 12:36:52 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VGwxLq014793; Mon, 31 Oct 2022 19:36:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=qpHNkl7oKOlGdHK/zehSz7eT7IweqVljWH+57bbI55A=; b=Qje6cT2KyBHx1I6IhlTHC00obnhk7XaED5PUkw2tfZKtwEx7cS0AB5ovvpFFFwLsa0BU u+9MT/hVy9tQdE+voUM3MKwbRspxRtOhrhzUKIVJxyW13JINPK9hmHWmS5YPSII50WCG 14D1fO+2LCLpLJvALdsmZqxOF0LoJAxFipNiaKrh/sxoPr+xuH9q3pmE7mz9a9nbJLBh 8gw+fHOwj0t8HSv8vPKXezduX9M+PfoPO4gwAZTpSAtwr9TPh5sHv8xZ5s6NMtUXf2NL 5br8iznn7DCRKM97CsjMTc+8bJcs/tix7XHu7jW0j8xTd8Bvf8Jn/x+oZXm7OGXn6ZxS UA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgv2acn7v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:32 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VHTkAj037528; Mon, 31 Oct 2022 19:36:32 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2041.outbound.protection.outlook.com [104.47.74.41]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm3nqek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KM/UzlNfFSnXgfvJ1v7rw0XmP2r5tWmIwEUhq7CDf44qzLTPKTVhPStEzknpRCqtjrDdWhhHgkU9dpd9r8624UHLAv+gM2ew+JynFSlV0FAbNnRcOnAetmHECZ2yGTAiLh7gY4VFkkfU7ckxALPQ7sIizglrhU/L/2X+ktJ3XpLzPxBPBh2GOU/wvjuLN002Qp3IVPVPcM2rl4PW0zRa/qCHgKLUUfEesnoZNRX7YQVxZw/FytEqmoQfXL1iIm6rWs6XlpJCW6/NJIrhm2MOflOGFGnlcudApiuTJLaf/unbInIzksv7jCb6lqz3oVl0MwONA4uknAYlSZY1FeE08Q== 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=qpHNkl7oKOlGdHK/zehSz7eT7IweqVljWH+57bbI55A=; b=QcZXpoH38dSnE1KTvS3LlLXBxJuK7ooEx9zJNHsmcRa1hTmTlYjeUuXl1nb7B5l7ZGLo1Px1GEk9+NSNebY7LoJAhqNzCGudZ1OnLGDMqmpkKlqtOhyjOEh5O+vR+dZ5UfKQHQGf/wI8siQsms4E/pWcXiarHj/i/lI4lCbEiCb+1MrzVaTkjP7n27U6H7qWBV9VFGiZauSQA0GRdBWaZFmAW0sFh9hG5Keg36awjyy5gP1t4wryrOYynGmNJgGT06pgY3gUMtJnA3LP38Ca7EK1qFFmUkgzMWTjxexTSUG8/P/9AI6dOp6jMiT3RjFOyxulpYYdGyCk5zfljtbweQ== 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=qpHNkl7oKOlGdHK/zehSz7eT7IweqVljWH+57bbI55A=; b=mbLVpqtCRzi26pZxaufEqjp6XaIZt2aS0teo1SNER2YH+kYEPbif8HJ94+ensfbvbEEFHJYNWyQ/Jm+dK3QHUkGEyjWDkrnzMo3hJnm9e6dyiU1gZi2fm8PmGZuDsCDpRAMdjGZ6l8DUYWyMn8AFLl0xqRm4TCkT4he1MBzmH2k= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS7PR10MB5070.namprd10.prod.outlook.com (2603:10b6:5:3a7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:29 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:29 +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 v13 6/7] crash: memory and cpu hotplug sysfs attributes Date: Mon, 31 Oct 2022 15:36:03 -0400 Message-Id: <20221031193604.28779-7-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SA0PR11CA0043.namprd11.prod.outlook.com (2603:10b6:806:d0::18) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS7PR10MB5070:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d8d6f90-f7c7-4fd3-3613-08dabb7734f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ga1DccLzHCY6MtZiilaOaPg8GnoEdjMYwe/CDtcqJBUCKtJQ1JSmmtCS+Y0XvErbLszjUVXo8AgW1l8NbYGYjDLdFCBnoscgeAOehAzbmFNZpHXRnOqWNDPF9QwihyqmFmEHtR2FQQkhcIXtA6POTLxJeYIT7ZyQozw1rGIO2cFPuqkIhrY5JyA0xaRhczLrgdCgAuhPICA7KrAe/7tuGA1fKuy8c2AttyOJTLhk40ekNFdZS4bLXGN/9NPU/2BJQvIPs0W0RGZPZ9w0T1vXCsbEg51k8zp9t1z0Ietexw4a7k0gC3V85Fuo3jUIetszNyWDMkw1hbRzh90hGNOFstYqnmNfqW+A0js7Wr4fx25EIuYCq0qV58gPfQY6jRaP5E2ZFaHyFdE4UMl2U7rgo6BvjJM6eiT3IFhKI60mL54hwvETjdLQzqbzd9VD1eD51jgSOM6H6PThkm7bxeVsd032mzcuAC0gifgChePAux9f/FkiX2GSskuadAN11UMRvpU30l0RGT0AKDQInDpA1viWoh7Js4Md9h60kFqOAaZfBQt0Y0dyzeep+QROJ/6HT+OTfKNjcPU4skx/OgAK17fvO+TNxAr7lMPvZFKJHJ/infeJ9zUBxDZMLa5EVB88R3Th9d+3aTiedjcQfTTTT9S3SUoSCGqW5umHQwupBNtHXn4FN7dJZ2yp9Qm8fsFLDEPoL97gsGs8EipSYBnLmQ== 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:(13230022)(366004)(396003)(136003)(346002)(39860400002)(376002)(451199015)(36756003)(86362001)(38100700002)(83380400001)(2906002)(6512007)(186003)(26005)(478600001)(107886003)(6666004)(2616005)(6506007)(1076003)(6486002)(316002)(7416002)(66556008)(66476007)(8676002)(5660300002)(41300700001)(4326008)(66946007)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vl40RPAR3SzedBEHqw4jfIvJzQQyYGhqILFaCsUelDOTtEVuq2oJJ/XXO2i3do+xoUvFtP+17tBlb0Ms3hAbIQxuPzNy1qrHntXADexjzVi1uvSmHx4ghNsg9tMGMNU4joHBnhNkShMBJR6LM5b8BBl/+uXZUNGF9v1EvTwa1DkW7/o/XuO5h1o9cnYOmz19vtcFTo18U43Ckbn+J4b/3iJkfaQT7C52EgZzkkW5034XxhTQD+plb6iUqXBH+JYjbKqU1PmcbSSLmnmqtSs3b/EM5pNVkv4CyLHrvOTapgdIJDlkoKTNnzEk67GSjRgE/OFOf3cAKy0ooGJYpV1n9nzWVqOmnvQ8dYKOfTSxuyO8B+onV1LpPhyf0782BJ1Mp5lXCd6CoFyAyqnqgGVVrwJMQFyFf6m953qVXQc4Herl+JhJCruylg2ONrDnMuARlful7QSSfCiGYG+XXAmTQLtrOtwlITprHxKZQhSNStwyiuCiEpTkK/hp3O0ZmAVGlpgScOvyMqFfm5CiEFCWtUcoj/hJJiCujidO3sBOZL9hV1qbtSuFZQ+4eKn4VR5bpwOeiJ4JMhj5dJCfHr6ovrhMVbch7XHnxJ2XfCEJ5bWTfkPxbt8Sh9WR5ghRSy/C9TXbMktsKVWwzO2Ba3gkg9ziWQVJpBKsZn7DDE3/11Y1XS2hnnOeCYtj5CMWAVvoRt+bik892gGYJK3/J3ezM/Ps0byHI2xdFM2JWQlagNG6cMl93yhExCcaFuSnzVICmTk4YFeaNaKLErcNpGEXzXI6T9j3xDdQ2tr07dh2WKJ7O1XVmDfdTRyt5NwY8dYxHXNSseeFbQROei8ueu6aA0DLuP7C7V5z8Hl1OMSDp3DfSFfajHduIJEV0HsBDHSNp1JvLvD0ab/Pt2Baa2DSxXRCQpcthFj/2aODowha5ScjP1EQbCMGkF2DZqsWpGDKbGj8go7pYPAtj40o8uu8IApG8g68PMP3tvtVADnro8/lA0SnWVvlWQUgblAc2I8UTDLR6ZnfXufHBaKCZkKm008c1NCjE8pTy+K3HHsDVMtyUXpNfP4+qmrIg5ch2x2A05c6qaA04V7LG5eCqmSmBNxInwKyHJ2W4H00XINlVsbvISCDAqqIYLJuLP5ATEVUhnLShWLRRYdWDEubr1EssOuP4uz/J1/NfhNl9aOWe3IN8DoqE6KopInDLZL5+syd3r7QxIMtJmDgEgPFx3ndQDIRhU8KGOhft5uwZgPWyFQLyP3b4jjHLed7m0RDgZWImHdZkeNP4WhrgEDUBootlvKXnkuM/lq1brJDqkZo5+uP1M0owM46brnPryZLePHJ750DR92cbBptavT5Q2lBH5iEsVGQLHikpwKRFuXqWT28wtVbrVq/z+xwoxKjLIsU4CDMj/4T1FC4o0Kx7Hx37w3lEb2Q91QWd4yYSqaalDfJ70YbP70wmGBcsbMfKcKa9rW4qJSc6N0gGD2sKwcBh5OpgJX5OJ37FuVY4EmLy1FdEFbMCupy9mhqGiWXmVyy2f3ZkeoXEg3AAgdrraMOJzDGbZskBdVmtGCIIdEQkocQ6mG7iHhZIafYCW6s10P9e/NriaSraL3s8NTzdQr09w== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d8d6f90-f7c7-4fd3-3613-08dabb7734f9 X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:29.3095 (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: 8mEEO+oV/a1I9lRdXBUZsYWyK48Obe9E/p5xOEGa1OBNWjew7KEqvM2r7CwKjarbSTurC919C1HWYGY6FhLGLG3jlXmcpUq36LMLZZvdJh0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5070 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-ORIG-GUID: FFcZNLO1OhCnBGK0_XpvRpmyRehwqI0X X-Proofpoint-GUID: FFcZNLO1OhCnBGK0_XpvRpmyRehwqI0X 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 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?1748233407033754139?= X-GMAIL-MSGID: =?utf-8?q?1748233407033754139?= 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 example, the following is the proposed udev rule change for RHEL system 98-kexec.rules (as the first lines of the rule file): # The kernel handles updates to crash elfcorehdr for cpu and memory changes SUBSYSTEM=="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 fail for CPU events, thus allowing userspace to process cpu hot un/plug events (ie the unload-then-reload of the kdump capture kernel). Signed-off-by: Eric DeVolder Acked-by: Baoquan He --- .../admin-guide/mm/memory-hotplug.rst | 8 ++++++++ Documentation/core-api/cpu_hotplug.rst | 18 ++++++++++++++++++ drivers/base/cpu.c | 14 ++++++++++++++ drivers/base/memory.c | 13 +++++++++++++ include/linux/kexec.h | 8 ++++++++ 5 files changed, 61 insertions(+) diff --git a/Documentation/admin-guide/mm/memory-hotplug.rst b/Documentation/admin-guide/mm/memory-hotplug.rst index a3c9e8ad8fa0..15fd1751a63c 100644 --- a/Documentation/admin-guide/mm/memory-hotplug.rst +++ b/Documentation/admin-guide/mm/memory-hotplug.rst @@ -293,6 +293,14 @@ The following files are currently defined: Availability depends on the CONFIG_ARCH_MEMORY_PROBE kernel configuration option. ``uevent`` read-write: generic udev file for device subsystems. +``crash_hotplug`` read-only: when changes to the system memory map + occur due to hot un/plug of memory, this file contains + '1' if the kernel updates the kdump capture kernel memory + map itself (via elfcorehdr), or '0' if userspace must update + the kdump capture kernel memory map. + + Availability depends on the CONFIG_MEMORY_HOTPLUG kernel + configuration option. ====================== ========================================================= .. 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 4c98849577d4..fedbf87f9d13 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -293,6 +293,17 @@ static ssize_t print_cpus_nohz_full(struct device *dev, static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); #endif +#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 9aa0da991cfb..226be3134ffe 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -483,6 +483,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 @@ -881,6 +891,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 04ef5172c4ba..e2dbbcbf37dc 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -542,6 +542,14 @@ 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 Mon Oct 31 19:36:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric DeVolder X-Patchwork-Id: 13422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2507518wru; Mon, 31 Oct 2022 12:42:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54rXii62dsM+YPZuS6RsWjS+/ZroVUkgpBBaX4m9t/fLLaGVnJzXXUBh5XoAJGWXT5ZTRz X-Received: by 2002:a05:6402:3887:b0:458:289e:c9cc with SMTP id fd7-20020a056402388700b00458289ec9ccmr15501019edb.101.1667245344483; Mon, 31 Oct 2022 12:42:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667245344; cv=pass; d=google.com; s=arc-20160816; b=zfzsA/daAsfA2erA5LdTH3Ju6KRMqvEC0MFmGefARASOul5QLgDuGuTCiBqkDCvxn1 aHIsOn+fF3FuETV4RnA0YHwqTTJMdAbedLr3v3ezAPzRE73xPi/WElCD95fsBe0/KTSF 9zMJXb9ynBJMIL5j2k7IA08vSIEYEQhISzajZCHLNMOm9IQylV8oonU/pmOWUpWoUCbE O618ZQKTeY+7VWqDvL0VvrYwfVSv4RdbgkwJ1Ei3Rlf9WVg6L7A8oqe8cHPxSVts8mMS +TTRrw88O3A5vyxVqRqP3kIxWJPdhPQSW/yWAeMHgsgoFAg2F3Y64gBCRZpzRDAKts96 Lq9w== 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=wlaWK8/IuhSMqnWWytUFpDjlT4v6bStGWHIlG7FPo7U=; b=ANon8omTBOVUXLAshwWhOGN4d+djyp4hze/N62s3Ms4MbRTr0H1PQsYEAAOzrPt5zP 1yIOHATQr4UNkmoHxZDBPbYKjOtE/BErJBAR6kM7mG26981aihBnQvityp4oip/ybLMh CWXP2YJbc6zEN3TRDhxGqxzw4+Hcl+ey6oHzFjlAClUqSEHfaB5wZNboue73V+10PAUH i/aSq5NAxKjwOj5/jyU6LNFW3WadKad3K18fSnXrxbnB9E2KtVNGwjUX4/2c1fF2k8BA eZpKM9Gs6VP4UUVEvAY6dfHKG5/4lVmAF5TVOzoFlDtl7VHF3VJYaeXDFMRdoS+OnPUR KYNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=3F8TrM66; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=fEOm6aYQ; 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 di14-20020a170906730e00b0078d85177210si9793467ejc.756.2022.10.31.12.41.59; Mon, 31 Oct 2022 12:42:24 -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-2022-7-12 header.b=3F8TrM66; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=fEOm6aYQ; 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 S230133AbiJaThK (ORCPT + 99 others); Mon, 31 Oct 2022 15:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbiJaTgy (ORCPT ); Mon, 31 Oct 2022 15:36:54 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E3A413E1F for ; Mon, 31 Oct 2022 12:36:53 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VGx8pO026899; Mon, 31 Oct 2022 19:36:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=wlaWK8/IuhSMqnWWytUFpDjlT4v6bStGWHIlG7FPo7U=; b=3F8TrM66wGCBhWxIiqnYwOb1xcwT0moDus40i3nJr4SGisTFmU8uGQffAww//30QCmeG DyhRtfCBdvxu/z+vhRbm/RPFDUTEvracHSsJBmOVV4XO5FpzcT9w7XNrf60nGmgHxsZW ZjZZf2fJWbqg5l5zXcu9xhGB6sQS2SiEZc+Lrlhkkh03OlDaiSCBp2NcLFShDUF06Ep4 iptqzqfWpvjAmh+rMIaPQF+FOLSxE6NHeNjO+DKJSnYz7yklFNPS2V0BIfuq9Dx9TXna Dgv8VOU6gIpV7iIUhL+QHR1FgNFx24WjUgpRPPwbHcAOaisLt47K8z/fonnuRtR9JoMG uw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kgts14sxg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:36 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29VJLgOH019196; Mon, 31 Oct 2022 19:36:35 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2046.outbound.protection.outlook.com [104.47.74.46]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kgtm9phh9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 31 Oct 2022 19:36:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PohFv556A5IVWUEfRqov6SKNZh2t2IDnNzwyJg1AHvcSs2hM0MisQv1pUpTEd5oHl+ZRS7go+EFHlOpSxvTeAVYAs0ObWYdprqj5nuoPWq2TYfaezIrWJP8szS/wDrTJtSFq7rdjRONAOEVvZSEc17O82KMhgugccgDv4i8STUhuiNbNLyqzno73jGPkhsO91lQenbGNsqVfhM3eV1SKrLaP+i5NRSyq05Vq29NVwm39FfhBupTPScIyk11ZTzqLOZsGOuj8YRqk4MyraKxT7Yrx5ERN7eD+OKAACWpbyYUZp5GQgtuuTO6knoaoEYox6AWocDWHHX7HOa7TB0GS6g== 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=wlaWK8/IuhSMqnWWytUFpDjlT4v6bStGWHIlG7FPo7U=; b=ocQrQSNW0Sk2AZyEJy7DaPVvC5iZ2iKoqWmQpBAIVBp+uBqyuZdPVhXIGDu+LUuivfFKCg1xHG2nOkD1IUpDCBL+VXAAbe24ahZGzSxyE7TaVXQjoz+B2vAqg5S5pTw7inZipb3dk4pVhZX6gtCBuej/xH40Tb0YG+uHPuGJZMOhzOLZqPNDFs+KV6N4pf7eft4lPh0FKWDgCNIFXVY6zlHrfFrPNZj8xEr4TmWCUXn+10ReGBAuxEFODiraERQZn1dp1Y++Rn/zJ1RaXZJlLNNUqiTYmxsc5ZZ8Bfn9Dem64j3cxLSQJZFDjCx9R+BqhS0Maw8qmNEpMfwC5c7iqQ== 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=wlaWK8/IuhSMqnWWytUFpDjlT4v6bStGWHIlG7FPo7U=; b=fEOm6aYQHmPnr4D89CoYwb2uuSFLf3Q7LRLifburMZdwcX7KtKzsIMNApTEk49wYE1XDXpARR4fxePpKbuD2cJYFooWju+mH8oDNWcxTfU+qCk5OVfDDDREGpdGVm59JHCksZq5xPTW/axhHGiY4lyDhbTlwm7f9PBAd/mhzCcA= Received: from CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) by DS7PR10MB5070.namprd10.prod.outlook.com (2603:10b6:5:3a7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Mon, 31 Oct 2022 19:36:33 +0000 Received: from CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7]) by CO1PR10MB4531.namprd10.prod.outlook.com ([fe80::f7b2:af85:fe37:31a7%9]) with mapi id 15.20.5769.021; Mon, 31 Oct 2022 19:36:32 +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 v13 7/7] x86/crash: add x86 crash hotplug support Date: Mon, 31 Oct 2022 15:36:04 -0400 Message-Id: <20221031193604.28779-8-eric.devolder@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221031193604.28779-1-eric.devolder@oracle.com> References: <20221031193604.28779-1-eric.devolder@oracle.com> X-ClientProxiedBy: SN1PR12CA0108.namprd12.prod.outlook.com (2603:10b6:802:21::43) To CO1PR10MB4531.namprd10.prod.outlook.com (2603:10b6:303:6c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR10MB4531:EE_|DS7PR10MB5070:EE_ X-MS-Office365-Filtering-Correlation-Id: 3388f6bf-4288-471e-43c3-08dabb7736ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U913ytYhkRhBaQYilV3ZVviUNgi7h/ej74g9xMBxg7PGLTokI7jPo8RnjNUmtO0FO1THbTBnbFgDJ4XzefyNW210pPpqtpDQoQhGwmcQEmfv8Pqu7SmpJLzODr58Qhqyp1ZtVl7GmipF0PSctFrU7a5ns0uxnXb7s/Nrf3DjL7665wFjXrwbpjxQlGbifJrsa/X6YJT2CrghLixELi4bfhJ+zbpr41ghz87nbvLbaAt7qTVPRBNw4yh7bbOBAmSr6lvO7FZeH+oIEy3jnG5oL2v1juaIyaXDH5IHWjp8OiAAIqQuoBrE2XqbylJdz9QsAGsRH9ax1ZAS8AWmJ/b3SXp7ZV1qTiLoqsTWkyf2NOUGUTCfKCZ5bPOoeh1ZyWqmkLXfdOVFy4Gmc1ct+vw/CLvpFqNchBYpULkDWaUDQgDDSEE9p6O3oBJV993oQcLkxwuZFXuhSMOduZfH2xycyNEBNQX7PaDi3HQCEzGSXGKZEOeRnprjY4oaYAAgsJXgwDiYCeHQmxpZ9WobhxlQFTcADJFBYrZJ3j0e1R488v2gKVSAnXomv523c3Ej12rfBFPr/ioT8Jifj07vX8SXm6mWmhNnIRo/JINiq5VqeRXAHEuy85SQxyhxZv9Lcc0yPxPTsFuIxfuIgrnrH39VtOKyIXBko762QWDCNfy4jw/LgmjP1timSTFO8V++lURuns9VFAIGSCt56zrJE39Ijw== 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:(13230022)(366004)(396003)(136003)(346002)(39860400002)(376002)(451199015)(36756003)(86362001)(38100700002)(83380400001)(2906002)(6512007)(186003)(26005)(478600001)(107886003)(6666004)(2616005)(6506007)(1076003)(6486002)(316002)(7416002)(66556008)(66476007)(8676002)(5660300002)(41300700001)(4326008)(66946007)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XZg9j3FVGnqF2FiXHpCKvkeGHEYYt9axDC3W3fSuHGy2wrEjOAFAik66VEs490saLs7CA9EKJMLCYhR1KnKrN6cX5QD13nAICYF4aVMbNtwLm3JSZe4xAdKcde5r4o5OgOO/WUiNZC1NhpmCk+eb9ih4cVJ2d3Q/kjWE7H0TdbVgDfUZ7HOmnSuvLyjSbfm7QiTZyo0FI1JThofxPO7W5a/Cozn1pLwihNIAB/+aZyqeOwtNvNlZ4ffjOp6B6zVVGAcxDtg1LJnDKAKr1EeFZB4ubtTZrchb1igIqSKCp3Uejn22sNWSKydty6nboPu5Tg7Mbpm8TUVXvUW9cDYNU4mAnqakteOBvy6tcgrvtOa6bvVVXN68rG1lvwkQczPkdnkKcrKTgF8H9LBFnwbet5syVxOgTSSpNFMCdO82sYxHcTgv3GDpTuY7w5EWikvS82AH/pSq4v+KPd+woVtmZdzXRuR91WL3OEweITEDXd74sUGG1A3+Vs+XhiPM6awGdXeBJOPyAYK5ek7DqupK4HqXfZU4on/w6dcK+qUIWRtlcBxxnMh6XMHNH7jI0wdl49WhO+nRSWdpG3fb9NT1hw3Mlo3i1cbbpSbqkJg6c6ashuZJXiFefxB1p6mXhLRYusc20P1Nil2YsuseCTSeLNRVm6sWTkk0GPXTwouIswaThLECNNiLMgcDi3nteWj8IuT9TWJmhUyTr6GAtzgd1tS6kMUhutf3AY/+5jKytv6j8gx4GOtrftcrRBWTr97KeYYvF4uLnkCwNbLO4vF+YVHC9wb/ExHYtSjzoyV9U2Rr1L4lSL98MNB3vOoJzklxbz+0klfLGxfF0AoOBalhatlu1k68HRRRD9XyCGz2rKTY1D4UT1ZuDJSwv6QFd9shK2h4dC8QmSDvG/1/A1pVvgs0r9BCjKsD8LufPydP2MdK6T6yUEQkHSaQJQJUsFQXG72djASPkmAPFww21DvtjCmuAQZaabngHxykOq7Bso54dHHoOEpgo7ioS2Nsvwxs1G1baBUGDWs0Bv+ahSuwdQHFwzDron+Bs36OrhPVpgwWSSNznLyewPvCmdWdIAR3GeA9qBJ/vWdcsIO/DH/o4Y9BlCZdPs6CKiwNPL5schLnZAEga7qfU8uQzhErpYzdS+TPnCC2nnNsmOXFXmZQWUifrBCbmLF9fPIs448qTqdiAOUGjOdgaOfYkIWDJmSRHl0ek2KBkTNNjR4XxFlmkNllfDQp+ShLLslmV3jJSxZp5cLQ1O7knWu2IOmCK4xvypdiaTXcRJL+4b6nQc7m5PQTNieHqA0U4bZktwDpALCE+fLYCeF8TLG2vMMXG5I321QtCGBc9Kx9ghAqIX1H4u8LJWhtoy19WGj9UJ6jU5wIwiXjDqsQs6SnM5VSiLmt6e7NOFsKVbvEfifPi8Z1HYRuGOugQCauSudatggUSVz1a3IitfJ7e0w0M5C5uLfu6JRRUwuWPDfY1xkdO3Hun2IPmhx04ol3hvac95+5pRMBfhlR5tjgy2PbR1Gs8kXtpI4hR8q0nEl+RUfiNCji+l4ojRP4WFSdXKLscR15ptatfWNDD8ulpsRBN3Zh+kDmN4LbI5HJ9mxi9g+DKcNvzw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3388f6bf-4288-471e-43c3-08dabb7736ab X-MS-Exchange-CrossTenant-AuthSource: CO1PR10MB4531.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2022 19:36:32.6999 (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: tLmKs2gN6t921bvV0HEpcrnajtbR/Dte/Pos9MoeY9dIydtf09RsgbhIUWoWCNDQ6IbVCOTdee+fOnk2O+9PZnu5o79V6pO4jenYqR1wxZM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5070 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_20,2022-10-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 bulkscore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2210310121 X-Proofpoint-GUID: xALIcaWDmzoExBYW6t6GhN0fvztX8hTl X-Proofpoint-ORIG-GUID: xALIcaWDmzoExBYW6t6GhN0fvztX8hTl 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 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?1748233454111661308?= X-GMAIL-MSGID: =?utf-8?q?1748233454111661308?= When CPU or memory is hot un/plugged, the crash elfcorehdr, which describes the CPUs and memory in the system, must also be updated. A new elfcorehdr is generated from the available CPUs and memory into a buffer, and then installed over the top of the existing elfcorehdr. The segment containing the elfcorehdr is identified at run time in crash_core:handle_hotplug_event(), which works for both the kexec_load() and kexec_file_load() syscalls. 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. Signed-off-by: Eric DeVolder --- arch/x86/include/asm/kexec.h | 14 +++++ arch/x86/kernel/crash.c | 108 ++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index a3760ca796aa..d72d347bd1d3 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h @@ -212,6 +212,20 @@ typedef void crash_vmclear_fn(void); extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss; extern void kdump_nmi_shootdown_cpus(void); +void arch_crash_handle_hotplug_event(struct kimage *image, + unsigned int hp_action); +#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 /* __ASSEMBLY__ */ #endif /* _ASM_X86_KEXEC_H */ diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index 9ceb93c176a6..2687acf28977 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -42,6 +42,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; @@ -394,10 +409,30 @@ int crash_load_segments(struct kimage *image) 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; + + if (IS_ENABLED(CONFIG_HOTPLUG_CPU) || IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) { + /* Ensure elfcorehdr segment large enough for hotplug changes */ + unsigned long pnum = 2; /* VMCOREINFO and kernel_map */ + + if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) + pnum += CONFIG_NR_CPUS_DEFAULT; + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) + pnum += CRASH_MAX_MEMORY_RANGES; + if (pnum < (unsigned long)PN_XNUM) { + kbuf.memsz = pnum * sizeof(Elf64_Phdr); + kbuf.memsz += sizeof(Elf64_Ehdr); + image->elfcorehdr_index = image->nr_segments; + image->elfcorehdr_index_valid = true; + /* 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); + } + } - kbuf.memsz = kbuf.bufsz; kbuf.buf_align = ELF_CORE_HEADER_ALIGN; kbuf.mem = KEXEC_BUF_MEM_UNKNOWN; ret = kexec_add_buffer(&kbuf); @@ -412,3 +447,70 @@ int crash_load_segments(struct kimage *image) return ret; } #endif /* CONFIG_KEXEC_FILE */ + +#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_MEMORY_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 + * @hp_action: the hot un/plug action being handled + * + * To accurately reflect hot un/plug changes, 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, + unsigned int hp_action) +{ + unsigned long mem, memsz; + unsigned long elfsz = 0; + void *elfbuf = NULL; + void *ptr; + + /* + * Create the new elfcorehdr reflecting the changes to CPU and/or + * memory resources. + */ + if (prepare_elf_headers(image, &elfbuf, &elfsz)) { + 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. + */ + ptr = arch_map_crash_pages(mem, memsz); + if (ptr) { + /* + * Temporarily invalidate the crash image while the + * elfcorehdr is updated. + */ + xchg(&kexec_crash_image, NULL); + memcpy_flushcache(ptr, elfbuf, elfsz); + xchg(&kexec_crash_image, image); + arch_unmap_crash_pages(ptr); + pr_debug("updated elfcorehdr\n"); + } else { + pr_err("updating elfcorehdr failed\n"); + } + +out: + if (elfbuf) + vfree(elfbuf); +} +#endif