From nobody Sat May 4 15:08:10 2024 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+84540+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16390204998301000.3855883334485; Wed, 8 Dec 2021 19:28:19 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ps4gYY1788612xGyIUnwItV9; Wed, 08 Dec 2021 19:28:19 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.47]) by mx.groups.io with SMTP id smtpd.web09.6933.1639020498700646554 for ; Wed, 08 Dec 2021 19:28:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jLWunJ7Wy6S6YlAOn4IfXIqGpIgydu9yieiyXcL3fVz0ren83KFtFqlWY+mGjv/IZRMNj4Z452G6Hp+UZOf2IN0gETZOo51V9t13JRRqDLo/HDHBZEI1sprYSyIFH4QewMrD6VNHLX9Ep9I7si3e+60eP2jyT/6yxbBJ3dwd0Riebunwt4kYLv2sEudivCRXRRio5wZ0mdBAULpViIIvUtkrKzZZvTnUqXppD2d2rHC0tnmUUrV6rwSFCm/iKRwbVVBtk/zIoZr20D1XdliXWBu9nkFamuhxxmf3s7UB9jMZQ2hUlwVGv8A3PlfoVekfZeFv6ufvtBSXkFb+dQGXlQ== 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=+Bzj241cDLYrgygXwsiNjE2wZEy81zlu3b0LzC+9OmY=; b=ZvqPSwKMg5zXQch+j0xsdWbWCEvcTGxWvKKA3I75yEPBV2UVfxYL8WJO7QZyXsEnhCzEDCwjwjMM8E52LZeKcTAZ6wA6AWQtTdcA7pKaijqnXu6L9/kXJPksB2Ms9yGCnVj/BNG2qhKGfYmOoAM/MJwobZ50gUvVJwMxvdUfoIVtKJc0vX6JmG266vnDs2zC/E888ivioKrywcqzl3K4TVOBBnKdWlrrQ0u21XD7t+ZMm/3uhJqhcv1o8s0B8Sg23ALTklmaiy8c65lx4nj3MzVUQehJuO9SkG9BeF7ycLNEvS0ujtLyVW633z1fh+FlUG2drP3AB7S1XuPL4jRjKw== 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 MWHPR10CA0005.namprd10.prod.outlook.com (2603:10b6:301::15) by BL0PR12MB5539.namprd12.prod.outlook.com (2603:10b6:208:1c3::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Thu, 9 Dec 2021 03:28:16 +0000 X-Received: from CO1NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:301:0:cafe::a8) by MWHPR10CA0005.outlook.office365.com (2603:10b6:301::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:16 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84540+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT014.mail.protection.outlook.com (10.13.175.99) 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:28:16 +0000 X-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:28:14 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 01/32] OvmfPkg/SecMain: move SEV specific routines in AmdSev.c Date: Wed, 8 Dec 2021 21:27:29 -0600 Message-ID: <20211209032800.3802995-2-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 10674c3a-2fd6-4b1d-e51a-08d9bac3f06a X-MS-TrafficTypeDiagnostic: BL0PR12MB5539:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: rx7TWvjrUCGVqdAHBlLBzKj4cPyVEX0A/K85QLh22g9KiHu2Wt3Qe6gag7PYdPl652vYF+JmBaLxBqbLHYpB/ftlbG1TTvJ6uAHlg5fMO/AjcIe2ulJ9UvP695mH3yeq/MdAePu4UnlQkrwiurNSm1wWBw6XL2xTRliNM4CRYGl+yUkL27vY8EVvJTvrJQV9NGugssBCuanlqilBQLza5WreNYn6pvMLN2Z0ar3c99NQg0oxEXIS5G/q0ZFbhPcmHggPGK6c0KZgDMlMhHen6sPguPu4wAJL7I1nirSj4HoswwANvJBoNmWZEJMmnaPZpq3wnuIWB/Q4wRLMMXrP3v2UuHD7e/EjaLs30R6NIxQP+j1pD4UO+kA4hCeiD/Nomeh8k+RDCGHT9nt7McYcNRMs1XCL4N+wL2oAIz+HxzG6JVTX6LZciKB9Y6CZx/W/205fDJeEmX/CC5yfH9cYJ8n9d39nxPUDAJT2p1iKU++8IeGM84YZFDm5ksla80p3pv3YwvHFgAtXXi1XZCGF+SUf1Anv/N9Mf0I8lP/+3115BW+9Vn+qCAJbmcXT+lLUA1VXqTVCctHwsQol3Zh1yptQfOG+A2FopO0R+2tZiq72TNPPde+z1hl2YY8hkGr+XCvxZZsqUOYz2ujXhbkBm3WLMasGfajeNGLfX7KfpeD5NrsoyX5tCSXJMscPS9KpWH5bsF5s/+J2KBoQMILcLE4Z1eyrQ7TdUiDe2h75JaQwnpnEyf30fVrAminDF2FNyh2mMXenL1tm/hsyeefYdRRMntoAzmQM0zC5673shtTUUqqlQ4xDbDd/0xToBmYNpUT5b/wG+82GUvP2DrpbGka/biKasKsvw4OGgDo7UDzpudNGufTRaK3TjqoqNBz6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:16.2999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10674c3a-2fd6-4b1d-e51a-08d9bac3f06a 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: CO1NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5539 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: zejo14QYFqzLIYc8AKOIx2r8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020499; bh=+CKRlDhr5dTT2ML3YTfGQR25NAWBYfF6eDFl7Bl42h8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=T1ta72p9hW5k2jphncfdQEBrwZJr0g3zHl1xH+dHqJIYnlt5kOZVODxWiRICgfcyEpO cVVKpibe/DTrQalRm74l8/d2BU/TOrrGDSimLHnDLSGG0IOiSvBRc7DDFktx9Q57Sfb+0 5xOF8k8dEpfoXry2f2ObSogfqqCV551DIMc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020501825100003 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Move all the SEV specific function in AmdSev.c. No functional change intended. Cc: Michael Roth 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: Jiewen Yao Signed-off-by: Brijesh Singh --- OvmfPkg/Sec/SecMain.inf | 2 + OvmfPkg/Sec/AmdSev.h | 71 +++++++++++++++++ OvmfPkg/Sec/AmdSev.c | 164 ++++++++++++++++++++++++++++++++++++++++ OvmfPkg/Sec/SecMain.c | 156 +------------------------------------- 4 files changed, 239 insertions(+), 154 deletions(-) create mode 100644 OvmfPkg/Sec/AmdSev.h create mode 100644 OvmfPkg/Sec/AmdSev.c diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index ea4b9611f52d..41dcdba1209a 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -23,6 +23,8 @@ [Defines] =20 [Sources] SecMain.c + AmdSev.c + AmdSev.h =20 [Sources.IA32] Ia32/SecEntry.nasm diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/AmdSev.h new file mode 100644 index 000000000000..c0b1ca96183d --- /dev/null +++ b/OvmfPkg/Sec/AmdSev.h @@ -0,0 +1,71 @@ +/** @file + File defines the Sec routines for the AMD SEV + + Copyright (c) 2021, Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _AMD_SEV_SEC_INTERNAL_H__ +#define _AMD_SEV_SEC_INTERNAL_H__ + +/** + Handle an SEV-ES/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ); + +/** + Validate the SEV-ES/GHCB protocol level. + + Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor + and the guest intersect. If they don't intersect, request termination. + +**/ +VOID +SevEsProtocolCheck ( + VOID + ); + +/** + Determine if the SEV is active. + + During the early booting, GuestType is set in the work area. Verify that = it + is an SEV guest. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled + +**/ +BOOLEAN +IsSevGuest ( + VOID + ); + +/** + Determine if SEV-ES is active. + + During early booting, SEV-ES support code will set a flag to indicate th= at + SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES + is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled + +**/ +BOOLEAN +SevEsIsEnabled ( + VOID + ); + +#endif diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c new file mode 100644 index 000000000000..27fd24fc137e --- /dev/null +++ b/OvmfPkg/Sec/AmdSev.c @@ -0,0 +1,164 @@ +/** @file + File defines the Sec routines for the AMD SEV + + Copyright (c) 2021, Advanced Micro Devices, Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include "AmdSev.h" + +/** + Handle an SEV-ES/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D ReasonCode; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + Validate the SEV-ES/GHCB protocol level. + + Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor + and the guest intersect. If they don't intersect, request termination. + +**/ +VOID +SevEsProtocolCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + // + // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for + // protocol checking + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbInfo.Function =3D GHCB_INFO_SEV_INFO_GET; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + if (Msr.GhcbInfo.Function !=3D GHCB_INFO_SEV_INFO) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMa= x) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || + (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) + { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + // + // SEV-ES protocol checking succeeded, set the initial GHCB address + // + Msr.GhcbPhysicalAddress =3D FixedPcdGet32 (PcdOvmfSecGhcbBase); + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + Ghcb =3D Msr.Ghcb; + SetMem (Ghcb, sizeof (*Ghcb), 0); + + // + // Set the version to the maximum that can be supported + // + Ghcb->ProtocolVersion =3D MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_V= ERSION_MAX); + Ghcb->GhcbUsage =3D GHCB_STANDARD_USAGE; +} + +/** + Determine if the SEV is active. + + During the early booting, GuestType is set in the work area. Verify that = it + is an SEV guest. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled + +**/ +BOOLEAN +IsSevGuest ( + VOID + ) +{ + OVMF_WORK_AREA *WorkArea; + + // + // Ensure that the size of the Confidential Computing work area header + // is same as what is provided through a fixed PCD. + // + ASSERT ( + (UINTN)FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) =3D= =3D + sizeof (CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER) + ); + + WorkArea =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); + + return ((WorkArea !=3D NULL) && (WorkArea->Header.GuestType =3D=3D GUEST= _TYPE_AMD_SEV)); +} + +/** + Determine if SEV-ES is active. + + During early booting, SEV-ES support code will set a flag to indicate th= at + SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES + is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled + +**/ +BOOLEAN +SevEsIsEnabled ( + VOID + ) +{ + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + if (!IsSevGuest ()) { + return FALSE; + } + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *)FixedPcdGet32 (PcdSevEsWorkAre= aBase); + + return (SevEsWorkArea->SevEsEnabled !=3D 0); +} diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 6d81d5b62988..58e3b923b40e 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -26,12 +26,11 @@ #include #include #include -#include -#include -#include =20 #include =20 +#include "AmdSev.h" + #define SEC_IDT_ENTRY_COUNT 34 =20 typedef struct _SEC_IDT_TABLE { @@ -726,157 +725,6 @@ FindAndReportEntryPoints ( return; } =20 -/** - Handle an SEV-ES/GHCB protocol check failure. - - Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest - wishes to be terminated. - - @param[in] ReasonCode Reason code to provide to the hypervisor for the - termination request. - -**/ -STATIC -VOID -SevEsProtocolFailure ( - IN UINT8 ReasonCode - ) -{ - MSR_SEV_ES_GHCB_REGISTER Msr; - - // - // Use the GHCB MSR Protocol to request termination by the hypervisor - // - Msr.GhcbPhysicalAddress =3D 0; - Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; - Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; - Msr.GhcbTerminate.ReasonCode =3D ReasonCode; - AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); - - AsmVmgExit (); - - ASSERT (FALSE); - CpuDeadLoop (); -} - -/** - Validate the SEV-ES/GHCB protocol level. - - Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor - and the guest intersect. If they don't intersect, request termination. - -**/ -STATIC -VOID -SevEsProtocolCheck ( - VOID - ) -{ - MSR_SEV_ES_GHCB_REGISTER Msr; - GHCB *Ghcb; - - // - // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for - // protocol checking - // - Msr.GhcbPhysicalAddress =3D 0; - Msr.GhcbInfo.Function =3D GHCB_INFO_SEV_INFO_GET; - AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); - - AsmVmgExit (); - - Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); - - if (Msr.GhcbInfo.Function !=3D GHCB_INFO_SEV_INFO) { - SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); - } - - if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMa= x) { - SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); - } - - if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || - (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) - { - SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); - } - - // - // SEV-ES protocol checking succeeded, set the initial GHCB address - // - Msr.GhcbPhysicalAddress =3D FixedPcdGet32 (PcdOvmfSecGhcbBase); - AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); - - Ghcb =3D Msr.Ghcb; - SetMem (Ghcb, sizeof (*Ghcb), 0); - - // - // Set the version to the maximum that can be supported - // - Ghcb->ProtocolVersion =3D MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_V= ERSION_MAX); - Ghcb->GhcbUsage =3D GHCB_STANDARD_USAGE; -} - -/** - Determine if the SEV is active. - - During the early booting, GuestType is set in the work area. Verify that = it - is an SEV guest. - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled - -**/ -STATIC -BOOLEAN -IsSevGuest ( - VOID - ) -{ - OVMF_WORK_AREA *WorkArea; - - // - // Ensure that the size of the Confidential Computing work area header - // is same as what is provided through a fixed PCD. - // - ASSERT ( - (UINTN)FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) =3D= =3D - sizeof (CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER) - ); - - WorkArea =3D (OVMF_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase); - - return ((WorkArea !=3D NULL) && (WorkArea->Header.GuestType =3D=3D GUEST= _TYPE_AMD_SEV)); -} - -/** - Determine if SEV-ES is active. - - During early booting, SEV-ES support code will set a flag to indicate th= at - SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES - is enabled. - - @retval TRUE SEV-ES is enabled - @retval FALSE SEV-ES is not enabled - -**/ -STATIC -BOOLEAN -SevEsIsEnabled ( - VOID - ) -{ - SEC_SEV_ES_WORK_AREA *SevEsWorkArea; - - if (!IsSevGuest ()) { - return FALSE; - } - - SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *)FixedPcdGet32 (PcdSevEsWorkAre= aBase); - - return (SevEsWorkArea->SevEsEnabled !=3D 0); -} - VOID EFIAPI SecCoreStartupWithStack ( --=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 (#84540): https://edk2.groups.io/g/devel/message/84540 Mute This Topic: https://groups.io/mt/87605518/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 Sat May 4 15:08:10 2024 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+84541+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16390205020989.812524586890959; Wed, 8 Dec 2021 19:28:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id hk8wYY1788612xglhxYeMwaQ; Wed, 08 Dec 2021 19:28:21 -0800 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.67]) by mx.groups.io with SMTP id smtpd.web08.6782.1639020500647011423 for ; Wed, 08 Dec 2021 19:28:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SQtsM3kff9FjdB4b0od5aGwM67RqWPA7lAumztLu7577ZXHyUHB62BkACSwheDreJu/7ly3xI443F0XCT0gUTtZ1uTBLRoybl57EB+SveMRo7UpW1sC33NNNVuZON8yslVVFO+cs9gBl18lKvR1xbI3/Htl8w+08iuYxPqiBaDmJdww7GfSZ2iW3S8GGAJNz/WFg42opCdJ2AGZYHgSXPx7jjk+rweGwZEfHNCascZ7NkSqGziTSmvIhwv6Ua/U8uF1pgl7QJk50lXuvQe7kOAVgL9dJx4cFfg9m2DyZ4S+VDhtuLXeyZ5oTrCJQPkALj6MWQRjQR3FvPy4hAauD4g== 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=5WRam0oUg9nu9VoBR5sUlXmm2sfMIeCmXdE2foHSX0o=; b=icNB5swBpJ0THZDK8XtgeoEY7xm8RLWPcTSKZGKHhVScuA1C8B4lQLOosgXHfvd0mAz1RTY//9g1CuqvAhyGzXHB5vPlDZAjBJ+M6EMqSr7OXxi1viuoOhDHFOMbK3iL42PW9SGFQxcyKjibcwsfd2ozAOFhnXqbohWRlT+1n8+h2gEECnUyQ5FWfIi4e+J+SaozpRwfwgJPMEU/nnKM08Ovc0tGlZMqXPB9GqfpfLzHxjyO4ELMT+yGavfxzsljAWXQGqwd2vSVZXPZDsi5eERWfw07e448kLzd4q+7tzOT/DiexObqGMjpaPWdJZWiZGDWd4HSA6T95QsKCHl0mA== 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 MW4PR03CA0278.namprd03.prod.outlook.com (2603:10b6:303:b5::13) by DM4PR12MB5325.namprd12.prod.outlook.com (2603:10b6:5:39e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Thu, 9 Dec 2021 03:28:18 +0000 X-Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b5:cafe::6b) by MW4PR03CA0278.outlook.office365.com (2603:10b6:303:b5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:18 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84541+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) 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:28:18 +0000 X-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:28:15 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 02/32] UefiCpuPkg/MpInitLib: move SEV specific routines in AmdSev.c Date: Wed, 8 Dec 2021 21:27:30 -0600 Message-ID: <20211209032800.3802995-3-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c9acddc-26f8-4b81-899c-08d9bac3f18f X-MS-TrafficTypeDiagnostic: DM4PR12MB5325:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 8yf8liK12zcolLTt6RUM5+rDQJA1+l1erI1hKRKzw9tNo4RV++mcMaeSBiZ6gkIQ9nTwhQ4/IlePq2yOOJIMbP+n+sYBnNZUK4W6QOHF7qoL8WIBWqd9TQNwwDj8nHx/viCHmMpTijorhZfIYi1pPSRh0u+Q5YpulOuA/F/3PWjhpxHRvI6PCsqiBSqghhNUFwxAC10ni81WEVEYTsohieNCzWi+jVB5pcyNyRFiQyiKCYuV7Q8v9i2KYbs2vhxPJqVRXo62qGYUHg+X5vYyBTlcJndFdP/Vnwpf6rYi+yhE9mHnxtEPNH26Jb5szbMyrvBKx2OkoQ+a9Os/i2vQ3UHJt/Qcb3E2u2HxgiwnxOJC93sgRpAoFPxBz1bKNTa2l/95nFjzpuCah6zj3dUsBQyjuhLZgHyO87lvqJowFMq8Ft18qNrprEylJYTpUcie1ppmzVtIyI5jpSrPRyrn2d97Y8kfEsPSCr1SpU6I3lPKnB6tuejnAoQ3TX6V1NqFk6Loq6kjksECYDz8qhGy2xM43ww46Fg1RDm0g0Aq2aV0rAItBXTUjzQ9+9A2TAlolUXW3HOTzZOke5JPQh/PBLzmNdRhvZYOEBj6L1OBaD1dCHSk7M37Pav64E2L8fzResxxUCOkvxQdtb6nX4HG7ztP5yfAxM6hKGm5p3NfipHDVqzUwYZyifag1EbOrmFFu0nU1kXTbZlrmU1DzywFoFvmm0Zg2M7QHQW89JJikfK4tJIgUgVbryMMINIfejnSbt4YOFVuqlX/4iKVBDBuaHeBw8vhBh9oF+YWPXERFH5GeWZfJZTVbsbQUCnbqL6pTMJIOGSMldrDZ4NGpcVOTxx2tyxXDaRik/NhKUnsJ6utfaI36H9McgV+scWcjooF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:18.2178 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c9acddc-26f8-4b81-899c-08d9bac3f18f 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: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5325 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: 477pohFTCWzTklBzkL3XUO5Ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020501; bh=UqYdE1yTBViEWGIhVqPJumTuHY8b0jn/ZX8z8Er91Dw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=IncP+Pj+N1KH5w/U7U5BEgw0md7JztHhDfW7TeFMRJKkBi/8/TiiMVTUxAMG0ai+32u qCgPtPivmuGgB/ZZZzvgOnsurY3uUSS9mWtcrLpchDgLj4hTVJ+yyN8UzT+nj/ymgP+ls PoBusiGdcKFtTau9oRRCsVhZeQG5qeC7wlQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020503986100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Move all the SEV specific function in AmdSev.c. No functional change intended. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Reviewed-by: Ray Ni Acked-by: Gerd Hoffmann Suggested-by: Jiewen Yao Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 37 ++- UefiCpuPkg/Library/MpInitLib/AmdSev.c | 245 ++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 224 +--------------- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 119 +++++++++ UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 100 ++----- 7 files changed, 421 insertions(+), 306 deletions(-) create mode 100644 UefiCpuPkg/Library/MpInitLib/AmdSev.c create mode 100644 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index d34419c2a524..6e510aa89120 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -28,6 +28,7 @@ [Sources.X64] X64/MpFuncs.nasm =20 [Sources.common] + AmdSev.c MpEqu.inc DxeMpLib.c MpLib.c diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 36fcb96b5852..2cbd9b8b8acc 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -28,6 +28,7 @@ [Sources.X64] X64/MpFuncs.nasm =20 [Sources.common] + AmdSev.c MpEqu.inc PeiMpLib.c MpLib.c diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a647772088d9..16b4d76d019b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -34,6 +34,9 @@ #include #include =20 +#include +#include + #include =20 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P') @@ -321,7 +324,7 @@ typedef struct { from long mode to real mode. **/ typedef -VOID + VOID (EFIAPI AP_RESET)( IN UINTN BufferStart, IN UINT16 Code16, @@ -346,7 +349,7 @@ extern EFI_GUID mCpuInitMpLibHobGuid; @param[in] PmCodeSegment Protected mode code segment value. **/ typedef -VOID + VOID (EFIAPI *ASM_RELOCATE_AP_LOOP)( IN BOOLEAN MwaitSupport, IN UINTN ApTargetCState, @@ -740,4 +743,34 @@ PlatformShadowMicrocode ( IN OUT CPU_MP_DATA *CpuMpData ); =20 +/** + Allocate the SEV-ES AP jump table buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateSevEsAPMemory ( + IN OUT CPU_MP_DATA *CpuMpData + ); + +/** + Program the SEV-ES AP jump table buffer. + + @param[in] SipiVector The SIPI vector used for the AP Reset +**/ +VOID +SetSevEsJumpTable ( + IN UINTN SipiVector + ); + +/** + The function puts the AP in halt loop. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +SevEsPlaceApHlt ( + CPU_MP_DATA *CpuMpData + ); + #endif diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c new file mode 100644 index 000000000000..0e3c6e231077 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -0,0 +1,245 @@ +/** @file + CPU MP Initialize helper function for AMD SEV. + + Copyright (c) 2021, AMD Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include + +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16)-1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if ((GdtEntry->Bits.L =3D=3D 0) && + (GdtEntry->Bits.DB =3D=3D 0) && + (GdtEntry->Bits.Type > 8)) + { + break; + } + + GdtEntry++; + } + + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Get Protected mode code segment with 32-bit default addressing + from current GDT table. + + @return Protected mode 32-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode32CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16)-1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if ((GdtEntry->Bits.L =3D=3D 0) && + (GdtEntry->Bits.DB =3D=3D 1) && + (GdtEntry->Bits.Type > 8)) + { + break; + } + + GdtEntry++; + } + + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Reset an AP when in SEV-ES mode. + + If successful, this function never returns. + + @param[in] Ghcb Pointer to the GHCB + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +VOID +MpInitLibSevEsAPReset ( + IN GHCB *Ghcb, + IN CPU_MP_DATA *CpuMpData + ) +{ + EFI_STATUS Status; + UINTN ProcessorNumber; + UINT16 Code16, Code32; + AP_RESET *APResetFn; + UINTN BufferStart; + UINTN StackStart; + + Status =3D GetProcessorNumber (CpuMpData, &ProcessorNumber); + ASSERT_EFI_ERROR (Status); + + Code16 =3D GetProtectedMode16CS (); + Code32 =3D GetProtectedMode32CS (); + + if (CpuMpData->WakeupBufferHigh !=3D 0) { + APResetFn =3D (AP_RESET *)(CpuMpData->WakeupBufferHigh + CpuMpData->Ad= dressMap.SwitchToRealNoNxOffset); + } else { + APResetFn =3D (AP_RESET *)(CpuMpData->MpCpuExchangeInfo->BufferStart += CpuMpData->AddressMap.SwitchToRealOffset); + } + + BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; + StackStart =3D CpuMpData->SevEsAPResetStackStart - + (AP_RESET_STACK_SIZE * ProcessorNumber); + + // + // This call never returns. + // + APResetFn (BufferStart, Code16, Code32, StackStart); +} + +/** + Allocate the SEV-ES AP jump table buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateSevEsAPMemory ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + if (CpuMpData->SevEsAPBuffer =3D=3D (UINTN)-1) { + CpuMpData->SevEsAPBuffer =3D + CpuMpData->SevEsIsEnabled ? GetSevEsAPMemory () : 0; + } +} + +/** + Program the SEV-ES AP jump table buffer. + + @param[in] SipiVector The SIPI vector used for the AP Reset +**/ +VOID +SetSevEsJumpTable ( + IN UINTN SipiVector + ) +{ + SEV_ES_AP_JMP_FAR *JmpFar; + UINT32 Offset, InsnByte; + UINT8 LoNib, HiNib; + + JmpFar =3D (SEV_ES_AP_JMP_FAR *)(UINTN)FixedPcdGet32 (PcdSevEsWorkAreaBa= se); + ASSERT (JmpFar !=3D NULL); + + // + // Obtain the address of the Segment/Rip location in the workarea. + // This will be set to a value derived from the SIPI vector and will + // be the memory address used for the far jump below. + // + Offset =3D FixedPcdGet32 (PcdSevEsWorkAreaBase); + Offset +=3D sizeof (JmpFar->InsnBuffer); + LoNib =3D (UINT8)Offset; + HiNib =3D (UINT8)(Offset >> 8); + + // + // Program the workarea (which is the initial AP boot address) with + // far jump to the SIPI vector (where XX and YY represent the + // address of where the SIPI vector is stored. + // + // JMP FAR [CS:XXYY] =3D> 2E FF 2E YY XX + // + InsnByte =3D 0; + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // CS override prefix + JmpFar->InsnBuffer[InsnByte++] =3D 0xFF; // JMP (FAR) + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // ModRM (JMP memory location) + JmpFar->InsnBuffer[InsnByte++] =3D LoNib; // YY offset ... + JmpFar->InsnBuffer[InsnByte++] =3D HiNib; // XX offset ... + + // + // Program the Segment/Rip based on the SIPI vector (always at least + // 16-byte aligned, so Rip is set to 0). + // + JmpFar->Rip =3D 0; + JmpFar->Segment =3D (UINT16)(SipiVector >> 4); +} + +/** + The function puts the AP in halt loop. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +SevEsPlaceApHlt ( + CPU_MP_DATA *CpuMpData + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + UINT64 Status; + BOOLEAN DoDecrement; + BOOLEAN InterruptState; + + DoDecrement =3D (BOOLEAN)(CpuMpData->InitFlag =3D=3D ApInitConfig); + + while (TRUE) { + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb, &InterruptState); + + if (DoDecrement) { + DoDecrement =3D FALSE; + + // + // Perform the delayed decrement just before issuing the first + // VMGEXIT with AP_RESET_HOLD. + // + InterlockedDecrement ((UINT32 *)&CpuMpData->MpCpuExchangeInfo->NumAp= sExecuting); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_AP_RESET_HOLD, 0, 0); + if ((Status =3D=3D 0) && (Ghcb->SaveArea.SwExitInfo2 !=3D 0)) { + VmgDone (Ghcb, InterruptState); + break; + } + + VmgDone (Ghcb, InterruptState); + } + + // + // Awakened in a new phase? Use the new CpuMpData + // + if (CpuMpData->NewCpuMpData !=3D NULL) { + CpuMpData =3D CpuMpData->NewCpuMpData; + } + + MpInitLibSevEsAPReset (Ghcb, CpuMpData); +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 2d8e9512ab98..34555c069331 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -599,123 +599,6 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 -/** - Get Protected mode code segment with 16-bit default addressing - from current GDT table. - - @return Protected mode 16-bit code segment value. -**/ -STATIC -UINT16 -GetProtectedMode16CS ( - VOID - ) -{ - IA32_DESCRIPTOR GdtrDesc; - IA32_SEGMENT_DESCRIPTOR *GdtEntry; - UINTN GdtEntryCount; - UINT16 Index; - - Index =3D (UINT16)-1; - AsmReadGdtr (&GdtrDesc); - GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); - GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base; - for (Index =3D 0; Index < GdtEntryCount; Index++) { - if ((GdtEntry->Bits.L =3D=3D 0) && - (GdtEntry->Bits.DB =3D=3D 0) && - (GdtEntry->Bits.Type > 8)) - { - break; - } - - GdtEntry++; - } - - ASSERT (Index !=3D GdtEntryCount); - return Index * 8; -} - -/** - Get Protected mode code segment with 32-bit default addressing - from current GDT table. - - @return Protected mode 32-bit code segment value. -**/ -STATIC -UINT16 -GetProtectedMode32CS ( - VOID - ) -{ - IA32_DESCRIPTOR GdtrDesc; - IA32_SEGMENT_DESCRIPTOR *GdtEntry; - UINTN GdtEntryCount; - UINT16 Index; - - Index =3D (UINT16)-1; - AsmReadGdtr (&GdtrDesc); - GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); - GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *)GdtrDesc.Base; - for (Index =3D 0; Index < GdtEntryCount; Index++) { - if ((GdtEntry->Bits.L =3D=3D 0) && - (GdtEntry->Bits.DB =3D=3D 1) && - (GdtEntry->Bits.Type > 8)) - { - break; - } - - GdtEntry++; - } - - ASSERT (Index !=3D GdtEntryCount); - return Index * 8; -} - -/** - Reset an AP when in SEV-ES mode. - - If successful, this function never returns. - - @param[in] Ghcb Pointer to the GHCB - @param[in] CpuMpData Pointer to CPU MP Data - -**/ -STATIC -VOID -MpInitLibSevEsAPReset ( - IN GHCB *Ghcb, - IN CPU_MP_DATA *CpuMpData - ) -{ - EFI_STATUS Status; - UINTN ProcessorNumber; - UINT16 Code16, Code32; - AP_RESET *APResetFn; - UINTN BufferStart; - UINTN StackStart; - - Status =3D GetProcessorNumber (CpuMpData, &ProcessorNumber); - ASSERT_EFI_ERROR (Status); - - Code16 =3D GetProtectedMode16CS (); - Code32 =3D GetProtectedMode32CS (); - - if (CpuMpData->WakeupBufferHigh !=3D 0) { - APResetFn =3D (AP_RESET *)(CpuMpData->WakeupBufferHigh + CpuMpData->Ad= dressMap.SwitchToRealNoNxOffset); - } else { - APResetFn =3D (AP_RESET *)(CpuMpData->MpCpuExchangeInfo->BufferStart += CpuMpData->AddressMap.SwitchToRealOffset); - } - - BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; - StackStart =3D CpuMpData->SevEsAPResetStackStart - - (AP_RESET_STACK_SIZE * ProcessorNumber); - - // - // This call never returns. - // - APResetFn (BufferStart, Code16, Code32, StackStart); -} - /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -895,47 +778,7 @@ ApWakeupFunction ( while (TRUE) { DisableInterrupts (); if (CpuMpData->SevEsIsEnabled) { - MSR_SEV_ES_GHCB_REGISTER Msr; - GHCB *Ghcb; - UINT64 Status; - BOOLEAN DoDecrement; - BOOLEAN InterruptState; - - DoDecrement =3D (BOOLEAN)(CpuMpData->InitFlag =3D=3D ApInitConfi= g); - - while (TRUE) { - Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); - Ghcb =3D Msr.Ghcb; - - VmgInit (Ghcb, &InterruptState); - - if (DoDecrement) { - DoDecrement =3D FALSE; - - // - // Perform the delayed decrement just before issuing the fir= st - // VMGEXIT with AP_RESET_HOLD. - // - InterlockedDecrement ((UINT32 *)&CpuMpData->MpCpuExchangeInf= o->NumApsExecuting); - } - - Status =3D VmgExit (Ghcb, SVM_EXIT_AP_RESET_HOLD, 0, 0); - if ((Status =3D=3D 0) && (Ghcb->SaveArea.SwExitInfo2 !=3D 0)) { - VmgDone (Ghcb, InterruptState); - break; - } - - VmgDone (Ghcb, InterruptState); - } - - // - // Awakened in a new phase? Use the new CpuMpData - // - if (CpuMpData->NewCpuMpData !=3D NULL) { - CpuMpData =3D CpuMpData->NewCpuMpData; - } - - MpInitLibSevEsAPReset (Ghcb, CpuMpData); + SevEsPlaceApHlt (CpuMpData); } else { CpuSleep (); } @@ -1268,71 +1111,6 @@ FreeResetVector ( } } =20 -/** - Allocate the SEV-ES AP jump table buffer. - - @param[in, out] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -AllocateSevEsAPMemory ( - IN OUT CPU_MP_DATA *CpuMpData - ) -{ - if (CpuMpData->SevEsAPBuffer =3D=3D (UINTN)-1) { - CpuMpData->SevEsAPBuffer =3D - CpuMpData->SevEsIsEnabled ? GetSevEsAPMemory () : 0; - } -} - -/** - Program the SEV-ES AP jump table buffer. - - @param[in] SipiVector The SIPI vector used for the AP Reset -**/ -VOID -SetSevEsJumpTable ( - IN UINTN SipiVector - ) -{ - SEV_ES_AP_JMP_FAR *JmpFar; - UINT32 Offset, InsnByte; - UINT8 LoNib, HiNib; - - JmpFar =3D (SEV_ES_AP_JMP_FAR *)(UINTN)FixedPcdGet32 (PcdSevEsWorkAreaBa= se); - ASSERT (JmpFar !=3D NULL); - - // - // Obtain the address of the Segment/Rip location in the workarea. - // This will be set to a value derived from the SIPI vector and will - // be the memory address used for the far jump below. - // - Offset =3D FixedPcdGet32 (PcdSevEsWorkAreaBase); - Offset +=3D sizeof (JmpFar->InsnBuffer); - LoNib =3D (UINT8)Offset; - HiNib =3D (UINT8)(Offset >> 8); - - // - // Program the workarea (which is the initial AP boot address) with - // far jump to the SIPI vector (where XX and YY represent the - // address of where the SIPI vector is stored. - // - // JMP FAR [CS:XXYY] =3D> 2E FF 2E YY XX - // - InsnByte =3D 0; - JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // CS override prefix - JmpFar->InsnBuffer[InsnByte++] =3D 0xFF; // JMP (FAR) - JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // ModRM (JMP memory location) - JmpFar->InsnBuffer[InsnByte++] =3D LoNib; // YY offset ... - JmpFar->InsnBuffer[InsnByte++] =3D HiNib; // XX offset ... - - // - // Program the Segment/Rip based on the SIPI vector (always at least - // 16-byte aligned, so Rip is set to 0). - // - JmpFar->Rip =3D 0; - JmpFar->Segment =3D (UINT16)(SipiVector >> 4); -} - /** This function will be called by BSP to wakeup AP. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Libr= ary/MpInitLib/X64/AmdSev.nasm new file mode 100644 index 000000000000..0ccafe25eca4 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -0,0 +1,119 @@ +;-------------------------------------------------------------------------= ----- ; +; Copyright (c) 2021, AMD Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; AmdSev.nasm +; +; Abstract: +; +; This provides helper used by the MpFunc.nasm. If AMD SEV-ES is active +; then helpers perform the additional setups (such as GHCB). +; +;-------------------------------------------------------------------------= ------ + +%define SIZE_4KB 0x1000 + +; +; The function checks whether SEV-ES is enabled, if enabled +; then setup the GHCB page. +; +SevEsSetupGhcb: + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)] + cmp byte [edi], 1 ; SevEsIsEnabled + jne SevEsSetupGhcbExit + + ; + ; program GHCB + ; Each page after the GHCB is a per-CPU page, so the calculation pro= grams + ; a GHCB to be every 8KB. + ; + mov eax, SIZE_4KB + shl eax, 1 ; EAX =3D SIZE_4K * 2 + mov ecx, ebx + mul ecx ; EAX =3D SIZE_4K * 2 * C= puNumber + mov edi, esi + add edi, MP_CPU_EXCHANGE_INFO_FIELD (GhcbBase) + add rax, qword [edi] + mov rdx, rax + shr rdx, 32 + mov rcx, 0xc0010130 + wrmsr + +SevEsSetupGhcbExit: + OneTimeCallRet SevEsSetupGhcb + +; +; The function checks whether SEV-ES is enabled, if enabled, use +; the GHCB +; +SevEsGetApicId: + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)] + cmp byte [edi], 1 ; SevEsIsEnabled + jne SevEsGetApicIdExit + + ; + ; Since we don't have a stack yet, we can't take a #VC + ; exception. Use the GHCB protocol to perform the CPUID + ; calls. + ; + mov rcx, 0xc0010130 + rdmsr + shl rdx, 32 + or rax, rdx + mov rdi, rax ; RDI now holds the original GHCB GPA + + mov rdx, 0 ; CPUID function 0 + mov rax, 0 ; RAX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + cmp edx, 0bh + jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + test edx, 0ffffh + jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 0c0000000h ; RDX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + + ; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX + jmp RestoreGhcb + +NoX2ApicSevEs: + ; Processor is not x2APIC capable, so get 8-bit APIC ID + mov rdx, 1 ; CPUID function 1 + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + shr edx, 24 + +RestoreGhcb: + mov rbx, rdx ; Save x2APIC/APIC ID + + mov rdx, rdi ; RDI holds the saved GHCB GPA + shr rdx, 32 + mov eax, edi + wrmsr + + mov rdx, rbx + + ; x2APIC ID or APIC ID is in EDX + jmp GetProcessorNumber + +SevEsGetApicIdExit: + OneTimeCallRet SevEsGetApicId diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 50df802d1fca..f7f2937fafad 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -15,6 +15,15 @@ %include "MpEqu.inc" extern ASM_PFX(InitializeFloatingPointUnits) =20 +%macro OneTimeCall 1 + jmp %1 +%1 %+ OneTimerCallReturn: +%endmacro + +%macro OneTimeCallRet 1 + jmp %1 %+ OneTimerCallReturn +%endmacro + DEFAULT REL =20 SECTION .text @@ -144,6 +153,12 @@ SkipEnable5LevelPaging: jmp far [edi] =20 BITS 64 + +; +; Required for the AMD SEV helper functions +; +%include "AmdSev.nasm" + LongModeStart: mov esi, ebx lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)] @@ -175,94 +190,17 @@ LongModeStart: add rax, qword [edi] mov rsp, rax =20 - lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)] - cmp byte [edi], 1 ; SevEsIsEnabled - jne CProcedureInvoke - ; - ; program GHCB - ; Each page after the GHCB is a per-CPU page, so the calculation pro= grams - ; a GHCB to be every 8KB. + ; Setup the GHCB when AMD SEV-ES active. ; - mov eax, SIZE_4KB - shl eax, 1 ; EAX =3D SIZE_4K * 2 - mov ecx, ebx - mul ecx ; EAX =3D SIZE_4K * 2 * C= puNumber - mov edi, esi - add edi, MP_CPU_EXCHANGE_INFO_FIELD (GhcbBase) - add rax, qword [edi] - mov rdx, rax - shr rdx, 32 - mov rcx, 0xc0010130 - wrmsr + OneTimeCall SevEsSetupGhcb jmp CProcedureInvoke =20 GetApicId: - lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevEsIsEnabled)] - cmp byte [edi], 1 ; SevEsIsEnabled - jne DoCpuid - ; - ; Since we don't have a stack yet, we can't take a #VC - ; exception. Use the GHCB protocol to perform the CPUID - ; calls. + ; Use the GHCB protocol to get the ApicId when SEV-ES is active. ; - mov rcx, 0xc0010130 - rdmsr - shl rdx, 32 - or rax, rdx - mov rdi, rax ; RDI now holds the original GHCB GPA - - mov rdx, 0 ; CPUID function 0 - mov rax, 0 ; RAX register requested - or rax, 4 - wrmsr - rep vmmcall - rdmsr - cmp edx, 0bh - jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOP= OLOGY - - mov rdx, 0bh ; CPUID function 0x0b - mov rax, 040000000h ; RBX register requested - or rax, 4 - wrmsr - rep vmmcall - rdmsr - test edx, 0ffffh - jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero - - mov rdx, 0bh ; CPUID function 0x0b - mov rax, 0c0000000h ; RDX register requested - or rax, 4 - wrmsr - rep vmmcall - rdmsr - - ; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX - jmp RestoreGhcb - -NoX2ApicSevEs: - ; Processor is not x2APIC capable, so get 8-bit APIC ID - mov rdx, 1 ; CPUID function 1 - mov rax, 040000000h ; RBX register requested - or rax, 4 - wrmsr - rep vmmcall - rdmsr - shr edx, 24 - -RestoreGhcb: - mov rbx, rdx ; Save x2APIC/APIC ID - - mov rdx, rdi ; RDI holds the saved GHCB GPA - shr rdx, 32 - mov eax, edi - wrmsr - - mov rdx, rbx - - ; x2APIC ID or APIC ID is in EDX - jmp GetProcessorNumber + OneTimeCall SevEsGetApicId =20 DoCpuid: mov eax, 0 --=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 (#84541): https://edk2.groups.io/g/devel/message/84541 Mute This Topic: https://groups.io/mt/87605520/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 Sat May 4 15:08:10 2024 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+84542+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020503546654.2963335786252; Wed, 8 Dec 2021 19:28:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lXgIYY1788612xovwNjSXOVU; Wed, 08 Dec 2021 19:28:23 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.75]) by mx.groups.io with SMTP id smtpd.web09.6935.1639020502269583467 for ; Wed, 08 Dec 2021 19:28:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PTP0ohq++rperhZYSVn45aZ77N+5xxd/tdKwPajZsayqjlWqw/XsHlEBgfrHsZWzCWzI9zwjazpjyTXiSb2wFBUsod2QBkWL1aNXf/Oah/2uOZH0iRtWD4bcAFAYVeE1pY/hhVCfujIyYq0lhyHcATViKrPn26d6Dnilbdd6umACdSeYFYxTcqLmxe/czVcGUavD5DIjp+Ah39px7RocJa4D8yrHL2f1xp6aydLlT/hI9/k15Hs4mn1xuAzOph5B6kJko+6KFoBBitPM+xxQ6iKKbsS0HqGRa43rHk/09KnMNLBnkwUjVQyB8SdaCdBsAym9YAtzH0o3ZyfjiaJuZQ== 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=PVwHdPTH7w71+i9gvRPLqc4BcSc326Bp+P8UvVM6v3c=; b=TYgHWbRkKKXZhyvMg/N7RJVrb01IkiSoDM6RobmtU0+fRUQ0ewPl16VoGSR3zCAyDtqTtqstCefK+AEVR/xKJ+T3ARFT/YaQ8htsTZJ+C3+IgKJKGLkwi/x/5b/rZfJB5royBNCDNgmZY/Nit/PSM+1URqp81t1cir3dMjSzrDmET72yrRGLDRwGMRs8AEn+WToJpAJxrkLbtyLGW6DjRFjc5cIfnVHJRKoRxmA+viE3sJpwfBKFPbga3dZkAEDGcx7no8MJ/rzs0VrcVJDiwHciIZYvpkggceuQ/JQT0yDy6m/WQIHfPqAM+zLKF26njmCJVfo3boeo2MyQOjyxWA== 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 MWHPR22CA0046.namprd22.prod.outlook.com (2603:10b6:300:69::32) by CH2PR12MB3735.namprd12.prod.outlook.com (2603:10b6:610:25::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:20 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:300:69:cafe::17) by MWHPR22CA0046.outlook.office365.com (2603:10b6:300:69::32) 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:28:19 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84542+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) 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:28:19 +0000 X-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:28:17 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 03/32] OvmfPkg/ResetVector: move clearing GHCB in SecMain Date: Wed, 8 Dec 2021 21:27:31 -0600 Message-ID: <20211209032800.3802995-4-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 764afdfb-0b99-48b6-0543-08d9bac3f267 X-MS-TrafficTypeDiagnostic: CH2PR12MB3735:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: bDleo+TUopcMJhy9qvpn66TgtplPFrlFLyQJsmSrt68/lsaWwFfhFRFJ0yh7I+6AwzqAFRoQsfAtQiaUVVw6f1v8nGCW0mZnCtDDfX830WzsDyAroZkWPW3WeuV8KIK45tNUtsNPxMQcTnbfEHl05oDYV6TcIyRD7c86zyv/9Ki7aQpCHXhW2tconPjfqMFcSWuQNdY91g5yLjjn5lsYF7qysm/HmD6A8wcuNsQeBY3FJ+dQLBTp8Vt3hvwFD+67NlXBxeIW639wk5kWImpOnGXJWUCu4QoR43zkkzPknzwFJxQ9eR7eRB6rfE+1vYcZDzAmshI5zeRqoPdx/9KCkKJY3OxYmJSTA9ModWJ6zyMrs2YI8YPmmKp41KyWw7Uc2zVHG+1oJtahAq6UbQIC9cvnwiBvKD4dVjf+U17nk5223Ue4/mnrgCj3CTnInY8m1ISsTdHbxQwZF/wHGKiHd5jaqbfnDuKRoe14htHC3RQmHuqDXdrCVeVjph8bAx0DGj4k5UwVlAGt7cBL3fW3asQJhdEZChUS9uqooSQXGCQJtW+OLqzwuWCGUka5KzlDknBQdaYdPNvT7GElXsnArYeUhNHbGPCIpb584CFDmSXYwsSXMUQgBE012VF0huQGl4buRG5Hvw0wSelnt8s7OW3yT6Qy6/238EFyZpwKpboFbfmPIoD1pFvSYIGDi87sEQzacc7EOGAUTVEsK5qN8rMaGJYUsm3B9LN/9Fmr/BsEq7Q2SpRe9LxnZ7qiQycESmA71bmQL12R05zbwWD/8kO5u18aF0QX46vn7qQKJTbSsj+nZ3tpwAOpX3AuBCIOKjs6Bb94Ok2RoOFiJ5GRBxfKjc6mfAYzWly2O7X44LYfCiWxhpMXDFX2IaVsf9Tv X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:19.6300 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 764afdfb-0b99-48b6-0543-08d9bac3f267 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3735 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: 4i4GyuNVZLj1di9hU8ky6Wwux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020503; bh=l+mXnf3tgnl8hsEcWwwu595ivH6ZfeOOUm45IsqLPV8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jd9JGwlDZKUDj40KOUnjwry2D7p+lmRcW0fWW0rZDpOsaaBMy/wQzyO9inUb7anh1sh +U1cq67yWF5xxFJkYtFkD+nzEWJ+9jzPCEEh9ovorjvgLXHxkbklA9Up4WKqe/H5GeYLu +KbLH8fxc6iGFP8m8blJwtKREhD5xRAdYAw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020504104100006 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 In preparation for SEV-SNP support move clearing of the GHCB memory from the ResetVector/AmdSev.asm to SecMain/AmdSev.c. The GHCB page is not accessed until SevEsProtocolCheck() switch to full GHCB. So, the move does not make any changes in the code flow or logic. The move will simplify the SEV-SNP support. Cc: Michael Roth 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 --- OvmfPkg/Sec/AmdSev.c | 2 +- OvmfPkg/ResetVector/Ia32/AmdSev.asm | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c index 27fd24fc137e..0828d090feaf 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -96,7 +96,7 @@ SevEsProtocolCheck ( AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); =20 Ghcb =3D Msr.Ghcb; - SetMem (Ghcb, sizeof (*Ghcb), 0); + SetMem (Ghcb, FixedPcdGet32 (PcdOvmfSecGhcbSize), 0); =20 // // Set the version to the maximum that can be supported diff --git a/OvmfPkg/ResetVector/Ia32/AmdSev.asm b/OvmfPkg/ResetVector/Ia32= /AmdSev.asm index 250ac8d8b180..48d9178168b0 100644 --- a/OvmfPkg/ResetVector/Ia32/AmdSev.asm +++ b/OvmfPkg/ResetVector/Ia32/AmdSev.asm @@ -177,12 +177,6 @@ pageTableEntries4kLoop: mov ecx, (GHCB_BASE & 0x1F_FFFF) >> 12 mov [ecx * 8 + GHCB_PT_ADDR + 4], strict dword 0 =20 - mov ecx, GHCB_SIZE / 4 - xor eax, eax -clearGhcbMemoryLoop: - mov dword[ecx * 4 + GHCB_BASE - 4], eax - loop clearGhcbMemoryLoop - SevClearPageEncMaskForGhcbPageExit: OneTimeCallRet SevClearPageEncMaskForGhcbPage =20 --=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 (#84542): https://edk2.groups.io/g/devel/message/84542 Mute This Topic: https://groups.io/mt/87605523/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 Sat May 4 15:08:10 2024 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+84543+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020505550990.2860512063046; Wed, 8 Dec 2021 19:28:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ollaYY1788612xvOoHR4XHYs; Wed, 08 Dec 2021 19:28:25 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.52]) by mx.groups.io with SMTP id smtpd.web12.6751.1639020503148542231 for ; Wed, 08 Dec 2021 19:28:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NE8PRzQDeHfb7Qs8PQ15GX7Axak0grnoiYvFKFxNVALo2divbelKNThpdpOAiHqoTq+QnjQpSbjt1sciBc39GTB9JXEDwKjIPFPcYb0uLHV1dXmifLawDqhHrjpPnTjCWzbXxMj/gNCipXVjQ/J9hk9kFFwFHKaKLp+mzdwBKvOAj6JwkqTq4zO0krfq+bkUHMSp/EXjmtnqwWPUF2cDDSrJZzA4ej6D/qySNi3+55iMnb4z3363okf23XH18egkkvjb3G46xRfwxsH7BdsAZbWMOZmb1SLZpF0ykn6KXzXkDZn1M5P6dySDHL1JBq0UWGQIr3hQzCAd+TUzJaQH9A== 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=eDKr64qQewFHb0w1u9Kwb1YhDCSZvqkWDhSh3lOC+30=; b=UWlM32WYqsTdaTZcqAGMH6KLTQIVLkVIR+ncDl4Rz7ihUPCS84jhNiK2REgukVJ+YgX+OuFK2DnZov0b+p3y3dGLo9v8NtEhfG/nua9DvNeAM1or6W1xOdy+lDFc7HBqxqeI8UQ9AWvmlA8Jag5a+Q4hWneQij8T79z3gme8njE+DqOdMW76G63h+IYF3meQkK2tYL3uc1TRyPFbQGBqqWs0GvWtb/fdX8PSIiod9d3McrqJhspkGuIZadAb2nHRnNA9WP4oSNv3jum8iqqFqsBGJ5seFiC7VWg9ZQxig8Z6PNOg9gfO5f++8Rkuh4sktwW+8iUG/KsJxL1RU03Kqw== 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 MWHPR22CA0039.namprd22.prod.outlook.com (2603:10b6:300:69::25) by BN8PR12MB3412.namprd12.prod.outlook.com (2603:10b6:408:65::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Thu, 9 Dec 2021 03:28:21 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:300:69:cafe::4b) by MWHPR22CA0039.outlook.office365.com (2603:10b6:300:69::25) 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:28:20 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84543+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) 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:28:20 +0000 X-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:28:18 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 04/32] OvmfPkg/ResetVector: introduce SEV metadata descriptor for VMM use Date: Wed, 8 Dec 2021 21:27:32 -0600 Message-ID: <20211209032800.3802995-5-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22b9e6e4-4e45-4ed3-601b-08d9bac3f2e5 X-MS-TrafficTypeDiagnostic: BN8PR12MB3412:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: O16wWOOiGCC+qAF3MejgT0JFPEa9nxF/HuYXCBhFg7Wc5iH+yuUuRJh1geDR9Kb9mhzjA9Cz/fSY+o0x++lI2CoRvMnCuzqMR3yggivRiiv1LyHXSALi2qUK8Lc9dU4xZUpA8ItOOlnLLmV8APa/qMSH/+VchDTFxG9u296KGGVT47HpoGLmc3WVVPoEFuWgFjqS8U6S3yYTLjCJMAHF7yA8as1Xoq5e9O4PdfGOF1pwypzvFuKsLjJcspoXh892m4poyR3ebhMUfzo4VLRHWiAruQ3Lq5oubZcujTyUrrRCjUiLebliqxMi2WsZ7/ZkBdlVTyQOiXCikgoTsx0PzseB/TV07d01bAA3cJHk+jiiWM/wyaeN5jtEhEQWM1vRO74ftv1XKGeTHHCZW52/rR5XEUeR7Vh1bwpFNDCrJzW+65N/mbRcBix80BDeX5Xjf+gz5h9TB/ElIGdlj7/YRB668goU3zglvxS1AUj26RU5G1A63WtEultFjABExz44fOEcex7jh5U1mAod4kJlUryVyiKkPR94T8h2L8ROfO+8eMiUihuiDl2GSdr8ulJaWcQBseQIEpWT1sAmnRPYvFx5vVVx8p7QUpmcYG+Jvr6oYWB4hI0azmsvL1wufThtoooagPBdJs9yW4dSt9lWRD90Xjwshzf7gg0/pcYvlDZZd24Qcvg7+3w0KZJLAeOxcVCvU/JExaKcg37ZZR8RySdbT6AMMpdaGCC85W5VLmclex4fDqci7Dsk7SIbtT+eDG9MlVDTnMlim+7fXflUj4wpqfkaHITxDCnipPn1Tym17Z9Afrl8p+2tS1lpj6tdDsEUgEi4OMnaseVAWIMHZTTCvolRYtVn0Hi7HwtKGemFgRTtI+zpiVyU60LH08vq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:20.4424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22b9e6e4-4e45-4ed3-601b-08d9bac3f2e5 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3412 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: bl8xT56QU83FIuHfAlXAPuJFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020505; bh=QTC4nYz9+bzo2RICFoaTlDOmbRaG5dX+bn1pW7UWu9I=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UR+721kNtzRs6lSHMwHMsK4N+L1apJ6a/ztDidmvF04au6takdTtrgs8YZik0NyoJtj hg0zeylEpW+Qfn/SZ5UBGyYy+zQvsEsjZR7EAI3/OLkvT0RTPXvhSHA3KWFxPQmtA1uyT FcF0dqjFgtydNoIDuMmcanMjni9oVCQa7S4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020506257100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The OvmfPkgX86 build reserves memory regions in MEMFD. The memory regions get accessed in the SEC phase. AMD SEV-SNP require that the guest's private memory be accepted or validated before access. Introduce a Guided metadata structure that describes the reserved memory regions. The VMM can locate the metadata structure by iterating through the reset vector guid and process the areas based on the platform specific requirements. Cc: Michael Roth 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 --- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 14 ++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 34 ++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm index dee2e3f9de31..12f2cedd6767 100644 --- a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -64,6 +64,20 @@ tdxMetadataOffsetStart: DB 0x86, 0x5e, 0x46, 0x85, 0xa7, 0xbf, 0x8e, 0xc2 tdxMetadataOffsetEnd: =20 +; +; SEV metadata descriptor +; +; Provide the start offset of the metadata blob within the OVMF binary. + +; GUID : dc886566-984a-4798-A75e-5585a7bf67cc +; +OvmfSevMetadataOffsetStart: + DD (fourGigabytes - OvmfSevMetadataGuid) + DW OvmfSevMetadataOffsetEnd - OvmfSevMetadataOffsetStart + DB 0x66, 0x65, 0x88, 0xdc, 0x4a, 0x98, 0x98, 0x47 + DB 0xA7, 0x5e, 0x55, 0x85, 0xa7, 0xbf, 0x67, 0xcc +OvmfSevMetadataOffsetEnd: + %endif =20 ; SEV Hash Table Block diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 87effedb9c60..d847794feadb 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -109,6 +109,7 @@ %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.asm" %include "Ia32/IntelTdx.asm" +%include "X64/OvmfSevMetadata.asm" %endif =20 %include "Ia16/Real16ToFlat32.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm new file mode 100644 index 000000000000..9d8c3e8194a4 --- /dev/null +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -0,0 +1,34 @@ +;-------------------------------------------------------------------------= ---- +; @file +; OVMF metadata for the AMD SEV confidential computing guests +; +; Copyright (c) 2021, AMD Inc. All rights reserved.
+; +; SPDX-License-Identifier: BSD-2-Clause-Patent +;-------------------------------------------------------------------------= ---- + +BITS 64 + +%define OVMF_SEV_METADATA_VERSION 1 + +; The section must be accepted or validated by the VMM before the boot +%define OVMF_SECTION_TYPE_SNP_SEC_MEM 0x1 + +ALIGN 16 + +TIMES (15 - ((OvmfSevGuidedStructureEnd - OvmfSevGuidedStructureStart + 15= ) % 16)) DB 0 + +OvmfSevGuidedStructureStart: +; +; OvmfSev metadata descriptor +; +OvmfSevMetadataGuid: + +_DescriptorSev: + DB 'A','S','E','V' ; Signature + DD OvmfSevGuidedStructureEnd - _DescriptorSev ; Length + DD OVMF_SEV_METADATA_VERSION ; Version + DD (OvmfSevGuidedStructureEnd - _DescriptorSev - 16) / 12 ; Number of se= ctions + +OvmfSevGuidedStructureEnd: + ALIGN 16 --=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 (#84543): https://edk2.groups.io/g/devel/message/84543 Mute This Topic: https://groups.io/mt/87605524/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 Sat May 4 15:08:10 2024 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+84544+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163902050641636.55250048107155; Wed, 8 Dec 2021 19:28:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id QHMWYY1788612xpnoGiV4iO5; Wed, 08 Dec 2021 19:28:25 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.81]) by mx.groups.io with SMTP id smtpd.web09.6937.1639020504976257205 for ; Wed, 08 Dec 2021 19:28:25 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KGl+Enht0jZwnyRY0UB5DyxmMBtNJXyuGn2XUOnCDl8IYFnQC8OmuYfOFilA/47yOjm+O1HEpaUREVX674pBCyraydFLoVoSf8yltMWlC02OcT7/gXVTP8A52WO0zpDqtDJnR4Jjznk7eese2Z2T68Ban3WGuQssNHhzJ8Tltkw6ENfSJE4hXE5YFmZCiQfDYwYaK+KsuNPfKVv8FXBOV8pvoaH0D8slFQURQcxVA3oJv476JvZwflVXAu5gyGwq1Fg3fvVdx8aKJBfdy0R0Jl/7KeRuEQpYkTyKj5kml7xlnkuGviNGy+PunhPkR5sj5zz6MZxDlX5MeGbMz+sm0w== 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=7x8G3Q31xoly7xt6GgeLMRuazWi9iHfeZzQI7xNLsN4=; b=bXN3ZqTic6YWb18W4SluzpAbvMzFAkUpj7xsHsTq4xLhTbgOVHey34FYcjmMejHQFQh1TC3MUpPbmvzcKERShi/ePQTTfutKuX/BE56EoZGwHMl2l9gX8HhM6UUP9bH8zVZwtuzF60nlkTmCmgDkAiOgPBTOaFg+jKKmGcCiGGXX6zVs4LJnSefN/wVeOH/ieHdOdtIaushZ3LHYLKWXoDSZLY0v2HZwbGIEIYcCUPnkHU/QwxrJbxa3j/+ZmkEJxfA9b/8mz2wwsPXjl5nddiJ54T6tDeLjmOEiyVUlthLSbID0AcB3I2ma4g/BLXNgoRgsRVfsAqTUiwsBo+pbkQ== 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 CO2PR04CA0136.namprd04.prod.outlook.com (2603:10b6:104::14) by BN9PR12MB5211.namprd12.prod.outlook.com (2603:10b6:408:11c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Thu, 9 Dec 2021 03:28:22 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:0:cafe::2c) by CO2PR04CA0136.outlook.office365.com (2603:10b6:104::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:28: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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84544+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=SATLEXMB03.amd.com; X-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:28:22 +0000 X-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:28:20 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 05/32] OvmfPkg: reserve SNP secrets page Date: Wed, 8 Dec 2021 21:27:33 -0600 Message-ID: <20211209032800.3802995-6-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15e88498-d351-4a04-88bb-08d9bac3f419 X-MS-TrafficTypeDiagnostic: BN9PR12MB5211:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: ZQ/fMwv1ewWr5Votzpfa8MWeifrO0mFUL0Q6bcMMBPHmJyZ1eiI6BuO9PQer3EgHsuWYn1kRYaD3pVQZaqrD/pvrd1SAB6iitWMzKm0XhS3pZ22ZXY+bft0AqJs+nEX3ybw4P1LuXxmjw1O62stsJvMayMosdnb4Fyc9mXlQ5UX42klAglrZVgYe2NPaZbvBlxEjuCMw0CMmMrpWEh+TA0JHw20BRk3+2c3Pz/6LdxNVgZWIDglxAnBuUlhZ30C253ibInBjUhrYu/Us8U4o+VmHHIOvinb29OBY1r7WLHqeM4BbQSNDBjB0XH1fjtWrjxRTQ8MzsGtYcCr3kkRluVznErRvGZR3c0RV5MNfKJCeL4eNKs2LzBGEFZeuETA8eVti0u41uxdc/dmXGRzvC1OGgD0Gd3OwaWt2druWKHcOEymPPKRE/mcJBuytnxrTW5a7pTZUG7UxvRyt8BjvijH8L2/wMFOU9Rg/pnC4aVo81LBMCRb1zEjOL1a90IXMwkIHvNjXGcBzvHBUXEhCtstpWa5OTcGwmL9rXOEg3zL67wqp1B74/9AhrFuVDbL1ktNzG3P4KUz3Y/El5dcWcKm9uuQ0uTOH2cmIull+Fr009y+FX+ZSCWb0HgW7hA/Buj30cvTTEPC4dD8P+u98OT0Y/ZOA6nPuYSLQAb4nM/KZ9DrunEKjEokv4mNNUBF80lQFJTFyXLkSmWrimxDr66rmtbSyeeD1HTUGO4GL04n28oKGaKnE3q60OhRK4BPRcia/TvBJrdB++QI/6yOtktt2v5gdf24ojOeuvduU7igcKXxCajCz2XUHInHTmKkcvHkFzUeQ48kZEEcYgI9mtxB6UtDy4BbrnMF45p4b+nrCXWOgOWSnSUGV1YjBuCzy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:22.4620 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15e88498-d351-4a04-88bb-08d9bac3f419 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: BN9PR12MB5211 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: oUQyYJu7rKt6CoVD8drT4eBox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020505; bh=yyK3ecBc7jmQBx9sf1AROa4BUFe6gtdnLcxGApKZBDA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=L9z0N4G7JxWUKf0qfsVQvsZQQUQZSv/kPRc9m0M0htWG0mxxdzpUasr3tDfiC1gO0BJ lkNQZH8xi/PHFkxovtrjKu5X1tV0puasNT1qUDG9w1nVkqaMS2Vcue+RHcVkU8dJx+92J uDA1cjs12S03gQzm3qDy4TI+nR6o8adzKlg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020508359100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 During the SNP guest launch sequence, a special secrets page needs to be inserted by the VMM. The PSP will populate the page; it will contain the VM Platform Communication Key (VMPCKs) used by the guest to send and receive secure messages to the PSP. The purpose of the secrets page in the SEV-SNP is different from the one used in SEV guests. In SEV, the secrets page contains the guest owner's private data after the remote attestation. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 3 +++ OvmfPkg/ResetVector/ResetVector.inf | 2 ++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++ OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 9 +++++++++ 5 files changed, 23 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 340d83f794d0..deb285fd62c5 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -350,6 +350,13 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdBfvRawDataOffset|0|UINT32|0x56 gUefiOvmfPkgTokenSpaceGuid.PcdBfvRawDataSize|0|UINT32|0x57 =20 + ## The base address and size of the SEV-SNP Secrets Area that contains + # the VM platform communication key used to send and recieve the + # messages to the PSP. If this is set in the .fdf, the platform + # is responsible to reserve this area from DXE phase overwrites. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|0|UINT32|0x58 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize|0|UINT32|0x59 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index b6cc3cabdd69..1313c7f016bf 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -88,6 +88,9 @@ [FD.MEMFD] 0x00C000|0x001000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecGhcbBackupSize =20 +0x00D000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|gUefiOvmfPkgTokenSpaceGui= d.PcdOvmfSnpSecretsSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 320e5f2c6527..fcbc25d0ce3d 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -59,3 +59,5 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index d847794feadb..4e685ef23684 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -103,6 +103,8 @@ %define SEV_ES_WORK_AREA_RDRAND (FixedPcdGet32 (PcdSevEsWorkAreaBase) + = 8) %define SEV_ES_WORK_AREA_ENC_MASK (FixedPcdGet32 (PcdSevEsWorkAreaBase) = + 16) %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) + %define SEV_SNP_SECRETS_BASE (FixedPcdGet32 (PcdOvmfSnpSecretsBase)) + %define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize)) =20 %include "X64/IntelTdxMetadata.asm" %include "Ia32/Flat32ToFlat64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 9d8c3e8194a4..2bc7790bd808 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -14,6 +14,9 @@ BITS 64 ; The section must be accepted or validated by the VMM before the boot %define OVMF_SECTION_TYPE_SNP_SEC_MEM 0x1 =20 +; AMD SEV-SNP specific sections +%define OVMF_SECTION_TYPE_SNP_SECRETS 0x2 + ALIGN 16 =20 TIMES (15 - ((OvmfSevGuidedStructureEnd - OvmfSevGuidedStructureStart + 15= ) % 16)) DB 0 @@ -30,5 +33,11 @@ _DescriptorSev: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _DescriptorSev - 16) / 12 ; Number of se= ctions =20 +; SEV-SNP Secrets page +SevSnpSecrets: + DD SEV_SNP_SECRETS_BASE + DD SEV_SNP_SECRETS_SIZE + DD OVMF_SECTION_TYPE_SNP_SECRETS + OvmfSevGuidedStructureEnd: ALIGN 16 --=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 (#84544): https://edk2.groups.io/g/devel/message/84544 Mute This Topic: https://groups.io/mt/87605525/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 Sat May 4 15:08:10 2024 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+84545+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020507792427.75770921809965; Wed, 8 Dec 2021 19:28:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id iMj8YY1788612xR1pbsZ6OP7; Wed, 08 Dec 2021 19:28:27 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.87]) by mx.groups.io with SMTP id smtpd.web08.6784.1639020506282600764 for ; Wed, 08 Dec 2021 19:28:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iRxu7iBcs0HfKEHRs3kDBS1L/XL6VQheAOKXjSJqQL68wbOWmOKsm7SxdVL5tkRYb3oHc2vlnxAbm3aNMm60v6jpp9tP1ZZMatiEWNGTwTar1+aJaK2RBjDrhZckA6XZqIIdsUWsETVFIL9KaI7UbC6RyyvtyikgU2+jMb63gabIOvYwj2Jwrpd3vfr+ld9Magn8IJH+0ItAaokYDwBFhY52IrjsokT+DvNObm5uswcZkFegQ0+nscwdd/I0lq+q529sQJ6YbyWdGe4tk9p7jpeCdLvUGlejyaM0LFkdbXBFUaICjqMcZgKrATDvsmtZVgV9YjrD5qlqYqJQnYtyTA== 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=vSsOCAoj05mNZJVzDfEaGhq0nwLq6KKyhcIqeqjED/4=; b=GZLqml0e2i1pCbM5iAjtFx0sJWwoaH3itTiN2ycL0OBaCOLWY5vvHsQ1ZQh4PwOfELqzqzjU04jko7UxjH9mzB8q4dv7gotOMG8Nhs/X2kFkUGMLPzexnU+WnbVlCrmHDZZnf/eLt50pSVZj1T5U9LT+YpikPxnYcVByjYnBW8mYq37pLztyEhSqksGK27WiH2INTG3VpVu1EnS9BfUMUmiwC9a5orViJoBR82VhtzoKI+0uxojgqWnHWwXn4h345IjvRlYa5VKY2thlJfqBmsvJxKQB7T8BGryGgtITXgRWnTEXlMW/gYtb163ImdbMJXd2Uk6dsRpWT98F8Wj4eQ== 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 CO2PR04CA0144.namprd04.prod.outlook.com (2603:10b6:104::22) by BN9PR12MB5065.namprd12.prod.outlook.com (2603:10b6:408:132::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:23 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:0:cafe::79) by CO2PR04CA0144.outlook.office365.com (2603:10b6:104::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:23 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84545+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=SATLEXMB03.amd.com; X-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:28:23 +0000 X-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:28:21 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 06/32] OvmfPkg: reserve CPUID page Date: Wed, 8 Dec 2021 21:27:34 -0600 Message-ID: <20211209032800.3802995-7-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6dc16e86-8c94-4ae7-a83e-08d9bac3f49c X-MS-TrafficTypeDiagnostic: BN9PR12MB5065:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 35M70DIF2p8o2daSxqU6LvUeqNrozxWkXvwNITPWdEiMVYHZfeTggF+4SIvTcV+aleVWEaAgFrLQ/zDgxBbcU3f4Aq1Eh5+Qeex+RQfp7SjA1ExOip8YVr5f0BuThmITNFQ/5L45faS8/4F0hRycAOCed8l+Q8AnCcpror77wDY3myWhVSsyJpLw+LgilOwfyhoW3xVGa4QnJeVWsWOqJpniIFZH2glQ8F77wz7Sm5Pjng7WANrv6gxGcI/364J5+SxwmdfN9fQ6e7FNIBsnRGccZXUC3HSxOT5p+1QbTRALzM7dNDu8Z5HyxsEZ8Ddvrtm08MLxWvpi+BpiHRXEFiY+iyE4aeroy1hzi3TXQ4CN6FxG0peUy4dlPVvq33H7DrzoRJMUUAYilQDkjevT2Vy7vfglLpgg/74g1JlvKDYn9UMxj3S/qBA68nkSk9+9XrUZhcjU1wsmDoIhI5G6qQIT9RkCP0+5G4wmWu1o+Q28ezXd9XLVQqrtTI8yBrEqUFldXK6dz7geOPqG0S1PMGrFOtjj4/dyCQKq5s3hJOAgrpvIpvuLAefx3rKaPusLPCNCKPRnybm1yICdt4pNxANkwrqgkIW9VNwDX1h38cw70UfcwFac6V56i6eDX8BHiTHktvu6pAt25IPdiANCOMungxtW8WLXeUQ/WDRPz2PWxXVH/RtlPRY35MQVPxjRNnAflFXxUaHbUUE8ErqxmHi3kZNqfHGYdHcRGpkUIjDweWGjzKth2d6OVb5aI6z6IeP8B9xS2LikthsSvCn4pudHxxfGcDJ94zYzEXB3nXAIt/DxVLraEATfxPwdvoCjyWIluOUOiE7W0m5fOVIWzjNtGOG9ydbZL0ecpwsHJTiQraFYN5hphF/pPAnrLLwE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:23.3369 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6dc16e86-8c94-4ae7-a83e-08d9bac3f49c 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: BN9PR12MB5065 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: A2NB3HbvH3OKZUsjmwG9FU78x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020507; bh=gapjB8LWKir6C/NJRO/BP+5o77SPs3cJFhYTihO3IHg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=OCPD53qmk48eyX2q7hf7ZWN+3Ibk2Sg6M1nECqNBFm5p0o1Ki54TC6Q1G+IuT1PcKYB BM6moGiJJ06HChwycHEoxhP52OJK9Og69fBWPfz6pI1cRlHod2n/vbDrq+JLku4Hr9Tv+ 1/t28dTzJacVlrU/Wv1Shv8ZLUT3CjluDYY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020508432100004 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Platform features and capabilities are traditionally discovered via the CPUID instruction. Hypervisors typically trap and emulate the CPUID instruction for a variety of reasons. There are some cases where incorrect CPUID information can potentially lead to a security issue. The SEV-SNP firmware provides a feature to filter the CPUID results through the PSP. The filtered CPUID values are saved on a special page for the guest to consume. Reserve a page in MEMFD that will contain the results of filtered CPUID values. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 7 +++++++ OvmfPkg/OvmfPkgX64.fdf | 3 +++ OvmfPkg/ResetVector/ResetVector.inf | 2 ++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++ OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 16 ++++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index deb285fd62c5..bc14cf2ed403 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -357,6 +357,13 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|0|UINT32|0x58 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize|0|UINT32|0x59 =20 + ## The base address and size of a CPUID Area that contains the hypervisor + # provided CPUID results. In the case of SEV-SNP, the CPUID results are + # filtered by the SEV-SNP firmware. If this is set in the .fdf, the + # platform is responsible to reserve this area from DXE phase overwrite= s. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|0|UINT32|0x60 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize|0|UINT32|0x61 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 1313c7f016bf..e94b433e7b28 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -91,6 +91,9 @@ [FD.MEMFD] 0x00D000|0x001000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|gUefiOvmfPkgTokenSpaceGui= d.PcdOvmfSnpSecretsSize =20 +0x00E000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|gUefiOvmfPkgTokenSpaceGuid.Pcd= OvmfCpuidSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index fcbc25d0ce3d..1c5d84184ed7 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -55,6 +55,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdBfvRawDataSize =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 4e685ef23684..fbaeab5f5168 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -105,6 +105,8 @@ %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) %define SEV_SNP_SECRETS_BASE (FixedPcdGet32 (PcdOvmfSnpSecretsBase)) %define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize)) + %define CPUID_BASE (FixedPcdGet32 (PcdOvmfCpuidBase)) + %define CPUID_SIZE (FixedPcdGet32 (PcdOvmfCpuidSize)) =20 %include "X64/IntelTdxMetadata.asm" %include "Ia32/Flat32ToFlat64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 2bc7790bd808..0cc12ad3473f 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -17,6 +17,16 @@ BITS 64 ; AMD SEV-SNP specific sections %define OVMF_SECTION_TYPE_SNP_SECRETS 0x2 =20 +; +; The section contains the hypervisor pre-populated CPUID values. +; In the case of SEV-SNP, the CPUID values are filtered and measured by +; the SEV-SNP firmware. +; The CPUID format is documented in SEV-SNP firmware spec 0.9 section 7.1 +; (CPUID function structure). +; +%define OVMF_SECTION_TYPE_CPUID 0x3 + + ALIGN 16 =20 TIMES (15 - ((OvmfSevGuidedStructureEnd - OvmfSevGuidedStructureStart + 15= ) % 16)) DB 0 @@ -39,5 +49,11 @@ SevSnpSecrets: DD SEV_SNP_SECRETS_SIZE DD OVMF_SECTION_TYPE_SNP_SECRETS =20 +; CPUID values +CpuidSec: + DD CPUID_BASE + DD CPUID_SIZE + DD OVMF_SECTION_TYPE_CPUID + OvmfSevGuidedStructureEnd: ALIGN 16 --=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 (#84545): https://edk2.groups.io/g/devel/message/84545 Mute This Topic: https://groups.io/mt/87605526/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 Sat May 4 15:08:10 2024 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+84546+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020509821721.0382739198822; Wed, 8 Dec 2021 19:28:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id v5zfYY1788612x7iTeKuxntC; Wed, 08 Dec 2021 19:28:29 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.70]) by mx.groups.io with SMTP id smtpd.web11.6926.1639020508070053888 for ; Wed, 08 Dec 2021 19:28:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bHaJ4+8gJS3ypT+rX/ZC0rNNWeUouCMEMplb7mWEI7topF20pb3AWwlHUJsn/LwUV+BdwcP2+QhHk97/nZQE51BEUyVlzzGn9eHEMemn0miZtcl0Y6OzQ3M2PE/QMMLQYZAFIpXLGKPG8pmLcrNnCAMKqPR6r5ezqE+yVedUiHuD/HFUyhOUaaKtR6EdgwefVAJN0cXGpP0tXBakA1irP/iYn2Guc5X3Y1+sP5Ctc7F0R192vBN0N3myDmQ4z2P0gSfDXOtvzTmfjlzOk9+awJFOQtj7hCh2q8A5as2/tgkM2fGGD2JmqCwUtqRUx2QGJdc6CU1ycSRfO0o4ZEHThw== 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=M++kr5DN/B2FTyRoR63HI0w7bzxmLkn7Y5lJWqyMeHU=; b=bojjtZw6VS9e1UZaDv3M41A74JCAOQ1rUuMtjzxP1l/lRJIMnrxknujkqiMt1R6SUZ0KNFDEYWyjxSajnLyEAlDUW+DLV2+VGwCfcS93AlLIN6bqRQBTCkqETDMnLcflC+RelPuHavNd9/cwABBzv5MmHcXU52sXDHawSUWwXo1KddHayrkAvERQ9M9JOwEoA3Ov4il7T29Lpn4hDK7gn0zVC9g22vRj7/BizOFLCgauLtCnencm/zuNc6EVZ+1+L6QL/F54WXzzQEp/dpaeyAlU9sCFLE5OEeChvrxCpdrI0SimwfdqS9Rf2rkNLvpm7RvA2/77R2Cx9OLi4qu3yA== 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 MWHPR1201CA0018.namprd12.prod.outlook.com (2603:10b6:301:4a::28) by BY5PR12MB4259.namprd12.prod.outlook.com (2603:10b6:a03:202::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Thu, 9 Dec 2021 03:28:25 +0000 X-Received: from CO1NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4a:cafe::6f) by MWHPR1201CA0018.outlook.office365.com (2603:10b6:301:4a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:28:25 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84546+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT015.mail.protection.outlook.com (10.13.175.130) 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:28:25 +0000 X-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:28:23 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 07/32] OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase Date: Wed, 8 Dec 2021 21:27:35 -0600 Message-ID: <20211209032800.3802995-8-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca7890d9-29b9-4b80-a227-08d9bac3f5c8 X-MS-TrafficTypeDiagnostic: BY5PR12MB4259:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 7iYzt24YN0iW5r0+ru95SOQJPz+Ha1C8RHdk0F8tGlMxc/zZ0xKynkgIR8Mulz3bAj9Vr5YSHK+vVpTCCkVRZ0e2+KrTcR9KpRsHrD4NUmijOK3KAsyjQg21fwJXk4oBV3KU4pQhVflIvKvnw90M3OjK6UsPCuP89jgCqdSwBpXDOpM3W0gCQjZK7je9AVGWrl/UCUXsFUU2RSoO1K0lt4pTiaSs3JP676avxGJidTbgLmXA6Poa2/Pc7N41c/8Kabb9YwQ2FASmbwXvvJxRkR1+pSMCNLX+q2dSHdhZQfhi3Knrs41m37y1OErpbnCq+z0Ttg7WB6sbWhgKtzSD4JHmkvkETGC9jWnVu9LN4yLKFzacq1TolcRUO/dxQwJl8YohzPiP7jDdaAwFvIGxbep71RjpfktsRqOfkASAJ+FhfQquGP8StDRpgWiUYuj3J2v6GGvpPKTQlC7NpHtwuyIezhReUu7vx9A+rgga+CYtS7FvqUaG29mZ1vY351isNtZrakU8TgjjWSMOE8ZZJ5NRqncyOg7YcvUezDf5WjyVM9Etc1oz/elhWig2Bb3/4fkdueTKnJUVLxYLADdbVtHGM+MlrYB6j3dgYT6T7D68HsW1F0dJj0mcV9ux/8FhTGMRR1pRTCAZwV+5D9QjW5zTNNYGlLq6aXyS34ylwJX4es7hUAR6WyYD9CcilXiEBRCBsw+pLZgjp3dNrHA7wtN4e8yjrZ8+4wVKtyMtvVXc7rpUHMcKcv6vudQnsSai27GtrCQPccUmG0NMCmt9xbi8Mq5aHpV6+sFEP5BaxORs7XQet4zkRbi61i/A0i3QE37NWyBD9jGYFzlYPFooACAalzR+rIWKkY1cIfnFUMhja6+zRKUlR0SPclnhnVu/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:25.2964 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca7890d9-29b9-4b80-a227-08d9bac3f5c8 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: CO1NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4259 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: aBj5fPsWKzkxlYe282dl7zaqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020509; bh=BxsblESWl+It5JIWC96f71VBRNHr1WXFQPtkYsVKeQU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HC5SDD8QNWS6KROxMwhI8lrGp36tmEDEZOaUBv9GmaSK5M4MkuiOhE8esPQS1n40TkE A7C78YmMyLkEU3oPKsspXIkEn7Nz1pc+qb0ZXHSdp3QZuhgLjKnZCn/g2w2AORxqKHHK6 eb4iJpRe+pmFRWiO9CsSV811G2v220KTSR0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020510717100004 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 An SEV-SNP guest requires that private memory (aka pages mapped encrypted) must be validated before being accessed. The validation process consist of the following sequence: 1) Set the memory encryption attribute in the page table (aka C-bit). Note: If the processor is in non-PAE mode, then all the memory accesses are considered private. 2) Add the memory range as private in the RMP table. This can be performed using the Page State Change VMGEXIT defined in the GHCB specification. 3) Use the PVALIDATE instruction to set the Validated Bit in the RMP table. During the guest creation time, the VMM encrypts the OVMF_CODE.fd using the SEV-SNP firmware provided LAUNCH_UPDATE_DATA command. In addition to encrypting the content, the command also validates the memory region. This allows us to execute the code without going through the validation sequence. During execution, the reset vector need to access some data pages (such as page tables, SevESWorkarea, Sec stack). The data pages are accessed as private memory. The data pages are not part of the OVMF_CODE.fd, so they were not validated during the guest creation. There are two approaches we can take to validate the data pages before the access: a) Enhance the OVMF reset vector code to validate the pages as described above (go through step 2 - 3). OR b) Validate the pages during the guest creation time. The SEV firmware provides a command which can be used by the VMM to validate the pages without affecting the measurement of the launch. Approach #b seems much simpler; it does not require any changes to the OVMF reset vector code. Update the OVMF metadata with the list of regions that must be pre-validated by the VMM before the boot. Cc: Michael Roth 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 --- OvmfPkg/ResetVector/ResetVector.inf | 1 + OvmfPkg/ResetVector/ResetVector.nasmb | 13 +++++++++++++ OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 1c5d84184ed7..a4154ca90c28 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -57,6 +57,7 @@ [Pcd] [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index fbaeab5f5168..cc364748b592 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -107,6 +107,19 @@ %define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize)) %define CPUID_BASE (FixedPcdGet32 (PcdOvmfCpuidBase)) %define CPUID_SIZE (FixedPcdGet32 (PcdOvmfCpuidSize)) + %define SNP_SEC_MEM_BASE_DESC_1 (FixedPcdGet32 (PcdOvmfSecPageTablesBase= )) + %define SNP_SEC_MEM_SIZE_DESC_1 (FixedPcdGet32 (PcdOvmfSecGhcbBase) - SN= P_SEC_MEM_BASE_DESC_1) + ; + ; The PcdOvmfSecGhcbBase reserves two GHCB pages. The first page is used + ; as GHCB shared page and second is used for bookkeeping to support the + ; nested GHCB in SEC phase. The bookkeeping page is mapped private. The = VMM + ; does not need to validate the shared page but it need to validate the + ; bookkeeping page. + ; + %define SNP_SEC_MEM_BASE_DESC_2 (GHCB_BASE + 0x1000) + %define SNP_SEC_MEM_SIZE_DESC_2 (SEV_SNP_SECRETS_BASE - SNP_SEC_MEM_BASE= _DESC_2) + %define SNP_SEC_MEM_BASE_DESC_3 (CPUID_BASE + CPUID_SIZE) + %define SNP_SEC_MEM_SIZE_DESC_3 (FixedPcdGet32 (PcdOvmfPeiMemFvBase) - S= NP_SEC_MEM_BASE_DESC_3) =20 %include "X64/IntelTdxMetadata.asm" %include "Ia32/Flat32ToFlat64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 0cc12ad3473f..d03fc6d45175 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -43,6 +43,16 @@ _DescriptorSev: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _DescriptorSev - 16) / 12 ; Number of se= ctions =20 +; Region need to be pre-validated by the hypervisor +PreValidate1: + DD SNP_SEC_MEM_BASE_DESC_1 + DD SNP_SEC_MEM_SIZE_DESC_1 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM +PreValidate2: + DD SNP_SEC_MEM_BASE_DESC_2 + DD SNP_SEC_MEM_SIZE_DESC_2 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM + ; SEV-SNP Secrets page SevSnpSecrets: DD SEV_SNP_SECRETS_BASE @@ -55,5 +65,10 @@ CpuidSec: DD CPUID_SIZE DD OVMF_SECTION_TYPE_CPUID =20 +; Region need to be pre-validated by the hypervisor +PreValidate3: + DD SNP_SEC_MEM_BASE_DESC_3 + DD SNP_SEC_MEM_SIZE_DESC_3 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM OvmfSevGuidedStructureEnd: ALIGN 16 --=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 (#84546): https://edk2.groups.io/g/devel/message/84546 Mute This Topic: https://groups.io/mt/87605528/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 Sat May 4 15:08:10 2024 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+84547+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020509318216.41057170275462; Wed, 8 Dec 2021 19:28:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id P2ziYY1788612xADp2nti2xb; Wed, 08 Dec 2021 19:28:28 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.76]) by mx.groups.io with SMTP id smtpd.web10.6824.1639020508111248148 for ; Wed, 08 Dec 2021 19:28:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UKyR1ElnWuo/5QI5zeDi4CYzenqkvaIbc6/smOpKkcW3m3V7he3bXxU+WAYIn1i6UnXalKqbjKheBHB4KjHtEJgLP+4geAq0AvkAHiPvWy2G1BHjlruXIkMnfdWlRARHStxxf+D2W0haqQ19s263l1XcvCWCPYbaWY0DhE28I3pnLdz9R9JoQTyuYzr4ObskwhV+7JvASiKlChc7Iy53slHhH1fQsHToEutfGnssfv/F+GnS9J/KAUG35WkvwR4301BPzR1zMZT3+N/CDg7fcsLkugsGFjHAhvHddH/dpH44qH7RRq/i69OpwN03bmAtAwVpRjG6fFDV/072FJ8wqQ== 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=19UpFsAojMNItsCb+HCNBgIG05cw1PHsY58EmIKvSfI=; b=HP4OmvxGBUYxZ/2kb2YGNR+pwb0LUUNTPsvA0gbpQ3GxyT9T44LnO7PHEwKEDHGjU0u95d+uoWK0csick52gLKl+JnVii3TlGP0VgAXrjNC2O0mNKrGLrw2VqbvjGI0AMJfQhWG4IYcJj0pqa+4kAd6KsGEePT1UUPRBmCscgz7/O0fh8MHuAQ1pwKMdQIHQV/IrrU/Lb2PvuzBFB0NSgXX/QDnXMD659zQnAxejlNbNYvFyLAbFBZJmfnWHzu3RkBzmlwETw+RwJ6E6KAzHGnxzSpHPOmgVY5SFPN++zkS7WP/Gdl8mId2hdRZFCBYIVyd7E4lvSCYMGYPYP61vYQ== 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 MWHPR1201CA0001.namprd12.prod.outlook.com (2603:10b6:301:4a::11) by MN2PR12MB4191.namprd12.prod.outlook.com (2603:10b6:208:1d3::7) 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:28:26 +0000 X-Received: from CO1NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4a:cafe::89) by MWHPR1201CA0001.outlook.office365.com (2603:10b6:301:4a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.17 via Frontend Transport; Thu, 9 Dec 2021 03:28:26 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84547+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT015.mail.protection.outlook.com (10.13.175.130) 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:28:26 +0000 X-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:28:24 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Michael Roth , Jiewen Yao , Brijesh Singh Subject: [edk2-devel] [PATCH v14 08/32] OvmfPkg/ResetVector: use SEV-SNP-validated CPUID values Date: Wed, 8 Dec 2021 21:27:36 -0600 Message-ID: <20211209032800.3802995-9-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88a380ff-b33a-442a-0128-08d9bac3f644 X-MS-TrafficTypeDiagnostic: MN2PR12MB4191:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 52YcHhz2gnaAdo+Z0r65ogoMlyDzSi7SY0+Qe1LPDwEKnXYmRF1B86KHn6c0O9mfq/sKqWkn055B1doSP939McnQnEAaKTZg5pbg5QJpPYoLuPsxa/4SvKM5tXr2YczzvOBYQ/+vCmnNqAS86ud3fd6vmn7k3U2u9xcC+5p1j8wpPGiVlkLTg2KBpjttgsDrCu6R5yYqLJaM/UTc6a/CE7fqJYvCtgdPXEvWFZy4h0JMFDyYbq2rPSDmbaFfA6EPN1hwWRjBHA/ZIeYldikdMyOdAisOAdi/HgNufkWdsMEEydngYJYdfOIU7P/3pyOzoXzzzfNHNiyu7ABO0IEFuTc/HMgJVUyzFdFa4ZEJVpktS5o/pB03zmGqSkMogs5+zAKJ3bDFzHTQjPtNb6XdD9rOR3rmmritDov6+UHa4n0bsxgbtL3maSKKfCzQyEfnf9bpWAN/02/duK+JfsFad0wKUeU4vvSHoHrVfuORmEF4fNSpmXvPhMZR+i8AQqXFOKQ3/YyGHC5b4sQED7BHC0BGX/UQ8ZQa9VKspeL9cEtCQzI68+F9blkb/PH1DDYEgXmfQy9pKo1ZhWeZtyKkgfSMf9xe5R0lPlZTCCryJodfvVjT4fmttNp4QQerRxx3xAvIA9rbm39ye5Ldj3Ec2yG18Hz16S2UIVMjsxzdRLShx6+miJuVQP/+7rYAKUPIl4SO6DKKdlY+z5cR/ZPMbUULQnUzFB+2D7GjOag9UywJR45Zh0gO4YQ1gldMLDw+iFudS/9h8iys0TspLDzUUAEHCDpQAz4MNob4pAj1ezU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:26.1039 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88a380ff-b33a-442a-0128-08d9bac3f644 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: CO1NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4191 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: PiJvQV4eQokDHredaigIaTaGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020508; bh=GghEKDhwITDTu1YqZg2vVtrGOEQs8VC49A16hPnhl5A=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=e+T3NuifAYYQvhwRKrQrGaSr9xPYuRYgSDK6hymMMO1rzj7s73dpLrbUQpU5D9QRbJ3 LyFn71/X04SUPMixI1G7JFyWZtLQ5c8jsIigBbgf4QzomSmpR2N5WKcukRCg906Pak4zI t9nIvGQjulxZE7JYcFl/KY4qNWJoHweJYDU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020510613100001 Content-Type: text/plain; charset="utf-8" From: Michael Roth CPUID instructions are issued during early boot to do things like probe for SEV support. Currently these are handled by a minimal #VC handler that uses the MSR-based GHCB protocol to fetch the CPUID values from the hypervisor. When SEV-SNP is enabled, use the firmware-validated CPUID values from the CPUID page instead [1]. [1]: SEV SNP Firmware ABI Specification, Rev. 0.8, 8.13.2.6 Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- OvmfPkg/ResetVector/Ia32/AmdSev.asm | 80 +++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/ResetVector/Ia32/AmdSev.asm b/OvmfPkg/ResetVector/Ia32= /AmdSev.asm index 48d9178168b0..1f827da3b929 100644 --- a/OvmfPkg/ResetVector/Ia32/AmdSev.asm +++ b/OvmfPkg/ResetVector/Ia32/AmdSev.asm @@ -34,6 +34,18 @@ BITS 32 %define GHCB_CPUID_REGISTER_SHIFT 30 %define CPUID_INSN_LEN 2 =20 +; #VC handler offsets/sizes for accessing SNP CPUID page +; +%define SNP_CPUID_ENTRY_SZ 48 +%define SNP_CPUID_COUNT 0 +%define SNP_CPUID_ENTRY 16 +%define SNP_CPUID_ENTRY_EAX_IN 0 +%define SNP_CPUID_ENTRY_ECX_IN 4 +%define SNP_CPUID_ENTRY_EAX 24 +%define SNP_CPUID_ENTRY_EBX 28 +%define SNP_CPUID_ENTRY_ECX 32 +%define SNP_CPUID_ENTRY_EDX 36 + =20 %define SEV_GHCB_MSR 0xc0010130 %define SEV_STATUS_MSR 0xc0010131 @@ -335,11 +347,61 @@ SevEsIdtNotCpuid: TerminateVmgExit TERM_VC_NOT_CPUID iret =20 - ; - ; Total stack usage for the #VC handler is 44 bytes: - ; - 12 bytes for the exception IRET (after popping error code) - ; - 32 bytes for the local variables. - ; +; Use the SNP CPUID page to handle the cpuid lookup +; +; Modified: EAX, EBX, ECX, EDX +; +; Relies on the stack setup/usage in #VC handler: +; +; On entry, +; [esp + VC_CPUID_FUNCTION] contains EAX input to cpuid instruction +; +; On return, stores corresponding results of CPUID lookup in: +; [esp + VC_CPUID_RESULT_EAX] +; [esp + VC_CPUID_RESULT_EBX] +; [esp + VC_CPUID_RESULT_ECX] +; [esp + VC_CPUID_RESULT_EDX] +; +SnpCpuidLookup: + mov eax, [esp + VC_CPUID_FUNCTION] + mov ebx, [CPUID_BASE + SNP_CPUID_COUNT] + mov ecx, CPUID_BASE + SNP_CPUID_ENTRY + ; Zero these out now so we can simply return if lookup fails + mov dword[esp + VC_CPUID_RESULT_EAX], 0 + mov dword[esp + VC_CPUID_RESULT_EBX], 0 + mov dword[esp + VC_CPUID_RESULT_ECX], 0 + mov dword[esp + VC_CPUID_RESULT_EDX], 0 + +SnpCpuidCheckEntry: + cmp ebx, 0 + je VmmDoneSnpCpuid + cmp dword[ecx + SNP_CPUID_ENTRY_EAX_IN], eax + jne SnpCpuidCheckEntryNext + ; As with SEV-ES handler we assume requested CPUID sub-leaf/index is 0 + cmp dword[ecx + SNP_CPUID_ENTRY_ECX_IN], 0 + je SnpCpuidEntryFound + +SnpCpuidCheckEntryNext: + dec ebx + add ecx, SNP_CPUID_ENTRY_SZ + jmp SnpCpuidCheckEntry + +SnpCpuidEntryFound: + mov eax, [ecx + SNP_CPUID_ENTRY_EAX] + mov [esp + VC_CPUID_RESULT_EAX], eax + mov eax, [ecx + SNP_CPUID_ENTRY_EBX] + mov [esp + VC_CPUID_RESULT_EBX], eax + mov eax, [ecx + SNP_CPUID_ENTRY_EDX] + mov [esp + VC_CPUID_RESULT_ECX], eax + mov eax, [ecx + SNP_CPUID_ENTRY_ECX] + mov [esp + VC_CPUID_RESULT_EDX], eax + jmp VmmDoneSnpCpuid + +; +; Total stack usage for the #VC handler is 44 bytes: +; - 12 bytes for the exception IRET (after popping error code) +; - 32 bytes for the local variables. +; SevEsIdtVmmComm: ; ; If we're here, then we are an SEV-ES guest and this @@ -367,6 +429,13 @@ SevEsIdtVmmComm: ; Save the CPUID function being requested mov [esp + VC_CPUID_FUNCTION], eax =20 + ; If SEV-SNP is enabled, use the CPUID page to handle the CPUID + ; instruction. + mov ecx, SEV_STATUS_MSR + rdmsr + bt eax, 2 + jc SnpCpuidLookup + ; The GHCB CPUID protocol uses the following mapping to request ; a specific register: ; 0 =3D> EAX, 1 =3D> EBX, 2 =3D> ECX, 3 =3D> EDX @@ -424,6 +493,7 @@ VmmDone: mov ecx, SEV_GHCB_MSR wrmsr =20 +VmmDoneSnpCpuid: mov eax, [esp + VC_CPUID_RESULT_EAX] mov ebx, [esp + VC_CPUID_RESULT_EBX] mov ecx, [esp + VC_CPUID_RESULT_ECX] --=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 (#84547): https://edk2.groups.io/g/devel/message/84547 Mute This Topic: https://groups.io/mt/87605529/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 Sat May 4 15:08:10 2024 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+84548+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020511407902.189571327658; Wed, 8 Dec 2021 19:28:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Tj8RYY1788612xaRCMaYgb0J; Wed, 08 Dec 2021 19:28:31 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.77]) by mx.groups.io with SMTP id smtpd.web10.6826.1639020510392814503 for ; Wed, 08 Dec 2021 19:28:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XGUGNEvxWTBxOJbQK3k3CSlZtRN2RQqx7Qzi5IrUCVZBFiPjM299JeW4KcJgA0Lq8ubbk4qNEpCQyGcaSjpGH4p+yDlj1oewDgZiHTO0oRJQfjAJVTvgw21r/V9J28q40aRE0xtzjyeaM1ICBYoZI3NVXPcqlr2pvHHczUgysmWhx/BmXt2mFPUkN8S1p/WPiVOXOAROStF+lALqZ6ekx2vB92wkN0lHSfGlsRMyUWRSta/k0Rf1H2zgdDBmIP9kgv0+bxrREdjuIO+ocFLvuEskp4TcURSu7QZPHCkR//SFZeFpVqkAwv/WJo9ymtGqdyGGoB0FQWB1Ou1WR9fyug== 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=iPgTTi5Ri9rWFFO7P4CBIzTHfIHae3OVb4Rd4TttkGk=; b=dcPFcYWnB4k9B6WVA1mzAuCeVyCDqunUTWue+meLr4SsdJJFYagtvndByZUQby4dB0ulGNEL8JoVxccFXC4WK80HjCazk7jbRpHiKP7VtWh4cAyFKhS3kaDW5dYEZUdFi9Kdv/doJVbUhvaJ7+/1cwp6Zlzcci6K1aWxOxYVgBkxSXz49G6xJ6ckvPGlHVFyhwsoW4c99+qm/dSgxMzE//TyPbsKvrFApAqQ1SlHwOEXnzUT7f7lUoc77BuoXi3+VTRWQV2dACjAZewveb6fqhhHM2RhKEuiDhIvFNfkA3qQPPlCyeg2/3ukuCyNJpR15vZVeWWljTEof9y1qUcCoA== 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 MWHPR1401CA0024.namprd14.prod.outlook.com (2603:10b6:301:4b::34) by DM6PR12MB3993.namprd12.prod.outlook.com (2603:10b6:5:1c5::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:28 +0000 X-Received: from CO1NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4b:cafe::ee) by MWHPR1401CA0024.outlook.office365.com (2603:10b6:301:4b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21 via Frontend Transport; Thu, 9 Dec 2021 03:28:28 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84548+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT016.mail.protection.outlook.com (10.13.175.141) 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:28:28 +0000 X-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:28:25 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 09/32] OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() Date: Wed, 8 Dec 2021 21:27:37 -0600 Message-ID: <20211209032800.3802995-10-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 893f8111-e77c-49af-cd2e-08d9bac3f77d X-MS-TrafficTypeDiagnostic: DM6PR12MB3993:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:196; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 6hUMJ94jiJkEiaHCWJf6nB+8ceoT6jXS2bzUKE9FBv/8rLRgl4ZAkMH3i9AiHOMsWKocuX6DOpIPS2cZhGd6tnF8FQSIPy865nE3BSqIm1jRs9VCyyvLi0xIoOOUQ+N1Qfgc3G+67WyiIPSLWABoqS0Z6JppjpJEdkTXRMWWEWQj28aqqQKla3srZxE6ajnD8dGaTr361Keyq6JfrXVihu1TnkDmEurxV70RkBgobxXQjGqoLAJbWjglKIz/TlakNJ0zFENtN9BtdEcZNcTIyPRAC4t4MT78xkD+z/BOm50awQTzbEspJCMErZ86PqkT96v93wQUccq5aC2AEkgZvIJWo4oVCRJ7C08pANBex6CiOFNWABrlRDhaWEKJkKj/e5DJzEMCGyJUaZmFswg35BrFFLRdI4V30ZVuXX2C4GrwT3OYypme0bpJvgrJU/f/Sa/AoLm+CN0SXJPuHWP5yxq3HzoEvGFBG60Qf/kbk+EgHycz5y1d4E7GLj8waDgAm4c2ZdmUp9pvkFk7Ie8FnJ5b+n2f4ajT2zu3yQ+3wSPz5b/t5atSkR2XWw9lGdKyo6Man9+kgv3DxdK9lE/6hXvnJXaJO20BMAdYyUkBlDZI8d51S22L8ZsQRplgCLU352AWglW3RmwlhbI5o04NV5OsxwjqIesVwcSxomOK575h6g2Y6qej7qrhvaKd4Nb+oi8+mttgvbgIpqyB+doXNYUK+/VKHmw5+Kk35ICRF2geunMTsIUDSrU1lP6yP+sxD3/gD1HCxvQZFvZyzjdAhXFUsraKcENEisYMh8kQ4bf3H5GTS40l+SVRswJhI3dOlFSTVft6r99GMMTFyo4z9yyDooDwTavv6f9mbNOpld+kgJSI2OywLWvgvPWIZ0628Z9Ez2ntcHn2sNGU2CcrBg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:28.1523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 893f8111-e77c-49af-cd2e-08d9bac3f77d 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: CO1NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3993 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: h17WgT5ZpmjB2jCBXIBJugpfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020511; bh=kELIQQqZdbuAkfXKBMrmFDwuVnZd2xyT2AHSJ58FbPc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=b3N4df8B6xmCbVunZY9ZKv/clbNIR90nL+gqIAl9It2xijG4tW5uPFoJweOCgEj7N2I UaM/D3zbNJjcAmVaw5shER15tUjql20yQhpnsKtp8gSQ/5xYKXsX6NGrgfkazl84QYku2 sJ4gTotjzBY8jmJBufBqaj4Sv7rKPYkTKOg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020512864100009 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Create a function that can be used to determine if VM is running as an SEV-SNP guest. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++++++++ .../DxeMemEncryptSevLibInternal.c | 27 +++++++++++++++++++ .../PeiMemEncryptSevLibInternal.c | 27 +++++++++++++++++++ .../SecMemEncryptSevLibInternal.c | 19 +++++++++++++ 4 files changed, 85 insertions(+) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index e1ec161d2159..3c77d71df754 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -47,6 +47,18 @@ typedef enum { MemEncryptSevAddressRangeError, } MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE; =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c index 4fee7b2ab345..15fcd5529587 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLibInternal.c @@ -19,6 +19,7 @@ =20 STATIC BOOLEAN mSevStatus =3D FALSE; STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevSnpStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 STATIC UINT64 mSevEncryptionMask =3D 0; @@ -82,11 +83,37 @@ InternalMemEncryptSevStatus ( if (Msr.Bits.SevEsBit) { mSevEsStatus =3D TRUE; } + + // + // Check MSR_0xC0010131 Bit 2 (Sev-Snp Enabled) + // + if (Msr.Bits.SevSnpBit) { + mSevSnpStatus =3D TRUE; + } } =20 mSevStatusChecked =3D TRUE; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevSnpStatus; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c index c4aa74a0a2dd..d68ff08c3ea6 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c @@ -19,6 +19,7 @@ =20 STATIC BOOLEAN mSevStatus =3D FALSE; STATIC BOOLEAN mSevEsStatus =3D FALSE; +STATIC BOOLEAN mSevSnpStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 STATIC UINT64 mSevEncryptionMask =3D 0; @@ -82,11 +83,37 @@ InternalMemEncryptSevStatus ( if (Msr.Bits.SevEsBit) { mSevEsStatus =3D TRUE; } + + // + // Check MSR_0xC0010131 Bit 2 (Sev-Snp Enabled) + // + if (Msr.Bits.SevSnpBit) { + mSevSnpStatus =3D TRUE; + } } =20 mSevStatusChecked =3D TRUE; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevSnpStatus; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibIntern= al.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c index b5b365641499..5d912b2a4a5e 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -62,6 +62,25 @@ InternalMemEncryptSevStatus ( return ReadSevMsr ? AsmReadMsr32 (MSR_SEV_STATUS) : 0; } =20 +/** + Returns a boolean to indicate whether SEV-SNP is enabled. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevSnpIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D InternalMemEncryptSevStatus (); + + return Msr.Bits.SevSnpBit ? TRUE : FALSE; +} + /** Returns a boolean to indicate whether SEV-ES is enabled. =20 --=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 (#84548): https://edk2.groups.io/g/devel/message/84548 Mute This Topic: https://groups.io/mt/87605530/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 Sat May 4 15:08:10 2024 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+84549+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020513308915.4911805054534; Wed, 8 Dec 2021 19:28:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jOulYY1788612xNluSVhbllE; Wed, 08 Dec 2021 19:28:33 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.46]) by mx.groups.io with SMTP id smtpd.web11.6928.1639020512158871216 for ; Wed, 08 Dec 2021 19:28:32 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S8Di9zXfAtb75y1WB6Lg84mcFtxlOhhhs+jC/Q/tdeIm+Ik/KxHIfblxdQR7UNvRMhrZgPNxkhmw4r3Tb5uXiZqz+ZShjeHnVGnz+oWoQ2uDcfIbh51RANdVB0E9IrSDXMg+HhbTN3S7Rw4p/lbkS+kqZBLmZ7LG8dCistlL0ZOa5427GkEzknKSc9SxcxI+xzyj8Ojl1MmpOKXTeyDJ28s8sU64ESs1izS7S7E+grU0NMkVGU290sCSk47q2F7U1DVJABvk5j+zmM4BN4YP2jtcxHtmDWtcWpdml4RqGNaeY06tgIRVNoF83mOyoLSMP5grR+p8tzGxZu7rXwXg/Q== 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=PZ7EsoyxMZmWcIuqZz5gkP46WPQIhGMJj/k6rXRM7WM=; b=a99YknKI/OlCq5ry7WVVvxVhx6lCXYI5kduue2spJ4CmlhVF6UOh1662dt9z7nhWBv8uJhftJpuFWcEyWHJoebMINSA9nbSwatkdU1JHiNE6no+G8vWZFzzUyk43ci0cS2BvEtQHlHaK82LIFlJ8wsjLghgD/rHoSX5zCbYuwtY5Agw2usxj/cNQhlSGjFhC3R6F3kDKbLM6/ZdQMT+j3kw6Y3pNTMEIIOoRBARbu9jnGE9iuKuuuXU2GruQOPgs2IZOBHosgbpIu8ySMVdSE3YoQo7PsAean944dv/nVq+fJQJu3jLYuaIN7yQXIxqrDatme0nYiqoe9NAkMpYBHg== 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 MWHPR1401CA0005.namprd14.prod.outlook.com (2603:10b6:301:4b::15) by CH0PR12MB5169.namprd12.prod.outlook.com (2603:10b6:610:b8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Thu, 9 Dec 2021 03:28:29 +0000 X-Received: from CO1NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4b:cafe::9a) by MWHPR1401CA0005.outlook.office365.com (2603:10b6:301:4b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:28:29 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84549+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT016.mail.protection.outlook.com (10.13.175.141) 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:28:29 +0000 X-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:28:27 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 10/32] OvmfPkg/SecMain: register GHCB gpa for the SEV-SNP guest Date: Wed, 8 Dec 2021 21:27:38 -0600 Message-ID: <20211209032800.3802995-11-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21a01343-2ec5-4f15-743f-08d9bac3f80a X-MS-TrafficTypeDiagnostic: CH0PR12MB5169:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 0r9jAMyKkJBSOfNcxEu3jxX3kYKahDkmlWdiw5xxFYcX+6+xjfpeCbJXQjFZtozGM3GO6atUkMprxZX6EE24gER0EPTSE6yeLq+GwIG6udrQ8WOhae/96y3T3LUruDNvFNuasJBmKJ38ISpwkU9S3hajOvlz4esPmyKDR5KNhRtFU6nGSM9PCnXMA1OQ0usg+rw+wPtCrLM6xdoZjySGHuA5gjZmdkEgvSAgiXXXencymDrr2+WkKcKNEPwcFlO1v+G07UayH1UCyNOBTh63ocayxITPt3Lh2xF4pJJJMZHwHD8x5sl5MDPJ04leMXXwNUG8VesezcgtpMUwyrTKmH5lDMjqaRDW2v8HlG3VeZUR3LU8aphAfLiUquqdy6Wvj416XC2TWc62RvhKTYccAQPVx+a8Pi/+FrLG1BEqngFz5YbfhdC/mTw+htT3OmNfGNn3gUhNMAe+dmE4Pr1IDXBW684IcC/KSondIOZlA/VdJG+NX10l1wh8gukA4we+0DwP5q0xrHgtroCOSj0I0uTxUc4p3iIKUo2DEkF24AyzdRNzPH9h9lzIJ+wuoOTmJlh4CmEnT9fIlm+9o1+tmfyDvjZRZNIBWBgbXqgHjWjr4kVVyGIn1dh+htxZ5cYJE5+wBWvmHaeO3fRGXZuTTkTCxZWpPXrFu51chn5ZTzTufJpPPFqPAgr2uIWANi9/B89pOZN1aqABZiPW9V4f6cadXj0+0Afetj2lCUE7faUqQRiKHu9a5bdqPB9ffKCjdhQK42B6rTA/WV0UDi/Fvjsx3+uDzyqhX7X3JaKJb0IH3KvUQFgtUbnqgRxmv00pcFJHPd9LIlMgrOwc0Pd06BscUX3Znxb0AQdV3Jlo9szwT9PPqhm93Fn/zvtfNq1+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:29.0741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 21a01343-2ec5-4f15-743f-08d9bac3f80a 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: CO1NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5169 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: PrA8OfHICrmIJkOo5LyKUh98x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020513; bh=aR90ANiDocZTLA7tISMn+Ldu1R6I6IYW0p9FL63WclU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=qlz8L1UP0lIci4mTBo5eoRAfqs+8u44s86pkRnM/nVvfBB9bAziOFBcscU8CLzS+iHR YRr5Ce+3bFlDeAW3qCFsBk7l7Eos+Tx6kOTV0sFruOORXjPspmsTgIUUQyYxZJGxaGsED opX1lRvVgHRr2CbXytbAXYz+4vfIusCGmDk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020515067100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The SEV-SNP guest requires that GHCB GPA must be registered before using. See the GHCB specification section 2.3.2 for more details. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/Sec/AmdSev.c | 119 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c index 0828d090feaf..aa655fd9cbae 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -48,6 +48,104 @@ SevEsProtocolFailure ( CpuDeadLoop (); } =20 +/** + Determine if SEV-SNP is active. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled + +**/ +STATIC +BOOLEAN +SevSnpIsEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + // + // Read the SEV_STATUS MSR to determine whether SEV-SNP is active. + // + Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); + + // + // Check MSR_0xC0010131 Bit 2 (Sev-Snp Enabled) + // + if (Msr.Bits.SevSnpBit) { + return TRUE; + } + + return FALSE; +} + +/** + Register the GHCB GPA + +*/ +STATIC +VOID +SevSnpGhcbRegister ( + EFI_PHYSICAL_ADDRESS Address + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request to register the GPA. + // + Msr.GhcbPhysicalAddress =3D Address & ~EFI_PAGE_MASK; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + // + // If hypervisor responded with a different GPA than requested then fail. + // + if ((Msr.GhcbGpaRegister.Function !=3D GHCB_INFO_GHCB_GPA_REGISTER_RESPO= NSE) || + ((Msr.GhcbPhysicalAddress & ~EFI_PAGE_MASK) !=3D Address)) + { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } +} + +/** + Verify that Hypervisor supports the SNP feature. + + */ +STATIC +BOOLEAN +HypervisorSnpFeatureCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + UINT64 Features; + + // + // Use the GHCB MSR Protocol to query the hypervisor capabilities + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbHypervisorFeatures.Function =3D GHCB_HYPERVISOR_FEATURES_REQUEST; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + Features =3D RShiftU64 (Msr.GhcbPhysicalAddress, 12); + + if ((Msr.GhcbHypervisorFeatures.Function !=3D GHCB_HYPERVISOR_FEATURES_R= ESPONSE) || + (!(Features & GHCB_HV_FEATURES_SNP))) + { + return FALSE; + } + + return TRUE; +} + /** Validate the SEV-ES/GHCB protocol level. =20 @@ -89,6 +187,27 @@ SevEsProtocolCheck ( SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); } =20 + // + // We cannot use the MemEncryptSevSnpIsEnabled () because the + // ProcessLibraryConstructorList () is not called yet. + // + if (SevSnpIsEnabled ()) { + // + // Check if hypervisor supports the SNP feature + // + if (!HypervisorSnpFeatureCheck ()) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + // + // Unlike the SEV-ES guest, the SNP requires that GHCB GPA must be + // registered with the Hypervisor before the use. This can be done + // using the new VMGEXIT defined in the GHCB v2. Register the GPA + // before it is used. + // + SevSnpGhcbRegister ((EFI_PHYSICAL_ADDRESS)(UINTN)FixedPcdGet32 (PcdOvm= fSecGhcbBase)); + } + // // SEV-ES protocol checking succeeded, set the initial GHCB address // --=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 (#84549): https://edk2.groups.io/g/devel/message/84549 Mute This Topic: https://groups.io/mt/87605531/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 Sat May 4 15:08:10 2024 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+84550+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020517432310.40834887832193; Wed, 8 Dec 2021 19:28:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ivUAYY1788612xoOBJRFFPMk; Wed, 08 Dec 2021 19:28:37 -0800 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.50]) by mx.groups.io with SMTP id smtpd.web08.6786.1639020516303465511 for ; Wed, 08 Dec 2021 19:28:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dGmsRLi0RdPdSFMeAXd9AP4ghQrSBwVYV37ke6NLfvCsFp+8kUEP0mEuBDfGD8/Q7PdtBFIKWKlo5YbXyoIqYjtfKvmxfesfhOQkjqLwVR21ldpWLmAtDjRHD1UnPomn3DY+gB/bscF6ybkHUizX27XJR9DAcjQk1x3WoGMMIAI848xI+fJ0x3LAYym0J2Ne+uqIfcnh+UAgk2gkjwwUC7zZuYtwh1AAvVYJrXzwgb8RGPQBMK1/Ez7bUZohdJEib1E7hrWwWbJDobYcd5Ct9sNrzFr7Sfy/pda90/LK/t/rIx9tXen5tGFNlQVCihIV3SPhOhTM+jAJpMMhWLwRWA== 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=gtxIYAAqtxTXgtP1bT2iwB92jNAJU1CyglX+mC4qmck=; b=akTCKwAzbTiARQLs5EUjdgCmndQxmBjvX1uE1FjkA9xBZPICBde12ge/6MtybaNgZEmzx1QKf3sggebJuI4PK4OeGnzYvCy6rjbMCWpXfUZvKpHfut/u8AFxFmPa5evrN9WCUT1Gb+JI+m3aiooSArkjiT4sCuOQFFOEXDsTvobza4iz0jYtGK0L8t5DxANZxz7KaukFR4sPstlfHpwXUb9AtF3fay93wVQPE3qvGJZBLPxEmJk/VdeDWleiP+pXbOSjelzPhKt8UjoU4fwKjZ36gIHfFQzX1JSU5KdlL7H4J8ZDkBhgYDPQplaDaBd3BJCX++WWcSUunloLfygcmQ== 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 MWHPR07CA0012.namprd07.prod.outlook.com (2603:10b6:300:116::22) by BN8PR12MB2963.namprd12.prod.outlook.com (2603:10b6:408:61::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:34 +0000 X-Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::77) by MWHPR07CA0012.outlook.office365.com (2603:10b6:300:116::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:28:34 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84550+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) 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:28:33 +0000 X-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:28:28 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Michael Roth , Jiewen Yao , Brijesh Singh Subject: [edk2-devel] [PATCH v14 11/32] OvmfPkg/VmgExitLib: use SEV-SNP-validated CPUID values Date: Wed, 8 Dec 2021 21:27:39 -0600 Message-ID: <20211209032800.3802995-12-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b68dc44c-a190-4017-128b-08d9bac3faf0 X-MS-TrafficTypeDiagnostic: BN8PR12MB2963:EE_ 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: zH6TxiKv7vvRTlge+n0BZ8L0ERHQCxjW9EIKU4QpRsVN0bwxvY0Y+bFkUUCJx7DCeWMMqxisxWJKmjtZa2pKCy5cblWSxToMTaTlOnp4hw0YKIujYaJAvFb1N3PBOTugmU2fGdfjbkPHpgvyFWZteWBWqKBL1lrocUwvry1JNeflkHzeRa8sEaNeXEOU9zBtj9wAeaXauhNQTjX04T0pMFu896Qt8tHZRplr+6QaO/ObGwJFYSqV81HAuPxujEh8sO+8DoaWQ+kMahzSdrI+3HLi9b0L9jf45IpIaezu5hDZ2Q4qEHqiST5bgml5MYxiJtcaQWoJUotIBxfVqd7VpwXYUrjNXhRZLw2UDWarHvBqkVLJP4pjyhG/tHqJviF1R6PozZZ8Kmbl9IlEMW51WGZNSsZX2uYYQ91oO2zP7pyAQoVCIwTK3gLeE2qLdn+rgoEbziNag9M0XNTWXcc8rNgo33MBU3mAqiguvBXOSRNXJLpp3jIIZdFpttl9yvzrdfJaAV6OV2/RLfOgkP26TUu6+y2dsn1VhXYP34PwQj1XAhLDIOIlZiHohqxa/5hEx0tjHTD+A3OkNGCSMRYFiZzspQfJVVMNhb8f1eHlAugIMxtz3/rcqogDxnn+RY8Lag2UTIo7bI+QIJEkoOmXp265w0g8wHr5vEeniqInv0hXU/FOyLDx/As98dsgLAzHlflNs7sNNnYvfCyB4hcNDJpxpGL5Ps+S/BGJ5Xtv+EB/pi4xQOKNHS/cMbDIXfPI5RyHnVoaLUkR687svgPTQX3D+duZcFri0HW3cl3/srxA+c2fvEV5WpCZqX6rS4xoASBcazR+g3b3gQ5acc23+A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:33.9515 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b68dc44c-a190-4017-128b-08d9bac3faf0 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: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2963 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: xa8sJZ2WycisRZnjmbuY6L1jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020517; bh=bNoxdDpOi+kKsmn1HuBXq10iXJOHC1cffzQEn5+iD7w=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=dpZhqHOJgtjpTVrfqkl/KgMnBrvhXXnyP62bHcjSa7NgK2npurr8MZu/dbHdj9dQOAH tIbVDveyQ3HuHjhBLzdc+LpHK8bpAn+BmWnI28JeO4LDTJRRJlrzOlCgiMmkYNuup0PE/ TiQJmAeKCaZCbeQWIE6V9Dey7CGUPa0wrkY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020519409100002 Content-Type: text/plain; charset="utf-8" From: Michael Roth SEV-SNP firmware allows a special guest page to be populated with guest CPUID values so that they can be validated against supported host features before being loaded into encrypted guest memory to be used instead of hypervisor-provided values [1]. Add handling for this in the CPUID #VC handler and use it whenever SEV-SNP is enabled. To do so, existing CPUID handling via VmgExit is moved to a helper, GetCpuidHyp(), and a new helper that uses the CPUID page to do the lookup, GetCpuidFw(), is used instead when SNP is enabled. For cases where SNP CPUID lookups still rely on fetching specific CPUID fields from hypervisor, GetCpuidHyp() is used there as well. [1]: SEV SNP Firmware ABI Specification, Rev. 0.8, 8.13.2.6 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 2 + OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 3 + OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 499 +++++++++++++++++- 3 files changed, 481 insertions(+), 23 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf b/OvmfPkg/Library= /VmgExitLib/SecVmgExitLib.inf index e6f6ea7972fd..78207fa0f9c9 100644 --- a/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf @@ -42,4 +42,6 @@ [LibraryClasses] [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize =20 diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf index c66c68726cdb..7963670e7d30 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -38,3 +38,6 @@ [LibraryClasses] LocalApicLib MemEncryptSevLib =20 +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 81a93968c85e..a40a31f7c275 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -17,6 +17,7 @@ #include =20 #include "VmgExitVcHandler.h" +// #include =20 // // Instruction execution mode definition @@ -130,6 +131,31 @@ UINT64 SEV_ES_INSTRUCTION_DATA *InstructionData ); =20 +// +// SEV-SNP Cpuid table entry/function +// +typedef PACKED struct { + UINT32 EaxIn; + UINT32 EcxIn; + UINT64 Unused; + UINT64 Unused2; + UINT32 Eax; + UINT32 Ebx; + UINT32 Ecx; + UINT32 Edx; + UINT64 Reserved; +} SEV_SNP_CPUID_FUNCTION; + +// +// SEV-SNP Cpuid page format +// +typedef PACKED struct { + UINT32 Count; + UINT32 Reserved1; + UINT64 Reserved2; + SEV_SNP_CPUID_FUNCTION function[0]; +} SEV_SNP_CPUID_INFO; + /** Return a pointer to the contents of the specified register. =20 @@ -1514,10 +1540,402 @@ InvdExit ( return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0); } =20 +/** + Fetch CPUID leaf/function via hypervisor/VMGEXIT. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communicati= on + Block + @param[in] EaxIn EAX input for cpuid instruction + @param[in] EcxIn ECX input for cpuid instruction + @param[in] Xcr0In XCR0 at time of cpuid instruction + @param[in, out] Eax Pointer to store leaf's EAX value + @param[in, out] Ebx Pointer to store leaf's EBX value + @param[in, out] Ecx Pointer to store leaf's ECX value + @param[in, out] Edx Pointer to store leaf's EDX value + @param[in, out] Status Pointer to store status from VMGEXIT (alway= s 0 + unless return value indicates failure) + @param[in, out] Unsupported Pointer to store indication of unsupported + VMGEXIT (always false unless return value + indicates failure) + + @retval TRUE CPUID leaf fetch successfully. + @retval FALSE Error occurred while fetching CPUID leaf. C= allers + should Status and Unsupported and handle + accordingly if they indicate a more precise + error condition. + +**/ +STATIC +BOOLEAN +GetCpuidHyp ( + IN OUT GHCB *Ghcb, + IN UINT32 EaxIn, + IN UINT32 EcxIn, + IN UINT64 XCr0, + IN OUT UINT32 *Eax, + IN OUT UINT32 *Ebx, + IN OUT UINT32 *Ecx, + IN OUT UINT32 *Edx, + IN OUT UINT64 *Status, + IN OUT BOOLEAN *UnsupportedExit + ) +{ + *UnsupportedExit =3D FALSE; + Ghcb->SaveArea.Rax =3D EaxIn; + VmgSetOffsetValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D EcxIn; + VmgSetOffsetValid (Ghcb, GhcbRcx); + if (EaxIn =3D=3D CPUID_EXTENDED_STATE) { + Ghcb->SaveArea.XCr0 =3D XCr0; + VmgSetOffsetValid (Ghcb, GhcbXCr0); + } + + *Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (*Status !=3D 0) { + return FALSE; + } + + if (!VmgIsOffsetValid (Ghcb, GhcbRax) || + !VmgIsOffsetValid (Ghcb, GhcbRbx) || + !VmgIsOffsetValid (Ghcb, GhcbRcx) || + !VmgIsOffsetValid (Ghcb, GhcbRdx)) + { + *UnsupportedExit =3D TRUE; + return FALSE; + } + + if (Eax) { + *Eax =3D (UINT32)(UINTN)Ghcb->SaveArea.Rax; + } + + if (Ebx) { + *Ebx =3D (UINT32)(UINTN)Ghcb->SaveArea.Rbx; + } + + if (Ecx) { + *Ecx =3D (UINT32)(UINTN)Ghcb->SaveArea.Rcx; + } + + if (Edx) { + *Edx =3D (UINT32)(UINTN)Ghcb->SaveArea.Rdx; + } + + return TRUE; +} + +/** + Check if SEV-SNP enabled. + + @retval TRUE SEV-SNP is enabled. + @retval FALSE SEV-SNP is disabled. + +**/ +STATIC +BOOLEAN +SnpEnabled ( + VOID + ) +{ + MSR_SEV_STATUS_REGISTER Msr; + + Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); + + return !!Msr.Bits.SevSnpBit; +} + +/** + Calculate the total XSAVE area size for enabled XSAVE areas + + @param[in] XFeaturesEnabled Bit-mask of enabled XSAVE features/are= as as + indicated by XCR0/MSR_IA32_XSS bits + @param[in] XSaveBaseSize Base/legacy XSAVE area size (e.g. when + XCR0 is 1) + @param[in, out] XSaveSize Pointer to storage for calculated XSAV= E area + size + @param[in] Compacted Whether or not the calculation is for = the + normal XSAVE area size (leaf 0xD,0x0,E= BX) or + compacted XSAVE area size (leaf 0xD,0x= 1,EBX) + + + @retval TRUE XSAVE size calculation was successful. + @retval FALSE XSAVE size calculation was unsuccessfu= l. +**/ +STATIC +BOOLEAN +GetCpuidXSaveSize ( + IN UINT64 XFeaturesEnabled, + IN UINT32 XSaveBaseSize, + IN OUT UINT32 *XSaveSize, + IN BOOLEAN Compacted + ) +{ + SEV_SNP_CPUID_INFO *CpuidInfo; + UINT64 XFeaturesFound =3D 0; + UINT32 Idx; + + *XSaveSize =3D XSaveBaseSize; + CpuidInfo =3D (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32 (PcdOvmfCpuidBase); + + for (Idx =3D 0; Idx < CpuidInfo->Count; Idx++) { + SEV_SNP_CPUID_FUNCTION *CpuidFn =3D &CpuidInfo->function[Idx]; + + if (!((CpuidFn->EaxIn =3D=3D 0xD) && + ((CpuidFn->EcxIn =3D=3D 0) || (CpuidFn->EcxIn =3D=3D 1)))) + { + continue; + } + + if (XFeaturesFound & (1ULL << CpuidFn->EcxIn) || + !(XFeaturesEnabled & (1ULL << CpuidFn->EcxIn))) + { + continue; + } + + XFeaturesFound |=3D (1ULL << CpuidFn->EcxIn); + if (Compacted) { + *XSaveSize +=3D CpuidFn->Eax; + } else { + *XSaveSize =3D MAX (*XSaveSize, CpuidFn->Eax + CpuidFn->Ebx); + } + } + + /* + * Either the guest set unsupported XCR0/XSS bits, or the corresponding + * entries in the CPUID table were not present. This is an invalid state. + */ + if (XFeaturesFound !=3D (XFeaturesEnabled & ~3UL)) { + return FALSE; + } + + return TRUE; +} + +/** + Check if a CPUID leaf/function is indexed via ECX sub-leaf/sub-function + + @param[in] EaxIn EAX input for cpuid instruction + + @retval FALSE cpuid leaf/function is not indexed by ECX i= nput + @retval TRUE cpuid leaf/function is indexed by ECX input + +**/ +STATIC +BOOLEAN +IsFunctionIndexed ( + IN UINT32 EaxIn + ) +{ + switch (EaxIn) { + case CPUID_CACHE_PARAMS: + case CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS: + case CPUID_EXTENDED_TOPOLOGY: + case CPUID_EXTENDED_STATE: + case CPUID_INTEL_RDT_MONITORING: + case CPUID_INTEL_RDT_ALLOCATION: + case CPUID_INTEL_SGX: + case CPUID_INTEL_PROCESSOR_TRACE: + case CPUID_DETERMINISTIC_ADDRESS_TRANSLATION_PARAMETERS: + case CPUID_V2_EXTENDED_TOPOLOGY: + case 0x8000001D: /* Cache Topology Information */ + return TRUE; + } + + return FALSE; +} + +/** + Fetch CPUID leaf/function via SEV-SNP CPUID table. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communicati= on + Block + @param[in] EaxIn EAX input for cpuid instruction + @param[in] EcxIn ECX input for cpuid instruction + @param[in] Xcr0In XCR0 at time of cpuid instruction + @param[in, out] Eax Pointer to store leaf's EAX value + @param[in, out] Ebx Pointer to store leaf's EBX value + @param[in, out] Ecx Pointer to store leaf's ECX value + @param[in, out] Edx Pointer to store leaf's EDX value + @param[in, out] Status Pointer to store status from VMGEXIT (alway= s 0 + unless return value indicates failure) + @param[in, out] Unsupported Pointer to store indication of unsupported + VMGEXIT (always false unless return value + indicates failure) + + @retval TRUE CPUID leaf fetch successfully. + @retval FALSE Error occurred while fetching CPUID leaf. C= allers + should Status and Unsupported and handle + accordingly if they indicate a more precise + error condition. + +**/ +STATIC +BOOLEAN +GetCpuidFw ( + IN OUT GHCB *Ghcb, + IN UINT32 EaxIn, + IN UINT32 EcxIn, + IN UINT64 XCr0, + IN OUT UINT32 *Eax, + IN OUT UINT32 *Ebx, + IN OUT UINT32 *Ecx, + IN OUT UINT32 *Edx, + IN OUT UINT64 *Status, + IN OUT BOOLEAN *Unsupported + ) +{ + SEV_SNP_CPUID_INFO *CpuidInfo; + BOOLEAN Found; + UINT32 Idx; + + CpuidInfo =3D (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32 (PcdOvmfCpuidBase); + Found =3D FALSE; + + for (Idx =3D 0; Idx < CpuidInfo->Count; Idx++) { + SEV_SNP_CPUID_FUNCTION *CpuidFn =3D &CpuidInfo->function[Idx]; + + if (CpuidFn->EaxIn !=3D EaxIn) { + continue; + } + + if (IsFunctionIndexed (CpuidFn->EaxIn) && (CpuidFn->EcxIn !=3D EcxIn))= { + continue; + } + + *Eax =3D CpuidFn->Eax; + *Ebx =3D CpuidFn->Ebx; + *Ecx =3D CpuidFn->Ecx; + *Edx =3D CpuidFn->Edx; + + Found =3D TRUE; + break; + } + + if (!Found) { + *Eax =3D *Ebx =3D *Ecx =3D *Edx =3D 0; + goto Out; + } + + if (EaxIn =3D=3D CPUID_VERSION_INFO) { + IA32_CR4 Cr4; + UINT32 Ebx2; + UINT32 Edx2; + + if (!GetCpuidHyp ( + Ghcb, + EaxIn, + EcxIn, + XCr0, + NULL, + &Ebx2, + NULL, + &Edx2, + Status, + Unsupported + )) + { + return FALSE; + } + + /* initial APIC ID */ + *Ebx =3D (*Ebx & 0x00FFFFFF) | (Ebx2 & 0xFF000000); + /* APIC enabled bit */ + *Edx =3D (*Edx & ~BIT9) | (Edx2 & BIT9); + /* OSXSAVE enabled bit */ + Cr4.UintN =3D AsmReadCr4 (); + *Ecx =3D (Cr4.Bits.OSXSAVE) ? (*Ecx & ~BIT27) | (*Ecx & BIT27) + : (*Ecx & ~BIT27); + } else if (EaxIn =3D=3D CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + /* OSPKE enabled bit */ + *Ecx =3D (Cr4.Bits.PKE) ? (*Ecx | BIT4) : (*Ecx & ~BIT4); + } else if (EaxIn =3D=3D CPUID_EXTENDED_TOPOLOGY) { + if (!GetCpuidHyp ( + Ghcb, + EaxIn, + EcxIn, + XCr0, + NULL, + NULL, + NULL, + Edx, + Status, + Unsupported + )) + { + return FALSE; + } + } else if ((EaxIn =3D=3D CPUID_EXTENDED_STATE) && ((EcxIn =3D=3D 0) || (= EcxIn =3D=3D 1))) { + MSR_IA32_XSS_REGISTER XssMsr; + BOOLEAN Compacted; + UINT32 XSaveSize; + + XssMsr.Uint64 =3D 0; + if (EcxIn =3D=3D 1) { + /* + * The PPR and APM aren't clear on what size should be encoded in + * 0xD:0x1:EBX when compaction is not enabled by either XSAVEC or + * XSAVES, as these are generally fixed to 1 on real CPUs. Report + * this undefined case as an error. + */ + if (!(*Eax & (BIT3 | BIT1))) { + /* (XSAVES | XSAVEC) */ + return FALSE; + } + + Compacted =3D TRUE; + XssMsr.Uint64 =3D AsmReadMsr64 (MSR_IA32_XSS); + } + + if (!GetCpuidXSaveSize ( + XCr0 | XssMsr.Uint64, + *Ebx, + &XSaveSize, + Compacted + )) + { + return FALSE; + } + + *Ebx =3D XSaveSize; + } else if (EaxIn =3D=3D 0x8000001E) { + UINT32 Ebx2; + UINT32 Ecx2; + + /* extended APIC ID */ + if (!GetCpuidHyp ( + Ghcb, + EaxIn, + EcxIn, + XCr0, + Eax, + &Ebx2, + &Ecx2, + NULL, + Status, + Unsupported + )) + { + return FALSE; + } + + /* compute ID */ + *Ebx =3D (*Ebx & 0xFFFFFF00) | (Ebx2 & 0x000000FF); + /* node ID */ + *Ecx =3D (*Ecx & 0xFFFFFF00) | (Ecx2 & 0x000000FF); + } + +Out: + *Status =3D 0; + *Unsupported =3D FALSE; + return TRUE; +} + /** Handle a CPUID event. =20 - Use the VMGEXIT instruction to handle a CPUID event. + Use VMGEXIT instruction or CPUID table to handle a CPUID event. =20 @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation Block @@ -1536,39 +1954,74 @@ CpuidExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 Status; + BOOLEAN Unsupported; + UINT64 Status; + UINT32 EaxIn; + UINT32 EcxIn; + UINT64 XCr0; + UINT32 Eax; + UINT32 Ebx; + UINT32 Ecx; + UINT32 Edx; =20 - Ghcb->SaveArea.Rax =3D Regs->Rax; - VmgSetOffsetValid (Ghcb, GhcbRax); - Ghcb->SaveArea.Rcx =3D Regs->Rcx; - VmgSetOffsetValid (Ghcb, GhcbRcx); - if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { + EaxIn =3D (UINT32)(UINTN)Regs->Rax; + EcxIn =3D (UINT32)(UINTN)Regs->Rcx; + + if (EaxIn =3D=3D CPUID_EXTENDED_STATE) { IA32_CR4 Cr4; =20 Cr4.UintN =3D AsmReadCr4 (); Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; - VmgSetOffsetValid (Ghcb, GhcbXCr0); + XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; } =20 - Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); - if (Status !=3D 0) { - return Status; + if (SnpEnabled ()) { + if (!GetCpuidFw ( + Ghcb, + EaxIn, + EcxIn, + XCr0, + &Eax, + &Ebx, + &Ecx, + &Edx, + &Status, + &Unsupported + )) + { + goto CpuidFail; + } + } else { + if (!GetCpuidHyp ( + Ghcb, + EaxIn, + EcxIn, + XCr0, + &Eax, + &Ebx, + &Ecx, + &Edx, + &Status, + &Unsupported + )) + { + goto CpuidFail; + } } =20 - if (!VmgIsOffsetValid (Ghcb, GhcbRax) || - !VmgIsOffsetValid (Ghcb, GhcbRbx) || - !VmgIsOffsetValid (Ghcb, GhcbRcx) || - !VmgIsOffsetValid (Ghcb, GhcbRdx)) - { - return UnsupportedExit (Ghcb, Regs, InstructionData); - } - - Regs->Rax =3D Ghcb->SaveArea.Rax; - Regs->Rbx =3D Ghcb->SaveArea.Rbx; - Regs->Rcx =3D Ghcb->SaveArea.Rcx; - Regs->Rdx =3D Ghcb->SaveArea.Rdx; + Regs->Rax =3D Eax; + Regs->Rbx =3D Ebx; + Regs->Rcx =3D Ecx; + Regs->Rdx =3D Edx; =20 return 0; + +CpuidFail: + if (Unsupported) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + return Status; } =20 /** --=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 (#84550): https://edk2.groups.io/g/devel/message/84550 Mute This Topic: https://groups.io/mt/87605533/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 Sat May 4 15:08:10 2024 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+84552+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020520175170.12248528675457; Wed, 8 Dec 2021 19:28:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jLr3YY1788612x8VPZBRgFIH; Wed, 08 Dec 2021 19:28:39 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.40]) by mx.groups.io with SMTP id smtpd.web08.6787.1639020518851867678 for ; Wed, 08 Dec 2021 19:28:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hgK8tcWfQ5E37N7/qDLB+lwY/3cAMnBBRvtVjGLUDgelJXWo3eQ9N6eUipSclRumL4YtloBot2xcx5AisFIK6W6pYtDCGjcD4mI7VaQ+W5Aky6emHpVBLF4dStQfaeNtsl0YxnHh/eyVwyCjDM157/zvboarSimYFwNSkQVKPkAegsh36Lai6gnYYdojyQDSJTZJSb8NwzxmbzWeXgH1AkO4DF95C1RGFW19ujnqZFThxa8haM5GyUzssxEQwsGMobgP2sfZoBtY9Gsp6PdqbSRDFU49mZHewSG8Q9rfwiWLLw1pr6GEmrxSpHewN49A65nDGKCewo6BH/MRpZb3yA== 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=el/WEuoKDl//KHbz1kXl7a/KRU4s9V+K3LPpbeEJmMM=; b=NTss+HuTJrRyz3c8q3wZJzzelOCmVaJS1VDSC1Xd7J6ZwERtSkk9/05ee0XybRUecpuGkIIRV0GLg3b+IPQ/PnEOFk8iexT+1phJzeYyrpoY8Fb4rOMerZ8aXeDRMygMefB42FCYqA99N6XNObQGMQIragKi4VPZhPxKogJJ2F2uBtKDc21t9uKgEOrTFE29YccFaTNDekrQIh6r1GPdjR2mUWWJpl2l3XnLImnWXzdJZ4LI4l27SCqVhFwOPLdiBqdOhbuEzANJflgFJdDO2hxOh0+UmOkPxiEgkPXu4rkMWKEo28CeEnsfhOPQyXY1xV8gpreCvi+UoDl4JrRdxw== 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 MWHPR07CA0014.namprd07.prod.outlook.com (2603:10b6:300:116::24) by MWHPR12MB1726.namprd12.prod.outlook.com (2603:10b6:300:110::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:35 +0000 X-Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::dc) by MWHPR07CA0014.outlook.office365.com (2603:10b6:300:116::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:28:35 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84552+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) 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:28:34 +0000 X-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:28:30 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Wed, 8 Dec 2021 21:27:40 -0600 Message-ID: <20211209032800.3802995-13-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8313fb04-762a-4b7d-334b-08d9bac3fb7b X-MS-TrafficTypeDiagnostic: MWHPR12MB1726:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: Wel8I+TSPcBKw+P2+iuK3Vuw4v6jlImp2aLNlHcu7c18d+j1Z4T5uAhQVzNltJkwhKXJVEjkFYjv5EKsVgzZZlLCB5mSpUDR1UR9jx7A0ZqEw06IrP7nS1JnR+PBoAHrHraUe24uwfWWg3urzJexMdPc5zl1PLD8znjrfYJZKfbJnnHL/xITTs4bacBCQ/mldu2mS4yKBIyD/g3dhFjlqt6WAEK2oZY93x7KVeizhkJvxcj2QrrVR8WbxGrbR7z29Uhb3wbhfl1BUqIUI5zdC2xJP3w7jktRmo89OqWnFhqhfY9iz7iiimQJQ7ClbhcQLuqaTCZUqfEnqrXS/wnVWWeGXoe9vOXYOKOeTt9UOSfaViwBiwpY1S6vzvGrisqsyJUkUTBHSjl1VnsLzojoCm0xjdf3Xp/xYUI3hu8I4DYeZOARDj8WtRhUuw5Yp9FokyiRdctr5maBVxQK3CYRAMlYTw8xCdatgvFO96Rtd8VRXUcuPS0afKVJRW8PI1JVwqVpXnn9u3U61K+VoF2jrP/QzPlhdXNboQNuZMGkYAyAA70bkg7zogl8JG9DOg9ZU7ccAwUgQvA+VQbgQiT9SNMeou7UTORkm/qglGTwGpKRzQRiNYOeHLVELu80alzcT2VfkEREOSIh+ukBJGPdWM8gX+8IGjTGh3jJZcgoCVtoSLSscpCLeTG3ksEsfcR9UJ0z+nu9vyTXn3NkvR/zfxHFCgeLhcshC95w5Fnjnd9YuwVOOw3V/k0FZ0SxGmLKnmZogAaWlwl+mY2mTRTnrKPokbsPJaltZhFYs1yymzgLWgxUtHX4Iw2BaQ5eZk5Sh50LnwrcSL2y5ZxsSaxjPSj7t756X7YN1lrgS/7Mv11yG8ZylFaTy9izdhMS/Wph X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:34.8633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8313fb04-762a-4b7d-334b-08d9bac3fb7b 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: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1726 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: ZqvBg9eFtkoVkxxsdzoUS0d6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020519; bh=CVsw1Ywii8O+xB8jLEGkEX7OT4zu4LEr3+S5Eb57l9I=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=K14Bj5EbthP4VGRbifxXZE4N9lM3kXcgShpnOb4wr4rVh+uB6YD45rvd4DWgPoybON4 3MbXUN5qY46707iZmK+2QJpCX8T803RrNPPTylfYe4YCn27559U1JrqCd0FG2YVelad4g ZlF5eFvOw46krJidOhBfxNp4fYO2cg/DSbI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020521483100008 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The SEV-SNP guest requires that GHCB GPA must be registered before using. See the GHCB specification section 2.3.2 for more details. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/AmdSev.c | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 3991edfd1e82..f66e0a7f4a10 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -19,9 +19,90 @@ #include #include #include +#include =20 #include "Platform.h" =20 +/** + Handle an SEV-SNP/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-SNP gue= st + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +STATIC +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D ReasonCode; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + + This function can be used to register the GHCB GPA. + + @param[in] Address The physical address to be registered. + +**/ +STATIC +VOID +GhcbRegister ( + IN EFI_PHYSICAL_ADDRESS Address + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + MSR_SEV_ES_GHCB_REGISTER CurrentMsr; + + // + // Save the current MSR Value + // + CurrentMsr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + // + // Use the GHCB MSR Protocol to request to register the GPA. + // + Msr.GhcbPhysicalAddress =3D Address & ~EFI_PAGE_MASK; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + // + // If hypervisor responded with a different GPA than requested then fail. + // + if ((Msr.GhcbGpaRegister.Function !=3D GHCB_INFO_GHCB_GPA_REGISTER_RESPO= NSE) || + ((Msr.GhcbPhysicalAddress & ~EFI_PAGE_MASK) !=3D Address)) + { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + // + // Restore the MSR + // + AsmWriteMsr64 (MSR_SEV_ES_GHCB, CurrentMsr.GhcbPhysicalAddress); +} + /** =20 Initialize SEV-ES support if running as an SEV-ES guest. @@ -115,6 +196,13 @@ AmdSevEsInitialize ( GhcbBackupBase )); =20 + // + // SEV-SNP guest requires that GHCB GPA must be registered before using = it. + // + if (MemEncryptSevSnpIsEnabled ()) { + GhcbRegister (GhcbBasePa); + } + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); =20 // --=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 (#84552): https://edk2.groups.io/g/devel/message/84552 Mute This Topic: https://groups.io/mt/87605536/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 Sat May 4 15:08:10 2024 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+84553+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020521498676.9438355346243; Wed, 8 Dec 2021 19:28:41 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AA5QYY1788612xuXBKlOrnsV; Wed, 08 Dec 2021 19:28:40 -0800 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.84]) by mx.groups.io with SMTP id smtpd.web11.6933.1639020520145881993 for ; Wed, 08 Dec 2021 19:28:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxNJRFYATYnt7OI4jfCkYpSnOk7uFslt4yqeKHv0KD2Ppm52IUSBh2zywGRV9rGv5wR7PjgB5v+rM63OXfLkKeGQYaoZfiSJVe3S2Nc5igHTO61aN9NISJg5CnKyom1Yc4auY5/WP8upc5pE9WwVgqddQ5IQpfX7/cea2VWs67lnFSv4JonTiHEUfxkxxQa3sLQYRv6qFxa6Jmn/L0hI9Mg0jq5GfQ/tFuw+tFGqdPEO2afF33XDw9Ie0kcpEoTl112GWj/G/vXY8BadLNSAsG6H0TpU24tbSkoBUOOKKbLn/vnxzXxuKYqscBeRUezDAuacTg/bHvFyCdiw4RZQVQ== 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=tBIjdlif3jDC5AnHBz/Vnt5lCzOXzPiePQJonZxr5Gw=; b=I4nLo1eF9H+YLAQJHFE0bsq23RQQIgw2tt/tsK9Kl88q/VjHh4M0dwJnnD9/ZWRXAtOBvTfZ1psTpkATFr5VEZtBPbTFF4S18V7AYFzM9c0XKrPiCYSfQqHzoao6X1b/oy3+fJyUPVyy3/ejlhv59ZqX7A5Fs6x5l9ZNy31J2LLBxL2fKmlDGsVgYG/z5QcUwXdFcAqIqEIIfTCedZzZGfqluP67hyg/PWmKowwPiNllpPHykppZK/UArd2Uei/oc12Kphn4GPzx81uHA6uqQDWK5lUhw5vWjCG3dH9FallFv07xubvXmfprxang4fRkUAwqvPmXb4ul++YbJuwujQ== 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 MWHPR07CA0016.namprd07.prod.outlook.com (2603:10b6:300:116::26) by MN2PR12MB3790.namprd12.prod.outlook.com (2603:10b6:208:164::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:35 +0000 X-Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::be) by MWHPR07CA0016.outlook.office365.com (2603:10b6:300:116::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.19 via Frontend Transport; Thu, 9 Dec 2021 03:28:35 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84553+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) 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:28:35 +0000 X-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:28:32 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao , Laszlo Ersek Subject: [edk2-devel] [PATCH v14 13/32] OvmfPkg/AmdSevDxe: do not use extended PCI config space Date: Wed, 8 Dec 2021 21:27:41 -0600 Message-ID: <20211209032800.3802995-14-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a0de34e-f133-4429-72a0-08d9bac3fbc5 X-MS-TrafficTypeDiagnostic: MN2PR12MB3790:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:773; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: bCBVnA1VYt22KtCB9jIDagYxJU5AtC6XybQ+8FUf23eCIumwfQ4PJSb65Je+7tl+7+vAkNvZ2Hs6u+lK34CcRBPtyanbCofOPMkFqmd56qNK01qyJiOFHynAkyHK5r2lQfXF+urolKXTumyhrSIxww9MrxbhIJ7LiSRXVGspY0vI57BWt97QIoVj1WmqLvfP2HPH8XmAfibLrtFV+xBuTETHAXEgvv4wSnCa4RXhKDAgf301CZ1VCOzdfJtkkaXAdv2UYh5nTU7/JsGwDw8hU5vhqkP8/9zept3okhmeqeQy8hTRcacI3Ve6lZcXpktDC4C8rka3f4pP7l42ltQEYrNAKew73IDnkzZhIvfELb3xL1VKFcZJ+u+qAJTdUnS4tRXbRPPx2B3aaw+y8XoKhNJzVYTxmNiufiCxHwcMCCAB4rApZQN1/dlZE6tMkopNJP1tWVeWUiSDeatYw4SLdHIHZCGerGzE7Wmm5lcz7R5fUCRwm1yqKtx9Y+u2jUj5VjS34BggTNggRwKP4AUDuhyPrFv6IusHozecO24MLKQgTYJbHc42T2SgqhVunRyc/FdjtG64SREqgJa7ZrF05AxBJ1jySPsKNKoxg2ZNgynB15cRFAdkODcmKJACBSQmIJOisW1vYYQTmi/KESfR3ty2Z1XMb8NRjIIH+FWkjfpSgN0/jKC9DZxXmsv0bt418MJvNF2iPL+h+73EkiplZa8be7Cidm62JmvqUuE48o7vd5LwiLDNnx/Hks6/KhsSgJ+Xe5JhAW6fDe3E2esfrURkuw7+xS454B1XYno9QeRCwCe4f16ELG/kietdZfk3b5M9IDPwSkPE0LfxmjHbA/ySjjuYMsWE1zbEi6Ad1MBYHMYVg4xqHV6YkrOtzavY X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:35.3498 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a0de34e-f133-4429-72a0-08d9bac3fbc5 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: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3790 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: gYKfkdDuM8i0do8GSk57YzP2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020520; bh=mjWAfcB2zS7n6ZjmsnodBIV4rdKa6ESodd5JFR0QGbI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fjTjyQLuoJaU5a5+X9aA7rYDa1VuWQqUaoKb/afYweAi6l/zWuaGh2sWYTzpB8mUxY3 NMl2qylpAuhPNffafSKMQhNhW+kinYwNY+aG+aV99+KhFofy88Z3tS05l32FuFvRUhzJz y225OLYXLQLqdiBhdXmmoQayOh0B0oP7uYU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020523598100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Commit 85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 added support to ensure that MMIO is only performed against the un-encrypted memory. If MMIO is performed against encrypted memory, a #GP is raised. The AmdSevDxe uses the functions provided by the MemEncryptSevLib to clear the memory encryption mask from the page table. If the MemEncryptSevLib is extended to include VmgExitLib then depedency chain will look like this: OvmfPkg/AmdSevDxe/AmdSevDxe.inf Acked-by: Gerd Hoffmann Acked-by: Jiewen Yao Suggested-by: Laszlo Ersek -----> MemEncryptSevLib class -----> "OvmfPkg/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf" instance -----> VmgExitLib class -----> "OvmfPkg/VmgExitLib" instance -----> LocalApicLib class -----> "UefiCpuPkg/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf" instance -----> TimerLib class -----> "OvmfPkg/AcpiTimerLib/DxeAcpiTimerLib.inf" instance -----> PciLib class -----> "OvmfPkg/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf" instance -----> PciExpressLib class -----> "MdePkg/BasePciExpressLib/BasePciExpressLib.inf" instance The LocalApicLib provides a constructor that gets called before the AmdSevDxe can clear the memory encryption mask from the MMIO regions. When running under the Q35 machine type, the call chain looks like this: AcpiTimerLibConstructor () [AcpiTimerLib] PciRead32 () [DxePciLibI440FxQ35] PciExpressRead32 () [PciExpressLib] The PciExpressRead32 () reads the MMIO region. The MMIO regions are not yet mapped un-encrypted, so the check introduced in the commit 85b8eac59b8c5bd9c7eb9afdb64357ce1aa2e803 raises a #GP. The AmdSevDxe driver does not require the access to the extended PCI config space. Accessing a normal PCI config space, via IO port should be sufficent. Use the module-scope override to make the AmdSevDxe use the BasePciLib instead of BasePciExpressLib so that PciRead32 () uses the IO ports instead of the extended config space. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Suggested-by: Laszlo Ersek Signed-off-by: Brijesh Singh --- OvmfPkg/AmdSev/AmdSevX64.dsc | 5 ++++- OvmfPkg/Bhyve/BhyveX64.dsc | 5 ++++- OvmfPkg/OvmfPkgIa32X64.dsc | 5 ++++- OvmfPkg/OvmfPkgX64.dsc | 5 ++++- OvmfPkg/OvmfXen.dsc | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 5ee54451169b..2997929faa05 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -816,7 +816,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 # diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index d8fe607d1cf7..f45634996247 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -790,7 +790,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 =20 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 71227d1b709a..13d9a1f111bc 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -969,7 +969,10 @@ [Components.X64] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 52f7598cf1c7..97b7cb40ff88 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -967,7 +967,10 @@ [Components] !endif =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index a31519e356b7..383cb03d2a14 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -729,7 +729,10 @@ [Components] } =20 OvmfPkg/PlatformDxe/Platform.inf - OvmfPkg/AmdSevDxe/AmdSevDxe.inf + OvmfPkg/AmdSevDxe/AmdSevDxe.inf { + + PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf + } OvmfPkg/IoMmuDxe/IoMmuDxe.inf =20 # --=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 (#84553): https://edk2.groups.io/g/devel/message/84553 Mute This Topic: https://groups.io/mt/87605538/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 Sat May 4 15:08:10 2024 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+84551+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020519480600.316609622844; Wed, 8 Dec 2021 19:28:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id macuYY1788612xx2jZkgtc4e; Wed, 08 Dec 2021 19:28:39 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.78]) by mx.groups.io with SMTP id smtpd.web12.6756.1639020518447031144 for ; Wed, 08 Dec 2021 19:28:38 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EbrMXRW0z6PUMIR5SKX6muyTGmsDy8BxWpkwVkjJuQwVGcqvF2jdGv+WBEVTTjzrmPvo8jWIxhuIIADgAEY/32PrX0x9h9iT2hX33jcJ/cyLr+1YPWu72TTwwVDN1QKYmcNwQv7vc3GjtXqbHeyALIxr3gW2tKandTxXzBRe+a114HKKorDP+1r86MHa8VMeDkgcJjWb6UolVo8yPGT34vnUPPnobHYP1vqwsgaww8tIYvSXE/eFEx+4qypmLofeJtFeowmUbs0jgIPYyAsm/Kc32dmprNa5eSOl/T466Uplpya+Ze/1326QH3QYr2WjJkSGTroeX078akZ2SuNisg== 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=AVPnBMr/Pdx/WH0tAf+gZUlU4+7be2Jlg3gVPfvzXBA=; b=XSyNI3FZJlLqTQLU04CX78CThJQb+Q5Q/zII6cPyaMpWXfkuMuYI8pE+9dPqmhqwkxq4A+CgamNYsciIpBRIDi67ttlYZc+ABYvleZLnbyG4d1PEItyEYFM9bJQsBIzoY6iX8zlA/lyKCAoJouPfe/a5zKWjcCTQyhKKTCY54iRBue/USEiQifD3iJUZs6CwDjr/izNcuOkboUXbAdlDtiymrZBjktIYp0Uq92mCbTUHMDzvutLUsX88tAfcUn+ECk/mFidPePGpZixB5R6LPffCaDpo3mlfpzH+JV9IUsaTetz4bRt3WpJc8W3Q2BckRwESSOP9Xe4Ic3CDMVk2Xw== 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 MWHPR07CA0019.namprd07.prod.outlook.com (2603:10b6:300:116::29) by DM4PR12MB5245.namprd12.prod.outlook.com (2603:10b6:5:398::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:36 +0000 X-Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::93) by MWHPR07CA0019.outlook.office365.com (2603:10b6:300:116::29) 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:28:36 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84551+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) 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:28:36 +0000 X-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:28:34 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 14/32] OvmfPkg/MemEncryptSevLib: add support to validate system RAM Date: Wed, 8 Dec 2021 21:27:42 -0600 Message-ID: <20211209032800.3802995-15-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cb2debaf-59d1-4471-0e18-08d9bac3fc38 X-MS-TrafficTypeDiagnostic: DM4PR12MB5245:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: rPRgr6DP6dzajIm2CSziStNf6IDWpsruSSQA73em10na/PUUwjv6YUJacNyDyFi4qgzOMKZ6r8LLQvSB7FzMGTOBANEE8ug9NgVnswAM8TsFdXmHOqXDJFSJEeYcRbU1BVcX0worQsfpzg06Len6Pyvg6XjVDenLxvpOTnaqUKyfb6iQk5HYfPlFrMYwXJluwWkbqlNsmZDDhg7oxRgjsIm2K8gbJsMxuT/PPnabqtTz3EC2o8MTysuqEf+/jrYuRd7Qpx7XbxWLBJ2lguK30UhYCwu1k+/SEw25PPWEsTpf0c/LFRCrsztZOk976JVp9zXmUfhZ38nqQ4q/eA33Nqvrk/Iu7fT2JwwHxYOYOE64dEtxz+2+m2mCxZe2Wy29Lk/eGuwyRBI8ISjuzpUmGJ0kdxKVwBUv3d/OOGnsmfPqikfvKoTUIDo++Xij2INx2IQ8bK9s7Mpe8zd2TavychBFLKSdpNwNIq5n/A+kFimGNd6o0yzoEbUiCO/eRXU7qYUyIq2HuiTpNAPLZhZ0o894/owqWEInIPku0P5B51bVwpDdrcIFHp2nXgCeuatmKmJwzsWW/+BhTjFwSlgoD2I7tO1U5OQ51ND6pieoOs2x9N/sFu/GFMYhR+vEqi6oj1ZxIjyU5FjDZ4n1itE9Ngf3bitfiOMync693mzhMBDRVRBRpA+maoi6hcyo8YpxAzi+eJcxcDZ9c9hsthWdH1oftdIFFQ8UN6zfAYN2qfnTOUkyvCcjzYsbo8g5ZnqulwwclwDH/87F94SDwrWNvix7gY9/m7sUMg10vVIrk4Z1VEQaXW1P1SVQMrx9sk3Tf5rwx1hMFxXUanROpyOpo4a+BuBPDkJvX1Ip698fJl0p4z+CmbjToOUznMuSpwxE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:36.1009 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cb2debaf-59d1-4471-0e18-08d9bac3fc38 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: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5245 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: Enrk0aS3GQuT00Za4l9mwjc4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020519; bh=EY4ppuYAQ+hEGoohqT58V5j5PrpJekYcRXLaTOn1Yr0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Brcb4gjjqkb8eU2Xd30lSSKkZEtnyTWspKFdC60IYBdS8mWx9Y8m0v9YPA6/0Gok9CO ZyXUOsKxjS68ovtNaxFgXG1k+wFqMaShhMBVRNGOqN6iGBQcNbdB6FE261mIMXBtcu0Ts MVrUoSrtCwOnFqFtLswdvhRKZAASA78inDM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020521442100005 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Many of the integrity guarantees of SEV-SNP are enforced through the Reverse Map Table (RMP). Each RMP entry contains the GPA at which a particular page of DRAM should be mapped. The guest can request the hypervisor to add pages in the RMP table via the Page State Change VMGEXIT defined in the GHCB specification section 2.5.1 and 4.1.6. Inside each RMP entry is a Validated flag; this flag is automatically cleared to 0 by the CPU hardware when a new RMP entry is created for a guest. Each VM page can be either validated or invalidated, as indicated by the Validated flag in the RMP entry. Memory access to a private page that is not validated generates a #VC. A VM can use the PVALIDATE instruction to validate the private page before using it. During the guest creation, the boot ROM memory is pre-validated by the AMD-SEV firmware. The MemEncryptSevSnpValidateSystemRam() can be called during the SEC and PEI phase to validate the detected system RAM. One of the fields in the Page State Change NAE is the RMP page size. The page size input parameter indicates that either a 4KB or 2MB page should be used while adding the RMP entry. During the validation, when possible, the MemEncryptSevSnpValidateSystemRam() will use the 2MB entry. A hypervisor backing the memory may choose to use the different page size in the RMP entry. In those cases, the PVALIDATE instruction should return SIZEMISMATCH. If a SIZEMISMATCH is detected, then validate all 512-pages constituting a 2MB region. Upon completion, the PVALIDATE instruction sets the rFLAGS.CF to 0 if instruction changed the RMP entry and to 1 if the instruction did not change the RMP entry. The rFlags.CF will be 1 only when a memory region is already validated. We should not double validate a memory as it could lead to a security compromise. If double validation is detected, terminate the boot. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + .../DxeMemEncryptSevLib.inf | 3 + .../PeiMemEncryptSevLib.inf | 3 + .../SecMemEncryptSevLib.inf | 3 + OvmfPkg/Include/Library/MemEncryptSevLib.h | 14 + .../X64/SnpPageStateChange.h | 30 ++ .../Ia32/MemEncryptSevLib.c | 17 + .../X64/DxeSnpSystemRamValidate.c | 40 +++ .../X64/PeiSnpSystemRamValidate.c | 36 +++ .../X64/SecSnpSystemRamValidate.c | 36 +++ .../X64/SnpPageStateChangeInternal.c | 301 ++++++++++++++++++ 12 files changed, 485 insertions(+) create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateCh= ange.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateCh= angeInternal.c diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 6a5be97c059d..1dc069e42420 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -266,6 +266,7 @@ [LibraryClasses.common.SEC] !else CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLi= b.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 13d9a1f111bc..a766457e6bc6 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -270,6 +270,7 @@ [LibraryClasses.common.SEC] !else CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf !endif + MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLi= b.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index f2e162d68076..f613bb314f5f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -34,8 +34,10 @@ [Sources] PeiDxeMemEncryptSevLibInternal.c =20 [Sources.X64] + X64/DxeSnpSystemRamValidate.c X64/MemEncryptSevLib.c X64/PeiDxeVirtualMemory.c + X64/SnpPageStateChangeInternal.c X64/VirtualMemory.c X64/VirtualMemory.h =20 @@ -49,6 +51,7 @@ [LibraryClasses] DebugLib MemoryAllocationLib PcdLib + VmgExitLib =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 03a78c32df28..0402e49a1028 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -36,6 +36,8 @@ [Sources] [Sources.X64] X64/MemEncryptSevLib.c X64/PeiDxeVirtualMemory.c + X64/PeiSnpSystemRamValidate.c + X64/SnpPageStateChangeInternal.c X64/VirtualMemory.c X64/VirtualMemory.h =20 @@ -49,6 +51,7 @@ [LibraryClasses] DebugLib MemoryAllocationLib PcdLib + VmgExitLib =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf index 279c38bfbc2c..939af0a91ea4 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf @@ -35,6 +35,8 @@ [Sources] [Sources.X64] X64/MemEncryptSevLib.c X64/SecVirtualMemory.c + X64/SecSnpSystemRamValidate.c + X64/SnpPageStateChangeInternal.c X64/VirtualMemory.c X64/VirtualMemory.h =20 @@ -46,6 +48,7 @@ [LibraryClasses] CpuLib DebugLib PcdLib + VmgExitLib =20 [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 3c77d71df754..4fa9c0d70083 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -214,4 +214,18 @@ MemEncryptSevClearMmioPageEncMask ( IN UINTN NumPages ); =20 +/** + Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. + + @param[in] BaseAddress Base address + @param[in] NumPages Number of pages starting from the ba= se address + +**/ +VOID +EFIAPI +MemEncryptSevSnpPreValidateSystemRam ( + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ); + #endif // _MEM_ENCRYPT_SEV_LIB_H_ diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h = b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h new file mode 100644 index 000000000000..b396f0ffbd75 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h @@ -0,0 +1,30 @@ +/** @file + + SEV-SNP Page Validation functions. + + Copyright (c) 2021 AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SNP_PAGE_STATE_INTERNAL_H_ +#define SNP_PAGE_STATE_INTERNAL_H_ + +// +// SEV-SNP Page states +// +typedef enum { + SevSnpPagePrivate, + SevSnpPageShared, +} SEV_SNP_PAGE_STATE; + +VOID +InternalSetPageState ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages, + IN SEV_SNP_PAGE_STATE State, + IN BOOLEAN UseLargeEntry + ); + +#endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b= /OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c index 9bd66301fc08..f92299fc773b 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c @@ -136,3 +136,20 @@ MemEncryptSevClearMmioPageEncMask ( // return RETURN_UNSUPPORTED; } + +/** + Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. + + @param[in] BaseAddress Base address + @param[in] NumPages Number of pages starting from the ba= se address + +**/ +VOID +EFIAPI +MemEncryptSevSnpPreValidateSystemRam ( + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + ASSERT (FALSE); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c new file mode 100644 index 000000000000..d3a95e4913b9 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c @@ -0,0 +1,40 @@ +/** @file + + SEV-SNP Page Validation functions. + + Copyright (c) 2021 AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +#include "SnpPageStateChange.h" + +/** + Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. + + @param[in] BaseAddress Base address + @param[in] NumPages Number of pages starting from the ba= se address + +**/ +VOID +EFIAPI +MemEncryptSevSnpPreValidateSystemRam ( + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + // + // All the pre-validation must be completed in the PEI phase. + // + ASSERT (FALSE); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c new file mode 100644 index 000000000000..bc891c2636d6 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -0,0 +1,36 @@ +/** @file + + SEV-SNP Page Validation functions. + + Copyright (c) 2021 AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include "SnpPageStateChange.h" + +/** + Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. + + @param[in] BaseAddress Base address + @param[in] NumPages Number of pages starting from the ba= se address + +**/ +VOID +EFIAPI +MemEncryptSevSnpPreValidateSystemRam ( + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c new file mode 100644 index 000000000000..bc891c2636d6 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c @@ -0,0 +1,36 @@ +/** @file + + SEV-SNP Page Validation functions. + + Copyright (c) 2021 AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +#include "SnpPageStateChange.h" + +/** + Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. + + @param[in] BaseAddress Base address + @param[in] NumPages Number of pages starting from the ba= se address + +**/ +VOID +EFIAPI +MemEncryptSevSnpPreValidateSystemRam ( + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c new file mode 100644 index 000000000000..9c552ef5c7b1 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -0,0 +1,301 @@ +/** @file + + SEV-SNP Page Validation functions. + + Copyright (c) 2021 AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "SnpPageStateChange.h" + +#define IS_ALIGNED(x, y) ((((x) & (y - 1)) =3D=3D 0)) +#define PAGES_PER_LARGE_ENTRY 512 + +STATIC +UINTN +MemoryStateToGhcbOp ( + IN SEV_SNP_PAGE_STATE State + ) +{ + UINTN Cmd; + + switch (State) { + case SevSnpPageShared: Cmd =3D SNP_PAGE_STATE_SHARED; + break; + case SevSnpPagePrivate: Cmd =3D SNP_PAGE_STATE_PRIVATE; + break; + default: ASSERT (0); + } + + return Cmd; +} + +STATIC +VOID +SnpPageStateFailureTerminate ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D GHCB_TERMINATE_GHCB_GENERAL; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + This function issues the PVALIDATE instruction to validate or invalidate = the memory + range specified. If PVALIDATE returns size mismatch then it retry validat= ing with + smaller page size. + + */ +STATIC +VOID +PvalidateRange ( + IN SNP_PAGE_STATE_CHANGE_INFO *Info, + IN UINTN StartIndex, + IN UINTN EndIndex, + IN BOOLEAN Validate + ) +{ + UINTN Address, RmpPageSize, Ret, i; + + for ( ; StartIndex <=3D EndIndex; StartIndex++) { + // + // Get the address and the page size from the Info. + // + Address =3D Info->Entry[StartIndex].GuestFrameNumber << EFI_PAGE_S= HIFT; + RmpPageSize =3D Info->Entry[StartIndex].PageSize; + + Ret =3D AsmPvalidate (RmpPageSize, Validate, Address); + + // + // If we fail to validate due to size mismatch then try with the + // smaller page size. This senario will occur if the backing page in + // the RMP entry is 4K and we are validating it as a 2MB. + // + if ((Ret =3D=3D PVALIDATE_RET_SIZE_MISMATCH) && (RmpPageSize =3D=3D Pv= alidatePageSize2MB)) { + for (i =3D 0; i < PAGES_PER_LARGE_ENTRY; i++) { + Ret =3D AsmPvalidate (PvalidatePageSize4K, Validate, Address); + if (Ret) { + break; + } + + Address =3D Address + EFI_PAGE_SIZE; + } + } + + // + // If validation failed then do not continue. + // + if (Ret) { + DEBUG (( + DEBUG_ERROR, + "%a:%a: Failed to %a address 0x%Lx Error code %d\n", + gEfiCallerBaseName, + __FUNCTION__, + Validate ? "Validate" : "Invalidate", + Address, + Ret + )); + SnpPageStateFailureTerminate (); + } + } +} + +STATIC +EFI_PHYSICAL_ADDRESS +BuildPageStateBuffer ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN EFI_PHYSICAL_ADDRESS EndAddress, + IN SEV_SNP_PAGE_STATE State, + IN BOOLEAN UseLargeEntry, + IN SNP_PAGE_STATE_CHANGE_INFO *Info + ) +{ + EFI_PHYSICAL_ADDRESS NextAddress; + UINTN i, RmpPageSize; + + // Clear the page state structure + SetMem (Info, sizeof (*Info), 0); + + i =3D 0; + NextAddress =3D EndAddress; + + // + // Populate the page state entry structure + // + while ((BaseAddress < EndAddress) && (i < SNP_PAGE_STATE_MAX_ENTRY)) { + // + // Is this a 2MB aligned page? Check if we can use the Large RMP entry. + // + if (UseLargeEntry && IS_ALIGNED (BaseAddress, SIZE_2MB) && + ((EndAddress - BaseAddress) >=3D SIZE_2MB)) + { + RmpPageSize =3D PvalidatePageSize2MB; + NextAddress =3D BaseAddress + SIZE_2MB; + } else { + RmpPageSize =3D PvalidatePageSize4K; + NextAddress =3D BaseAddress + EFI_PAGE_SIZE; + } + + Info->Entry[i].GuestFrameNumber =3D BaseAddress >> EFI_PAGE_SHIFT; + Info->Entry[i].PageSize =3D RmpPageSize; + Info->Entry[i].Operation =3D MemoryStateToGhcbOp (State); + Info->Entry[i].CurrentPage =3D 0; + Info->Header.EndEntry =3D (UINT16)i; + + BaseAddress =3D NextAddress; + i++; + } + + return NextAddress; +} + +STATIC +VOID +PageStateChangeVmgExit ( + IN GHCB *Ghcb, + IN SNP_PAGE_STATE_CHANGE_INFO *Info + ) +{ + EFI_STATUS Status; + + // + // As per the GHCB specification, the hypervisor can resume the guest be= fore + // processing all the entries. Checks whether all the entries are proces= sed. + // + // The stragtegy here is to wait for the hypervisor to change the page + // state in the RMP table before guest access the memory pages. If the + // page state was not successful, then later memory access will result + // in the crash. + // + while (Info->Header.CurrentEntry <=3D Info->Header.EndEntry) { + Ghcb->SaveArea.SwScratch =3D (UINT64)Ghcb->SharedBuffer; + VmgSetOffsetValid (Ghcb, GhcbSwScratch); + + Status =3D VmgExit (Ghcb, SVM_EXIT_SNP_PAGE_STATE_CHANGE, 0, 0); + + // + // The Page State Change VMGEXIT can pass the failure through the + // ExitInfo2. Lets check both the return value as well as ExitInfo2. + // + if ((Status !=3D 0) || (Ghcb->SaveArea.SwExitInfo2)) { + SnpPageStateFailureTerminate (); + } + } +} + +/** + The function is used to set the page state when SEV-SNP is active. The pa= ge state + transition consist of changing the page ownership in the RMP table, and u= sing the + PVALIDATE instruction to update the Validated bit in RMP table. + + When the UseLargeEntry is set to TRUE, then function will try to use the = large RMP + entry (whevever possible). + */ +VOID +InternalSetPageState ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages, + IN SEV_SNP_PAGE_STATE State, + IN BOOLEAN UseLargeEntry + ) +{ + GHCB *Ghcb; + EFI_PHYSICAL_ADDRESS NextAddress, EndAddress; + MSR_SEV_ES_GHCB_REGISTER Msr; + BOOLEAN InterruptState; + SNP_PAGE_STATE_CHANGE_INFO *Info; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + EndAddress =3D BaseAddress + EFI_PAGES_TO_SIZE (NumPages); + + DEBUG (( + DEBUG_VERBOSE, + "%a:%a Address 0x%Lx - 0x%Lx State =3D %a LargeEntry =3D %d\n", + gEfiCallerBaseName, + __FUNCTION__, + BaseAddress, + EndAddress, + State =3D=3D SevSnpPageShared ? "Shared" : "Private", + UseLargeEntry + )); + + while (BaseAddress < EndAddress) { + UINTN CurrentEntry, EndEntry; + + // + // Initialize the GHCB + // + VmgInit (Ghcb, &InterruptState); + + // + // Build the page state structure + // + Info =3D (SNP_PAGE_STATE_CHANGE_INFO *)Ghcb->SharedBuffer; + NextAddress =3D BuildPageStateBuffer ( + BaseAddress, + EndAddress, + State, + UseLargeEntry, + Info + ); + + // + // Save the current and end entry from the page state structure. We ne= ed + // it later. + // + CurrentEntry =3D Info->Header.CurrentEntry; + EndEntry =3D Info->Header.EndEntry; + + // + // If the caller requested to change the page state to shared then + // invalidate the pages before making the page shared in the RMP table. + // + if (State =3D=3D SevSnpPageShared) { + PvalidateRange (Info, CurrentEntry, EndEntry, FALSE); + } + + // + // Invoke the page state change VMGEXIT. + // + PageStateChangeVmgExit (Ghcb, Info); + + // + // If the caller requested to change the page state to private then + // validate the pages after it has been added in the RMP table. + // + if (State =3D=3D SevSnpPagePrivate) { + PvalidateRange (Info, CurrentEntry, EndEntry, TRUE); + } + + VmgDone (Ghcb, InterruptState); + + BaseAddress =3D NextAddress; + } +} --=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 (#84551): https://edk2.groups.io/g/devel/message/84551 Mute This Topic: https://groups.io/mt/87605535/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 Sat May 4 15:08:10 2024 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+84554+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020522387121.19596532401135; Wed, 8 Dec 2021 19:28:42 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lKtRYY1788612xXQC8RLfA5p; Wed, 08 Dec 2021 19:28:41 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.71]) by mx.groups.io with SMTP id smtpd.web12.6758.1639020521061239946 for ; Wed, 08 Dec 2021 19:28:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qvpk9RTWfMfWjHJwYF109LLP7b+TynQjOj69eAPBDqgYWi2ntGxbPqacjhc8MAC1ovNsgke1SOT6bUkQTLHE1v12hM2quygwvAijG0C07IvLOZFbYePAKa1fL4AYhKOlP9oUSReuZ5cjwE+bXNnZnsCwUnYwoKKE3Vlkiatnj0YxGRcdaVnFvqxQz/7zw77weTzIM4a8XPJAH9NOZpqVEyQCl/Xi5+/QLhhJBe6w7sBRiUA+12jxr9m0rS5q7YGND9fh5TjzSd3yIx0ijgThx+BY7a1aGWpj5Se1tuf1vN4reE9Vj2Fo8wneCeq2MIJ4vB0onIbNYpLW8PF0b7mmSQ== 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=aXvVEzyHGTZIdoV2SshsD5xZqtL7LpgyPP2I8GyuDaI=; b=OK4OvEcRxPkD1LnRHhMyb+SlpQCG2JejmYhOxvqTSaLCIzwDd+R3mPO3kPevOW7f6/r5yNPtnpAnOOWCwBAftYR9h1PYKWns2D7dBebObkIxXQ2r9/6M3PmAy6z7kSMN1rX1N+8SxulUfJapziFm25IyeCUARWD14Zy290X9dVensi8ZkxAP9nlSmQAhUDAe1CB5bKd6a4sdE0fhVQzbfhnoN5L7VoFjgqT9ED3OAW/FbnETrgrMO9z6bmCLEjzs4iF2rXZtIuik6baYAgH9XJl5uTZoapV06/EIYutHCoPlMibzO3585bsSdj71cB9ESapxo9G94++46XpO0+p8qg== 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 MW4P223CA0018.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::23) by DM6PR12MB4028.namprd12.prod.outlook.com (2603:10b6:5:1ce::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:38 +0000 X-Received: from CO1NAM11FT012.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::b2) by MW4P223CA0018.outlook.office365.com (2603:10b6:303:80::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:28:38 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84554+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT012.mail.protection.outlook.com (10.13.175.192) 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:28:38 +0000 X-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:28:35 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 15/32] OvmfPkg/MemEncryptSevLib: add function to check the VMPL0 Date: Wed, 8 Dec 2021 21:27:43 -0600 Message-ID: <20211209032800.3802995-16-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a769e35a-0109-4a15-c61b-08d9bac3fd97 X-MS-TrafficTypeDiagnostic: DM6PR12MB4028: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-Message-Info: pV3HMLxbDj7u3rRHVMP9LVNM6z76/EYPtYsjibSWWZr8o3/mKUK0CcUQt8iFA1cZFuaYvYonWwgiKN4rMCaedZy5d4LRQ1XFFLiO+NbNTqj9O1zoKpUBsU0aiunYRvTTwaevE9Xw+6sHCIYf1L4jQWevRBU5ho23eS1qZEqB7cYp4Em8wb4NdJivf+Uwlw/RedjZ4vOV7NNXzqxV/KO/xM0Vg8FQNffVl4q17/sp0IohS/ZY4H7lKvUA/yEiMLF+/OUfeiqXxqR/JoAjNmjYe4q10HLcj6E2fEiUOQl+/AulBwcPO1LjCIVPj2gpTay7RLUJJcjjff/l/3eq7t4d3Os5ruZVWxXKAyIlyjr6N+c4rpJWSc/AExpm6i5TeUo2C5IKU5ehpG9BON7W4HzGBuvdWvi/gmFvKxGFIR6kAtYWSdJMrTIrRbE52LLaUzU7agwrzv4nbzKZNp/ZwcjI/dbDo6VdJGe7Rq2ONNynxYY2FeEfFVibovsYz37eKz+ctD9tpiuXJ8PTVQ4GN+gNpvnRTmOLDVNCv0KxcYzVoTgPh4Z7vJNfCa/ZcnAssjyMAVb3mF4yJsU621gwukvxNSEf6OEaTgNbTUZSRtsOCtf1x4Jn+E7f7ZpA97J1CPUEf32YsAOJon1VAj6v5qrEsxHqa2eUEEaaUufdfFUNbaf2Q9IvQG+2312kfo4erAAjBXyPaKsGrsXmFzz2vPh09eK2Vfqv3qA8HbV1kxcW+YYInoalDAro2SC18hpXEYmvurWrvcCDrrYcA2AjDihGKepDy4cv4+NcGlLEG4TVLmoDCqQJzpNvufngaw35YhbuNvHxvoMGg3yCHPm5/LJB/gf5xWs9FYl8Lws4m+3DM1Fug2jwoHzEF9oWfDBw0vnC X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:38.3935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a769e35a-0109-4a15-c61b-08d9bac3fd97 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: CO1NAM11FT012.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4028 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: Q1Ci91JbWT6dZHLQe1GlRdtwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020521; bh=wqf6OxvRlgCYXHylenLmt+8xKnMSrk3iHpaKDkf2Xlw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=evG1mambmNOq9kgETcZFo4NTD2KorcWCMKUigEEwGFWkohgU01Ac79z4NZiyAAXJskP Tp8PylD9FKxbLQ5dZF9dHmq9nM4xdlQpvcITwu5Qag6Lza3vMUGsqSMg6Cvwf8+q5TsBK rO/gqgBEShcupjSbyegIhnvuAbnPbTU/v2o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020523701100003 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Virtual Machine Privilege Level (VMPL) feature in the SEV-SNP architecture allows a guest VM to divide its address space into four levels. The level can be used to provide the hardware isolated abstraction layers with a VM. The VMPL0 is the highest privilege, and VMPL3 is the least privilege. Certain operations must be done by the VMPL0 software, such as: * Validate or invalidate memory range (PVALIDATE instruction) * Allocate VMSA page (RMPADJUST instruction when VMSA=3D1) The initial SEV-SNP support assumes that the guest is running on VMPL0. Let's add function in the MemEncryptSevLib that can be used for checking whether guest is booted under the VMPL0. Cc: Michael Roth 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 --- .../X64/SnpPageStateChange.h | 5 ++ .../X64/SecSnpSystemRamValidate.c | 46 +++++++++++++++++++ .../X64/SnpPageStateChangeInternal.c | 1 - 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h = b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h index b396f0ffbd75..43319cc9ed17 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h @@ -27,4 +27,9 @@ InternalSetPageState ( IN BOOLEAN UseLargeEntry ); =20 +VOID +SnpPageStateFailureTerminate ( + VOID + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c index bc891c2636d6..7797febb8ac6 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c @@ -14,6 +14,43 @@ =20 #include "SnpPageStateChange.h" =20 +// +// The variable used for the VMPL check. +// +STATIC UINT8 gVmpl0Data[4096]; + +/** + The function checks whether SEV-SNP guest is booted under VMPL0. + + @retval TRUE The guest is booted under VMPL0 + @retval FALSE The guest is not booted under VMPL0 + **/ +STATIC +BOOLEAN +SevSnpIsVmpl0 ( + VOID + ) +{ + UINT64 Rdx; + EFI_STATUS Status; + + // + // There is no straightforward way to query the current VMPL level. + // The simplest method is to use the RMPADJUST instruction to change + // a page permission to a VMPL level-1, and if the guest kernel is + // launched at a level <=3D 1, then RMPADJUST instruction will return + // an error. + // + Rdx =3D 1; + + Status =3D AsmRmpAdjust ((UINT64)gVmpl0Data, 0, Rdx); + if (EFI_ERROR (Status)) { + return FALSE; + } + + return TRUE; +} + /** Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. =20 @@ -32,5 +69,14 @@ MemEncryptSevSnpPreValidateSystemRam ( return; } =20 + // + // The page state change uses the PVALIDATE instruction. The instruction + // can be run on VMPL-0 only. If its not VMPL-0 guest then terminate + // the boot. + // + if (!SevSnpIsVmpl0 ()) { + SnpPageStateFailureTerminate (); + } + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); } diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c index 9c552ef5c7b1..d11aafae8472 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -42,7 +42,6 @@ MemoryStateToGhcbOp ( return Cmd; } =20 -STATIC VOID SnpPageStateFailureTerminate ( VOID --=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 (#84554): https://edk2.groups.io/g/devel/message/84554 Mute This Topic: https://groups.io/mt/87605541/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 Sat May 4 15:08:10 2024 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+84555+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020523638293.16935377294544; Wed, 8 Dec 2021 19:28:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5y8nYY1788612x66SmK0a7dF; Wed, 08 Dec 2021 19:28:43 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.71]) by mx.groups.io with SMTP id smtpd.web10.6827.1639020521896368542 for ; Wed, 08 Dec 2021 19:28:42 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XZG0BZWql7RvkHcNkynWO8K/0vcFibVTwZOuTkK9kr3s0ncV+Va19kTXiwyoved6qZ9JrC/lR1QRDCuZ0Dip32iqWl3A3ev7HHSNRtRgbYP0ZwHd/P/C6V7WcD0meU3gqpUzXaCB0i6739UVZG+puG8Zkw6f3zbcZWm+VVv+lLsqnXj0zjBSRq/gm2eTiW6tt0KzoJp7qKnT8TiqSUHFaYpWmu5BNkC3Q68ZCWl2rHPSzF1IyOlcFsowqjGSL+zidZuSy976f+w9GsjEEhqGW8sEPL4baE/wZOv1y4IE/07vfHo+YoKlya2ke1yBioq0qd7jMK9P8THu3f4mA9TkWQ== 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=33a8S+jyym0cjXHDRsIAsIrMlMGxq8eT0b4QuzHYm88=; b=hLta/DT2348CaJ8XS7yFgntgf4u8FxGzuYLD7u7YmYIKn77kqqkfuJiHzR0Uaj4xxhpAok/bd2gIjHpNYks+1cqLxPz5K9HzpOMlZubuN9GsfSS7ALmBJHEKVzoxfUsPVawBdwJxCzcLG7sy9ENcGVs6zIHT9oddh4ORVqCLmb4Ty2HfG+WKk6eLvplfgcWqAs3pJ8AeNhZWJI3oouMrHKZhe1MYTFsj6vRfZOuXKMjgOXWmBF0K8wLoyFcAVgm/xabq/9VA6OSnVqwlco4u1TYlhvBlqs/U9to33DrLsJUDsKa0NDEtld1w2689vee2cKWNZxIlA8LK3WAQwnNNjQ== 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 MW4P223CA0015.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::20) by BL0PR12MB5508.namprd12.prod.outlook.com (2603:10b6:208:1c1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:40 +0000 X-Received: from CO1NAM11FT012.eop-nam11.prod.protection.outlook.com (2603:10b6:303:80:cafe::5a) by MW4P223CA0015.outlook.office365.com (2603:10b6:303:80::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:28: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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84555+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT012.mail.protection.outlook.com (10.13.175.192) 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:28:39 +0000 X-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:28:37 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 16/32] OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM Date: Wed, 8 Dec 2021 21:27:44 -0600 Message-ID: <20211209032800.3802995-17-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3f8554d-efb3-4b8d-e053-08d9bac3fe34 X-MS-TrafficTypeDiagnostic: BL0PR12MB5508: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-Message-Info: +vy4KWv/XO+sHWpy7sf4KMFdzh/HQfJ51QlDVYyNy/zYrNveOMqVU9VWQdgZPc8qfOhFKyskpB2jbTfakw7bZf50bzk9T6rFpOYmPKsZONzY18p3G3Zo591W35XUeZ1SfB8n8v/m8haT6prxmCBU9ZMiWj3AJggNZWLIFICqGQxU4TP/6Z7XTquWfxwyqNZVqGpf+5nxwbZouUapXBICuzLNuRth4dCiUtw6yTdd/oB4vMu4xc1bdmT2VAnuyYYu86gXyo3ij956fYkFRIfiPCvPbAfG7sSv3m/J35uJGY8Y7RQWjmR2nTmtrrh/5s4TtHxpSkoFj30M8VlO8doFXvuGCIOzGkvciHN9K539VpDwWzzkM10lXplsS5k/BXoGF7RENRtQvxVbtTJjF1OQp25+Xw1JcDcyZ8mBWtfOr2ZAmyafTuoa9AOmLqmifo9+qa1etl56Z0U/9CcqkJrygiZYkDiPInQ2ef/Y7bMk6+yMqgYgi3sIflLWslYNqdaqGuqMdLo8B+XuO85ZfLU+CVimZOuMvizceVv3F9Vc0x+uf1SCBx4HI1enBoIiAOD3OrRYJLZ2PKxNFRIh7rWvvOtwCAOH6c8KrrSZpFqNiWZoifBQrX4DA1TSDnE3c6dYbypRbKsC+93LQ3HGP+WK37MYAmZpRfouM7OE+R4DTzKGSXfNNb2VHiAlaDN7jUtrHfvA0Tuvl6XvnDDUW7b9HiU+zvMqv1K9YXulaFhRVAAg8/yRP8L/qoFchPXjZa0skgwemmNc79Tr2EcazVV1snkAxtD1DFLcgcrtuWmraFHqpBoju0YXXHk1PMW8HYQnnAHmtC3P1NxH4wOTpBwjoQJIJl7acCcLf+KGIX3z2fSPPtK7xT2VU75GBFMytrQ7ciU7fClYcVTveMv9dkrGnw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:39.4226 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3f8554d-efb3-4b8d-e053-08d9bac3fe34 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: CO1NAM11FT012.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5508 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: 1Df4zzkUk2dIDPMUyWvcYgI7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020523; bh=BpF3vpyf3iPpQbMYN4n1gIMehLg3vEF7qhEHRRjBquE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Xf7oBCjULnUShfO8OwOczWSHHhs22ki6+g/494AKwkXV/eEpxLE6/sPijJS0i3pUFHU llGfCydgKiGcSUgcC57WVXqlVsNq9YOIjbCu7AVRn4V+l+gGZPa306LwsVdVAnEnIHWz9 cBv0buNeh2vPFSrUQwkGFV/DulVeespQ0Ms= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020525771100010 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSevSnpPreValidateSystemRam() is used for pre-validating the system RAM. As the boot progress, each phase validates a fixed region of the RAM. In the PEI phase, the PlatformPei detects all the available RAM and calls to pre-validate the detected system RAM. While validating the system RAM in PEI phase, we must skip previously validated system RAM to avoid the double validation. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../PeiMemEncryptSevLib.inf | 2 + .../X64/PeiSnpSystemRamValidate.c | 67 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 0402e49a1028..49d5bd1beff1 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -58,3 +58,5 @@ [FeaturePcd] =20 [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index bc891c2636d6..2d2136f8054c 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -14,6 +14,46 @@ =20 #include "SnpPageStateChange.h" =20 +typedef struct { + UINT64 StartAddress; + UINT64 EndAddress; +} SNP_PRE_VALIDATED_RANGE; + +STATIC SNP_PRE_VALIDATED_RANGE mPreValidatedRange[] =3D { + // The below address range was part of the SEV OVMF metadata, and range + // should be pre-validated by the Hypervisor. + { + FixedPcdGet32 (PcdOvmfSecPageTablesBase), + FixedPcdGet32 (PcdOvmfPeiMemFvBase), + }, +}; + +STATIC +BOOLEAN +DetectPreValidatedOverLap ( + IN PHYSICAL_ADDRESS StartAddress, + IN PHYSICAL_ADDRESS EndAddress, + OUT SNP_PRE_VALIDATED_RANGE *OverlapRange + ) +{ + UINTN i; + + // + // Check if the specified address range exist in pre-validated array. + // + for (i =3D 0; i < ARRAY_SIZE (mPreValidatedRange); i++) { + if ((mPreValidatedRange[i].StartAddress < EndAddress) && + (StartAddress < mPreValidatedRange[i].EndAddress)) + { + OverlapRange->StartAddress =3D mPreValidatedRange[i].StartAddress; + OverlapRange->EndAddress =3D mPreValidatedRange[i].EndAddress; + return TRUE; + } + } + + return FALSE; +} + /** Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. =20 @@ -28,9 +68,34 @@ MemEncryptSevSnpPreValidateSystemRam ( IN UINTN NumPages ) { + PHYSICAL_ADDRESS EndAddress; + SNP_PRE_VALIDATED_RANGE OverlapRange; + if (!MemEncryptSevSnpIsEnabled ()) { return; } =20 - InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); + EndAddress =3D BaseAddress + EFI_PAGES_TO_SIZE (NumPages); + + while (BaseAddress < EndAddress) { + // + // Check if the range overlaps with the pre-validated ranges. + // + if (DetectPreValidatedOverLap (BaseAddress, EndAddress, &OverlapRange)= ) { + // Validate the non-overlap regions. + if (BaseAddress < OverlapRange.StartAddress) { + NumPages =3D EFI_SIZE_TO_PAGES (OverlapRange.StartAddress - BaseAd= dress); + + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TR= UE); + } + + BaseAddress =3D OverlapRange.EndAddress; + continue; + } + + // Validate the remaining pages. + NumPages =3D EFI_SIZE_TO_PAGES (EndAddress - BaseAddress); + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); + BaseAddress =3D EndAddress; + } } --=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 (#84555): https://edk2.groups.io/g/devel/message/84555 Mute This Topic: https://groups.io/mt/87605542/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 Sat May 4 15:08:10 2024 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+84556+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163902052581641.074924981471895; Wed, 8 Dec 2021 19:28:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XRuIYY1788612x96lD9wXd9V; Wed, 08 Dec 2021 19:28:45 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.50]) by mx.groups.io with SMTP id smtpd.web11.6934.1639020524677393468 for ; Wed, 08 Dec 2021 19:28:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EaVwbkeOsq3/H8ioEaSyujzoQUCEORIw7149KwbW118BCLyiWjyHzRXEHWD6cBKNZkx2tSTG47tlTxwrt+x6jz+u5pXMjXtdPm/RnBSFbWZC7HrmzzHebmCp0dcICx25nMQYQdqkq6C3HdduEZ41t7SUb4in+3WScXKY0UdN33ZeH4LnPbOHXIjAFy/iP7lWQXLxM3Gcdj7uk4fUTUjH5+X4CoEwHCYwXpdg2V1Z985knQvrkoNzT1KP6mSSCpnUuFgr+CI7RO7dBoj+RGJJGtBcprsYscT0/Z1syrVjdpZTrkN0vkrqIV4QLOOErGHRcsaUfpGBi3vm6Q0Wv6dzcw== 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=wYPCcP4dXn1ohcWZgEBHwWnMJ61gnfTZ4EBKYo9YkuE=; b=TRW/kLW2hascHW2aKfyK0FOqpck4a9iRHVOpTcgMVWrnZBWFzqHVlbN3iBeP6lEghZpAXvuWbEqTx+y6hIWaYBWzDnfNs0qEImT/a5BmjMgsR+2xhBpeEp6YqrTyXyZVbELYA4wdojb3wHISxE7yObyD2+UfYyqamel+85uqmcdkLIPm+Ds5LwtTlQOAfY35oS3jNwgBE/A6YQqphw5K9muXQDRBHDhocwkpyxNk6E4cu1eVhjiczkvtNFFhAJOiELEG3fqBZFhrktMfw75lBP1j7xNZRManySfiha0K1wIKfRW9SiNJhx0qVL/HkKaiPhMipJyPts21jSgknC4z9Q== 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 MW4PR03CA0273.namprd03.prod.outlook.com (2603:10b6:303:b5::8) by CH2PR12MB3879.namprd12.prod.outlook.com (2603:10b6:610:23::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.22; Thu, 9 Dec 2021 03:28:42 +0000 X-Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b5:cafe::e4) by MW4PR03CA0273.outlook.office365.com (2603:10b6:303:b5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:41 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84556+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) 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:28:41 +0000 X-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:28:38 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 17/32] OvmfPkg/MemEncryptSevLib: add support to validate > 4GB memory in PEI phase Date: Wed, 8 Dec 2021 21:27:45 -0600 Message-ID: <20211209032800.3802995-18-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ffd955b-d5e2-4099-6743-08d9bac3ff98 X-MS-TrafficTypeDiagnostic: CH2PR12MB3879: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-Message-Info: tUnVMltCkugNTlxkbRdstmqwa9KAk7OozBWg+xboGr0cDzZMgicvLRWauf1hN02YnnHgS6gMa8WpAQWeP8ylXiH8Th9bbEiLViqavNsNZWXF051rA2fB3PE2ryg1w8ygerUfUKPygzxWU2BmFdIgdhgtLPdM0tpRgIaFWfYcy5d6QbSq6GRQF8YMcb3Pn6DtLd6r8ALYNjwZCf2ncURjycNX80WHX/Ds2CVAyXIxVKt2n9VMA3odzWpzi7pFF7ypO6EeUGtDa1RZmNESd28mpyEd8ZiO92EQcVvrKpY56r81QeG4yUOwXECey6AQCUIdDu4l3TkKuIhnGV0h7ghXUhrJTaS/CeOPHw+4rM/Pzjt/qrYRtVCTkCOnwniizmgtx5oi/aOctMYjBGmK6sm7/mc8pe2/svFb+RO0fHt85jHqE/sZaDVfwwdmaTOYIIOCxyePL0/uEmEOsEdwNI4aYMuGVSPZyIA7RHtY4Cy2JMmPpI0VD389bH49G6+xUsVL/HHAmjFVDzQmHWizEbCVTDmxfvwO11o/2fDtDuDieoM7a9ZLSfZeDO2xqNRhBVJxkMPNyj9gndIPhrWDuAWCkg/8F0/FnClYuxCyU6oMvksLhb4piPucPFytFXqYHvjhPwUlLjWVuQL5+HCwMdlZgppiKQ4BxkzUJvfnwM2tCjGBjtpHHtJAgK/pQ7AVtbsXIdqVcL2Ga376QtA0fzjvb2RM8GI2YXICFbCaSEzW/DBva1UaFnrHxDnWHcRVOx7YvFbdIt+l9x5l9DfQ6pOOwJVcDE8XyWT4XBVQPMkmCUb5kOS2ImRMObKDbH0hnG5xGI9ePjEimBNwCtt5m6hxxcsj3yqdZlmPR7Id8XRprnW9+ulcL1BpgRhTmQTgbSI/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:41.7640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ffd955b-d5e2-4099-6743-08d9bac3ff98 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: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3879 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: rIFtPEQ2Wc8fFLDlGrPwYGUqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020525; bh=vhjacwjwZkSXmn3EPZx8Wjy+Ah+AhfOjmDWG5DbucVk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UFNTal2g/EN7E6Yrj9vaWRp7VXQQ6Kly6UlloMb0Vm1zhakzRb2XZ4RJe9F6LKiEdl5 XUG5zm6dJJS//2ATG4rG2u0loj4mCpuSA2mlP6EGMlfwpgOdHefpfPp734PPn3hjgj37h q/GyXF47NLoeSOIoVPuOm0/t5uSEssiMvRE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020527948100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The initial page built during the SEC phase is used by the MemEncryptSevSnpValidateSystemRam() for the system RAM validation. The page validation process requires using the PVALIDATE instruction; the instruction accepts a virtual address of the memory region that needs to be validated. If hardware encounters a page table walk failure (due to page-not-present) then it raises #GP. The initial page table built in SEC phase address up to 4GB. Add an internal function to extend the page table to cover > 4GB. The function builds 1GB entries in the page table for access > 4GB. This will provide the support to call PVALIDATE instruction for the virtual address > 4GB in PEI phase. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 24 ++++ .../X64/PeiDxeVirtualMemory.c | 114 ++++++++++++++++++ .../X64/PeiSnpSystemRamValidate.c | 22 ++++ 3 files changed, 160 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h index 93e3d08589d7..ffc7430b2243 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h @@ -144,4 +144,28 @@ InternalMemEncryptSevClearMmioPageEncMask ( IN UINTN Length ); =20 +/** + Create 1GB identity mapping for the specified virtual address range. + + The function is preliminary used by the SEV-SNP page state change + APIs to build the page table required before issuing the PVALIDATE + instruction. The function must be removed after the EDK2 core is + enhanced to do the lazy validation. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] VirtualAddress Virtual address + @param[in] Length Length of virtual address range + + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + +**/ +RETURN_STATUS +EFIAPI +InternalMemEncryptSevCreateIdentityMap1G ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index bbc48ff6d879..f1485722f7cf 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -536,6 +536,120 @@ EnableReadOnlyPageWriteProtect ( AsmWriteCr0 (AsmReadCr0 () | BIT16); } =20 +RETURN_STATUS +EFIAPI +InternalMemEncryptSevCreateIdentityMap1G ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length + ) +{ + PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; + PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; + UINT64 PgTableMask; + UINT64 AddressEncMask; + BOOLEAN IsWpEnabled; + RETURN_STATUS Status; + + // + // Set PageMapLevel4Entry to suppress incorrect compiler/analyzer warnin= gs. + // + PageMapLevel4Entry =3D NULL; + + DEBUG (( + DEBUG_VERBOSE, + "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx\n", + gEfiCallerBaseName, + __FUNCTION__, + Cr3BaseAddress, + PhysicalAddress, + (UINT64)Length + )); + + if (Length =3D=3D 0) { + return RETURN_INVALID_PARAMETER; + } + + // + // Check if we have a valid memory encryption mask + // + AddressEncMask =3D InternalGetMemEncryptionAddressMask (); + if (!AddressEncMask) { + return RETURN_ACCESS_DENIED; + } + + PgTableMask =3D AddressEncMask | EFI_PAGE_MASK; + + // + // Make sure that the page table is changeable. + // + IsWpEnabled =3D IsReadOnlyPageWriteProtected (); + if (IsWpEnabled) { + DisableReadOnlyPageWriteProtect (); + } + + Status =3D EFI_SUCCESS; + + while (Length) { + // + // If Cr3BaseAddress is not specified then read the current CR3 + // + if (Cr3BaseAddress =3D=3D 0) { + Cr3BaseAddress =3D AsmReadCr3 (); + } + + PageMapLevel4Entry =3D (VOID *)(Cr3BaseAddress & ~PgTableMask); + PageMapLevel4Entry +=3D PML4_OFFSET (PhysicalAddress); + if (!PageMapLevel4Entry->Bits.Present) { + DEBUG (( + DEBUG_ERROR, + "%a:%a: bad PML4 for Physical=3D0x%Lx\n", + gEfiCallerBaseName, + __FUNCTION__, + PhysicalAddress + )); + Status =3D RETURN_NO_MAPPING; + goto Done; + } + + PageDirectory1GEntry =3D (VOID *)( + (PageMapLevel4Entry->Bits.PageTableBas= eAddress << + 12) & ~PgTableMask + ); + PageDirectory1GEntry +=3D PDP_OFFSET (PhysicalAddress); + if (!PageDirectory1GEntry->Bits.Present) { + PageDirectory1GEntry->Bits.Present =3D 1; + PageDirectory1GEntry->Bits.MustBe1 =3D 1; + PageDirectory1GEntry->Bits.MustBeZero =3D 0; + PageDirectory1GEntry->Bits.ReadWrite =3D 1; + PageDirectory1GEntry->Uint64 |=3D (UINT64)PhysicalAddress | = AddressEncMask; + } + + if (Length <=3D BIT30) { + Length =3D 0; + } else { + Length -=3D BIT30; + } + + PhysicalAddress +=3D BIT30; + } + + // + // Flush TLB + // + CpuFlushTlb (); + +Done: + // + // Restore page table write protection, if any. + // + if (IsWpEnabled) { + EnableReadOnlyPageWriteProtect (); + } + + return Status; +} + /** This function either sets or clears memory encryption bit for the memory region specified by PhysicalAddress and Length from the current page tab= le diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index 2d2136f8054c..0e3eba3c5121 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -10,9 +10,12 @@ =20 #include #include +#include +#include #include =20 #include "SnpPageStateChange.h" +#include "VirtualMemory.h" =20 typedef struct { UINT64 StartAddress; @@ -70,6 +73,7 @@ MemEncryptSevSnpPreValidateSystemRam ( { PHYSICAL_ADDRESS EndAddress; SNP_PRE_VALIDATED_RANGE OverlapRange; + EFI_STATUS Status; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; @@ -77,6 +81,24 @@ MemEncryptSevSnpPreValidateSystemRam ( =20 EndAddress =3D BaseAddress + EFI_PAGES_TO_SIZE (NumPages); =20 + // + // The page table used in PEI can address up to 4GB memory. If we are as= ked to + // validate a range above the 4GB, then create an identity mapping so th= at the + // PVALIDATE instruction can execute correctly. If the page table entry = is not + // present then PVALIDATE will #GP. + // + if (BaseAddress >=3D SIZE_4GB) { + Status =3D InternalMemEncryptSevCreateIdentityMap1G ( + 0, + BaseAddress, + EFI_PAGES_TO_SIZE (NumPages) + ); + if (EFI_ERROR (Status)) { + ASSERT (FALSE); + CpuDeadLoop (); + } + } + while (BaseAddress < EndAddress) { // // Check if the range overlaps with the pre-validated ranges. --=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 (#84556): https://edk2.groups.io/g/devel/message/84556 Mute This Topic: https://groups.io/mt/87605543/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 Sat May 4 15:08:10 2024 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+84557+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020526248900.0563976396261; Wed, 8 Dec 2021 19:28:46 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 02q6YY1788612x4YnYS73Q7X; Wed, 08 Dec 2021 19:28:45 -0800 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.57]) by mx.groups.io with SMTP id smtpd.web12.6761.1639020524959696983 for ; Wed, 08 Dec 2021 19:28:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D5kSfe2jI3ebtJgYpLKL+e2tZjb3yboZXIhkw9ujxCm0S3z1nhTlQXPpZ6JiInbso3b0czBIPuABIoG50oMH7YSG0B3bTnXMQCZibZ4ykKhirEEtzRYmrkSup0NEfNYUGhQUUGEGzobSuOMTCeA3DkbzI5yTIMnMgbGxq1fNB28cSbXpn+DS6wtJT+UMyn9/jkpr/54JsFVD07OvBOatbqSXrekLbqGcn5/mGiUF8zB8R5QibiykmT04cdp7ehaB3dRHm86agB720WN4ODmxy5LQxUy4L0evSNMwap3OsmzfSY5UHQ9ORekPwMA/aHlPRuGzYGgV7I4gW++nFlbprw== 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=r63e7AvLBPWBkst74vPCYdDwB2c+QNDX/OY6oOjOnrE=; b=MCZ2cWiyXbjE5ta3f832eSJwXeTeUaeY8yJdGywKznz+OhOsO1x8PZi64kC1p5IWbcwj/yX3q/mrFEaSEzAqz8BF0K8b9k1SxuS7CIWeunypHnju5IsSk18jf4kuhZ+DCQ2Q9DoZRiwUXynmz3Is2E0mqfla+nGu/g6uIgB/J6A6u4QU633iA186Jq8WTzx1+gd5LZUFwWmncyTbIGwr7sDt+JYsEe5o/KpIzAEl0CUuNGQj1b1/6MckiHxOVNKST/XRYvFmPPq09XShzUhqxkHnPHRfJDxn1iVr0OAxRvLEiIm/FmWyTTYmMAyj7Jp6j5+RArxxMdpkxoO63wWMig== 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 MW4PR03CA0300.namprd03.prod.outlook.com (2603:10b6:303:b5::35) by SN1PR12MB2397.namprd12.prod.outlook.com (2603:10b6:802:27::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:43 +0000 X-Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b5:cafe::de) by MW4PR03CA0300.outlook.office365.com (2603:10b6:303:b5::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:28:42 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84557+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) 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:28:42 +0000 X-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:28:40 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 18/32] OvmfPkg/SecMain: validate the memory used for decompressing Fv Date: Wed, 8 Dec 2021 21:27:46 -0600 Message-ID: <20211209032800.3802995-19-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da016110-0746-4774-fa9d-08d9bac40030 X-MS-TrafficTypeDiagnostic: SN1PR12MB2397:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: n0kbEzyGFedBiX50XMFbPUGC90xrn9Y4tATURm2/yxF7wLrw47c+LYTYSHBw+ZDq0OSs5nnxIDDjG6j7G1TD2+jBEv0smTs2zrxWJ7vwrvF+unYjtPnf/SHpCi5BXWMQV2O+b7EeWFmgy3e96X6RRWatjsaabm4np5eN24YZ+Ij9i7Yn8yhsnU6BZAK2HQBJTcjZ4sZqq7iThhbEjEelriysKIFOF0XjPEok77gEJLs1HT4QDZZF4jDB9um37uruo6QfjjBdoKioxHDstXjuN4mwjuEt3WKUbeLTY6sJulX+MxiB1aMKsCCpE//OKFFlHDwVDjfOMtC+dXfveqyTkhDvJhlreAs3KJTAwuAAYClGX99rnaZKHDCaNePVV6O05bCzYo5FZOLbVWq2uAEbUn29mKJAHgMAX0LxPyuXzBcuiPd7iyStTlSf8rbl+Ctt2kyPtKTBa90J2ozGrhxRh+dj9IYL17pJKkKcsD4WhoXTFbtiX0PObjqq9En1tILxFyQm0b6dPOvuyad0/2K3trFgLtmKZ3pb6HF65YJ4PukiZrJc5+QMy5GfN/DlHIY9tDnT7k8HlvUx0BRdE/YmZyvZYxz6gpSG6g3+O/SbDfUeRdPJADE485N8c0PJFSPgwVBn/zE+krD+1PrkjpVkDhUVdJA++VkbRDq/epgm5E6OTnh3xXk4vn0/zDDJ+w7Kwf/62GoHJLBVKh2ko/kT1yhY8gRoUgj2D+3+E36ywVmr0efjrRw1/JbjFF6fwDzfxaJTGwoYUSXifqQDzsTYB7TuSnYMEDSSlp8CLRYBOvP2O0lPB3CGTeR/CQxIIBHFL0j+nBtQGq14TyxgU0sGYy32dQmpFxeNbW66Ei2L+5C1S6tRiQCRBTiUkeHX/oMh X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:42.7639 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da016110-0746-4774-fa9d-08d9bac40030 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: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2397 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: DACGFwldGzGAIIUUVBp5YkoKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020525; bh=RmIMjxPLVCVOqkwTpUxdMebhQl1QMTxvB8CwQfM9ofU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q389kXFiS12Vd786U8akQx2a1Ei/OLg55e9MLW1sK5HK5vz2ulepHWmXum4xmeI4i48 nhhoQumkE8Oyt3Lwoasv9pwaB74AhPdrF4r9pdk4lVLR0/WMWGVfho7lgtjKgoNKKatrE 7n6gH8aPskDb50r/4MQtkTwPcrzlAuPUNXI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020528035100004 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The VMM launch sequence should have pre-validated all the data pages used in the Reset vector. The range does not cover the data pages used during the SEC phase (mainly PEI and DXE firmware volume decompression memory). When SEV-SNP is active, the memory must be pre-validated before the access. Add support to pre-validate the memory range from SnpSecPreValidatedStart to SnpSecPreValidatedEnd. This should be sufficent to enter into the PEI phase. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 4 ++++ .../PeiMemEncryptSevLib.inf | 2 ++ OvmfPkg/Sec/SecMain.inf | 3 +++ OvmfPkg/Sec/AmdSev.h | 23 +++++++++++++++++++ .../X64/PeiSnpSystemRamValidate.c | 5 ++++ OvmfPkg/Sec/AmdSev.c | 22 +++++++++++++++++- OvmfPkg/Sec/SecMain.c | 5 ++++ OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 ++++ 8 files changed, 68 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index bc14cf2ed403..c22b846cd663 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -364,6 +364,10 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|0|UINT32|0x60 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize|0|UINT32|0x61 =20 + ## The range of memory that is validated by the SEC phase. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart|0|UINT32|0x62 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd|0|UINT32|0x63 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 49d5bd1beff1..50c83859d7e7 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -60,3 +60,5 @@ [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 41dcdba1209a..95cf0025e100 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -52,6 +52,7 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + MemEncryptSevLib CpuExceptionHandlerLib =20 [Ppis] @@ -74,6 +75,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/AmdSev.h index c0b1ca96183d..dffd2ceb9656 100644 --- a/OvmfPkg/Sec/AmdSev.h +++ b/OvmfPkg/Sec/AmdSev.h @@ -68,4 +68,27 @@ SevEsIsEnabled ( VOID ); =20 +/** + Validate System RAM used for decompressing the PEI and DXE firmware volum= es + when SEV-SNP is active. The PCDs SecValidatedStart and SecValidatedEnd are + set in OvmfPkg/FvmainCompactScratchEnd.fdf.inc. + +**/ +VOID +SecValidateSystemRam ( + VOID + ); + +/** + Determine if SEV-SNP is active. + + @retval TRUE SEV-SNP is enabled + @retval FALSE SEV-SNP is not enabled + +**/ +BOOLEAN +SevSnpIsEnabled ( + VOID + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index 0e3eba3c5121..497016544482 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -29,6 +29,11 @@ STATIC SNP_PRE_VALIDATED_RANGE mPreValidatedRange[] =3D= { FixedPcdGet32 (PcdOvmfSecPageTablesBase), FixedPcdGet32 (PcdOvmfPeiMemFvBase), }, + // The below range is pre-validated by the Sec/SecMain.c + { + FixedPcdGet32 (PcdOvmfSecValidatedStart), + FixedPcdGet32 (PcdOvmfSecValidatedEnd) + }, }; =20 STATIC diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c index aa655fd9cbae..499d0c27d8fa 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -55,7 +55,6 @@ SevEsProtocolFailure ( @retval FALSE SEV-SNP is not enabled =20 **/ -STATIC BOOLEAN SevSnpIsEnabled ( VOID @@ -281,3 +280,24 @@ SevEsIsEnabled ( =20 return (SevEsWorkArea->SevEsEnabled !=3D 0); } + +/** + Validate System RAM used for decompressing the PEI and DXE firmware volum= es + when SEV-SNP is active. The PCDs SecValidatedStart and SecValidatedEnd are + set in OvmfPkg/FvmainCompactScratchEnd.fdf.inc. + +**/ +VOID +SecValidateSystemRam ( + VOID + ) +{ + PHYSICAL_ADDRESS Start, End; + + if (IsSevGuest () && SevSnpIsEnabled ()) { + Start =3D (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfSecValidatedSt= art); + End =3D (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfSecValidatedEn= d); + + MemEncryptSevSnpPreValidateSystemRam (Start, EFI_SIZE_TO_PAGES ((UINTN= )(End - Start))); + } +} diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 58e3b923b40e..2c5561661ef3 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -860,6 +860,11 @@ SecCoreStartupWithStack ( SecCoreData.BootFirmwareVolumeBase =3D BootFv; SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; =20 + // + // Validate the System RAM used in the SEC Phase + // + SecValidateSystemRam (); + // // Make sure the 8259 is masked before initializing the Debug Agent and = the debug timer is enabled // diff --git a/OvmfPkg/FvmainCompactScratchEnd.fdf.inc b/OvmfPkg/FvmainCompac= tScratchEnd.fdf.inc index 46f52583297c..d8d45fc9aa6d 100644 --- a/OvmfPkg/FvmainCompactScratchEnd.fdf.inc +++ b/OvmfPkg/FvmainCompactScratchEnd.fdf.inc @@ -63,3 +63,8 @@ DEFINE DECOMP_SCRATCH_BASE =3D (($(DECOMP_SCRATCH_BASE_UNALIGNED= ) + $(DECOMP_SCRATCH_BASE_ALIGNMENT)) & $(DECOMP_SCRATCH_BASE_MASK)) =20 SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd =3D $(DECOMP= _SCRATCH_BASE) + $(DECOMP_SCRATCH_SIZE) + +# +# The range of pages that should be pre-validated during the SEC phase whe= n SEV-SNP is active in the guest VM. +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart =3D $(MEMFD_BASE_A= DDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd =3D $(DECOMP_SCRATCH= _BASE) + $(DECOMP_SCRATCH_SIZE) --=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 (#84557): https://edk2.groups.io/g/devel/message/84557 Mute This Topic: https://groups.io/mt/87605545/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 Sat May 4 15:08:10 2024 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+84558+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020528543386.1485759930688; Wed, 8 Dec 2021 19:28:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id swpQYY1788612xiulwZ3jMEY; Wed, 08 Dec 2021 19:28:48 -0800 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.88]) by mx.groups.io with SMTP id smtpd.web08.6790.1639020527477349691 for ; Wed, 08 Dec 2021 19:28:47 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MV/s6mKistjdYtA9LLgSkyG9b7zXn/OokjWthEWfkD2gcAjYhOShlSjM1Y8D2cxJuXd5IwQsIdxn7wy9aU5fF1uDEhklWEWuLlU37M8vJJV04QvdytfkiEwU0hv1QhkHPrbbmPQrxQpa5/6A0o9nqTw1GIUcwFVJvc7j+3+I0htcEqkUisITUKM3WzA1WSCyck0y28jRxcYx53j30QsE12ZdV5nz0Y3Ah8hk/jwIvTWglZ7hR36Zcsc7YDYEvToH9PVYepspCW5HxeWCItpatzcNtFY2HRlTWPIZQ9EHzHLOjb9b/9QxeyGYIVQHexORJoXBJOgk0XeNA/n7DxJ71Q== 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=B/0U6A2g+95Rtlkzn8oMd5375moYawxawknRF1qgtyY=; b=ccdhMw0PcCPOmmRoPQuXwtJSHMhCVdUtOqfwACy8fh8x86bNza70t65AEXLnwRtfpn3gBrb0VqRfAw2pr7Sdjea8eOnxWLSA+0C2+umZKj7sUIQNYen3TgYlNJCkaXR4Vi5/fDiJw3JAj6tjsSMqB3LKvhk6ep40SKbYaBJxExM7JpGgAT3Rl1i5ps5deKVcnB+Kb9VN1RG3c9RNDtmOuUdiFtC7Bo9muRHHu+5vBq7Mo+tTxswRvRiKwZrPkkWn8xc1VEAlkQ8BvoGQr+6reUvo00roE7BGK33QNOL4fTmHaJAnNyQoPTEUQiwEwj+v9cuygSWTl8Agii60GNv8Lw== 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 MW4PR04CA0161.namprd04.prod.outlook.com (2603:10b6:303:85::16) by BN6PR1201MB0018.namprd12.prod.outlook.com (2603:10b6:405:54::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20; Thu, 9 Dec 2021 03:28:45 +0000 X-Received: from CO1NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::61) by MW4PR04CA0161.outlook.office365.com (2603:10b6:303:85::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:45 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84558+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT057.mail.protection.outlook.com (10.13.174.205) 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:28:45 +0000 X-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:28:42 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 8 Dec 2021 21:27:47 -0600 Message-ID: <20211209032800.3802995-20-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5aea90e0-f815-4b7e-7e29-08d9bac401ac X-MS-TrafficTypeDiagnostic: BN6PR1201MB0018:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: YgHMsogyZzbCEiqYuwGgMYOZrJ++IEKKsiQDxNHuw8dx5qS24OiPH5CahVL69qAqe6G0HHdCB8W9uNCvnhTc2AHcGi/epIwiL+hjaMOmicjIlTT0StBTzbiRpMaYf0/aKU70R7vpKc+jRRv9zUWz2+aVOqW6LsQJv9sNmVi0ViMPKkcWjSr/7ZveDPO/B7vIjQ+hkL4hvWh1GgjWRU2Z+nZXG29gstxDix8vaUH/DEYBoaSUA2TzVYnflIaGagTWkgraooVNpYJ9epVriRvH2AbDp/3mHtJpJVXM+3xD+12haJX4k13mB33GU8lKpNhy1fLjSJ/C64tlG1PrFdzPnJLDJ1jYN6kfvYjRo+Qlwakn4oR8pXse7HVZJHUcDdTJZ3lx/U465RE1tSAx0RCOhUZSutM4VAI2Ewy0Xt1YfW19tXuMyFsWhwIKGPOZuHiae5t3muEEtiPZa+4XHNERNzOlEPiriqibaKZnRiv6gPDOoD2IIOQaR0i+Sm3iRva5aqTqpqx2S2qwUWghbwPHabo/LdZcrJ3jgL3MVrqYoisSV1rPWclUVCLUZ0z8Dhz80zCFXnirguDpnIeNlmc9VpnGWrnDrbhu1yqzdSFaXRpIJA5ShmFntqcsd4+ME4MxaTPp5CDDPTMzP96bE1+lM7sRCRxJmwKx0vJEZMEqbUeN9JI2VuOZdOF7muDP2+eONNUxvyby0Bh2iZvzVOP1DKnBIN6le30/NRueOUgf49VNJ8mTjWbcUXz1FfDjzoSR7Sf6JxdgBw++x2h9maL/lSyWx/woQP9KlMVWsOKOiTx0YrVQSyzC64smXKM3ry0YkheEv+2b92qePO5vD07a5WnBH8aaKIaZZZ+l4ZAXCGNXNKOJyLvmnbB/eZiUav/H X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:45.2511 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5aea90e0-f815-4b7e-7e29-08d9bac401ac 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: CO1NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0018 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: WSoxMx8YLpY5o1zagQPBsR50x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020528; bh=XFS59k50gTJ3a5HfXTAVZUSATuY2DK158iY8gHY5nY0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=a0+cAaYu9HANOHXg+uVj+hrB+qGqq5oikpiFu12miIUFrjeccizcNdflmhxVVlaLLk/ p3N9y/RZ09reHbD/SAoT25K38Jd41EUWH+/k9YIxVpwPoq787c4vnm+u++eqidwfmGPVE p2PQctq0cqGNnqHyQnHNuA7MoSNh1WPecU0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020530180100009 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 When SEV-SNP is active, a memory region mapped encrypted in the page table must be validated before access. There are two approaches that can be taken to validate the system RAM detected during the PEI phase: 1) Validate on-demand OR 2) Validate before access On-demand =3D=3D=3D=3D=3D=3D=3D=3D=3D If memory is not validated before access, it will cause a #VC exception with the page-not-validated error code. The VC exception handler can perform the validation steps. The pages that have been validated will need to be tracked to avoid the double validation scenarios. The range of memory that has not been validated will need to be communicated to the OS through the recently introduced unaccepted memory type https://github.com/microsoft/mu_basecore/pull/66, so that OS can validate those ranges before using them. Validate before access =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Since the PEI phase detects all the available system RAM, use the MemEncryptSevSnpValidateSystemRam() function to pre-validate the system RAM in the PEI phase. For now, choose option 2 due to the dependency and the complexity of the on-demand validation. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/AmdSev.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index f66e0a7f4a10..a0f9178ed6e9 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -23,6 +23,40 @@ =20 #include "Platform.h" =20 +/** + Initialize SEV-SNP support if running as an SEV-SNP guest. + +**/ +STATIC +VOID +AmdSevSnpInitialize ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + // + // Iterate through the system RAM and validate it. + // + for (Hob.Raw =3D GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_= NEXT_HOB (Hob)) { + if ((Hob.Raw !=3D NULL) && (GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_RES= OURCE_DESCRIPTOR)) { + ResourceHob =3D Hob.ResourceDescriptor; + + if (ResourceHob->ResourceType =3D=3D EFI_RESOURCE_SYSTEM_MEMORY) { + MemEncryptSevSnpPreValidateSystemRam ( + ResourceHob->PhysicalStart, + EFI_SIZE_TO_PAGES ((UINTN)ResourceHob->ResourceLength) + ); + } + } + } +} + /** Handle an SEV-SNP/GHCB protocol check failure. =20 @@ -243,6 +277,14 @@ AmdSevInitialize ( return; } =20 + // + // Check and perform SEV-SNP initialization if required. This need to be + // done before the GHCB page is made shared in the AmdSevEsInitialize().= This + // is because the system RAM must be validated before it is made shared. + // The AmdSevSnpInitialize() validates the system RAM. + // + AmdSevSnpInitialize (); + // // Set Memory Encryption Mask PCD // --=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 (#84558): https://edk2.groups.io/g/devel/message/84558 Mute This Topic: https://groups.io/mt/87605546/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 Sat May 4 15:08:10 2024 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+84559+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020530632750.0685289792226; Wed, 8 Dec 2021 19:28:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id CO6sYY1788612xPEd2zQfA9D; Wed, 08 Dec 2021 19:28:50 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.58]) by mx.groups.io with SMTP id smtpd.web12.6762.1639020529593813650 for ; Wed, 08 Dec 2021 19:28:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CUhdTj3Ch4WXvlVyt1NJ+YJKLC6Bl+7XnYrIwq4Y5Mgf2NJ6jW1K/fWT1SfygioHgxkuTm4ehljtETep96gEMZjp1f2iXz+EM2ffs0KO+LwH31YlEd2G7thFFIJd8kpiekTy8MHb2NAjvfcufH2M1E95pSBoCAKZOy3Uip8YVC/zTdrVLxlz4dTPUoxgV8HyuHSYIuZjmt8SV5ETZcsYDi9uMwd3DsYK4ftYGv6UE0pRumOD+gG3d8pUlXYFnmem29dE1ClCBQwmdX7RsGmXH8MUyfRhv1GTB+Fzjj7Sc8pkTBSBZ2KTOQsM0K2kyJXOOusAB6R4z//q4/cuByKzcg== 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=fyUM/arM6+ndN/DDKNHZaLKwpQ5dne/L8jjIPxhGeiM=; b=PxUg/MG52u5ZAkCBIKQFJhGzpQ9UPbzdfdFJUBqq1A4GBLkc8srP3Jf4MwbY+Xs1J8VpVURB4kCpPpnCooTNfEqNDKXC3v45Tchczr5sb3CUXujuzX2nZLdNmVkR07mH5dnD8+4rB2GNsS9WkwPvptvNFbFM/hZR3YrM6Ucwe0+m60ZmlClYMD9aouRGFldCbtIjIcrhU2TLeYScE5v0hmbFyezNtSPhKXkoJzbp4XiGTMW2ooPAzD8zCZCu1Ca3RodvddcBcAphBQsBFUPTasxPkOBZ2/AUjgyS0HDZzszcOePLqI6CFKXPn3RNLQNPtiL0h8x03A3KbNLXwUwr6g== 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 MWHPR21CA0055.namprd21.prod.outlook.com (2603:10b6:300:db::17) by BN8PR12MB2947.namprd12.prod.outlook.com (2603:10b6:408:6c::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Thu, 9 Dec 2021 03:28:47 +0000 X-Received: from CO1NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:300:db:cafe::99) by MWHPR21CA0055.outlook.office365.com (2603:10b6:300:db::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.6 via Frontend Transport; Thu, 9 Dec 2021 03:28:47 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84559+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT059.mail.protection.outlook.com (10.13.174.160) 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:28:46 +0000 X-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:28:44 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 20/32] MdePkg: Define ConfidentialComputingGuestAttr Date: Wed, 8 Dec 2021 21:27:48 -0600 Message-ID: <20211209032800.3802995-21-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7670ea7e-97c2-4c05-1b76-08d9bac402b3 X-MS-TrafficTypeDiagnostic: BN8PR12MB2947:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: ocHHIVwCPKHj7o2fAMaqIqkY3tvgStjPHvA2jl2yKdE3hSNJJ8tqpfYjsLML9IIuSsPJkqxHIAhxm2e+2NIgla4gm2P5c9k0KgePGd/HP2bRYEZn4ZRon2DnP4Fehlm+lOM3wM0jdIpdgomfOkO+dD/QWEL09SIreLcnpJAaN0SI+nMgtIWF7SKLE/Xe5clpP8DXr8uU7rAg3fHhOCcx1c+xd2BIHfXVBwyozgSJMR3pzkMCwvuuYjdicG+1ly9ZGuBoaYPoya3mkclE/L8J3+iHE9DMS1yfDVjXe7iD2zAFZEdH2GUsd38UrjGoEWmjKC68aFYAFW8OSh/ySjgM2rJl15XmurSHNwzjZb2VpSMzY/6XJHYTi91qo4TDkNnJjTawQvl0S3lboSk5pQNnZKzqOTaSuVuue+ffjWJsn5u06LSmSDvqQUvy6zIZ92sttmQgPmbJ774m9jXjrsAYi1ZAFuwVtdhowb4kYVXv5ZW0mFnT/Yap5AiTbWHa0RbA4wPsAIx9BN80Lq+KAtag2W7nB+pffi5G3xQHx8i0WMgPx40qTT4imoqGEG9e7HEmNV3RaP5cUXEElh0/JFp7v1ksQ0w3TCqXn6lQa8u3+d/IlbBQK+bHVkcOPg64MkvkX9ne3iunRqEkzcn6z8oq948igUjNpXbwHU7HsWgLN/zzsaJzlxxHxsbKA80GcpU5FYFNoe9X6BkUIH/9U4c/wQOE3cFDKVLCPnKptBfq1HsrK1l5fmL81U/RgPJRQNIbgQWeYeRuGR0wjBYYYn4HFpSHJQC7ZDCoqSAJT7hVyJX5QeNCIjyoVIz/gn7U6UWp72F9KKliXmyc0Tq4m9esaLLljrnEb1MXtk7iNolAjuSblr8y4/4WkCThgq4yRNoo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:46.9722 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7670ea7e-97c2-4c05-1b76-08d9bac402b3 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: CO1NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2947 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: 8RMj9hnmvfXqpdFCBzxiuFfRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020530; bh=xjS5xajR9uJxTswKoOo541py4Wg93RepJeUNo+IXAw8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MskrSSEXNXEdh57t6khK8nKXCCg+AOdpJNkvQ+8j2JqZega/mQvIgDmLLJ8Vs1n6GLZ AHab3ERjH0RsFhq0wtnrzazzejknDh2q81i7hNhK74hGAOequETcVw88OW8PSgzzxAOdl kQ4t4F2YF12NBXS6DfUUgDIpWwls+BAAygo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020532398100002 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 While initializing APs, the MpInitLib may need to know whether the guest is running with active AMD SEV or Intel TDX memory encryption. Add a new ConfidentialComputingGuestAttr PCD that can be used to query the memory encryption attribute. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong 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: Ray Ni Suggested-by: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- MdePkg/MdePkg.dec | 4 +++ .../Include/ConfidentialComputingGuestAttr.h | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 MdePkg/Include/ConfidentialComputingGuestAttr.h diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 8b18415b107a..cd903c35d2ff 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2396,5 +2396,9 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic= , PcdsDynamicEx] # @Prompt FSB Clock. gEfiMdePkgTokenSpaceGuid.PcdFSBClock|200000000|UINT32|0x0000000c =20 + ## This dynamic PCD indicates the memory encryption attribute of the gue= st. + # @Prompt Memory encryption attribute + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0|UINT64|0x00= 00002e + [UserExtensions.TianoCore."ExtraFiles"] MdePkgExtra.uni diff --git a/MdePkg/Include/ConfidentialComputingGuestAttr.h b/MdePkg/Inclu= de/ConfidentialComputingGuestAttr.h new file mode 100644 index 000000000000..6a1301801519 --- /dev/null +++ b/MdePkg/Include/ConfidentialComputingGuestAttr.h @@ -0,0 +1,25 @@ +/** @file +Definitions for Confidential Computing Attribute + +Copyright (c) 2021 AMD Inc. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef CONFIDENTIAL_COMPUTING_GUEST_ATTR_H_ +#define CONFIDENTIAL_COMPUTING_GUEST_ATTR_H_ + +typedef enum { + /* The guest is running with memory encryption disabled. */ + CCAttrNotEncrypted =3D 0, + + /* The guest is running with AMD SEV memory encryption enabled. */ + CCAttrAmdSev =3D 0x100, + CCAttrAmdSevEs =3D 0x101, + CCAttrAmdSevSnp =3D 0x102, + + /* The guest is running with Intel TDX memory encryption enabled. */ + CCAttrIntelTdx =3D 0x200, +} CONFIDENTIAL_COMPUTING_GUEST_ATTR; + +#endif --=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 (#84559): https://edk2.groups.io/g/devel/message/84559 Mute This Topic: https://groups.io/mt/87605547/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 Sat May 4 15:08:10 2024 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+84570+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020576017774.3787666429473; Wed, 8 Dec 2021 19:29:36 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eF7WYY1788612xZSQSr6wjWY; Wed, 08 Dec 2021 19:29:35 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.84]) by mx.groups.io with SMTP id smtpd.web10.6838.1639020574941028931 for ; Wed, 08 Dec 2021 19:29:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aficLNIPnmDt4fyaUxdt7d58DNptxlKrM6yYKjPdF0tMmA1gk1f59tiEdtJCEtd43+VgZ9toITfm/0fBBJqbeHMlPQG7GiUnWp9u6BG/GmurZl9PLY8Ja7QIcCh/SkkHgvWMJ8wLN329ETWJnKafit1HOMBGxRSjIaJdhnG1hwES9j+t0swaGrntrSCrYVI65mOEq0Ai7P1E+QebRKY1+atNmsQ55rGuYfR+3hyADOOJRhDujupHTVIZhCZovyCxFzUpuLgoChDERtyqfdDgjLB01l5+HPNJtcadWgSrsbYIKhAQ1McbzlBDVrmmmm09LJzneyHqfZy25ahSBT2oFA== 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=AiVmExZ347/yaHkODgrz0DhUoTZQxh3htkW5sbcX1GI=; b=T449Jg8f7U2ynTN4SwMIVcTYQIOsjhCzSuz4OBqszwstp8vskwxiqNZdnsShavkoL9kSYjLxdQ/5oxOIC8yOlAaphdEYU++0+SMwzOowEivIwO9jqS0QGdpVyHYEzC+c/BeEfOLCzt4SPjAuRkIJ1UnNQOtk2EZlqTLY8wnnmSrHwOcNUwjJ9U9vRAZVPXihcVdA9i63BG9Pd9ZjZwynfsTPDwPlgOiVh3n7PeuXF3pLkRX2r1FbqcoLIDLUDglvl/+BwjyW6oRURyHGyllPZu5/dkfAiu5nOuA+cpvqfI2tnXCVx5FU8+J50SZ9sWT2BUI+G6xj+yM1fBcOkLAEyg== 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 MWHPR22CA0055.namprd22.prod.outlook.com (2603:10b6:300:12a::17) by MW2PR12MB4667.namprd12.prod.outlook.com (2603:10b6:302:12::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Thu, 9 Dec 2021 03:29:18 +0000 X-Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:300:12a:cafe::4) by MWHPR22CA0055.outlook.office365.com (2603:10b6:300:12a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.17 via Frontend Transport; Thu, 9 Dec 2021 03:29:18 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84570+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) 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:18 +0000 X-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:28:46 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 21/32] OvmfPkg/PlatformPei: set PcdConfidentialComputingAttr when SEV is active Date: Wed, 8 Dec 2021 21:27:49 -0600 Message-ID: <20211209032800.3802995-22-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8defe00-5bce-4a18-b4c8-08d9bac4156f X-MS-TrafficTypeDiagnostic: MW2PR12MB4667:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: agkBNwjQx6AnamWo3/9PdbRqoXOZDJ6xyjChG/t659rlTIlwn88miGVtU1L5QV0Syk9Bz0UTNl1HhcYrWL0rGQiV9fFbe0s3Ktab7AmMdpJYWG9xd1vipPnZ0pmtDqgiVaKya+xzukZX+Kc57w+cfTBHgVPKYA1GwM+iqi6MQsf8IaDgXNnwizIU8Iv9wgZBZoQW+RfrI/WzO5rXIhuHzqG8TWo3SUmjX8FQQP/Dp7TQsIlFwqOxQOYFdaM2rzbUWHpcUrkaBytrcnoG+BarvT7SMqBGccd1zP+gfag06hwAbwjkaA57FBNzr5Zfw0LdUIBGN9tjBcDFbpqGa6916SrvHpY1erowp4djSQhHZDR7m/gFUyuEHlDZkXeaJh7seB9KNBuiLLwlEU90e/9QVxHIdWX9g3ZeCqGgEeeGGZ46Wevc6mcgDuOa+rcxKs656cj057n49ezt8XwRSrgU4xCHO3rzK9pmR73zp9AR0CUurfz7vOGmGJX90gGZdpG5Nmj37UqXhtYaje4skKJz7GY/E3FoVUhAe8LV2JukQQsOxsoFKu0R/MIva1KpbW8mK5nbeL83VExATHw4+0fP0Dfjtmgoa33XW9OThb6g6+bu5SN2oz8XklPtklf/wSyJutPvWLyDBo7LkPLjnHNb5K7kzjhxp8kno3dsGTGJOUp0R0f3TH3dODeb0V2pMrnkC4yXRdK/yftJXh0xNb85tO81eomweBV1QDySagkYY0+0WJ7jUpo5kVYNp2UDXvYo2xh6U1HlAZT5T2e8BAUo7YL+yOC6CErR4LB1pM3m5Xz+1PrtaJ4tEh4nfg2GveUl7seI07ALOF4xcsVUL6M8/BWLGaSC3sIey6UBOUc902DeTJfceBg2OnRUScQ2NsEZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:18.4072 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8defe00-5bce-4a18-b4c8-08d9bac4156f 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: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB4667 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: xrQ6qjC0iR4GrEFB4Os0OSWgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020575; bh=9cA9Z9zSPpJhssgf2HDOUUT8L66VolfhKl+FOhjkws4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ic2DA6xLqroDS7ki4GEGLhIHR+amT0I2yaeQdbETzhiyP9f1dGsLiLfj40JUK2TSoRh llxz/TL59rOEumZGC826BeqmumDUSybfRCTgzOS6An/G7VW7MMb/WJItWyTop6rkNPp55 ljCwEnSMOMXlM4bruXugF0Hyidb5PAS/gKY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020577071100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MpInitLib uses the ConfidentialComputingAttr PCD to determine whether AMD SEV is active so that it can use the VMGEXITs defined in the GHCB specification to create APs. Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong 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: Jiewen Yao Signed-off-by: Brijesh Singh --- OvmfPkg/AmdSev/AmdSevX64.dsc | 3 +++ OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 15 +++++++++++++++ 6 files changed, 28 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 2997929faa05..8f5876341e26 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -575,6 +575,9 @@ [PcdsDynamicDefault] =20 gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x00 =20 + # Set ConfidentialComputing defaults + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0 + !if $(TPM_ENABLE) =3D=3D TRUE gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00= , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} !endif diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 1dc069e42420..dbcfa5ab52ce 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -651,6 +651,9 @@ [PcdsDynamicDefault] gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01 gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport|0x01 =20 + # Set ConfidentialComputing defaults + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0 + [PcdsDynamicHii] !if $(TPM_ENABLE) =3D=3D TRUE && $(TPM_CONFIG_ENABLE) =3D=3D TRUE gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer|L"TCG2_= VERSION"|gTcg2ConfigFormSetGuid|0x0|"1.3"|NV,BS diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index a766457e6bc6..e4597e7f03da 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -659,6 +659,9 @@ [PcdsDynamicDefault] gEfiSecurityPkgTokenSpaceGuid.PcdTpmInstanceGuid|{0x00, 0x00, 0x00, 0x00= , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} !endif =20 + # Set ConfidentialComputing defaults + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0 + [PcdsDynamicDefault.X64] # IPv4 and IPv6 PXE Boot support. gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 97b7cb40ff88..08837bf8ec97 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -662,6 +662,9 @@ [PcdsDynamicDefault] gEfiNetworkPkgTokenSpaceGuid.PcdIPv4PXESupport|0x01 gEfiNetworkPkgTokenSpaceGuid.PcdIPv6PXESupport|0x01 =20 + # Set ConfidentialComputing defaults + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0 + [PcdsDynamicHii] !if $(TPM_ENABLE) =3D=3D TRUE && $(TPM_CONFIG_ENABLE) =3D=3D TRUE gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer|L"TCG2_= VERSION"|gTcg2ConfigFormSetGuid|0x0|"1.3"|NV,BS diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 67eb7aa7166b..bada5ea14439 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -106,6 +106,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a0f9178ed6e9..c60a153a059e 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 #include "Platform.h" =20 @@ -345,4 +346,18 @@ AmdSevInitialize ( // Check and perform SEV-ES initialization if required. // AmdSevEsInitialize (); + + // + // Set the Confidential computing attr PCD to communicate which SEV + // technology is active. + // + if (MemEncryptSevSnpIsEnabled ()) { + PcdStatus =3D PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdS= evSnp); + } else if (MemEncryptSevEsIsEnabled ()) { + PcdStatus =3D PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdS= evEs); + } else { + PcdStatus =3D PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdS= ev); + } + + ASSERT_RETURN_ERROR (PcdStatus); } --=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 (#84570): https://edk2.groups.io/g/devel/message/84570 Mute This Topic: https://groups.io/mt/87605570/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 Sat May 4 15:08:10 2024 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+84560+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020562895317.0049967323664; Wed, 8 Dec 2021 19:29:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id sfhNYY1788612x3yZEuFmcuO; Wed, 08 Dec 2021 19:29:22 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.88]) by mx.groups.io with SMTP id smtpd.web11.6942.1639020561672524975 for ; Wed, 08 Dec 2021 19:29:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNZSnN0iemh7YyXBAiv49FO4RaRhZeUkDx/1P0PyLEEv4i0rcfI7p1niWzz1gnQ09nsJY4PT55iHLgJQGcdituAoufgyOFfkzKxPynePq0a3cw6KxdXk9iipk8LtzRz4WT8QZ+/Ghj8fMYsitaiE18ND2Dm2CzjuFYkUzXxjHBJhix9BSjya6NsLOdIHykqnZlUE+cBE3CX5TcALlKebXU2anZY5M4DpjxsX5B6er3F8PGvrywhjlIFzj943/9QLB/QkO9nx4d+utnI4za1kGnC906GitTkQG59vc6kAq/TsZwyBDwRUUvAcUEF5HeezfljZ6fqGanoiP+zwoK8FIg== 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=duJqfwl50RSHSHGaf6w5AoL5e9h/JECmlVQe7V7850I=; b=PXoWVMF2LzjtLFWciHIAM/4nF3fEj8JWLRxi9q/Jo2Q9XtyNuuFZB5AsEW4/EAkEkJLnXBbeMBvM4eFWrSxCCEhFkr4hVUEaIMaeuSRjhiWPZc5PzeksugOyweQQZacG1I7km6Yuwjl561uESqmFG9ULl0IYMbDruRlE7rLF3HuVwJy1oFl3Yq2SwM5y77njS0Nm5HrbSql7iDbDIb5iNnOxGYU/bVGmdYAu1WUQArWVjcsfKJ5AMw7hKT7S7xhXvhQ4B+PrpBEXoEvA0zoCJJlsQxF/Kuk8yZnmbsSAk2ZDYDPod4VGIYa3PsnSyb0vkwVlxyl4qeLvvZD2Tq8YzQ== 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 CO2PR04CA0198.namprd04.prod.outlook.com (2603:10b6:104:5::28) by DM4PR12MB5152.namprd12.prod.outlook.com (2603:10b6:5:393::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Thu, 9 Dec 2021 03:29:19 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::df) by CO2PR04CA0198.outlook.office365.com (2603:10b6:104:5::28) 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:19 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84560+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=SATLEXMB03.amd.com; X-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:19 +0000 X-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:11 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 22/32] UefiCpuPkg/MpInitLib: use PcdConfidentialComputingAttr to check SEV status Date: Wed, 8 Dec 2021 21:27:50 -0600 Message-ID: <20211209032800.3802995-23-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8566a903-17dc-4327-9228-08d9bac41612 X-MS-TrafficTypeDiagnostic: DM4PR12MB5152:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:409; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: sIi9A0FZhBjk1t5+VMMdkxsl1kB9xCq0ncEzzE9WHRAKH9qvwSICkSJHw3iks/DT/5b2XJI7Dux15WeJYAcVFdOiqQwQSrOZFiSbEvUxKSFpW5jDIUU5CvOphtpkYniIv10htrkWrQn+5DQHN4qzZ0RPMZ2fe/iBSfxlABNWqawOKv0n85EPel18rZeisfugJDP4JJZ2JA836JTj8M1F78uEh5UKYDcStJnbOfE3YYeunFSVgbCWD7QzvM7n3gp4EA8aHA5k4k320jX6ToqAiLw/YK1nTfcpIfLPdvcFTgFNipF8UafCnnFs2JK15qRwy+Xd2KQLYMYxp7uwE16ZpE3AEUMQhc3HtcZT+UqCwoRXUh5HrfoU/tbNwBal0QkxM3qeFXtkmww4gPnJ9yQq6FlUjorN+lZVpONfR08zOsA/X9LXNcfJ9skKex+nfnWZzbQR8SfkABbFY1A0rPi+v22QgOS1Q7F51DHq1eDCWr0LJ9nvf6tN6CTK5dYy5DqOChaLbP46ZFnbHtOJZv4m35ZBSvF2h0Gx9L61Xj63bZZih9mNm/YialR14cYBgNLnuWgk//RnHKE8znJSEVu/pjXWjI16UpivnarMyPWvv4ZlzGi9KUCFn0Gen7iMJ09JkbS8siKhWAgjt1t5+o0Zm1Uw9BNwXbGHnr8eLAuAwgSJzal5BK/lVNaM+JeBo+9RUpuEHGViE0eo7ZQawQyzK/x3P473r5ET3pQQVVeoqn1a9yxdxLiUy+hym0pXCKyNG83++9ovcF5fmTtBFzorBOOULQw9cPS39jloz89IXoP6rN1JggcT8ls2p868Y2gZ2xWmlrIOYLB0Q3eHtrhiqHxb/201vtNiGpNgYGW/WDHL5gOcPHTP/zl7jqfA0MWJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:19.4589 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8566a903-17dc-4327-9228-08d9bac41612 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: DM4PR12MB5152 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: Bsuq0KBf76bV49xxefxu1cDPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020562; bh=J3UP+Pldiqx1t8JxMymR0TQ76V68USL7/hIb3m0khLg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HoF8b+LJ6cmmehfnwM1Ti6wwhhwWnR8xHsUHm8Ar/XD0QYlXjw+CUlQ/gYzRZ/WK2E+ rWFJi7J49jsTzOk8VKlMby2Qn4zadVYue0LuwJPx5HwUq2ntwBOUkxzc+qAeotqYGz0yk JnHcCVsxGW4L68hJQbO9jPS16V8SE367YEo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020563554100001 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Previous commit introduced a generic confidential computing PCD that can determine whether AMD SEV-ES is enabled. Update the MpInitLib to drop the PcdSevEsIsEnabled in favor of PcdConfidentialComputingAttr. Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong 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: Jiewen Yao Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 2 +- UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 2 +- UefiCpuPkg/Library/MpInitLib/MpLib.h | 13 ++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 6 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 73 ++++++++++++++++++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 4 +- 6 files changed, 90 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 6e510aa89120..de705bc54bb4 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -73,7 +73,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 2cbd9b8b8acc..b7e15ee023f0 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -63,9 +63,9 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOME= TIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONS= UMES + gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 16b4d76d019b..a84df60519ed 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -33,6 +33,7 @@ #include #include #include +#include =20 #include #include @@ -773,4 +774,16 @@ SevEsPlaceApHlt ( CPU_MP_DATA *CpuMpData ); =20 +/** + Check if the specified confidential computing attribute is active. + + @retval TRUE The specified Attr is active. + @retval FALSE The specified Attr is not active. +**/ +BOOLEAN +EFIAPI +ConfidentialComputingGuestHas ( + CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr + ); + #endif diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 9d9206d20915..02bc9c2bd2c4 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -93,7 +93,7 @@ GetWakeupBuffer ( EFI_PHYSICAL_ADDRESS StartAddress; EFI_MEMORY_TYPE MemoryType; =20 - if (PcdGetBool (PcdSevEsIsEnabled)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { MemoryType =3D EfiReservedMemoryType; } else { MemoryType =3D EfiBootServicesData; @@ -107,7 +107,7 @@ GetWakeupBuffer ( // LagacyBios driver depends on CPU Arch protocol which guarantees below // allocation runs earlier than LegacyBios driver. // - if (PcdGetBool (PcdSevEsIsEnabled)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { // // SEV-ES Wakeup buffer should be under 0x88000 and under any previous= one // @@ -125,7 +125,7 @@ GetWakeupBuffer ( ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { StartAddress =3D (EFI_PHYSICAL_ADDRESS)-1; - } else if (PcdGetBool (PcdSevEsIsEnabled)) { + } else if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { // // Next SEV-ES wakeup buffer allocation must be below this allocation // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 34555c069331..64fddb497e1e 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -295,7 +295,7 @@ GetApLoopMode ( ApLoopMode =3D ApInHltLoop; } =20 - if (PcdGetBool (PcdSevEsIsEnabled)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { // // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB // protocol for starting APs @@ -1055,7 +1055,7 @@ AllocateResetVector ( // The AP reset stack is only used by SEV-ES guests. Do not allocate it // if SEV-ES is not enabled. // - if (PcdGetBool (PcdSevEsIsEnabled)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { // // Stack location is based on ProcessorNumber, so use the total numb= er // of processors for calculating the total stack area. @@ -1847,7 +1847,7 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *)(CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64)(UINTN)(CpuMpData->CpuData + Max= LogicalProcessorNumber); InitializeSpinLock (&CpuMpData->MpLock); - CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); + CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdSe= vEs); CpuMpData->SevEsAPBuffer =3D (UINTN)-1; CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 @@ -2755,3 +2755,70 @@ MpInitLibStartupAllCPUs ( NULL ); } + +/** + The function check if the specified Attr is set. + + @param[in] CurrentAttr The current attribute. + @param[in] Attr The attribute to check. + + @retval TRUE The specified Attr is set. + @retval FALSE The specified Attr is not set. + +**/ +STATIC +BOOLEAN +AmdMemEncryptionAttrCheck ( + IN UINT64 CurrentAttr, + IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr + ) +{ + switch (Attr) { + case CCAttrAmdSev: + // + // SEV is automatically enabled if SEV-ES or SEV-SNP is active. + // + return CurrentAttr >=3D CCAttrAmdSev; + case CCAttrAmdSevEs: + // + // SEV-ES is automatically enabled if SEV-SNP is active. + // + return CurrentAttr >=3D CCAttrAmdSevEs; + case CCAttrAmdSevSnp: + return CurrentAttr =3D=3D CCAttrAmdSevSnp; + default: + return FALSE; + } +} + +/** + Check if the specified confidential computing attribute is active. + + @param[in] Attr The attribute to check. + + @retval TRUE The specified Attr is active. + @retval FALSE The specified Attr is not active. + +**/ +BOOLEAN +EFIAPI +ConfidentialComputingGuestHas ( + IN CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr + ) +{ + UINT64 CurrentAttr; + + // + // Get the current CC attribute. + // + CurrentAttr =3D PcdGet64 (PcdConfidentialComputingGuestAttr); + + // + // If attr is for the AMD group then call AMD specific checks. + // + if (((RShiftU64 (CurrentAttr, 8)) & 0xff) =3D=3D 1) { + return AmdMemEncryptionAttrCheck (CurrentAttr, Attr); + } + + return (CurrentAttr =3D=3D Attr); +} diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index ab79360bb935..efce5747277a 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -225,7 +225,7 @@ GetWakeupBuffer ( // Need memory under 1MB to be collected here // WakeupBufferEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Re= sourceDescriptor->ResourceLength; - if (PcdGetBool (PcdSevEsIsEnabled) && + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs) && (WakeupBufferEnd > mSevEsPeiWakeupBuffer)) { // @@ -264,7 +264,7 @@ GetWakeupBuffer ( WakeupBufferSize )); =20 - if (PcdGetBool (PcdSevEsIsEnabled)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { // // Next SEV-ES wakeup buffer allocation must be below this // allocation --=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 (#84560): https://edk2.groups.io/g/devel/message/84560 Mute This Topic: https://groups.io/mt/87605557/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 Sat May 4 15:08:10 2024 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+84561+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020563343820.527555244207; Wed, 8 Dec 2021 19:29:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id gjClYY1788612xbbHH1QMqyz; Wed, 08 Dec 2021 19:29:23 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.62]) by mx.groups.io with SMTP id smtpd.web11.6943.1639020562244728628 for ; Wed, 08 Dec 2021 19:29:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RHJ6XILpW6CPQy9kozPHo7zvQbj+Hr3Gxrro4z9KCA464SGd+wG5lFKNlPIqsloRTjhwEJFDxBXGtsFDN1DmzyJlgdrOInReSNDnsjHIC3srXCjGMm5T6rPvgjKzNtdUiBUH0WQ69nPkIgPMb6QaXLuboiDryayzV+2V9JIE6a5ddHU6cb0vP1UA8pyfWq/pkyXgF5uUua1Nkf6p8yalKwMnd12WYD/uLrTPM2RZxit35c1YenGrIEsblCnx1B8cXnil7yoVHLzySTtjjlo+FKqnA00T86zdzp4mbG3u6Wtor0++YH8uo41tkT2pwg83X/EY1IgOy3JggTG7lbFW0w== 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=PiiCehMHKG2DTh1EZBAKY2fYx5BhzLypUkAmF3uvoHY=; b=ULP5XBlQ1iMcUwD4rXudgpIzmnzXT/sT4tzvSdbCC3hvznEJp2lL3Tu1p4yavz5+yP1dtfrEuSE3E8VzGQDus588B9k8q77NKqZD7k3rXXpdzDTt7zZXR9+bo03e/oad7jpRBAwZdvHlsxHFRhoAWSM3x2DQmT4pXdGBKXYYmaNbfHlOb09dWit68vxuHa2/fGcPMOWNmpk+KJ7PrDailnmg7otYREtpycB6JErLvylpd1dbhtmTJABzzemtj7aWCmjNDLNcwPB+4N57/rjBS15gUyroNYpA1IL4Tz8Bm0W2x0nyFsQjzxF0frnlQTsHYAI21TDTn0yPizsJIKgutA== 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 CO2PR04CA0199.namprd04.prod.outlook.com (2603:10b6:104:5::29) by DM6PR12MB3562.namprd12.prod.outlook.com (2603:10b6:5:3c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13; Thu, 9 Dec 2021 03:29:20 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::69) by CO2PR04CA0199.outlook.office365.com (2603:10b6:104:5::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.13 via Frontend Transport; Thu, 9 Dec 2021 03:29:20 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84561+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=SATLEXMB03.amd.com; X-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:20 +0000 X-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:13 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Ray Ni Subject: [edk2-devel] [PATCH v14 23/32] UefiCpuPkg: add PcdGhcbHypervisorFeatures Date: Wed, 8 Dec 2021 21:27:51 -0600 Message-ID: <20211209032800.3802995-24-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 877f9ba5-19cc-47af-65a0-08d9bac41668 X-MS-TrafficTypeDiagnostic: DM6PR12MB3562: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-Message-Info: cN4msQxWwW9fjSvPfidUSv6f9Mb5KR+/+5e/yYolNkY2kX4auDZWsqpmWolsPPFvH94zMhJsO+e0n14nSrAYzzxWO/IPNROd5YRnjMbQld1uwNuBMNoKroRbjR4pL040eWs95Bjrhrzsj/jgot/DDCsFzEZ49KH6pDMNn9cepx8NN5rxBzv/1f1xPwQVauqdhLpddeZDK0eO2OA75iwNcA6BhtVAaK/uXZJAWHVIwwQ334oPXhIN19tSZyB9mrZ50XQMPAyzcrU3G/0JgcSSSnIWFLbJP41zVITmqR0HRMlpGvjct0XNqQx2spei2/0sIHTHQQagWyCP1ZiUoPVlDsCGDSKQtgYx7pWhNKsraoHXvjOQbpi/yDm5i9F1T/ZtvL7+5yTiLIBOEAdAu8Bq6alDiS3WGryOMCVs3Sb9H9FuLO6MRrXnzmCdBjOL/Bs5nHgcFmMKCcbkps9JAR+jtljjmOzdyzPdZ5IYRLmuy2SB7c53Gn5B3uHtjiU+JbA2thIH9SPM+kc2tKWs6X0vebrhonEnpdqdikzqqqxQ3C9Hpktx+KX/IH3tiFOyBeLvWcgdQBafw6BFdKNSUUTLplOYGDkpaDxYpxxRzETh7xQFtZQNfH/9v6vU4y0QetpI5xgnsrlSRTFM5KHRT6nwRTzlCIDK+SpfwHRR79KcVyM+GYIB8k67qUaGSFw6/c6+3ErEQ5/7A4NP+c878mWMy6x12eNY17YqfgrzpHXJhP5shB7aOaf/LVoJCkuDNXUaYxXfobKwqbbZhQ4KIa9dhsgIGFeetBdkufMs4BoyksplvaWLZDNASpMSGuxPY37TE6/p6P0xnRBwp0PHSTrF2wr42fyxvkEJZ+43OFLBEyPnRhZuEeGDAOC9IjvT3kfDEDeNenVV4tyjsxJP1HtxDw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:20.0214 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 877f9ba5-19cc-47af-65a0-08d9bac41668 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: DM6PR12MB3562 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: T4NvFxohR9QLAflWlRnT9ui2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020563; bh=y8nYkSDwhO4yPl6AIyFfg53ElJq+p8oyt7pqQKk6m4g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tgiOLV9XBdDBmGhU6sy4hKh6I9hBZjfqSMdNdXXHO1hHYXZcheidivzBvHMwaH6wXKC 9BZlHZqJGX+bKj592wL/cnksCQ9xijqoI44vwghNvEy1YYqHv2bxrs5x0NE0LDIqe4Ofn bW0WW4rIiXNH6ZDT2c4fqKJR3MtAB7pC5gc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020563597100003 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Version 2 of the GHCB specification added a new VMGEXIT that the guest could use for querying the hypervisor features. One of the immediate users for it will be an AP creation code. When SEV-SNP is enabled, the guest can use the newly added AP_CREATE VMGEXIT to create the APs. The MpInitLib will check the hypervisor feature, and if AP_CREATE is available, it will use it. See GHCB spec version 2 for more details on the VMGEXIT. Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong 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: Ray Ni Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- UefiCpuPkg/UefiCpuPkg.dec | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 62acb291f309..7de66fde674c 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -396,5 +396,10 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt SEV-ES Status gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x60000016 =20 + ## This dynamic PCD contains the hypervisor features value obtained thro= ugh the GHCB HYPERVISOR + # features VMGEXIT defined in the version 2 of GHCB spec. + # @Prompt GHCB Hypervisor Features + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures|0x0|UINT64|0x60000018 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni --=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 (#84561): https://edk2.groups.io/g/devel/message/84561 Mute This Topic: https://groups.io/mt/87605558/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 Sat May 4 15:08:10 2024 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+84569+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020570006568.1999446700419; Wed, 8 Dec 2021 19:29:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ndmkYY1788612x2ppIbBIkjv; Wed, 08 Dec 2021 19:29:29 -0800 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.61]) by mx.groups.io with SMTP id smtpd.web12.6773.1639020568207471646 for ; Wed, 08 Dec 2021 19:29:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kK0J+jXDJ3FFgC/J8V49TYD9+k+WSPs5wnzaD9haf2a31c3QfElJ2s1++EkvUHw9G7hbjH1j+ZIadlILHpLF/744u9EKrU6cEKr+PKaAc77YdHq0fc3ktmjoKS5XbQ8T2obT13FjufVtweq/zw7E6NBMjzIOboO0TDF7+UAZGOE82dALjAg7CmiWD18qJVzX6phFNS7sSbmruFNF3L0Klwrf8bHEx+K4Jts06I13k0UQ6XYTmv/ZnCS2jdc5qTdqaGgU5IkVcgRF2bSt2mpNF49gfMUrt8ESjAr3HBsaSVWVbuSit8NJC16eUWJ9vC3ImdyrtAToK/JWAuJF8yLGiw== 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=+RozJ1lm1vcL+TYv6jXzlFdBtZv5BVhvnmmuCZ2UUyE=; b=en5PPSNB7xzgMLL2Hdp0VCFZHWF27wwCq5lgpz8b9Ulr+7jNWGu0jbFWr+Uhlwb4uHT5S0vGdPn5Cef6yH9RcMtPM19lhtvUogUAN6sTObWin/u+9hdg14Tnw9VLZsWY/gp0M+iSwFGTPJr6gEJNfMMkgCq8u9eyfWf2HWE5RDzPaWvpWKsXHbjUKMd2x8VEATF1eErm03+bLwUr3H9reJYEHinQuFEbGQH1KSCR6f+/fGlZDQ3NPCiA9aXBmkjIl0HSgbFIZWJiELrNt8hkm200F9ce1i3emj5v1kkxBxNfeqMl7gPZG4COtGmRNjabsOxcrrnEI+aGXcBsr5W9mA== 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 CO2PR04CA0182.namprd04.prod.outlook.com (2603:10b6:104:5::12) by BYAPR12MB2599.namprd12.prod.outlook.com (2603:10b6:a03:6b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:29:21 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::4c) by CO2PR04CA0182.outlook.office365.com (2603:10b6:104:5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:29:20 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84569+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=SATLEXMB03.amd.com; X-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:20 +0000 X-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:14 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Wed, 8 Dec 2021 21:27:52 -0600 Message-ID: <20211209032800.3802995-25-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7dcb1317-48a9-48e6-7297-08d9bac416d8 X-MS-TrafficTypeDiagnostic: BYAPR12MB2599:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: djPUU1CLne4UE6UVtF8HGoY5nLav0Ub9qPqSmbcULrsePg+GtGsAWXdJVYtFgDR5nzJMXw/nG2YMw7m6nZOJyy6azZnHIadEfqwjN9XwPWZMDDVl4iz0VHVwGC50IXH3l9O2JA+K4q4N6ldMzuOvA0TZAlx8svtGF9y5qmAV6L/+3Jf7w7bJTXl+YdnGn6qic3Qe9NgJGuOKpLivBxHFWBW4G2zTk4x+Soq0i1Z3ACnr8q/g/5ba54b89ioE+sBayJRtRDK0N8yI3GIzEdkAtkKAjNQbHWCojBtSoC1N10R0DFmN4aqQvMcgOOsoh6OvXlgN3Fou7odBO6AVc57cDiLtXUxhrJ5upO33CQMUq7GvNsEkC77lNQg0Fwu8Lzq7H2iuaSiJayVPiZ0SN3Wa4z/MmFdC3JuFdX4d9XKdLekRAGMMIlFN5U6csYN+dxKwDcdziEGsdj0/5V0XrpenySjp9bdUbyO8QU4CtQn8acWA6/ei+gGnTCcEvS5ydwuGZE1RNmsO4yxSNCn7sNcFCkJ38Cibl5ufdORiAFzq0TRZo6L3JcP4W1iatwq5qO0KrjOV90HrG3IPeSTI3X3PA/mdMIiaANOA8B1YopbCZYKdA/zJK0VPoCylk+DU7my8KQyMK5Rp1um/1M0ekMmXP6dBQ8usti3l/P9vtnRE9GLdSzGlw3MqQYTH9GfE+HKep41cMzKLQh+KMmNJk5JmYbDe2oIUMJaoYATVqqDVRxYpXMgUo+jDsnQ/YmyNBrA6QHAx8AJajY+g436wA69oyC4GUHTa/vYCmX0wmKpeLvsfSQ4DR3IFnStzeJ+w0yOwyKtZvxoR7fOOXw2ERmDUY1JECTpCMc4c0UDM2z8AUYWrPnlCwLpe4cUCtj6BUXTs X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:20.7713 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7dcb1317-48a9-48e6-7297-08d9bac416d8 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: BYAPR12MB2599 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: 5C5b5AgsdcXXMr42U5Cu29lxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020569; bh=uhU2CFDD9Sz3NunY3v9bnHbmjpuajHUf24pqSxLZZzQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SZvZlcJ6H89br0hmRiKYZjtfTMJ1PG+vQPxfz9iQ3LghntYkRxOkq90uSkcZDEuolZg OpKAs0Prd/DsKN7p/Rcfdbw8rYeYlj89esvVuxtPq8fEJBzZNB6MvHyFjcltbcsXfN3Fa d3iCgUxfnbsFdf5tiabVtvULzuCurw1AYgw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020570379100034 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Version 2 of the GHCB specification added the support to query the hypervisor feature bitmap. The feature bitmap provide information such as whether to use the AP create VmgExit or use the AP jump table approach to create the APs. The MpInitLib will use the PcdGhcbHypervisorFeatures to determine which method to use for creating the AP. Query the hypervisor feature and set the PCD accordingly. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 55 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index bada5ea14439..3c05b550e4bd 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -62,6 +62,7 @@ [LibraryClasses] MtrrLib MemEncryptSevLib PcdLib + VmgExitLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase @@ -107,6 +108,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index c60a153a059e..9b71f7cf2fab 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -24,6 +24,12 @@ =20 #include "Platform.h" =20 +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ); + /** Initialize SEV-SNP support if running as an SEV-SNP guest. =20 @@ -36,11 +42,21 @@ AmdSevSnpInitialize ( { EFI_PEI_HOB_POINTERS Hob; EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT64 HvFeatures; + EFI_STATUS PcdStatus; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; } =20 + // + // Query the hypervisor feature using the VmgExit and set the value in t= he + // hypervisor features PCD. + // + HvFeatures =3D GetHypervisorFeature (); + PcdStatus =3D PcdSet64S (PcdGhcbHypervisorFeatures, HvFeatures); + ASSERT_RETURN_ERROR (PcdStatus); + // // Iterate through the system RAM and validate it. // @@ -91,6 +107,45 @@ SevEsProtocolFailure ( CpuDeadLoop (); } =20 +/** + Get the hypervisor features bitmap + +**/ +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ) +{ + UINT64 Status; + GHCB *Ghcb; + MSR_SEV_ES_GHCB_REGISTER Msr; + BOOLEAN InterruptState; + UINT64 Features; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + // + // Initialize the GHCB + // + VmgInit (Ghcb, &InterruptState); + + // + // Query the Hypervisor Features. + // + Status =3D VmgExit (Ghcb, SVM_EXIT_HYPERVISOR_FEATURES, 0, 0); + if ((Status !=3D 0)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + Features =3D Ghcb->SaveArea.SwExitInfo2; + + VmgDone (Ghcb, InterruptState); + + return Features; +} + /** =20 This function can be used to register the GHCB GPA. --=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 (#84569): https://edk2.groups.io/g/devel/message/84569 Mute This Topic: https://groups.io/mt/87605567/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 Sat May 4 15:08:10 2024 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+84563+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020565321494.5679680744446; Wed, 8 Dec 2021 19:29:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 46MfYY1788612xEDfGNjhVrp; Wed, 08 Dec 2021 19:29:25 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.74]) by mx.groups.io with SMTP id smtpd.web09.6950.1639020564352595501 for ; Wed, 08 Dec 2021 19:29:24 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jj8Rj03X0OOhmyUfY08iw3VaRkbeq439WUj10k8rmOTuOJvpPBjsIY2rgYXeDPyZkgYoGTOVw8s8/EDbvt2euDOt00ECjxhg4orfpWQCNx1F17yOQyeFGiL1OT5a440XpgW2YpAH3aDUR0OiUF/iVdS3PhvpdvdMSSuE1c6hse3ShyYS6Ak+1xtN1VKGNej1vdFXD6udKwDamW5eWz+5ezu8pEueGe+ywxY/xYybURUp8WX0el33v3bDzyMChGGSGuSll1W8yODcqCIeQc0Pby1clEpT3qIuKBzAcuacRxUxvE9OrVpoEzhdBUObMqPFAPXmcfSgjPrBWeqgVNGaEw== 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=0lR/ixXj+hx1esNmRKafKALKf8C2O8MrLk7Kaz7xzTo=; b=XzCO1uoi87mHJ9JshLh8BmC4udBWA32VImQ10Inl6sey9YgpWSoxm7P6NPccuHCJR/7mwD4XXmGfrX1aN4TaIlNvPxlXaepHo86v1HkCn9272LIIUBNVA96OA1aRGu++fSDG9jj27/RLTemYITe/bk9btiSIEe9gU1YLj3sdGusJ+Y6hiy6BPAx0D5DI9nCrKFuxfd6FQCNlZO10yGONip5xoDcOJNFkq0c4CxmT2oQX8xOw7iyBhrH2CjyHvUovbEv0q5LNXC5psTRdoCiRI2x2/1gNjR4PPaU6DoJQfjY7aeqN1N63Xd+Qa+jXwwu6mPbkNOOhlKAmbz9JrUa4Xg== 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 CO2PR04CA0198.namprd04.prod.outlook.com (2603:10b6:104:5::28) by SJ0PR12MB5439.namprd12.prod.outlook.com (2603:10b6:a03:3ae::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Thu, 9 Dec 2021 03:29:21 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::c7) by CO2PR04CA0198.outlook.office365.com (2603:10b6:104:5::28) 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:21 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84563+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=SATLEXMB03.amd.com; X-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:21 +0000 X-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:16 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 25/32] MdePkg/GHCB: increase the GHCB protocol max version Date: Wed, 8 Dec 2021 21:27:53 -0600 Message-ID: <20211209032800.3802995-26-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4fc43b1f-8d52-4c24-0ab1-08d9bac41733 X-MS-TrafficTypeDiagnostic: SJ0PR12MB5439:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1060; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: cJk/FPPn1Dk7sz3mQfQ7CdEyp1ic4stro96jYgMswYZ3YJ0v2cunWywEdAoajO1A6Bae5D/phghaS5aBrMkeUtBtAmrdvn6CoQmFmxLaHv5/Mdlah0d8Aee8YFbstNOCA+aZhwO3QoFyIl2FAiJ+Cfs3VwP+76uR1YwxDuAQIowTqfowQyWt+6aNtSpRggU34on2906vcOsnr1dqsOGgTf/RbYG7a8uAoPutQqER4Jw2uOLCUKIFFHuvtsRtuGJGjGGrpxQj3wMSCe4cwxXqjzzyTTs7oTxDfsIg27BN/0M/bw2wUBLTSBH3A3uf71lG5JmpL4ni/0f/0AFK1d/+rNhxNCpLdZLxiCwJMyaGA6lgB/puS29Ee+c3faqehABbMphv8gstnyd0Ab/6Jk+tUERFz5If+8q4ZzycrH/bptmiIqPmsHyAHG30PgdyjPAy41Fy1zgOoGKFf3V07TGaM4w8ly87VaPNwGZlUePYSn151pNCLZdjk+v0Za4JM3w7tZGanf0Pe6gz6cJiRKm3FPS1dHNlFFRE1+rqmiTpDsFKDW3oixsgViz3PSbbQeqFy29XdI0M7DE7a85n3mw8wQ/ukuMSMp723dIl3OzHrRGPeRTR9Y6nn49e1e7pb3cH9vEoGhE/q5Flt8BZWuvJUcsv05kGvv+22HG9eorqLgSMxh45PubKvh/3ZpMdLFqhK/toQNP6liN/5Xdv21SEAafwb+ufU1EB8fq9CfitqilW9rYzCGHnJCTvUMMPBF+EOo+VQuRE4i62u4vmI77tcpEclbdsZlrK+PF3+bZ9oZAdu3w0BbLU+uClbXVlbixPI7cZ3HAwxnlBe31apO/S3WjIOYYrXFutG49obiF7gQao6JUBmRHxdKCxrwWYDij0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:21.3494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4fc43b1f-8d52-4c24-0ab1-08d9bac41733 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: SJ0PR12MB5439 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: laFkHSxqKfTvGH5vnUHkOFXxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020565; bh=MKCnj6NMB8YbK4GCDUIOrGxpmC4nQnjtMitHwETa+m4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=pfMJMuzbtj/+weGKURx665AK6fsm+cbkYPHxar+K15/wSEUbJiyai8s37f720K7jj28 3zLqJ9yUWYi/FZo5+p14U+38GMbLrjcalefMYrH6DPclU8AvJ1lw8mK+C8vCssl9K7EV0 Vc+v9VEqgRVKro/1irb+82wkm7CzGE/23S4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020565880100011 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Now that OvmfPkg supports version 2 of the GHCB specification, bump the protocol version. Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong 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: Ray Ni Acked-by: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- MdePkg/Include/Register/Amd/Ghcb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h index e7626a2c138b..dab396f3ede8 100644 --- a/MdePkg/Include/Register/Amd/Ghcb.h +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -24,7 +24,7 @@ #define VC_EXCEPTION 29 =20 #define GHCB_VERSION_MIN 1 -#define GHCB_VERSION_MAX 1 +#define GHCB_VERSION_MAX 2 =20 #define GHCB_STANDARD_USAGE 0 =20 --=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 (#84563): https://edk2.groups.io/g/devel/message/84563 Mute This Topic: https://groups.io/mt/87605560/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 Sat May 4 15:08:10 2024 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+84562+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020564799238.9859709168353; Wed, 8 Dec 2021 19:29:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Lk1MYY1788612xeZAg7owPeB; Wed, 08 Dec 2021 19:29:24 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.67]) by mx.groups.io with SMTP id smtpd.web08.6800.1639020563649085053 for ; Wed, 08 Dec 2021 19:29:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c0f3dU8eJay4P8AS/uP9IO0RN/IJ5bwVv2+twG2xTbrkReAMCvADI4ZTyHDrLtHIQ3zjgZc6likLLNIBNSI9V/o+mm3kyilOhXVeRisrfS+oMRmYv5gR7R9pP9LB3CMLRNn3ZVquTKUJ9yvccOp4gGcu2tTy6yu+pBEf3Kx6DPoDKXUrV5cOnx1E5GjmlbAM+j2gv5ymIlS44ox9DcxqP/CJXATi36McZsShxbNrNMdYlnJQCM7OyL4yBxKlFSedSP4gzhjPATv+cKWZp2gJ+I1LI8sfa67BgFVVnueHd0pVS1Zj/5DHM6OteR/LNdl8k0caR6Q5+Tc7AxvwREzGpA== 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=+Uh3G/HXouVDCETkAETXYLFlbwzk/n/7dzPG6SRI/sg=; b=YGmKNPo5yMO1wZ3kfyLUbHxohODudcRxXxHp4QrW2P5+9H1haJstSd5dUrmi11yPlTsct1pTN51i6u0MWDUktZzPS90LT6fDF9rTtefAis2HpRxWfH0d3T/C8BmKGUZ+fMiN9hPQbfL5d007gpnKjzo3sjErFsn5QpPob4xcIna+SQdDtO/p1tU5XfLARAH4t4YQRLUVBCiYGzEnEXMMCbqeTysuupKD6G6cuZIzGfbmgw7x3C/0ZZt8Ef1EHLFzOcgFavOT+KVz+Hf3HuKG8lIB9v4D/2fj1nBlLwyqSK2ba44czA9XMp69AOau7ONwDv7eOunqj3znYnlL4rZ+aQ== 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 CO2PR04CA0202.namprd04.prod.outlook.com (2603:10b6:104:5::32) by DM6PR12MB4530.namprd12.prod.outlook.com (2603:10b6:5:2aa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Thu, 9 Dec 2021 03:29:22 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::bd) by CO2PR04CA0202.outlook.office365.com (2603:10b6:104:5::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84562+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=SATLEXMB03.amd.com; X-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:21 +0000 X-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:17 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Ray Ni Subject: [edk2-devel] [PATCH v14 26/32] UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled Date: Wed, 8 Dec 2021 21:27:54 -0600 Message-ID: <20211209032800.3802995-27-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e4f0456d-4647-464a-1986-08d9bac41784 X-MS-TrafficTypeDiagnostic: DM6PR12MB4530:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: T83zwzTDeVzF3fx3RzJmqr3gCxj9ccgaP2fwrMyDgetdlnW6mFE6OE6Jr8+4Tc+bmEp6Xu1l/inSg1uKPlmaoniiurqdRA1WERthqOAckaMPx+3EcwkA26zCCBhzU2k6yex6OZVVmFB/rPTn09FWVdIiCCDKTBlbv2dVtyVRibg9+yJRPzo3L8LH76KPVqS98pRNTbpGOB4p+vCDGS0wp1OmvqFQ35Ur7pyJx3N+oxh6Flev8LBYT38Xz+F0I6wgeJAGUEUDjSXn11Mp2iGuotSB1iGBlXdXmFY+6AZSKuuA3nwkCYiC3IO4DmqM7mQlA5/BfoqoJnGS+GM79NGdkbwIGBhin+vTSHheRjlRBnO9cC6zoMUfD/DL9xVv6yExAyGiLY2m6L0KVH9EHBZ27oouvJGhwdSScxBBiGpbvRx3E/9M3xNpt3dnWRN3wmoPILLXw6TF+yAUT+Vegq0lECvH5YMpvBShIDkPGn7CeBJs3uDbPma5vrLCzCxyz9LmYqkLKPKQeiMGpgQkhKmcjj9TnKp3ZfzHr96vWt/ANr6JWlQ4W0S3mgZwiRVeR9FXxfrVZDxkkV/4i+fqecqhfYlCAd0taz4uX4NFdVdOvB7b4taT7JfFjdl2EY3yBNmSa0uFrbdVMxavR9QDHais8+V9LX/VD2au7eh2+NW9a07T1b9E9hjCZxU/f0bBOmP1WqBA+ODPwAxLRFs2nuzKO9mUxCiQR8z4Z1bwLrsP/7dYUzuPjpne9/J/jS6VqzpMXP2FwWHvl5tbbzeMDq8SoejZuvYuTbPw47uc3ZhZzHIXT4LMHU1DhpHSbYmhpnJLoJNyxsdCFvitfye0I2djnghWN69zFdebbKrIvfx1BxjfisK1e2QBjny0D3ggkEW5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:21.8963 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e4f0456d-4647-464a-1986-08d9bac41784 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: DM6PR12MB4530 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: X9u3Pt0A66gJRIAcLqMYEEUSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020564; bh=Ex4YHlyevNzqXRvZST4IOMqpBZKeAGuaiSGiwLgqh70=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=f7QrQ10TpFtUjqtEc/l6UDF/b9Tt+xl632uCU7AbaPUvdVNqqEhBT96dXOHN7kGDGIx hXOduvUrdO43EKoDqCagARMkulvuY+DZxDCQaOnxOipMkkDmkx8/BMjiJ/y0biGMs8Any +jszN/OGuDzFT0ad9evcrjKbAea88YhFcXk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020565808100009 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 Acked-by: Ray Ni Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.c | 12 +++-- UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 54 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a84df60519ed..56de3bfb1ccf 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 64fddb497e1e..44a011ba75de 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -896,8 +896,9 @@ FillExchangeInfoData ( ExchangeInfo->Enable5LevelPaging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 - ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; - ExchangeInfo->GhcbBase =3D (UINTN)CpuMpData->GhcbBase; + ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->SevSnpIsEnabled =3D CpuMpData->SevSnpIsEnabled; + ExchangeInfo->GhcbBase =3D (UINTN)CpuMpData->GhcbBase; =20 // // Get the BSP's data of GDT and IDT @@ -1847,9 +1848,10 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *)(CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64)(UINTN)(CpuMpData->CpuData + Max= LogicalProcessorNumber); InitializeSpinLock (&CpuMpData->MpLock); - CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdSe= vEs); - CpuMpData->SevEsAPBuffer =3D (UINTN)-1; - CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); + CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evEs); + CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evSnp); + CpuMpData->SevEsAPBuffer =3D (UINTN)-1; + CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 // // Make sure no memory usage outside of the allocated buffer. 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 (#84562): https://edk2.groups.io/g/devel/message/84562 Mute This Topic: https://groups.io/mt/87605559/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 Sat May 4 15:08:10 2024 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+84564+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020565750960.31790115997; Wed, 8 Dec 2021 19:29:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id OottYY1788612xrw8gPrZ4eO; Wed, 08 Dec 2021 19:29:25 -0800 X-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 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 X-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 X-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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84564+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=SATLEXMB03.amd.com; X-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 X-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 via groups.io" 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: [edk2-devel] [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> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 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-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-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 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: H6C0BS4M0S2q16ziwI9L4Jnwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020565; bh=9zBY6AwkbOWzo2gEzY4ybK5PBm9CuB/IpasHUUouO6M=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=eTotRzMcBFEDPOT7cTIoVpXJhmJg8DP1tVcvWbG/g2/SYIKhULOS4R+08aehqmDolRq /zz7ZmmnrPYN1Xy7jTa9WLsWLZRjXb9T6rxX3yls5xet3iKLxz7y83KOjF3237QvsGskX 71CihkpU6MMU++EeotZT0NRQqQ0tYDAQMHg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020567930100018 Content-Type: text/plain; charset="utf-8" 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 -=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 (#84564): https://edk2.groups.io/g/devel/message/84564 Mute This Topic: https://groups.io/mt/87605561/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 Sat May 4 15:08:10 2024 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+84565+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020567581203.42174806220635; Wed, 8 Dec 2021 19:29:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dSwQYY1788612xZNYYyUvK88; Wed, 08 Dec 2021 19:29:27 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.43]) by mx.groups.io with SMTP id smtpd.web11.6945.1639020566617812919 for ; Wed, 08 Dec 2021 19:29:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PyhFknOm8LHz+zSdJ0Sb8WQS90R+LEhCip1NkwlJyHSI6ehTKm2fD4/1NWNRWRVVYhEllb283BFjOlbBWURZhO0dgwK0mjz7qwbu9xBdJ4HNOzIAewAzGrWPgFD3xR9XK/OVdRV1CajdUeBTvmJOFNhtoKccjeRSYAz29xiDa/6JeBxDIppWcFmj/JILPOLEAOw6CTcsBODrWBRN4s81xg0dcyesjNcH+AsGerZGgTOZge9/Od+PktK/UGu+OQrDM52pY9Ld3PFzFNitW854wfrRy/27q1XQAtkH/CeF/w7kuC6VDIsVzZTNkcK54HZFim8dgBJJ4VqJzWarMO3evg== 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=U5IHDWwx5eEvEn+S9y8BqdCO1Vpl2Bp91uBmvKjsET0=; b=KvmDGP/rWGqojJ9hF+7MqkChP9jMaTHUlZ5+Q+4cQX46TrsMsfVTZWDBTXKth1uW4TAm3ekmSnIuVfZI4qisULzkO+XjvJdspGOMaYNq+42l8bRQP9Exsge3hH4ULHfP9kh00TwYTJeNH0D9POInG+EAJ1zXjap92oc/SjvUEocrDGgSMO1jWE06BDS+yaOY9V41ObNncgAlSPPs7qAdWRbZrcyw4ySmz8qwNqpTdykk4X2p2VenJkM7AEY9QbmeYrSzINZ52efACCy4FbYqV+kIBVRo0UgeRhU8UT7RKQRt9pY4OuARrCJyuEa/yb3RWP7ZUPQ0j8qUWP/VG61xOQ== 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 CO2PR04CA0201.namprd04.prod.outlook.com (2603:10b6:104:5::31) by SA0PR12MB4574.namprd12.prod.outlook.com (2603:10b6:806:94::22) 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:23 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::5a) by CO2PR04CA0201.outlook.office365.com (2603:10b6:104:5::31) 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:23 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84565+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=SATLEXMB03.amd.com; X-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:23 +0000 X-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:20 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Wed, 8 Dec 2021 21:27:56 -0600 Message-ID: <20211209032800.3802995-29-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d75a11c9-ba06-4ef3-0e63-08d9bac4183e X-MS-TrafficTypeDiagnostic: SA0PR12MB4574:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 8JZttarudDzvB8usqvWWgxjx2oUKpvlCfy86FSCLZLJU3frFMf1BJYZSVV7NDLvsa1qmMtpinQNOaJM4tAzLkI/fNJK7bdXI/PN89JkOs8uklkrM05bXUkJBGepx+rZ9vQUrq5eSnc/8mHYy+JMIPfGbThFfm97kexIzcOqIZLYuZxPDXcxR62W4scpxvs+xH8sjba9rxeVAphgJJKo/ml9/FzpSTLCUZmUKyeYwgugqJQNTq+KYH1LNYHSeYBw+V4Vbk/WD/86zjCa702CKCwSFLqydEt1xGhXR+Sw4YBnEme6t0tMPfdeL88jH6lCGfLoTTkZHiKuiqUHF7wXji+C6M3uZpIjdBHELzHsI+jsyg2uy3VPrJdCiBPyDyPW+DXDzX7eOaI3ZKWWMqfaVdgCsdZfXyARoZB4/wdfAosLbiur0v0DHS7d59CjKzlo+lSilT9XSqXiAaNU+ak6OMrewBb3H7i1PytBt/8ft9JNSIqUd2oIyWpJ7mxP+vkBr144rPBQuBTwNvc9++aOM+AZFcToqdFSfA8k2SY99Qg2dn68oq/BZQKLxUkwc2zW65T4We1yTxkCwVQB4i1kdauCPAcnDKmRKKhbuGwuJEe2njL3Pfv9jtqa2PrmqCTAuUlISsM1/3gjwPWKeENrOO8p3Uehmx/ifzAhGVutw7UboN9kYipVM+WuaDo5ERvUcK0N791idgjQ13r658ylM5VlhkdMKJDQ1DPD8CCbKNmKMYk8Q1z8tEq5ZSByR1qqm/2A0RfiUJL2ye9QST8SOfSlbLIKJPCFKE/ddINvor9k5RiNnajG7brgdUfp4sLWxMewbExGLWub33hBGC9alM2Vk9zprGHnanI6C1M71QLRyiJKweEMJRR4griuEXOW6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:23.1149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d75a11c9-ba06-4ef3-0e63-08d9bac4183e 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: SA0PR12MB4574 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: 5hSTpPN2ieXeWs2WxI9QWHFwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020567; bh=OoUoIxxS7fMb2vN1qkuXnafn1MWw9YtOBgVrldfbAbU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aWmmo+xE1sR76Bnk59ZL6d9Vfu2r2b2KpKxqFAAeN6ehX33kqp+OQ23CQOfImJ7Qvon D6HOPeaRHfsr7/gFn7DmCEtNMVWEUPTQvgI7jDXhZuziUiisHKVZT4+OknddsnH52PpjJ kkitX2uSrCLgH58EowOhnJ2VZz0vsxI6zeY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020568049100021 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSev{Set,Clear}PageEncMask() functions are used to set or clear the memory encryption attribute in the page table. When SEV-SNP is active, we also need to change the page state in the RMP table so that it is in sync with the memory encryption attribute change. Cc: Michael Roth 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index f1485722f7cf..814f814035fa 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -17,6 +17,7 @@ #include =20 #include "VirtualMemory.h" +#include "SnpPageStateChange.h" =20 STATIC BOOLEAN mAddressEncMaskChecked =3D FALSE; STATIC UINT64 mAddressEncMask; @@ -693,10 +694,12 @@ SetMemoryEncDec ( PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; PAGE_TABLE_ENTRY *PageDirectory2MEntry; + PHYSICAL_ADDRESS OrigPhysicalAddress; PAGE_TABLE_4K_ENTRY *PageTableEntry; UINT64 PgTableMask; UINT64 AddressEncMask; BOOLEAN IsWpEnabled; + UINTN OrigLength; RETURN_STATUS Status; =20 // @@ -749,6 +752,22 @@ SetMemoryEncDec ( =20 Status =3D EFI_SUCCESS; =20 + // + // To maintain the security gurantees we must set the page to shared in = the RMP + // table before clearing the memory encryption mask from the current pag= e table. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); + } + + // + // Save the specified length and physical address (we need it later). + // + OrigLength =3D Length; + OrigPhysicalAddress =3D PhysicalAddress; + while (Length !=3D 0) { // // If Cr3BaseAddress is not specified then read the current CR3 @@ -922,6 +941,21 @@ SetMemoryEncDec ( // CpuFlushTlb (); =20 + // + // SEV-SNP requires that all the private pages (i.e pages mapped encrypt= ed) must be + // added in the RMP table before the access. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D SetCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState ( + OrigPhysicalAddress, + EFI_SIZE_TO_PAGES (OrigLength), + SevSnpPagePrivate, + FALSE + ); + } + Done: // // Restore page table write protection, if any. --=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 (#84565): https://edk2.groups.io/g/devel/message/84565 Mute This Topic: https://groups.io/mt/87605563/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 Sat May 4 15:08:10 2024 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+84566+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020568568514.5445459442474; Wed, 8 Dec 2021 19:29:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6iQJYY1788612xywGSis6Hhd; Wed, 08 Dec 2021 19:29:28 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.77]) by mx.groups.io with SMTP id smtpd.web12.6771.1639020567515130768 for ; Wed, 08 Dec 2021 19:29:27 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HYB2p3DDhvwVUDyRE8GPVsnDPin9KfAfc1Tj2dMgPmmLzjYDRrsMTigXroLQob5sfZZ6J04MMPASE2pbNOwRvgaDpjQkGRjffhjoL7qFt2BLGqzD3WGyGwsmFU4vMSjB8favFtu/rp+/kQcb4d6tHNdd2Mi6536G318CTDs+ehQwEl9xU5Fz1FTrCmd3yhtwJY5Z/FjNCQfAQGqX0/q7iGmAO00ijP0Eb7oDsak9tZMfq/WVyCMhBzSNE5TFYgBvsstMwmhNM7kUx7xFq1mipkLdmYRBvwagRVohWOkxtStxrQw2aMKXd9IhX+J8PSBJfPlBsLM2G3ck75qk0qg69A== 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=D7OmvnCDjUXJ0j5+hDzugV0b85XsbMqd8TbKHrtBYI8=; b=U6zdtk0k9Q8V3nCOZQ1ngO+0jLQQCLzMmMXkIzPe1EmwXxFxiQZngIZHBMttLKphywh5mzyMkg1A8q35cE4d8KyxK16Mhp4l66zrc56EfbNVmaS3tcJO1DRzEGmxpgOCWntdOOi5JSI1aRWeIT9wAc1nEdW17bGrIBTDIruH240iggQ0fi373IXPwAVX2ykG7G05BgmHr3oPECUZDNVyc9N1XgoM9JQMNMX01JGxw7hzWpmA4DhbP6W0AOu1pt/Wv/dwQrikn+NVYM6ALkapx2ZqHP68LBT6V1EarH6WLqfBSRwh2MiKjQ8ei2sfzYK6A31KYzyAkuDmimU2oxyCyQ== 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 MWHPR22CA0070.namprd22.prod.outlook.com (2603:10b6:300:12a::32) by CY4PR12MB1272.namprd12.prod.outlook.com (2603:10b6:903:3e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20; Thu, 9 Dec 2021 03:29:23 +0000 X-Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:300:12a:cafe::d6) by MWHPR22CA0070.outlook.office365.com (2603:10b6:300:12a::32) 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:23 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84566+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) 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:23 +0000 X-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:21 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v14 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 8 Dec 2021 21:27:57 -0600 Message-ID: <20211209032800.3802995-30-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9978035c-46d6-43d0-b52c-08d9bac41890 X-MS-TrafficTypeDiagnostic: CY4PR12MB1272:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: fI8zCKcKEG8EhKgvE0t4FX88y+Llw3Yn7b7JrFgZEoJwf5luJf0yo9vOPSylxNg9IS7K6LbHDn6ZgbO7ni0cs9E41T6yGcxiQi8wE9efZNTAm0GZwS9riOVhR4lxCaKdw8YKTdIk+X3QPr4RrEPcQedr2Xodx+BuejZKf3rU1CAZj2ErZg3mskG4JO/AdmoX7BA7zlS2AM8rzvL4coPUNgVNi+TX2XL3JiGCFUneNWZDQ5p/XGUB5aGbW0eTcivnh4TbYQJuWucPultwdsldozzqjA+rELG8EVg6kOStVyeEAjPq/yhvNvXClhhtWRTw2MYybag+t0dlv9h4R46ysodQBXdvI0DKd0NAUR2w4G+sSHVgzLyfV210iBjvK7+m2DYSUe03ggfKzX41YnudxhkTKpYh5eYPd35JpM8QIJpf6kegvYtB1L3tblL0FwcSrb/bP2NGfGYtsx1biNyQZlXwNLC0jxMioOn+OvkMZ4fdcqvrxMD2HVOoobGGuPWbyd6RVWgB7pM6ApPFma2W75L12grdYCm2EQidE/d7NdMrHOnA6wlijZkETAYDaQo87OgeCr4tpkgg4W7OZEgZB/9x5v42hpl59ID3PuTQedOYBjBJdAEZ88f/Kl467mIBDuuj6I3FFMDgxFGa+SEUkz5R9QEJdK7+7usffFRdha94zPkxmZJviytx94CXyZSIylYXrlT5gDq31nsNtZQ7d7AQD0tpUYhKCT9zIzPOYrVjsl4MKsQjtHqZ//Q4YElh/ANZYhMBdsUSaLAfBBcDjs96XNxVCQ0Rt7SoGT+Xi80= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:23.6566 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9978035c-46d6-43d0-b52c-08d9bac41890 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: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1272 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: lOsRXJ1BKnnARn271XwrNfxzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020568; bh=QYJOzqxuv1FYdoFWLf3xgRGmTSC6vJhsYo+YICQnaFM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=QRHSkbDS2/MvzoKQJXhf1Vds4zSwCKFrvjsDEqHR6Xk5P7RLOrj92QfQOquKBMQvn9c MtgR60xx1Jp9SUZeRwyh+Rn5UGwo4a55c/cv9388CPp1b9RAnEDXLPoDvhI/3bED7ldzF qUjzIwUJp9SeLSw9DBiEYH/liXBlpdDxL38= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020570133100025 Content-Type: text/plain; charset="utf-8" The SetMemoryEncDec() is used by the higher level routines to set or clear the page encryption mask for system RAM and Mmio address. When SEV-SNP is active, in addition to set/clear page mask it also updates the RMP table. The RMP table updates are required for the system RAM address and not the Mmio address. Add a new parameter in SetMemoryEncDec() to tell whether the specified address is Mmio. If its Mmio then skip the page state change in the RMP table. Cc: Michael Roth 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: Jiewen Yao Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index 814f814035fa..b9c0a5b25ac0 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -671,6 +671,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( @param[in] Mode Set or Clear mode @param[in] CacheFlush Flush the caches before applying the encryption mask + @param[in] Mmio The physical address specified is Mm= io =20 @retval RETURN_SUCCESS The attributes were cleared for the memory region. @@ -686,7 +687,8 @@ SetMemoryEncDec ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length, IN MAP_RANGE_MODE Mode, - IN BOOLEAN CacheFlush + IN BOOLEAN CacheFlush, + IN BOOLEAN Mmio ) { PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; @@ -709,14 +711,15 @@ SetMemoryEncDec ( =20 DEBUG (( DEBUG_VERBOSE, - "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u\n", + "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u Mmio=3D%u\n", gEfiCallerBaseName, __FUNCTION__, Cr3BaseAddress, PhysicalAddress, (UINT64)Length, (Mode =3D=3D SetCBit) ? "Encrypt" : "Decrypt", - (UINT32)CacheFlush + (UINT32)CacheFlush, + (UINT32)Mmio )); =20 // @@ -758,7 +761,7 @@ SetMemoryEncDec ( // // The InternalSetPageState() is used for setting the page state in the = RMP table. // - if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + if (!Mmio && (Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); } =20 @@ -996,7 +999,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1029,7 +1033,8 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1062,6 +1067,7 @@ InternalMemEncryptSevClearMmioPageEncMask ( PhysicalAddress, Length, ClearCBit, - FALSE + FALSE, + TRUE ); } --=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 (#84566): https://edk2.groups.io/g/devel/message/84566 Mute This Topic: https://groups.io/mt/87605564/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 Sat May 4 15:08:10 2024 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+84567+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020568986886.9758665340762; Wed, 8 Dec 2021 19:29:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id TzbwYY1788612xT5489kh4yO; Wed, 08 Dec 2021 19:29:28 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.46]) by mx.groups.io with SMTP id smtpd.web10.6836.1639020567702591459 for ; Wed, 08 Dec 2021 19:29:27 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QXc+uHBlkD2ELJ2uIM9bUrOiL+dEyLv/Bzt5jpPp07lugnPKzzbzoB3JPcTgbqvPCCEn4sMtNcn08EyIa965FSI/4NvNMzBfQJhO63AaIg746MKAFtLatFS2zuRXMb6B/oi8+wzE2iNqMsNe5wP2GKWRlIEErQomIzl1J73JltLXUg586MCuVLaCtpeCcgLSz+bKiEyG1bhcxVJFtFt1Ea7iGKOYP7A6icZrykaojxGmooJ0QMQytO8hoM/iFiZ1u9BMxklU27IxEy0+4pyeRVf0I5hxiK4D9RzgrEoOe8BQmBSdxX62KW4HQeZuO9hKQAsLCNcCobw+wLzOI0x9xA== 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=quoJY9fBDOmf5ayCixxmUWJb49SOCGCcV2wXBN6dWaA=; b=Koo0UXfCZVdXfZtx4xlr5S0Pd9nKn5FAJ4LcUN51QFPRUHwK12d3qy+uyMeBCHIglbvaKm5TVz1/kBE9qL6kFIg2Andkss4/GIDZ/hSiqtg/wDySf2OqdqJ5NOJiZmWhzobghgC48fzZrfjcZrhutGCgJV0qKYQ158NRO0KF6CwD36B0H0jFBHPmR9Eyi4vPEPOGcdqcrlCiUgPrS/CNvbK4V4Cn9p6KxYK936p1M6CJdG4rtzqL12nPoZjZZn4bDAqkA7Z3JCNadnjLlr7esF0V8N85v+F1j0c3ayUTzkstbJxLjtSMAGBWF/JxwgUHy7eIoHWGhTjnl5NzztxDYg== 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 MW4PR04CA0038.namprd04.prod.outlook.com (2603:10b6:303:6a::13) by BYAPR12MB3638.namprd12.prod.outlook.com (2603:10b6:a03:dc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Thu, 9 Dec 2021 03:29:25 +0000 X-Received: from CO1NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::db) by MW4PR04CA0038.outlook.office365.com (2603:10b6:303:6a::13) 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:25 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84567+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT010.mail.protection.outlook.com (10.13.175.88) 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:25 +0000 X-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:23 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Wed, 8 Dec 2021 21:27:58 -0600 Message-ID: <20211209032800.3802995-31-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23ccc662-cbc5-4122-3694-08d9bac41996 X-MS-TrafficTypeDiagnostic: BYAPR12MB3638:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: BwXnKNy+x0Lip0Z10OPdiddYjseWO2lmxC5h6BUWitmbcUXm+ymjoY/82IzP6P599x0g0YH7HFCwYpznEpLssR3Dxj4g9mXECxkkGHJq2Xa1pEuUoGzG/Nu6Lmt9lp3nfQdjFsuSmAYmqnPYEiRjahK83GdEz7uYzR9lLl4rZyVHWJsUTZosg6CEa6MP4iLSDpZIqvnj8tbjpWnJlr5y4CkYzLihfCLY70I3TQEAi82agbfzq2djrdgI9w3kvTgfx1UsQekfmvgnvmuCzr4V+UpKetcwaCXlAr6uA4AaSvhYY/uYr7rMQFZmuSCCpXVcv26sl2MWLDT50h7AgeIVniO1j+Dn9a9XSflOlu8Zfxk2xxT1xuQ2BvWY59+0dTm1WI614EhfNmewr7KzR4I+SFJWRxhIEgZKz/cxEBM/6uoeISPbM9xRSmolwUeS6UkuMAcVjNBRCSuoJwq/IvPxbzxIaWVNjzRpl/oDH1gRBUZrH7ncp0EF7kk1kMSPHsuRvx+YPgYSzcbgQd9x3xBXshVSDoiKpjzZQiHLl/PkKc88i/cUTGacnvViApYliD0NiOVpRAFV3Lu/6AwXB7kZFzQKOeqHjQX8APwjio1z6XFQ08cf3uZL0tZzYeZQXZLvAxQxFvQyeP7h5NT5PD32BHidLIM+SCsRaoWPVKzFhM0FcuuQ9Io/f4lFIqa9lb8ZtzIU4cdNBtBRrA1sgoqS3nLLITD0kh4LU2OQSpKymIAExe331upYKx/bzSQBOprYqkElj5VbByS9Ih5Q/L7Cln7LazxRTGh06SBmaZado1A= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:25.3704 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23ccc662-cbc5-4122-3694-08d9bac41996 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: CO1NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3638 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: l1PUbnK8bAXAEl8O3tJY9Qeax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020568; bh=F17eaA7mDDAkhsAENpJbpwuiTJiXuSgLe5rXhzgBxtQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Uze63q3ES6Zra+d54y/E0Neq0+DTuo6Rxynho2NUcT0GmZ3b3XD/3Zf6cyUYZyddkNe 758NqVP/HduswGIAme4dE1aad2o2h4b7Yxz3xzy2N0rKnIeUCt7FGRsr+jgwZFgMPBz3G BFspb8NiyOVnsxp0fgn9FCtcKoah7tRfuRI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020570231100027 Content-Type: text/plain; charset="utf-8" When SEV-SNP is active, the CPUID and Secrets memory range contains the information that is used during the VM boot. The content need to be persist across the kexec boot. Mark the memory range as Reserved in the EFI map so that guest OS or firmware does not use the range as a system RAM. Cc: Michael Roth 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 --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/Platform.h | 5 +++++ OvmfPkg/PlatformPei/AmdSev.c | 31 +++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/MemDetect.c | 2 ++ 4 files changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 3c05b550e4bd..1c56ba275835 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -111,6 +111,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory @@ -121,6 +123,8 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 357b3d4095c3..24e4da4e1d93 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -104,6 +104,11 @@ AmdSevInitialize ( =20 extern EFI_BOOT_MODE mBootMode; =20 +VOID +SevInitializeRam ( + VOID + ); + extern BOOLEAN mS3Supported; =20 extern UINT8 mPhysMemAddressWidth; diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 9b71f7cf2fab..fb7e21ec140f 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -416,3 +416,34 @@ AmdSevInitialize ( =20 ASSERT_RETURN_ERROR (PcdStatus); } + +/** + The function performs SEV specific region initialization. + + **/ +VOID +SevInitializeRam ( + VOID + ) +{ + if (MemEncryptSevSnpIsEnabled ()) { + // + // If SEV-SNP is enabled, reserve the Secrets and CPUID memory area. + // + // This memory range is given to the PSP by the hypervisor to populate + // the information used during the SNP VM boots, and it need to persist + // across the kexec boots. Mark it as EfiReservedMemoryType so that + // the guest firmware and OS does not use it as a system memory. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfSnpSecretsBase), + (UINT64)(UINTN)PcdGet32 (PcdOvmfSnpSecretsSize), + EfiReservedMemoryType + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN)PcdGet32 (PcdOvmfCpuidBase), + (UINT64)(UINTN)PcdGet32 (PcdOvmfCpuidSize), + EfiReservedMemoryType + ); + } +} diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3f59a1ac79f6..738ed0c208ae 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -871,6 +871,8 @@ InitializeRamRegions ( { QemuInitializeRam (); =20 + SevInitializeRam (); + if (mS3Supported && (mBootMode !=3D BOOT_ON_S3_RESUME)) { // // This is the memory range that will be used for PEI on S3 resume --=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 (#84567): https://edk2.groups.io/g/devel/message/84567 Mute This Topic: https://groups.io/mt/87605565/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 Sat May 4 15:08:10 2024 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+84568+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020569619578.242278684096; Wed, 8 Dec 2021 19:29:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id UYllYY1788612xlNUfSsG2xB; Wed, 08 Dec 2021 19:29:29 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.55]) by mx.groups.io with SMTP id smtpd.web12.6772.1639020568003457527 for ; Wed, 08 Dec 2021 19:29:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GG8t393rqz9DWd/EJOfqXeT+VZ6KNhYaVw9SzjBmzHIZy3uB3gdTWGHS20B+w7tSYw1X5ielEF1HpbpnO1QNGFpgiPfnYgigUMeAIonXM6oyZJUnHe1WJaEBhQ5K3JYE4p7ItXNhm51rwCotAYrJvBmCiL15iZsO4tDKkGfLqSumedD87oxDvsVRl2noieUhlrjK+WyriN9bK/wRQjXkarICN0MQEPyxyfHp0jCI/soCBmNO0sgm39iq/o0QgIZVmuGjAmHLDl1o0wIbKcFvwtGBXISV99Rsjo2UQ89WJzehKU2AwfAOqznTsNqpuI9L0DPDQkd3s1BhTQGNNDcWaQ== 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=RB7b74NbN8PGMcytdnbhcmwPQRATMLFGwLReLLCqpYk=; b=Vp3AF+a7Q2MLLjLybfKrytHyMMQzc4LNIflsFYcVRhRPLzeNM2kZsEmX4L7kZ/vmj9N2n7ptxGipuFxz9rIdn7uyssmslXz4h2ctczP3azq4/ymgdnisbj3ep+ty7C6b3DLljryLEhpdWa1ZxjlVaaeAI1RlcqF/rSvYpSGPmXHtYAdcfTTKrCZHeIK6DC7umhaEgg68XB3EWsYZA5u8h1gTB5uBZxHIsZ/CvPP/tiFAmSRRa8+v6AHTlqYkmDTAL0fHcHTY+EYjUXhzIp6miBkjjtKsJQKfNc6r0nI5Xm1ikbXiP3+g6efJ0+Tu04Wzr9g1PCfV5ImkyBRBhGJ3xg== 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 MW4PR04CA0048.namprd04.prod.outlook.com (2603:10b6:303:6a::23) by BY5PR12MB4274.namprd12.prod.outlook.com (2603:10b6:a03:206::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Thu, 9 Dec 2021 03:29:26 +0000 X-Received: from CO1NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::5b) by MW4PR04CA0048.outlook.office365.com (2603:10b6:303:6a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21 via Frontend Transport; Thu, 9 Dec 2021 03:29:26 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84568+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT010.mail.protection.outlook.com (10.13.175.88) 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:26 +0000 X-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:24 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 31/32] OvmfPkg/AmdSev: expose the SNP reserved pages through configuration table Date: Wed, 8 Dec 2021 21:27:59 -0600 Message-ID: <20211209032800.3802995-32-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 005baa4e-1acc-4893-ba66-08d9bac419fc X-MS-TrafficTypeDiagnostic: BY5PR12MB4274:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: i5NhRE6usN8MmAJF7Ghg65fROxwo43LeJxUQHXIfGvmRibNRTmfmpvxXu1rP0V4cJvI0bRnSSDTqvM8c2K0eZQIPHWD0ZgEU/rgn8Q9xnGy7eE3rSGjC4vDUHCuHiaAGuZRduZc1iQ4EXwLva9clrltJdF9OeqLNt+CBomJdfh1J2Mxsn59bdsJq7mXgLxlB2STcQj9bEYjQgPQ0OdOD4T7pOX0oYgIHuUF6XXmZADSj2LbMlgSyDalQTdB5YH/KgtuKOuCiTcTaE4F1gS/pVWE2ryFsu0+QUZ3f6OLQmgtQhkLQJAcxqzVKdnoMqHJmYU2/vCkNYCbuubsCIlfHuhReo7Qg2C70UtG1nRkupKzKY+Te7/EMqV134qO+rN7Yg12tEjGsjtuZwmM4vHFAQ4u5eIYDkgp67jj51BkHtuvcNNJj+FyKRFszkUliG2jUp0muooBHicmNMdHRAk0KNeTqF0qG7Dm+th2bcGbu6sHpbrcMjaqLOHHm6BwxoQF/bAChFp6ncDRmZp2Pwn5pdjY/l3PSeBVsBxhDMsNLUvnvzFPABTeqW/K4kloy3uc/KFGF/lDi+1fNrVYl8lIVey2qzTIFYu735+XgJ81vEvofGcH7vwDyF1YeyNIASHV/lvlR74NPghBuSlV00e2SyO8grtWaKE1tqry7OLGjOXqZ3LGK4tU82Cal0u0ULoCm7b6fHT/OyuhbMKBenqfvJ/R74xJR2iRVZVGAwrltivnidFgQHm2uxGr7dv/SKvd0aEUciWtqHbTrcZ+1ITXT+kNBvey0hmJJQ4HB5CZ76oVTU6Jb8KAS5J4Zm4RYS1GK0HaiRGDMqFtdG6CICEzyqGJZFVG7sFbxLR921HRqKwNChnZwIiZ6q2py9Ci206dI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:26.0266 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 005baa4e-1acc-4893-ba66-08d9bac419fc 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: CO1NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4274 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: keEGDvq0atQy9Ndo4EU3C4IUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020569; bh=tS8TnO7BvGwIMRpwvsmVyU21nyDuez5gVTgxPEu2764=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=g5fo1haGAohuzFTubwUhV9jL0YBAqmiwlAofN3z15tvlEwAv36jiGwN8kzwGzlC4PIN jc93zNASfy8wvurm6sctM5idwoUpDgTlmlJPVJWPrTlyzaaxnL3P5u/Faiw/Q5clymsoB HhuV2ChvX+ORfnWPwZwRnJBEoip2uQgrDh4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020570334100032 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Now that both the secrets and cpuid pages are reserved in the HOB, extract the location details through fixed PCD and make it available to the guest OS through the configuration table. Cc: Michael Roth 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 --- OvmfPkg/OvmfPkg.dec | 1 + OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 7 ++++ .../Guid/ConfidentialComputingSevSnpBlob.h | 33 +++++++++++++++++++ OvmfPkg/AmdSevDxe/AmdSevDxe.c | 23 +++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 OvmfPkg/Include/Guid/ConfidentialComputingSevSnpBlob.h diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index c22b846cd663..769bef0ffa12 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -124,6 +124,7 @@ [Guids] gQemuKernelLoaderFsMediaGuid =3D {0x1428f772, 0xb64a, 0x441e, {= 0xb8, 0xc3, 0x9e, 0xbd, 0xd7, 0xf8, 0x93, 0xc7}} gGrubFileGuid =3D {0xb5ae312c, 0xbc8a, 0x43b1, {= 0x9c, 0x62, 0xeb, 0xb8, 0x26, 0xdd, 0x5d, 0x07}} gConfidentialComputingSecretGuid =3D {0xadf956ad, 0xe98c, 0x484c, {= 0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47}} + gConfidentialComputingSevSnpBlobGuid =3D {0x067b1f5f, 0xcf26, 0x44c5, {= 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42}} =20 [Ppis] # PPI whose presence in the PPI database signals that the TPM base addre= ss diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf b/OvmfPkg/AmdSevDxe/AmdSevDxe.= inf index 0676fcc5b6a4..9acf860cf25e 100644 --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.inf +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.inf @@ -42,6 +42,13 @@ [FeaturePcd] =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize + +[Guids] + gConfidentialComputingSevSnpBlobGuid =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId diff --git a/OvmfPkg/Include/Guid/ConfidentialComputingSevSnpBlob.h b/OvmfP= kg/Include/Guid/ConfidentialComputingSevSnpBlob.h new file mode 100644 index 000000000000..b328310fd0c2 --- /dev/null +++ b/OvmfPkg/Include/Guid/ConfidentialComputingSevSnpBlob.h @@ -0,0 +1,33 @@ +/** @file + UEFI Configuration Table for exposing the SEV-SNP launch blob. + + Copyright (c) 2021, Advanced Micro Devices Inc. All right reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + **/ + +#ifndef CONFIDENTIAL_COMPUTING_SEV_SNP_BLOB_H_ +#define CONFIDENTIAL_COMPUTING_SEV_SNP_BLOB_H_ + +#include + +#define CONFIDENTIAL_COMPUTING_SNP_BLOB_GUID \ + { 0x067b1f5f, \ + 0xcf26, \ + 0x44c5, \ + { 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42 }, \ + } + +typedef struct { + UINT32 Header; + UINT16 Version; + UINT16 Reserved1; + UINT64 SecretsPhysicalAddress; + UINT32 SecretsSize; + UINT64 CpuidPhysicalAddress; + UINT32 CpuidLSize; +} CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION; + +extern EFI_GUID gConfidentialComputingSevSnpBlobGuid; + +#endif diff --git a/OvmfPkg/AmdSevDxe/AmdSevDxe.c b/OvmfPkg/AmdSevDxe/AmdSevDxe.c index be26dde71f9d..662d3c4ccb0f 100644 --- a/OvmfPkg/AmdSevDxe/AmdSevDxe.c +++ b/OvmfPkg/AmdSevDxe/AmdSevDxe.c @@ -17,8 +17,20 @@ #include #include #include +#include +#include #include =20 +STATIC CONFIDENTIAL_COMPUTING_SNP_BLOB_LOCATION mSnpBootDxeTable =3D { + SIGNATURE_32 ('A', 'M', 'D', 'E'), + 1, + 0, + (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfSnpSecretsBase), + FixedPcdGet32 (PcdOvmfSnpSecretsSize), + (UINT64)(UINTN)FixedPcdGet32 (PcdOvmfCpuidBase), + FixedPcdGet32 (PcdOvmfCpuidSize), +}; + EFI_STATUS EFIAPI AmdSevDxeEntryPoint ( @@ -135,5 +147,16 @@ AmdSevDxeEntryPoint ( } } =20 + // + // If its SEV-SNP active guest then install the CONFIDENTIAL_COMPUTING_S= EV_SNP_BLOB. + // It contains the location for both the Secrets and CPUID page. + // + if (MemEncryptSevSnpIsEnabled ()) { + return gBS->InstallConfigurationTable ( + &gConfidentialComputingSevSnpBlobGuid, + &mSnpBootDxeTable + ); + } + return EFI_SUCCESS; } --=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 (#84568): https://edk2.groups.io/g/devel/message/84568 Mute This Topic: https://groups.io/mt/87605566/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 Sat May 4 15:08:10 2024 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+84571+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020577920313.40237951950417; Wed, 8 Dec 2021 19:29:37 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id e0W1YY1788612xd83YXi227U; Wed, 08 Dec 2021 19:29:37 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.73]) by mx.groups.io with SMTP id smtpd.web09.6951.1639020576163630543 for ; Wed, 08 Dec 2021 19:29:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W+cSUO1tqbO0yN2m6DuBjw6M/0FSrB7M7gAnJ6Ikh29coLlzLCLqn7FjL0zIKtAFyTDrQSgSyY30C4kkOBWP04LnC18ReWsjx8AGbLj50U2ubzQW/SbnO3/YPKYrZNwtpOexujzG9TVHHun0vFNRh2+ZMZtZJzPvc1IhVXEkZBwwaevjUft2md/a1gpfZpDhjsmxJRhca91AUrbesJThx8sdrB9OWjjHGedkfbZzLYdzt7tJUINbxyPpRDRE871TvPMCD32ATeL0HJzCOHlnHW+kQEV0NtMhJXl/7yaikL7MVHm9jkUgOVYmwlmKS/n/r60EnMTp5oNtkWULyVEU/w== 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=S+iW/Y+gMuUwcZnEtxgG9B6KQ+dEJ2kCma8+RjqdC38=; b=OGL6oDhUa6jcRTArG04MGLb7qLmwrzQSyvy4EG78ZyzpJT+f6snZJXl4cJCYc4jJlMHjKMHzlZG7E7S1XRlUN+03xIMJ4eBU05ndtSjrFQ79ikr+pW59cqB7tW4n9EMFe6kFdIm4FaoeZtRZlxZFy3m1sCN42a4ncJBLJ4lIrwiTadF61g5lv222xcFQ1GaeUfMVjscI3M1Nws0j9Nw9ca8JIYlJZq+cNDqnFe9hvBQiTMqd9msUWf9V4pyez3LEcO9w3sGarkvCSDK/n4bptxaR7Vo67otEzCQzgiKFYJCPgGUDq/GC/kh+EyxkEMENgOSvOULZrFemzap19MMKNg== 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 MWHPR14CA0001.namprd14.prod.outlook.com (2603:10b6:300:ae::11) by MN2PR12MB4814.namprd12.prod.outlook.com (2603:10b6:208:1b6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.24; Thu, 9 Dec 2021 03:29:28 +0000 X-Received: from CO1NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ae:cafe::aa) by MWHPR14CA0001.outlook.office365.com (2603:10b6:300:ae::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:29:28 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84571+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT041.mail.protection.outlook.com (10.13.174.217) 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:27 +0000 X-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:25 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Michael Roth , Brijesh Singh Subject: [edk2-devel] [PATCH v14 32/32] UefiCpuPkg/MpInitLib: Use SEV-SNP AP Creation NAE event to launch APs Date: Wed, 8 Dec 2021 21:28:00 -0600 Message-ID: <20211209032800.3802995-33-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c7b062cc-8f01-4bf6-4f71-08d9bac41b06 X-MS-TrafficTypeDiagnostic: MN2PR12MB4814:EE_ 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: CUn+OP7Q9K/QwvdyQIJtbeGcm2E/r3hP6Wsr2OQeLy6lSgMiviBCDOk3px2/BfY0VZ3Gol0Ov9/805j5bzlkG5ImbMnvRaLT/SjUwaNxcM0zS+oZCw1FmlJgzJH8YFpPVTs7foUF0k1JB+gyltJ39pi+fvCXOJEzu3Xez4gwEvnfEyRCnbhYv6St9fNOLMhUhpCl5Q9nDMGAb4eKc5nE0J25cT7DTk40NudPRN6IQXDk3BvhorwQaF/V/6GHSstTlO82V19AW8Ieti02xRBUY2TIrc6mPVyXUCkaPsrPSBvNX8DNoshBKr75OMSexOggXVMGzWY6v7vXi7fFk7fAwd3J0ElXynuk4rn5h2nn3QPu3KDyJGxHjB4uqX1zntuQXUPWzuwIt/l8PUprvz0wgf3a3IpYjNd1mymvbAuZwh954h50qNAyGHFNwXu6ZWyyB2720UI6dgYSzWvzzK1FHa6ssDKREWX1q5vr42QXF1fSQ6eNSlUqECUPeyk48OOzgvb/BrQlWoY2iRUEkKMUdUCq1V0fQBMIEDBK7pfpREXhi3R0J/IOrQhO9BKK+aN4CqT31ez+8ysHPUBR4qJ6NcmWRknzCsrcv1KB6eV1lkPbzQnloXcw8659VRDXzFt0kaujKxRWvcJ3T2tUIgqiiGI1V+NOx+sRRXpaJeUFrF5g0rF0tvYrC8A9c9HS1mddLXdJmadJXzjCbH9ztd4QvvXjE1NhTe9qHlyR6dHVZoGVc/Avod+ONZu349Y/MpRSQbdZe818k8l/FxO+eIqSbJiujQZNeB+y+A3bS5QNrjAYkp71C1w9zIysJr7VNDuUrYx/9iMN6YRUKyRo9xrpMgtzb9u8/L7QNaANUNUEWb9pgV8OTxPanjQQPbx+ydjf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:27.7671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7b062cc-8f01-4bf6-4f71-08d9bac41b06 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: CO1NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4814 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: pRQ4VvPDrA9yQAA8SpGj6Iagx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020577; bh=9hWiapABVzeZYcMuliohI6WQ9gGy3zdC6nwqnemxtbU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VaJXdiPV8stLfVJ6acBWeq36/xlBxNaItb3W8CNA4TKflC1w2WgJWb06TcdaSq4W/Lz CWWGJ3gWW0lkNkiyHfA9oXx0OJM0BNaOwf/D1omxobtg+Wp5AbgQXwHuqIQrfAERmQ4cW oH7VzQF+tP0h/h7T7x9vaUQ2YITM5VqfsXA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020579298100005 Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Use the SEV-SNP AP Creation NAE event to create and launch APs under SEV-SNP. This capability will be advertised in the SEV Hypervisor Feature Support PCD (PcdSevEsHypervisorFeatures). 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: Ray Ni Acked-by: Gerd Hoffmann Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 44 +++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 13 +- UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c | 70 +++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 59 ++-- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 263 ++++++++++++++++++ 7 files changed, 433 insertions(+), 22 deletions(-) create mode 100644 UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c create mode 100644 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index de705bc54bb4..e1cd0b350008 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -22,9 +22,11 @@ [Defines] # =20 [Sources.IA32] + Ia32/AmdSev.c Ia32/MpFuncs.nasm =20 [Sources.X64] + X64/AmdSev.c X64/MpFuncs.nasm =20 [Sources.common] @@ -73,6 +75,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index b7e15ee023f0..5facf4db9499 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -22,9 +22,11 @@ [Defines] # =20 [Sources.IA32] + Ia32/AmdSev.c Ia32/MpFuncs.nasm =20 [Sources.X64] + X64/AmdSev.c X64/MpFuncs.nasm =20 [Sources.common] @@ -64,6 +66,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOME= TIMES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures ## CONS= UMES gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONS= UMES gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONS= UMES =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index be67cd88ec46..7d84a56fbc51 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -15,6 +15,7 @@ =20 #include #include +#include #include #include #include @@ -150,6 +151,7 @@ typedef struct { UINT8 PlatformId; UINT64 MicrocodeEntryAddr; UINT32 MicrocodeRevision; + SEV_ES_SAVE_AREA *SevEsSaveArea; } CPU_AP_DATA; =20 // @@ -294,6 +296,7 @@ struct _CPU_MP_DATA { =20 BOOLEAN SevEsIsEnabled; BOOLEAN SevSnpIsEnabled; + BOOLEAN UseSevEsAPMethod; UINTN SevEsAPBuffer; UINTN SevEsAPResetStackStart; CPU_MP_DATA *NewCpuMpData; @@ -799,4 +802,45 @@ FillExchangeInfoDataSevEs ( IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo ); =20 +/** + Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page. + + @param[in] PageAddress + @param[in] VmsaPage + + @return RMPADJUST return value +**/ +UINT32 +SevSnpRmpAdjust ( + IN EFI_PHYSICAL_ADDRESS PageAddress, + IN BOOLEAN VmsaPage + ); + +/** + Create an SEV-SNP AP save area (VMSA) for use in running the vCPU. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] CpuData Pointer to CPU AP Data + @param[in] ApicId APIC ID of the vCPU +**/ +VOID +SevSnpCreateSaveArea ( + IN CPU_MP_DATA *CpuMpData, + IN CPU_AP_DATA *CpuData, + UINT32 ApicId + ); + +/** + Create SEV-SNP APs. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] ProcessorNumber The handle number of specified processor + (-1 for all APs) +**/ +VOID +SevSnpCreateAP ( + IN CPU_MP_DATA *CpuMpData, + IN INTN ProcessorNumber + ); + #endif diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 02bc9c2bd2c4..60d14a5a0e10 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -93,7 +93,14 @@ GetWakeupBuffer ( EFI_PHYSICAL_ADDRESS StartAddress; EFI_MEMORY_TYPE MemoryType; =20 - if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs) && + !ConfidentialComputingGuestHas (CCAttrAmdSevSnp)) + { + // + // An SEV-ES-only guest requires the memory to be reserved. SEV-SNP, w= hich + // is also considered SEV-ES, uses a different AP startup method, thou= gh, + // which does not have the same requirement. + // MemoryType =3D EfiReservedMemoryType; } else { MemoryType =3D EfiBootServicesData; @@ -380,7 +387,7 @@ RelocateApLoop ( MpInitLibWhoAmI (&ProcessorNumber); CpuMpData =3D GetCpuMpData (); MwaitSupport =3D IsMwaitSupport (); - if (CpuMpData->SevEsIsEnabled) { + if (CpuMpData->UseSevEsAPMethod) { StackStart =3D CpuMpData->SevEsAPResetStackStart; } else { StackStart =3D mReservedTopOfApStack; @@ -430,7 +437,7 @@ MpInitChangeApLoopCallback ( CpuPause (); } =20 - if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer !=3D (UINTN)-1= )) { + if (CpuMpData->UseSevEsAPMethod && (CpuMpData->WakeupBuffer !=3D (UINTN)= -1)) { // // There are APs present. Re-use reserved memory area below 1MB from // WakeupBuffer as the area to be used for transitioning to 16-bit mode diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c b/UefiCpuPkg/Librar= y/MpInitLib/Ia32/AmdSev.c new file mode 100644 index 000000000000..c83144285b68 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c @@ -0,0 +1,70 @@ +/** @file + + AMD SEV helper function. + + Copyright (c) 2021, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" + +/** + Create an SEV-SNP AP save area (VMSA) for use in running the vCPU. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] CpuData Pointer to CPU AP Data + @param[in] ApicId APIC ID of the vCPU +**/ +VOID +SevSnpCreateSaveArea ( + IN CPU_MP_DATA *CpuMpData, + IN CPU_AP_DATA *CpuData, + UINT32 ApicId + ) +{ + // + // SEV-SNP is not support on 32-bit build. + // + ASSERT (FALSE); +} + +/** + Create SEV-SNP APs. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] ProcessorNumber The handle number of specified processor + (-1 for all APs) +**/ +VOID +SevSnpCreateAP ( + IN CPU_MP_DATA *CpuMpData, + IN INTN ProcessorNumber + ) +{ + // + // SEV-SNP is not support on 32-bit build. + // + ASSERT (FALSE); +} + +/** + Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page. + + @param[in] PageAddress + @param[in] VmsaPage + + @return RMPADJUST return value +**/ +UINT32 +SevSnpRmpAdjust ( + IN EFI_PHYSICAL_ADDRESS PageAddress, + IN BOOLEAN VmsaPage + ) +{ + // + // RMPADJUST is not supported in 32-bit mode + // + return RETURN_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index b73a6e9a0ffc..4a73787ee43a 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -295,10 +295,12 @@ GetApLoopMode ( ApLoopMode =3D ApInHltLoop; } =20 - if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs) && + !ConfidentialComputingGuestHas (CCAttrAmdSevSnp)) + { // - // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB - // protocol for starting APs + // For SEV-ES (SEV-SNP is also considered SEV-ES), force AP in Hlt-l= oop + // mode in order to use the GHCB protocol for starting APs // ApLoopMode =3D ApInHltLoop; } @@ -763,7 +765,7 @@ ApWakeupFunction ( // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly // performs another INIT-SIPI-SIPI sequence. // - if (!CpuMpData->SevEsIsEnabled) { + if (!CpuMpData->UseSevEsAPMethod) { InterlockedDecrement ((UINT32 *)&CpuMpData->MpCpuExchangeInfo->Num= ApsExecuting); } } @@ -777,7 +779,7 @@ ApWakeupFunction ( // while (TRUE) { DisableInterrupts (); - if (CpuMpData->SevEsIsEnabled) { + if (CpuMpData->UseSevEsAPMethod) { SevEsPlaceApHlt (CpuMpData); } else { CpuSleep (); @@ -1061,9 +1063,13 @@ AllocateResetVector ( ); // // The AP reset stack is only used by SEV-ES guests. Do not allocate it - // if SEV-ES is not enabled. + // if SEV-ES is not enabled. An SEV-SNP guest is also considered + // an SEV-ES guest, but uses a different method of AP startup, elimina= ting + // the need for the allocation. // - if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) { + if (ConfidentialComputingGuestHas (CCAttrAmdSevEs) && + !ConfidentialComputingGuestHas (CCAttrAmdSevSnp)) + { // // Stack location is based on ProcessorNumber, so use the total numb= er // of processors for calculating the total stack area. @@ -1114,7 +1120,7 @@ FreeResetVector ( // perform the restore as this will overwrite memory which has data // needed by SEV-ES. // - if (!CpuMpData->SevEsIsEnabled) { + if (!CpuMpData->UseSevEsAPMethod) { RestoreWakeupBuffer (CpuMpData); } } @@ -1193,7 +1199,7 @@ WakeUpAP ( =20 if (ResetVectorRequired) { // - // For SEV-ES, the initial AP boot address will be defined by + // For SEV-ES and SEV-SNP, the initial AP boot address will be defin= ed by // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address // from the original INIT-SIPI-SIPI. // @@ -1203,8 +1209,14 @@ WakeUpAP ( =20 // // Wakeup all APs + // Must use the INIT-SIPI-SIPI method for initial configuration in + // order to obtain the APIC ID. // - SendInitSipiSipiAllExcludingSelf ((UINT32)ExchangeInfo->BufferStart); + if (CpuMpData->SevSnpIsEnabled && (CpuMpData->InitFlag !=3D ApInitCo= nfig)) { + SevSnpCreateAP (CpuMpData, -1); + } else { + SendInitSipiSipiAllExcludingSelf ((UINT32)ExchangeInfo->BufferStar= t); + } } =20 if (CpuMpData->InitFlag =3D=3D ApInitConfig) { @@ -1295,7 +1307,7 @@ WakeUpAP ( CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; =20 // - // For SEV-ES, the initial AP boot address will be defined by + // For SEV-ES and SEV-SNP, the initial AP boot address will be defin= ed by // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address // from the original INIT-SIPI-SIPI. // @@ -1303,10 +1315,14 @@ WakeUpAP ( SetSevEsJumpTable (ExchangeInfo->BufferStart); } =20 - SendInitSipiSipi ( - CpuInfoInHob[ProcessorNumber].ApicId, - (UINT32)ExchangeInfo->BufferStart - ); + if (CpuMpData->SevSnpIsEnabled && (CpuMpData->InitFlag !=3D ApInitCo= nfig)) { + SevSnpCreateAP (CpuMpData, (INTN)ProcessorNumber); + } else { + SendInitSipiSipi ( + CpuInfoInHob[ProcessorNumber].ApicId, + (UINT32)ExchangeInfo->BufferStart + ); + } } =20 // @@ -1855,10 +1871,15 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *)(CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64)(UINTN)(CpuMpData->CpuData + Max= LogicalProcessorNumber); InitializeSpinLock (&CpuMpData->MpLock); - CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evEs); - CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evSnp); - CpuMpData->SevEsAPBuffer =3D (UINTN)-1; - CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); + CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmd= SevEs); + CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmd= SevSnp); + CpuMpData->SevEsAPBuffer =3D (UINTN)-1; + CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); + CpuMpData->UseSevEsAPMethod =3D CpuMpData->SevEsIsEnabled && !CpuMpData-= >SevSnpIsEnabled; + + if (CpuMpData->SevSnpIsEnabled) { + ASSERT ((PcdGet64 (PcdGhcbHypervisorFeatures) & GHCB_HV_FEATURES_SNP_A= P_CREATE) =3D=3D GHCB_HV_FEATURES_SNP_AP_CREATE); + } =20 // // Make sure no memory usage outside of the allocated buffer. diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c b/UefiCpuPkg/Library= /MpInitLib/X64/AmdSev.c new file mode 100644 index 000000000000..a3cd377ef600 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c @@ -0,0 +1,263 @@ +/** @file + + AMD SEV helper function. + + Copyright (c) 2021, AMD Incorporated. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include +#include +#include + +/** + Create an SEV-SNP AP save area (VMSA) for use in running the vCPU. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] CpuData Pointer to CPU AP Data + @param[in] ApicId APIC ID of the vCPU +**/ +VOID +SevSnpCreateSaveArea ( + IN CPU_MP_DATA *CpuMpData, + IN CPU_AP_DATA *CpuData, + UINT32 ApicId + ) +{ + SEV_ES_SAVE_AREA *SaveArea; + IA32_CR0 ApCr0; + IA32_CR0 ResetCr0; + IA32_CR4 ApCr4; + IA32_CR4 ResetCr4; + UINTN StartIp; + UINT8 SipiVector; + UINT32 RmpAdjustStatus; + UINT64 VmgExitStatus; + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + BOOLEAN InterruptState; + UINT64 ExitInfo1; + UINT64 ExitInfo2; + + // + // Allocate a single page for the SEV-ES Save Area and initialize it. + // + SaveArea =3D AllocateReservedPages (1); + if (!SaveArea) { + return; + } + + ZeroMem (SaveArea, EFI_PAGE_SIZE); + + // + // Propogate the CR0.NW and CR0.CD setting to the AP + // + ResetCr0.UintN =3D 0x00000010; + ApCr0.UintN =3D CpuData->VolatileRegisters.Cr0; + if (ApCr0.Bits.NW) { + ResetCr0.Bits.NW =3D 1; + } + + if (ApCr0.Bits.CD) { + ResetCr0.Bits.CD =3D 1; + } + + // + // Propagate the CR4.MCE setting to the AP + // + ResetCr4.UintN =3D 0; + ApCr4.UintN =3D CpuData->VolatileRegisters.Cr4; + if (ApCr4.Bits.MCE) { + ResetCr4.Bits.MCE =3D 1; + } + + // + // Convert the start IP into a SIPI Vector + // + StartIp =3D CpuMpData->MpCpuExchangeInfo->BufferStart; + SipiVector =3D (UINT8)(StartIp >> 12); + + // + // Set the CS:RIP value based on the start IP + // + SaveArea->Cs.Base =3D SipiVector << 12; + SaveArea->Cs.Selector =3D SipiVector << 8; + SaveArea->Cs.Limit =3D 0xFFFF; + SaveArea->Cs.Attributes.Bits.Present =3D 1; + SaveArea->Cs.Attributes.Bits.Sbit =3D 1; + SaveArea->Cs.Attributes.Bits.Type =3D SEV_ES_RESET_CODE_SEGMENT_TYPE; + SaveArea->Rip =3D StartIp & 0xFFF; + + // + // Set the remaining values as defined in APM for INIT + // + SaveArea->Ds.Limit =3D 0xFFFF; + SaveArea->Ds.Attributes.Bits.Present =3D 1; + SaveArea->Ds.Attributes.Bits.Sbit =3D 1; + SaveArea->Ds.Attributes.Bits.Type =3D SEV_ES_RESET_DATA_SEGMENT_TYPE; + SaveArea->Es =3D SaveArea->Ds; + SaveArea->Fs =3D SaveArea->Ds; + SaveArea->Gs =3D SaveArea->Ds; + SaveArea->Ss =3D SaveArea->Ds; + + SaveArea->Gdtr.Limit =3D 0xFFFF; + SaveArea->Ldtr.Limit =3D 0xFFFF; + SaveArea->Ldtr.Attributes.Bits.Present =3D 1; + SaveArea->Ldtr.Attributes.Bits.Type =3D SEV_ES_RESET_LDT_TYPE; + SaveArea->Idtr.Limit =3D 0xFFFF; + SaveArea->Tr.Limit =3D 0xFFFF; + SaveArea->Ldtr.Attributes.Bits.Present =3D 1; + SaveArea->Ldtr.Attributes.Bits.Type =3D SEV_ES_RESET_TSS_TYPE; + + SaveArea->Efer =3D 0x1000; + SaveArea->Cr4 =3D ResetCr4.UintN; + SaveArea->Cr0 =3D ResetCr0.UintN; + SaveArea->Dr7 =3D 0x0400; + SaveArea->Dr6 =3D 0xFFFF0FF0; + SaveArea->Rflags =3D 0x0002; + SaveArea->GPat =3D 0x0007040600070406ULL; + SaveArea->XCr0 =3D 0x0001; + SaveArea->Mxcsr =3D 0x1F80; + SaveArea->X87Ftw =3D 0x5555; + SaveArea->X87Fcw =3D 0x0040; + + // + // Set the SEV-SNP specific fields for the save area: + // VMPL - always VMPL0 + // SEV_FEATURES - equivalent to the SEV_STATUS MSR right shifted 2 bits + // + SaveArea->Vmpl =3D 0; + SaveArea->SevFeatures =3D AsmReadMsr64 (MSR_SEV_STATUS) >> 2; + + // + // To turn the page into a recognized VMSA page, issue RMPADJUST: + // Target VMPL but numerically higher than current VMPL + // Target PermissionMask is not used + // + RmpAdjustStatus =3D SevSnpRmpAdjust ( + (EFI_PHYSICAL_ADDRESS)(UINTN)SaveArea, + TRUE + ); + ASSERT (RmpAdjustStatus =3D=3D 0); + + ExitInfo1 =3D (UINT64)ApicId << 32; + ExitInfo1 |=3D SVM_VMGEXIT_SNP_AP_CREATE; + ExitInfo2 =3D (UINT64)(UINTN)SaveArea; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb, &InterruptState); + Ghcb->SaveArea.Rax =3D SaveArea->SevFeatures; + VmgSetOffsetValid (Ghcb, GhcbRax); + VmgExitStatus =3D VmgExit ( + Ghcb, + SVM_EXIT_SNP_AP_CREATION, + ExitInfo1, + ExitInfo2 + ); + VmgDone (Ghcb, InterruptState); + + ASSERT (VmgExitStatus =3D=3D 0); + if (VmgExitStatus !=3D 0) { + RmpAdjustStatus =3D SevSnpRmpAdjust ( + (EFI_PHYSICAL_ADDRESS)(UINTN)SaveArea, + FALSE + ); + if (RmpAdjustStatus =3D=3D 0) { + FreePages (SaveArea, 1); + } else { + DEBUG ((DEBUG_INFO, "SEV-SNP: RMPADJUST failed, leaking VMSA page\n"= )); + } + + SaveArea =3D NULL; + } + + if (CpuData->SevEsSaveArea) { + RmpAdjustStatus =3D SevSnpRmpAdjust ( + (EFI_PHYSICAL_ADDRESS)(UINTN)CpuData->SevEsSaveAre= a, + FALSE + ); + if (RmpAdjustStatus =3D=3D 0) { + FreePages (CpuData->SevEsSaveArea, 1); + } else { + DEBUG ((DEBUG_INFO, "SEV-SNP: RMPADJUST failed, leaking VMSA page\n"= )); + } + } + + CpuData->SevEsSaveArea =3D SaveArea; +} + +/** + Create SEV-SNP APs. + + @param[in] CpuMpData Pointer to CPU MP Data + @param[in] ProcessorNumber The handle number of specified processor + (-1 for all APs) +**/ +VOID +SevSnpCreateAP ( + IN CPU_MP_DATA *CpuMpData, + IN INTN ProcessorNumber + ) +{ + CPU_INFO_IN_HOB *CpuInfoInHob; + CPU_AP_DATA *CpuData; + UINTN Index; + UINT32 ApicId; + + ASSERT (CpuMpData->MpCpuExchangeInfo->BufferStart < 0x100000); + + CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; + + if (ProcessorNumber < 0) { + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + if (Index !=3D CpuMpData->BspNumber) { + CpuData =3D &CpuMpData->CpuData[Index]; + ApicId =3D CpuInfoInHob[Index].ApicId, + SevSnpCreateSaveArea (CpuMpData, CpuData, ApicId); + } + } + } else { + Index =3D (UINTN)ProcessorNumber; + CpuData =3D &CpuMpData->CpuData[Index]; + ApicId =3D CpuInfoInHob[ProcessorNumber].ApicId, + SevSnpCreateSaveArea (CpuMpData, CpuData, ApicId); + } +} + +/** + Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page. + + @param[in] PageAddress + @param[in] VmsaPage + + @return RMPADJUST return value +**/ +UINT32 +SevSnpRmpAdjust ( + IN EFI_PHYSICAL_ADDRESS PageAddress, + IN BOOLEAN VmsaPage + ) +{ + UINT64 Rdx; + + // + // The RMPADJUST instruction is used to set or clear the VMSA bit for a + // page. The VMSA change is only made when running at VMPL0 and is ignor= ed + // otherwise. If too low a target VMPL is specified, the instruction can + // succeed without changing the VMSA bit when not running at VMPL0. Usin= g a + // target VMPL level of 1, RMPADJUST will return a FAIL_PERMISSION error= if + // not running at VMPL0, thus ensuring that the VMSA bit is set appropri= ately + // when no error is returned. + // + Rdx =3D 1; + if (VmsaPage) { + Rdx |=3D RMPADJUST_VMSA_PAGE_BIT; + } + + return AsmRmpAdjust ((UINT64)PageAddress, 0, Rdx); +} --=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 (#84571): https://edk2.groups.io/g/devel/message/84571 Mute This Topic: https://groups.io/mt/87605572/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-