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.1000.1610696751316272665 for ; Thu, 14 Jan 2021 23:45:51 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=KbcSVpBv; 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 10F7jPkE124609; Fri, 15 Jan 2021 07:45:48 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=0TXUHAyB5qujgAAwloDi+IDm5+MzvCV8XdUzwkknHDU=; b=KbcSVpBvjA4wDwk+cdsbIY6DLDtiJW2hT2S7Z2YRwUxAjeDLQ7f3TQyFm2meX1XDuvtl gHBAk2bkJNq1v2Nk+bSliKeXMcAekpzk7BVpFWXabmDAscmEwc16gcese5uJhkFB0N2C RbOzEpXigF2qejtxtG0s0fc+H5sfi2maBBjm2ePAwdYuRAX47o3OSoPJAPB0q43N/iU+ qwJgut7NJopDW+fZb/ASEPyuTBT9RYPiB4lsV+YtgnexXrP1U6tEWD+DLNNK2ZAU40VR zPM7RyYdl5gYRwgj+lh/KCHETV8TSoBzCreWWmstXbCPSxq/tjgMCydVlkof6HFKR8GW KA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 360kvkbnhs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:48 +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 10F7dk2P131982; Fri, 15 Jan 2021 07:45:47 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 360keavrer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:47 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 10F7jkSf020819; Fri, 15 Jan 2021 07:45:46 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2021 23:45:45 -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 07/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() Date: Thu, 14 Jan 2021 23:45:30 -0800 Message-Id: <20210115074533.277448-8-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 Introduce UnplugCpus() which, for each APIC ID being unplugged: * informs PiSmmCpuDxeSmm by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor() * stores the APIC ID in CPU_HOT_EJECT_DATA.ApicIdMap, such that it can later be used in the eject phase at SMI exit Also add a holding area in CpuEject() where CPUs being ejected can wait until ejected. 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 | 106 +++++++++++++++++++++++++++++++++= ++++ 1 file changed, 106 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index f088049c7aef..4048490783e4 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -183,6 +183,99 @@ Fatal: } =0D /**=0D + CPU Hot-unplug handler function. + + @param[in] mUnplugApicIds List of APIC IDs to be unplugged. + + @param[in] ToUnplugCount Count of APIC IDs to be unplugged. + + @retval EFI_SUCCESS Some of the requested APIC IDs will be ho= t-unplugged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +UnplugCpus( + IN APIC_ID *mUnplugApicIds, + IN UINT32 ToUnplugCount + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + UINT32 ToUnplugIdx; + UINT32 EjectCount =3D 0; + UINTN ProcessorNum; + + ToUnplugIdx =3D 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx]; + + // + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find + // the ProcessorNum for the APIC ID to be removed. + // + for (ProcessorNum =3D 0; + ProcessorNum < mCpuHotPlugData->ArrayLength; + ProcessorNum++) { + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) { + break; + } + } + + // + // Ignore the unplug if APIC ID not found + // + if (ProcessorNum =3D=3D mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_INFO, "%a: did not find APIC ID " FMT_APIC_ID " to unp= lug\n", + __FUNCTION__, RemoveApicId)); + ToUnplugIdx++; + continue; + } + + // + // Mark ProcessorNum for removal from SMM data structures + // + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= ); + + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, RemoveApicId, Status)); + goto Fatal; + } else { + // + // Stash the APIC IDs so we can do the actual unplug later. + // + if (mCpuHotEjectData->ApicIdMap[ProcessorNum] !=3D CPU_EJECT_INVALID= ) { + // + // Since ProcessorNum and APIC-ID map 1-1, so a valid + // mCpuHotEjectData->ApicIdMap[ProcessorNum] means something + // is horribly wrong. + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %u maps to %llx, cannot map= to " FMT_APIC_ID "\n", + __FUNCTION__, ProcessorNum, mCpuHotEjectData->ApicIdMap[Processo= rNum], RemoveApicId)); + goto Fatal; + } + + mCpuHotEjectData->ApicIdMap[ProcessorNum] =3D (UINT64)RemoveApicId; + EjectCount++; + } + + ToUnplugIdx++; + } + + // + // We've handled this unplug. + // + return EFI_SUCCESS; + +Fatal: + return EFI_INTERRUPT_PENDING; +} + +/** CPU Hotplug MMI handler function.=0D =0D This is a root MMI handler.=0D @@ -298,6 +391,8 @@ CpuHotplugMmi ( =0D if (PluggedCount > 0) { Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } else if (ToUnplugCount > 0) { + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount); } =0D if (EFI_ERROR(Status)) { @@ -334,6 +429,17 @@ CpuEject( if (ApicId =3D=3D CPU_EJECT_INVALID) { return; } + + // + // CPU(s) being unplugged get here from SmmCpuFeaturesSmiRendezvousExit() + // after having been cleared to exit the SMI by the monarch and thus have + // no SMM processing remaining. + // + // Given that we cannot allow them to escape to the guest, we pen them + // here until the SMM monarch tells the HW to unplug them. + // + + CpuDeadLoop (); } =0D //=0D --=20 2.9.3