From nobody Thu Nov 14 05:15:07 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+69970+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+69970+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049331; cv=none; d=zohomail.com; s=zohoarc; b=acwmcCSXmiB0eHiemSL0oJGm6cjkxyQ/LHXN+7NQ43Y9FsQj6/2TsMnCl3DbpWjOXkwN//TFQxOi7tCnciGWrjNoHIfADFiTET5ueJ+JBhO35p+gZ87CJSnLzwJ6n4jIa+O47wXURnhtOdRtkxWL1NLuNJNxsXwF4w9OV5DeW5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049331; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=0mCBmSNGuGkzoKvQW+LmZ1EeVSqcpk2+JNUiMDLpCRY=; b=czfY03wHzCNwTW4NlqIeXxgFo94VRWFIno2X5wlyG1NWPMuflOgRehhtEQkjo95lfMTMKM2VUWAUdk8dT3/mv44t6B2AFXK5k6l9e0xdOZfs2fFUKGfsqmrQ4g7ot1CDFa/so2V6y7YfkdM6DAxJc8gyqleiYOY07rbWbUVQuTI= ARC-Authentication-Results: i=1; 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+69970+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049331394663.9848444260966; Thu, 7 Jan 2021 11:55:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id zngGYY1788612xd6NTWk1RIt; Thu, 07 Jan 2021 11:55:31 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web12.2153.1610049330549072028 for ; Thu, 07 Jan 2021 11:55:30 -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 107JtQZO192293; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 35wftxdn2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:26 +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 107JaVDH023876; Thu, 7 Jan 2021 19:55:25 GMT X-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35v4ree7pt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:25 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtOcT003561; Thu, 7 Jan 2021 19:55:24 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:23 -0800 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 v2 01/10] OvmfPkg/CpuHotplugSmm: move CPU Hotplug into PlugCpus() Date: Thu, 7 Jan 2021 11:55:06 -0800 Message-Id: <20210107195515.106158-2-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: ZIPClywJEOPtbIkHsxZL6gpSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049331; bh=EbAkdsgOdw+ghAi13Xfz+lI8tcaOUp8Tjey3sx3tZ4s=; h=Cc:Date:From:Reply-To:Subject:To; b=SoUBH8gEip4chlkuBg1te44QmQe4dDLYVNGPBtT4atZt6+ZNj+gtYOe2iW1CU3d5oQ0 Fmx2snIy7XVECQD1g1eZjIZIGQb6v6GyWXH4rSt9XgAl3FyoYvGlKg8gRTvmq7G6ysGGy M822a6VUtdHtMLmer981xQitI4S9sriN56E= 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..0f8f210d0ecf 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] mPluggedApicIds 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-plu= gged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +PlugCpus( + IN APIC_ID *mPluggedApicIds, + 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 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++; + } + + // + // 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 (#69970): https://edk2.groups.io/g/devel/message/69970 Mute This Topic: https://groups.io/mt/79507537/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:15:07 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+69979+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+69979+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049456; cv=none; d=zohomail.com; s=zohoarc; b=ew15KGZ8DhuD2CJI1v9xNbQGAMmcAMU1fB6/aX2QO+KqjVaX/+utBn+o7mOZ1c4+yb+qCYxYvDwIGsFu3tmdPtAWxvREbtYqgzn4B7lpDaMosR1ZPBJqBWKtgoRNNqkYB7xs9mvFpzDt8F9CZP9V3Ppd3Mx8f4nWLgaYjR96U6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049456; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hpUvJ3j7GNJyaWKRijLHN7tpKLN7QGVv7WoZSf4ojlU=; b=PHNfWtYh2dHjSYq0vuezr+fBvH8NM7x+Ee062v8r8dXW/JfU+sacuJXnamz0C/ZeeRm8T0YA5FPDq94qsYScqfxq0dpqcs//TALH9WlRKaLCg8Td1bKA3BEGsFzAVqD7jPY6geavUrC1CKbBHSjQ56sprFtDJpRnpp4/nH0KYys= ARC-Authentication-Results: i=1; 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+69979+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049456296244.66707380624814; Thu, 7 Jan 2021 11:57:36 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id TMU2YY1788612xBt61IEEvX7; Thu, 07 Jan 2021 11:57:35 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web08.2230.1610049450451219305 for ; Thu, 07 Jan 2021 11:57:30 -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 107JtQ5n013632; Thu, 7 Jan 2021 19:57:27 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 35wepme2tp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:57:27 +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 107JacP9136060; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 35w3qu6cqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:26 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107JtPpI021867; Thu, 7 Jan 2021 19:55:25 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:24 -0800 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 v2 02/10] OvmfPkg/CpuHotplugSmm: handle Hot-unplug events Date: Thu, 7 Jan 2021 11:55:07 -0800 Message-Id: <20210107195515.106158-3-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: o2mNMZtEOTkKh0Qx40S7fnu3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049455; bh=xEubsMPTZyEZ6xRzvtBEPgHjYQMeT7JfFWOof0aPNyw=; h=Cc:Date:From:Reply-To:Subject:To; b=YQGgqZ2Xxn9ympCdiVnHA7boRgaoCaHg9ArptQxfPql+2M+DslAE/lyyW6+UqJ0Od9p XlXmSrVyUG5I9ehhZjPRdqzg/fFffd+MPGpIfhhGsqL6w1F0zWeIjRKJVNhOtjsp7hmhc fH/B9O/t1+1lAFOciZoJ/640leai4oCeqJ8= 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. Additionally we now ignore CPUs which have only 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@redhat= .com/ Also define QEMU_CPUHP_STAT_EJECTED while we are at it. 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/QemuCpuhp.c | 35 +++++++++++++++++--= ---- OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 2 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 8d4a6693c8d6..2dd783ebf42e 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -205,7 +205,7 @@ QemuCpuhpCollectApicIds ( UINT8 CpuStatus; APIC_ID *ExtendIds; UINT32 *ExtendCount; - APIC_ID NewApicId; + APIC_ID OpApicId; =20 // // Write CurrentSelector (which is valid) to the CPU selector register. @@ -245,10 +245,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)); @@ -260,12 +260,31 @@ QemuCpuhpCollectApicIds ( =20 ExtendIds =3D PluggedApicIds; ExtendCount =3D PluggedCount; - } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { - DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: remove\n", __FUNCT= ION__, + } 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", __FU= NCTION__, CurrentSelector)); =20 ExtendIds =3D ToUnplugApicIds; ExtendCount =3D ToUnplugCount; + } else if ((CpuStatus & QEMU_CPUHP_STAT_REMOVE) !=3D 0) { + // + // Let the OSPM deal with the "remove" event. + // + DEBUG ((DEBUG_INFO, "%a: CurrentSelector=3D%u: remove (ignored)\n", = __FUNCTION__, + CurrentSelector)); + + CurrentSelector++; + continue; } else { DEBUG ((DEBUG_VERBOSE, "%a: CurrentSelector=3D%u: no event\n", __FUNCTION__, CurrentSelector)); @@ -281,10 +300,10 @@ QemuCpuhpCollectApicIds ( return EFI_BUFFER_TOO_SMALL; } QemuCpuhpWriteCommand (MmCpuIo, QEMU_CPUHP_CMD_GET_ARCH_ID); - NewApicId =3D QemuCpuhpReadCommandData (MmCpuIo); + OpApicId =3D QemuCpuhpReadCommandData (MmCpuIo); DEBUG ((DEBUG_VERBOSE, "%a: ApicId=3D" FMT_APIC_ID "\n", __FUNCTION__, - NewApicId)); - ExtendIds[(*ExtendCount)++] =3D NewApicId; + OpApicId, ExtendCount)); + ExtendIds[(*ExtendCount)++] =3D OpApicId; =20 // // We've processed the CPU with (known) pending events, but we must ne= ver diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/In= clude/IndustryStandard/QemuCpuHotplug.h index a34a6d3fae61..692e3072598c 100644 --- a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h +++ b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h @@ -34,6 +34,8 @@ #define QEMU_CPUHP_STAT_ENABLED BIT0 #define QEMU_CPUHP_STAT_INSERT BIT1 #define QEMU_CPUHP_STAT_REMOVE BIT2 +#define QEMU_CPUHP_STAT_EJECTED BIT3 +#define QEMU_CPUHP_STAT_FW_REMOVE BIT4 =20 #define QEMU_CPUHP_RW_CMD_DATA 0x8 =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 (#69979): https://edk2.groups.io/g/devel/message/69979 Mute This Topic: https://groups.io/mt/79507575/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:15:07 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+69972+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+69972+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049341; cv=none; d=zohomail.com; s=zohoarc; b=nr39rJ+Mc8x8UmChmwGUyFxBks+LGWUhwhwNzdcSAyJTSgh3FUHyHlf2ImxU2tx+P02cAqksYbZPoYKWi7uyKY4JC1Zcp+D53bWrQ27+cBjsKiViLO7N4Djp2tnM/qARS1bhE3pcHPj9kIJTnS5eJksMnn4ixdG3rFy5/0MIde8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=8/Mp3EaZZqfywebjo8sGkg4/vIsqfAJw+fNCdXvuEns=; b=SJIZ1f9f9cKk0Sa5VDtAH/skpPqTx1teFDmYEIQnTe4wtJQLvHw+I02BW7ossA5szysdAKs3QbYGYP5ycfUIwAA/cl8MCw/5DWFIVtHOy26T5y+whc0FVcg1aNRBDzR2MJS5GkRP36d2N5ldpGgVXO0cl+m8hUqbRve2USJpNeQ= ARC-Authentication-Results: i=1; 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+69972+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 161004934189763.393867748610205; Thu, 7 Jan 2021 11:55:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Hg0IYY1788612xRXBfjKdFLm; Thu, 07 Jan 2021 11:55:41 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.2189.1610049330943402912 for ; Thu, 07 Jan 2021 11:55:31 -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 107JtRVS150438; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 35wcuxxedu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:27 +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 107Jadrv136087; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 35w3qu6crh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:26 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtPWs021811; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:25 -0800 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 v2 03/10] OvmfPkg/CpuHotplugSmm: add Qemu CpuStatus helper Date: Thu, 7 Jan 2021 11:55:08 -0800 Message-Id: <20210107195515.106158-4-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: ND5XBpt2JyuFQ9Bd6xzQB7Hvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049341; bh=3qzfqAxuIU+QAa/ucejdqYZZpQprgIjz3sJfaNjmwc0=; h=Cc:Date:From:Reply-To:Subject:To; b=gC3K6TEA0BT/3vItQ7+Cl4tpwfKf9bJx7mJh4O9Ha4xdDk8nrnKFZMF/Jpd2EZH/MXj jBKg/hc8uqShoGwBEXcwR92IjUs4lDWJVxndcAD1CLupbBKAPkPpDWpRkgcdzCa7tMKYC cvdhCe5XCK+qpvBC3QMcPmif31B+epdkSdQ= 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 similar fashion to the 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 --- OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 23 +++++++++++++++++++++++ OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.c index 2dd783ebf42e..14145696aa50 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.c @@ -67,6 +67,29 @@ QemuCpuhpReadCpuStatus ( return CpuStatus; } =20 +UINT8 +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 (); + } + return Status; +} + UINT32 QemuCpuhpReadCommandData ( IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo diff --git a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h b/OvmfPkg/CpuHotplugSmm/Qemu= Cpuhp.h index 8adaa0ad91f0..9f084d199fd4 100644 --- a/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h +++ b/OvmfPkg/CpuHotplugSmm/QemuCpuhp.h @@ -30,6 +30,12 @@ QemuCpuhpReadCpuStatus ( IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo ); =20 +UINT8 +QemuCpuhpWriteCpuStatus ( + IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo, + IN UINT8 CpuStatus + ); + UINT32 QemuCpuhpReadCommandData ( IN CONST EFI_MM_CPU_IO_PROTOCOL *MmCpuIo --=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 (#69972): https://edk2.groups.io/g/devel/message/69972 Mute This Topic: https://groups.io/mt/79507539/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:15:07 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+69971+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+69971+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049331; cv=none; d=zohomail.com; s=zohoarc; b=SzQKnSzQFFpr1Ip36sElD1JGsiNGOAZXM+9rodxDKjRJUNiATGU7+6LjzfRmE6Isarjp8ZiG5sQfBKZxwxu/tGOQjbJpl7+A8OkZIkMbX0K2GT5rZUqoLbXirxs4SRkCcdEhg3tiJS4Uln9knRDLbkgv5vp/aP2D6uUX7ONaIF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049331; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zUJL3Nucx15J8Z3O7cxLXrkOHq/JOMUDJrDClOP8Nnc=; b=ItoS48x8l8BGzi4/gRpslWY36AHMXK/Eb2pFtVLSSVTs6AV1axYrcY2pRFOCOjfW/Qekn5OneAsm9LsXnFAis6k5GaXBIrIN6n2zZzPW3zWQmoIh637TqsewmZF+OIEAqaLr6EI39dPmXqJvIYz3Uiz0j3pyr9h5b3V+vTqtWms= ARC-Authentication-Results: i=1; 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+69971+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049331965362.0989675273712; Thu, 7 Jan 2021 11:55:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id u5cKYY1788612xTu9oVSyUGa; Thu, 07 Jan 2021 11:55:31 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web12.2154.1610049330884282644 for ; Thu, 07 Jan 2021 11:55:31 -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 107JtREL150435; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 35wcuxxedv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:27 +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 107JaWef024026; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35v4ree7qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:27 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtQRw003565; Thu, 7 Jan 2021 19:55:26 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:26 -0800 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 v2 04/10] OvmfPkg/CpuHotplugSmm: handle CPU hot-unplug Date: Thu, 7 Jan 2021 11:55:09 -0800 Message-Id: <20210107195515.106158-5-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: Wa9dpwYOEZTYeBv6YrWYqNpOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049331; bh=fDTQI1H7jasQOttRPR/rqgTk6gEvQPMZhlvOq6tImRc=; h=Cc:Date:From:Reply-To:Subject:To; b=VKPMOJSLZ/uMYVspbkCQHqPR9hD3DAVCayGTBFyUPUVtIxH3AerRrZz0bD4mzX4KocK nSImUsr8XT4+oQMtWm9Jop/rkdM77tecqKvmoEWOtHWPCrVYUxGCkjjQihg2sPMAGRgUs QGcVYJ5Y4Rmxj/pPNh0Iw5Et5I6TZJeBJYI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Introduce a new function UnplugCpus() which, for each unplugged CPU: * finds the slot for APIC ID in CPU_HOT_PLUG_DATA * informs PiSmmCpuDxeSmm by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor() * caches the APIC ID, such that it can be ejected at SMI exit 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 | 135 +++++++++++++++++++++++++++++++++= +++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 0f8f210d0ecf..20d92a35da39 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -53,6 +53,14 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData; STATIC APIC_ID *mPluggedApicIds; STATIC APIC_ID *mToUnplugApicIds; // +// Similar to the SMRAM arrays above mHotunplugWork stores APIC IDs of +// processors with pending unplugs for the duration of the MMI. +// +// This array maps ProcessorNum -> APIC ID and so has room for possible +// CPU count. +// +STATIC APIC_ID *mHotUnplugWork; +// // Address of the non-SMRAM reserved memory page that contains the Post-SM= M Pen // for hot-added CPUs. // @@ -182,6 +190,100 @@ Fatal: } =20 /** + CPU Hot-unplug handler function. + + @param[in] mUnplugApicIds List of APIC IDs to be unplugged. + + @param[in] ToUnplugCount Count of APIC IDs to be unplugged. + + @param[out] mHotUnplugWork List mapping ProcessorNum -> APIC ID for = later unplug. + Invalid entries are specified as MAX_UINT= 32. + + @retval EFI_SUCCESS Some of the requested APIC IDs will be hot-= unplugged. + + @retval EFI_INTERRUPT_PENDING Fatal error while hot-plugging. + +**/ +STATIC +EFI_STATUS +EFIAPI +UnplugCpus( + IN APIC_ID *mUnplugApicIds, + IN UINT32 ToUnplugCount, + OUT APIC_ID *mHotUnplugWork + ) +{ + EFI_STATUS Status =3D EFI_SUCCESS; + UINT32 ToUnplugIdx; + + // + // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL. + // + + ToUnplugIdx =3D 0; + while (ToUnplugIdx < ToUnplugCount) { + APIC_ID RemoveApicId; + UINT32 ProcessorNum; + + RemoveApicId =3D mUnplugApicIds[ToUnplugIdx]; + + for (ProcessorNum =3D 0; + ProcessorNum < mCpuHotPlugData->ArrayLength; + ProcessorNum++) { + if (mCpuHotPlugData->ApicId[ProcessorNum] =3D=3D RemoveApicId) { + break; + } + } + + // + // Ignore the unplug if APIC ID is 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; + } + + Status =3D mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum= ); + + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n", + __FUNCTION__, RemoveApicId, Status)); + goto Fatal; + } else { + // + // Stash the APIC IDs so we can do the actual unplug later. + // + + if (mHotUnplugWork[ProcessorNum] !=3D MAX_UINT32) { + // + // Since ProcessorNum and APIC-ID are a 1-1 mapping, so an already + // filled mHotUnplugWork[ProcessorNum] is a fatal error. + // + DEBUG ((DEBUG_ERROR, "%a: ProcessorNum %u maps to " FMT_APIC_ID ",= cannot map to " FMT_APIC_ID "\n", + __FUNCTION__, ProcessorNum, mHotUnplugWork[ProcessorNum], Remove= ApicId)); + goto Fatal; + } + + DEBUG ((DEBUG_INFO, "%a: Caching ProcessorNum %u -> " FMT_APIC_ID " = for unplugging\n", + __FUNCTION__, ProcessorNum, RemoveApicId)); + mHotUnplugWork[ProcessorNum] =3D RemoveApicId; + } + + ToUnplugIdx++; + } + + // + // We've handled this unplug. + // + return EFI_SUCCESS; + +Fatal: + return EFI_INTERRUPT_PENDING; +} + +/** CPU Hotplug MMI handler function. =20 This is a root MMI handler. @@ -297,6 +399,8 @@ CpuHotplugMmi ( =20 if (PluggedCount > 0) { Status =3D PlugCpus(mPluggedApicIds, PluggedCount); + } else if (ToUnplugCount > 0) { + Status =3D UnplugCpus(mToUnplugApicIds, ToUnplugCount, mHotUnplugWork); } =20 if (EFI_ERROR(Status)) { @@ -330,6 +434,7 @@ CpuHotplugEntry ( { EFI_STATUS Status; UINTN Size; + UINTN Idx; =20 // // This module should only be included when SMM support is required. @@ -403,12 +508,36 @@ CpuHotplugEntry ( } =20 // + // Allocate for the full CPU count. We index to-be-unplugged APIC IDs + // with ProcessorNum. + // + if (RETURN_ERROR (SafeUintnMult (sizeof (APIC_ID), mCpuHotPlugData->Arra= yLength, &Size))) { + Status =3D EFI_ABORTED; + DEBUG ((DEBUG_ERROR, "%a: invalid CPU_HOT_PLUG_DATA\n", __FUNCTION__)); + goto ReleaseToUnplugApicIds; + } + Status =3D gMmst->MmAllocatePool (EfiRuntimeServicesData, Size, + (VOID **)&mHotUnplugWork); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: MmAllocatePool(): %r\n", __FUNCTION__, Statu= s)); + goto ReleaseToUnplugApicIds; + } + + // + // We will use mHotUnplugWork to map from ProcessorNum -> APIC_ID. + // Initialize to known invalid values. + // + for (Idx =3D 0; Idx < mCpuHotPlugData->ArrayLength; Idx++) { + mHotUnplugWork[Idx] =3D MAX_UINT32; + } + + // // Allocate the Post-SMM Pen for hot-added CPUs. // Status =3D SmbaseAllocatePostSmmPen (&mPostSmmPenAddress, SystemTable->BootServices); if (EFI_ERROR (Status)) { - goto ReleaseToUnplugApicIds; + goto ReleaseToHotUnplugWork; } =20 // @@ -468,6 +597,10 @@ ReleasePostSmmPen: SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices); mPostSmmPenAddress =3D 0; =20 +ReleaseToHotUnplugWork: + gMmst->MmFreePool (mHotUnplugWork); + mHotUnplugWork =3D NULL; + ReleaseToUnplugApicIds: gMmst->MmFreePool (mToUnplugApicIds); mToUnplugApicIds =3D NULL; --=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 (#69971): https://edk2.groups.io/g/devel/message/69971 Mute This Topic: https://groups.io/mt/79507538/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:15:07 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+69977+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+69977+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049357; cv=none; d=zohomail.com; s=zohoarc; b=IDsMMcTWpGwOWyq4EJEcgrSpX3Lkg6WlQoeG28mUiekUl6uMVZwaMxUNpc3Tjeac5prZS2+ZalfhskxyScz1XzdQMXUVha2y9VbUoIECNpZ2cA0up90W/ZoR6X4SpJ5ekxPF3NMP5p2IczIXxV2RtZpIl+222RMU9SS3QjmadrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049357; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=EIYMUwHmCqPaGVa7rcUSuHkV7KpGLDENwKmhjtXmfcM=; b=j7CGDNCHWOjLIv7BWqjK2yelhtDJfG9h2FdvFuEfpprWpkdQcID6dri75f0O+ZE9KlC7tP6sZpbtW0gYCcGnRBGSIREc96CXlgS5K02lW1VnJR73QegXk4ZBrTM19boEgRs/eFntmeBA8UOIEQRPFC8dm8u0nXocGJ0obbwwqGk= ARC-Authentication-Results: i=1; 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+69977+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049357736872.2334748364758; Thu, 7 Jan 2021 11:55:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id U7h9YY1788612xgOT4D0P56x; Thu, 07 Jan 2021 11:55:56 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.2198.1610049354782679023 for ; Thu, 07 Jan 2021 11:55:54 -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 107JtQQ9150405; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 35wcuxxee6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:30 +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 107Jss9b026109; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 35v1fbn1rf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:29 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtRIP021828; Thu, 7 Jan 2021 19:55:27 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:27 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Jian J Wang , Michael D Kinney , Liming Gao , Zhiguang Liu , Eric Dong , Ray Ni , Rahul Kumar , Aaron Young Subject: [edk2-devel] [PATCH v2 05/10] MdePkg: add MmRegisterShutdownInterface() Date: Thu, 7 Jan 2021 11:55:10 -0800 Message-Id: <20210107195515.106158-6-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: kXwdPSUbx6tZulr8K9zNtsycx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049356; bh=pQoTgKnXFCsOSWpa4uOiZcS2x+xVMs68sDeObLtiEMY=; h=Cc:Date:From:Reply-To:Subject:To; b=Eqw2CerPZ8UuijfqzfzD/DaPqAvS2mxMiGUbckBWZKFmWmYOsyAyjG0x3q9bh6VW+88 8IeQsgkkxIdVELSzTdeKCyr5/JA8szkWFjLPr0xw58z/bjj8ueRt2xWy6Cjj4PCmX9Skp /PvU4bZQy3c/9yKL/U9GAEozGj5d+gmNkOE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add MmRegisterShutdownInterface(), which is used to register a callback, that gets used to do the final ejection as part of CPU hot-unplug. Cc: Jian J Wang Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Igor Mammedov Cc: Boris Ostrovsky Cc: Aaron Young Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3132 Signed-off-by: Ankur Arora --- Not sure this is the right way to register a callback to be called from SmmCpuFeaturesRendezvousExit(). Happy to hear suggestions for a better way to accomplish this. --- MdeModulePkg/Core/PiSmmCore/PiSmmCore.c | 1 + MdePkg/Include/Pi/PiMmCis.h | 16 ++++++++++++++= ++ MdePkg/Include/Pi/PiSmmCis.h | 2 ++ MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c | 11 +++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 1 + UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 1 + 6 files changed, 32 insertions(+) diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c b/MdeModulePkg/Core/Pi= SmmCore/PiSmmCore.c index cfa9922cbdb5..9d883bb06633 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmCore.c @@ -39,6 +39,7 @@ EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst =3D { SmmFreePool, SmmAllocatePages, SmmFreePages, + NULL, // SmmShutdownAp NULL, // SmmStartupThisAp 0, // CurrentlyExecutingCpu 0, // NumberOfCpus diff --git a/MdePkg/Include/Pi/PiMmCis.h b/MdePkg/Include/Pi/PiMmCis.h index fdf0591a03d6..237bd8dcba76 100644 --- a/MdePkg/Include/Pi/PiMmCis.h +++ b/MdePkg/Include/Pi/PiMmCis.h @@ -77,6 +77,14 @@ EFI_STATUS IN OUT VOID *ProcArguments OPTIONAL ); =20 +typedef +EFI_STATUS +(EFIAPI *EFI_MM_SHUTDOWN_AP)( + IN UINTN CpuNumber, + IN BOOLEAN IsBSP + ); + + /** Function prototype for protocol install notification. =20 @@ -242,6 +250,13 @@ VOID IN CONST EFI_MM_ENTRY_CONTEXT *MmEntryContext ); =20 +EFI_STATUS +EFIAPI +MmRegisterShutdownInterface ( + IN EFI_MM_SHUTDOWN_AP Procedure + ); + + /// /// Management Mode System Table (MMST) /// @@ -282,6 +297,7 @@ struct _EFI_MM_SYSTEM_TABLE { /// /// MP service /// + EFI_MM_SHUTDOWN_AP MmShutdownAp; EFI_MM_STARTUP_THIS_AP MmStartupThisAp; =20 /// diff --git a/MdePkg/Include/Pi/PiSmmCis.h b/MdePkg/Include/Pi/PiSmmCis.h index 06ef4aecd7b5..296dc01f6703 100644 --- a/MdePkg/Include/Pi/PiSmmCis.h +++ b/MdePkg/Include/Pi/PiSmmCis.h @@ -49,6 +49,7 @@ EFI_STATUS IN UINTN TableSize ); =20 +typedef EFI_MM_SHUTDOWN_AP EFI_SMM_SHUTDOWN_AP; typedef EFI_MM_STARTUP_THIS_AP EFI_SMM_STARTUP_THIS_AP; typedef EFI_MM_NOTIFY_FN EFI_SMM_NOTIFY_FN; typedef EFI_MM_REGISTER_PROTOCOL_NOTIFY EFI_SMM_REGISTER_PROTOCOL_N= OTIFY; @@ -137,6 +138,7 @@ struct _EFI_SMM_SYSTEM_TABLE2 { /// /// MP service /// + EFI_SMM_SHUTDOWN_AP SmmShutdownAp; EFI_SMM_STARTUP_THIS_AP SmmStartupThisAp; =20 /// diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c b/MdePk= g/Library/MmServicesTableLib/MmServicesTableLib.c index 27f9d526e396..c7d81a0dc193 100644 --- a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c +++ b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c @@ -55,3 +55,14 @@ MmServicesTableLibConstructor ( =20 return EFI_SUCCESS; } + +EFI_STATUS +EFIAPI +MmRegisterShutdownInterface ( + IN EFI_MM_SHUTDOWN_AP Procedure + ) +{ + gMmst->MmShutdownAp =3D Procedure; + + return EFI_SUCCESS; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index db68e1316ec5..f2f67e85e5e9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -22,6 +22,7 @@ SMM_CPU_PRIVATE_DATA mSmmCpuPrivateData =3D { NULL, // Pointer to CpuSaveState= Size array NULL, // Pointer to CpuSaveState= array { {0} }, // SmmReservedSmramRegion + NULL, // SmmShutdownAp { SmmStartupThisAp, // SmmCoreEntryContext.Smm= StartupThisAp 0, // SmmCoreEntryContext.Cur= rentlyExecutingCpu diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index b8aa9e1769d3..7672834a2f70 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -247,6 +247,7 @@ typedef struct { VOID **CpuSaveState; =20 EFI_SMM_RESERVED_SMRAM_REGION SmmReservedSmramRegion[1]; + EFI_SMM_SHUTDOWN_AP SmmShutdownAp; EFI_SMM_ENTRY_CONTEXT SmmCoreEntryContext; EFI_SMM_ENTRY_POINT SmmCoreEntry; =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 (#69977): https://edk2.groups.io/g/devel/message/69977 Mute This Topic: https://groups.io/mt/79507550/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:15:07 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+69973+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+69973+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049332; cv=none; d=zohomail.com; s=zohoarc; b=LRYFQUYIHw/DXUHx3gSdSqO4v3EFsZCb4eeF52nEw0DMUjXGCyaAyHpyZkAtOHaf5SeE6KkxZ5sDMtiJxB6fJbTorA+CrHeWYOZBcCwtesTc+a2CKXVRz74IjXXz6rhNSLZIishEOB63FjcxiLqRAYJwxAPdnkBrOHXV33d1uaM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049332; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wiSL1dxU4XpDBh7p2B8uxETCSyf6XiaRuLFQ1bCOvNM=; b=NCTlH1DhNcP11KW5IzLm6x3XXH5+e8X7vq7iXGaIOcE+2fUx+ournHGjRgtTK8AVXKNsoeLCh4hdHhEWqzSlDAbwxm4y6hbOC13fTK99Z8ewlBxClY7WZQn8SdvRZ4+mKuNXwnU5GePVPZxip/eeibprxguh6045Fti0raPJYSA= ARC-Authentication-Results: i=1; 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+69973+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 161004933213165.26538670143475; Thu, 7 Jan 2021 11:55:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XRqcYY1788612xHzNhvwF0XJ; Thu, 07 Jan 2021 11:55:31 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.2142.1610049331141846464 for ; Thu, 07 Jan 2021 11:55:31 -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 107JtUhX013659; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 35wepme2js-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:30 +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 107JaWWq023991; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 35v4ree7ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:30 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtSrd021829; Thu, 7 Jan 2021 19:55:28 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:28 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Eric Dong , Ray Ni , Rahul Kumar , Aaron Young Subject: [edk2-devel] [PATCH v2 06/10] UefiCpuPkg/PiSmmCpuDxeSmm: initialize IsBsp Date: Thu, 7 Jan 2021 11:55:11 -0800 Message-Id: <20210107195515.106158-7-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: 0rBqhdlMo397JcZml66jwA2Gx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049331; bh=IJwN+XiiTbNO1p3UMDUcvZHlkDI4kZyvYGUaQiNU5z0=; h=Cc:Date:From:Reply-To:Subject:To; b=qKOAJT6ZGf261JcHdkiBzPx2IRNwp+fxTExtbeQWUh8kGVIFGmXwOI0jgGq6aIuXpaH 2ZHRtu+Y2PkFQ7QYxjyoipDFkp9Eww3dOsYiZEOAVsIAZ9hvemDuGWclYDbMCh4kUEOI7 736ulSa6x7ytq/qwg+WfId2uQCz9BkQMLI4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Initialize IsBsp early to ensure that this variable reflects the BSP status correctly. Also replace this check: if (mSmmMpSyncData->BspIndex =3D=3D (UINT32)CpuIndex) with: if (IsBsp) Note that there's a window of time when these two diverge, when the BSP, at exit from BSPHandler(), resets mSmmMpSyncData->BspIndex. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Igor Mammedov Cc: Boris Ostrovsky Cc: Aaron Young Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3132 Signed-off-by: Ankur Arora --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 4bcd217917d7..e7ea44eb86fc 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1565,7 +1565,12 @@ SmiRendezvous ( { EFI_STATUS Status; BOOLEAN ValidSmi; - BOOLEAN IsBsp; + + // + // IsBsp starts out as false. Once a CPU gets elected as BSP, + // it will transition its value to true. + // + BOOLEAN IsBsp =3D FALSE; BOOLEAN BspInProgress; UINTN Index; UINTN Cr2; @@ -1656,7 +1661,6 @@ SmiRendezvous ( // // Elect BSP // - IsBsp =3D FALSE; if (FeaturePcdGet (PcdCpuSmmEnableBspElection)) { if (!mSmmMpSyncData->SwitchBsp || mSmmMpSyncData->CandidateBsp[Cpu= Index]) { // @@ -1679,6 +1683,8 @@ SmiRendezvous ( (UINT32)-1, (UINT32)CpuIndex ); + + IsBsp =3D mSmmMpSyncData->BspIndex =3D=3D (UINT32)CpuIndex; } } } @@ -1686,7 +1692,7 @@ SmiRendezvous ( // // "mSmmMpSyncData->BspIndex =3D=3D CpuIndex" means this is the BSP // - if (mSmmMpSyncData->BspIndex =3D=3D CpuIndex) { + if (IsBsp) { =20 // // Clear last request for SwitchBsp. --=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 (#69973): https://edk2.groups.io/g/devel/message/69973 Mute This Topic: https://groups.io/mt/79507540/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:15:07 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+69974+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+69974+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049339; cv=none; d=zohomail.com; s=zohoarc; b=VjAA1WwIdj+DuJyTT1Fri3BtvKxRfIUJE1ooxd6hDXqYiuMjeIg3RlWjimqhl3mwwAlZaMhyViT7IgJC+q/lXoEZDwttIqGGF6sM8x93FGhybiJT96hAQ8wcrnHi8A4Ft7hEK/WT34FMdi2enPrWv6SasYEFVzANxMu1r3mf4Nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049339; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oRO8N/ZNxd0BnGQ/m2bXVBKT3GilUB1i+UxEA7jAg1g=; b=iE8fNwnpIgXf1indbW0oP3SR0radWo57kNa0qHoxLbxl1evRVX9Ha35ozGttSwuuFpXX9ajHEUk/l6kDT1ZaNF8qHIdMDMBBnUed4JreBQAnrdv2eka4PORMBaTsOrx1LqnyRMIwJT3ec3E8InftAoqeHu9c3PpDodw7xEQgSg4= ARC-Authentication-Results: i=1; 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+69974+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049339123995.2748726256764; Thu, 7 Jan 2021 11:55:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id k3W4YY1788612xdDxU9sNMSz; Thu, 07 Jan 2021 11:55:38 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web09.2190.1610049333296358043 for ; Thu, 07 Jan 2021 11:55:33 -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 107JtQXq150426; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 35wcuxxee7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:30 +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 107JaW1h024058; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 35v4ree7s3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:30 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107JtTeN021921; Thu, 7 Jan 2021 19:55:29 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:29 -0800 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 , Eric Dong , Ray Ni , Rahul Kumar , Aaron Young Subject: [edk2-devel] [PATCH v2 07/10] UefiCpuPkg/SmmCpuFeaturesLib: add IsBsp as a param to SmmCpuFeaturesRendezvousExit() Date: Thu, 7 Jan 2021 11:55:12 -0800 Message-Id: <20210107195515.106158-8-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: RHMYXTP2L4uLoLJ1C4EpkNPbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049338; bh=OYZOAPsxEzoC+H7eX02lJvH2kI+0potr2FNMYqWvIDg=; h=Cc:Date:From:Reply-To:Subject:To; b=D+WCdZsYgSL6MrPvUqzjhcGUcOtT0Ar2oJGyaD5TOc2aGeKEz9hA/jdRPf3r1U/RTYQ av+mKtZlDtIkmCnFH1XyoPaZROIEZWKBGM/lCSDOKeGoNl+0msxU5vbU8IFFV5nRfqlvV MTaTS9gS5a1zkx5NlXwkmKQbW5pNZgmTcmE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add IsBsp as a parameter to SmmCpuFeaturesRendezvousExit(). This'll be used to disambiguate the BSP so it can eject hot-unplugged CPUs. Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar 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/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 6 +++++- UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h | 4 +++- UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 4 +++- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 7ef7ed98342e..4d78bbfe7634 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -368,13 +368,17 @@ SmmCpuFeaturesRendezvousEntry ( @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must be between 0 and the NumberOfCpus field in the System Management System Table (SMST). + @param[in] IsBSP Is this CPU the SMM BSP? **/ VOID EFIAPI SmmCpuFeaturesRendezvousExit ( - IN UINTN CpuIndex + IN UINTN CpuIndex, + IN BOOLEAN IsBSP ) { + if(gSmst->SmmShutdownAp) + gSmst->SmmShutdownAp(CpuIndex, IsBSP); } =20 /** diff --git a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h b/UefiCpuPkg/In= clude/Library/SmmCpuFeaturesLib.h index dbcd57e0ad42..5e8c4000f010 100644 --- a/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h +++ b/UefiCpuPkg/Include/Library/SmmCpuFeaturesLib.h @@ -259,11 +259,13 @@ SmmCpuFeaturesRendezvousEntry ( @param[in] CpuIndex The index of the CPU that is exiting SMM. The valu= e must be between 0 and the NumberOfCpus field in the Syst= em Management System Table (SMST). + @param[in] IsBSP Is this CPU the SMM BSP? **/ VOID EFIAPI SmmCpuFeaturesRendezvousExit ( - IN UINTN CpuIndex + IN UINTN CpuIndex, + IN BOOLEAN IsBSP ); =20 /** diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/Uef= iCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 8fed18cf0e17..325518d3de3e 100644 --- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -443,11 +443,13 @@ SmmCpuFeaturesRendezvousEntry ( @param[in] CpuIndex The index of the CPU that is exiting SMM. The valu= e must be between 0 and the NumberOfCpus field in the Syst= em Management System Table (SMST). + @param[in] IsBSP Is this CPU the SMM BSP? **/ VOID EFIAPI SmmCpuFeaturesRendezvousExit ( - IN UINTN CpuIndex + IN UINTN CpuIndex, + IN BOOLEAN IsBSP ) { } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index e7ea44eb86fc..fb6aab17de37 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1728,7 +1728,7 @@ SmiRendezvous ( } =20 Exit: - SmmCpuFeaturesRendezvousExit (CpuIndex); + SmmCpuFeaturesRendezvousExit (CpuIndex, IsBsp); =20 // // Restore Cr2 --=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 (#69974): https://edk2.groups.io/g/devel/message/69974 Mute This Topic: https://groups.io/mt/79507543/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:15:07 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+69975+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+69975+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049341; cv=none; d=zohomail.com; s=zohoarc; b=JEv+c7OStFbu8yUJS9YMUSPwFzMEi7lA3IgMD4rXJLWNgvyN5NkV577wi3t4kCiqNsXskcD9H9ZszQzUn8Oz67REOIV5uGnIaM4z6/0swsAVT7rhakqhHrTAl04+C4Jv80vwlK1h7vfrFalFCd2eqQMhXdc8acRgx/kBHgUJfxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xf9ag9FnPy6J074YyDEJJFwk4cRgGpAL/9DIb/V35YE=; b=Z+bkmeHMi0r3IbXkOa0qB4T58DnfaBxuuPJZ6NWTAL6CPfBvMO4gBWJ8u5bxMEMPOPxMGRua8bzOhLxx0NbtlrGntYhtjj++7PuAiOW6DzhYv8E7uUST19BDbm6FU11ArHjVVPG1G9KYKpdklMvMnzj0uuiDMmpSBO10YS8pn8I= ARC-Authentication-Results: i=1; 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+69975+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049341307532.2437772434225; Thu, 7 Jan 2021 11:55:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id kSQMYY1788612xpcagnKPvkn; Thu, 07 Jan 2021 11:55:40 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.2146.1610049335374482640 for ; Thu, 07 Jan 2021 11:55:35 -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 107JtVks013664; Thu, 7 Jan 2021 19:55:32 GMT X-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 35wepme2jw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:32 +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 107JtSh4109071; Thu, 7 Jan 2021 19:55:31 GMT X-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 35w3g3835t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:31 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 107JtU30021843; Thu, 7 Jan 2021 19:55:30 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:30 -0800 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 , Eric Dong , Ray Ni , Rahul Kumar , Aaron Young Subject: [edk2-devel] [PATCH v2 08/10] OvmfCpuPkg/CpuHotplug: add a hot-unplug handler called at SMI exit Date: Thu, 7 Jan 2021 11:55:13 -0800 Message-Id: <20210107195515.106158-9-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: KKbelP8WicfYreFQlSJVU6mNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049340; bh=f+j/6y27w3u7qgHkLvtNoj+bUQEQrU/ua0TlP7O9sps=; h=Cc:Date:From:Reply-To:Subject:To; b=DMzZWaAfPWNvtUC6XIn78W+eyxp3/d8Rjm/tAJ60BteTWfYO9yoKnDYqkmaHmtmNCWe 24cJqGmb4E35ItlQeg6M5jKEkopfw7u6vNtbLsOGGyMuuWM4OAFOLF4dXpE0J8+DKWxOl uCwFK/rfKpcCaTUQG4Ac/WtoZcXP0YZ9Sf4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add CpuUnplugExitWork(), to be called from SmmCpuFeaturesRendezvousExit() to do the final ejection as part of CPU hot-unplug. On the BSP, CpuUnplugExitWork() calls QEMU to do the ejection for each CPU that is unplugged. QEMU handles this by signalling the remote VCPU thread which forces the SMI AP to context switch out of the SMI and with its QEMU state destroyed. On the AP, CpuUnplugExitWork() provides a holding area where the CPU spins until context switched out by QEMU via the BSP. Given that the context switch would end up with the AP state being cleaned up, this means that the AP CPU will never return to finish the SMI handling, and thus would not restore some of the CPU state that it ordinarily would (in SmiRendezvous() and in SmiEntry.nasm::CommonHandler). This unrestored state includes FPU state, CET enable, stuffing of RSB and the final RSM. Given that the CPU state is destroyed by QEMU on unplug, this should be okay. Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar 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 | 68 +++++++++++++++++++++++++++++++= ++++ UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 6 ++++ 2 files changed, 74 insertions(+) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 20d92a35da39..379c9a66f261 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -421,6 +421,69 @@ Fatal: return EFI_INTERRUPT_PENDING; } =20 +EFI_STATUS +EFIAPI +CpuUnplugExitWork( + IN UINTN CpuIndex, + IN BOOLEAN IsBSP + ) +{ + APIC_ID RemoveApicId; + + RemoveApicId =3D mHotUnplugWork[CpuIndex]; + + if (!IsBSP && RemoveApicId =3D=3D MAX_UINT32) { + return EFI_SUCCESS; + } + + if (IsBSP) { + UINT32 Idx; + for (Idx =3D 0; Idx < mCpuHotPlugData->ArrayLength; Idx++) { + RemoveApicId =3D mHotUnplugWork[Idx]; + + if (RemoveApicId !=3D MAX_UINT32) { + // + // The CPU(s) to be unplugged have received the BSP's signal to exit the + // SMI and either will execute SmmCpuFeaturesSmiRendezvousExit() and this + // callback or are waiting here. + // + // Tell HW to put it out of its misery. + // + QemuCpuhpWriteCpuSelector (mMmCpuIo, RemoveApicId); + QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED); + + // + // Barrier to ensure that the compiler doesn't reorder the next store + // + MemoryFence(); + + // + // Clear the unplug status to make sure that an invalid SMI later + // does not try to do an unplug or go to the dead loop. + // + mHotUnplugWork[Idx] =3D MAX_UINT32; + + DEBUG ((DEBUG_INFO, "%a: Unplugged CPU " FMT_APIC_ID "\n", + __FUNCTION__, RemoveApicId)); + } + } + return EFI_SUCCESS; + } + =20 + // + // CPU(s) being unplugged get here from SmmCpuFeaturesSmiRendezvousExit() + // after having been cleared to exit the SMI by the monarch and thus have + // no SMM processing remaining. + // + // Given that we cannot allow them to escape to the guest, we pen them + // here until the SMM monarch tells the HW to unplug them. + // + + CpuDeadLoop (); + + return EFI_ABORTED; +} + =20 // // Entry point function of this driver. @@ -573,6 +636,11 @@ CpuHotplugEntry ( } =20 // + // Register handler for hot-unplugging an AP. + // + MmRegisterShutdownInterface(CpuUnplugExitWork); + + // // Register the handler for the CPU Hotplug MMI. // Status =3D gMmst->MmiHandlerRegister ( diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index fb6aab17de37..f246d730d1e2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1727,6 +1727,12 @@ SmiRendezvous ( } } =20 + // + // Note that the BSP will unplug any CPUs that have been marked for + // hot-unplug at any point after it sets AllCpusInSync =3D FALSE + // so it cannot depend on an AP executing code post that point. + // + Exit: SmmCpuFeaturesRendezvousExit (CpuIndex, IsBsp); =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 (#69975): https://edk2.groups.io/g/devel/message/69975 Mute This Topic: https://groups.io/mt/79507544/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:15:07 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+69976+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+69976+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049337; cv=none; d=zohomail.com; s=zohoarc; b=CK6No5FAUI9dizADjjN3PcxqFKcJU1dNpM6rr6yjt/pjh8Zhej/8U3jRjUvb75/xMEuNocZWfz1ExuOZmZ+x09LCDTCkh7PcK202GWsN2eDKJyDGNoD7i6JCcsla//yzl7rtZxv5w7u0xNahr/1px8SQuhuKlOeqyPpL4by+YdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049337; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YGVBSWR3YyATrCFsUo5MVj0+6L7UQTPUq0fUiI55/IE=; b=KBWk9KoEXsTvvMnFhHXX73Y81fRzSnoNKEvVJQMqHR9gvRBAFeGOM+s1auEc27yc6AQ3Jzq3VjB2jA/tNlvqwmWS90g20w/0seqDBqOwUbPU/MVNoEINhn6DLmwpe+DgDL5597q8I1MlvC8f/ym/tX5cInftN9ND0botlDAza4k= ARC-Authentication-Results: i=1; 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+69976+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049337700108.13601162257078; Thu, 7 Jan 2021 11:55:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 09iEYY1788612x4sMwqOKuXh; Thu, 07 Jan 2021 11:55:37 -0800 X-Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) by mx.groups.io with SMTP id smtpd.web11.2147.1610049335981401378 for ; Thu, 07 Jan 2021 11:55:36 -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 107JtRVT150438; Thu, 7 Jan 2021 19:55:33 GMT X-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 35wcuxxeee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:55:33 +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 107JaWPd024045; Thu, 7 Jan 2021 19:55:32 GMT X-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 35v4ree7su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:32 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107JtVTF015277; Thu, 7 Jan 2021 19:55:31 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:31 -0800 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 v2 09/10] OvmfPkg/SmmControl2Dxe: negotiate ICH9_LPC_SMI_F_CPU_HOT_UNPLUG Date: Thu, 7 Jan 2021 11:55:14 -0800 Message-Id: <20210107195515.106158-10-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: cZsm5hbwPs6hIepBcG26UvpSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049337; bh=K+VzcqBbpikqcsSouiPRrvSkKUw21IvX/MhZcN7lUuw=; h=Cc:Date:From:Reply-To:Subject:To; b=kYaduDDsdI25rZNbMVORmAiQnsLMW3XfQJ4+WkCoDLYrnhV9ZYItUyg7i6GC3ZVXusB 11cRI0KuRLegurd1Yd+VPkKMthLVSvHq07jCbYT+Qv+GLGDcHlX/qGcUTXtKdyfcjAAL2 M3CG79oei1MeypEbTsSl7H3JE9c39IkbN5w= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Treat ICH9_LPC_SMI_F_CPU_HOT_UNPLUG as a subfeature of the feature flag ICH9_LPC_SMI_F_CPU_HOTPLUG, so enable it only if the other is also being negotiated. 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 | 5 ----- OvmfPkg/SmmControl2Dxe/SmiFeatures.c | 21 +++++++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/Cpu= Hotplug.c index 379c9a66f261..1f9fd31dfe43 100644 --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c @@ -391,11 +391,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 PlugCpus(mPluggedApicIds, PluggedCount); diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c b/OvmfPkg/SmmControl2Dxe/= SmiFeatures.c index c9d875543205..b95827051c2b 100644 --- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c +++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c @@ -29,6 +29,13 @@ // #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_HOT_UNPLUG upon hot unplug", in the +// "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg fi= les. +// Can only be negotiated alongside ICH9_LPC_SMI_F_CPU_HOTPLUG. +// +#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. @@ -120,8 +127,18 @@ 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; + + if (!(mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOTPLUG) && + (mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOT_UNPLUG)) { + DEBUG ((DEBUG_WARN, "%a CPU host-feat %x, requested mask %Lx\n", + __FUNCTION__, mSmiFeatures, RequestedFeaturesMask)); + + mSmiFeatures &=3D ~ICH9_LPC_SMI_F_CPU_HOT_UNPLUG; + } + QemuFwCfgSelectItem (mRequestedFeaturesItem); QemuFwCfgWriteBytes (sizeof mSmiFeatures, &mSmiFeatures); =20 @@ -162,8 +179,8 @@ NegotiateSmiFeatures ( if ((mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOTPLUG) =3D=3D 0) { DEBUG ((DEBUG_INFO, "%a: CPU hotplug not negotiated\n", __FUNCTION__)); } else { - DEBUG ((DEBUG_INFO, "%a: CPU hotplug with SMI negotiated\n", - __FUNCTION__)); + DEBUG ((DEBUG_INFO, "%a: CPU hotplug%s with SMI negotiated\n", + __FUNCTION__, (mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOT_UNPLUG) ? ", un= plug" : "")); } =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 (#69976): https://edk2.groups.io/g/devel/message/69976 Mute This Topic: https://groups.io/mt/79507545/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:15:07 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+69980+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+69980+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610049478; cv=none; d=zohomail.com; s=zohoarc; b=huSWPPsFGerrr0pePyWr1myd2VrVRfizFMRqmKBbid3WxdV2qEjySiXirAyo2ElihPQ4ENALjqcl9iesqxIiikWBuwtjQyW3JI5XqEo9TehqWFhzCLsX37guueDaUisa4So89mqKvV6QBIisFmQJzeFaywWM0hBCIJe0heCPnpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610049478; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1uj24YYmDLd1rdphMl1tc0N5AEUE33yZfH5teTh860s=; b=Kkc//oxzf723yQ0UXJhZJAss+nO7QT/5DQ1yNea27VjVcD/4TnbQLENsZD+fV3b/QxxH5VwtIbN1kfc4X+5NFnhawZQJ1F854do/Ffj57VNUp2IBB2LdibCFQSEFLxwLb0mgpOUy7COWHbNW+8PC3KqrYzw60pVnhld2nfLAZRg= ARC-Authentication-Results: i=1; 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+69980+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610049477998133.54822588967454; Thu, 7 Jan 2021 11:57:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ULHEYY1788612x42y6NIdhTh; Thu, 07 Jan 2021 11:57:55 -0800 X-Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by mx.groups.io with SMTP id smtpd.web11.2173.1610049470165048084 for ; Thu, 07 Jan 2021 11:57:50 -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 107JtbvA013698; Thu, 7 Jan 2021 19:57:34 GMT X-Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 35wepme2u9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 07 Jan 2021 19:57:33 +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 107Jss2t026037; Thu, 7 Jan 2021 19:55:33 GMT X-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 35v1fbn1t4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Jan 2021 19:55:33 +0000 X-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 107JtWOw015280; Thu, 7 Jan 2021 19:55:32 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Jan 2021 11:55:31 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: lersek@redhat.com, imammedo@redhat.com, boris.ostrovsky@oracle.com, Ankur Arora , Michael D Kinney , Liming Gao , Zhiguang Liu , Aaron Young Subject: [edk2-devel] [PATCH v2 10/10] MdePkg: use CpuPause() in CpuDeadLoop() Date: Thu, 7 Jan 2021 11:55:15 -0800 Message-Id: <20210107195515.106158-11-ankur.a.arora@oracle.com> In-Reply-To: <20210107195515.106158-1-ankur.a.arora@oracle.com> References: <20210107195515.106158-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 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: DJJ3BBs6eGOVRIk5JqyKhx7jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610049475; bh=qL4uJx1zVE7uSt7EtIq73NFgu6Juk3FI+qNN0DfX/nc=; h=Cc:Date:From:Reply-To:Subject:To; b=wDGvfpEXNPdijij7HO94Sd45DNgu4gTIUc4IIl0REbfBVre5QPwDslDAwjYeoVXLWEB zWeUmhRz5/HDuialXssPla+UcoEVeRmXRQwWLSt5mi3N5co6nQynY/q4GAKdjAd9YqPRi YobFz3kZQo0CxtOW5XXf0IFyU00oTTEuptM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Use CpuPause() to allow the CPU to go into a lower power state state while we spin wait. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Laszlo Ersek 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: Michael D Kinney --- MdePkg/Library/BaseLib/CpuDeadLoop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseLib/CpuDeadLoop.c b/MdePkg/Library/BaseLib/= CpuDeadLoop.c index 9e110cacbc96..e76312de7b4e 100644 --- a/MdePkg/Library/BaseLib/CpuDeadLoop.c +++ b/MdePkg/Library/BaseLib/CpuDeadLoop.c @@ -28,5 +28,6 @@ CpuDeadLoop ( { volatile UINTN Index; =20 - for (Index =3D 0; Index =3D=3D 0;); + for (Index =3D 0; Index =3D=3D 0;) + CpuPause(); } --=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 (#69980): https://edk2.groups.io/g/devel/message/69980 Mute This Topic: https://groups.io/mt/79507581/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-