From nobody Thu Nov 14 16:53:31 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+70766+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+70766+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 1611643510813895.0472119138601; Mon, 25 Jan 2021 22:45:10 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 37kjYY1788612xzXzNM4hhgA; Mon, 25 Jan 2021 22:45:10 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web09.8843.1611643504107837252 for ; Mon, 25 Jan 2021 22:45:04 -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 10Q6XsGM053694; Tue, 26 Jan 2021 06:45:00 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 368b7qrnuk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:00 +0000 X-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10Q6a688097113; Tue, 26 Jan 2021 06:45:00 GMT X-Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by userp3030.oracle.com with ESMTP id 368wqw1qcn-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G3MvQ4KWGEKVIcqiRH8Qffa0H73HkSrerjCkJ4YMrNcocgIsLi8DPBP7uu78IMShSwULSycj3hRAtxVQ8Yp3FXUQYMynLiRxBN/lm6E4avLxtwCZG4H9AUZdj7/OIi9LZJotWdvQ3IzcElyXKrQSsg/cWEyijDANkc35ixgeX1FQb/ggBwAUUNaHjFCpsNMTysBvxO8lh9EnrKbeiLCmbqd3QP+tD6HTI/MSFiBwU7iav9qEoIvoGS3G2uOOkO22hKUQv95fDNT7h9RdVn/Pk5/eO7rECRIz5LuLGlu8n+cwSJxA1L9f4eQD51XOEAzBCt/3tmpmJkg5IFht6I1ZBw== 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=DGWFRrEXVuBMKJZS5HEyR44jBu4frhxHnnWSVDSsWsc=; b=jatxgsc7RLgXdraHuI93MMEWIPTPFCJeKiB/JyXYFYgE7P7/P5/hGzVFXEPOF1IFewqiOJ5zHYhvvUvZc0+ldukwc/KrYFQNNmtxGd8BV4LkSCXgT958ikk/+aQQvFsQSWTA3kqtA/gAlNe6J/d8HvQW293YdE6CklagnaaeYK8Qmsh/7D/4tIZNl5L+5SibbrjqhA7YxazYa2twjGNwD0exkbabbJLj1aJy1ghjjlbm2INE3XINb92MLsk1BrdzJtCbKS3MJn9wc1gs4zT96dGgynBJS+HsgGAH/uvS4YJrqKu+9KkPjQqqPaOFg27f29zfjaY6A3ovy0CtOQDeMw== 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 CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) by CY4PR1001MB2184.namprd10.prod.outlook.com (2603:10b6:910:45::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Tue, 26 Jan 2021 06:44:57 +0000 X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6]) by CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6%6]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 06:44:57 +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 v5 7/9] OvmfPkg/CpuHotplugSmm: add CpuEject() Date: Mon, 25 Jan 2021 22:44:38 -0800 Message-Id: <20210126064440.299596-8-ankur.a.arora@oracle.com> In-Reply-To: <20210126064440.299596-1-ankur.a.arora@oracle.com> References: <20210126064440.299596-1-ankur.a.arora@oracle.com> X-Originating-IP: [70.36.60.91] X-ClientProxiedBy: MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from localhost.localdomain (70.36.60.91) by MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Tue, 26 Jan 2021 06:44:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 48f426e5-9121-4c47-0013-08d8c1c5e3c4 X-MS-TrafficTypeDiagnostic: CY4PR1001MB2184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft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eTcRVfxtXqIw/TjNG?= =?us-ascii?Q?GXfWVH3foJvs9k6paev9BdWfn5K6TazxOuEqCPcLMgvKY4t29eQvN60mFDAC?= =?us-ascii?Q?hgojvprHdEpKP5mbTKG2DB2WhqfSRh8wULsVOis2Ge/qsTzXPLn6Uu0xroqb?= =?us-ascii?Q?uRQAOM/XfGLkmRYvoqLgtNqtd7ZoD+jbTA+aZsfItKfCBXNXWmS8nTrPuZ1+?= =?us-ascii?Q?0ZxxDmNPnLdtiwsS0uTtC9kyfzYNbSNRPMGRkN6zRZTZ92IMk7mDvVCzLuK3?= =?us-ascii?Q?EnGF3bTWcxVM+ujfGI1wkfUX7sB0s/46yoqgA9iMCHSmzOA0jjWWBUkh1fYU?= =?us-ascii?Q?ajsgju++4FFgFWXEZ9D175bF4SCJ/WtbJVA3D2pkJhOENsfMb7ppCWzQ6Yq6?= =?us-ascii?Q?HjC8vG1t8aTchZ3XsrzsOSkXPIgfr15tWZX9zQQwfjCKSUoTmmfLwb5Titlr?= =?us-ascii?Q?g5PjxllSWRRUJzyqAcPe3mqRNsrLdZVlCbiFRJv1nh/eusbvVLS7QU4QarWm?= =?us-ascii?Q?RD3bsK8U5zCSz3Ykh0Tg8QdeadbjD/m+bFGVRa1Na+x6ebh4lcdZw7zgU/Fz?= =?us-ascii?Q?5kC/12yuFo3ee4bWOmFCWkdRXvOw9XwjHA9cchJMRujlktOoRujq2DJkZ31/?= =?us-ascii?Q?CNb3RKNkRf6ZgSxUPdtiH05IJwStIpL3pwBhroMX9GSO2lQz9ofOWK0j9DMD?= =?us-ascii?Q?auibLwBO?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48f426e5-9121-4c47-0013-08d8c1c5e3c4 X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 06:44:55.1144 (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: 8VfexRuORZ7mbjFwsqV5WYFDtn93q8Yz3e0qcT9j44H2cSnyIG7baeQLdcxSFRIADKAkB7ybXRk1+3PZRwjaW5C8hZclttfwsKDUaKGCdtU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2184 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: bMKtuOvhjChkZC3iILZkMg2zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611643510; bh=diICOlP6k/U/ZPhYd4rl7BPX7iGqNQJ7XwRvKfPuwjM=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Gy7WUJLEzzRMU8NlGMqqMfBinaCgKUkWBEoPBSBD1yUBtL8q7bKpnD/WNZSfb64OWjq iLfVhNPH/qdEUbUNHzfkyrXkLIFzFCozzVU+rpx9TkBe2UEiD49ZzIMM5rd3n/l9925Wo 9q+ebBdmqCyIOEpQDovgIXridEiSBSglxV8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add CpuEject(), which handles the CPU ejection, and provides a holding area for said CPUs. It is called via SmmCpuFeaturesRendezvousExit(), at the tail end of the SMI handling. Also UnplugCpus() now stashes APIC IDs of CPUs which need to be ejected in CPU_HOT_EJECT_DATA.ApicIdMap. These are used by CpuEject() to identify such CPUs. 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 --- OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 94 ++++++++++++++++++++++++++++++++++= +++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index d165d6ccea0d..99e6845a12d9 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -14,6 +14,7 @@ #include // gMmst #include // PcdGetBool() #include // SafeUintnSub() +#include // CPU_HOT_EJECT_DATA #include // EFI_MM_CPU_IO_PROTOCOL #include // EFI_SMM_CPU_SERVICE_PROTOC= OL #include // EFI_STATUS @@ -32,11 +33,12 @@ STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo; // STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService; // -// This structure is a communication side-channel between the +// These structures serve as communication side-channels between the // EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider // (i.e., PiSmmCpuDxeSmm). // STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; +STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData; // // SMRAM arrays for fetching the APIC IDs of processors with pending event= s (of // known event types), for the time of just one MMI. @@ -182,6 +184,43 @@ Fatal: } =20 /** + CPU Hot-eject handler function. + + If the executing CPU is not being ejected: NOP. + If the executing CPU is being ejected: wait in a CpuDeadLoop() + until ejected. + + @param[in] ProcessorNum Index of executing CPU. +**/ +VOID +EFIAPI +CpuEject( + IN UINTN ProcessorNum + ) +{ + // + // APIC ID is UINT32, but mCpuHotEjectData->ApicIdMap[] is UINT64 + // so use UINT64 throughout. + // + UINT64 ApicId; + + ApicId =3D mCpuHotEjectData->ApicIdMap[ProcessorNum]; + if (ApicId =3D=3D CPU_EJECT_INVALID) { + return; + } + + // + // CPU(s) being unplugged get here from SmmCpuFeaturesSmiRendezvousExit() + // after having been cleared to exit the SMI by the monarch and thus have + // no SMM processing remaining. + // + // Given that we cannot allow them to escape to the guest, we pen them + // here until the SMM monarch tells the HW to unplug them. + // + CpuDeadLoop (); +} + +/** CPU Hot-unplug MMI handler function. =20 @param[in] UnplugApicIds List of APIC IDs to be unplugged. @@ -203,9 +242,11 @@ UnplugCpus( { EFI_STATUS Status; UINT32 ToUnplugIdx; + UINT32 EjectCount; UINTN ProcessorNum; =20 ToUnplugIdx =3D 0; + EjectCount =3D 0; while (ToUnplugIdx < ToUnplugCount) { APIC_ID RemoveApicId; =20 @@ -242,11 +283,35 @@ UnplugCpus( DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", __FUNCTION__, RemoveApicId, Status)); goto Fatal; + } else { + // + // Stash the APIC IDs so we can do the actual unplug later. + // + if (mCpuHotEjectData->ApicIdMap[ProcessorNum] !=3D CPU_EJECT_INVALID= ) { + // + // Since ProcessorNum and APIC-ID map 1-1, so a valid + // mCpuHotEjectData->ApicIdMap[ProcessorNum] means something + // is horribly wrong. + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %u maps to %llx, cannot map= to " FMT_APIC_ID "\n", + __FUNCTION__, ProcessorNum, mCpuHotEjectData->ApicIdMap[Processo= rNum], RemoveApicId)); + goto Fatal; + } + + mCpuHotEjectData->ApicIdMap[ProcessorNum] =3D (UINT64)RemoveApicId; + EjectCount++; } =20 ToUnplugIdx++; } =20 + if (EjectCount !=3D 0) { + // + // We have processors to be ejected; install the handler. + // + mCpuHotEjectData->Handler =3D CpuEject; + } + // // We've handled this unplug. // @@ -445,7 +510,13 @@ CpuHotplugEntry ( // Our DEPEX on EFI_SMM_CPU_SERVICE_PROTOCOL guarantees that PiSmmCpuDxe= Smm // has pointed PcdCpuHotPlugDataAddress to CPU_HOT_PLUG_DATA in SMRAM. // + // Additionally, CPU Hot-unplug is available only if CPU Hotplug is, so + // the same DEPEX also guarantees that PcdCpuHotEjectDataAddress points + // to CPU_HOT_EJECT_DATA in SMRAM. + // mCpuHotPlugData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress); + mCpuHotEjectData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress); + if (mCpuHotPlugData =3D=3D NULL) { Status =3D EFI_NOT_FOUND; DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Stat= us)); @@ -457,6 +528,9 @@ CpuHotplugEntry ( if (mCpuHotPlugData->ArrayLength =3D=3D 1) { return EFI_UNSUPPORTED; } + ASSERT (mCpuHotEjectData && + (mCpuHotPlugData->ArrayLength =3D=3D mCpuHotEjectData->ArrayLeng= th)); + // // Allocate the data structures that depend on the possible CPU count. // @@ -539,6 +613,24 @@ CpuHotplugEntry ( // SmbaseInstallFirstSmiHandler (); =20 + if (mCpuHotEjectData) { + UINT32 Idx; + // + // For CPU ejection we need to map ProcessorNum -> APIC_ID. By the time + // we do that, however, the Processor's APIC ID has already been remov= ed + // from SMM data structures. So we will use mCpuHotEjectData->ApicIdMap + // to map from ProcessorNum -> APIC_ID. + // + for (Idx =3D 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) { + mCpuHotEjectData->ApicIdMap[Idx] =3D CPU_EJECT_INVALID; + } + + // + // Wait to init the handler until an ejection is warranted + // + mCpuHotEjectData->Handler =3D NULL; + } + return EFI_SUCCESS; =20 ReleasePostSmmPen: --=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 (#70766): https://edk2.groups.io/g/devel/message/70766 Mute This Topic: https://groups.io/mt/80125314/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-