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.web12.4627.1607405701722426272 for ; Mon, 07 Dec 2020 21:35:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=W+G09AN4; 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 0B85PG6b125438; Tue, 8 Dec 2020 05:35:01 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=gQzCwLgvwUB+OgFYvy4fep5Xv29S3MsAjPLrg58BepU=; b=W+G09AN4hJ3j7xK7ycNbAE2JREXGKoNijGRM0pEZDQlwSDRVvWl65mt9LDbuMOVuuX5p E1hxQfEWOvyHQqlU6M15q1GV7StyiSB4Pg+5pE/kgHuSEFfSA74LHLzvhf7icd7iOd4q 2HXmF+zHSkojatSv5+SFNK+IfcKos6LF1z5sEH+8DEEWPJp/BatbJlKxgwaJ0Y6moJH5 jxM7tey+/2w9D+3dbntYp31NdaEs69e8Gd+K5pCDiumGBlbnAPQRV60f/lExnxKn6d9N u4K0ews2Mmf0UsnKr+TbPJwqOSj92KrbIuyWGzOCTGpqbDlLfoRFNbrtVtysOfIvnFPK BQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 35825m0vp9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 08 Dec 2020 05:35:01 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B85YcFP074979; Tue, 8 Dec 2020 05:35:00 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 358kysb9a7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Dec 2020 05:35:00 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B85YxMQ006149; Tue, 8 Dec 2020 05:34:59 GMT Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Dec 2020 21:34:59 -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 4/5] OvmfPkg/CpuHotplugSmm: handle CPU hot-unplug Date: Mon, 7 Dec 2020 21:34:31 -0800 Message-Id: <20201208053432.2690694-5-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 adultscore=0 spamscore=0 mlxscore=0 malwarescore=0 suspectscore=1 mlxlogscore=999 bulkscore=0 phishscore=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 Introduce a new function UnplugCpus() which, for each unplugged CPU: - find the slot for APIC ID in CPU_HOT_PLUG_DATA. - inform PiSmmCPuDxeSmm by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor(). - update the QEMU_CPUHP_STAT_EJECTED bit in the QEMU_CPUHP_R_CPU_STAT regiser. Signed-off-by: Ankur Arora --- OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 0f8f210d0ecf..0a839ae52215 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -181,6 +181,84 @@ Fatal: return EFI_INTERRUPT_PENDING;=0D }=0D =0D +/**=0D + CPU Hot-unplug handler function.=0D +=0D + @param[in] mUnplugApicIds List of APIC IDs to be plugged.=0D +=0D + @param[in] ToUnplugCount Count of APIC IDs to be plugged.=0D +=0D + @retval EFI_SUCCESS Some of the requested APIC IDs were hot-unp= lugged.=0D +=0D + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging.=0D +=0D +**/=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +UnplugCpus(=0D + IN APIC_ID *mUnplugApicIds,=0D + IN UINT32 ToUnplugCount=0D + )=0D +{=0D + EFI_STATUS Status =3D EFI_SUCCESS;=0D + UINT32 ToUnplugIdx;=0D +=0D + //=0D + // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.=0D + //=0D +=0D + ToUnplugIdx =3D 0;=0D + while (ToUnplugIdx < ToUnplugCount) {=0D + APIC_ID RemoveApicId;=0D + UINT32 ProcessorNum;=0D +=0D + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx];=0D +=0D + for (ProcessorNum =3D 0;=0D + ProcessorNum < mCpuHotPlugData->ArrayLength;=0D + ProcessorNum++) {=0D + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) {=0D + break;=0D + }=0D + }=0D +=0D + //=0D + // Ignore the unplug if APIC ID not found=0D + //=0D + if (ProcessorNum =3D=3D mCpuHotPlugData->ArrayLength) {=0D + DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID " to = unplug\n",=0D + __FUNCTION__, RemoveApicId));=0D + ToUnplugIdx++;=0D + continue;=0D + }=0D +=0D + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= );=0D +=0D + if (EFI_ERROR(Status)) {=0D + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",=0D + __FUNCTION__, RemoveApicId, Status));=0D + goto Fatal;=0D + }=0D +=0D + //=0D + // Tell the host that the firmware is done.=0D + //=0D + QemuCpuhpWriteCpuSelector (mMmCpuIo, RemoveApicId);=0D + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED);=0D +=0D + ToUnplugIdx++;=0D + }=0D +=0D + //=0D + // We've handled this unplug.=0D + //=0D + return EFI_SUCCESS;=0D +=0D +Fatal:=0D + return EFI_INTERRUPT_PENDING;=0D +}=0D +=0D /**=0D CPU Hotplug MMI handler function.=0D =0D @@ -297,6 +375,8 @@ CpuHotplugMmi ( =0D if (PluggedCount > 0) {=0D Status =3D PlugCpus(mPluggedApicIds, PluggedCount);=0D + } else if (ToUnplugCount > 0) {=0D + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount);=0D }=0D =0D if (EFI_ERROR(Status)) {=0D --=20 2.25.4