From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web08.1039.1610696866141499503 for ; Thu, 14 Jan 2021 23:47:46 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=wrBnJg/f; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: ankur.a.arora@oracle.com) 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 10F7jdMP124792; Fri, 15 Jan 2021 07:47:42 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=APt1wbyEEKxM2JTc2+odOGPvst3NVr9cGGFt6/parnI=; b=wrBnJg/f8J/BSxaPGy6ISJ9Y0ToDwhX7kS1C7tXMYHP+UH6n0JUVGLCNX1wK3wAy9UYr LIW6i5kKRm0kqPf2PeFkvyDGLIPcrfZnvOVSh2l9NdMjoLuATSksoKnAddO1gTz+RSYt xexBPT7YkaPuVZ8MOiexqjfCA7oioeY3DYlX2iahCs4cgM4cnPw4nhUFBK5KvCoiML1X LEQTYtmTz8k8vb6/ynJko7CCKvWXXvizcXUrxu1f61zrvXeQYLQ1GUcrmBXp4hK/Bjk5 kRgywmTbT5uOISEBS4+YXcaa4wQQlSgIDl/QR5mrjvRsdT7EDnHy3hvSs6HUauCwAIe0 MA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 360kvkbnnm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:47:42 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10F7dtpI132436; Fri, 15 Jan 2021 07:45:41 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 360keavrd2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:41 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 10F7jf2n008864; Fri, 15 Jan 2021 07:45:41 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2021 23:45:40 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: imammedo@redhat.com, lersek@redhat.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Boris Ostrovsky , Aaron Young Subject: [PATCH v3 01/10] OvmfPkg/CpuHotplugSmm: refactor hotplug logic Date: Thu, 14 Jan 2021 23:45:24 -0800 Message-Id: <20210115074533.277448-2-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210115074533.277448-1-ankur.a.arora@oracle.com> References: <20210115074533.277448-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 Content-Transfer-Encoding: quoted-printable Refactor CpuHotplugMmi() to pull out the CPU hotplug logic into PlugCpus(). This is in preparation for supporting CPU hot-unplug. 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 | 208 ++++++++++++++++++++++-----------= ---- 1 file changed, 123 insertions(+), 85 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index cfe698ed2b5e..38c71bc11864 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 +/** + CPU Hotplug handler function. + + @param[in] mPluggedApicIds List of APIC IDs to be plugged. + + @param[in] PluggedCount Count of APIC IDs to be plugged. + + @retval EFI_SUCCESS Some of the requested APIC IDs were hot-plu= gged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +PlugCpus( + IN APIC_ID *mPluggedApicIds, + IN UINT32 PluggedCount + ) +{ + EFI_STATUS Status; + UINT32 PluggedIdx; + UINT32 NewSlot; + + // + // Process hot-added CPUs. + // + // The Post-SMM Pen need not be reinstalled multiple times within a sing= le + // root MMI handling. Even reinstalling once per root MMI is only pruden= ce; + // in theory installing the pen in the driver's entry point function sho= uld + // suffice. + // + SmbaseReinstallPostSmmPen (mPostSmmPenAddress); + + PluggedIdx =3D 0; + NewSlot =3D 0; + while (PluggedIdx < PluggedCount) { + APIC_ID NewApicId; + UINT32 CheckSlot; + UINTN NewProcessorNumberByProtocol; + + NewApicId =3D mPluggedApicIds[PluggedIdx]; + + // + // Check if the supposedly hot-added CPU is already known to us. + // + for (CheckSlot =3D 0; + CheckSlot < mCpuHotPlugData->ArrayLength; + CheckSlot++) { + if (mCpuHotPlugData->ApicId[CheckSlot] =3D=3D NewApicId) { + break; + } + } + if (CheckSlot < mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged " + "before; ignoring it\n", __FUNCTION__, NewApicId)); + PluggedIdx++; + continue; + } + + // + // Find the first empty slot in CPU_HOT_PLUG_DATA. + // + while (NewSlot < mCpuHotPlugData->ArrayLength && + mCpuHotPlugData->ApicId[NewSlot] !=3D MAX_UINT64) { + NewSlot++; + } + if (NewSlot =3D=3D mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n", + __FUNCTION__, NewApicId)); + goto Fatal; + } + + // + // Store the APIC ID of the new processor to the slot. + // + mCpuHotPlugData->ApicId[NewSlot] =3D NewApicId; + + // + // Relocate the SMBASE of the new CPU. + // + Status =3D SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], + mPostSmmPenAddress); + if (EFI_ERROR (Status)) { + goto RevokeNewSlot; + } + + // + // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + Status =3D mMmCpuService->AddProcessor (mMmCpuService, NewApicId, + &NewProcessorNumberByProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, NewApicId, Status)); + goto RevokeNewSlot; + } + + DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%= Lx, " + "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__, + NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot], + (UINT64)NewProcessorNumberByProtocol)); + + NewSlot++; + PluggedIdx++; + } + + // + // We've handled this hotplug. + // + return EFI_SUCCESS; + +RevokeNewSlot: + mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64; + +Fatal: + return EFI_INTERRUPT_PENDING; +} =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) { + Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } =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)) { + goto Fatal; }=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.9.3