From nobody Sat Feb 7 06:55:25 2026 Delivered-To: importer@patchew.org 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+82591+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634962488640899.1706569369359; Fri, 22 Oct 2021 21:14:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uiP8YY1788612xPik8ui1f8P; Fri, 22 Oct 2021 21:14:48 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.77]) by mx.groups.io with SMTP id smtpd.web11.2840.1634962487463489621 for ; Fri, 22 Oct 2021 21:14:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bEGIlTdh7o0RGvYu7xSa6yYAsrGKnqFJSNIoSLXZ9pM1kZ4v6LykJ3pkwOPLRThfBLDm5VJOmWblPXC4+ZCoHHCidavAQiJOR6tB594xdalAZV2oMDRsJI2W79P0k72LoRLyiGlwmXtc2XgphYevjD4y0tz4U0+nYZ4q6g8v1gYyH2GOrzftZvMUYQ7qjPBEDFPiV9uPh7GvFvDEObA91+V0VQ0SSfxpqAF39/7KjIm61vpQehhzM5Sy+QEcFDVpQb2sux9oiZS6s3pLsDhAA8rzbJ3mAeL+gEYYGo+k4EzPG3C5LH3y+ZaBAPyEuXi/vU9dSszHPVTSfUpIhat8Bw== 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=fg55SiKjHgyEg+RLzTS2/GuEu38lO01I4SttHiIAZbs=; b=NjqmdCYqiafrxD3tDhy2ueCDTp8T4xciQbCkxTjRMz+DtH2W5hYA+6AHVzSEdIpBJUBWs+kPRj+Os/wdUxEbsOER+eNuXkBt4y0NFqv1eo4qAN5IQtwUCVoFiOLdXz99/OAHBbmtYCP8voiOu6GFkeI25Ark4HIiuH3fRFNRUiEB3ATBgibdu+4Xg93UyHI39FEqgKZVFIsdlmQVMcKUB5BRuOVwrz5jERTeg7okJIYPqRR9u+BnO8OyqtC5hb8TZc3ewQZVSoBp8wA8fl7+f8zVRd/afamdhzR1BF7M50J6V0S1S4aKZvplPeNMYY9DKiXP8/yuS97PHN11ql0KfQ== 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 X-Received: from BN6PR2001CA0035.namprd20.prod.outlook.com (2603:10b6:405:16::21) by BL0PR12MB4689.namprd12.prod.outlook.com (2603:10b6:208:8f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sat, 23 Oct 2021 04:14:43 +0000 X-Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:405:16:cafe::6e) by BN6PR2001CA0035.outlook.office365.com (2603:10b6:405:16::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 04:14:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; 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+82591+1787277+3901457@groups.io; helo=mail02.groups.io; 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; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4628.16 via Frontend Transport; Sat, 23 Oct 2021 04:14:42 +0000 X-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.2308.15; Fri, 22 Oct 2021 23:14:39 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH v11 26/32] UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled Date: Fri, 22 Oct 2021 23:13:43 -0500 Message-ID: <20211023041349.1263726-27-brijesh.singh@amd.com> In-Reply-To: <20211023041349.1263726-1-brijesh.singh@amd.com> References: <20211023041349.1263726-1-brijesh.singh@amd.com> MIME-Version: 1.0 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: c08ae428-9b61-4057-e6ae-08d995dba382 X-MS-TrafficTypeDiagnostic: BL0PR12MB4689: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: NBYsefTSWQ8R81+3hR8eQ1oU03svUncQwUR33nUpmZ0q4uFZpo8Z6z3J/pCkjF/q/t0+qc6VeLsNWH1EUIirXJ/ZlnjwIFTrDjuUmTCfIso+YoQBF5NE4tJyBOV3S7dHFYZM3pLfl4cqjZDIncdXBMtOHgYyrwjdx3Gs0yZeAYN92J0ZixnF/XXpdtw6WA/0vTSo3fjTbQQYCtFPF0aV8KGcer0t5l/13On4bPs2mDCJe7qo/DvfkMDdL3w/HIHgzF2MN7lWd0drsJD4kBViomLAGB0Z42YOq/qurqTzi0NTqvlQVXQULFsog2rFlbNSzhLPg+JesMOQSy552MUrtFLDLlxFkkaVTb3oAPBXQwRtOyUzw95Tv6xdZSoWYYSKe/4pPkNrErKOiBT7oJ1zP3kU/W2ztAK69ipCr4FWOeLoUB/2+QNoem/x51udm8ZjiKQu1J8R5uwHFPTpgJ2FpteFg0sKLQ4balSlAi7o/KjbFH4lyDUyVDDcg24LDhy7q52bhPM7fu/e+WYM6jQKbCg3v18Z70DwnAQZYDuqD+bb/8pWhZCsQDVrWw0kiixCqYPBwG6Hze8+2jg6MXkOsHE4aiS0yV8xt0rLybmjenLigHjlhwdS/seIXU6/bI2POw+zO9clwBPxTl6X2CAwumw726Srp9fZLfWoRhJf/yC0XujY5UTJ4CMQGdN2nAaYrWTgcHBNGk2VxUDoruFCEqyAFnfr+Zgb2f1UNKvUFuM5mkT8SzOVilPnniwaONLsZ2BiIO4IpYgeIN8ZUFH/ZPRnkItoUwlNl6TlzQ2jOcESdEuKk4eoIqOqn/tT0agV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 04:14:42.2847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c08ae428-9b61-4057-e6ae-08d995dba382 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: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4689 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,brijesh.singh@amd.com X-Gm-Message-State: L87or6hyDYdIJsI2EDhZw6wjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634962488; bh=ryMt9yvCvMg4uBejODjHl5yLMHvERv7JJulHRn+dvgs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Sy/hWbbueRVpcgx7AOw10Texb5F/qGeaL9mH4F5HOnCsg48L2BEikTQ02tEU1VaQcdu mPf91gpL2M4helKVgV15+Joya2eKzgtpTLYdOUSpRew+cw/9EUVyYmnBIu0u1HeNNsJqA mbCAOndBqqxfcuzv8PeRBQakAsx5IDZkusg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634962489487100105 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 An SEV-SNP guest requires that the physical address of the GHCB must be registered with the hypervisor before using it. See the GHCB specification section 2.3.2 for more details. Cc: Michael Roth 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 Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 + UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 54 ++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 2107f3f705a2..45bc1de23e3c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -222,6 +222,7 @@ typedef struct { // BOOLEAN Enable5LevelPaging; BOOLEAN SevEsIsEnabled; + BOOLEAN SevSnpIsEnabled; UINTN GhcbBase; } MP_CPU_EXCHANGE_INFO; =20 @@ -291,6 +292,7 @@ struct _CPU_MP_DATA { BOOLEAN WakeUpByInitSipiSipi; =20 BOOLEAN SevEsIsEnabled; + BOOLEAN SevSnpIsEnabled; UINTN SevEsAPBuffer; UINTN SevEsAPResetStackStart; CPU_MP_DATA *NewCpuMpData; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9109607c87a9..ab838cbc0ff6 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -889,6 +889,7 @@ FillExchangeInfoData ( DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->SevSnpIsEnabled =3D CpuMpData->SevSnpIsEnabled; ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; =20 // @@ -1817,6 +1818,7 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdSe= vEs); + CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evSnp); CpuMpData->SevEsAPBuffer =3D (UINTN) -1; CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index 2e9368a374a4..01668638f245 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -92,6 +92,7 @@ struc MP_CPU_EXCHANGE_INFO .ModeHighSegment: CTYPE_UINT16 1 .Enable5LevelPaging: CTYPE_BOOLEAN 1 .SevEsIsEnabled: CTYPE_BOOLEAN 1 + .SevSnpIsEnabled CTYPE_BOOLEAN 1 .GhcbBase: CTYPE_UINTN 1 endstruc =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Libr= ary/MpInitLib/X64/AmdSev.nasm index 0ccafe25eca4..0034920b2f6b 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -15,6 +15,57 @@ =20 %define SIZE_4KB 0x1000 =20 +RegisterGhcbGpa: + ; + ; Register GHCB GPA when SEV-SNP is enabled + ; + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)] + cmp byte [edi], 1 ; SevSnpIsEnabled + jne RegisterGhcbGpaDone + + ; Save the rdi and rsi to used for later comparison + push rdi + push rsi + mov edi, eax + mov esi, edx + or eax, 18 ; Ghcb registration request + wrmsr + rep vmmcall + rdmsr + mov r12, rax + and r12, 0fffh + cmp r12, 19 ; Ghcb registration response + jne GhcbGpaRegisterFailure + + ; Verify that GPA is not changed + and eax, 0fffff000h + cmp edi, eax + jne GhcbGpaRegisterFailure + cmp esi, edx + jne GhcbGpaRegisterFailure + pop rsi + pop rdi + jmp RegisterGhcbGpaDone + + ; + ; Request the guest termination + ; +GhcbGpaRegisterFailure: + xor edx, edx + mov eax, 256 ; GHCB terminate + wrmsr + rep vmmcall + + ; We should not return from the above terminate request, but if we do + ; then enter into the hlt loop. +DoHltLoop: + cli + hlt + jmp DoHltLoop + +RegisterGhcbGpaDone: + OneTimeCallRet RegisterGhcbGpa + ; ; The function checks whether SEV-ES is enabled, if enabled ; then setup the GHCB page. @@ -39,6 +90,9 @@ SevEsSetupGhcb: mov rdx, rax shr rdx, 32 mov rcx, 0xc0010130 + + OneTimeCall RegisterGhcbGpa + wrmsr =20 SevEsSetupGhcbExit: --=20 2.25.1 -=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 (#82591): https://edk2.groups.io/g/devel/message/82591 Mute This Topic: https://groups.io/mt/86530740/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-