From nobody Thu Nov 14 17:06:10 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+70873+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+70873+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 1611882075748595.891435363371; Thu, 28 Jan 2021 17:01:15 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SOvZYY1788612xrhgn86rUGD; Thu, 28 Jan 2021 17:01:15 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web09.3201.1611882069925198477 for ; Thu, 28 Jan 2021 17:01:10 -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 10T0dwYl041203; Fri, 29 Jan 2021 01:01:07 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 368b7r6v3j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:01:06 +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 10T0eFsm081629; Fri, 29 Jan 2021 01:01:06 GMT X-Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by userp3030.oracle.com with ESMTP id 368wr13gd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:01:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AF3/6VG7E43wTCRLT5SV8aAndBifGBIlTfBAjdgaxCgN0YvtcaqsElKel81y7GENRPtUXiTKUEdOSIp4Kd+HRjTLbw0/7SW3o4Y7UFmS9unUoyWa0hlXbFnCCh7xux+6osmllLIi2VwvOrvUJzm2/W0A/amNyFmcpvpcsb1Pb1Pv+qjBMKQ7KVLFeNXBxtPa6dEOWsnf2rjAy/bz4rawT9sqnX2Ury/k4zhNU2omPWNNioH4iJzEGBj1LhCEv0JtJ+HW3xvQcSVUrIx+mOvIVL2ff9CTO4OpfCT7Qya+GVpAtjAf8g6C6k3b+7wGYfDN/r/PqhU+ahwppzUZvhQ/Ng== 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=Cas9E3Jz2zOrncuZdVvfzFahgTeS8mCUq401jOp9ndU=; b=mrHqEscHOPKBLMeEE8qMenoUbVbH9sr0y/eCPUt3WJ6B8YffZlsCaUxf3W1x4wnGJUT+Fgbt8OuJepiKjFzoNqQIct+78hDNQwCnp5VqHsPz7/ODyCmbe4FPt4n6pVy/qBq59rboPg2t4iiUMuzVuuPx4X4hvXFky5WA4iMJrMTD9kRVBfgZ1o2yJLr46KGrYSXyLr0If1vJUZ4rhlWkatSrTYszUZuIRDbYFrr0pbPKmF2bYeiYYDm99nDoxzk48nvV+hCAUlMI8Qm4ee5SdphHnQtVAY2e0AuIT3nV7CdSSP7T2NBfMiw/OC4IOWmEp6wE1+sADjdhBnTHUmVVHA== 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 CY4PR1001MB2246.namprd10.prod.outlook.com (2603:10b6:910:41::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.16; Fri, 29 Jan 2021 01:00:55 +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.3805.019; Fri, 29 Jan 2021 01:00:55 +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 v6 7/9] OvmfPkg/CpuHotplugSmm: add CpuEject() Date: Thu, 28 Jan 2021 16:59:48 -0800 Message-Id: <20210129005950.467638-8-ankur.a.arora@oracle.com> In-Reply-To: <20210129005950.467638-1-ankur.a.arora@oracle.com> References: <20210129005950.467638-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.8] X-ClientProxiedBy: MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from prion.us.oracle.com (148.87.23.8) by MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 01:00:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbc69340-ae6a-4d3d-5758-08d8c3f13809 X-MS-TrafficTypeDiagnostic: CY4PR1001MB2246: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderAD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wm236GgtMyr0l6JlmOhigbmMqK6ycTs8lb?= =?us-ascii?Q?UUlPuuopw+ECJGyazfNre9hxsnylOZMq2zn8h6E6+vfECiwunyVtIeP9eZ2Z?= =?us-ascii?Q?wZApIA/OPr8jGWHWDt7T7e7581AoU+kjLCPH3ON0o2wwWf4mNoY/LyFcRVBw?= =?us-ascii?Q?85Fme60SK2aKVv3dA0V0QIKQwtgUd/wiigzkG1fPsSSRv8eGeMILrpWmkU5i?= =?us-ascii?Q?bqXEr0AbpDYi1xtWo+LbAZ2sAJ2uP2gL1KsL7WZpblRi5CCEjDjjG40Egtzc?= =?us-ascii?Q?FcbiTJjCwVyg7gw1hjAZU5IHSYOuVN02tfKFQWPzCKoJDMuBJZqU2uThKqYv?= =?us-ascii?Q?2Jc52MGcWqRDX0Yjpt/NtcweP+2qujqO7rrfl3Nn2bHgnUkfCtHB4mX64GbM?= =?us-ascii?Q?Avvm5xybL8X2EBbPt4O8/zDLyf0Vg+Db7QDuJZVhq9vVz7fMsPAOlrIw5Rq+?= =?us-ascii?Q?ZUZzF0UMuNj58R/p3zA8VVy9/hA1oun49raCAjYcRH/Xvll5Zs6hHKkx29gv?= =?us-ascii?Q?AZAX+A+P2VOWg08rBcHZ9EemVMqMdjHhaaD5ZbzLm8EUofC6nbZPOe5tm7QX?= =?us-ascii?Q?JwHVysrgiyc8N1MLyfuW5aUpdaZCoB2TuXmuV6s+XuXKNlQHNKG49gBrDuG2?= =?us-ascii?Q?D67ab5a49iVFXN9T0ZXs/xLr1gOVZQ2WfzmBd33Qi4M/27Yxqjx2FT9QMixU?= =?us-ascii?Q?1OOzjyoQlHw3dQNojiS91I95Y9AT7wIY7e/UFHz47Tf333+oO8XyIO0IeI1I?= =?us-ascii?Q?Vw8P24jI?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fbc69340-ae6a-4d3d-5758-08d8c3f13809 X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 01:00:06.9995 (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: fE8T43r/GGwJErxkZdmqc5J5Vb7wW9zkpLUcYW2R81E6d7b4lwaUXZlKzr1N8L+XAtSJszx/xTkO17kvw0F4tTywzB0vqvAJAi5dgPtvO68= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2246 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: vyFyzhQEmzv7GG1PosbNyZ6Jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611882075; bh=9D3utrqATAuzN5nU4mmWM/v4jxSQ+XwMtYmX0Mo9uiA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=aIKZAt11mIvnDhzZpP194X8dK2e+m4/QLfx+fbshC+FIyuBFIilRzJfoKvQpXujVzOf wacjwKzy1qAnyVYOJCTR38SyMelnV8HCzTewqLuTyI9wxav5MwfZVHxM9k6IKUYyR0Xvv gjnisdKSp1xjT3IbF5bCKbX44MTcWU1GLqw= 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 | 109 +++++++++++++++++++++++++++++++++= ++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 70d69f6ed65b..526f51faf070 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. @@ -188,11 +190,53 @@ RevokeNewSlot: } =20 /** + CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit(), + on each CPU at exit from SMM. + + If, the executing CPU is not being ejected, nothing to be done. + 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 (); +} + +/** Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). =20 For each such CPU, report the CPU to PiSmmCpuDxeSmm via - EFI_SMM_CPU_SERVICE_PROTOCOL. If the to be hot-unplugged CPU is - unknown, skip it silently. + EFI_SMM_CPU_SERVICE_PROTOCOL and stash the APIC ID for later ejection. + If the to be hot-unplugged CPU is unknown, skip it silently. + + Additonally, if we do stash any APIC IDs, also install a CPU eject handl= er + which would handle the ejection. =20 @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to= be hot-unplugged. @@ -216,9 +260,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 @@ -255,13 +301,41 @@ 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 ejection 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[ProcessorNum], RemoveApicId)); + + Status =3D EFI_INVALID_PARAMETER; + 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 removed this set of APIC IDs from SMM data structures. + // We've removed this set of APIC IDs from SMM data structures and + // have installed an ejection handler if needed. // return EFI_SUCCESS; =20 @@ -458,7 +532,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)); @@ -470,6 +550,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. // @@ -552,6 +635,24 @@ CpuHotplugEntry ( // SmbaseInstallFirstSmiHandler (); =20 + if (mCpuHotEjectData) { + UINT32 Idx; + // + // For CPU ejection we need to map ProcessorNum -> APIC_ID. By the time + // we need the mapping, however, the Processor's APIC ID has already b= een + // removed from SMM data structures. So we will maintain a local map + // in mCpuHotEjectData->ApicIdMap. + // + 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 (#70873): https://edk2.groups.io/g/devel/message/70873 Mute This Topic: https://groups.io/mt/80199926/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-