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.49]) by mx.groups.io with SMTP id smtpd.web08.394.1636738841597695615 for ; Fri, 12 Nov 2021 09:40:41 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=0myIab5e; 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.49, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IKJVfUlKYG38v9APqtl7Zokh8VYcDA11Wqgp92Atct+U9dIcTSbTLJGU/lTBHYijuhAS6YEUNERYhenWLhVBIiH10nGEotwymOYTMpYbNlTtgOjdOgtfZQLRpDeYIQy0fyuQb89mbka8uT0+wbAoYfzs1XOM6sTJL4w//LibECfjNa16785A/Y8t0Org9s0LfKU7antisR5uI0/io5L0s57X7ekgbnaS3k1dv1VPpJLKZxMo7NnP+gwp9A2yzx9/t/3Ibtvuofi/M4sKSZkc5Ez+DZQHyuc9h/WFod3UQL9RheygsMna/lztvjm+JfHJ9rSo3qOryHm9TXVSDAqMTw== 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=Ia6yxTCul9RDyiKTzNJi1C+x730Tc1KvGEKTbHHINJM=; b=etrKUnUgJaCULgBTZg/dxGg2QqJPooYi0QINkanqNPJkCfsdBefJ4ZSvCyCMzVOj41+8xAY/NfDwxIQxDT3nVIeuRP5YUZBTHY3okazzHA3QhDLcpWrrVumWGSj4MlHhvKTaEb/+QqFUA4MhY0bpmasyxkbJSa3iSIPZjKNu2gYMpqhvyGtpK1rpvFp4Mh9kgj4FNib+AFTImPC3PsBYa25x/rqpCUL1ErVHarSjFu0eQfZt3YMTGtsX8aQ1LSCsa6Pee0F3xlCRcD2/DswaeGvF7aocunBMWZmNqRDwVFpxSHaGxVQAV+dydWFUIS7YAY6br//cl8jkHnfKi+b8uw== 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=Ia6yxTCul9RDyiKTzNJi1C+x730Tc1KvGEKTbHHINJM=; b=0myIab5e5OjvTZlwILYZLiZUzDklWysnk5a/gG56nUVD8vrnYtkLhLYx596fOuDBG9wFUwRmMw55LZAQuok7Lw/DcDmvHsf1hO7O3yOfNfmbEefNCiPSGkDg8JJlj+qb9nGSBiTn/AE02S/ADuG6/ldEEiwohrq/2tO5e0LlIa8= Received: from BN6PR19CA0078.namprd19.prod.outlook.com (2603:10b6:404:133::16) by MWHPR1201MB2476.namprd12.prod.outlook.com (2603:10b6:300:de::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.26; Fri, 12 Nov 2021 17:40:39 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:404:133:cafe::ef) by BN6PR19CA0078.outlook.office365.com (2603:10b6:404:133::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 12 Nov 2021 17:40:39 +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=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:39 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 12 Nov 2021 11:40:37 -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 v13 27/32] UefiCpuPkg/MpInitLib: use BSP to do extended topology check Date: Fri, 12 Nov 2021 11:39:54 -0600 Message-ID: <20211112173959.2505972-28-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-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 SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40d71d07-d65f-47da-3aad-08d9a6038ae9 X-MS-TrafficTypeDiagnostic: MWHPR1201MB2476: 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: r0rF67cUzIvhKbztUM03Ubg0eL5TJvpyUvempRTEVk9OIW9bDAZmvqEW6YaEd1Nla/l5Aun57eldCYviwAJD+PzS4jcy9By6XG8QLgwhjiZWPNg8Xuv64ZteLVgqEPbAdrpA0R18zrZV9CwoVIUXt6aVtXS/NYf+pc/c3EUgOn4IgmkEq9APG6di2c1DwXGZnXBCecNc/Gg/J8EWlZRINRQxb91LIoB9w2HnGZW4NIGHPcPsE0KO/2uF2itDBvnj8cAsAq+jEKWVtuPdmte3MqW3LD9e5/jViaztY8obPdpRrMS6N481dzPoQCNSK6I3rUJOmHGfeH0hZgEgXA8ulvgkzxGR00SM1tBihWHcqqNl0Q19dut8g8fisnGt6x0les4EIW86pZTkarmTx4vkJOYP9jEwgVFcshjBn2n0sHaMLU4LTs56qJ5n+YbZwdR9TaM12cwK5any4Gy50Og5atHgO2La9g7tTeGjNC0ogv6oHoeIRuEWbI6xs4SktHOW9ysEMZTrqbPERMT7ibwMtzMsfMpySKSiCG9rbrAO5u8HN3J/UKRnaol37KOH6a5alp9GLX1NC2MXdDOkRm2Fwy+TkPl4kjYV00TIytHRHK6gX8a7I8+CVFLuKe1dupdla6PylDDUuPP4xWVTeSj0vsoEKjoi5bQLe0Ptv7XRsTbpFzINuCZN4olt5R5lLX8uYWtC5WJ3elghpDAf8TE7bZU5KZcJzrcOvrp80WM3DBkfeSadUJZHa5do09JPSEfRS1lLbBKFHm5pOM18qTEbLw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(6029001)(4636009)(46966006)(36840700001)(336012)(6916009)(26005)(1076003)(5660300002)(70586007)(86362001)(6666004)(70206006)(4326008)(186003)(16526019)(36756003)(82310400003)(19627235002)(8676002)(44832011)(316002)(508600001)(2616005)(2906002)(7416002)(54906003)(426003)(36860700001)(8936002)(83380400001)(47076005)(81166007)(356005)(7696005)(36900700001)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:39.4839 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40d71d07-d65f-47da-3aad-08d9a6038ae9 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB2476 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 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 45bc1de23e3c..c5887ff6f647 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() @@ -789,5 +790,15 @@ 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 =20 diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c index 7dbf117c2b71..db02d059512c 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -237,3 +237,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 315172fb937a..b13ba3075273 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -892,6 +892,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