From nobody Thu Nov 14 05:04:45 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+71830+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+71830+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 1613725507927304.57160672566533; Fri, 19 Feb 2021 01:05:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id JXuHYY1788612xHctvxOKJEY; Fri, 19 Feb 2021 01:05:07 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web10.6072.1613725501728380005 for ; Fri, 19 Feb 2021 01:05:01 -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 11J94w9P192847; Fri, 19 Feb 2021 09:04:58 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 36p49bgvyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:57 +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 11J8tl0q182210; Fri, 19 Feb 2021 09:04:57 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by userp3020.oracle.com with ESMTP id 36prhve0ju-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=heQaPlG0kqlW8fZdHLZgXaB7kzAVXSNNylToCRfN1+jk+Id35i4wjgYSUG6vxu79xaM7h/DSpr9erQirtK5MOcl273hNNi0LSBxWY81IAAGfcwwjrtIodGBJvoTqdwORNTOJAsqeAbM2kVPqtmcyrsl1w1QZnxLYo0UW5Yv/Mi4Em1Kple1yNNWrM4K3TqEjdqzp+LrWEysdAoNJXSKNG3B6ZMUDlP43lpdjbeIjGwauXTsxWTT8KU6xypUpD5UtCANw/Yr46zO3RvumL2n+tLsASdwNIDcLMkTxSC/hpvf/PAit+FUZqGcz3xn7QRo+IzlSmAuQOCSAu6Zicq/D7Q== 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=j5sLrnWcUR41bTrM95Iz2yAXNjCYFkDKXmHyHRZ5diI=; b=kFDy7L7EBUz+DRbzrzkMl+jaSnfmaN8G1hMj48P+32sKK6KDpx/xzRwSU1IK2ydXBHj6uDOUsXgduO4geinSGosWjqFUwhKgwxzxQgRAVf1k519bj5/Uq7bD52yobXWrJaLjtkMz2qHwAqLQIbfIg74ugowmta2q6Icn/wd/gy8KPM447P7fZoBN9N4D370bWsNGBdsmUVhUtedl1+V2SvqwQHaJfGVopDI0iZx+L091/lEAaVX1T+qDhoS/1iE2LwCiT5xxSOFNIgPc8iMGy98VIOerJR+ze9+og1Ac3yBNAAXFrtljss7o6h6G5iSX3BJw+rG5PGM/nebWFqkYmQ== 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:04:55 +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:04:55 +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 01/10] OvmfPkg/CpuHotplugSmm: refactor hotplug logic Date: Fri, 19 Feb 2021 01:04:35 -0800 Message-Id: <20210219090444.1332380-2-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:04:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c2bc89d-f761-4aec-c663-08d8d4b56c91 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 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0kMd+EuLimjRgBmlixuoXHRWVXt8JFBtykLNx1qJsu4IfBFz8PHjPQFK?= =?us-ascii?Q?uueZ5S9Fig+6P0VDlMOcu0urNoPNQ5m3/Vn6+XvJM1kS7L8N2G2dmyw40w9y?= =?us-ascii?Q?OnMlSJaXyzVVLPD1XJslzx9u?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c2bc89d-f761-4aec-c663-08d8d4b56c91 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:04:55.0518 (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: uncPAut0d2NDZac5CH3oAYaoHkNowYbx5o9yMzF86/N8DPAasocyaNdOzPX4FZdFBsXrfgWdNBtqQqs0OEM7Hywx7HPxOyThnIBRt1Ke3ik= 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: 41OQKm0bwvuCNHFK1frMqljux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725507; bh=Id4p+bO+oCvlongIII6Wmql5CXXdMpiiwnqBERmFYwk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=wZDNQz95Vvr4+zv/DFu8bImBy3ObsaFFpyiS6o4zhABNjku/Bx6lrDxW2UtNW1+aUDC LOV2NEk1c+F+s0X7TCw0FpM3RbpY4JTupnU2r2emnMGESo+xxWKwRvNFmhvnrIeLdz7tj eWMtBkKddkAXfWufKD7mFRHitfLD27EpKQo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Refactor CpuHotplugMmi() to pull out the CPU hotplug logic into ProcessHotAddedCpus(). This is in preparation for supporting CPU hot-unplug. 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 these review comments from v6: (1) s/EFI_ERROR(/EFI_ERROR (/ (2) Remove the empty line in the comment block above ProcessHotAddedCpus(). () Nest the EFI_ERROR handling inside the (PluggedCount > 0) clause. OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 210 ++++++++++++++++++++++-----------= ---- 1 file changed, 126 insertions(+), 84 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index cfe698ed2b5e..bf68fcd42914 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -62,6 +62,129 @@ STATIC UINT32 mPostSmmPenAddress; // STATIC EFI_HANDLE mDispatchHandle; =20 +/** + Process CPUs that have been hot-added, per QemuCpuhpCollectApicIds(). + + For each such CPU, relocate the SMBASE, and report the CPU to PiSmmCpuDx= eSmm + via EFI_SMM_CPU_SERVICE_PROTOCOL. If the supposedly hot-added CPU is alr= eady + known, skip it silently. + + @param[in] PluggedApicIds The APIC IDs of the CPUs that have been + hot-plugged. + + @param[in] PluggedCount The number of filled-in APIC IDs in + PluggedApicIds. + + @retval EFI_SUCCESS CPUs corresponding to all the APIC IDs are + populated. + + @retval EFI_OUT_OF_RESOURCES Out of APIC ID space in "mCpuHotPlugData". + + @return Error codes propagated from SmbaseRelocate() + and mMmCpuService->AddProcessor(). +**/ +STATIC +EFI_STATUS +ProcessHotAddedCpus ( + IN APIC_ID *PluggedApicIds, + IN UINT32 PluggedCount + ) +{ + EFI_STATUS Status; + UINT32 PluggedIdx; + UINT32 NewSlot; + + // + // The Post-SMM Pen need not be reinstalled multiple times within a sing= le + // root MMI handling. Even reinstalling once per root MMI is only pruden= ce; + // in theory installing the pen in the driver's entry point function sho= uld + // suffice. + // + SmbaseReinstallPostSmmPen (mPostSmmPenAddress); + + PluggedIdx =3D 0; + NewSlot =3D 0; + while (PluggedIdx < PluggedCount) { + APIC_ID NewApicId; + UINT32 CheckSlot; + UINTN NewProcessorNumberByProtocol; + + NewApicId =3D PluggedApicIds[PluggedIdx]; + + // + // Check if the supposedly hot-added CPU is already known to us. + // + for (CheckSlot =3D 0; + CheckSlot < mCpuHotPlugData->ArrayLength; + CheckSlot++) { + if (mCpuHotPlugData->ApicId[CheckSlot] =3D=3D NewApicId) { + break; + } + } + if (CheckSlot < mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged " + "before; ignoring it\n", __FUNCTION__, NewApicId)); + PluggedIdx++; + continue; + } + + // + // Find the first empty slot in CPU_HOT_PLUG_DATA. + // + while (NewSlot < mCpuHotPlugData->ArrayLength && + mCpuHotPlugData->ApicId[NewSlot] !=3D MAX_UINT64) { + NewSlot++; + } + if (NewSlot =3D=3D mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n", + __FUNCTION__, NewApicId)); + return EFI_OUT_OF_RESOURCES; + } + + // + // Store the APIC ID of the new processor to the slot. + // + mCpuHotPlugData->ApicId[NewSlot] =3D NewApicId; + + // + // Relocate the SMBASE of the new CPU. + // + Status =3D SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], + mPostSmmPenAddress); + if (EFI_ERROR (Status)) { + goto RevokeNewSlot; + } + + // + // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + Status =3D mMmCpuService->AddProcessor (mMmCpuService, NewApicId, + &NewProcessorNumberByProtocol); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, NewApicId, Status)); + goto RevokeNewSlot; + } + + DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%= Lx, " + "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__, + NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot], + (UINT64)NewProcessorNumberByProtocol)); + + NewSlot++; + PluggedIdx++; + } + + // + // We've processed this batch of hot-added CPUs. + // + return EFI_SUCCESS; + +RevokeNewSlot: + mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64; + + return Status; +} =20 /** CPU Hotplug MMI handler function. @@ -122,8 +245,6 @@ CpuHotplugMmi ( UINT8 ApmControl; UINT32 PluggedCount; UINT32 ToUnplugCount; - UINT32 PluggedIdx; - UINT32 NewSlot; =20 // // Assert that we are entering this function due to our root MMI handler @@ -179,87 +300,11 @@ CpuHotplugMmi ( goto Fatal; } =20 - // - // Process hot-added CPUs. - // - // The Post-SMM Pen need not be reinstalled multiple times within a sing= le - // root MMI handling. Even reinstalling once per root MMI is only pruden= ce; - // in theory installing the pen in the driver's entry point function sho= uld - // suffice. - // - SmbaseReinstallPostSmmPen (mPostSmmPenAddress); - - PluggedIdx =3D 0; - NewSlot =3D 0; - while (PluggedIdx < PluggedCount) { - APIC_ID NewApicId; - UINT32 CheckSlot; - UINTN NewProcessorNumberByProtocol; - - NewApicId =3D mPluggedApicIds[PluggedIdx]; - - // - // Check if the supposedly hot-added CPU is already known to us. - // - for (CheckSlot =3D 0; - CheckSlot < mCpuHotPlugData->ArrayLength; - CheckSlot++) { - if (mCpuHotPlugData->ApicId[CheckSlot] =3D=3D NewApicId) { - break; - } - } - if (CheckSlot < mCpuHotPlugData->ArrayLength) { - DEBUG ((DEBUG_VERBOSE, "%a: APIC ID " FMT_APIC_ID " was hot-plugged " - "before; ignoring it\n", __FUNCTION__, NewApicId)); - PluggedIdx++; - continue; - } - - // - // Find the first empty slot in CPU_HOT_PLUG_DATA. - // - while (NewSlot < mCpuHotPlugData->ArrayLength && - mCpuHotPlugData->ApicId[NewSlot] !=3D MAX_UINT64) { - NewSlot++; - } - if (NewSlot =3D=3D mCpuHotPlugData->ArrayLength) { - DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n", - __FUNCTION__, NewApicId)); + if (PluggedCount > 0) { + Status =3D ProcessHotAddedCpus (mPluggedApicIds, PluggedCount); + if (EFI_ERROR (Status)) { goto Fatal; } - - // - // Store the APIC ID of the new processor to the slot. - // - mCpuHotPlugData->ApicId[NewSlot] =3D NewApicId; - - // - // Relocate the SMBASE of the new CPU. - // - Status =3D SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot], - mPostSmmPenAddress); - if (EFI_ERROR (Status)) { - goto RevokeNewSlot; - } - - // - // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. - // - Status =3D mMmCpuService->AddProcessor (mMmCpuService, NewApicId, - &NewProcessorNumberByProtocol); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n", - __FUNCTION__, NewApicId, Status)); - goto RevokeNewSlot; - } - - DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%= Lx, " - "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__, - NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot], - (UINT64)NewProcessorNumberByProtocol)); - - NewSlot++; - PluggedIdx++; } =20 // @@ -267,9 +312,6 @@ CpuHotplugMmi ( // return EFI_SUCCESS; =20 -RevokeNewSlot: - mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64; - Fatal: ASSERT (FALSE); CpuDeadLoop (); --=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 (#71830): https://edk2.groups.io/g/devel/message/71830 Mute This Topic: https://groups.io/mt/80751393/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- From nobody Thu Nov 14 05:04:45 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+71829+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+71829+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 1613725502754474.28497189522193; Fri, 19 Feb 2021 01:05:02 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id UfOEYY1788612xTm2C8ju9Ho; Fri, 19 Feb 2021 01:05:02 -0800 X-Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web10.6069.1613725501373003584 for ; Fri, 19 Feb 2021 01:05:01 -0800 X-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J94Fvb111119; Fri, 19 Feb 2021 09:04:58 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 36p7dnrn7h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:58 +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 11J8tl0s182210; Fri, 19 Feb 2021 09:04:58 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by userp3020.oracle.com with ESMTP id 36prhve0ju-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=krsszLS2JIyf/JmUhymkojMC0vPSPz/7205Z4rf5GFlJg9gd1rqfTtDcBB1PkmmgCTUiHMlFQGujsh7ClNjXRqQqZTZDQJ05n+ZDFKvcs8Dxlu4+A91gsnVDQO9JxpPKnoGdcp0IT+qocMcmwAPVnVC+nxUilweJCLkLdA8n+p1ogGSLGcmN+dlE/fwlxx7ytDgBgugOLHRMYjYGdhiCJcuXx5sUpRTx4uG1ltW+JkWi+kuVuWXYWLqm1NJvJQKk4QjFGhx7n3b8RZPWS/35QQmqEmJVqlCmOOGxtyR/XD68TzWXdrFp4l2lMt8G+ZwTXSBxQC99vz3nHfepiesmEQ== 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=LRmSgHeU2Z8fSi2Ls38i75CZGzgGp6EbcgbHjRODjIU=; b=OMGaxWd1RoojsEPKaoxxLGBPOqwDAsRCSCGyCkMN5Ugc6rj5npa9+yYC9CxAhUXTwXecsLxG9wkMrgnQYqLSu2hNq079fngtWRiDbgnj3/4zOBceYIBOjAfygL2aa+26yyA2fKqJX9E/yJFoIDLuvJZjKuPWPvpyKnRNpatgIv4wvPEE4Anmrlvsffv8001GhfbXsWVGU98NThrb4i1DRcCdjRxfebPQ3PsPwS15CZh0mqJp2u6PdLGxURMovuB1BxP+UdvwaicuqseMqhBEtZiw9E47M9uUzM8gyMvZPGLUuWEr4eUE+xrPEH8pgevWvzwQNjvXh9p6qeHqQY9oCQ== 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:04:56 +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:04:56 +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 02/10] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Date: Fri, 19 Feb 2021 01:04:36 -0800 Message-Id: <20210219090444.1332380-3-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:04:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 191fa47a-41ac-40e2-829b-08d8d4b56d4a X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Fo1i1XSdmvC6zbaXGKygZIo/pPbeW3aMPKRlIwjZpovVLgB1zD9PJUMq89qxjlXDTOPtappUSnHLsfZ2ZzLdfYMLhVdvXcjDiq/ivR9PO/t7Hjb8wd25k6Q2c+YO7rU3v7CTTjGYVGPufOXzyCnfuML/SqSHL3T1VFoYrhGu1YtNq1sbSerAMdpTAh3ZO6nB9mm2IAUBdYee+doniYytSfIwKi5m+LJisTbp9sNZDQvm5St9kkpwpElO8jv0yBRPLbpFdhhopXlRwVSdCSN2O22spfSpMcukAAPD3oEcScrZMHI7FMpub97BsRjKCx5Nemo+6vYanxyhyOgrh3Jy9Pc+3hms7G19aYN0sz+wphtmosXX/060ttNCv/1jOwYH/D0oHQzoeszm5fznSnpBsL1Ee8CiOCtC3UlDDyZFp1dr53WAuMuljI+Ubtt4LIz4usM0X9UiKz6ZQIdazxHtJA8r+EkKI1fvIYuW0v71Y0lRK+jaICKYsYSTiPD1O0yyfNEIAMFXBFkCTp3yNib6YIbf+VV3wRH31wKaEIl2Ibmdwb9EY0zIlI7GRej8Wv/lAliqwSm3/00w1zM2x/54HSuvLd1QSWWUZyMPQnLUk58= X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?tONmShFZJlpjntvJei9/nbpcfN15GOezPbZRNpE/26+FoSUOX3bekLc+T9K8?= =?us-ascii?Q?yzzaUShZZqzVWZ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LsjjqiV2Wq?= =?us-ascii?Q?J7MHd5uK/lT0IqTmocdaqyE0Et29I6urUOk3kZu/RNCsnnFVMiyueNFmfQeS?= =?us-ascii?Q?yLYocvDqOUO0yCRzFj3KW30aF1kgcE+UUel6+yMhqAe8hoA/VSHYh0L8DkJN?= =?us-ascii?Q?VBI/sG4fWGIB6QiHNzwSCbHvmfGK25kpizcNqHJJGOAMlcBBU0t8rwZrSpyd?= =?us-ascii?Q?ksUhy3OQS9IF7BNv1ipfMsHQR5DUD/ja87AtV/emjzlQyo/gqhAKMSh9yCjI?= =?us-ascii?Q?qa6XQcEGYoM1ObiyXf65icT5SShgHR00hFFtgS4B4ubBUQ5+Lc/Ylo3UdR9w?= =?us-ascii?Q?sXp9j5SSYIwSoScTAon/ix7Jud3WszvUxjA426+fmEmnhXKl0VGHBEbc/GET?= =?us-ascii?Q?9A0/Yf+RrEg3xh+IpR04hL/I?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 191fa47a-41ac-40e2-829b-08d8d4b56d4a 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:04:56.2326 (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: ZPfIezvB0z2y/VKag7vWE9jwCDQVFxACeK5niqxflr3yuqXKhOUYcEGI9TUWptwa9Vc2HbKe4kWX6bziVv6by8SpDpIWHRprRmnyTHZn3OM= 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: Y69LLLUZ7FymSKz95kCTZ3Ajx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725502; bh=l2Ivvx2ZmMF4vjryqlUHawIY0CHUd3IhaKw4gua6W6M=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=RwPMnhGVp1sf2OKkiOZbw8zCGU9NXmJw4JRi6EbOTanq8+cXlhIPGZ6oA4sSEVMxWQi VTYV6/LntYgYKDTqBKyKUZ8YjgsrK62d7UtdsvvOca7mlCOJ4e5YNez2BInwkVtfqmL9p lbirzeRI9S8FWpzS4axylanW5syhOm4Zng4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Process fw_remove events in QemuCpuhpCollectApicIds() and collect corresponding APIC IDs for CPUs that are 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 --- Notes: Addresses the following review comments from v6: (1,4) Move (and also rename) QEMU_CPUHP_STAT_EJECTED to patch 8, where we actually use it. (2) Downgrade debug mask from DEBUG_INFO to DEBUG_VERBOSE. (3a,3b,3c) Keep the CurrentSelector increment operation at the tail of the loop. () As discussed elsewhere we also need to get the CpuSelector while collecting ApicIds in QemuCpuhpCollectApicIds(). This patch adds a separate parameter for the CpuSelector values, because that works better alongside the hotplug ExtendIds logic. OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 1 + OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 1 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 21 +++++- OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 84 ++++++++++++++++---= ---- 4 files changed, 79 insertions(+), 28 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.h index 8adaa0ad91f0..1e23b150910e 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 *ToUnplugSelector, 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..3192bfea1f15 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -52,6 +52,7 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; // STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mToUnplugApicIds; +STATIC UINT32 *mToUnplugSelector; // // Address of the non-SMRAM reserved memory page that contains the Post-SM= M Pen // for hot-added CPUs. @@ -289,6 +290,7 @@ CpuHotplugMmi ( mPluggedApicIds, &PluggedCount, mToUnplugApicIds, + mToUnplugSelector, &ToUnplugCount ); if (EFI_ERROR (Status)) { @@ -333,7 +335,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 +391,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 +410,12 @@ CpuHotplugEntry ( DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s)); goto ReleasePluggedApicIds; } + Status =3D gMmst->MmAllocatePool (EfiRuntimeServicesData, SizeSel, + (VOID **)&mToUnplugSelector); + 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 +423,7 @@ CpuHotplugEntry ( Status =3D SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, SystemTable->BootServices); if (EFI_ERROR (Status)) { - goto ReleaseToUnplugApicIds; + goto ReleaseToUnplugSelector; } =20 // @@ -472,6 +483,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices); mPostSmmPenAddress =3D 0; =20 +ReleaseToUnplugSelector: + gMmst->MmFreePool (mToUnplugSelector); + mToUnplugSelector =3D NULL; + ReleaseToUnplugApicIds: gMmst->MmFreePool (mToUnplugApicIds); mToUnplugApicIds =3D NULL; diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 8d4a6693c8d6..36372a5e6193 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -164,6 +164,9 @@ QemuCpuhpWriteCommand ( @param[out] ToUnplugApicIds The APIC IDs of the CPUs that are about to = be hot-unplugged. =20 + @param[out] ToUnplugSelector The QEMU Selectors of the CPUs that are abo= ut to + be hot-unplugged. + @param[out] ToUnplugCount The number of filled-in APIC IDs in ToUnplugApicIds. =20 @@ -187,6 +190,7 @@ QemuCpuhpCollectApicIds ( OUT APIC_ID *PluggedApicIds, OUT UINT32 *PluggedCount, OUT APIC_ID *ToUnplugApicIds, + OUT UINT32 *ToUnplugSelector, OUT UINT32 *ToUnplugCount ) { @@ -204,6 +208,7 @@ QemuCpuhpCollectApicIds ( UINT32 PendingSelector; UINT8 CpuStatus; APIC_ID *ExtendIds; + UINT32 *ExtendSel; 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,40 +264,69 @@ QemuCpuhpCollectApicIds ( CurrentSelector)); =20 ExtendIds =3D PluggedApicIds; + ExtendSel =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; + ExtendSel =3D ToUnplugSelector; 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; + ExtendSel =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)); + 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 (ExtendSel !=3D NULL) { + ExtendSel[(*ExtendCount)] =3D CurrentSelector; + } + ExtendIds[(*ExtendCount)++] =3D NewApicId; =20 - // - // 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; - // otherwise, QEMU_CPUHP_CMD_GET_PENDING would stick to the currently - // selected CPU. - // - CurrentSelector++; + // + // We've processed the CPU with (known) pending events, but we must = never + // clear events. Therefore we need to advance past this CPU manually; + // otherwise, QEMU_CPUHP_CMD_GET_PENDING would stick to the currently + // selected CPU. + // + CurrentSelector++; + } } while (CurrentSelector < PossibleCpuCount); =20 DEBUG ((DEBUG_VERBOSE, "%a: PluggedCount=3D%u ToUnplugCount=3D%u\n", --=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 (#71829): https://edk2.groups.io/g/devel/message/71829 Mute This Topic: https://groups.io/mt/80751392/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- From nobody Thu Nov 14 05:04:45 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+71831+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+71831+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 161372550457498.06004033167767; Fri, 19 Feb 2021 01:05:04 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Xmz6YY1788612xLsx8q8M69m; Fri, 19 Feb 2021 01:05:04 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.6107.1613725501901957568 for ; Fri, 19 Feb 2021 01:05:02 -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 11J93veU178541; Fri, 19 Feb 2021 09:04:59 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 36pd9ag89k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:59 +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 11J8tl0t182210; Fri, 19 Feb 2021 09:04:58 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by userp3020.oracle.com with ESMTP id 36prhve0ju-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:04:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fTY2AzcCWNwd60zbVbc6o+JyCY4572eeJw/piuVm/Ezq80nojpiCJz+/7yLAa5UP+sKHnafyVCyVRJS4Zw93IVB38Lny8nRTXtKK+qGB3g+SxUb4EvocemF1RFMJ4iYKS3SjzCXDRQonTi/byTfH603CJOG612oidxMLcwpdVTJu9PIbrUB+cgeY5c6h3MZsVq1QXNXIFtA2MgzMsQe6brtSbup+6NngfqnK5BMOcGGGYv4kR3mPSmqc0ahD4+3JbqpB6OgF0gy7sPjT9ukp3PymMqdbqcl1G3Vdz6QjQuaI1i1DycEliMDAnruUAIAkxJTI4OfjjoL0GoUbFPs6aA== 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=8fO67yOsbQGfKTZwTbqUZ414s/0CVrpbiuLZpLVLgDQ=; b=JaioWhgexAZxVDXgD6HWTeO3zddXjUFk6eHljt6uX/r2p9I9kFEfw2EnG19Qz/s71//OwBZS4JvYaavvvB0vwOoF1BgBEnbm/if1vLk/3J4rHWzLuj+2xVfzRhgiNaq8BmeNljmuVCJJMb/8zKzz77g49lnHaUune5ON+HOXCSmnLHIj3m4/5DIiKLAax+YOYztN1aW6yr0qLAFO7ctjwB+4ldpxcSK4GTSS2oIs6Rzlwa10WwmXLXJU4Mz2iYqTUHD0e+wIxpUwiaS/hE9Zzs/H4LsPXIOhg4vVBMzYhP6kRRzdDAKvAYnMJjJjGyxiBUIBRDYU99zUwXFZqeM8pA== 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:04:57 +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:04:57 +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 03/10] OvmfPkg/CpuHotplugSmm: add Qemu Cpu Status helper Date: Fri, 19 Feb 2021 01:04:37 -0800 Message-Id: <20210219090444.1332380-4-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:04:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2235f95-f7a8-427b-e3d1-08d8d4b56dfa X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-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?us-ascii?Q?rDV/eB65w7oHx6Gm1/htJ7zBKysXIfeuLEuoSSGVjOK+c3a8+Cta0DGKg0bI?= =?us-ascii?Q?uQ/3G7HBySVUL7dH1SPQPS1ML01z8ixA6oAt4c+pcvAweMwcxZzWSBkFcBal?= =?us-ascii?Q?JYKwCHutHr1qKg98/F5bJ2XW?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b2235f95-f7a8-427b-e3d1-08d8d4b56dfa 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:04:57.4005 (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: vJZeNlKc8egjKX5kPxDYFSioE9Y7EOK678hX5J6tccPpCGPTeFhmVkQjDFG6tDM4NqeijHP7Im23MI8wiUgx2db+hVwj98YHYKOTh5CuRA4= 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: 7bM8nZofAF0dTDk8m6ikJDS3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725504; bh=3qYCIkOY5AX22n6/+hlD4guZThLhZtacG2I1QMw422c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=TfON5GKBkM1U2Z3m71vk/MWzPHzhwP+U7jtHGCcAPA7eC73witt6dqOafP9BplNYhEi l8ocbAnMpRgVfsN/oDIWYzmI2jI5o5NRsgTItlId/grrq59B0mE2uqxVNrblCedkXWoGu wxj4QXf/5KGqO4rLau14kOF/wgCjUW30HHM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add QemuCpuhpWriteCpuStatus() which will be used to update the QEMU CPU status register. On error, it hangs in a similar fashion as other helper functions. 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: Address this review comment: () Move QemuCpuhpWriteCpuStatus() (declaration and definition) between QemuCpuhpWriteCpuSelector() and QemuCpuhpWriteCommand() to match the order of the register descriptions in QEMU. OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 6 ++++++ OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.h index 1e23b150910e..859412c1a173 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h @@ -42,6 +42,12 @@ QemuCpuhpWriteCpuSelector ( ); =20 VOID +QemuCpuhpWriteCpuStatus ( + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, + IN UINT8 CpuStatus + ); + +VOID QemuCpuhpWriteCommand ( IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN UINT8 Command diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 36372a5e6193..9434bb14dd4e 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -114,6 +114,28 @@ QemuCpuhpWriteCpuSelector ( } =20 VOID +QemuCpuhpWriteCpuStatus ( + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, + IN UINT8 CpuStatus + ) +{ + EFI_STATUS Status; + + Status =3D MmCpuIo->Io.Write ( + MmCpuIo, + MM_IO_UINT8, + ICH9_CPU_HOTPLUG_BASE + QEMU_CPUHP_R_CPU_STAT, + 1, + &CpuStatus + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status)); + ASSERT (FALSE); + CpuDeadLoop (); + } +} + +VOID QemuCpuhpWriteCommand ( IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, IN UINT8 Command --=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 (#71831): https://edk2.groups.io/g/devel/message/71831 Mute This Topic: https://groups.io/mt/80751394/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- From nobody Thu Nov 14 05:04:45 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+71833+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+71833+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 1613725507234224.8839556458788; Fri, 19 Feb 2021 01:05:07 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id mGwSYY1788612xk6elic6MRg; Fri, 19 Feb 2021 01:05:06 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web12.6144.1613725506144600680 for ; Fri, 19 Feb 2021 01:05:06 -0800 X-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J952fx093498; Fri, 19 Feb 2021 09:05:02 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 36p66r8rdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +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 11J8uJSF131491; Fri, 19 Feb 2021 09:05:01 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by aserp3020.oracle.com with ESMTP id 36prp2pa12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lpOMPKX0vBjLJ3Pl4iW1WexB0Rjv9zT343TY0ZnNarHEAz+4lYNScN/33AtYbQFH0Fb6iiYQlPDPMu3e9u2Dqmk7i2eee+l3SohUn9xHzefLuSZ6i2wD2RhMX7KbgDcBIZ0g1+AO20wK+oPugIXMNAwkm7EiN7xKhbeWgTB37XDEQJbPGnjWudgIgw3AD1nQhsa40ykSj1WP48XptR0gXQE9kECFzhqI0m0hdPxYNJNZLHbAbWxz+YDoKArKDdSlt5qAgjRk5oA4oNEWiUV8nYo4MfmqABojjsF6iYvlm+jbqkACEVkxLHS5qBctkkkF15UiHVTC9760r+m1zHZ/HA== 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=b2bE66bX2QhqReGUL5sLF1Eh2kfjXO969oJmWd9P7zo=; b=Of9fup8BsWxD7w/NjhT3EDh9PW56H2cHaS6eTG6EHLCtoyi3h5XguGMLhAykyav8bhLWLIyOSiIRs7gW5lwZ9DwLP5mp+1JeLoXWgxxoLkG/TP6twJwRdLfrSvDjX3nMMEcZdLyi+YLnearcEz3A4GfIvOniwMEAcgoZKUwE8RWYxY+j0FaZ7PWiXpUMa0hVp7clq/CUBB1W6uKDHsZT+lfxnCxyZFEAX7k40DuBgQ9mTB0qtn68YPumFHvYa2yd5/2E1wUGhAQgCWWCfTYG+S6afL/2i4pjzVsdmBNGqgcXhSbk6FoI7pbq8bJ4Id399v8adwtCdI/T9nGuy0j93A== 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:04:58 +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:04:58 +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 04/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() Date: Fri, 19 Feb 2021 01:04:38 -0800 Message-Id: <20210219090444.1332380-5-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:04:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a0bb102f-2608-405c-5544-08d8d4b56eac X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: 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: rEuZ/QS5C+KDLBR7w8W97OTqsll67iMMFkZVUoBWbteSaFKifdva28uxW6fGvQb76V8lfNoutX0uQYmp1Mqe6C08mq1MqURU/owwZA75K8tE3FRMoJBsp+Gqytbag9tXZEGavH4Rybh1wUfV875z4zguGV0hM7kNCquLVEVP1sDVqaPZMoK/tCCAgQLWmlPWiOAYOYO/CrQU7G672uFkqTW5rKMtW0/JQXOZ3coWp60fHp/5TuZDxaImwYI0rA8Zisqu6j7G0f+Tp/I2QSvNVZQBQzL6DoNOukY6358IPManWOH8TCkwvXsCClzrkFN70v0OzljE72Qnr5Jp/BcHi/ziEkn2W2jTM1kY2Vv9vKaK83uIQKiIJHlYZJ14x4ybotDpXw9cACEe0j1BA3e1A60Yz+yWdHvxLVMWKAuP6Vn+GbEDK75+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zMEP+zN2L9525fcxKgvqFaPuzSLG?= =?us-ascii?Q?AEWHuTC0yFQo6M8FzFXPbHhU3BV+Nub7KRsWCZMNi9HvKzEhMBeh8eB3N8qz?= =?us-ascii?Q?3PNHELvROsofkHCbf7hFJF9raWf9ikITH1QM9sbXQ8A9xNV5Z1L1U6pP6bSF?= =?us-ascii?Q?00iWGLmDo3lTxks4OmK1Ce1nz8nMnEdWs7DLjSmuXJ+UXYflg1mfB3dnXnM9?= =?us-ascii?Q?FYb+DrYiEXowmXmGu5QXbIs8G7Zb4SNZpodwlmleKgiGaQfsCi48+6E9F92T?= =?us-ascii?Q?aZRZe/VN22WvA80Mj68/WhrAPigqfv0IcdHb9RPURGX25yF5BDBoh0dzdAqj?= =?us-ascii?Q?345KG5AbYFe6AjgMs8Rw45LytCefxQpCoBW3m7vngicmWtFb8fR01pJMhOfP?= =?us-ascii?Q?jo+0/38HVwi+mkk/u8ozlu491H5T/3GklVG/jaEbtLV9qLENGPTI7qPuHiAI?= =?us-ascii?Q?qc4sEUe0uybLx+c+MnaRebmTyw+gr/MN76ZMYJTEAfXAX/EYa8JFnCNUJwq7?= =?us-ascii?Q?IAy3e+RNUXtxk7ImbRqn2Maqo4wk0Fveb5NtyMtH8j+/vvB21YtJUbRhtHbc?= =?us-ascii?Q?u57r+UOXbY/gr4ZLyZGAPHC9iXCVKKDdwLhzCMBuB6Z6gUpH0W1F9wJ6g+ht?= =?us-ascii?Q?BVuixpy6kQErVog8sBJPeJvA?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0bb102f-2608-405c-5544-08d8d4b56eac 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:04:58.5943 (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: kAn1JVcEdPeXhMR94wcjNylE+a32wwAiruKiK6sG2ZyyLyB6vO0gQISwnB26dUuiBcnU2xIuN0pN74keYnm3tlgQpc/pv00RFQe1bJ9rNik= 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: 7DXd68reDmMuBAS7D34qZMMTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725506; bh=jz9wJCt2U6/aI/um0kae9yaMIoNBZ5igbzA6yBJ4eh0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=NYYS7WDrFBUHODzTlT9niCgZ1ngnW4rDNfk+Bb/ZpgsSX64DayI3axgEht6/bZf4RC/ 8l7MicJVIVb/yF5fyXU5kPgtOuH8bbaqyDMWg12gGKIJJHjQE7K6fJ5i75KK5idLDQ3zo 9A8cADoGNkBxIXSqbd1CWEwD6xcLmmGpCjM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce UnplugCpus() which maps each APIC ID being unplugged onto the hardware ID of the processor and informs PiSmmCpuDxeSmm of removal by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor(). With this change we handle the first phase of unplug where we collect the CPUs that need to be unplugged and mark them for removal in SMM data structures. 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 these review comments from v6: (1) Drop the empty line in the comment block around UnplugCpus(). (2) Make the "did not find APIC ID" DEBUG_VERBOSE instead of DEBUG_INF= O. (3) Un-Indented ("Outdented") the line following the comment "Ignore t= he unplug if APIC ID. (4) Remove the empty line between Status assignment and check. (5) Drop the "goto Fatal" logic and just return Status directly. (6) Handle both Plugging and Unplugging of CPUs in one go. (7) Also nest the EFI_STATUS check. OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 84 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 84 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 3192bfea1f15..f07b5072749a 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -188,6 +188,83 @@ RevokeNewSlot: } =20 /** + Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). + + For each such CPU, report the CPU to PiSmmCpuDxeSmm via + EFI_SMM_CPU_SERVICE_PROTOCOL. If the to be hot-unplugged CPU is + unknown, skip it silently. + + @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to= be + hot-unplugged. + + @param[in] ToUnplugCount The number of filled-in APIC IDs in + ToUnplugApicIds. + + @retval EFI_SUCCESS Known APIC IDs have been removed from SMM = data + structures. + + @return Error codes propagated from + mMmCpuService->RemoveProcessor(). +**/ +STATIC +EFI_STATUS +UnplugCpus ( + IN APIC_ID *ToUnplugApicIds, + IN UINT32 ToUnplugCount + ) +{ + EFI_STATUS Status; + UINT32 ToUnplugIdx; + UINTN ProcessorNum; + + ToUnplugIdx =3D 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + + RemoveApicId =3D ToUnplugApicIds[ToUnplugIdx]; + + // + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find + // the ProcessorNum for the APIC ID to be removed. + // + for (ProcessorNum =3D 0; + ProcessorNum < mCpuHotPlugData->ArrayLength; + ProcessorNum++) { + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) { + break; + } + } + + // + // Ignore the unplug if APIC ID not found + // + if (ProcessorNum =3D=3D mCpuHotPlugData->ArrayLength) { + DEBUG ((DEBUG_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID + " to unplug\n", __FUNCTION__, RemoveApicId)); + ToUnplugIdx++; + continue; + } + + // + // Mark ProcessorNum for removal from SMM data structures + // + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, RemoveApicId, Status)); + return Status; + } + + ToUnplugIdx++; + } + + // + // We've removed this set of APIC IDs from SMM data structures. + // + return EFI_SUCCESS; +} + +/** CPU Hotplug MMI handler function. =20 This is a root MMI handler. @@ -309,6 +386,13 @@ CpuHotplugMmi ( } } =20 + if (ToUnplugCount > 0) { + Status =3D UnplugCpus (mToUnplugApicIds, ToUnplugCount); + if (EFI_ERROR (Status)) { + goto Fatal; + } + } + // // We've handled this MMI. // --=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 (#71833): https://edk2.groups.io/g/devel/message/71833 Mute This Topic: https://groups.io/mt/80751397/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- From nobody Thu Nov 14 05:04:45 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+71832+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+71832+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 1613725512581509.40438488980544; Fri, 19 Feb 2021 01:05:12 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id HJlJYY1788612xQWGsLcdMII; Fri, 19 Feb 2021 01:05:12 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web09.6097.1613725505888869563 for ; Fri, 19 Feb 2021 01:05:06 -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 11J93veV178541; Fri, 19 Feb 2021 09:05:02 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 36pd9ag89s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +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 11J8uJSG131491; Fri, 19 Feb 2021 09:05:02 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by aserp3020.oracle.com with ESMTP id 36prp2pa12-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BYK+xL6JGcNPMiYPF6xz2BkXaNBlTf2v0yTGDcnD0qzbUHpc1MbHJDpaktjAKjerooQVQ351XOSn8j0L36b8Uuva4T8uGppOHqUL85I4gOugxWtO5w0AjOQiaqW9vgZ0Ayt4eP8A6fJTkDqFjFpkd3Ta6xvdW54XdQn+WQ6ny0XRjMVojD6jp9KxJ1JGdD0qkVN7dhfFmaQXJDx0lx76RYNHRkKtxg+X6IgpriBS32uFsY6JEI3/zIgQKjx56RVGnRWvnEG9zOtBiN/W+zk9p4Y8qIo/mMJkmLYqRJXlY8+j9Yt7kOdyccQulEr0f6e59cL+vIN4mqyftim2ytT0yw== 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=+3bXinEZ60WMWrmk1NDiDkwT8uTwh3vAxcj3qYBEanA=; b=VXvtoF+SKmGDItyPH0Kdn/0KjjYX0MqdyX+0VPs0ahxDh0Nd1BTIQzwSkmkrheWHWBQKfL4nB0dxkXjyVAZX2WtgBdLlacOS3yu4W+WzgWdHeNzWhrngjw6002RjW/plqSr19naIyiUaivF20OWCthW1bEUeuNAhc3B8bWeHyX1oi0u5ex18RiZyx11OEKp1HLYkZ3+x1nlHvjwZAHyTOvzEiUHMYPHrEVr5PAgRgCTrVLTfaPGAT4DSU/U48wehwzgcRCxUwZVvSpweQIH/z3SbJFyY20Iez2Q/WyFd/Wio/NT7gQFKLJ+xhp0ulBLZUM9ecjWAHVcXvQ7DMKXPGA== 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:04:59 +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:04: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 v7 05/10] OvmfPkg/CpuHotplugSmm: define CPU_HOT_EJECT_DATA Date: Fri, 19 Feb 2021 01:04:39 -0800 Message-Id: <20210219090444.1332380-6-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:04:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21165d02-4107-4184-4f10-08d8d4b56f64 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: t2fWglAegj2AuUG03YG+WfvAmSFTTbElcLj9SJ2tfvMWsnt2lKdzj5kmmw/KjRPYll+6T+l6oUPaWOgyAflm+mm8sy6IJWTV5QyKA9KlMPLxxbFGa6aD5lPTJJmuBoEToTMjRdTUyM1qMsR3KZfXAqwEqc7/vr0ntFsAjxIC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OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21165d02-4107-4184-4f10-08d8d4b56f64 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:04:59.7790 (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: QLwoePifVPhmLu1CtRAuzzCFUZEOj535Vb7HZSnHWIOr94QOsJEBJsLrbCX73dPJyBjPGc0UBo1CZy4YAUO4Hav8TL5QyXEcdHTxEWbhIwI= 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: l7h2WaxkkZF1Fs9TeR0eoi61x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725512; bh=Zv8phFI1iEF1M78VuODfS+UbBO8Z5JwrfJc6O6+Xbv8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=vFHsy8kKtM3/961U9ZYkedo0dGkJQrrWFBlEjbxtMC15U7NNxPN5nxEZHpfA9Ew952h oKKIsQOJ2gBwGbmdCrU5rGgPX9wh6XRTFXf/kSfYLK+4CTcviwEOLeXeNQ/rG40fDCdyM BuCEsKzKv/gjtzUAmLdi0Q4TYYSYd5LAn6U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Define CPU_HOT_EJECT_DATA and add PCD PcdCpuHotEjectDataAddress, which will be used to share CPU ejection state between OvmfPkg/CpuHotPlugSmm and PiSmmCpuDxeSmm. 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 review comments in v6: (1) Dropped modifications to LibraryClasses in OvmfPkg.dec (2,3) Cleanup comments around PCD PcdCpuHotEjectDataAddress. (4) Move PCD PcdCpuHotEjectDataAddress declaration in CpuHotplugSmm.inf to a patch-7 where it actually gets used. (5a,5b) Change the comment in the top block to use Laszlo's language. Also detail when the PCD would contain a valid value. (6) Move Library/CpuHotEjectData.h to Pcd/CpuHotEjectData.h (7,15,16) Fixup guard macro to be C namespace compliant. Also fixup the comment style near the endif guard. (8-10) Rename CPU_HOT_EJECT_FN to a more EDK2 compliant style. Also add a comment block and fix spacing. () Rename ApicIdMap -> QemuSelectorMap while keeping the type as UINT6= 4. Related to a comment in patch-8 ("... add worker to do CPU ejection".) (11a,11b) Rename CPU_EJECT_INVALID to CPU_EJECT_QEMU_SELECTOR_INVALID and add a comment about it. () Remove CPU_EJECT_WORKER based on review comment on a patch 8. (12,14) Remove CPU_HOT_EJECT_DATA fields Revision and Reserved. Reorder CPU_HOT_EJECT_DATA to minimize internal padding and ensure elements are properly aligned. (13a,13b) Change CpuIndex->ApicId map to ProcessorNum -> QemuSelector () Make CPU_HOT_EJECT_HANDLER->Handler, CPU_HOT_EJECT_HANDLER->QemuSelectorMap volatile. OvmfPkg/OvmfPkg.dec | 4 +++ OvmfPkg/Include/Pcd/CpuHotEjectData.h | 52 +++++++++++++++++++++++++++++++= ++++ 2 files changed, 56 insertions(+) create mode 100644 OvmfPkg/Include/Pcd/CpuHotEjectData.h diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 4348bb45c64a..9629707020ba 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -352,6 +352,10 @@ [PcdsDynamic, PcdsDynamicEx] # This PCD is only accessed if PcdSmmSmramRequire is TRUE (see below). gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE|BOOLEAN|0x34 =20 + ## This PCD adds a communication channel between OVMF's SmmCpuFeaturesLib + # instance in PiSmmCpuDxeSmm, and CpuHotplugSmm. + gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress|0|UINT64|0x46 + [PcdsFeatureFlag] gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderPciTranslation|TRUE|BOOLEAN|0= x1c gUefiOvmfPkgTokenSpaceGuid.PcdQemuBootOrderMmioTranslation|FALSE|BOOLEAN= |0x1d diff --git a/OvmfPkg/Include/Pcd/CpuHotEjectData.h b/OvmfPkg/Include/Pcd/Cp= uHotEjectData.h new file mode 100644 index 000000000000..024a92726869 --- /dev/null +++ b/OvmfPkg/Include/Pcd/CpuHotEjectData.h @@ -0,0 +1,52 @@ +/** @file + Definition for the CPU_HOT_EJECT_DATA structure, which shares + CPU hot-eject state between OVMF's SmmCpuFeaturesLib instance in + PiSmmCpuDxeSmm, and CpuHotplugSmm. + + CPU_HOT_EJECT_DATA is allocated in SMRAM, and pointed-to by + PcdCpuHotEjectDataAddress. + + PcdCpuHotEjectDataAddress is valid when SMM_REQUIRE is TRUE + and MaxNumberOfCpus > 1. + + Copyright (C) 2021, Oracle Corporation. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef CPU_HOT_EJECT_DATA_H_ +#define CPU_HOT_EJECT_DATA_H_ + +/** + CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit() + on each CPU at exit from SMM. + + @param[in] ProcessorNum ProcessorNum denotes the CPU exiting SMM, + and will be used as an index into + CPU_HOT_EJECT_DATA->QemuSelectorMap. It is + identical to the processor handle in + EFI_SMM_CPU_SERVICE_PROTOCOL. +**/ +typedef +VOID +(EFIAPI *CPU_HOT_EJECT_HANDLER) ( + IN UINTN ProcessorNum + ); + +// +// CPU_EJECT_QEMU_SELECTOR_INVALID marks CPUs not being ejected in +// CPU_HOT_EJECT_DATA->QemuSelectorMap. +// +// QEMU CPU Selector is UINT32, so we choose an invalid value larger +// than that type. +// +#define CPU_EJECT_QEMU_SELECTOR_INVALID (MAX_UINT64) + +typedef struct { + volatile UINT64 *QemuSelectorMap; // Maps ProcessorNum -> QemuSele= ctor + // for pending hot-ejects + volatile CPU_HOT_EJECT_HANDLER Handler; // Handler to do the CPU ejection + UINT32 ArrayLength; // Entries in the QemuSelectorMap +} CPU_HOT_EJECT_DATA; + +#endif // CPU_HOT_EJECT_DATA_H_ --=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 (#71832): https://edk2.groups.io/g/devel/message/71832 Mute This Topic: https://groups.io/mt/80751396/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- From nobody Thu Nov 14 05:04:45 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+71834+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+71834+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 1613725513097271.3311554309198; Fri, 19 Feb 2021 01:05:13 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id v2hbYY1788612xN0TJoObNGE; Fri, 19 Feb 2021 01:05:12 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.6098.1613725506222021084 for ; Fri, 19 Feb 2021 01:05: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 11J953Ot192904; Fri, 19 Feb 2021 09:05:03 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 36p49bgw0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +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 11J8uJSH131491; Fri, 19 Feb 2021 09:05:02 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by aserp3020.oracle.com with ESMTP id 36prp2pa12-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LoPpl1JxwUYyiXjw7vUuxahpb8xXadkR+84ZVMorexZRzKVAqESpGHYN4NCrm6l/Ir91a1OX5VEtDds4RVoy/vPbH7iYg2Q16s7naxhVfS2HLEgWjavEPC9I77bFjdMeP5Do7uLItVAeQ5ExlSN0w0FKMrrTBZG+cet+3qwfC1+84+LzOzwb1srlS7g1IZrhpFuS/uCBOmY3raORmwK0cPN6JL9lW9gBwNzLw0QZ+GfKEDSkwIXzwI4yH7tV6kCn74yVM6zbNd46vIBVWiKYTuEmNf35D2dQNDGo5DCk4Ef10Q2rV5JE+Z2qr+nHOnZBB3BI3EZoCcQjCjY3+JzjcQ== 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=ZSmLXnkGnrGbL4Gfu1w8+AqfVIYwQx2NR1XNbeKZBdM=; b=A/xUCOgcmNcc/zW0Jw6q9HRjl5DggN/tPM1s75jwEQ2hpevKCcsN+PYHLiaMTADvxrATfYn7mw1IdM5b2Oe5e8v7bWfSkij+7ZJqyGlubtA/nx+NcgSoYbCHLABT33cmeNZOaiDV6e2+KbQvSxPeUNH7tNaqlx+mjggmcqZPUdqAGBW2nAtCAYG3O450BR1G6tGVHW6950BLiR6oblLu4gsjQxKIzrikqvTjLJkepTacLxuwX6S/FQ/a6OLKm7DthpqZ/kW+qIBKSwnQsbcR0apDRcviIjQxip9qMmGztOLuQYRLMpFmxHVIKiqg9RB54/zxSQ+7iChwxYcAcPYheQ== 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:01 +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:01 +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 06/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Date: Fri, 19 Feb 2021 01:04:40 -0800 Message-Id: <20210219090444.1332380-7-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:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 042783e8-6318-43ec-5989-08d8d4b57029 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:124; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: kyS+11IxOWnDRMM/f2Rl9Ge22tyxuU6O0w5ByfWxl9Jz/s+4oVreFPu7MlLXn+40p33uKKVednZEJxFnKzRWmNJUyFGRn3r6WhQ/5P6f0Wj2cmj3FNdMUOO88u2woPobsT6CUKsIyOtDg+ftz04eG7mEOhF5w3xDtpn0SAsZRKbILEwqB40caRfq4CbTlJUyqOJgSeLNcRsngkd5/YSGgOuPjkdDZNxxiQUSXCiBsz7F3r7J4ENOS66kvc39ZvVHsz+xoAR7VfJNkvRnctgtQ/54yx/FIwVaKzEAeB2AwxdfpCAQgT8TryzYWyb9lIMbAnNZHc1XONbPi+Imxm8k0STlDbtfW4gAbgAhI89hLZlCUYNyzWN4tY9P/q0rzcLvne/0Aqf79miUYMIduM5w7+45iTv3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R88yBU+zQ4dKmWofav2i6hSOmRZ8sQWdm3AnUKaFwOTK?= =?us-ascii?Q?LjU+lFu6Jcy4/RZgoSpehmSajDkLl41jhJAqfgUJGSQtxJws6dxObyGEVGqR?= =?us-ascii?Q?9arZ4qJXQWk4/rFo+bjC6GM4fKvwXLJK+rMpGDtpV10pDTKFizIUaZSQcEI3?= =?us-ascii?Q?gjJGG3GZyF8G+qIObajaW4m+0wxYuwMGveAn/dVz2JNcv3LCH7zPcFUxPhi1?= =?us-ascii?Q?uEQNASyz8XgipY1GlEOWxXZ22YWwoMOdtQXKMaBkwziZ6WM1orOseZ+0d3qB?= =?us-ascii?Q?pRX2YtDYvPNCGynMZdT2ZVx0EY28VVhKkQCMUy1vgLjVBuBnJYgff39xsXDd?= =?us-ascii?Q?PXN0t/nPEqpMfEKMtx91J0PbeWXIbElwsxozvMNIspeMHUUTTirYwgjK5P6e?= =?us-ascii?Q?3r8f1Ep86JrkcZQDKDE6+CTbmRsH4MAjsdy2Xfs2+bbrvTMTghJn/w43MHPI?= =?us-ascii?Q?BkaSm45wYLwNoEENZl1Tajp3xdeis+Vsby3ydx3S9B/WoTA9tTjXevQ1vw8B?= =?us-ascii?Q?LZqMlTAeUp/XXFWu7SnFXd/jkGbW03RH2wSok3hH3v7ddM08+HexKPlc/YOe?= =?us-ascii?Q?wZtndRI7JA5X9HRZvdxww1/46a0kc0M1AHYfMz0S71jnQf1nn7Tzds9Ev/6I?= =?us-ascii?Q?7UczN9pv4QVYhdAzz+Hz7JyW?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 042783e8-6318-43ec-5989-08d8d4b57029 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:01.0863 (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: zS6VB2xa+6z4HLOeO4DaRy9oB8OLVQDUHE1eZYMkUFdbKfa3NdfK73+UAjRcC9Q6/tAr8j3Y7fnFGtpxLUc91rr3veqOuaHxIBPGpiPKlNM= 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: hbOy743koFK0Fy77rHLAfG2Rx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725512; bh=HCVedflQ3aC+AswpxjzcH4y8MlUOM8X/TobxFaJlyrs=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HR9EPikmnuYf2rxwFrvgJGGlKCtjWk3eYFBDEzy7UXKpJbBNFoOkA8Uen9kP5J7A1vs Dg90CXzKg3jK10L8fNtSk+JT+R/MoibG2yfFGSxvWXaHY4IUB50J0i4ZduxpOtpDIQ87K AQ6w1S2j2RYvjS7IJMp/6A8nLFamMhW612c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Init CPU_HOT_EJECT_DATA, which will be used to share CPU ejection state between SmmCpuFeaturesLib (via PiSmmCpuDxeSmm) and CpuHotPlugSmm. The init happens via SmmCpuFeaturesSmmRelocationComplete(), and so it will run as part of the PiSmmCpuDxeSmm entry point function, PiCpuSmmEntry(). Once inited, CPU_HOT_EJECT_DATA is exposed via PcdCpuHotEjectDataAddress. The CPU hot-eject handler (CPU_HOT_EJECT_DATA->Handler) is setup when there is an ejection request via CpuHotplugSmm. 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 review comments: (1) Detail in commit message about context in which CPU_HOT_EJECT_DATA is inited. (2) Add in sorted order MemoryAllocationLib in LibraryClasses (3) Sort added includes in SmmCpuFeaturesLib.c (4a-4b) Fixup linkage directives for mCpuHotEjectData. (5) s/CpuHotEjectData/mCpuHotEjectData/ (6,10a,10b) Remove dependence on PcdCpuHotPlugSupport (7) Make the tense structure consistent in block comment for InitCpuHotEject(). (8) s/SmmCpuFeaturesSmmInitHotEject/InitCpuHotEject/ (9) s/mMaxNumberOfCpus/MaxNumberOfCpus/ (11) Remove a bunch of obvious comments. (14a,14b,14c) Use SafeUint functions and rework the allocation logic so we can just use a single allocation. (12) Remove the AllocatePool() cast. (13) Use a CpuDeadLoop() in case of failure; albeit via a goto, not inline. (15) Initialize the mCpuHotEjectData->QemuSelectorMap locally. (16) Fix indentation in PcdSet64S. (17) Change the cast in PcdSet64S() to UINTN. (18) Use RETURN_STATUS instead of EFI_STATUS. (19,20) Move the Handler logic in SmmCpuFeaturesRendezvousExit() into into a separate patch. .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 4 + .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 92 ++++++++++++++++++= ++++ 2 files changed, 96 insertions(+) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/Ovmf= Pkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index 97a10afb6e27..8a426a4c10fb 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -30,9 +30,13 @@ [LibraryClasses] BaseMemoryLib DebugLib MemEncryptSevLib + MemoryAllocationLib PcdLib + SafeIntLib SmmServicesTableLib UefiBootServicesTableLib =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 7ef7ed98342e..adbfc90ad46e 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -11,10 +11,13 @@ #include #include #include +#include #include +#include #include #include #include +#include #include #include #include @@ -171,6 +174,92 @@ SmmCpuFeaturesHookReturnFromSmm ( return OriginalInstructionPointer; } =20 +STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData =3D NULL; + +/** + Initialize mCpuHotEjectData if PcdCpuMaxLogicalProcessorNumber > 1. + + Also setup the corresponding PcdCpuHotEjectDataAddress. +**/ +STATIC +VOID +InitCpuHotEjectData ( + VOID + ) +{ + UINTN ArrayLen; + UINTN BaseLen; + UINTN TotalLen; + UINT32 Idx; + UINT32 MaxNumberOfCpus; + RETURN_STATUS PcdStatus; + + MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + + if (MaxNumberOfCpus =3D=3D 1) { + return; + } + + // + // We want the following lay out for CPU_HOT_EJECT_DATA: + // UINTN alignment: CPU_HOT_EJECT_DATA + // --- padding if needed --- + // UINT64 alignment: CPU_HOT_EJECT_DATA->QemuSelectorMap[] + // + // Accordingly, we allocate: + // sizeof(*mCpuHotEjectData) + (MaxNumberOfCpus * + // sizeof(mCpuHotEjectData->QemuSelectorMap[0])). + // Add sizeof(UINT64) to use as padding if needed. + // + + if (RETURN_ERROR (SafeUintnMult (sizeof (*mCpuHotEjectData), 1, &BaseLen= )) || + RETURN_ERROR (SafeUintnMult ( + sizeof (mCpuHotEjectData->QemuSelectorMap[0]), + MaxNumberOfCpus, &ArrayLen)) || + RETURN_ERROR (SafeUintnAdd (BaseLen, ArrayLen, &TotalLen))|| + RETURN_ERROR (SafeUintnAdd (TotalLen, sizeof (UINT64), &TotalLen))) { + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_EJECT_DATA\n", __FUNCTION__)= ); + goto Fatal; + } + + mCpuHotEjectData =3D AllocatePool (TotalLen); + if (mCpuHotEjectData =3D=3D NULL) { + ASSERT (mCpuHotEjectData !=3D NULL); + goto Fatal; + } + + mCpuHotEjectData->Handler =3D NULL; + mCpuHotEjectData->ArrayLength =3D MaxNumberOfCpus; + + mCpuHotEjectData->QemuSelectorMap =3D (void *)mCpuHotEjectData + + sizeof (*mCpuHotEjectData); + mCpuHotEjectData->QemuSelectorMap =3D + (void *)ALIGN_VALUE ((UINTN)mCpuHotEjectData->QemuSelectorMap, + sizeof (UINT64)); + // + // We use mCpuHotEjectData->QemuSelectorMap to map + // ProcessorNum -> QemuSelector. Initialize to invalid values. + // + for (Idx =3D 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) { + mCpuHotEjectData->QemuSelectorMap[Idx] =3D CPU_EJECT_QEMU_SELECTOR_INV= ALID; + } + + // + // Expose address of CPU Hot eject Data structure + // + PcdStatus =3D PcdSet64S (PcdCpuHotEjectDataAddress, + (UINTN)(VOID *)mCpuHotEjectData); + if (RETURN_ERROR (PcdStatus)) { + ASSERT_EFI_ERROR (PcdStatus); + goto Fatal; + } + + return; + +Fatal: + CpuDeadLoop (); +} + /** Hook point in normal execution mode that allows the one CPU that was ele= cted as monarch during System Management Mode initialization to perform addit= ional @@ -188,6 +277,9 @@ SmmCpuFeaturesSmmRelocationComplete ( UINTN MapPagesBase; UINTN MapPagesCount; =20 + + InitCpuHotEjectData (); + if (!MemEncryptSevIsEnabled ()) { return; } --=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 (#71834): https://edk2.groups.io/g/devel/message/71834 Mute This Topic: https://groups.io/mt/80751398/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- From nobody Thu Nov 14 05:04:45 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+71835+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+71835+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 1613725509303359.0735383430374; Fri, 19 Feb 2021 01:05:09 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id qOOaYY1788612xxIKWGd3jQd; Fri, 19 Feb 2021 01:05:08 -0800 X-Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web08.6044.1613725508235378302 for ; Fri, 19 Feb 2021 01:05:08 -0800 X-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J94GeU111126; Fri, 19 Feb 2021 09:05:05 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 36p7dnrn81-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:04 +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 11J8uDEf164199; Fri, 19 Feb 2021 09:05:04 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-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QPgr7VmdozPkpUOIJ9ERZkJ+sUqrhyoYDNuoGbjogr1vjkwSZqAcTNFVDq/sEUKTW71ixafOcO/23Dfz4tOr6YVIsDKeK8RIhMMkv+Pkckl+Ctnp2h/9S3P5fwLw1zjwrOT1jWfU1U37/qfPlMqOcopZW22huUq/ZH5CesDaXIGrsbGJf59EVgPPwO4T49jtdgORrwpYV/qinziJ8jp6DsY1fPjlDddpaniHtzjMUFAYg/zEwaSMkBeVh8Qf1v3uGU/JchJl5mx5N1fIkx+wQ6X2YFhZZTNkqwbA5vwTY1P4QQd+eKGpiYxsMP9qi0ILDN8jXIpmVd2xUgUxF4A2Mg== 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=peem+hchwuwd8Ambz/j8BraugAi7vEGN0rZ8mmkOR9U=; b=BLY3Lpt+IsC9OTerGGr4DqhHFf27pvUEVaHYQRiT/66NAMm6/GP8Ql/S0YPKvENkY9Ih8bUrOK+x3kbtlct+uZzjSpdIgyI5ru7X0M0ia7ePvvMg1MTO6X2FC9ab13DYr8JKXugCQUhugmQwjNjeD8xVnc61ViP38jTNakww+iQQi/Uk5Br2GmVC55dAr2pWMpTcNgV+UKEQcCzyduRXZBU5Z/BiS9XrAAI8WK7fqwPz57+tHrCDHILEtMzduu5zbFlt43ANEkyyNSDwnfZJMNZOVfwwUDd3540tqaC0QrpoNaIGdkmoBJVe2dy/C8uXYFGr4uGt4lNw86VnZHnv7Q== 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:02 +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:02 +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 07/10] OvmfPkg/SmmCpuFeaturesLib: call CPU hot-eject handler Date: Fri, 19 Feb 2021 01:04:41 -0800 Message-Id: <20210219090444.1332380-8-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:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fa14554c-81f9-4bdf-59be-08d8d4b570df X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: GbxGzF+WopetGtYLXlRbcM2HmfxAmndGLZFes5YVPgcB00oNKkXrC9w/cG1ZsEngXJnpsgzGiwwkgr0lsvWwWuxsEhQTO2qgXxx8nnCgZYS0yl7qz+EfSUYy6QzaJLMBljvUghVtrdO7W6hhdLMqjyXGSreh7mOvj3HsFGvWtJfsKNtsNWJsFnijuXq4fXgq9IdSnZdWN1TqYplYkoEKGGXKk1URT6GLvqD1NhJBy1X0fsAaGagEcVuQnjMcCnAPVp+MFy99+PRaKOIhJoppEz0xRDLqGcXgN/fA+oKIFd+q1Ny9RxTLXlX9E0eLrC2ifqQbss0uTG3+AV6wCij509UYPCzINPastfUIOw8BFPE/p1dVrKisdhupHBVo3jUSYOy8JrlockIvJLYbvvnLPLk05afntxPs4Q8ULDC6lKWITALfSUJHCJSmT2NEtLCQLaC0XePHpmzthLD6JyTojVIa3hzZRu3LPf8nX0VsEjAUg0PINyzxFtVGUqK/wK01L8QVg1jGTvRZv/pQ8tH+OE1u9tS3IPbxM+2+0lqg5nhzlV5MfV1NaEhLvzHN6cAYV+otB7Y/kLjGXzgic4u6kOBAi127VAEApRIoiJVGDRE= X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?CjXd+kEgKQUSbS/qKHa03KqPfhwpOptvuYht8PO6ormKhEK8Htad4gRrvQwt?= =?us-ascii?Q?QIac+BaJ25EZ5i+76/0nRL/Kc4T1a5GoHmCNGPpKvJB90w2xScyYpNPxhmnY?= =?us-ascii?Q?RQdW7pkJbm3R1ciba/I7jnL9Q/wUqNketWWUB2ZTIDKg2TyihDtoc6Y03Up9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W7RE+hGiLtHyRptBHx71tpLCslx3xuUjb0?= =?us-ascii?Q?Y8O5gA1d/7cLTbea3DcyRP1II2WWkjO9/n4plPVIYhDDvyE7NhVsbhj3Gt9w?= =?us-ascii?Q?w6kG6Eu+rqWfUMy2u3GaU3TecYLRNg0RVZfZo+ZlYfrVwO8HRg9sqgGryChn?= =?us-ascii?Q?qT7lOq2yt09ktbFzSTSmcCjFxc/h1g3sa1P4t68Zlt4cKn7li2M7XdMWT9rJ?= =?us-ascii?Q?VxwkR/JvQF77apZq5gegdroqL4ARo1AE936j4GgK1uLwf7yaePY7KsK331wq?= =?us-ascii?Q?vSNW3lVuBokPyi9N/Kn3ewkS?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa14554c-81f9-4bdf-59be-08d8d4b570df 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:02.2771 (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: 1GwGAQCNnnexzeZ2tu1VBtU/QEGebFkiyE1ccmCryWeOuGDwyA1qE6SybSt6OAfsI4EPiWSe717qVxVA97dTPo571y85tSxOkIgbpzIFFYs= 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: bu521SezxiIYl5fv8INirntOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725508; bh=vFnuHpa7OPtZVVKX0SqfJBZ8qP6kcx6d2HmDsO95sdI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XGgpZMbZpPrMkuFV1of+h+fRi9QulgVUPJ39SJiQc2uiWaVJOh4u0qeK+P3dBFXKI1P SqhSYNm87ZQ4uWtsjLa9jae3zgIkpa2D29YWOBwHBFiAIgPdx0eBzX88PFpPVKGZSgpdf UmzPWu2xu7yJ+qqH1kWMYd/ivhFUrCIoTuE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Call the CPU hot-eject handler if one is installed. The condition for installation is (PcdCpuMaxLogicalProcessorNumber > 1), and there's a hot-unplug request. The handler executes in context of SmmCpuFeaturesRendezvousExit(), which is called at the tail end of SmiRendezvous() after the BSP has given the signal to exit via the "AllCpusInSync" loop. 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: Address the following review comments from v6, patch-6: (19a) Move the call to the ejection handler to a separate patch. (19b) Describe the calling context of SmmCpuFeaturesRendezvousExit(). (20) Add comment describing the state when the Handler is not armed. OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index adbfc90ad46e..c5cfe2610c23 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -467,6 +467,19 @@ SmmCpuFeaturesRendezvousExit ( IN UINTN CpuIndex ) { + // + // We only call the Handler if CPU hot-eject is enabled + // (PcdCpuMaxLogicalProcessorNumber > 1), and hot-eject is needed + // in this SMI exit (otherwise mCpuHotEjectData->Handler is not armed.) + // + + if (mCpuHotEjectData !=3D NULL) { + CPU_HOT_EJECT_HANDLER Handler =3D mCpuHotEjectData->Handler; + + if (Handler !=3D NULL) { + Handler (CpuIndex); + } + } } =20 /** --=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 (#71835): https://edk2.groups.io/g/devel/message/71835 Mute This Topic: https://groups.io/mt/80751399/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- From nobody Thu Nov 14 05:04:45 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+71836+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+71836+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 161372551550237.2718002776146; Fri, 19 Feb 2021 01:05:15 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id oDSNYY1788612xQDuNY7TZbZ; Fri, 19 Feb 2021 01:05:15 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web08.6045.1613725509170432364 for ; Fri, 19 Feb 2021 01:05:09 -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 11J94vK7192839; Fri, 19 Feb 2021 09:05:06 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 36p49bgw0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:06 +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 11J8uDEg164199; Fri, 19 Feb 2021 09:05:05 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-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GjXWFppySvxidKQEPyeC/rdR/lb2UL0i44u6PwyzJs7JHxOUvuju8dIiorrqzVjilAswb/hpQerPeXA/ZbFgwjf6wUzqAENq+JlsnflL/v0lZmEa+AeNg4KrgTzAuUQgTN8Hb+yhIEKFPaENVquWQC+dlAlvx0qkTcQf9xHu8lfy2hJ01+9SzJEnaaqpuddOGODIRChuQ4WFX/NIhsDZh0g6uZpsnjTjkOYeXBbrKE9iPNhqwB5JyHnw8AyElzkpdnnDX4MrzDeejV2pdRecwyn8idhOdHMheVUVI3VZSqX8+Rj8xjE61REvoljhHEvJZ61olJ+Cb5k09mbFCHdbWw== 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=8O+v4Cw/pnCptuFQ6/9+HeC9SUdImG7B9ejbq/+vRd4=; b=Awb4LjsC8ikUPXroZkeWnQZBjN38asHLjq54DVd9n1Do9fhyEXMmqfjLTLwh5HGaqvGMRrMXtlqhkF74fn8q9AgmccBeQ7rsHU4G2B87DYQFftppl4ReOap5yKy6MCyBzDX/B7SD/4Ekjzrwi+YsAfkWXLo2ECnzqJB7QirJoCWnz45UohJ/I1A96K9Dbnpy8N7xcdWkHzuHQ8q1rZtZIOj17Lv/6gqkrEjdqqT6Eq92hohJX7N0Gt1eatQR2RMduqGSkwMB1O8UykXHa+OJl7pCLpKhF3il5Svcvw13OiAa/d6Lti5j/xoFYofd357mSM2TURvG8RnWM52PBzKnxw== 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:03 +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:03 +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 08/10] OvmfPkg/CpuHotplugSmm: add EjectCpu() Date: Fri, 19 Feb 2021 01:04:42 -0800 Message-Id: <20210219090444.1332380-9-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:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e7d1a7db-c3fe-4a05-fc59-08d8d4b5719f X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 21U5WDjkrOKMXWnrUMHh0jJIWnff8O7wfDYGwMunQLSrE+l/nBZtfjQ+MEmrMoBtUmLtlQGgFaMOcXg/Y8PY2DQayxZ7fBRXIWtUuqy1XSaQiLwGEkzOQajb4f5vHcm2tkPCyM/tlczzGK4uGcMkAv5OuAd6HtXElgVUMYYESCdd5fowQzB/9aj0bXW9SZy4pHv9mSe3UTyRsR4DPorLMUuMZoNdt83x+Rg2s9Zu/vbByvtkKwSc2QbI6k0/zcwVudq/W1fcnf6S42nmGwUJvfP1KVDAb7dRdqw78/mWyThTx+pfx/hLO5qds2nVb4cobvpvewKOSYj03Pc9p54NMUo6B0/rlYhsWcKQaeproN6pqKNOdMCbgnvHyLmJMHIFmeCTvTee3dfVc0TqoZ2XlgGBw5ve4dvV8yQZHCk7VXdAaOoEAoTt1Ot8zYGw/Z1eLgTGS7ZGMRj07AzS5dlou+PnDEtVX32IwlN4rUOrng+TdjQw8E2IsmufngSzINNB07w7AZGsysXsyytkgMF1P7Uqg6lySWM9SpWihcITcIUc7aCjEMOjEQUCye2Bo8o4pgwtbsZOaRJAWbd27YbqIg36CafjhXsnG39k4gkew48= X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?720v8CUzNFo7lcWnJNBVUcBcr9o0t74gz0xSUZ+dCYR0AFVM60Xc+GTTdzjs?= =?us-ascii?Q?HDWXNTIiG86TL4fnXGpzinejxCfJQJIMDppqx4WtSNAuzuAaNrt3mmfTKbbP?= =?us-ascii?Q?3eNj3vfNBSe+YMiLTPHyqcVlp1T/nxkbY2tIBC+QBQGrzDZ/mDaqp2rTW+At?= =?us-ascii?Q?dYmte5myQqDi+gvbIL2pye4RWjPe1O4pUVI9hopDHjs42jQLqOJTFUov4x5w?= =?us-ascii?Q?hh2Gh8vFeknHFBwsDhGwSrLZASEIR2VtMddiUyZT9AYafW762Dx7OsCfyc38?= =?us-ascii?Q?GBg8ZUDJCr8/f16u9plGTltn+qOblC1mgaa20g7SKcgIeu259pVouDCoiuRC?= =?us-ascii?Q?bjhEHuJLgy5R7Pjr/0bIgF9Tsn083XyQa2VADKamDmrRkZAUwUrZxrPpArr7?= =?us-ascii?Q?x+v2OqAW0t7NiElzQIm0PRLFezEit/HFPzmZCKPROVOHT6GX9r7TXBtY/MgG?= =?us-ascii?Q?zJxwnRmde8Bz0swc+EXlCcP0DWqy2OlZ/v3XPN4SJd5+41vlboID/DaqvhiR?= =?us-ascii?Q?sIIpZ0fy0erXPhleYLLF5LZYoBmsc3GPk9AZvSltf89Li9jG9U4Oyy2LiOVn?= =?us-ascii?Q?GyjGDFO8Wt8Z0E2j+XyughdZ8k0DGIqUMV4I6oX1i6w394+ineGZEwi7RJHU?= =?us-ascii?Q?qIwzydAzH+AwGb0vTkvxJrUJBp4VuroPvCKnjJxKX5W3zxLNITtRbrouSvF0?= =?us-ascii?Q?8keIQAow8L5dYxbtnzJ0c90pEbqAvI97Tk1WT2FJk8FLaVuBXyUrkElhik1B?= =?us-ascii?Q?921zlOMFW2XJXvwWThU5tcCvHjN87O5mrKetYRDIJ9ymjS3atASq8LwiRPtH?= =?us-ascii?Q?Sp5W93c0oMftrmMrZRxLEIRfD8zfCsWDTV97Rg/sN2y1ivHjkLAxJ5pdSkgs?= =?us-ascii?Q?g8W8lp+A8rUWTx5bC1RVGi5DzzSULFUDYMoMA/Ojhk13mw1YZd6hxMaxiin9?= =?us-ascii?Q?rEyMNsu+c8B8nl8rZPMYvM4zZNkP/0A5nbzc6NIukz+bhnuNwlAl/9seerYc?= =?us-ascii?Q?Qg/6bmfV+kgk0av03rbqJYbtgTry8MJb/jfwk4jjGDIaDK0PM/9oXGv+cvwN?= =?us-ascii?Q?aF0u60nYz/PBxe6j17FhzJXHpCv6Cya+ROwH33WOx9H18DgZracmilAacppE?= =?us-ascii?Q?n7t2tuNf5WR835ZdW3B2W6u5QCuk+qMJo5rvo3wplwppIOQXmoUE9obk7BrC?= =?us-ascii?Q?c5J7Uujjq9KuRo/pRQEC8ahX3gDMniWTYLbvTFvmrPbUfLADMMnaM9lponoM?= =?us-ascii?Q?faYF9qGX1K7j6wcQPK2dtlCjjUkIcGt2j3qJu78uAOcwrIYU+9FWaJvgHfce?= =?us-ascii?Q?cKwhNikrAT0+KnRFBEyt+UaG?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7d1a7db-c3fe-4a05-fc59-08d8d4b5719f 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:03.5166 (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: zUz6h+FLVKpDw21vqI4yzWUMwsdWnMRQZUbJKM2BeC5Hl/UDoMTVvGgR3eJmmYfqYla9UHII145YfCQ6y7464wFzaYvnb0WOjWhg415yVK4= 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: PiMlBuwsPp0Z3GMOB2dFONBrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725515; bh=37JTdiqTQ68toBzmV6kHjrMu0NhSkRZ5nSBQFSaBCJU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PpFM3/5BrBlnBC2d0dyWHItbzMblwgFdzT+kdGr0p+W2SuBaHd+CUkQVDNoc/RM2lBa pBZqng91/w1PdZs4yR0yn4GTMcl3uFLrL/zBNDo/zVH7576BlhsJ7LXWcbdMp8v/pv5sO wG5j66AVoXJs6QIGsc92Ql4eQSdTLQEi+MI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add EjectCpu(), which handles the CPU ejection, and provides a holding area for said CPUs. It is called via SmmCpuFeaturesRendezvousExit(), at the tail end of the SMI handling. Also UnplugCpus() now stashes QEMU Selectors of CPUs which need to be ejected in CPU_HOT_EJECT_DATA.QemuSelectorMap. This is used by EjectCpu() to identify CPUs marked for ejection. 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: Address these review comments from v6: (1) s/CpuEject/EjectCpu/g (2) Ensure that the added include is in sorted order. (3) Switch to a cheaper CpuSleep() based loop instead of CpuDeadLoop(). Also add the CpuLib LibraryClass. (4) Remove the nested else clause (5) Use Laszlo's much clearer comment when we try to map multiple QemuSelector to the same ProcessorNum. (6a) Fix indentation of the debug print in the block in (5). (6b,6c,6d) Fix printf types for ProcessorNum, use FMT_APIC_ID for APIC_ID and 0x%Lx for QemuSelector[]. () As discussed elsewhere add an DEBUG_INFO print logging the correspondence between ProcessorNum, APIC_ID, QemuSelector. (7a,7b) Use EFI_ALREADY_STARTED instead of EFI_INVALID_PARAMETER and document it in the UnplugCpus() comment block. () As discussed elsewhere, add the import statement for PcdCpuHotEjectDataAddress. (9) Use Laszlo's comment in the PcdGet64(PcdCpuHotEjectDataAddress) description block. (10) Change mCpuHotEjectData init state checks from ASSERT to ones consistent with similar checks for mCpuHotPlugData. (11-14) Get rid of mCpuHotEjectData init loop: moved to a prior patch so it can be done at allocation time. (15) s/SmmCpuFeaturesSmiRendezvousExit/SmmCpuFeaturesRendezvousExit/ (16,17) Document the ordering requirements of mCpuHotEjectData->Handler, and mCpuHotEjectData->QemuSelectorMap. Not addressed: (8) Not removing the EjectCount variable as I'd like to minimize stores/loads to CPU_HOT_EJECT_DATA->Handler and so would like to do t= his a single time at the end of the iteration. (It is safe to write mult= iple times to the handler in UnplugCpus() but given the ordering concerns around it, it seems cleaner to not access it unnecessarily.) OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 2 + OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 157 ++++++++++++++++++++++++++++= ++-- 2 files changed, 151 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf b/OvmfPkg/CpuHotplugSm= m/CpuHotplugSmm.inf index 04322b0d7855..ebcc7e2ac63a 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf @@ -40,6 +40,7 @@ [Packages] [LibraryClasses] BaseLib BaseMemoryLib + CpuLib DebugLib LocalApicLib MmServicesTableLib @@ -54,6 +55,7 @@ [Protocols] =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress ## CON= SUMES + gUefiOvmfPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress ## CON= SUMES gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase ## CON= SUMES =20 [FeaturePcd] diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index f07b5072749a..5dcaca53d42f 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -10,10 +10,12 @@ #include // ICH9_APM_CNT #include // QEMU_CPUHP_CMD_GET_PENDING #include // CpuDeadLoop() +#include // CpuSleep() #include // ASSERT() #include // gMmst #include // PcdGetBool() #include // SafeUintnSub() +#include // CPU_HOT_EJECT_DATA #include // EFI_MM_CPU_IO_PROTOCOL #include // EFI_SMM_CPU_SERVICE_PROTOC= OL #include // EFI_STATUS @@ -32,11 +34,12 @@ STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo; // STATIC EFI_SMM_CPU_SERVICE_PROTOCOL *mMmCpuService; // -// This structure is a communication side-channel between the +// These structures serve as communication side-channels between the // EFI_SMM_CPU_SERVICE_PROTOCOL consumer (i.e., this driver) and provider // (i.e., PiSmmCpuDxeSmm). // STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; +STATIC CPU_HOT_EJECT_DATA *mCpuHotEjectData; // // SMRAM arrays for fetching the APIC IDs of processors with pending event= s (of // known event types), for the time of just one MMI. @@ -188,18 +191,72 @@ RevokeNewSlot: } =20 /** + CPU Hot-eject handler, called from SmmCpuFeaturesRendezvousExit() + on each CPU at exit from SMM. + + If, the executing CPU is not being ejected, nothing to be done. + If, the executing CPU is being ejected, wait in a halted loop + until ejected. + + @param[in] ProcessorNum ProcessorNum denotes the CPU exiting SMM, + and will be used as an index into + CPU_HOT_EJECT_DATA->QemuSelectorMap. It is + identical to the processor handle number in + EFI_SMM_CPU_SERVICE_PROTOCOL. +**/ +VOID +EFIAPI +EjectCpu ( + IN UINTN ProcessorNum + ) +{ + UINT64 QemuSelector; + + QemuSelector =3D mCpuHotEjectData->QemuSelectorMap[ProcessorNum]; + if (QemuSelector =3D=3D CPU_EJECT_QEMU_SELECTOR_INVALID) { + return; + } + + // + // CPU(s) being unplugged get here from SmmCpuFeaturesRendezvousExit() + // after having been cleared to exit the SMI by the BSP and thus have + // no SMM processing remaining. + // + // Given that we cannot allow them to escape to the guest, we pen them + // here until the BSP tells QEMU to unplug them. + // + for (;;) { + DisableInterrupts (); + CpuSleep (); + } +} + +/** Process to be hot-unplugged CPUs, per QemuCpuhpCollectApicIds(). =20 For each such CPU, report the CPU to PiSmmCpuDxeSmm via - EFI_SMM_CPU_SERVICE_PROTOCOL. If the to be hot-unplugged CPU is - unknown, skip it silently. + EFI_SMM_CPU_SERVICE_PROTOCOL and stash the APIC ID for later ejection. + If the to be hot-unplugged CPU is unknown, skip it silently. + + Additonally, if we do stash any APIC IDs, also install a CPU eject handl= er + which would handle the ejection. =20 @param[in] ToUnplugApicIds The APIC IDs of the CPUs that are about to= be hot-unplugged. =20 + @param[in] ToUnplugSelector The QEMU Selectors of the CPUs that are ab= out to + be hot-unplugged. + @param[in] ToUnplugCount The number of filled-in APIC IDs in ToUnplugApicIds. =20 + @retval EFI_ALREADY_STARTED For the ProcessorNum that + EFI_SMM_CPU_SERVICE_PROTOCOL had assigned = to + one of the APIC ID in ToUnplugApicIds, + mCpuHotEjectData->QemuSelectorMap already = has + the QemuSelector value stashed. (This shou= ld + never happen.) + @retval EFI_SUCCESS Known APIC IDs have been removed from SMM = data structures. =20 @@ -210,23 +267,36 @@ STATIC EFI_STATUS UnplugCpus ( IN APIC_ID *ToUnplugApicIds, + IN UINT32 *ToUnplugSelector, IN UINT32 ToUnplugCount ) { EFI_STATUS Status; UINT32 ToUnplugIdx; + UINT32 EjectCount; UINTN ProcessorNum; =20 ToUnplugIdx =3D 0; + EjectCount =3D 0; while (ToUnplugIdx < ToUnplugCount) { APIC_ID RemoveApicId; + UINT32 QemuSelector; =20 RemoveApicId =3D ToUnplugApicIds[ToUnplugIdx]; + QemuSelector =3D ToUnplugSelector[ToUnplugIdx]; =20 // - // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find - // the ProcessorNum for the APIC ID to be removed. + // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use RemoveApic= Id + // to find the corresponding ProcessorNum for the CPU to be removed. // + // With this we can establish a 3 way mapping: + // APIC_ID -- ProcessorNum -- QemuSelector + // + // We stash the ProcessorNum -> QemuSelector mapping so it can later be + // used for CPU hot-eject in SmmCpuFeaturesRendezvousExit() context (w= here + // we only have ProcessorNum available.) + // + for (ProcessorNum =3D 0; ProcessorNum < mCpuHotPlugData->ArrayLength; ProcessorNum++) { @@ -255,11 +325,64 @@ UnplugCpus ( return Status; } =20 + if (mCpuHotEjectData->QemuSelectorMap[ProcessorNum] !=3D + CPU_EJECT_QEMU_SELECTOR_INVALID) { + // + // mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is set to + // CPU_EJECT_QEMU_SELECTOR_INVALID when mCpuHotEjectData->QemuSelect= orMap + // is allocated, and once the subject processsor is ejected. + // + // Additionally, mMmCpuService->RemoveProcessor(ProcessorNum) invali= dates + // mCpuHotPlugData->ApicId[ProcessorNum], so a given ProcessorNum can + // never match more than one APIC ID and by transitivity, more than = one + // QemuSelector in a single invocation of UnplugCpus(). + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %Lu maps to QemuSelector 0x%L= x, " + "cannot also map to 0x%Lx\n", __FUNCTION__, (UINT64)ProcessorNum, + (UINT64)mCpuHotEjectData->QemuSelectorMap[ProcessorNum], QemuSelec= tor)); + + Status =3D EFI_ALREADY_STARTED; + return Status; + } + + // + // Stash the QemuSelector so we can do the actual ejection later. + // + mCpuHotEjectData->QemuSelectorMap[ProcessorNum] =3D (UINT64)QemuSelect= or; + + DEBUG ((DEBUG_INFO, "%a: Started hot-unplug on ProcessorNum %Lu, APIC = ID " + FMT_APIC_ID ", QemuSelector 0x%Lx\n", __FUNCTION__, (UINT64)Processo= rNum, + RemoveApicId, mCpuHotEjectData->QemuSelectorMap[ProcessorNum])); + + EjectCount++; ToUnplugIdx++; } =20 + if (EjectCount !=3D 0) { + // + // We have processors to be ejected; install the handler. + // + mCpuHotEjectData->Handler =3D EjectCpu; + + // + // The BSP, CPUs to be ejected dereference mCpuHotEjectData->Handler, = and + // mCpuHotEjectData->QemuSelectorMap[] in SmmCpuFeaturesRendezvousExit= (). + // + // Assignments to both of these are ordered-before the BSP's SMI exit = signal + // which happens via a write to SMM_DISPATCHER_MP_SYNC_DATA->AllCpusIn= Sync. + // Dereferences of both are ordered-after the synchronization via + // "AllCpusInSync". + // + // So we are guaranteed that the Handler would see the assignments abo= ve. + // However, add a MemoryFence() here in-lieu of a compiler barrier to + // ensure that the compiler doesn't monkey around with the stores. + // + MemoryFence (); + } + // - // We've removed this set of APIC IDs from SMM data structures. + // We've removed this set of APIC IDs from SMM data structures and + // have installed an ejection handler if needed. // return EFI_SUCCESS; } @@ -387,7 +510,7 @@ CpuHotplugMmi ( } =20 if (ToUnplugCount > 0) { - Status =3D UnplugCpus (mToUnplugApicIds, ToUnplugCount); + Status =3D UnplugCpus (mToUnplugApicIds, mToUnplugSelector, ToUnplugCo= unt); if (EFI_ERROR (Status)) { goto Fatal; } @@ -458,9 +581,14 @@ CpuHotplugEntry ( =20 // // Our DEPEX on EFI_SMM_CPU_SERVICE_PROTOCOL guarantees that PiSmmCpuDxe= Smm - // has pointed PcdCpuHotPlugDataAddress to CPU_HOT_PLUG_DATA in SMRAM. + // has pointed: + // - PcdCpuHotPlugDataAddress to CPU_HOT_PLUG_DATA in SMRAM, + // - PcdCpuHotEjectDataAddress to CPU_HOT_EJECT_DATA in SMRAM, if the + // possible CPU count is greater than 1. // mCpuHotPlugData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotPlugDataAddress); + mCpuHotEjectData =3D (VOID *)(UINTN)PcdGet64 (PcdCpuHotEjectDataAddress); + if (mCpuHotPlugData =3D=3D NULL) { Status =3D EFI_NOT_FOUND; DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_PLUG_DATA: %r\n", __FUNCTION__, Stat= us)); @@ -472,6 +600,19 @@ CpuHotplugEntry ( if (mCpuHotPlugData->ArrayLength =3D=3D 1) { return EFI_UNSUPPORTED; } + + if (mCpuHotEjectData =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + } else if (mCpuHotPlugData->ArrayLength !=3D mCpuHotEjectData->ArrayLeng= th) { + Status =3D EFI_INVALID_PARAMETER; + } else { + Status =3D EFI_SUCCESS; + } + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: CPU_HOT_EJECT_DATA: %r\n", __FUNCTION__, Sta= tus)); + goto Fatal; + } + // // Allocate the data structures that depend on the possible CPU count. // --=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 (#71836): https://edk2.groups.io/g/devel/message/71836 Mute This Topic: https://groups.io/mt/80751400/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- From nobody Thu Nov 14 05:04:45 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-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Y14KTjtwI93zT6LLxUOXVPohJ2RnW3qXVANlPwJAIi+RLCBt6R/bqIbOY8D5x5xwb7gQGAeQG6mBrFF76MSllO2neNgubvXx4RW5rwKBzXuRKqOGk6IflWxrdjem5XU6UNN7P63f6PWJbCiy/OUMCZuSIUGPyZDsU9Ny45kPPXlvaEOs8iWwJsSfeT53g4X8zywgqM0cerLfcA5psBn/SZOxTiKaSHOtCvi42PVCLFO9jVIdnjcgwmKFQk/r9hKZmG9ujPrJIx/4rZIbKJ1Rebc+Vm0zTrwgSOBGcQ1g37DXjs7iPO4mHUwsrsqvkK1sFEDKToDudm26kf1yQmFMHmZW8LWI2PWTBGCzR2JcjlHKdWq8oOeZtu5BaijSOA63SOji+I0C63VmAxot1BpobZf2vlq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IHDzhZS6ZM/HOFrjaxduCSgtLI12nXah/0wU1rznn2rmR1H?= =?us-ascii?Q?f7gXwesPTSU7BYGBkzjYFssefsfq7MuR/Jfy9CNbE9OdtwUKAR1+vrdxsNvE?= =?us-ascii?Q?6yGLv6JsBcwpZjey2hs+gxhZch5f+HT2BqJP4RfG+YrdrNPz6qY1FjZYZYGZ?= =?us-ascii?Q?qvsS4e9bafi5e9Lnd1j6wmpXAaxOGBwaFoCn7HHwKNB9v3qqjFWx3QjjZKp0?= =?us-ascii?Q?WmYOyREkqYyk4OgTUR2i/mOeBhkr1GqFIA0gUBNpPSLNfTknc1AwswBe46Mb?= =?us-ascii?Q?gj57wB4kAGbkehKegpkhmqgWTvGONgdotgxHTzOxQPNfY5UnyUAXE++yoBo9?= =?us-ascii?Q?R8lqnLd/IiXMSfvzgDmbOGuw2igW5gC27quyrZbSkLjiNGACiGxkeATX/RFD?= =?us-ascii?Q?AQWYbX44L0obJRHQ1yhCbHJa4u/g35AIRHXp/ErkFsk12IULm4/1l/IH7Wi7?= =?us-ascii?Q?jAvtDObVVifm5czf25E9XtIGjaBcOU004X2O4dkQZUDrzCojabZaeS7hSn4f?= =?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- From nobody Thu Nov 14 05:04:45 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+71838+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+71838+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 1613725521577646.2706312167082; Fri, 19 Feb 2021 01:05:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q9H9YY1788612xTCOgpTa1RB; Fri, 19 Feb 2021 01:05:21 -0800 X-Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by mx.groups.io with SMTP id smtpd.web12.6146.1613725515382964226 for ; Fri, 19 Feb 2021 01:05:15 -0800 X-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J94GeV111126; Fri, 19 Feb 2021 09:05:11 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 36p7dnrn88-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:11 +0000 X-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 11J8uU7G011766; Fri, 19 Feb 2021 09:05:10 GMT X-Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2176.outbound.protection.outlook.com [104.47.55.176]) by aserp3030.oracle.com with ESMTP id 36prbrwvyu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Feb 2021 09:05:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SYcQt47fpLS4M28oXpv2qmFn7XmuCSoYWe/QzWsJ+SNIFKqqigJvPmvMyVFjySDV4+VQQXqiSWk5zvt/u6nXJAtttHj67YpX1TvKgbpexzE3FsldDOQmAjlkj+cruJtvL0ZXje647kN+2AJ6iqhX0VRD3nzLZwte9XPIAbfExZRj2d/bUskw3Bdtp+cPtRofN8gGT04ndugSKXV/osBwf1Y5OxaOnB/qB+b7vVDPeYLZoATaznPKvNS99QwWJqJXTWE/Oy6ejjkx3AiW2+aEVsLKTJvgghQb+J10qF17X/7RFRzED9cz9Waoy7YeK686iY+fvrSCSROTEBXJhZX1AQ== 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=9bkWGfoq1y7L5hpHb9XwV6nCkXOVbulHM1KyVz0wRtg=; b=EugBkJnKhrf8lOxlyocXIOH/ZhKra2r3nx9H8HV/pecFQuCztSVEDnOjhFFEkzHucoVYxeNyK8vHglNazVgvz5ADHjldsQFz36lskEXazZYpHEpyQMwLapQX+yrr6QoX3q4HfPwfwFqubh1nyxu+BRcuhCaTTGbP+hRAsHQ7eVuzdjZ621MIU1N8ZmEvVULijERKxin+GAaCp4W8r2SoUwX6eUr+KvKihwwxRxe4S3rHy+hodpOzrYBWnQyv3dox1Uwc+i7ntzmT13hs/qPR4gU/bAVjveZLxkpwdN58yeXqZwrf9QlKhURb2RiqzAFoi/7WlNPBeUz7cU1LOiVNjQ== 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:06 +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:06 +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 10/10] OvmfPkg/SmmControl2Dxe: negotiate CPU hot-unplug Date: Fri, 19 Feb 2021 01:04:44 -0800 Message-Id: <20210219090444.1332380-11-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:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95113c2f-49d5-4855-4afc-08d8d4b57318 X-MS-TrafficTypeDiagnostic: BYAPR10MB3605: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: bllc3OA64aTBxhK3cZuxM0pdlMKvcl6cSY8wdj1VWijYtWpuLzpMLVnW6iYuSDvYBESqXpT33wvcfcZc8zMVm6eIFO81uS0OAae7akqOOvaKn062Ojmm5oUCXXdjDG+2Rv6EHldMGmRUK6+3dI3BxeNjoKGIz3HIgpTu7y6vGiYZJupDyYREQfdrjMBedBKf9PR6XDYnkxqdt16d7pd1q4yABKWUfiYEg/fkilnPvfDQpMQN/VVGXxONhKLUqM0a6l/3yhmoE5of4F/3T0G0Af4WNCvVUwhR4q40f4COIxRmG8GjZJ34VtAaPonzFE2IFtPZ8a2rZIfHOYj9+HRwq2IRbdGeDAy/DDDNFxaEmpnLMJhNId2BNqh8vU/YY6oq7KVoYksuGiwWmNg6vQRatw7hxE6iqMDvl30/w48eW75GZOkZiHxnpXDxE9w5UyVknqxi0RPISmYvosqVi+27XjbApSSGDi47TPiEuhfMad1O8b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Nk3znWNbD/Hal1/qydoGDvydsJnw4+C8fsRC2?= =?us-ascii?Q?cFleBHhwIUrSYhfU/QAe8Kz+dkY4Y4OugbZY53OOP49qRsLYjICTv7uwoJZq?= =?us-ascii?Q?PImqHsCw9wTiuirZFTpRQjd4A9Mq4+z1C17teEialgaw7Xz3o0tr90+gJ7Cr?= =?us-ascii?Q?T2AtQic3lyCMcpacBx8jh23VpJGuzHeW2HfVyW+0AZU8VGubuMx/uIFzyL0Z?= =?us-ascii?Q?9vVwOtG+agy/SFSVQan8wNrbHXbVUi78dXZdxB6gzRT/iJyhBIuTNGkl41tg?= =?us-ascii?Q?8c/VmPxXgn6drbGtLAwf1nXPU9PUZNMFPuvdSn/EzORlC72uFlK/chzAAlLP?= =?us-ascii?Q?oWdHYet6B3z05UvNxl+jvizl/2+zxZrZ7FxqJwc3DZZZbauAyGLYzfOPYeDo?= =?us-ascii?Q?bpXAdNfsuIIoS40hKPju+oPaAqjRTYZLyy/71KkIytwoAWgielj7D0Pngtmf?= =?us-ascii?Q?81zychpHcChPsdOLb0EAdVwlhqpYphDWsafzTd/5z0nsbpWdtNXxOa7Jppkh?= =?us-ascii?Q?B7tNxJ8le5zdybuqKYwhI+8g+aK6iAHP80P5UhQ8ZderIfRGr+tIIdvu2dSF?= =?us-ascii?Q?GokoJQtfKY1n4u4SIEOhl8xi?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95113c2f-49d5-4855-4afc-08d8d4b57318 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:06.0266 (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: Bi89IOPSEU6J4YVBPM0cbTqg1shi7gOmzUdqXfEjRy+GImi/QwDGAQZI0hbHTIqJc2yCdl5/DvHWXPRsQrTnnM5sds8u6HUBR4Qfei0B7/I= 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: mER1q60hGEjKIdNzcGE3VHCUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1613725521; bh=QAfto4F3lqUOd/mtRob3fnTmUj3klz8pVxUvcGghhGs=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qyQwgVZVQVAaYWjWbuKNGdo61VkSvsVBwhFZ48vwZaW2b17IiiXlrUmK87pOTBdRE6x gD8xslWO/rjfGZR/Du4Eree+mmLWGrviQI119CfUDim5Y1atdqrIwXwrkK6x1l6kkjtXt sLjKDyxwrkgPupqVlqr6i4m9gHk2JrFyI0E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Advertise OVMF support for CPU hot-unplug and negotiate it if QEMU requests the feature. 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 review comments: (1,3) s/hot unplug/hot-unplug/ (2) Get rid of the reference to the made up ICH9_APM_CNT_CPU_HOT_UNPLUG (4,6) Remove the artificial tie in between ICH9_LPC_SMI_F_CPU_HOTPLUG, ICH9_LPC_SMI_F_CPU_HOT_UNPLUG. (5) Fully spell out "SMI on CPU hot-unplug". (7) Emit separate messages on negotiation (or not) of ICH9_LPC_SMI_F_CPU_HOT_UNPLUG. OvmfPkg/SmmControl2Dxe/SmiFeatures.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c b/OvmfPkg/SmmControl2Dxe/= SmiFeatures.c index c9d875543205..b1d59a559dae 100644 --- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c +++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c @@ -29,6 +29,12 @@ // #define ICH9_LPC_SMI_F_CPU_HOTPLUG BIT1 =20 +// The following bit value stands for "enable CPU hot-unplug, and inject a= n SMI +// with control value ICH9_APM_CNT_CPU_HOTPLUG upon hot-unplug", in the +// "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg fi= les. +// +#define ICH9_LPC_SMI_F_CPU_HOT_UNPLUG BIT2 + // // Provides a scratch buffer (allocated in EfiReservedMemoryType type memo= ry) // for the S3 boot script fragment to write to and read from. @@ -112,7 +118,8 @@ NegotiateSmiFeatures ( QemuFwCfgReadBytes (sizeof mSmiFeatures, &mSmiFeatures); =20 // - // We want broadcast SMI, SMI on CPU hotplug, and nothing else. + // We want broadcast SMI, SMI on CPU hotplug, SMI on CPU hot-unplug + // and nothing else. // RequestedFeaturesMask =3D ICH9_LPC_SMI_F_BROADCAST; if (!MemEncryptSevIsEnabled ()) { @@ -120,8 +127,10 @@ NegotiateSmiFeatures ( // For now, we only support hotplug with SEV disabled. // RequestedFeaturesMask |=3D ICH9_LPC_SMI_F_CPU_HOTPLUG; + RequestedFeaturesMask |=3D ICH9_LPC_SMI_F_CPU_HOT_UNPLUG; } mSmiFeatures &=3D RequestedFeaturesMask; + QemuFwCfgSelectItem (mRequestedFeaturesItem); QemuFwCfgWriteBytes (sizeof mSmiFeatures, &mSmiFeatures); =20 @@ -166,6 +175,13 @@ NegotiateSmiFeatures ( __FUNCTION__)); } =20 + if ((mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOT_UNPLUG) =3D=3D 0) { + DEBUG ((DEBUG_INFO, "%a: CPU hot-unplug not negotiated\n", __FUNCTION_= _)); + } else { + DEBUG ((DEBUG_INFO, "%a: CPU hot-unplug with SMI negotiated\n", + __FUNCTION__)); + } + // // Negotiation successful (although we may not have gotten the optimal // feature set). --=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 (#71838): https://edk2.groups.io/g/devel/message/71838 Mute This Topic: https://groups.io/mt/80751403/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-