From nobody Thu Nov 14 16:53:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+71917+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+71917+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=oracle.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1613978392375815.4657935344097; Sun, 21 Feb 2021 23:19:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kkCFYY1788612xLduJPrilep; Sun, 21 Feb 2021 23:19:51 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web10.31720.1613978391470280373 for ; Sun, 21 Feb 2021 23:19:51 -0800 X-Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11M7F30k132647; Mon, 22 Feb 2021 07:19:48 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 36ttcm2kec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Feb 2021 07:19:48 +0000 X-Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11M7GSL7067574; Mon, 22 Feb 2021 07:19:47 GMT X-Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by aserp3020.oracle.com with ESMTP id 36ucawnxq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Feb 2021 07:19:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQMr5Iwkgn7uaiiq73+3cUTQFXUlCGcYP2XfaVLsLwnPA0Z9L1qDjVExbFzmQQ/ofl8PS+GvvjcIMKhmNI5Q3KC4LEDmKcnnNU0OUOR5eV1NZhUjTrkXrtTcRE9DQBb5kBvtnkId57egs6HFCmAMVPzsZEcwlI+jmQwBGO08rXz7yLQbSRtHhucwvkinPYk/ZMTIVOOyO2noCW6g866gZYrGt+1spG2C4ChKABNW6W6KGxGLlRoryE/eOrqZ53TgSOsjsxl5ssR3X+8bademITTNiWiCuFKH0af6XTl8tsgB0pDMygtjoJ+OZL45w5xkfvVYqW2vVbH3D+TOILAcoQ== 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-SenderADCheck; bh=ZSmLXnkGnrGbL4Gfu1w8+AqfVIYwQx2NR1XNbeKZBdM=; b=OEPvNRKgo4u6ts7I3So179BpSxr0+NnmOuWo1b1oGch//jf39c3ByUfGlnHxBPR56+FOdAf5+7Gv282y84Hji3kSWEHbxKBXrAqEA9IgSO7hfkOIifKBrgYuJN0vSgXQWXKms+0/DezBW/ZwJmM5oNMLOpcTS6bx2d4jZZB9WMY7rczOHPmM1YuFQDRbZmkHgrElsrpoFAdVz6THFcOCXWpPqXLv7M68Q1nNouXFr6ZqTljYAqdmZONlJqmUouYkKZsJir2M05KILyw0mNINb5l7KeRfunF3sQg7MOlOHl2whlb62RiI3BQbiYArZwYkQ+7e6mMxbRnyAAEMn2SkIg== 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 X-Received: from SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) by BY5PR10MB3922.namprd10.prod.outlook.com (2603:10b6:a03:1fd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.32; Mon, 22 Feb 2021 07:19:45 +0000 X-Received: from SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16]) by SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16%6]) with mapi id 15.20.3868.033; Mon, 22 Feb 2021 07:19:45 +0000 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Aaron Young Subject: [edk2-devel] [PATCH v8 06/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Date: Sun, 21 Feb 2021 23:19:24 -0800 Message-Id: <20210222071928.1401820-7-ankur.a.arora@oracle.com> In-Reply-To: <20210222071928.1401820-1-ankur.a.arora@oracle.com> References: <20210222071928.1401820-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.11] X-ClientProxiedBy: MWHPR17CA0065.namprd17.prod.outlook.com (2603:10b6:300:93::27) To SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from prion.us.oracle.com (148.87.23.11) by MWHPR17CA0065.namprd17.prod.outlook.com (2603:10b6:300:93::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.27 via Frontend Transport; Mon, 22 Feb 2021 07:19:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 64b7c523-28d4-4054-c8b3-08d8d7023abc X-MS-TrafficTypeDiagnostic: BY5PR10MB3922: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:124; X-MS-Exchange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7vGApuSNIdi?= =?us-ascii?Q?HcSsFKA9J43TMPzu0bp1mVj3o/tmKZA4Dd2XAm/2RagOIpKtNBQBYz/fpfeO?= =?us-ascii?Q?rOLiJDk08jPkGVyJhEu4ouOzOBI8IqNuFPrffFmFMDThWk4xxsR2RYY5gPPl?= =?us-ascii?Q?NiisrUBEec4xPFqA3xZEC7PL?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64b7c523-28d4-4054-c8b3-08d8d7023abc X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2021 07:19:44.9586 (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: W5RdDylVSly0vo/eE3jap8Fdz2UkwQVtaYZoAct/SkUAy1N3lRKkOOLz1MikJ5QlA8T+YU/PBkjaO6MeZ0ytuUpmfpweuPvX65TTQnCoWc0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB3922 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ankur.a.arora@oracle.com X-Gm-Message-State: MkG3HLbXMrc3SlZqhiSjlBrVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613978391; bh=7zjqutfONjl1U++1sjyTUugni7xdLjUls2U3ssNdQ+E=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=M0iBjXLjkEbdVpK47NBikAoQ4j7ziFM/yFXoMLZ4LpyEtIyKl65AtvFmtjZUEuJG+Jo WGdN1MjgBs3d5FJC7XuRG5OZEA/ibirB1WfG++3JqpP9hvDF1r6xXlQHy6ox2nmTJSsUm 4ub0GslbKF1T8FFGD7piFVSy8NogILTIcNw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Init CPU_HOT_EJECT_DATA, which will be used to share CPU ejection state between SmmCpuFeaturesLib (via PiSmmCpuDxeSmm) and CpuHotPlugSmm. The init happens via SmmCpuFeaturesSmmRelocationComplete(), and so it will run as part of the PiSmmCpuDxeSmm entry point function, PiCpuSmmEntry(). Once inited, CPU_HOT_EJECT_DATA is exposed via PcdCpuHotEjectDataAddress. The CPU hot-eject handler (CPU_HOT_EJECT_DATA->Handler) is setup when there is an ejection request via CpuHotplugSmm. Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Igor Mammedov Cc: Boris Ostrovsky Cc: Aaron Young Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3132 Signed-off-by: Ankur Arora --- Notes: Addresses the following review comments: (1) Detail in commit message about context in which CPU_HOT_EJECT_DATA is inited. (2) Add in sorted order MemoryAllocationLib in LibraryClasses (3) Sort added includes in SmmCpuFeaturesLib.c (4a-4b) Fixup linkage directives for mCpuHotEjectData. (5) s/CpuHotEjectData/mCpuHotEjectData/ (6,10a,10b) Remove dependence on PcdCpuHotPlugSupport (7) Make the tense structure consistent in block comment for InitCpuHotEject(). (8) s/SmmCpuFeaturesSmmInitHotEject/InitCpuHotEject/ (9) s/mMaxNumberOfCpus/MaxNumberOfCpus/ (11) Remove a bunch of obvious comments. (14a,14b,14c) Use SafeUint functions and rework the allocation logic so we can just use a single allocation. (12) Remove the AllocatePool() cast. (13) Use a CpuDeadLoop() in case of failure; albeit via a goto, not inline. (15) Initialize the mCpuHotEjectData->QemuSelectorMap locally. (16) Fix indentation in PcdSet64S. (17) Change the cast in PcdSet64S() to UINTN. (18) Use RETURN_STATUS instead of EFI_STATUS. (19,20) Move the Handler logic in SmmCpuFeaturesRendezvousExit() into into a separate patch. .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 4 + .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 92 ++++++++++++++++++= ++++ 2 files changed, 96 insertions(+) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/Ovmf= Pkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index 97a10afb6e27..8a426a4c10fb 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -30,9 +30,13 @@ [LibraryClasses] BaseMemoryLib DebugLib MemEncryptSevLib + MemoryAllocationLib PcdLib + SafeIntLib SmmServicesTableLib UefiBootServicesTableLib =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 7ef7ed98342e..adbfc90ad46e 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -11,10 +11,13 @@ #include #include #include +#include #include +#include #include #include #include +#include #include #include #include @@ -171,6 +174,92 @@ SmmCpuFeaturesHookReturnFromSmm ( return OriginalInstructionPointer; } =20 +STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData =3D NULL; + +/** + Initialize mCpuHotEjectData if PcdCpuMaxLogicalProcessorNumber > 1. + + Also setup the corresponding PcdCpuHotEjectDataAddress. +**/ +STATIC +VOID +InitCpuHotEjectData ( + VOID + ) +{ + UINTN ArrayLen; + UINTN BaseLen; + UINTN TotalLen; + UINT32 Idx; + UINT32 MaxNumberOfCpus; + RETURN_STATUS PcdStatus; + + MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + + if (MaxNumberOfCpus =3D=3D 1) { + return; + } + + // + // We want the following lay out for CPU_HOT_EJECT_DATA: + // UINTN alignment: CPU_HOT_EJECT_DATA + // --- padding if needed --- + // UINT64 alignment: CPU_HOT_EJECT_DATA->QemuSelectorMap[] + // + // Accordingly, we allocate: + // sizeof(*mCpuHotEjectData) + (MaxNumberOfCpus * + // sizeof(mCpuHotEjectData->QemuSelectorMap[0])). + // Add sizeof(UINT64) to use as padding if needed. + // + + if (RETURN_ERROR (SafeUintnMult (sizeof (*mCpuHotEjectData), 1, &BaseLen= )) || + RETURN_ERROR (SafeUintnMult ( + sizeof (mCpuHotEjectData->QemuSelectorMap[0]), + MaxNumberOfCpus, &ArrayLen)) || + RETURN_ERROR (SafeUintnAdd (BaseLen, ArrayLen, &TotalLen))|| + RETURN_ERROR (SafeUintnAdd (TotalLen, sizeof (UINT64), &TotalLen))) { + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_EJECT_DATA\n", __FUNCTION__)= ); + goto Fatal; + } + + mCpuHotEjectData =3D AllocatePool (TotalLen); + if (mCpuHotEjectData =3D=3D NULL) { + ASSERT (mCpuHotEjectData !=3D NULL); + goto Fatal; + } + + mCpuHotEjectData->Handler =3D NULL; + mCpuHotEjectData->ArrayLength =3D MaxNumberOfCpus; + + mCpuHotEjectData->QemuSelectorMap =3D (void *)mCpuHotEjectData + + sizeof (*mCpuHotEjectData); + mCpuHotEjectData->QemuSelectorMap =3D + (void *)ALIGN_VALUE ((UINTN)mCpuHotEjectData->QemuSelectorMap, + sizeof (UINT64)); + // + // We use mCpuHotEjectData->QemuSelectorMap to map + // ProcessorNum -> QemuSelector. Initialize to invalid values. + // + for (Idx =3D 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) { + mCpuHotEjectData->QemuSelectorMap[Idx] =3D CPU_EJECT_QEMU_SELECTOR_INV= ALID; + } + + // + // Expose address of CPU Hot eject Data structure + // + PcdStatus =3D PcdSet64S (PcdCpuHotEjectDataAddress, + (UINTN)(VOID *)mCpuHotEjectData); + if (RETURN_ERROR (PcdStatus)) { + ASSERT_EFI_ERROR (PcdStatus); + goto Fatal; + } + + return; + +Fatal: + CpuDeadLoop (); +} + /** Hook point in normal execution mode that allows the one CPU that was ele= cted as monarch during System Management Mode initialization to perform addit= ional @@ -188,6 +277,9 @@ SmmCpuFeaturesSmmRelocationComplete ( UINTN MapPagesBase; UINTN MapPagesCount; =20 + + InitCpuHotEjectData (); + if (!MemEncryptSevIsEnabled ()) { return; } --=20 2.9.3 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#71917): https://edk2.groups.io/g/devel/message/71917 Mute This Topic: https://groups.io/mt/80819861/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-