From nobody Thu Nov 14 22:52:58 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+72704+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+72704+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 161553044398527.721356309728208; Thu, 11 Mar 2021 22:27:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 904xYY1788612xmulHgYcM5w; Thu, 11 Mar 2021 22:27:23 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web10.4847.1615530434239456035 for ; Thu, 11 Mar 2021 22:27:14 -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 12C6APDJ139263; Fri, 12 Mar 2021 06:27:10 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 373y8c14as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:10 +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 12C6PY05079482; Fri, 12 Mar 2021 06:27:09 GMT X-Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam07lp2040.outbound.protection.outlook.com [104.47.56.40]) by userp3030.oracle.com with ESMTP id 374kp243k0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Mar 2021 06:27:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eYKDeq+Lbg9RKU9gXN6rNQHJFIgNorFgkFxkbdFoQKRNT4F55abpc71uvVdUUGPcyhVM514c95LNQG8LJg025MR7unW8ilr4iGGUpJ36DUmPCAVBBcwb+9U/+KowmUIw5qP2DZPBE6OyLg4DVQzs/V+Ku8BiFcZDZvXJhEY4JYwhDz/XqrZE/88NLW9H+7ow0z4x6R/DL7GmXRBhUEKP9WDuKx40y5UegfAulTIO9fR5tDHfgBl2qDk3lo9KV0IOt/n5Ve68ew8mgGt2KkYGgcTKY2WlrjCH15kUWzoVDGSwzFaJEM+/2ys33lrngilbMaew3l+4RhGsL45Kym1/0A== 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=IyGh2hGyPNEI+2m0OrCnDZEcNOlJaF8tmhqHfhD22sw=; b=iCCxKdWB6145wB6qoYqUHg7bbECs5FfVnyrQ8g4nQaBwL9SuiR9zdpAWzLNphnJ6ISZkOEVPww8vBjDbeGu8wOt7nujgAqUbC07qlsZh6OxCvoXzAm57wrmkWf98RqWq6G30l7kyx1Qtx7s6AnYJ0F3q2yf4o3/9wNt+Y9Gdy1eKiNG4gSlTHMpg5oQOEFK0KbiUbIFMsxKBwBWmFym79pqhC/H57z/5+NBzKHHCjGidEfyX8ufeoPW6fQPQBoiopV3C3+qYAZO3v+7D6tKqHJ4h+MXJoJVABcRRwkTX9IOtGPRe1OJ5bfaBdkkUzIkMHZzG1803FJuDkZuW3PyyiA== 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 BYAPR10MB3191.namprd10.prod.outlook.com (2603:10b6:a03:14f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.24; Fri, 12 Mar 2021 06:27:08 +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.3912.030; Fri, 12 Mar 2021 06:27:08 +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 v9 02/10] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Thu, 11 Mar 2021 22:26:48 -0800 Message-Id: <20210312062656.2477515-3-ankur.a.arora@oracle.com> In-Reply-To: <20210312062656.2477515-1-ankur.a.arora@oracle.com> References: <20210312062656.2477515-1-ankur.a.arora@oracle.com> X-Originating-IP: [148.87.23.12] X-ClientProxiedBy: MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) 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.12) by MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 06:27:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8d8cd79d-535d-4d3f-3777-08d8e51fdc65 X-MS-TrafficTypeDiagnostic: BYAPR10MB3191: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:167; X-MS-Exchange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us-ascii?Q?ggfETtJ75W9dDxSi8ydRgabdOJrQToC7hAte5pVsYKR/YTrBliG+n7zitGtM?= =?us-ascii?Q?Wc8W9s9hVJoau7AOkEdA8XdAudzMSEnkaD1zQlrcV6naW1LLTcsIIZnacOYL?= =?us-ascii?Q?aqqK0hV2w1FdgQoH9W2RxWTs?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d8cd79d-535d-4d3f-3777-08d8e51fdc65 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB4605.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 06:27:07.9184 (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: TCOokEFuHjku8skuLqr2dqmJCXO+Ziodff4RZ2zsTqFQJBO9+J/CvrtRoDq/Nqv+Rhm7EHYoa3ZOzQlBkQ3fJFot+DG5MyAXVmioZMtQ9G0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3191 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: YdFTCSruovMHafKhtk7mbkTTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1615530443; bh=HNobZkkDv/RpZLS/MZHDKcA/wN6+JA08Wv/wg/MAYec=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PotlkIH2QyQxYFJyKon4nw9eI2UqUjW0b/IRKIWyhjwzz7kNkJM/JuhQhiuE6FZaE99 /zo/cQZ0k95C90OjV9MqE+ef2dPMM6Kcbd8ipa6UixAbo+/2dn2laMz7R8f+LJNzmiTd0 +vGW25ksmwTYpi7BdpoRLaujjrOX24zZCx4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Process fw_remove events in QemuCpuhpCollectApicIds(), and collect APIC IDs and QEMU CPU Selectors for CPUs being hot-unplugged. In addition, we now ignore CPUs which only have remove set. These CPUs haven't been processed by OSPM yet. This is based on the QEMU hot-unplug protocol documented here: https://lore.kernel.org/qemu-devel/20201204170939.1815522-3-imammedo@redh= at.com/ 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 Reviewed-by: Laszlo Ersek --- Notes: Addresses the following comments from v8: (1) Fix commit message to mention that we collect cpu-selectors as we= ll. (2,3,6) s/UnplugSelector/UnplugSelectors/ in CpuHotplug.c, QemuCpuhp.c (4) Fix comment above the declaration of the now renamed mToUnplugSel= ector. (5) Fix spacing around "||". (7) Fix QemuCpuCollectApicIds() comments to line up descriptions for ToUnplugSelectors and other params. (8) s/ExtendSel/ExtendSels/. (9) Add the (ExtendSels =3D> ExtendIds) assert. (10) Fix the missing CurrentSelector++ bug. OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 1 + OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 1 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 29 +++++-- OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 101 +++++++++++++++---= ---- 4 files changed, 93 insertions(+), 39 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.h index 8adaa0ad91f0..3e2c2192e1c0 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h @@ -55,6 +55,7 @@ QemuCpuhpCollectApicIds ( OUT APIC_ID *PluggedApicIds, OUT UINT32 *PluggedCount, OUT APIC_ID *ToUnplugApicIds, + OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugCount ); =20 diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/In= clude/IndustryStandard/QemuCpuHotplug.h index a34a6d3fae61..2ec7a107a64d 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_FW_REMOVE BIT4 =20 #define QEMU_CPUHP_RW_CMD_DATA 0x8 =20 diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index bf68fcd42914..ee1497b93140 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -45,13 +45,16 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; // don't want to allocate SMRAM at OS runtime, and potentially fail (or // fragment the SMRAM map). // -// These arrays provide room for ("possible CPU count" minus one) APIC IDs -// each, as we don't expect every possible CPU to appear, or disappear, in= a -// single MMI. The numbers of used (populated) elements in the arrays are +// The first array stores APIC IDs for hot-plug events, the second and the +// third store APIC IDs and QEMU CPU Selectors (both indexed similarly) for +// hot-unplug events. All of these provide room for "possible CPU count" m= inus +// one elements as we don't expect every possible CPU to appear, or disapp= ear, +// in a single MMI. The numbers of used (populated) elements in the arrays= are // determined on every MMI separately. // STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mToUnplugApicIds; +STATIC UINT32 *mToUnplugSelectors; // // Address of the non-SMRAM reserved memory page that contains the Post-SM= M Pen // for hot-added CPUs. @@ -289,6 +292,7 @@ CpuHotplugMmi ( mPluggedApicIds, &PluggedCount, mToUnplugApicIds, + mToUnplugSelectors, &ToUnplugCount ); if (EFI_ERROR (Status)) { @@ -333,7 +337,9 @@ CpuHotplugEntry ( ) { EFI_STATUS Status; + UINTN Len; UINTN Size; + UINTN SizeSel; =20 // // This module should only be included when SMM support is required. @@ -387,8 +393,9 @@ CpuHotplugEntry ( // // Allocate the data structures that depend on the possible CPU count. // - if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Size))= || - RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Size, &Size))) { + if (RETURN_ERROR (SafeUintnSub (mCpuHotPlugData->ArrayLength, 1, &Len)) = || + RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), Len, &Size)) || + RETURN_ERROR (SafeUintnMult (sizeof (UINT32), Len, &SizeSel))) { Status =3D EFI_ABORTED; DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__)); goto Fatal; @@ -405,6 +412,12 @@ CpuHotplugEntry ( DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s)); goto ReleasePluggedApicIds; } + Status =3D gMmst->MmAllocatePool (EfiRuntimeServicesData, SizeSel, + (VOID **)&mToUnplugSelectors); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s)); + goto ReleaseToUnplugApicIds; + } =20 // // Allocate the Post-SMM Pen for hot-added CPUs. @@ -412,7 +425,7 @@ CpuHotplugEntry ( Status =3D SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, SystemTable->BootServices); if (EFI_ERROR (Status)) { - goto ReleaseToUnplugApicIds; + goto ReleaseToUnplugSelectors; } =20 // @@ -472,6 +485,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices); mPostSmmPenAddress =3D 0; =20 +ReleaseToUnplugSelectors: + gMmst->MmFreePool (mToUnplugSelectors); + mToUnplugSelectors =3D NULL; + ReleaseToUnplugApicIds: gMmst->MmFreePool (mToUnplugApicIds); mToUnplugApicIds =3D NULL; diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 8d4a6693c8d6..8434dd446b96 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -145,27 +145,30 @@ QemuCpuhpWriteCommand ( =20 On error, the contents of the output parameters are undefined. =20 - @param[in] MmCpuIo The EFI_MM_CPU_IO_PROTOCOL instance for - accessing IO Ports. + @param[in] MmCpuIo The EFI_MM_CPU_IO_PROTOCOL instance for + accessing IO Ports. =20 - @param[in] PossibleCpuCount The number of possible CPUs in the system. = Must - be positive. + @param[in] PossibleCpuCount The number of possible CPUs in the system= . Must + be positive. =20 - @param[in] ApicIdCount The number of elements each one of the - PluggedApicIds and ToUnplugApicIds arrays c= an - accommodate. Must be positive. + @param[in] ApicIdCount The number of elements each one of the + PluggedApicIds and ToUnplugApicIds arrays= can + accommodate. Must be positive. =20 - @param[out] PluggedApicIds The APIC IDs of the CPUs that have been - hot-plugged. + @param[out] PluggedApicIds The APIC IDs of the CPUs that have been + hot-plugged. =20 - @param[out] PluggedCount The number of filled-in APIC IDs in - PluggedApicIds. + @param[out] PluggedCount The number of filled-in APIC IDs in + PluggedApicIds. =20 - @param[out] ToUnplugApicIds The APIC IDs of the CPUs that are about to = be - hot-unplugged. + @param[out] ToUnplugApicIds The APIC IDs of the CPUs that are about t= o be + hot-unplugged. =20 - @param[out] ToUnplugCount The number of filled-in APIC IDs in - ToUnplugApicIds. + @param[out] ToUnplugSelectors The QEMU Selectors of the CPUs that are a= bout + to be hot-unplugged. + + @param[out] ToUnplugCount The number of filled-in APIC IDs in + ToUnplugApicIds. =20 @retval EFI_INVALID_PARAMETER PossibleCpuCount is zero, or ApicIdCount = is zero. @@ -187,6 +190,7 @@ QemuCpuhpCollectApicIds ( OUT APIC_ID *PluggedApicIds, OUT UINT32 *PluggedCount, OUT APIC_ID *ToUnplugApicIds, + OUT UINT32 *ToUnplugSelectors, OUT UINT32 *ToUnplugCount ) { @@ -204,6 +208,7 @@ QemuCpuhpCollectApicIds ( UINT32 PendingSelector; UINT8 CpuStatus; APIC_ID *ExtendIds; + UINT32 *ExtendSels; UINT32 *ExtendCount; APIC_ID NewApicId; =20 @@ -245,10 +250,10 @@ QemuCpuhpCollectApicIds ( if ((CpuStatus & QEMU_CPUHP_STAT_INSERT) !=3D 0) { // // The "insert" event guarantees the "enabled" status; plus it exclu= des - // the "remove" event. + // the "fw_remove" event. // if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0 || - (CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + (CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: " "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, CpuStatus)); @@ -259,33 +264,63 @@ QemuCpuhpCollectApicIds ( CurrentSelector)); =20 ExtendIds =3D PluggedApicIds; + ExtendSels =3D NULL; ExtendCount =3D PluggedCount; - } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { - DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: remove\n", __FUNCT= ION__, - CurrentSelector)); + } else if ((CpuStatus & QEMU_CPUHP_STAT_FW_REMOVE) !=3D 0) { + // + // "fw_remove" event guarantees "enabled". + // + if ((CpuStatus & QEMU_CPUHP_STAT_ENABLED) =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: CurrentSelector=3D%u CpuStatus=3D0x%x: " + "inconsistent CPU status\n", __FUNCTION__, CurrentSelector, + CpuStatus)); + return EFI_PROTOCOL_ERROR; + } + + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: fw_remove\n", + __FUNCTION__, CurrentSelector)); =20 ExtendIds =3D ToUnplugApicIds; + ExtendSels =3D ToUnplugSelectors; ExtendCount =3D ToUnplugCount; + } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + // + // Let the OSPM deal with the "remove" event. + // + DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: remove (ignored)\n= ", + __FUNCTION__, CurrentSelector)); + + ExtendIds =3D NULL; + ExtendSels =3D NULL; + ExtendCount =3D NULL; } else { DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: no event\n", __FUNCTION__, CurrentSelector)); break; } =20 - // - // Save the APIC ID of the CPU with the pending event, to the correspo= nding - // APIC ID array. - // - if (*ExtendCount =3D=3D ApicIdCount) { - DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__)); - return EFI_BUFFER_TOO_SMALL; - } - QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); - NewApicId =3D QemuCpuhpReadCommandData (MmCpuIo); - DEBUG ((DEBUG_VERBOSE, "%a: ApicId=3D" FMT_APIC_ID "\n", __FUNCTION__, - NewApicId)); - ExtendIds[(*ExtendCount)++] =3D NewApicId; + ASSERT ((ExtendIds =3D=3D NULL) =3D=3D (ExtendCount =3D=3D NULL)); + ASSERT ((ExtendSels =3D=3D NULL) || (ExtendIds !=3D NULL)); =20 + if (ExtendIds !=3D NULL) { + // + // Save the APIC ID of the CPU with the pending event, to the + // corresponding APIC ID array. + // For unplug events, also save the CurrentSelector. + // + if (*ExtendCount =3D=3D ApicIdCount) { + DEBUG ((DEBUG_ERROR, "%a: APIC ID array too small\n", __FUNCTION__= )); + return EFI_BUFFER_TOO_SMALL; + } + QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); + NewApicId =3D QemuCpuhpReadCommandData (MmCpuIo); + DEBUG ((DEBUG_VERBOSE, "%a: ApicId=3D" FMT_APIC_ID "\n", __FUNCTION_= _, + NewApicId)); + if (ExtendSels !=3D NULL) { + ExtendSels[(*ExtendCount)] =3D CurrentSelector; + } + ExtendIds[(*ExtendCount)++] =3D NewApicId; + } // // We've processed the CPU with (known) pending events, but we must ne= ver // clear events. Therefore we need to advance past this CPU manually; --=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 (#72704): https://edk2.groups.io/g/devel/message/72704 Mute This Topic: https://groups.io/mt/81273603/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-