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.web12.2153.1610049330549072028 for ; Thu, 07 Jan 2021 11:55:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=kDVAT+Ey; 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 107JtQZO192293; Thu, 7 Jan 2021 19:55:26 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=ALTMQpzbM+2xdqmGfSVOuUK6fj5WB0cSFF3pqlPsuX0=; b=kDVAT+EyP1851uhcmb4Em6rvCnHo4FFK+31MYDEJKIMlu2PcOu3+vORHVpOdxr3KVI8Z STA6XrJ4mN1IXjGLK5o32EiH1EmQOyJm4nMWVxePS4suqE15yU4MerkcwGPvdtVUCEtU aet1eCxf7j8rEldxnO9IpSGWZDeKSINlwDR9n2je9u40oWmTmpInsmGphPYcX0wZ6HaJ TIilox0FDk80bHeNqKNLeS3gNSA56MS6LZcmzVA31rkMqll7ecD3iihRUIESbjEHw0i6 Y2Mvv9wgztNTsTgc2Kk3TRKjOuVg0O/hxkMWBJRKukm253aaPxoGn++fQwNLjmKAZL3h iQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 35wftxdn2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:26 +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 107JaVDH023876; Thu, 7 Jan 2021 19:55:25 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35v4ree7pt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:25 +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 107JtOcT003561; Thu, 7 Jan 2021 19:55:24 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:23 -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 01/10] OvmfPkg/CpuHotplugSmm: move CPU Hotplug into PlugCpus() Date: Thu, 7 Jan 2021 11:55:06 -0800 Message-Id: <20210107195515.106158-2-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 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1011 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101070115 Content-Transfer-Encoding: 8bit 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=3132 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/CpuHotplug.c index cfe698ed2b5e..0f8f210d0ecf 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -62,6 +62,124 @@ STATIC UINT32 mPostSmmPenAddress; // STATIC EFI_HANDLE mDispatchHandle; +/** + 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-plugged. + + @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 single + // root MMI handling. Even reinstalling once per root MMI is only prudence; + // in theory installing the pen in the driver's entry point function should + // suffice. + // + SmbaseReinstallPostSmmPen (mPostSmmPenAddress); + + PluggedIdx = 0; + NewSlot = 0; + while (PluggedIdx < PluggedCount) { + APIC_ID NewApicId; + UINT32 CheckSlot; + UINTN NewProcessorNumberByProtocol; + + NewApicId = mPluggedApicIds[PluggedIdx]; + + // + // Check if the supposedly hot-added CPU is already known to us. + // + for (CheckSlot = 0; + CheckSlot < mCpuHotPlugData->ArrayLength; + CheckSlot++) { + if (mCpuHotPlugData->ApicId[CheckSlot] == 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] != MAX_UINT64) { + NewSlot++; + } + if (NewSlot == 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] = NewApicId; + + // + // Relocate the SMBASE of the new CPU. + // + Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], + mPostSmmPenAddress); + if (EFI_ERROR (Status)) { + goto RevokeNewSlot; + } + + // + // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + Status = 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] = MAX_UINT64; + +Fatal: + return EFI_INTERRUPT_PENDING; +} /** CPU Hotplug MMI handler function. @@ -122,8 +240,6 @@ CpuHotplugMmi ( UINT8 ApmControl; UINT32 PluggedCount; UINT32 ToUnplugCount; - UINT32 PluggedIdx; - UINT32 NewSlot; // // Assert that we are entering this function due to our root MMI handler @@ -179,87 +295,12 @@ CpuHotplugMmi ( goto Fatal; } - // - // Process hot-added CPUs. - // - // The Post-SMM Pen need not be reinstalled multiple times within a single - // root MMI handling. Even reinstalling once per root MMI is only prudence; - // in theory installing the pen in the driver's entry point function should - // suffice. - // - SmbaseReinstallPostSmmPen (mPostSmmPenAddress); + if (PluggedCount > 0) { + Status = PlugCpus(mPluggedApicIds, PluggedCount); + } - PluggedIdx = 0; - NewSlot = 0; - while (PluggedIdx < PluggedCount) { - APIC_ID NewApicId; - UINT32 CheckSlot; - UINTN NewProcessorNumberByProtocol; - - NewApicId = mPluggedApicIds[PluggedIdx]; - - // - // Check if the supposedly hot-added CPU is already known to us. - // - for (CheckSlot = 0; - CheckSlot < mCpuHotPlugData->ArrayLength; - CheckSlot++) { - if (mCpuHotPlugData->ApicId[CheckSlot] == 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] != MAX_UINT64) { - NewSlot++; - } - if (NewSlot == 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] = NewApicId; - - // - // Relocate the SMBASE of the new CPU. - // - Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], - mPostSmmPenAddress); - if (EFI_ERROR (Status)) { - goto RevokeNewSlot; - } - - // - // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. - // - Status = 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++; + if (EFI_ERROR(Status)) { + goto Fatal; } // @@ -267,9 +308,6 @@ CpuHotplugMmi ( // return EFI_SUCCESS; -RevokeNewSlot: - mCpuHotPlugData->ApicId[NewSlot] = MAX_UINT64; - Fatal: ASSERT (FALSE); CpuDeadLoop (); -- 2.9.3