From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.81]) by mx.groups.io with SMTP id smtpd.web12.15090.1634672419095761834 for ; Tue, 19 Oct 2021 12:40:19 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=NRDVtQcy; 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.223.81, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AgRLKTw66Xhoi78YLN5I5C/kOiYoMFJOJuWwATM/28xVctuX605+J35ZrCgcReSYcXjsMtamSok0SW2wjZvl9cJaAx306NTKxJHBN8WZDU8QTejgVZcJxuqPVFM2Ty5zOwbUypaAq2mqX3AgQv1NX3izI9YWWbSBH7kak0tfLYNj+cAXKs/v728qHm2p0nxQhXBh7Nm8ugDeMjqYmqmsz32XiybBSLQZgOREGFyUzQFJeS7sNydbIeoXV6vTBVlIE+AQttOERWYNQldVWXyDbshpvp1kHgcFqHCZZbb5HVs7500L0/uEwyknYtqP460TOn6BcEuot+Fun3CgiFnkFQ== 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=+TfJypqUug0RrXurJHrK4ph3xkZPrVZ4Q5LPClKW0rA=; b=NuFx81o8wv/0sO90R6k56o2iakafM0GAsd+hln12nFEVgCP9fPWECpI75nln/7g8P4BivII4qxT2CF7kRq4Ek6Qw16h9vp4xExQG9YY1eZYAKF95Yxz4YszD4mGGfG+c4LX/EHhJ+Tab2Woa1z0BBWEj+EVKPd16VOXHJH0xuOgTix3p1lH2CLX0yOUc3GOUyDrIbbcSEqL0SQJYgU+KZTWpaGWYdhwHHGm4sTr9pGxXNQ5qQarTeRApDHzrO9vWhIl987S9HQoEqSFQ3UWvpXhuOgJ4TTnIyqMk2JJnEt6+PzziuKXLrYEINTH/Qjsz954cGrxb+OJEUfVQzwD8Fg== 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=+TfJypqUug0RrXurJHrK4ph3xkZPrVZ4Q5LPClKW0rA=; b=NRDVtQcyGKMJDSjOwO1qHDiI60NQi5LNM2eT9BabL1MVZ4zDK1joQS0gRJIE5fYv3o3sBZbYqmbx1UBTRBqaCzKIVKBFiTQ6wYii2HpyRq1D0kRnOhLDYcqoLYTLU6QgZddAMrpjh7AZqGw6xuniQtMQxw7HcZYUD4qcQsH9UnY= Received: from MWHPR02CA0018.namprd02.prod.outlook.com (2603:10b6:300:4b::28) by BN9PR12MB5306.namprd12.prod.outlook.com (2603:10b6:408:103::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Tue, 19 Oct 2021 19:40:16 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:300:4b:cafe::f4) by MWHPR02CA0018.outlook.office365.com (2603:10b6:300:4b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:16 +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 (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 CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:15 +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.2308.15; Tue, 19 Oct 2021 14:40:10 -0500 From: "Brijesh Singh" 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: [PATCH v10 26/32] UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled Date: Tue, 19 Oct 2021 14:39:28 -0500 Message-ID: <20211019193934.1052465-27-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da8fc775-28c4-44b3-9744-08d99338466b X-MS-TrafficTypeDiagnostic: BN9PR12MB5306: 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: BCL:0; X-Microsoft-Antispam-Message-Info: SnlHvQTP2nZ4UPVSV18g5DMqM+7Wx2enDDrQqjw2XegpfrbKuRzCPIM2mqjsPnTcBD7bZNiMUVkdUke5fQb+gwTdiDvr2jiOFFKzk8Z3tgsbG/w9oNJQT1ibFRZ7ske1+uDok7oAYGnQtEtaRPbXeW6vNe2XpB5khCBt8JU2Td+3YGwrkj995DpeCJWezqtGh4Og9tGiwqRWb6hlcpqTyq983INSh8HRYTwCaSqCgOf/vRxJaHBmsvA9gx+r80GD68x4ykbaw+KJJjamQ/qJL727uZugIsndxh+Fn0AG+WEBApESRgTe5PkwOWWWr8byZxTAHRMcWvvui1542LJUBGfBGcu0RPmS35blsFTdqCVTs8SkB9ChflLxpsU9v39rHMrzZU93v3SR+uiBqZk2KQbEKX+55SxzKHJMB0gbFki7t9lqMJnILq0OC/A6U8VmpaJ6XZy7NlQXmnLledN33FcCqwPQrqm2385s5lO+QgkeKN9zsNBSJwpJO+7jPLS1rHXYoeR0yDutoIfbri3AfDOhhaI4Js+uqFkJrZgiMO86L2fUxfHMOaGPEEsWcv0TB4lnw3tI3+bY3Rn2L5Od8lUVFu2MQm6FEvUmq03YpVAX8ET2aoyf7JRrkBhOi9Cmz06VLKKC2PbGpeo2XCv0s5XSlOTIDRtFHxA2TAQtFw+CoSbmnuL9mSaONmUxnyCbR12frCluqJXQRqmtW/kn7gjqGy1C22hju7STcQI6odgU0lbK+LL7elbw6h5r7Ph362BdzXHwRwsEfOR3cgBMFtUzLSHnhbcRg7IdpTKcfEJNiK8Kq+HoOadw2QtBP3VH 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)(36840700001)(46966006)(508600001)(6916009)(4326008)(426003)(44832011)(36756003)(2616005)(6666004)(47076005)(82310400003)(336012)(316002)(2906002)(7696005)(966005)(7416002)(36860700001)(8676002)(26005)(54906003)(356005)(8936002)(19627235002)(83380400001)(70206006)(16526019)(186003)(70586007)(86362001)(1076003)(81166007)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:15.7024 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da8fc775-28c4-44b3-9744-08d99338466b 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: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5306 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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 e587d228ab45..b05eb4413a95 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