From nobody Thu Nov 14 17:01:19 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+70760+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+70760+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 1611643498544260.48561388097346; Mon, 25 Jan 2021 22:44:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8psiYY1788612xORgcusge6c; Mon, 25 Jan 2021 22:44:58 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web12.8811.1611643497571663911 for ; Mon, 25 Jan 2021 22:44:57 -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 10Q6ZvEf058587; Tue, 26 Jan 2021 06:44:53 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 3689aagu0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:44:53 +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 10Q6ZWIw002707; Tue, 26 Jan 2021 06:44:52 GMT X-Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by userp3020.oracle.com with ESMTP id 368wjqs12b-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jan 2021 06:44:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JzrzSMuCSt6B3iiGyDMuE462iXQvAGbUu6QiDvyFqbKhsUav/AUXi/hq2qszWsupYb8e4KxDYY75WiQ4FEWG8W1AA/y9X1jCbxqzl8St+yXUVdyBVue0xx9m6FL+5hbHmn74qfiNHmWTFPgi8RRe65ulb7/S9C7aR54a+pZjE7z7enZgiKb54sjQpnEHaGrV/AECmY7474D+nZ0rFy7VQFikGz6tvmReZGhhDyWZNjZbgzUhPtyz18cDTD7y9Q2Cr2lIxnRZuLTADbHvLsSpNgi7BjSCXI5r2jIfQSmM9o/mRypHHhVeD31y+mWVcbgvFl0DZ2ePXVEMizckWW8qYQ== 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=W+6TEr5s+CeCtyf1xQDHO0aOpEswCDJxoKuz5AorSlc=; b=MjvgcuUjTZLuqbsEHYYIOpnT2g+mJXt3M1SRRep5Z1L+apYp0810Z/v8zIg9BnR7YkHe9ZcJo+X12gSHcbjrxj7T9fJ3o5HY9sxY4bCx7Rf3VzTAhwqpDqni2tEC+Hjrxym8I+fcv+LT95uzk17P2HEjL/QZOVTyrcNeb9dF8fWxbTs7gb1hVyZxYVWixiXW5wdteN7JxC0VPbXgrpFxMSNobeWC0arTmAcUyNli5bDS6m5B9EjJvfPUabGty+PNbWozQjNLUFBlsBbGtpYJM9eHbO/Hn24+iy2bXRdRs/6ITpeHh8sNI+mpTrtWDz6NW4zCHTcv2P/Ewlo0x48uWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) by CY4PR10MB1781.namprd10.prod.outlook.com (2603:10b6:910:a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Tue, 26 Jan 2021 06:44:50 +0000 X-Received: from CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6]) by CY4PR10MB1718.namprd10.prod.outlook.com ([fe80::39dc:6ba7:9397:cb6%6]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 06:44:50 +0000 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Aaron Young Subject: [edk2-devel] [PATCH v5 1/9] OvmfPkg/CpuHotplugSmm: refactor hotplug logic Date: Mon, 25 Jan 2021 22:44:32 -0800 Message-Id: <20210126064440.299596-2-ankur.a.arora@oracle.com> In-Reply-To: <20210126064440.299596-1-ankur.a.arora@oracle.com> References: <20210126064440.299596-1-ankur.a.arora@oracle.com> X-Originating-IP: [70.36.60.91] X-ClientProxiedBy: MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) To CY4PR10MB1718.namprd10.prod.outlook.com (2603:10b6:910:9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from localhost.localdomain (70.36.60.91) by MWHPR18CA0061.namprd18.prod.outlook.com (2603:10b6:300:39::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Tue, 26 Jan 2021 06:44:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb4c4c04-6a93-4a18-9b86-08d8c1c5e100 X-MS-TrafficTypeDiagnostic: CY4PR10MB1781: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADChe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av6aK1jNys2hAWn9/rmhzqZ?= =?us-ascii?Q?Pk6aL3V1u9RcoixJpvrR+2DvEoEhh1rCwKt7m5NfUMPyXqo+vbaIe5Y1+xpj?= =?us-ascii?Q?r2t1RbKOaiYJqw+J6pK09wF6hEJ30Nw5kFvGCmS+n1cfMVFBIQeYwp9wsvoa?= =?us-ascii?Q?pfuVNqifVkVFGz74Mx/4PcLt40f6WGXqWz+f/eVY+z3HMH8i/1STMrBrTMNo?= =?us-ascii?Q?Agr6JcEa84F87bOSfQAUbn1QsVQOZypH+9kFaNPaXu/Yk9pNoj/ViJxV/bih?= =?us-ascii?Q?A4+74By61g0EOzz8CAcQrtb5GMHeUI5qhcyXpnyXRwgD91W0HtPnCjVI6KWY?= =?us-ascii?Q?rs/UKInyZMCkDNEqWmwm1yUlGRe4Fy+AeF0BwK/bV7cBkKzH+e5MCi3hvRjC?= =?us-ascii?Q?sJSHt1upH74jbx385bm6eIU2PPnrujF0x5qWscxgJouIZLVAZGZ4X5bJq4Pb?= =?us-ascii?Q?0B9aNvssGq2yo9B+jz0ju/K/5VxALlF/0q4I0QW5fyQgBnRINnCfHvsYzd3W?= =?us-ascii?Q?V3k0J+51HnCTPvuZ4FPxCW0XfRXFIFVKiNd0DkSfP3g/S3HN5JcB5EjA0sLD?= =?us-ascii?Q?SoTe4hWh8l1S/aIGGS+SkAB2WjWV2g3gwXgjSmT/f8KfrKZA7NbCKQQolhf9?= =?us-ascii?Q?qbFp09XKcNXjYdoO5kG06SjmEd/Ry81RYWyUW7iZBSZs+1fqhMnbi3VDb79K?= =?us-ascii?Q?8QEdob7Z?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb4c4c04-6a93-4a18-9b86-08d8c1c5e100 X-MS-Exchange-CrossTenant-AuthSource: CY4PR10MB1718.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 06:44:50.2445 (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: AXBBhGRZ4vU0cGTbuuHdvL/8JR/FDnChDb11UoshxrHNnn/eu79vhuL5PftsNfhkeeXNumlwZlFVckB/0OBYX9HqGk/bAZwTXMDrv2IgPdY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR10MB1781 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: Iq4ZL545RYNUJwUVFlj2MCSKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611643498; bh=vY8FbPWNKnoZEzQHgcIrb9+mryblvCwgwfmp5uhFTnc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Vqv8NMmZ8QnLV5Fc0qyScxqJlMFJUKC4zQV4dG6KpD2rUa2exxv6XwvPvtAqBTwg6SO BhaizxslmVKRb9xrcAaRIpwe4mppNT4AVaf3k2K1AiWhHBU8yFp/8OXrl/oXjTT4++jf2 MPKbzdVRF9DE2uwMbj8Mpv1U1R/WoMvrct4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Refactor CpuHotplugMmi() to pull out the CPU hotplug logic into PlugCpus(). 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 --- OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 208 ++++++++++++++++++++++-----------= ---- 1 file changed, 123 insertions(+), 85 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index cfe698ed2b5e..a5052a501e5a 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -62,6 +62,124 @@ STATIC UINT32 mPostSmmPenAddress; // STATIC EFI_HANDLE mDispatchHandle; =20 +/** + CPU Hotplug handler function. + + @param[in] PluggedApicIds List of APIC IDs to be plugged. + + @param[in] PluggedCount Count of APIC IDs to be plugged. + + @retval EFI_SUCCESS Some of the requested APIC IDs were hot-p= lugged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +PlugCpus( + IN APIC_ID *PluggedApicIds, + IN UINT32 PluggedCount + ) +{ + EFI_STATUS Status; + UINT32 PluggedIdx; + UINT32 NewSlot; + + // + // 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 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)); + 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++; + } + + // + // We've handled this hotplug. + // + return EFI_SUCCESS; + +RevokeNewSlot: + mCpuHotPlugData->ApicId[NewSlot] =3D MAX_UINT64; + +Fatal: + return EFI_INTERRUPT_PENDING; +} =20 /** CPU Hotplug MMI handler function. @@ -122,8 +240,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 +295,12 @@ 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); + if (PluggedCount > 0) { + Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } =20 - 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)); - 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++; + if (EFI_ERROR(Status)) { + goto Fatal; } =20 // @@ -267,9 +308,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 (#70760): https://edk2.groups.io/g/devel/message/70760 Mute This Topic: https://groups.io/mt/80125308/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-