From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.64]) by mx.groups.io with SMTP id smtpd.web12.6770.1639020564360667123 for ; Wed, 08 Dec 2021 19:29:24 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=pZt2GJ1D; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.220.64, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BgspckRKu+kadwsyXBI0nmrFPPvlcNN57V3M9pCgic+tFAVTU9eQaKVi27Hls5y7bBwNnq9wSRD5iamQwZPzLAuLYIZH/quUxuDl4Prce1mI7rttNFX36yefAV9wvAtEdniElNLccAWChtnCfnhRpHgWjER49yEp89Zz0YIe7pxsFL7I6M8syUV+Rs9tUkTiSQhkkhLPE04mM5KIexcz00IerDRCRvoGZvlYfUouvXWPcdieCBlbd2Zx5Y/NJzaVcBgfx4l2cwxkywdLnMT0MBYv9kVjDZnIyvBIzfuhJI3ZgeQP/u4EgeJyDtxJrrpOabpUhAk9okUvI3idS134MQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=U+bP5GtrsELu4HBNzGoYyzz9Ph7PVOrvwtVcVB6wCr0=; b=RuTzfO7nf8Ft7mHf5xwmtyj/AxnGO3P/8XHxdE7COKEzc0zyQM7F+nnGk+i42gLnzpm1u9cQno37qhiKNqzY3/JaUEYJVhluZX3PQ1IdNatI3xARsg8o+HCInP9sFL/V3qan/FrBrySD6QXcdRPi5TfTnKY9/r+FdOdscX0h7p62SAIi+U61UpAlxQksp3rQrp/dN/tIBA1DwgXYHg4z+wd43gTihM4Yp1xCxHC9fZ03jPezKaxFWneEMHf0wWJaMEZ6/rYH6ihlJaxdL45TgFU198sEE1dz8hD9PH/1s4B8C+J89QxqZuW+nIPuChDBEiMwteY2CWmvlwBwWHbL5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U+bP5GtrsELu4HBNzGoYyzz9Ph7PVOrvwtVcVB6wCr0=; b=pZt2GJ1DNJi1dKKLKkKmxD1pHiqXJ+6jSsh9XjLHMJ1EC8GNEI6Hx1zHzi48HkaAKiizalsL4q841C96xnga1KWVdWn25dUrZaucRXh4Xww3NMhlgoCfvJ3S33Zb1ZH7ZSDJabuK+mdt+dEjU3dJEmPaLT/vSNqPcGG+VIyXAUM= Received: from CO2PR04CA0197.namprd04.prod.outlook.com (2603:10b6:104:5::27) by CH0PR12MB5267.namprd12.prod.outlook.com (2603:10b6:610:d2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.19; Thu, 9 Dec 2021 03:29:22 +0000 Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::5) by CO2PR04CA0197.outlook.office365.com (2603:10b6:104:5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12 via Frontend Transport; Thu, 9 Dec 2021 03:29:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT031.mail.protection.outlook.com (10.13.174.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 03:29:22 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 8 Dec 2021 21:29:18 -0600 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Michael Roth , Brijesh Singh Subject: [PATCH v14 27/32] UefiCpuPkg/MpInitLib: use BSP to do extended topology check Date: Wed, 8 Dec 2021 21:27:55 -0600 Message-ID: <20211209032800.3802995-28-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d231f316-45ea-4911-13f1-08d9bac417e1 X-MS-TrafficTypeDiagnostic: CH0PR12MB5267:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TKnz+aJICE1f2sNnW/Gw8QilPQtyZvcowir66ILNQ/0spyiLwFQ8ZfwYHu0eSmAM1uy64+hCEMDDIwp5Oo7soesoYKGDipC7fq+JQZMR5flINICmbnU0yf85yrOXnnYZYrlTO+MeBVXdGGK3wct2D24uC/sQO8T3NryOqt2EehjDOqzhZGK3UPZfSlGKf50vokxEKb4vxGwSvOYlMnOGnAJ5FPUTQR0ooBueL0YqALKdI5Rj5rBoGZ4zjR3QYC80AcguG355r7HEY41C9/3Eq0R4Jt1ELZb1cvNaLXVp4nZ8gfNn49BYUlBHzJuvnh4lvTiUQzIE+oagCsqTNaEducI6/eGi2s0BK0HOrqM2mltfuIfWTFm5qb0XtRnnMMSS65JE2+ieNp5wNrEaSfGZ6/hqpFtN54yoX7qbmprncL3eS94SEEr2Ls6TuqaQ11PPFJx3W4af7ILMHBVKlCBTp1T/ipHbI+t7+6ibTP/KzIMv+hjUHRfRn+ZtDGyqbUz5JKmfDwMWZDfO1tzJ5aW6Ygq7/xR5ECC0ZOaZWhCHOVLSvvixkl83zS0KGxyMZontpf3uXIpJgGhr1TrKM6a6gv2tB/eh6fPMdOYrvD8EunsslH6rgslSOOJJAToNGFIqZAGw1F8DbnaF2/KNlAtUNlHtT59+xuAdIFjbIIrKvgQJcYtSDVRIZxxVKQpk9/MBzj7a8jHxVF9OgSPYEesDImoLiMXwbXe2EXed2K3S+IAO21Fppy6XT/GzgpQdZ4VISIRLvKnLn0XidDerE+q0b6QugLWpbQi4PxCJ0lB2f/X2eBmH44vySesOgMSoKZn51d0Xee09E0slAsDGUCpGaA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(6029001)(4636009)(46966006)(36840700001)(40470700001)(4326008)(336012)(6916009)(36860700001)(5660300002)(2906002)(8676002)(7416002)(7696005)(8936002)(36756003)(82310400004)(44832011)(426003)(2616005)(26005)(47076005)(6666004)(81166007)(19627235002)(356005)(40460700001)(83380400001)(316002)(86362001)(1076003)(70586007)(54906003)(508600001)(70206006)(186003)(16526019)(36900700001)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:22.5056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d231f316-45ea-4911-13f1-08d9bac417e1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5267 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Michael Roth During AP bringup, just after switching to long mode, APs will do some cpuid calls to verify that the extended topology leaf (0xB) is available so they can fetch their x2 APIC IDs from it. In the case of SEV-ES, these cpuid instructions must be handled by direct use of the GHCB MSR protocol to fetch the values from the hypervisor, since a #VC handler is not yet available due to the AP's stack not being set up yet. For SEV-SNP, rather than relying on the GHCB MSR protocol, it is expected that these values would be obtained from the SEV-SNP CPUID table instead. The actual x2 APIC ID (and 8-bit APIC IDs) would still be fetched from hypervisor using the GHCB MSR protocol however, so introducing support for the SEV-SNP CPUID table in that part of the AP bring-up code would only be to handle the checks/validation of the extended topology leaf. Rather than introducing all the added complexity needed to handle these checks via the CPUID table, instead let the BSP do the check in advance, since it can make use of the #VC handler to avoid the need to scan the SNP CPUID table directly, and add a flag in ExchangeInfo to communicate the result of this check to APs. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Acked-by: Ray Ni Suggested-by: Brijesh Singh Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 11 ++++++++ UefiCpuPkg/Library/MpInitLib/AmdSev.c | 21 +++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 7 +++++ UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 27 ++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 56de3bfb1ccf..be67cd88ec46 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -224,6 +224,7 @@ typedef struct { BOOLEAN SevEsIsEnabled; BOOLEAN SevSnpIsEnabled; UINTN GhcbBase; + BOOLEAN ExtTopoAvail; } MP_CPU_EXCHANGE_INFO; =20 #pragma pack() @@ -788,4 +789,14 @@ ConfidentialComputingGuestHas ( CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr ); =20 +/** + The function fills the exchange data for the AP. + + @param[in] ExchangeInfo The pointer to CPU Exchange Data structure +**/ +VOID +FillExchangeInfoDataSevEs ( + IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo + ); + #endif diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c index 0e3c6e231077..b4a344ee6b33 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -243,3 +243,24 @@ SevEsPlaceApHlt ( =20 MpInitLibSevEsAPReset (Ghcb, CpuMpData); } + +/** + The function fills the exchange data for the AP. + + @param[in] ExchangeInfo The pointer to CPU Exchange Data structure +**/ +VOID +FillExchangeInfoDataSevEs ( + IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo + ) +{ + UINT32 StdRangeMax; + + AsmCpuid (CPUID_SIGNATURE, &StdRangeMax, NULL, NULL, NULL); + if (StdRangeMax >=3D CPUID_EXTENDED_TOPOLOGY) { + CPUID_EXTENDED_TOPOLOGY_EBX ExtTopoEbx; + + AsmCpuid (CPUID_EXTENDED_TOPOLOGY, NULL, &ExtTopoEbx.Uint32, NULL, NUL= L); + ExchangeInfo->ExtTopoAvail =3D !!ExtTopoEbx.Bits.LogicalProcessors; + } +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 44a011ba75de..b73a6e9a0ffc 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -900,6 +900,13 @@ FillExchangeInfoData ( ExchangeInfo->SevSnpIsEnabled =3D CpuMpData->SevSnpIsEnabled; ExchangeInfo->GhcbBase =3D (UINTN)CpuMpData->GhcbBase; =20 + // + // Populate SEV-ES specific exchange data. + // + if (ExchangeInfo->SevSnpIsEnabled) { + FillExchangeInfoDataSevEs (ExchangeInfo); + } + // // Get the BSP's data of GDT and IDT // diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index 01668638f245..aba53f57201c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -94,6 +94,7 @@ struc MP_CPU_EXCHANGE_INFO .SevEsIsEnabled: CTYPE_BOOLEAN 1 .SevSnpIsEnabled CTYPE_BOOLEAN 1 .GhcbBase: CTYPE_UINTN 1 + .ExtTopoAvail: CTYPE_BOOLEAN 1 endstruc =20 MP_CPU_EXCHANGE_INFO_OFFSET equ (SwitchToRealProcEnd - RendezvousFunnelPro= cStart) diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Libr= ary/MpInitLib/X64/AmdSev.nasm index 0034920b2f6b..8bb1161fa0f7 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -118,6 +118,32 @@ SevEsGetApicId: or rax, rdx mov rdi, rax ; RDI now holds the original GHCB GPA =20 + ; + ; For SEV-SNP, the recommended handling for getting the x2APIC ID + ; would be to use the SNP CPUID table to fetch CPUID.00H:EAX and + ; CPUID:0BH:EBX[15:0] instead of the GHCB MSR protocol vmgexits + ; below. + ; + ; To avoid the unecessary ugliness to accomplish that here, the BSP + ; has performed these checks in advance (where #VC handler handles + ; the CPUID table lookups automatically) and cached them in a flag + ; so those checks can be skipped here. + ; + mov eax, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)] + cmp al, 1 + jne CheckExtTopoAvail + + ; + ; Even with SEV-SNP, the actual x2APIC ID in CPUID.0BH:EDX + ; fetched from the hypervisor the same way SEV-ES does it. + ; + mov eax, [esi + MP_CPU_EXCHANGE_INFO_FIELD (ExtTopoAvail)] + cmp al, 1 + je GetApicIdSevEs + ; The 8-bit APIC ID fallback is also the same as with SEV-ES + jmp NoX2ApicSevEs + +CheckExtTopoAvail: mov rdx, 0 ; CPUID function 0 mov rax, 0 ; RAX register requested or rax, 4 @@ -136,6 +162,7 @@ SevEsGetApicId: test edx, 0ffffh jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero =20 +GetApicIdSevEs: mov rdx, 0bh ; CPUID function 0x0b mov rax, 0c0000000h ; RDX register requested or rax, 4 --=20 2.25.1