From nobody Thu Nov 14 16:58:14 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+69971+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+69971+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049331; cv=none; d=zohomail.com; s=zohoarc; b=SzQKnSzQFFpr1Ip36sElD1JGsiNGOAZXM+9rodxDKjRJUNiATGU7+6LjzfRmE6Isarjp8ZiG5sQfBKZxwxu/tGOQjbJpl7+A8OkZIkMbX0K2GT5rZUqoLbXirxs4SRkCcdEhg3tiJS4Uln9knRDLbkgv5vp/aP2D6uUX7ONaIF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049331; 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=zUJL3Nucx15J8Z3O7cxLXrkOHq/JOMUDJrDClOP8Nnc=; b=ItoS48x8l8BGzi4/gRpslWY36AHMXK/Eb2pFtVLSSVTs6AV1axYrcY2pRFOCOjfW/Qekn5OneAsm9LsXnFAis6k5GaXBIrIN6n2zZzPW3zWQmoIh637TqsewmZF+OIEAqaLr6EI39dPmXqJvIYz3Uiz0j3pyr9h5b3V+vTqtWms= 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+69971+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 1610049331965362.0989675273712; Thu, 7 Jan 2021 11:55:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id u5cKYY1788612xTu9oVSyUGa; Thu, 07 Jan 2021 11:55:31 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web12.2154.1610049330884282644 for ; Thu, 07 Jan 2021 11:55:31 -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 107JtREL150435; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 35wcuxxedv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:27 +0000 X-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 107JaWef024026; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35v4ree7qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:27 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtQRw003565; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:26 -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 v2 04/10] OvmfPkg/CpuHotplugSmm: handle CPU hot-unplug Date: Thu, 7 Jan 2021 11:55:09 -0800 Message-Id: <20210107195515.106158-5-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-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: Wa9dpwYOEZTYeBv6YrWYqNpOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049331; bh=fDTQI1H7jasQOttRPR/rqgTk6gEvQPMZhlvOq6tImRc=; h=Cc:Date:From:Reply-To:Subject:To; b=VKPMOJSLZ/uMYVspbkCQHqPR9hD3DAVCayGTBFyUPUVtIxH3AerRrZz0bD4mzX4KocK nSImUsr8XT4+oQMtWm9Jop/rkdM77tecqKvmoEWOtHWPCrVYUxGCkjjQihg2sPMAGRgUs QGcVYJ5Y4Rmxj/pPNh0Iw5Et5I6TZJeBJYI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce a new function UnplugCpus() which, for each unplugged CPU: * finds the slot for APIC ID in CPU_HOT_PLUG_DATA * informs PiSmmCpuDxeSmm by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor() * caches the APIC ID, such that it can be ejected at SMI exit 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 | 135 +++++++++++++++++++++++++++++++++= +++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 0f8f210d0ecf..20d92a35da39 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -53,6 +53,14 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mToUnplugApicIds; // +// Similar to the SMRAM arrays above mHotunplugWork stores APIC IDs of +// processors with pending unplugs for the duration of the MMI. +// +// This array maps ProcessorNum -> APIC ID and so has room for possible +// CPU count. +// +STATIC APIC_ID *mHotUnplugWork; +// // Address of the non-SMRAM reserved memory page that contains the Post-SM= M Pen // for hot-added CPUs. // @@ -182,6 +190,100 @@ Fatal: } =20 /** + CPU Hot-unplug handler function. + + @param[in] mUnplugApicIds List of APIC IDs to be unplugged. + + @param[in] ToUnplugCount Count of APIC IDs to be unplugged. + + @param[out] mHotUnplugWork List mapping ProcessorNum -> APIC ID for = later unplug. + Invalid entries are specified as MAX_UINT= 32. + + @retval EFI_SUCCESS Some of the requested APIC IDs will be hot-= unplugged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +UnplugCpus( + IN APIC_ID *mUnplugApicIds, + IN UINT32 ToUnplugCount, + OUT APIC_ID *mHotUnplugWork + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + UINT32 ToUnplugIdx; + + // + // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + + ToUnplugIdx =3D 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + UINT32 ProcessorNum; + + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx]; + + for (ProcessorNum =3D 0; + ProcessorNum < mCpuHotPlugData->ArrayLength; + ProcessorNum++) { + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) { + break; + } + } + + // + // Ignore the unplug if APIC ID is not found + // + if (ProcessorNum =3D=3D mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID " to = unplug\n", + __FUNCTION__, RemoveApicId)); + ToUnplugIdx++; + continue; + } + + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= ); + + if (EFI_ERROR(Status)) { + 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 (mHotUnplugWork[ProcessorNum] !=3D MAX_UINT32) { + // + // Since ProcessorNum and APIC-ID are a 1-1 mapping, so an already + // filled mHotUnplugWork[ProcessorNum] is a fatal error. + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %u maps to " FMT_APIC_ID ",= cannot map to " FMT_APIC_ID "\n", + __FUNCTION__, ProcessorNum, mHotUnplugWork[ProcessorNum], Remove= ApicId)); + goto Fatal; + } + + DEBUG ((DEBUG_INFO, "%a: Caching ProcessorNum %u -> " FMT_APIC_ID " = for unplugging\n", + __FUNCTION__, ProcessorNum, RemoveApicId)); + mHotUnplugWork[ProcessorNum] =3D RemoveApicId; + } + + ToUnplugIdx++; + } + + // + // We've handled this unplug. + // + return EFI_SUCCESS; + +Fatal: + return EFI_INTERRUPT_PENDING; +} + +/** CPU Hotplug MMI handler function. =20 This is a root MMI handler. @@ -297,6 +399,8 @@ CpuHotplugMmi ( =20 if (PluggedCount > 0) { Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } else if (ToUnplugCount > 0) { + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount, mHotUnplugWork); } =20 if (EFI_ERROR(Status)) { @@ -330,6 +434,7 @@ CpuHotplugEntry ( { EFI_STATUS Status; UINTN Size; + UINTN Idx; =20 // // This module should only be included when SMM support is required. @@ -403,12 +508,36 @@ CpuHotplugEntry ( } =20 // + // Allocate for the full CPU count. We index to-be-unplugged APIC IDs + // with ProcessorNum. + // + if (RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), mCpuHotPlugData->Arra= yLength, &Size))) { + Status =3D EFI_ABORTED; + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__)); + goto ReleaseToUnplugApicIds; + } + Status =3D gMmst->MmAllocatePool (EfiRuntimeServicesData, Size, + (VOID **)&mHotUnplugWork); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s)); + goto ReleaseToUnplugApicIds; + } + + // + // We will use mHotUnplugWork to map from ProcessorNum -> APIC_ID. + // Initialize to known invalid values. + // + for (Idx =3D 0; Idx < mCpuHotPlugData->ArrayLength; Idx++) { + mHotUnplugWork[Idx] =3D MAX_UINT32; + } + + // // Allocate the Post-SMM Pen for hot-added CPUs. // Status =3D SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, SystemTable->BootServices); if (EFI_ERROR (Status)) { - goto ReleaseToUnplugApicIds; + goto ReleaseToHotUnplugWork; } =20 // @@ -468,6 +597,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices); mPostSmmPenAddress =3D 0; =20 +ReleaseToHotUnplugWork: + gMmst->MmFreePool (mHotUnplugWork); + mHotUnplugWork =3D NULL; + ReleaseToUnplugApicIds: gMmst->MmFreePool (mToUnplugApicIds); mToUnplugApicIds =3D NULL; --=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 (#69971): https://edk2.groups.io/g/devel/message/69971 Mute This Topic: https://groups.io/mt/79507538/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-