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.web10.30154.1610951826638322691 for ; Sun, 17 Jan 2021 22:37:06 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=Msc/9rhu; 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 10I6XQbf007158; Mon, 18 Jan 2021 06:37:03 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=Msc/9rhuFqUJPeQYkw8+6JmQwNZIsv2fRFcu7eSAbVLy/na/Sg2s3QbCuXHl+jN4496v dH4kZJKpFPBkRwr0DFAkq8QpWGvhD7k31Mq766c1TvvFpDCmLdj0qRehdKz9ugdriOoM YUwxwZUgk9QfFJ5Dd4Z6ATFjytZKzWz5frBecuRPg1Jhspvz4X34r1x4jdz0oBEu4TGv T+HEBcHvONLDJmOH6I8UZNYxGFNcUdESHnUo3waqDAFWvsFlASXQIWPnYF2mJId9a7kB bR3n9aDMj4+cSkBy5utT5Z/DmDAZgEd0XtekDDnqnr4mg5MTJiSraAgA98oDfpz8sYax 1A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 363xyhk0ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:37:03 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10I6VMbT051601; Mon, 18 Jan 2021 06:35:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 364a2uj8n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Jan 2021 06:35:02 +0000 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 10I6Z1BP010338; Mon, 18 Jan 2021 06:35:02 GMT 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:01 -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 v4 1/9] OvmfPkg/CpuHotplugSmm: refactor hotplug logic Date: Sun, 17 Jan 2021 22:34:49 -0800 Message-Id: <20210118063457.358581-2-ankur.a.arora@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210118063457.358581-1-ankur.a.arora@oracle.com> References: <20210118063457.358581-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9867 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101180038 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9867 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101180038 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