From nobody Thu Nov 14 16:47:04 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+71837+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+71837+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 1613725511698457.4757158249985; Fri, 19 Feb 2021 01:05:11 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AoH6YY1788612xiAqEjjd7yX; Fri, 19 Feb 2021 01:05:10 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.6109.1613725510374463804 for ; Fri, 19 Feb 2021 01:05:10 -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 11J93k8k178481; Fri, 19 Feb 2021 09:05:07 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36pd9ag8a3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:07 +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 11J8uDEk164199; Fri, 19 Feb 2021 09:05:06 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by userp3030.oracle.com with ESMTP id 36prq1nxha-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mgeu/x7mfG9LKbQEAEFZ+WflADdwL+3pevJRN1ZlN1E2vi58BIESkngKUOIhQB8f5B41uXHgPKv381Bch6FV1khoXA0kwXDumFt8KagfjpbWFzlAbpe/vsuNaLx5RY0CItpG2sLmUsGa4Rr6/G+Upsj7U0n+Fs1rjnCj+z4TQ+Gyx+fGS/mNqykEQlf9N9Rw9ugFj1/RnmkXdZQEkaHjOwhQP5oWnb5goL5l+2CV7YL7Y7oOLMn+RlLoyrb22D70wWEBXQmcseROKnLpDicuTtY1ftmcDQ0D0zWqre9WjehWmCLCLJjxHH+XwJq0aKepFfze2dgJwXDQlh8JaORV+w== 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=0uo5ooyNjpnvEFkbduSFlZ5FNvANd4nFffiie8dusnc=; b=AKum1F4GPEMWbXFPuLmvjXE2kDRYwWVuyTeFGuveNOBxYSTpyjYNfVjxQYF9g4kCVH+xqZvZ4kHwsezSXYI+ww5Qg+aBEaxrjXMzwrJlHh32lvdwBObbbBB31lkBKK9TNi00IziSjL3j/p/QY6aJW3/e9S4dD3bEoIhBN9A6A7tFCyLkhkd7zixMBLlhxs8HB08CDv/XALAEBWOEBray/9MmQlB2VriyZxpdpDp4Cq6ZpQTNKLrCzCV4bjN45pzE72KJ1/p7uSlfUMBkA/dhMXBGt5sDaQeVYLEINlhYxOscoDQU1qSLfjLZmdCs+xoqBMmqRfV1daMrRDnhFPEJZA== 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 SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) by BYAPR10MB3605.namprd10.prod.outlook.com (2603:10b6:a03:129::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.27; Fri, 19 Feb 2021 09:05:04 +0000 X-Received: from SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16]) by SJ0PR10MB4605.namprd10.prod.outlook.com ([fe80::a021:790:7ce6:6f16%6]) with mapi id 15.20.3868.029; Fri, 19 Feb 2021 09:05: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 v7 09/10] OvmfPkg/CpuHotplugSmm: do actual CPU hot-eject Date: Fri, 19 Feb 2021 01:04:43 -0800 Message-Id: <20210219090444.1332380-10-ankur.a.arora@oracle.com> In-Reply-To: <20210219090444.1332380-1-ankur.a.arora@oracle.com> References: <20210219090444.1332380-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.5] X-ClientProxiedBy: MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) To SJ0PR10MB4605.namprd10.prod.outlook.com (2603:10b6:a03:2d9::24) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from prion.us.oracle.com (148.87.23.5) by MWHPR13CA0004.namprd13.prod.outlook.com (2603:10b6:300:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.8 via Frontend Transport; Fri, 19 Feb 2021 09:05:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 501c566a-fcba-4591-bb8b-08d8d4b57251 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exch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=?us-ascii?Q?6BhAoiRZ1rIppDohTuLZ8wIQftNppUX+KsNi2gbEaqSW8KTdAVg81t/Dm3O6?= =?us-ascii?Q?2k7eLIw3f6WlFiKwoTZOP/oEf7XRfAk1jSpj/U45xauzsLZDltBlK1UGe/tq?= =?us-ascii?Q?Nq1XqZPuDtkDQSX+MUUXjbMD?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 501c566a-fcba-4591-bb8b-08d8d4b57251 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2021 09:05:04.7323 (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: anjttlfZDh2u/dcl+A7kwsHvan3mTHQfazNrJzgTO7LREgZIRPM/3FKvNeYYOEdfGETIZfT8CEiTeaK+q1fzkIr1uto7yKhYtdrBjyspN/Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3605 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: SHDhWpxtRhNjfrdANpAXsCYTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725510; bh=Fgnbk++XEThV/zXuIZu14dt7sT6+tELFI0PlTMotTT0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gDzqB53Fc3hr88OKIdsf9MBPlnDkMXauk8YxDC0lR3crEjlaVNOdvsclOi84dhYWIaA tVsJ6qElaG8sQ1Apr2NEqpPHJ/UiwTeV7TUC4hONVbL+KBtxtIsyCkWTXC3U+cGfyZaq3 QmYGott//OIm4y400Gp3oHevU+ibEs8L1e4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add logic in EjectCpu() to do the actual the CPU ejection. On the BSP, ejection happens by first selecting the CPU via its QemuSelector and then sending the QEMU "eject" command. QEMU in-turn signals the remote VCPU thread which context-switches the CPU out of the SMI handler. Meanwhile the CPU being ejected, waits around in its holding area until it is context-switched out. Note that it is possible that a slow CPU gets ejected before it reaches the wait loop. However, this would never happen before it has executed the "AllCpusInSync" loop in SmiRendezvous(). It can mean that an ejected CPU does not execute code after that point but given that the CPU state will be destroyed by QEMU, the missed cleanup is no great loss. 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 --- Notes: Addresses the following reviewing comments from v6: (1) s/CpuEject/EjectCpu/g (2,2a,2c) Get rid of eject-worker and related. (2b,2d) Use the PlatformSmmBspElection() logic to find out IsBSP. (3,3b) Use CPU_HOT_EJECT_DATA->QemuSelector instead of ApicIdMap to do the actual ejection. (4,5a,5b) Fix the format etc in the final unplugged log message () Also as discussed elsewhere document the ordering requirements for mCpuHotEjectData->QemuSelector[] and mCpuHotEjectData->Handler. () [from patch 2] Move definition of QEMU_CPUHP_STAT_EJECTED to this patch. () s/QEMU_CPUHP_STAT_EJECTED/QEMU_CPUHP_STAT_EJECT/ OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 1 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 122 +++++++++++++++++= ++-- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 31 ++++++ 3 files changed, 147 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/In= clude/IndustryStandard/QemuCpuHotplug.h index 2ec7a107a64d..d0e83102c13f 100644 --- a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h +++ b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h @@ -34,6 +34,7 @@ #define QEMU_CPUHP_STAT_ENABLED BIT0 #define QEMU_CPUHP_STAT_INSERT BIT1 #define QEMU_CPUHP_STAT_REMOVE BIT2 +#define QEMU_CPUHP_STAT_EJECT BIT3 #define QEMU_CPUHP_STAT_FW_REMOVE BIT4 =20 #define QEMU_CPUHP_RW_CMD_DATA 0x8 diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 5dcaca53d42f..b80d4a2283a4 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -18,6 +18,7 @@ #include // CPU_HOT_EJECT_DATA #include // EFI_MM_CPU_IO_PROTOCOL #include // EFI_SMM_CPU_SERVICE_PROTOC= OL +#include // MSR_IA32_APIC_BASE_REGISTER #include // EFI_STATUS =20 #include "ApicId.h" // APIC_ID @@ -191,12 +192,36 @@ RevokeNewSlot: } =20 /** + EjectCpu needs to know the BSP at SMI exit at a point when + some of the EFI_SMM_CPU_SERVICE_PROTOCOL state has been torn + down. + Reuse the logic from OvmfPkg::PlatformSmmBspElection() to + do that. +**/ +STATIC +BOOLEAN +CheckIfBsp ( + IN UINTN ProcessorNum + ) +{ + MSR_IA32_APIC_BASE_REGISTER ApicBaseMsr; + BOOLEAN IsBsp; + + ApicBaseMsr.Uint64 =3D AsmReadMsr64 (MSR_IA32_APIC_BASE); + IsBsp =3D (BOOLEAN)(ApicBaseMsr.Bits.BSP =3D=3D 1); + return IsBsp; +} + +/** 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 the BSP, nor being ejected, nothing + to be done. If, the executing CPU is being ejected, wait in a halted loop until ejected. + If, the executing CPU is the BSP, set QEMU CPU status to eject + for CPUs being ejected. =20 @param[in] ProcessorNum ProcessorNum denotes the CPU exiting SMM, and will be used as an index into @@ -211,9 +236,97 @@ EjectCpu ( ) { UINT64 QemuSelector; + BOOLEAN IsBsp =3D CheckIfBsp (ProcessorNum); =20 + // + // mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is updated + // on the BSP in the ongoing SMI iteration at two places: + // + // - UnplugCpus() where the BSP determines if a CPU is under ejection + // or not. As the comment where mCpuHotEjectData->Handler is set-up + // describes any such updates are guaranteed to be ordered-before the + // dereference below. + // + // - EjectCpu() on the BSP updates QemuSelectorMap[ProcessorNum] for + // CPUs after they have been hot-ejected. + // + // The CPU under ejection: might be executing anywhere between the + // "AllCpusInSync" exit loop in SmiRendezvous() to about to + // dereference QemuSelectorMap[ProcessorNum]. + // Given that the BSP ensures that this store only happens after the + // CPU has been ejected, this CPU would never see the after value. + // (Note that any CPU that is already executing the CpuSleep() loop + // below never raced any updates and always saw the before value.) + // + // CPUs not-under ejection: never see any changes so they are fine. + // + // Lastly, note that we are also guaranteed that any dereferencing + // CPU only sees the before or after value and not an intermediate + // value. This is because QemuSelectorMap[ProcessorNum] is aligned at + // a natural boundary. + // QemuSelector =3D mCpuHotEjectData->QemuSelectorMap[ProcessorNum]; - if (QemuSelector =3D=3D CPU_EJECT_QEMU_SELECTOR_INVALID) { + if (QemuSelector =3D=3D CPU_EJECT_QEMU_SELECTOR_INVALID && !IsBsp) { + return; + } + + if (IsBsp) { + UINT32 Idx; + + for (Idx =3D 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) { + UINT64 QemuSelector; + + QemuSelector =3D mCpuHotEjectData->QemuSelectorMap[Idx]; + + if (QemuSelector !=3D CPU_EJECT_QEMU_SELECTOR_INVALID) { + // + // This to-be-ejected-CPU has already received the BSP's SMI exit + // signal and, will execute SmmCpuFeaturesRendezvousExit() + // followed by this callback or is already waiting in the + // CpuSleep() loop below. + // + // Tell QEMU to context-switch it out. + // + QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32) QemuSelector); + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECT); + + // + // We need a compiler barrier here to ensure that the compiler + // does not reorder the CpuStatus and QemuSelectorMap[Idx] stores. + // + // A store fence is not strictly necessary on x86 which has + // TSO; however, both of these stores are in different address spa= ces + // so also add a Store Fence here. + // + MemoryFence (); + + // + // Clear the eject status for this CPU Idx to ensure that an inval= id + // SMI later does not end up trying to eject it or a newly + // hotplugged CPU Idx does not go into the dead loop. + // + mCpuHotEjectData->QemuSelectorMap[Idx] =3D + CPU_EJECT_QEMU_SELECTOR_INVALID; + + DEBUG ((DEBUG_INFO, "%a: Unplugged ProcessorNum %u, " + "QemuSelector 0x%Lx\n", __FUNCTION__, Idx, QemuSelector)); + } + } + + // + // We are done until the next hot-unplug; clear the handler. + // + // By virtue of the MemoryFence() in the ejection loop above, the + // following store is ordered-after all the ejections are done. + // (We know that there is at least one CPU hot-eject handler if this + // handler was installed.) + // + // As described in OvmfPkg::SmmCpuFeaturesRendezvousExit() this + // means that the only CPUs which might dereference + // mCpuHotEjectData->Handler are not under ejection, so we can + // safely reset. + // + mCpuHotEjectData->Handler =3D NULL; return; } =20 @@ -496,11 +609,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); diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index c5cfe2610c23..0345466ac5a5 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -472,6 +472,37 @@ SmmCpuFeaturesRendezvousExit ( // (PcdCpuMaxLogicalProcessorNumber > 1), and hot-eject is needed // in this SMI exit (otherwise mCpuHotEjectData->Handler is not armed.) // + // mCpuHotEjectData itself is stable once setup so it can be + // dereferenced without needing any synchronization, + // but, mCpuHotEjectData->Handler is updated on the BSP in the + // ongoing SMI iteration at two places: + // + // - UnplugCpus() where the BSP determines if a CPU is under ejection + // or not. As the comment where mCpuHotEjectData->Handler is set-up + // describes any such updates are guaranteed to be ordered-before the + // dereference below. + // + // - EjectCpu() (which is called via the Handler below), on the BSP + // updates mCpuHotEjectData->Handler once it is done with all ejection= s. + // + // The CPU under ejection: might be executing anywhere between the + // "AllCpusInSync" exit loop in SmiRendezvous() to about to + // dereference the Handler field. + // Given that the BSP ensures that this store only happens after all + // CPUs under ejection have been ejected, this CPU would never see + // the after value. + // (Note that any CPU that is already executing the CpuSleep() loop + // below never raced any updates and always saw the before value.) + // + // CPUs not-under ejection: might see either value of the Handler + // which is fine, because the Handler is a NOP for CPUs not-under + // ejection. + // + // Lastly, note that we are also guaranteed that any dereferencing + // CPU only sees the before or after value and not an intermediate + // value. This is because mCpuHotEjectData->Handler is aligned at a + // natural boundary. + // =20 if (mCpuHotEjectData !=3D NULL) { CPU_HOT_EJECT_HANDLER Handler =3D mCpuHotEjectData->Handler; --=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 (#71837): https://edk2.groups.io/g/devel/message/71837 Mute This Topic: https://groups.io/mt/80751401/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-