From nobody Thu Nov 14 16:47:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+68464+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68464+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1607433837; cv=none; d=zohomail.com; s=zohoarc; b=XRw491TXQEU3szMcSwuGH8NosH34pP1ly02wCE9gLhGYZDdzoG0Y+7dR6LltJxbEXZxfpcdxphT8Z2PQE3bJrvTZLU/OIVzzgQMgQwfIYqaBaCjRmj939/7hXzLwd5VGKshHyxrpRJ3S1xDVXkZUNgXAY9Z+OWigfckHM1HqaWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607433837; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ylXIGHkkBDj53Z/eJZW8qqhANgtlEK2TsjhDB/f6Qvs=; b=j3zTp9nrBoK1LKhL8gAT/IOaEDNzH0uBhGKranJZ3BYtwAVo/Ijx1u9EAE1DQwQOWGqfMs7RL42QVnQL6QXyiDEgX47F0Qioe1MeXlIGdFdCQo+0VTyGNRyXzccGz0CUZV8hWdW8VH015VcChM53zhrZCJ9131+kaqvCbNrA1Eg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68464+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1607433837577466.4613306603941; Tue, 8 Dec 2020 05:23:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jc7xYY1788612xjawS6hgDv4; Tue, 08 Dec 2020 05:23:57 -0800 X-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 X-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 X-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 X-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 X-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 X-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 X-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: [edk2-devel] [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> In-Reply-To: <20201208053432.2690694-1-ankur.a.arora@oracle.com> References: <20201208053432.2690694-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ankur.a.arora@oracle.com X-Gm-Message-State: o0h7MV6OLlhdo1CTRUwHKIt6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1607433837; bh=39JV0x/TRSLv8fnihPYAhkZaBiVxSILPAkp+msSnsqs=; h=Cc:Date:From:Reply-To:Subject:To; b=DKB7iH7J0WA6alcPsCoqRE3ni02+nIbwxBBD3MiBiTdHo87kzU6v7yVHp0ZzSVdyUZc jXHStuLGhbAM7myZsYtjyfzJBOcfGehZPgiOEPprBhmaJe6GcRWSvc4K1a3dwtqkcA9Ir 9rX6iLLgHRMB8TRGPLacUODbfVZ0wJIW6hA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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; } =20 +/** + CPU Hot-unplug handler function. + + @param[in] mUnplugApicIds List of APIC IDs to be plugged. + + @param[in] ToUnplugCount Count of APIC IDs to be plugged. + + @retval EFI_SUCCESS Some of the requested APIC IDs were hot-unp= lugged. + + @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; + + // + // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + + ToUnplugIdx =3D 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + UINT32 ProcessorNum; + + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx]; + + 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_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID " to = unplug\n", + __FUNCTION__, RemoveApicId)); + ToUnplugIdx++; + continue; + } + + 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; + } + + // + // Tell the host that the firmware is done. + // + QemuCpuhpWriteCpuSelector (mMmCpuIo, RemoveApicId); + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED); + + ToUnplugIdx++; + } + + // + // We've handled this unplug. + // + return EFI_SUCCESS; + +Fatal: + return EFI_INTERRUPT_PENDING; +} + /** CPU Hotplug MMI handler function. =20 @@ -297,6 +375,8 @@ CpuHotplugMmi ( =20 if (PluggedCount > 0) { Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } else if (ToUnplugCount > 0) { + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount); } =20 if (EFI_ERROR(Status)) { --=20 2.25.4 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#68464): https://edk2.groups.io/g/devel/message/68464 Mute This Topic: https://groups.io/mt/78802725/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-