From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=IiHZQIsm; spf=pass (domain: oracle.com, ip: 141.146.126.79, mailfrom: ankur.a.arora@oracle.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=kunoH/Xl08X9H2piUqKyxmFsTqW8q7yduyT6ubEQPB0=; b=IiHZQIsmz0QvPg9ACUNPleKiRhNz0p4V66Sodm9LpFJ3jhN1pk6+I0rJFgjNG5qCinB3 PJap5hs8gs4Y8Pa4Ier3nYb7q51hD5rZw/EVjBK8hztZiJxkrP6peR4b+fpMluKTFk46 wgrhx2gynAMsMBGC4MNssCCNbcCDL6wvCj9VtNEW5OzUqgtyR7Pwtjlxwhf52gYa61aZ cdihSrCIjAq+AvuiY40D814iLQysOj4zbbvUOdmctjMXY0LbYP68g18oAcdht8fwgT8M ALHPtFmFH7/6FQSmIs4yIIM9d8aayIPScMqi5Iia8k8PE17rEL+g2Tagf6+K6NhFiIjp IQ== 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 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 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 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 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: [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> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070114 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070115 Content-Transfer-Encoding: quoted-printable 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;=0D STATIC APIC_ID *mToUnplugApicIds;=0D //=0D +// Similar to the SMRAM arrays above mHotunplugWork stores APIC IDs of=0D +// processors with pending unplugs for the duration of the MMI.=0D +//=0D +// This array maps ProcessorNum -> APIC ID and so has room for possible=0D +// CPU count.=0D +//=0D +STATIC APIC_ID *mHotUnplugWork;=0D +//=0D // Address of the non-SMRAM reserved memory page that contains the Post-SM= M Pen=0D // for hot-added CPUs.=0D //=0D @@ -182,6 +190,100 @@ Fatal: }=0D =0D /**=0D + CPU Hot-unplug handler function.=0D +=0D + @param[in] mUnplugApicIds List of APIC IDs to be unplugged.=0D +=0D + @param[in] ToUnplugCount Count of APIC IDs to be unplugged.=0D +=0D + @param[out] mHotUnplugWork List mapping ProcessorNum -> APIC ID for = later unplug.=0D + Invalid entries are specified as MAX_UINT= 32.=0D +=0D + @retval EFI_SUCCESS Some of the requested APIC IDs will be hot-= unplugged.=0D +=0D + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging.=0D +=0D +**/=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +UnplugCpus(=0D + IN APIC_ID *mUnplugApicIds,=0D + IN UINT32 ToUnplugCount,=0D + OUT APIC_ID *mHotUnplugWork=0D + )=0D +{=0D + EFI_STATUS Status =3D EFI_SUCCESS;=0D + UINT32 ToUnplugIdx;=0D +=0D + //=0D + // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.=0D + //=0D +=0D + ToUnplugIdx =3D 0;=0D + while (ToUnplugIdx < ToUnplugCount) {=0D + APIC_ID RemoveApicId;=0D + UINT32 ProcessorNum;=0D +=0D + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx];=0D +=0D + for (ProcessorNum =3D 0;=0D + ProcessorNum < mCpuHotPlugData->ArrayLength;=0D + ProcessorNum++) {=0D + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) {=0D + break;=0D + }=0D + }=0D +=0D + //=0D + // Ignore the unplug if APIC ID is not found=0D + //=0D + if (ProcessorNum =3D=3D mCpuHotPlugData->ArrayLength) {=0D + DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID " to = unplug\n",=0D + __FUNCTION__, RemoveApicId));=0D + ToUnplugIdx++;=0D + continue;=0D + }=0D +=0D + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= );=0D +=0D + if (EFI_ERROR(Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",=0D + __FUNCTION__, RemoveApicId, Status));=0D + goto Fatal;=0D + } else {=0D + //=0D + // Stash the APIC IDs so we can do the actual unplug later.=0D + //=0D +=0D + if (mHotUnplugWork[ProcessorNum] !=3D MAX_UINT32) {=0D + //=0D + // Since ProcessorNum and APIC-ID are a 1-1 mapping, so an already=0D + // filled mHotUnplugWork[ProcessorNum] is a fatal error.=0D + //=0D + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %u maps to " FMT_APIC_ID ",= cannot map to " FMT_APIC_ID "\n",=0D + __FUNCTION__, ProcessorNum, mHotUnplugWork[ProcessorNum], Remove= ApicId));=0D + goto Fatal;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: Caching ProcessorNum %u -> " FMT_APIC_ID " = for unplugging\n",=0D + __FUNCTION__, ProcessorNum, RemoveApicId));=0D + mHotUnplugWork[ProcessorNum] =3D RemoveApicId;=0D + }=0D +=0D + ToUnplugIdx++;=0D + }=0D +=0D + //=0D + // We've handled this unplug.=0D + //=0D + return EFI_SUCCESS;=0D +=0D +Fatal:=0D + return EFI_INTERRUPT_PENDING;=0D +}=0D +=0D +/**=0D CPU Hotplug MMI handler function.=0D =0D This is a root MMI handler.=0D @@ -297,6 +399,8 @@ CpuHotplugMmi ( =0D if (PluggedCount > 0) {=0D Status =3D PlugCpus(mPluggedApicIds, PluggedCount);=0D + } else if (ToUnplugCount > 0) {=0D + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount, mHotUnplugWork)= ;=0D }=0D =0D if (EFI_ERROR(Status)) {=0D @@ -330,6 +434,7 @@ CpuHotplugEntry ( {=0D EFI_STATUS Status;=0D UINTN Size;=0D + UINTN Idx;=0D =0D //=0D // This module should only be included when SMM support is required.=0D @@ -403,12 +508,36 @@ CpuHotplugEntry ( }=0D =0D //=0D + // Allocate for the full CPU count. We index to-be-unplugged APIC IDs=0D + // with ProcessorNum.=0D + //=0D + if (RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), mCpuHotPlugData->Arra= yLength, &Size))) {=0D + Status =3D EFI_ABORTED;=0D + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__))= ;=0D + goto ReleaseToUnplugApicIds;=0D + }=0D + Status =3D gMmst->MmAllocatePool (EfiRuntimeServicesData, Size,=0D + (VOID **)&mHotUnplugWork);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s));=0D + goto ReleaseToUnplugApicIds;=0D + }=0D +=0D + //=0D + // We will use mHotUnplugWork to map from ProcessorNum -> APIC_ID.=0D + // Initialize to known invalid values.=0D + //=0D + for (Idx =3D 0; Idx < mCpuHotPlugData->ArrayLength; Idx++) {=0D + mHotUnplugWork[Idx] =3D MAX_UINT32;=0D + }=0D +=0D + //=0D // Allocate the Post-SMM Pen for hot-added CPUs.=0D //=0D Status =3D SmbaseAllocatePostSmmPen (&mPostSmmPenAddress,=0D SystemTable->BootServices);=0D if (EFI_ERROR (Status)) {=0D - goto ReleaseToUnplugApicIds;=0D + goto ReleaseToHotUnplugWork;=0D }=0D =0D //=0D @@ -468,6 +597,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices);= =0D mPostSmmPenAddress =3D 0;=0D =0D +ReleaseToHotUnplugWork:=0D + gMmst->MmFreePool (mHotUnplugWork);=0D + mHotUnplugWork =3D NULL;=0D +=0D ReleaseToUnplugApicIds:=0D gMmst->MmFreePool (mToUnplugApicIds);=0D mToUnplugApicIds =3D NULL;=0D --=20 2.9.3