From nobody Thu Nov 14 16:58:06 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+70483+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+70483+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610951713; cv=none; d=zohomail.com; s=zohoarc; b=dxVmziILwjdMKordecJeh96fEBBfJPFOwdC4eYVf765FLtO3BQIHH5DE3ZT1nT0Ecy7lZRvmau+7mekiwYV39W8Jjgoozjba8OCsyue5ZCzm2mXTneTfO9gGSdJuZ/tk3L67xoSImK8kASWpcrtezFPy7pKBjPX49X52n/f3Zfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610951713; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=WYGvggHSWxw10BL3M1nN3wFazQh2iWsUD20+rbGn2pg=; b=VcagZIWFMKOR+rDn7h9Svl+sqL/KDvRQF8nzGiiBlVscVduU8VQeTFnToYPSosFoiZgPYXgnIthKaQsiPuMYKlwBx3SDMb62BzUzOtfS98CCh6PBbeC6mu8tBkFqj/a5EoZGLzrfmWWB49n9tnpV38PrHy+jpc5sBp5dW38CF/0= ARC-Authentication-Results: i=1; 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+70483+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610951713885487.0488666760249; Sun, 17 Jan 2021 22:35:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id RO74YY1788612x48pQFsyMM3; Sun, 17 Jan 2021 22:35:13 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web08.30320.1610951712361140290 for ; Sun, 17 Jan 2021 22:35:12 -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 10I6XPDb007140; Mon, 18 Jan 2021 06:35:09 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 363xyhk085-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:35:09 +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 10I6Upos031699; Mon, 18 Jan 2021 06:35:09 GMT X-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 3649wpejpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:35:09 +0000 X-Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 10I6Z8TE010379; Mon, 18 Jan 2021 06:35:08 GMT X-Received: from prion.us.oracle.com (/10.159.226.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 17 Jan 2021 22:35:07 -0800 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 v4 7/9] OvmfPkg/CpuHotplugSmm: add CpuEject() Date: Sun, 17 Jan 2021 22:34:55 -0800 Message-Id: <20210118063457.358581-8-ankur.a.arora@oracle.com> In-Reply-To: <20210118063457.358581-1-ankur.a.arora@oracle.com> References: <20210118063457.358581-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: CzSGfmlBenhGe4qQ0vHJ6u9Dx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610951713; bh=P4tarBekCp+rvQveWltcttnl2+gZCIqOejiIDc2Nc6k=; h=Cc:Date:From:Reply-To:Subject:To; b=XYnaRVNOD88MsMl0vmKso26zfXO55Y/gcqo4MeM8K47E+/s2j4635WMHEvOyyRk8ETB XZr05eETLIGLiL2Fo9Sjh/U/l0NnIZ7F+RYR1WBsuzfplRcLr8p5JVERFzh/ST0can9WA BnLzs5fm5orSr985y0YAqE6DUjyFwAjdFZA= 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 | 84 ++++++++++++++++++++++++++++++++++= +++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index ccd5787b7327..e8ba9ae59e69 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. @@ -181,6 +183,34 @@ Fatal: return EFI_INTERRUPT_PENDING; } =20 +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 @@ -203,6 +233,7 @@ UnplugCpus( { EFI_STATUS Status =3D EFI_SUCCESS; UINT32 ToUnplugIdx; + UINT32 EjectCount =3D 0; UINTN ProcessorNum; =20 ToUnplugIdx =3D 0; @@ -242,11 +273,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) { + // + // We have processors to be ejected; install the handler. + // + mCpuHotEjectData->Handler =3D CpuEject; + } + // // We've handled this unplug. // @@ -445,7 +500,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 +518,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 +603,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 (#70483): https://edk2.groups.io/g/devel/message/70483 Mute This Topic: https://groups.io/mt/79917580/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-