From nobody Thu Nov 14 17:06:36 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+71834+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+71834+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 1613725513097271.3311554309198; Fri, 19 Feb 2021 01:05:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id v2hbYY1788612xN0TJoObNGE; Fri, 19 Feb 2021 01:05:12 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.6098.1613725506222021084 for ; Fri, 19 Feb 2021 01:05:06 -0800 X-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J953Ot192904; Fri, 19 Feb 2021 09:05:03 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 36p49bgw0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +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 11J8uJSH131491; Fri, 19 Feb 2021 09:05:02 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by aserp3020.oracle.com with ESMTP id 36prp2pa12-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LoPpl1JxwUYyiXjw7vUuxahpb8xXadkR+84ZVMorexZRzKVAqESpGHYN4NCrm6l/Ir91a1OX5VEtDds4RVoy/vPbH7iYg2Q16s7naxhVfS2HLEgWjavEPC9I77bFjdMeP5Do7uLItVAeQ5ExlSN0w0FKMrrTBZG+cet+3qwfC1+84+LzOzwb1srlS7g1IZrhpFuS/uCBOmY3raORmwK0cPN6JL9lW9gBwNzLw0QZ+GfKEDSkwIXzwI4yH7tV6kCn74yVM6zbNd46vIBVWiKYTuEmNf35D2dQNDGo5DCk4Ef10Q2rV5JE+Z2qr+nHOnZBB3BI3EZoCcQjCjY3+JzjcQ== 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=A/xUCOgcmNcc/zW0Jw6q9HRjl5DggN/tPM1s75jwEQ2hpevKCcsN+PYHLiaMTADvxrATfYn7mw1IdM5b2Oe5e8v7bWfSkij+7ZJqyGlubtA/nx+NcgSoYbCHLABT33cmeNZOaiDV6e2+KbQvSxPeUNH7tNaqlx+mjggmcqZPUdqAGBW2nAtCAYG3O450BR1G6tGVHW6950BLiR6oblLu4gsjQxKIzrikqvTjLJkepTacLxuwX6S/FQ/a6OLKm7DthpqZ/kW+qIBKSwnQsbcR0apDRcviIjQxip9qMmGztOLuQYRLMpFmxHVIKiqg9RB54/zxSQ+7iChwxYcAcPYheQ== 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 BYAPR10MB3605.namprd10.prod.outlook.com (2603:10b6:a03:129::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.27; Fri, 19 Feb 2021 09:05:01 +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.029; Fri, 19 Feb 2021 09:05:01 +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 v7 06/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Date: Fri, 19 Feb 2021 01:04:40 -0800 Message-Id: <20210219090444.1332380-7-ankur.a.arora@oracle.com> In-Reply-To: <20210219090444.1332380-1-ankur.a.arora@oracle.com> References: <20210219090444.1332380-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.5] X-ClientProxiedBy: MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) 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.5) by MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.8 via Frontend Transport; Fri, 19 Feb 2021 09:05:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 042783e8-6318-43ec-5989-08d8d4b57029 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:124; X-MS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Q1vw8B?= =?us-ascii?Q?LZqMlTAeUp/XXFWu7SnFXd/jkGbW03RH2wSok3hH3v7ddM08+HexKPlc/YOe?= =?us-ascii?Q?wZtndRI7JA5X9HRZvdxww1/46a0kc0M1AHYfMz0S71jnQf1nn7Tzds9Ev/6I?= =?us-ascii?Q?7UczN9pv4QVYhdAzz+Hz7JyW?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 042783e8-6318-43ec-5989-08d8d4b57029 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2021 09:05:01.0863 (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: zS6VB2xa+6z4HLOeO4DaRy9oB8OLVQDUHE1eZYMkUFdbKfa3NdfK73+UAjRcC9Q6/tAr8j3Y7fnFGtpxLUc91rr3veqOuaHxIBPGpiPKlNM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3605 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: hbOy743koFK0Fy77rHLAfG2Rx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725512; bh=HCVedflQ3aC+AswpxjzcH4y8MlUOM8X/TobxFaJlyrs=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HR9EPikmnuYf2rxwFrvgJGGlKCtjWk3eYFBDEzy7UXKpJbBNFoOkA8Uen9kP5J7A1vs Dg90CXzKg3jK10L8fNtSk+JT+R/MoibG2yfFGSxvWXaHY4IUB50J0i4ZduxpOtpDIQ87K AQ6w1S2j2RYvjS7IJMp/6A8nLFamMhW612c= 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 (#71834): https://edk2.groups.io/g/devel/message/71834 Mute This Topic: https://groups.io/mt/80751398/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-