From nobody Thu Nov 14 16:50:18 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+70767+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+70767+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=oracle.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1611643511955569.6181809104975; Mon, 25 Jan 2021 22:45:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id hIQJYY1788612xQ3P5Duc2eW; Mon, 25 Jan 2021 22:45:11 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.8844.1611643506063631436 for ; Mon, 25 Jan 2021 22:45:06 -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 10Q6Z9xQ058326; Tue, 26 Jan 2021 06:45:01 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 3689aagu16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:01 +0000 X-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10Q6a689097113; Tue, 26 Jan 2021 06:45:00 GMT X-Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by userp3030.oracle.com with ESMTP id 368wqw1qcn-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:45:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iAmESYs36oaizAZTXCxENgYyZTMc7RtQ6SF8d232z8yr5MQ6zQz4lRKGISPXetp/k5c8gcftW32ddBVNyTA6sDR89z094HQNa+Ih5z0UEQ7wZSqaLiEZbz270VFE1Atj5HZlbTYF/zrtS2iL2vs6PNFoU8LWizrYgzNPXS/3+66xBaNf95dmrJfpXKtp+YNzZtyOFqhgfsV6ZK4HMq+3tjV3ud1IdKOvufxfZLNmIAwFYgO84SRNE+vyvCuzsGD5VXp0c7VDAgV0baAeNemjOi/mcPszO4X/LsGXpVv0QV3uLDQwBPR1xREKrcJyTZdX3MrMO4LHGTpr338+FJy5Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L1gPodx8KoROTcPRXS118SD00ecs41MWalErPdya0ZY=; b=T8J5/cM1v7Od4euBX/WcAyabzmRQ7ST9opNWclXSl4UfxCYMnowg1MPiOBXrx4FrQXwvWq2XiXr+BO2Xjc/PPCRKZ2DVMXirPn5gbkUCDxuIccMslCCh+OpiTpkndm++C4ZQZ6dRj3QwthoTkSgJPrhJIMJhwN0qUWvFv1UGspI3cAoDqmpytdPY9f6miQI8xpLotjx7Vq2Kw9d+wnIgrkbqKjW/KaxoBkUznaf0/PNr4DevCNkdIAi2n40dPCEw0yhFtT0LLAiZTKFWYx5zWbC5x6i0ii3a5YEKCfiXq3e1rUmZAB2yHRrHaNurMDYn7LNwQCQVtTDP/JgkrUf8nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) by CY4PR1001MB2184.namprd10.prod.outlook.com (2603:10b6:910:45::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.14; Tue, 26 Jan 2021 06:44:59 +0000 X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6]) by CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6%6]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 06:44:59 +0000 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: [edk2-devel] [PATCH v5 8/9] OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection Date: Mon, 25 Jan 2021 22:44:39 -0800 Message-Id: <20210126064440.299596-9-ankur.a.arora@oracle.com> In-Reply-To: <20210126064440.299596-1-ankur.a.arora@oracle.com> References: <20210126064440.299596-1-ankur.a.arora@oracle.com> X-Originating-IP: [70.36.60.91] X-ClientProxiedBy: MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from localhost.localdomain (70.36.60.91) by MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Tue, 26 Jan 2021 06:44:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e282034-7316-467a-747d-08d8c1c5e452 X-MS-TrafficTypeDiagnostic: CY4PR1001MB2184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: wzIKhLbUKKROs7SL2KXIcHwWPUlQ58FClqVwr9FSVaIcBGH4YtS0cCzqICKKQq1VQ2ee+l8XUHL1nulHPp48x+Ylk9UIdC6TlgfGUGYc4HOIDGGrW99OlThrwsefmeXimyHzSt72m5YT7bbcm5+qDw4y+uhodfd8SIhD3xSSAE3PSTDH24ywNkzgTfmJ0t4E7ecqyhVpuicTnNZuqYgZQSIH4KOsWl3sKKvdvu3kZgSPTQosMA1can0tuq6GgP1kRX8DH5K0yV41E8k2zt+8iUZqPDPvWER8SF3UGQP8Bt36OMw5qLs3WbVGIeEWcU6e875xXD9TKnkk10TE82l4lSrg5hkizkxkhoSph9sasjzXqPprHrvVM/FrJ6r7ISPsUjMTDC6zmiH4LHBH/YMaBYnJPurKTnblmpYYO847I3jfvGrrawtLV4cNZPMKgex44UMCpIOc08HQESsJtwuj9rhOpexOlSkSqgcBh539n18K80cVmph0/2I5QE4byQxu3PpwfC0aguNiKczP0ggjqg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?u9s+y5TE87QrK/omzEb5BIImq//eiEGhPFJuqLJWkfW3CirV80XJ+oap6Yer?= =?us-ascii?Q?DP6Z/FP9iJeIHdU36lQgQKzZafFSzF4F3YQCvPrFwOdXeTCynU125NHjSRix?= =?us-ascii?Q?vX5Cf1g7WvfdXV7ke8FvfNUXX11cBb6B2K3gWljZbdpRUfAiO89//RQEbM1g?= =?us-ascii?Q?/36LE6ecOA3rkztBrKL5qULgS5yNfVp5fDV7eibZ9S0qCBGjzedGumKiyl1b?= =?us-ascii?Q?uukdq78MUR4XhsUXhffniXqhlHAsgjIuUXiBMn/hifBMzL3Nzulan3JJkgMu?= =?us-ascii?Q?MruQmBKdlSmMQudxUCDTSZ7K2zP00wshxtnARpH+p2J5bKT+KUnjK/k68DoH?= =?us-ascii?Q?q39OyT9NED8YPfLhMh4stLLdcVHS2ayPbcKNMQ1YYcHgJw4F2c6mAeSBulkW?= =?us-ascii?Q?Vhb3ARPFqcEmt6EfjbXejWZefTmPbZTQ8K3SQsI+gssskUAofnEHtg8afEFA?= =?us-ascii?Q?4dOOIbren760nLkqfS7UAAAyTvhYseQbIOgCgbC9cyanC8INmnayuZDiLj7e?= =?us-ascii?Q?ppTdyVbaEu4zaUsKznFARcqZo/jBsliuOt5HH06IDfNEeu71OkDJJX5xYYc7?= =?us-ascii?Q?E/P0xVtoFXqKwan61om9WB1Kqoznxu268R8k/T1IKZVmDdTTZGOpSaoCOoRx?= =?us-ascii?Q?nLsxKyfvLb88CvWyiH8aT9QDri1VvbDmkOurl3z5UIEe50AtO41XZHSt9nSX?= =?us-ascii?Q?bZNFS9Hwbu7+JNPQUMgwZRnFl0xJc9m9FcJhe2uRsYXJGGhi/5j+dIbYVI/X?= =?us-ascii?Q?u+DxYRtjzE68POoThTqbbke5zJ8H7G0yDkFrHqmblw161KenvDV2tGlGTZa3?= =?us-ascii?Q?XClrIpQLeXI27aqvoRG8c5tr64ZuaxPRz4D3pcLf3L58aZwycTcjea0P3e8l?= =?us-ascii?Q?8/xlof/hVdKUfIslCtluFPgM21+vYMUo91tJivdyHkKEc/kV8MSKTJwXceXV?= =?us-ascii?Q?1CZTo559OWV1giXqzZtnGeEghvG5TzCQuPZ/06pEbJDXvMg88yaCHJp/GZ3R?= =?us-ascii?Q?aKj8Ptry5wopaOfQ+iW58HJD6quDCjFbc/IYamhgtRV+soOVdEafr7vBTiXG?= =?us-ascii?Q?y1l90h9E?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e282034-7316-467a-747d-08d8c1c5e452 X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 06:44:55.9860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XrVcoYnP3JGB7/Kg853XSidEq4XZuP9ibtOxOcLHqqsZKHfo2dBQoPh5CB69UV5nTVpwjYj2LrcjwStYlJGZgzHqK3Aj8dZ8IMngJGW2eBI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2184 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: pZZONDy2jSDzeLrJAVgiwIxnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611643511; bh=lyWKZcWTPh3dby+udOQCPL28jC1M/UBAUqjDFGR0OU0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=f/DGY35m5o7aiURwfOnG+1Ak3Pd8Avxky3YYYLrgE5sMLBUTia2LfAHcc1JZ5ZmjB6G Bjv6hHxYtQZxbYY+FeQJvc6IgYm9aoQ+aV7AKhzl22Gk3ib/+PCjJBJbYNfxIANQFHjzv m80gwfOTjBOCtLkOgIxcCs7R0AMw5wUZHEA= 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 actual ejection via QEMU in CpuEject(). CpuEject(), on the worker CPU, ejects each marked CPU by first selecting its APIC ID and then sending the QEMU "eject" command. QEMU in-turn signals the remote VCPU thread which context-switches it out of the SMI. CpuEject(), on the CPU being ejected, spins around in its holding area until this final context-switch. This does mean that there is some CPU state that would ordinarily be restored (in SmiRendezvous() and in SmiEntry.nasm::CommonHandler), but will not be anymore. This unrestored state includes FPU state, CET enable, stuffing of RSB and the final RSM. Since the CPU state is destroyed by QEMU, 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 | 73 ++++++++++++++++++++++++++++++++++= ---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 99e6845a12d9..d4e27d641dc5 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -186,10 +186,13 @@ Fatal: /** CPU Hot-eject handler function. =20 - If the executing CPU is not being ejected: NOP. + If the executing CPU is neither a worker, nor being ejected: NOP. If the executing CPU is being ejected: wait in a CpuDeadLoop() until ejected. =20 + If the executing CPU is a worker CPU: set QEMU Cpu status to eject + for CPUs being ejected. + @param[in] ProcessorNum Index of executing CPU. **/ VOID @@ -209,6 +212,56 @@ CpuEject( return; } =20 + if (ApicId =3D=3D CPU_EJECT_WORKER) { + UINT32 CpuIndex; + + for (CpuIndex =3D 0; CpuIndex < mCpuHotEjectData->ArrayLength; CpuInde= x++) { + UINT64 RemoveApicId; + + RemoveApicId =3D mCpuHotEjectData->ApicIdMap[CpuIndex]; + + if ((RemoveApicId !=3D CPU_EJECT_INVALID && + RemoveApicId !=3D CPU_EJECT_WORKER)) { + // + // This to-be-ejected-CPU has already received the BSP's SMI exit + // signal and, will execute SmmCpuFeaturesSmiRendezvousExit() + // followed by this callback or is already waiting in the + // CpuDeadLoop() below. + // + // Tell QEMU to context-switch it out. + // + QemuCpuhpWriteCpuSelector (mMmCpuIo, (APIC_ID) RemoveApicId); + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED); + + // + // Compiler barrier to ensure the next store isn't reordered + // + MemoryFence(); + + // + // Clear the eject status for CpuIndex to ensure that an invalid + // SMI later does not end up trying to eject it or a newly + // hotplugged CpuIndex does not go into the dead loop. + // + mCpuHotEjectData->ApicIdMap[CpuIndex] =3D CPU_EJECT_INVALID; + + DEBUG ((DEBUG_INFO, "%a: Unplugged CPU %u -> " FMT_APIC_ID "\n", + __FUNCTION__, CpuIndex, RemoveApicId)); + } + } + + // + // Clear our own worker status. + // + mCpuHotEjectData->ApicIdMap[ProcessorNum] =3D CPU_EJECT_INVALID; + + // + // We are done until the next hot-unplug; clear the handler. + // + mCpuHotEjectData->Handler =3D NULL; + return; + } + // // CPU(s) being unplugged get here from SmmCpuFeaturesSmiRendezvousExit() // after having been cleared to exit the SMI by the monarch and thus have @@ -306,6 +359,19 @@ UnplugCpus( } =20 if (EjectCount !=3D 0) { + UINTN Worker; + + Status =3D mMmCpuService->WhoAmI(mMmCpuService, &Worker); + ASSERT_EFI_ERROR(Status); + // + // UnplugCpus() is called via the root MMI handler and thus we are + // executing in the BSP context. + // + // Mark ourselves as the worker CPU. + // + ASSERT (mCpuHotEjectData->ApicIdMap[Worker] =3D=3D CPU_EJECT_INVALID); + mCpuHotEjectData->ApicIdMap[Worker] =3D CPU_EJECT_WORKER; + // // We have processors to be ejected; install the handler. // @@ -429,11 +495,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); --=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 (#70767): https://edk2.groups.io/g/devel/message/70767 Mute This Topic: https://groups.io/mt/80125315/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-