From nobody Thu Nov 14 17:08:35 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+70874+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+70874+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 1611882077855585.2182268156394; Thu, 28 Jan 2021 17:01:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id khBZYY1788612xpfC6Rde9ni; Thu, 28 Jan 2021 17:01:17 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web09.3202.1611882071984432895 for ; Thu, 28 Jan 2021 17:01:12 -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 10T0eplt064441; Fri, 29 Jan 2021 01:01:09 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 368brkxs9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:01:09 +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 10T0dtF1084478; Fri, 29 Jan 2021 01:01:08 GMT X-Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by userp3020.oracle.com with ESMTP id 368wjutpvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Jan 2021 01:01:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cm68AqGZGw//plVfF/Y0m9jMLrEsabv+Jf7msq6JoapvuAvAJ1MjDRr/81Np0gbINPlYB6Qz8y+ugW6w/oQn+ObYMKkCQMB6vJLYV/DUpKX82gqRcwVGnlERZwemCRwmLGu0vPwTomTWCbywZE7BpYHw0gBuZcVAApR8fOsDb8mdeFx+FE1TzhqFwh8rq1ztO4MTCaKtdDu8LWRc+koeTNFXUIFgEILOByyWtZ1U0l64Z2WCm4HfVxQL+ADjWSZmAT7+4tylc3y7g/xFXZcVr/ScEJgJ4f/CSli9Kr/dhRQe+AfYsr5lFNvakjlGOsWusP1/3s3VyDw1/q+hvil9dQ== 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=JCwKS/cvEanE1H3hBiZcnWxV/RiXa5isy4L/1PprdC0=; b=GU7AXLY1dW4C3JY2jjJ+lw3jiB9Z0GBP28Tk+9QVIcs0PG6cP+DpjG7pxAknD8aXl7Q5vtDLp7Z8rQUg0+JRlDc+BkBgB/QHNevDPoClrbkVV42ITurri2QKpwrNkwQt9kLI7fSth92Rzr64jGTN8gCoxaXNvyJL6TOxkCzpeAzff03dTfAJYiI/x2TR3mPADtqwlS+ocT5ki5F4Xj+Mq6zQtXA2FnR/C6GbYmrMYfcFotZBCJ3lN0Hm0dVEBZ0mMMH1FBw2gQ7pt+4lUbF19IHwQtSXFivMvRDshbb7YKybz5cHo+HEQEVl9IYjDAJsCDDWRTV8+xQf9vXX10QFbA== 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 CY4PR1001MB2246.namprd10.prod.outlook.com (2603:10b6:910:41::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.16; Fri, 29 Jan 2021 01:01:04 +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.3805.019; Fri, 29 Jan 2021 01:01:04 +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 v6 8/9] OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection Date: Thu, 28 Jan 2021 16:59:49 -0800 Message-Id: <20210129005950.467638-9-ankur.a.arora@oracle.com> In-Reply-To: <20210129005950.467638-1-ankur.a.arora@oracle.com> References: <20210129005950.467638-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.8] X-ClientProxiedBy: MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from prion.us.oracle.com (148.87.23.8) by MWHPR1401CA0022.namprd14.prod.outlook.com (2603:10b6:301:4b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.17 via Frontend Transport; Fri, 29 Jan 2021 01:00:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c12de2ec-cc4e-4d07-f023-08d8c3f138df X-MS-TrafficTypeDiagnostic: CY4PR1001MB2246: 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: HlklQwGDx+sOxIISa3ler/tnNd7RFDlP5pYVYIl0AERY7sQzYpFe2vDsjd/agkcJyofBwSQpVdcvke0BFe5kdjNRjsnLKjbtifRVdrsl3KL+cp8oMpwrL8s5AUd6iArEmzdedbfxiHnuUoInegQaIhlTabVq/ddbLjbESpamHFu91d6WLHXpzQqHDhWZeS3MCMsqmsdXL59ZT0zJ54POvld4wuNzIOBaUfblBQkCtR3RbYin47FXUsxbT7IQJLe3Z52WE43bB1ZhfpNdOjeGiCEnT8qwLytPY7eWOG17YG5SU4P2hvbUEbH3xAK/T4GkS0R82iizfokf0Qa9THbYjuY6a0dVZi9gZHcxS/rr5V5m7f6iSdee0e7zgl4Fc2TxxHqw8YwPn//vI8A29DSURk9i5bsWW5Rz7fMmF1XwxMOapVoZ9ZbL+MPkXyPCnu+HJzU2hYBhUjM7a9mox4AD68JYV5ZHnM1ceS2NrgZBrVfaYiqGcTl2VB6lmRluFSpQQMH7oCcjcovT6jzSqLRIqwHiP7OixU9K/6TIbi2jn4k7QrtqA7+OWPfQe967beuGqFuQ+OYB3tS6JnyL3N/o3D4WVUGTi4EZpDSMTLkzLIk= X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?qn0ehnigrCcA7VLK6uGGuW7cWw1kxy3l4SMcS18Uaz1GjQdo87Yz3a8oEV76?= =?us-ascii?Q?H+sR0CbT3OShOEco09LuNJV8XmMemZXBFxuZY1uxM/cxX5im7O6raUr6UcND?= =?us-ascii?Q?XyjLLMtwCU0MHymBsqLKCNP+IQGz+gzwXhD9FQ7fYCLppNxx9+1hSNQyOo8Q?= =?us-ascii?Q?sV2kmvTJlIvzOsUtqRO+cISJPR6Yo4Aq5SLHjoXBQlrvTugKzgNWjxsPPthn?= =?us-ascii?Q?BQXk8Icgb1aeKYiCRRrR4qPkvm5GcPSqp+7HWmIq1twpoGB7bJbptnhg+fAK?= =?us-ascii?Q?dQGRR9as+reVhOzAn+hGDxCKaETLwLJK7TKa8Q6Wtl6wrw61df6moN5EOEHg?= =?us-ascii?Q?EDwIHa2gyvx2FlXgfs1gQCGHlpEKmK0ZD9mqv3DTSB3T1bNJjTInjUcmHCPO?= =?us-ascii?Q?w/cNAESW2yIsxquQYfPgoBcRyUFhYW2b3TAcOK/Cjw5D0qe9k2HpZmTTwLNM?= =?us-ascii?Q?X6Y8zdRTPL3FOViSg3wiW/KBzOhZ4+f559W1f31+AAEe96nAIcxHUOu7YsHP?= =?us-ascii?Q?mwB4Nud/oiMGCjpqkY+4HP0QufTF5brKugDn7m4SHpwvDPzX7V7fyw1av8yl?= =?us-ascii?Q?+kADqQ96p8VB2SktnrOgoEBX9ASU5WKP7HWsM5Q5h2Ensh1tIj+lKeMx03XP?= =?us-ascii?Q?9IaISIjFTDYHmQRFYF9TL8UoNDi6f+c508v1QnNT7AoQDympYZTwSDgJ46MU?= =?us-ascii?Q?pFowWWC8DpRcoa5yNZlG9umx8PthlxxbBbDmmlap0aV0j5bX5vrIcVYLgOxz?= =?us-ascii?Q?i8v4GkULx08DpXIJWGPGTXsqGovpIOlsJzBuJHbKtkfpxoXmrHjxMX1iu1Mv?= =?us-ascii?Q?vBl62IalMHBSPk42bwQivodhsuVIPGNrFmGnHxdPZqjoCCCzlh4L3Jhn4lI1?= =?us-ascii?Q?Y8KLTfX0mHp/6XJY3dMOmsmpXL2iy83Tz5Y5va4NyklSbGHxmUKF0xwz4X4Y?= =?us-ascii?Q?+S1bFQGkqpXyBGKALZ3moMdd4E56cAfz90PDe8n3EZi30tpKYd2oDRyjJgjU?= =?us-ascii?Q?CjcTs+u2yplnqJJYR6LjQE51u9SsgXhNdwrrJq+7fYT0SBrv6yGXGC/GXSTO?= =?us-ascii?Q?qfJCmo+I?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c12de2ec-cc4e-4d07-f023-08d8c3f138df X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jan 2021 01:00:08.5218 (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: elx558NLx7BawA20Ume7sl9zyaUeyTP772QEn0+5hu+lFwqoNrPisVAu9SEhkqJpbKiayDBWUCfKCyBftpgd6VUMtc7ZTAxnWnZzDNjsQEw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1001MB2246 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: DIeFLGUF8rkIAzHOKTV0qfaex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611882077; bh=Ffi3VXM/fJq3qdBQu+GuwzwA3ag8xZI7puyYtoLtxNc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qcuCNb50zf2eho6Fqd/M5F74tBx7eJSJ1/SX9gzLT/ECHOj7v60YXDiZ9sZ4o77nBoB 2LThhajxIhWB7OmbTYCKS7A44QsDXMNBrmCw8icIT4CuWP5s7c5zgyCVRGn52ms2dhPK1 H706otH2FNYAcdpGHI8wrtlJVSyEI3KBDsY= 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 526f51faf070..bf91344eef9c 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -193,9 +193,12 @@ RevokeNewSlot: CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit(), on each CPU at exit from SMM. =20 - If, the executing CPU is not being ejected, nothing to be done. + If, the executing CPU is neither a worker, nor being ejected, nothing + to be done. If, the executing CPU is being ejected, wait in a CpuDeadLoop() until ejected. + If, the executing CPU is a worker CPU, set QEMU CPU status to eject + for CPUs being ejected. =20 @param[in] ProcessorNum Index of executing CPU. =20 @@ -217,6 +220,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 @@ -327,6 +380,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. // @@ -451,11 +517,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 ProcessHotAddedCpus (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 (#70874): https://edk2.groups.io/g/devel/message/70874 Mute This Topic: https://groups.io/mt/80199930/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-