From nobody Thu Nov 14 17:03:30 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+70378+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+70378+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610696752; cv=none; d=zohomail.com; s=zohoarc; b=PFNKKv4F6MX9IF14LXYhhiovDISwM9RnMp++k3NVCnwi/AmOkuGykxL9Xo96nPpq9J0M6uDE2FYlR3/0bqvZST1zr/sijZhNqCnHKSubIkoLz1q8ZodfZmWVQr3NVAvkVM3oDq+hjbaYZdT7YtPuWUfIYFiM9GX6Cpelv8HZAZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610696752; 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=WBTxPuQuZ0Fzs5SkhmqT1n1vJsIhQMZy8ugmCjmqGv0=; b=dW23yFcEoPqrnbLvFIw2EBWPflMJSKVQZ+m7rI+IaA6vnF2TR6ajbiIZe9lkvBvdT45OeaoZTAptZkkgoeM0gftyvH1PWOJYjevxUNrNlajl7zA3iYvksnREJO83Vj1z6bvR1Y749REoA/qEKAW/OcVgjfI5LVz22n6egJ9mFWY= 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+70378+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 1610696752062889.7687380276999; Thu, 14 Jan 2021 23:45:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3yatYY1788612xlJfCoQ6jN7; Thu, 14 Jan 2021 23:45:51 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web08.1021.1610696751173219037 for ; Thu, 14 Jan 2021 23:45:51 -0800 X-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10F7hmoR185509; Fri, 15 Jan 2021 07:45:48 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 360kg23rep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:47 +0000 X-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 10F7dkOF132020; Fri, 15 Jan 2021 07:45:47 GMT X-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 360keavrex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:47 +0000 X-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 10F7jkPn008893; Fri, 15 Jan 2021 07:45:46 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2021 23:45:46 -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: [edk2-devel] [PATCH v3 08/10] OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection Date: Thu, 14 Jan 2021 23:45:31 -0800 Message-Id: <20210115074533.277448-9-ankur.a.arora@oracle.com> In-Reply-To: <20210115074533.277448-1-ankur.a.arora@oracle.com> References: <20210115074533.277448-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: 49WdknQ7WxeWsZuUmiBY1XBIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610696751; bh=v6yIlX1h7DtOp21DnEFAhGV5rtb5qUos1VM3hM6VFzs=; h=Cc:Date:From:Reply-To:Subject:To; b=UBD5rvup2+aloDIohkL9WKY5gSh+pUx0xNy1avo23krV1CIlUhhUHEuOh2kdt3Dx+Lm 2Fc2rPXv1bUTyDb8Hh26dfveTik/ly9hKCC+OqWeLpM1UC51MLCsXEVrr/JWdPh56fgDv fYQrPjCsAmFDsKZnQB3l4tS65BQhAjy7Ikg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Designate a worker CPU (we use the one executing the root MMI handler), which will do the final CPU ejection. This happens via CpuEject(). On the worker CPU, CpuEject() calls QEMU to do the ejection for each CPU that is unplugged. QEMU handles this by signalling the remote VCPU thread which forces the SMI AP to context switch out of the SMI, ending with its QEMU state destroyed. On the AP, CpuEject() spins around in its holding area until the context-switch happens. Given that the context switch would end up with the AP state being cleaned up, this means that the AP will never return to finish the SMI handling, and thus would not restore some of the CPU state that it ordinarily would (in SmiRendezvous() and in SmiEntry.nasm::CommonHandler). This unrestored state includes FPU state, CET enable, stuffing of RSB and the final RSM. Given that the CPU state is destroyed by QEMU on unplug, this should be okay. 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 | 61 ++++++++++++++++++++++++++++++++++= ---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 4048490783e4..8aa52ebe5dd1 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -266,6 +266,20 @@ UnplugCpus( ToUnplugIdx++; } =20 + if (EjectCount) { + UINTN Worker; + Status =3D mMmCpuService->WhoAmI(mMmCpuService, &Worker); + ASSERT_EFI_ERROR(Status); + // + // UnplugCpus() is called via the root MMI handler and thus we are in = the + // BSP context. Accordingly, mark ourselves as the ejecting CPU. + // Note that, the QEMU eject protocol does not specify that only the B= SP + // can do the ejection, so this should be safe on any CPU (that is not= itself + // being unplugged.) + // + mCpuHotEjectData->ApicIdMap[Worker] =3D CPU_EJECT_WORKER; + } + // // We've handled this unplug. // @@ -383,11 +397,6 @@ CpuHotplugMmi ( if (EFI_ERROR (Status)) { goto Fatal; } - if (ToUnplugCount > 0) { - DEBUG ((DEBUG_ERROR, "%a: hot-unplug is not supported yet\n", - __FUNCTION__)); - goto Fatal; - } =20 if (PluggedCount > 0) { Status =3D PlugCpus(mPluggedApicIds, PluggedCount); @@ -430,6 +439,48 @@ CpuEject( return; } =20 + if (ApicId =3D=3D CPU_EJECT_WORKER) { + UINT32 CpuIndex; + for (CpuIndex =3D 0; CpuIndex < mCpuHotEjectData->ArrayLength; CpuInde= x++) { + UINT64 RemoveApicId =3D mCpuHotEjectData->ApicIdMap[CpuIndex]; + + if ((RemoveApicId !=3D CPU_EJECT_INVALID && RemoveApicId !=3D CPU_EJ= ECT_WORKER)) { + + // + // The CPUs to be unplugged have received the BSP's signal to exit= the + // SMI and either will execute SmmCpuFeaturesSmiRendezvousExit() + // followed by this callback or are already waiting in the CpuDead= Loop() + // below. + // + // Tell QEMU to put them out of their misery. + // + QemuCpuhpWriteCpuSelector (mMmCpuIo, RemoveApicId); + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED); + + // + // Compiler memory barrier to ensure the next store isn't reorder= ed + // + MemoryFence(); + + // Clear the unplug status for CpuIndex to ensure that an invalid = SMI + // later does not end up trying to unplug it or the newly hotplugg= ed + // CpuIndex does not go into the dead loop. + // + mCpuHotEjectData->ApicIdMap[CpuIndex] =3D CPU_EJECT_INVALID; + + DEBUG ((DEBUG_INFO, "%a: Unplugged CPU " FMT_APIC_ID "\n", + __FUNCTION__, RemoveApicId)); + } + } + + // + // Clear our own CPU status to ensure that we don't needlessly enter + // the this loop on the next SMI. + // + mCpuHotEjectData->ApicIdMap[ProcessorNum] =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 --=20 2.9.3 -=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 (#70378): https://edk2.groups.io/g/devel/message/70378 Mute This Topic: https://groups.io/mt/79697149/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-