From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.4546.1607405695540783587 for ; Mon, 07 Dec 2020 21:34:55 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=xekLe/J6; spf=pass (domain: oracle.com, ip: 141.146.126.78, mailfrom: ankur.a.arora@oracle.com) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B85QgqA126073; Tue, 8 Dec 2020 05:34:54 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=+enE9jf5AMPzTVCJytTjMRG64kYwQflHSi8x9zoN/ZA=; b=xekLe/J6XVL9mPWhpXwdIpulozUqgAbg4pqOm8zn41KBoFu7StAjTW85WtOJHQjKjS0Q Yf/A5CJ3WiQ9YXX/lic2wqS6rAq+N91XKnwqJFIKapym7xMoRfmQwqe0z/n7y8oV69Ur 802HCEHlapjph/5PnPtrSjx+cFP43boxMgas6jw+BTDRDwIgwaeIvjnc1eCh2ABIGG// ek3lq88mdmxCtkzuqAAVEVN+VGo3DJ/4/k7HSY3FW250WFbDVTZeKfcb+UBnbKDktYiu E6muCnO8tq62YO7xPbWJdb2hKH0tE0K4OQGg7Z/MtUT+JLEtRe7/m3g8ZxP0xQ+JzG1Q Iw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 35825m0vnq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 08 Dec 2020 05:34:54 +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 0B85Ykav116085; Tue, 8 Dec 2020 05:34:54 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 358ksn3e2t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Dec 2020 05:34:54 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0B85Yrt3022951; Tue, 8 Dec 2020 05:34:53 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Dec 2020 21:34:53 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: imammedo@redhat.com, lersek@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora Subject: [RFC PATCH 1/5] OvmfPkg/CpuHotplugSmm: move CPU Hotplug into PlugCpus() Date: Mon, 7 Dec 2020 21:34:28 -0800 Message-Id: <20201208053432.2690694-2-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201208053432.2690694-1-ankur.a.arora@oracle.com> References: <20201208053432.2690694-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9828 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=1 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012080033 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9828 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 mlxscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012080032 Content-Transfer-Encoding: quoted-printable Move the CPU Hotplug logic into PlugCpus() in preparation for adding corresponding unplug logic. Signed-off-by: Ankur Arora --- OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 208 +++++++++++++++++------------ 1 file changed, 123 insertions(+), 85 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index cfe698ed2b5e..0f8f210d0ecf 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -62,6 +62,124 @@ STATIC UINT32 mPostSmmPenAddress; //=0D STATIC EFI_HANDLE mDispatchHandle;=0D =0D +/**=0D + CPU Hotplug handler function.=0D +=0D + @param[in] mPluggedApicIds List of APIC IDs to be plugged.=0D +=0D + @param[in] PluggedCount Count of APIC IDs to be plugged.=0D +=0D + @retval EFI_SUCCESS Some of the requested APIC IDs were hot-plu= gged.=0D +=0D + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging.=0D +=0D +**/=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +PlugCpus(=0D + IN APIC_ID *mPluggedApicIds,=0D + IN UINT32 PluggedCount=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINT32 PluggedIdx;=0D + UINT32 NewSlot;=0D +=0D + //=0D + // Process hot-added CPUs.=0D + //=0D + // The Post-SMM Pen need not be reinstalled multiple times within a sing= le=0D + // root MMI handling. Even reinstalling once per root MMI is only pruden= ce;=0D + // in theory installing the pen in the driver's entry point function sho= uld=0D + // suffice.=0D + //=0D + SmbaseReinstallPostSmmPen (mPostSmmPenAddress);=0D +=0D + PluggedIdx =3D 0;=0D + NewSlot =3D 0;=0D + while (PluggedIdx < PluggedCount) {=0D + APIC_ID NewApicId;=0D + UINT32 CheckSlot;=0D + UINTN NewProcessorNumberByProtocol;=0D +=0D + NewApicId =3D mPluggedApicIds[PluggedIdx];=0D +=0D + //=0D + // Check if the supposedly hot-added CPU is already known to us.=0D + //=0D + for (CheckSlot =3D 0;=0D + CheckSlot < mCpuHotPlugData->ArrayLength;=0D + CheckSlot++) {=0D + if (mCpuHotPlugData->ApicId[CheckSlot] =3D=3D NewApicId) {=0D + break;=0D + }=0D + }=0D + if (CheckSlot < mCpuHotPlugData->ArrayLength) {=0D + DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged = "=0D + "before; ignoring it\n", __FUNCTION__, NewApicId));=0D + PluggedIdx++;=0D + continue;=0D + }=0D +=0D + //=0D + // Find the first empty slot in CPU_HOT_PLUG_DATA.=0D + //=0D + while (NewSlot < mCpuHotPlugData->ArrayLength &&=0D + mCpuHotPlugData->ApicId[NewSlot] !=3D MAX_UINT64) {=0D + NewSlot++;=0D + }=0D + if (NewSlot =3D=3D mCpuHotPlugData->ArrayLength) {=0D + DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",=0D + __FUNCTION__, NewApicId));=0D + goto Fatal;=0D + }=0D +=0D + //=0D + // Store the APIC ID of the new processor to the slot.=0D + //=0D + mCpuHotPlugData->ApicId[NewSlot] =3D NewApicId;=0D +=0D + //=0D + // Relocate the SMBASE of the new CPU.=0D + //=0D + Status =3D SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot]= ,=0D + mPostSmmPenAddress);=0D + if (EFI_ERROR (Status)) {=0D + goto RevokeNewSlot;=0D + }=0D +=0D + //=0D + // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.=0D + //=0D + Status =3D mMmCpuService->AddProcessor (mMmCpuService, NewApicId,=0D + &NewProcessorNumberByProtocol);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",=0D + __FUNCTION__, NewApicId, Status));=0D + goto RevokeNewSlot;=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%= Lx, "=0D + "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__,= =0D + NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot],=0D + (UINT64)NewProcessorNumberByProtocol));=0D +=0D + NewSlot++;=0D + PluggedIdx++;=0D + }=0D +=0D + //=0D + // We've handled this hotplug.=0D + //=0D + return EFI_SUCCESS;=0D +=0D +RevokeNewSlot:=0D + mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64;=0D +=0D +Fatal:=0D + return EFI_INTERRUPT_PENDING;=0D +}=0D =0D /**=0D CPU Hotplug MMI handler function.=0D @@ -122,8 +240,6 @@ CpuHotplugMmi ( UINT8 ApmControl;=0D UINT32 PluggedCount;=0D UINT32 ToUnplugCount;=0D - UINT32 PluggedIdx;=0D - UINT32 NewSlot;=0D =0D //=0D // Assert that we are entering this function due to our root MMI handler= =0D @@ -179,87 +295,12 @@ CpuHotplugMmi ( goto Fatal;=0D }=0D =0D - //=0D - // Process hot-added CPUs.=0D - //=0D - // The Post-SMM Pen need not be reinstalled multiple times within a sing= le=0D - // root MMI handling. Even reinstalling once per root MMI is only pruden= ce;=0D - // in theory installing the pen in the driver's entry point function sho= uld=0D - // suffice.=0D - //=0D - SmbaseReinstallPostSmmPen (mPostSmmPenAddress);=0D + if (PluggedCount > 0) {=0D + Status =3D PlugCpus(mPluggedApicIds, PluggedCount);=0D + }=0D =0D - PluggedIdx =3D 0;=0D - NewSlot =3D 0;=0D - while (PluggedIdx < PluggedCount) {=0D - APIC_ID NewApicId;=0D - UINT32 CheckSlot;=0D - UINTN NewProcessorNumberByProtocol;=0D -=0D - NewApicId =3D mPluggedApicIds[PluggedIdx];=0D -=0D - //=0D - // Check if the supposedly hot-added CPU is already known to us.=0D - //=0D - for (CheckSlot =3D 0;=0D - CheckSlot < mCpuHotPlugData->ArrayLength;=0D - CheckSlot++) {=0D - if (mCpuHotPlugData->ApicId[CheckSlot] =3D=3D NewApicId) {=0D - break;=0D - }=0D - }=0D - if (CheckSlot < mCpuHotPlugData->ArrayLength) {=0D - DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged = "=0D - "before; ignoring it\n", __FUNCTION__, NewApicId));=0D - PluggedIdx++;=0D - continue;=0D - }=0D -=0D - //=0D - // Find the first empty slot in CPU_HOT_PLUG_DATA.=0D - //=0D - while (NewSlot < mCpuHotPlugData->ArrayLength &&=0D - mCpuHotPlugData->ApicId[NewSlot] !=3D MAX_UINT64) {=0D - NewSlot++;=0D - }=0D - if (NewSlot =3D=3D mCpuHotPlugData->ArrayLength) {=0D - DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",=0D - __FUNCTION__, NewApicId));=0D - goto Fatal;=0D - }=0D -=0D - //=0D - // Store the APIC ID of the new processor to the slot.=0D - //=0D - mCpuHotPlugData->ApicId[NewSlot] =3D NewApicId;=0D -=0D - //=0D - // Relocate the SMBASE of the new CPU.=0D - //=0D - Status =3D SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot]= ,=0D - mPostSmmPenAddress);=0D - if (EFI_ERROR (Status)) {=0D - goto RevokeNewSlot;=0D - }=0D -=0D - //=0D - // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.=0D - //=0D - Status =3D mMmCpuService->AddProcessor (mMmCpuService, NewApicId,=0D - &NewProcessorNumberByProtocol);=0D - if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",=0D - __FUNCTION__, NewApicId, Status));=0D - goto RevokeNewSlot;=0D - }=0D -=0D - DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%= Lx, "=0D - "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__,= =0D - NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot],=0D - (UINT64)NewProcessorNumberByProtocol));=0D -=0D - NewSlot++;=0D - PluggedIdx++;=0D + if (EFI_ERROR(Status)) {=0D + goto Fatal;=0D }=0D =0D //=0D @@ -267,9 +308,6 @@ CpuHotplugMmi ( //=0D return EFI_SUCCESS;=0D =0D -RevokeNewSlot:=0D - mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64;=0D -=0D Fatal:=0D ASSERT (FALSE);=0D CpuDeadLoop ();=0D --=20 2.25.4