From nobody Thu Nov 14 22:16:11 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+72707+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+72707+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 1615530444465992.7168280249679; Thu, 11 Mar 2021 22:27:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7SW0YY1788612xr6QmqaJkTt; Thu, 11 Mar 2021 22:27:24 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web12.4953.1615530437937203933 for ; Thu, 11 Mar 2021 22:27:18 -0800 X-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12C6ACEv178525; Fri, 12 Mar 2021 06:27:15 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 37415rgyek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:15 +0000 X-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 12C6PApo055289; Fri, 12 Mar 2021 06:27:14 GMT X-Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2049.outbound.protection.outlook.com [104.47.56.49]) by userp3020.oracle.com with ESMTP id 374kgw3bqs-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MjtXmxi9FWne2I0JgflTvPbccquw7LTgdOSoMpXptTlpEgs63c+UWbyWXem8EJyryLWecMHm9lRkj5xnAfM+ramU2OgeIP9PeiFa8+FIMmEjZQ4lekxG5hH7i8a9bIAMdOVbUxP+c9hN19O8KFCXHnERvEmdVs8fsRI+3BLHgjfsqgGnABWtBxHQuwmJRsjPglRWSXfOS7QhmmxzG62gnNh3kUVT1tZQz2OrppDIFLFKmyVlWeNHh8pXM6o5MNBjX75GEimCI2tIq9wF+FBWvwl4GIjbgntb3uH1UFzLh0gcKsInYsbyrD4dwi1XzQLuBzKcI9UYW22kxHmEXc/PrA== 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=403GKhoEcxX7WidGJ/pPPepIXdVa3BzVG5cEbqee9Yw=; b=SOLtRiOWdfjGz1BOcDJvcQRBgIe1uoaaYmyfr2SAyAMFXLDNcVhimwM2BE5Zlyu4TnWLJN2LXQFaHLbxLxxxmERAgtOdYW3ChGvgDs9r8jigI7og9Y7kR2QYwUzk6FgOrtiMCMjzArKvtJxQxjgKSuOHidIWlgloYgkuwv56rMzMgwc3E5nUYnZfe1BeeSnKyMBi1S4unMjk6jx6Fv5MR2qIyEwr63QZTIF3A+Ssa9KGq4NDmWrtIwCoV08Ya7OUSgYtRqup/7W6AfaX4mq1rdod9s7W6ukOWgB4v3OBzkCZJf4sl3Fw8sNlTOqCtSJDb9CjiPhw6f54u/Xnjjhhrw== 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 BYAPR10MB3191.namprd10.prod.outlook.com (2603:10b6:a03:14f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.24; Fri, 12 Mar 2021 06:27:12 +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.3912.030; Fri, 12 Mar 2021 06:27:12 +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 v9 06/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Date: Thu, 11 Mar 2021 22:26:52 -0800 Message-Id: <20210312062656.2477515-7-ankur.a.arora@oracle.com> In-Reply-To: <20210312062656.2477515-1-ankur.a.arora@oracle.com> References: <20210312062656.2477515-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.12] X-ClientProxiedBy: MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) 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.12) by MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 06:27:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4a56906-7594-4d06-55d1-08d8e51fdf46 X-MS-TrafficTypeDiagnostic: BYAPR10MB3191: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange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zp?= =?us-ascii?Q?2sT39TsJ54e4IjJg8YGrzDabqNA5taEJKimiKiKxO9J55REVXtNaK7odVmAW?= =?us-ascii?Q?yEznxOhDC7VW7FC7wGTcFUWCaet3/NjJLuw77n+gyUDje7wF5KW7goFOBnPD?= =?us-ascii?Q?+m9MjGMtlXJameeka3SgF9y0?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4a56906-7594-4d06-55d1-08d8e51fdf46 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 06:27:12.7751 (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: 11zJSz0bRH14k3MnS5zHtotRgcT0s+CVz/ighLZZpuVhMO7EqtJV+vlS1/s/K6Eo/lXEjC5kE3Pmr2JDlrw31FQUfwZIb4+Uu+FGlskm6eg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3191 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: GsbMvyQMCyVfmUiPnZUcOXF3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615530444; bh=+VbRqnfbWTfJcrX7qjWZ/PBRoUl9Ng3wn9C2FSqwOuA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=oVNBW2b+yX+uAL3Zo292UC42eOdO2v7HJFZEAdm+yxUxhgE7yCqIXFLbkE+XIhWyyOH 8Vg3rHWahkfZAXpM1fbckPQi3/S3b9XHt76iuuX9bfiS//NhR2Z0q/GgXrEdLdZDGmjkc gmtflyN/UtW3gEQBhrrlV42cuTKTxpdfNU4= 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 Reviewed-by: Laszlo Ersek --- Notes: Addresses the following comments from v8: =20 (1) Remove line before the "if (MaxNumberofCpus =3D=3D 1)" check. (3) Fixup the space around "||". (2,6) Simplify the three SafeInt multiplication into the ones suggested by Laszlo. (4) Get rid of the mixed sizeof(mCpuHotEjectData->QemuSelectorMap[0]) a= nd sizeof(UINT64) in favour of UINT64 everywhere. I was planning to use the first, but describing the alignment needed is easier in terms o= f the second. Also, as Laszlo's comments on v8-patch-9 mention, we don't really n= eed this alignment for correctness reasons. This patch retains it, so we don't pay access penalty for unaligned access. (5) Change alignment from UINT64 to UINT64-1. (7) Use the more idiomatic ALIGN_POINTER instead of ALIGN_VALUE. (8) RETURN_ERROR -> ASSERT_RETURN_ERROR. .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 4 ++ .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 77 ++++++++++++++++++= ++++ 2 files changed, 81 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..5c025bc717c3 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,77 @@ 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 Size; + UINT32 Idx; + UINT32 MaxNumberOfCpus; + RETURN_STATUS PcdStatus; + + MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + if (MaxNumberOfCpus =3D=3D 1) { + return; + } + + // + // We allocate CPU_HOT_EJECT_DATA and CPU_HOT_EJECT_DATA->QemuSelectorMa= p[] + // in a single allocation, and explicitly align the QemuSelectorMap[] (w= hich + // is a UINT64 array) at its natural boundary. + // Accordingly, allocate: + // sizeof(*mCpuHotEjectData) + (MaxNumberOfCpus * sizeof(UINT64)) + // and, add sizeof(UINT64) - 1 to use as padding if needed. + // + + if (RETURN_ERROR (SafeUintnMult (MaxNumberOfCpus, sizeof (UINT64), &Size= )) || + RETURN_ERROR (SafeUintnAdd (Size, sizeof (*mCpuHotEjectData), &Size)= ) || + RETURN_ERROR (SafeUintnAdd (Size, sizeof (UINT64) - 1, &Size))) { + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_EJECT_DATA\n", __FUNCTION__)= ); + goto Fatal; + } + + mCpuHotEjectData =3D AllocatePool (Size); + if (mCpuHotEjectData =3D=3D NULL) { + ASSERT (mCpuHotEjectData !=3D NULL); + goto Fatal; + } + + mCpuHotEjectData->Handler =3D NULL; + mCpuHotEjectData->ArrayLength =3D MaxNumberOfCpus; + + mCpuHotEjectData->QemuSelectorMap =3D ALIGN_POINTER (mCpuHotEjectData + = 1, + 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); + ASSERT_RETURN_ERROR (PcdStatus); + + 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 +262,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 (#72707): https://edk2.groups.io/g/devel/message/72707 Mute This Topic: https://groups.io/mt/81273607/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-