From nobody Tue May 14 12:14:04 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+81890+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414426264363.43339646839172; Wed, 13 Oct 2021 09:57:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vScTYY1788612xCGhu6O88CF; Wed, 13 Oct 2021 09:57:42 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.65]) by mx.groups.io with SMTP id smtpd.web10.93.1634144261531554680 for ; Wed, 13 Oct 2021 09:57:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cXf7U1HHPsslPX/fzmQg8Iw7BalT2rZWOUH2ZifRfSQPkAk81mR1kdKcte47A2B/poY0eQ64ROtAaZCKDDR0YulkPdufih4Lb3h6ASP1cLoYEDZPL3WghUdr3xOf38u2HmqyDuKWPRxxGfptNZ68rRW/xWKugOIlw3SaqMEB5Opk1i0ANuzah1IrNsLt2JS6iAxDrQe1FPxlElsV9jj2uzesNzXalQ7HfFq4xew+ur1p7kzqlqhG3BLWajyzwz+Fpl+AkXtN87V6M4tsaq80hUoUZxkUBCRwB3RyzKb7jKSF0Ou9BZZlGOqHCv6cvnPqiGbZHAQIvN/iIJkwodqNPQ== 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=KdziwIaksyReiyMuw6UfqeLz32bN5hIpKOxnP8MDU7Y=; b=NoM45c1Oq3f8kzlkt24cf+UjrKQURUSvro0SXs9fGb9X47uDPKj28DM3WyKB7RUloD9vdu4+8aCXb9MHziz3u/+ledbgqye6zlIkOiZudpteMeFDcaNF1BS9owMkw4oN+6RT/US3IqJANaxS8SrPTozp9iYeDHuU/IQbG3DV+OEO2ce68ZOplOzD7i6k7x2pskRCCZS6oLDOqH2ss4UVhtqEfstkbOOeCldEbxUfnvpwZ2N3RnW5i7P9SBRbvo+1fy6XP+qbBcRyPczoEtjMLPJrEARROy2c3Jws9oVN7tXWRcCGAZ1BZgUih4SMJF+LSR/8X47qQQWQQpy0vHg9WA== 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 MW4PR04CA0032.namprd04.prod.outlook.com (2603:10b6:303:6a::7) by BY5PR12MB4273.namprd12.prod.outlook.com (2603:10b6:a03:212::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Wed, 13 Oct 2021 16:57:39 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::1f) by MW4PR04CA0032.outlook.office365.com (2603:10b6:303:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81890+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:39 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:36 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 01/32] OvmfPkg/SecMain: move SEV specific routines in AmdSev.c Date: Wed, 13 Oct 2021 11:56:42 -0500 Message-ID: <20211013165713.727815-2-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 82acbbc0-9cc6-4e34-491f-08d98e6a9083 X-MS-TrafficTypeDiagnostic: BY5PR12MB4273: 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: L8MvFZ+1gRHA7PdoScXZCBjxFHvQYjI6s8s/fUW0b8nmxCYMtJNT9A0fH6LyJKSEb9uelBkib5gTx/WrzO7UCX1RWvhgcXnXxzE/YnWcnPSL5OnjIsx8Elh8mCP18OkTfSPLJPnpcB4ZqRkQK0CGZjvBxWejK1eruegfmI4y0VpxtP5eD4ZDFoS3hZBDVno9yiMLZxDMCTgs12BTxnJyVWZRYdF5zaTVpHVYvxQzVLU4Z6j+YAKZbf4iF/Ji+uFTwT5/F7d57vMBWdrdRvEm/JCAHCyrZ2NsfidZsBCiZZC35XWsLNvan2SoThvnjYEHh/Vbspc/UGnbtrZ/wJNbSUXBQCsyamEIbjLZBymOAb9W3Gy2U2Rl7F5sLOOF/h4RoiSKpTW5i9RXueUvHw2AyEiAsjWai8BB2tn+ggDCQqgsItcM8ZyIiXWnJuPvhQvyqOW8m07jR8Jm7O/MPanm7e1sBq7iD44xwDx6pjZrM9f+a4GW/bY/TSVcPkvmYJpwD8e9GdC/OawcQRkcf1B1Kak4fsbdZdu1ArBBOwkEQ/c8vR1378U/vN/IppjJJiydardgVs/rgJqgHXavdCS5iZJYNfvsiaBK2qZeMmVLC9eCp7EHuo/QJWsoi96V7hulbr0E1zvlnQy9NysjH3ZbpMgx7JfGidQclUO3t+eZ65oGJw6kYmUYsoCND39GnCyDC6NaMicum7k/D3tRIf1Io+rbG2AAkBVlIi1qnwhqMl+7au3ogRuV/mIF7OW3taZspDLR3dKb6xyKpmfdvZSamu0xUf/f1P1iEh7p6Ll1P8TUcnpsqwuRj31DgLuVJdAF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:39.0317 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82acbbc0-9cc6-4e34-491f-08d98e6a9083 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4273 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: YKNNzXZ3js4bbRYD5dY344Z7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144262; bh=s0UQZ5kgTG6dOCAZJYDyJ8tDV0mH3R49lS2bfKsVvwU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=AsJZWGAk5Gy8kW225M/XGAcLjMkAeuy0YvQcr2kmRaegTbPfaysdre16vAeusvtctrm 5wJ6S2/u6qiPZstUwM2o0ObsskFOcOojlYoEOwQrac1SwITuequm8QWTALSeOS9pb2hbv dX8O7VFbQxhocgZjyL3+QPgs0QSYfgO3duY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144264414100003 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: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/Sec/SecMain.inf | 1 + OvmfPkg/Sec/AmdSev.h | 72 ++++++++++++++++++ OvmfPkg/Sec/AmdSev.c | 161 ++++++++++++++++++++++++++++++++++++++++ OvmfPkg/Sec/SecMain.c | 153 +------------------------------------- 4 files changed, 236 insertions(+), 151 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..9523a8ea6c8f 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -23,6 +23,7 @@ [Defines] =20 [Sources] SecMain.c + AmdSev.c =20 [Sources.IA32] Ia32/SecEntry.nasm diff --git a/OvmfPkg/Sec/AmdSev.h b/OvmfPkg/Sec/AmdSev.h new file mode 100644 index 000000000000..adad96d23189 --- /dev/null +++ b/OvmfPkg/Sec/AmdSev.h @@ -0,0 +1,72 @@ +/** @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..3b4adaae32c7 --- /dev/null +++ b/OvmfPkg/Sec/AmdSev.c @@ -0,0 +1,161 @@ +/** @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 (PcdOvmfConfidentialComputingWorkAreaHeade= r) =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 (PcdSevEsWorkAr= eaBase); + + return (SevEsWorkArea->SevEsEnabled !=3D 0); +} diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 707b0d4bbff4..406e3a25d0cd 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 { @@ -717,154 +716,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 (PcdOvmfConfidentialComputingWorkAreaHeade= r) =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 (PcdSevEsWorkAr= eaBase); - - 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 (#81890): https://edk2.groups.io/g/devel/message/81890 Mute This Topic: https://groups.io/mt/86292883/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 Tue May 14 12:14:04 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+81892+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144265319675.5724066577857; Wed, 13 Oct 2021 09:57:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lDnRYY1788612xaTg1N7KZud; Wed, 13 Oct 2021 09:57:44 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.71]) by mx.groups.io with SMTP id smtpd.web12.110.1634144263734777729 for ; Wed, 13 Oct 2021 09:57:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uaj/3ToB0dtrrio2pLEZMn3liQSpF4ToWxNABDvK/M7O8QyERnQyjYyUb72+gkAG+9e3YErWKODEiqZ7A7ZybjvQ3FjUR3ldBV/Gl9ln3DctyMPl2xVKxVeYHIojrHIMVLtc5uFcZQuRYWzi9+kKPRTpBbDFe4KFicr6ZV8IBCrnxrIyIO1D8taWBLYQmfQdkFYCKwRVfBlMIhVtJZipPczYVwPD4TgdLhKox3G78ReRHiaYTZGNkGJ/X4s5G23pcKNguSGgI6mApurfuN7qsJcV11GbryBZbGWvhXo71M+ZQchlnuMVJ+otKpmENovW6dexV+PqkuysiH45MRj1QA== 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=XFw81/VdnZTV6s8iSc/cTLsVp8a2N98OPbm3nTlTU98=; b=SvlFwPmq8VLimZPOhET3X7wIlY/KN614WoELuE5eallOiJr5JVkOHbGfX2j2SWrd7KN/XD+f6pJ61+OuW12a3wnDYYip7/C98Mtal+CiE/o9osPy3EUHvX4/4L0+jtHmnuiBGbXDB3w0jDzrCt46NReUlLlH2uG2bx8GDsmWQpADKzNRQJUU/Hm9zt5A+Y5FuBp7l1nXM7Y0jDSsAGpiBGT/M4d6M0H4/r9It8/ui4lC3d+8J8U/HbKGt6M5FnbERVEyzT+bXMigExkPGNuW+Nsl/zUUIIjh0DjB3OxYGK5jSbVlY4KN6O0HKTi/4EtnXsjNtQPPAMHrt1fVxv6xbg== 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 MW4PR04CA0044.namprd04.prod.outlook.com (2603:10b6:303:6a::19) by CH0PR12MB5075.namprd12.prod.outlook.com (2603:10b6:610:e2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 16:57:40 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::97) by MW4PR04CA0044.outlook.office365.com (2603:10b6:303:6a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.26 via Frontend Transport; Wed, 13 Oct 2021 16:57:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81892+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:40 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:37 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Eric Dong , Ray Ni , Rahul Kumar , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 02/32] UefiCpuPkg/MpInitLib: move SEV specific routines in AmdSev.c Date: Wed, 13 Oct 2021 11:56:43 -0500 Message-ID: <20211013165713.727815-3-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 817c1f49-21f1-43b7-a6a5-08d98e6a9119 X-MS-TrafficTypeDiagnostic: CH0PR12MB5075: 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: ORP2dFus2YdER5D7w5fTD6HEHQfbElbjOjvfU84RpO6sR+y5cKZC5yTSuI/8A4g/LrUij8F6/9FqZy9D/h73rTPBWMtOKUxPoBPmdoU+4gaOJ8pZLeO9S3aTLGN+ihnyXgAIvmQbbsQeJOGqz+Yy/m69vOe/9Ha/osa9g1r8n62kc8ceQbw4kKQBQhUjvhk16fWOwamz++CBDjhdN/5kROmJi1bNNghfpMxbPOP2orX7af6ifO9lZttJjNnrjAXDtgVoZAUED1avNFOz1ONwpA39yBBDEvxpbAkrNUdezhGNytupQwUWP6A6tk+qmDdyjQRvAkerDI5fRltyHptPGxAEb814vICcAQfwHlZZV4+FCtJosV36rdNBSxFCrPDIussTJZBorApCQTnqrVMlemCGwMAfT/sY32JCnpG6GP5LPJwassmBGMhD270VGvMAZtoPeW4sprUs7/ZtdyXIH6ET+lpff+vLN6+nK4pZWWuMFGNuhc0SFrMKzbjW/r4a4LefVjqklMfPioZKIw0zmKkwDWPvG61eNROrZlqUMYVDpMRra36EOwHstn9mCmU7r9r8Fji7m/Z0RtsA6ULW/OrEi/SRoDj7UmaaTQkLalJdopoTssuY0GPi9iPWYGXoCQ1W6zs+wrjAORA51QKSSSJk11obkong8NM2REL+H610JbW48QERXGLCulAfOrytxe7kYEl+5ZH2CUQdo08ExnEUEuqa2USf6Oz/VaDWirdwauL9tnqSyinUqoBI2R75L32OMhDWyh5J0dnZuaKAwnoj1i7GEKYB+Bl+Ltd05qbU3frUktxtqb3M9WNBHt2f X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:40.0181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 817c1f49-21f1-43b7-a6a5-08d98e6a9119 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5075 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: S78p2PQYmFU0Pcj7t1KxFmWPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144264; bh=qw5t1Op4wbGk1Z2XdtWXNmc72URbYG1r44GhqACpfmI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=kD0gcGaMHs8gjsxSy76j5OwaK0Aez+KWY1SnpCEDNtWiG56ax5yNnHXlmVqTc0pbuj1 gQlDP6Yl/6HzCDSQk8+7TEMFDRP9tR3oqVaU0kaPTVnzMjDxuWaQqYlqL+TpHdxr6kAb5 coJW6Hr6zwU6/3lj1cdow7f4ku81zRqutGo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144266751100013 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 Suggested-by: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 33 +++ UefiCpuPkg/Library/MpInitLib/AmdSev.c | 239 ++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 218 +--------------- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 119 +++++++++ UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 100 ++------ 7 files changed, 413 insertions(+), 298 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 e88a5355c983..3d4446df8ce6 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') @@ -741,5 +744,35 @@ 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 =20 diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c new file mode 100644 index 000000000000..7dbf117c2b71 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -0,0 +1,239 @@ +/** @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->A= ddressMap.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 (PcdSevEsWorkArea= Base); + 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->NumA= psExecuting); + } + + 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 b9a06747edbf..890945bc5994 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -596,117 +596,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->A= ddressMap.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 @@ -884,47 +773,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 ApInitConf= ig); - - 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->MpCpuExchangeIn= fo->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 (); } @@ -1252,71 +1101,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 (PcdSevEsWorkArea= Base); - 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 (#81892): https://edk2.groups.io/g/devel/message/81892 Mute This Topic: https://groups.io/mt/86292885/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 Tue May 14 12:14:04 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+81891+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414426436535.76007804418555; Wed, 13 Oct 2021 09:57:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id nxZxYY1788612xSk4qUSi4p6; Wed, 13 Oct 2021 09:57:44 -0700 X-Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.46]) by mx.groups.io with SMTP id smtpd.web12.109.1634144263488404743 for ; Wed, 13 Oct 2021 09:57:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gSMMh1t7wt3TFJ8HcN+L6EUuMTz/DVyyn0ohSw7ajcetDmJPu9EqXTt76YBuo/KYIvumY4m8b5sDIePG6RTcugEBsNpupGBU00T9orDTQ8nI1bxQlT6+NBsTuvLWQQKXcjNinieo2Oeqov88Ebsoyxvc/7JlY3FUFMEWOVGrPTQcUh5DTw26zzN+PmRIgssA/0ALhJHWkoG7Y8N7ZF5bgelgi2KJ1Nh6Cy3hZn0zubTdZVEj25PeeX+2+d+9thXSV/gKVWMZSN+z9aamSEumHetLBK3Y84ykaNW8SfHY33KBwtLvxv/D7bcnqWG7Rl8J3pS9w0vUbGCnwFjFPnqAAQ== 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=AINumP86uSNPlYoT8Fq5kGXANP8TRYHU1Ca47I3OecI=; b=MX9pTgmUdOGyY7UBEAcPQ+Md3UwNsRgNmnGvPNJhC0JIpyDKBlyvAyEKTKPU5tz+KnvtRahLIoM+/pRDYlGjXzDumPq3KLaC2ve1/VITB9RXVGv9NGlynUnlGwQGUA7auUJXtoVeqm+6Vs0fOT9XulPuDAuSwDGoCEide6QVReF+F0VipMbQlU+NuVGHxWN51C7epyD5C1wvAdN15ZsSLpmIh4ylW19U6IYrmZ+mfRQ7jKDQJ/t0ldhm7ftbSz7S/0EBAmq6rQP5nxrBrhbFLOJZI8X6w/Q4cxsq2da8YzApwC/O/cq9q5GNwgNXwPYyUMDq4NdpIusTtDuQULz5hw== 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 MW4PR04CA0056.namprd04.prod.outlook.com (2603:10b6:303:6a::31) by CY4PR1201MB0119.namprd12.prod.outlook.com (2603:10b6:910:1e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Wed, 13 Oct 2021 16:57:41 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::df) by MW4PR04CA0056.outlook.office365.com (2603:10b6:303:6a::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81891+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:40 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:38 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 03/32] OvmfPkg/ResetVector: move clearing GHCB in SecMain Date: Wed, 13 Oct 2021 11:56:44 -0500 Message-ID: <20211013165713.727815-4-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 56730f95-8d00-4cc6-e618-08d98e6a91ab X-MS-TrafficTypeDiagnostic: CY4PR1201MB0119: 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: p2zxs0Jwvin9tsIZcj/ilLjK00DwxPiGHSBypmZHv1wN5CtyhUgGKgSqucvJ5uijDhLoWNUWqBmzqf7kF0v+3B3iVCmCF8XXeryWMEeL2Ct0kab5GlcPaxjLzLQu9OpRobQwtjDQDdd4nSqdefZAj7xE9cebze7Zjr0SK0dM+2ijP89RYtUFApkHXhUxpR7Jf3CBzsK5FtwZCazVfOTwirfAyMENlJ8c8+1IrjPj2MIgsGmC75wnWRX2ACZ1rUPpb7BUgMw4Vo/a3v7MV7NAAbeOuW7GPAucju44fldZ7/LcR3703PjObZol9lhSMGCbDJ0XFUO5vlOiam0kuEKMrBMgj+ojs+dGlonZUoy6mDZoyQEAlhap4LvsvXzDLdTGEwwrC606k56giu31sZvvtC6mapZfKuWirEGV3a65CpCPI98g7scy3ZxakaF3NHLlVh7lzpuOE8V/jzePeAXZI2hw8HjMAmn9vv1UW1Xc1d5EEHz03BZQLz/zbqmftLpmlIprO3BVQSt2vqkROgxDmcfn44Kj2mGyhb2BiCFwAhDAuLqlcuYnVk1OyO54izA01hPWqrNBx/Qz2Wf3aznsfV8nXDBDcL/P9VdqjQFaiWj0IkJhlTucNP4qODK3c7OND4BIj+C0xRO2tRoi5pnPvnbs/M+6c2iJu4KmQWxhRD9bQm+3uk5+jZnsEUkZA1y1qYamPZHMgxIkLO3NvUtgLZPSHbNJUhNvKSuVvP5V6zBVFLSUAgWADpT58a9IIx4HegQWgqKreerRNiAPTzgYB4dxgQJEJXzW8C3wWsXB2EEFm2w++k7LWWeruL2K1cTb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:40.9776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 56730f95-8d00-4cc6-e618-08d98e6a91ab X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0119 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: Am0WX4N2m8OBWwig0xHXE8OGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144264; bh=j02vc0GnxFAtn970FE4qZ7EhCq+oKSe9AExEo9QJa1I=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=bF6rRxouzDlQ/ZA12xeI6ig/fnPUEpzMUWDGsGqdcXc13z4j/8x3Fdoy3ImO4vs2iV2 at/vxyhjiIFL4uQir0fmf+BTN6ZbQb2n6JHEFgDyIvJWBSa0QsaOtw4JBcIs5CkXWxFuH geWfFjdUkzONEmBPZ7Eh7WF4Y81R//LhpXI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144266472100009 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 3b4adaae32c7..7f74e8bfe88e 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -95,7 +95,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 (#81891): https://edk2.groups.io/g/devel/message/81891 Mute This Topic: https://groups.io/mt/86292884/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 Tue May 14 12:14:04 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+81893+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144266984193.0558334123741; Wed, 13 Oct 2021 09:57:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2bzbYY1788612x5aAV7UrlQs; Wed, 13 Oct 2021 09:57:46 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.89]) by mx.groups.io with SMTP id smtpd.web10.94.1634144265718206493 for ; Wed, 13 Oct 2021 09:57:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ekmvp+eT34NsZKjKDjp++Bft3zF69/RoehhQe+4KG9JopbXxi4V7HChJ8KgFFdtqiaOLUgfnjGdYnFU5R96MLKujwkuCvxCOJ8uQ6/EUABdgZbI5je+NLl+FkNzjB1ASKRUfppFDR+9aUTrJh7jZMQko2g24jAmviDSR6nqlFqer5fHyC77ZeUvHoHhaRAmgQ5uaYApdMAeQUd2Fv2fDS4mlhKqu6Hw/P2Hclc4SSdyAfEKm6PfTkRVXRjmWgU4Ci0+a3LLypKi8e77Mjujj2yMSj8RHlYVikUQ497G+gvPESlQAvOJFS/prIWKWsmx5ziHMROfBbbPH11S2dp6zbA== 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=28wM8DRAdgO30JnP1gJgf86JvPmnXfkqgnWPF8rmMI4=; b=cZJ1t2DbrYicGeA5cqfjM8JYedLlOnih6hZGORP4slDDOXhflAaUQR4xPnkPrPVyeFt0e3tTAvXwT3ODnSeQ7l+POTUWyLZ1/CAGW31i0YJ8RrqMZ3YiQG0HL+Lv6VQNNUqYzg/udvXeNgrwdpkBpUdQAL5KteyOIlvSUk78CrrvpDbqzXvCyp08Ud4c4HGxoOEM+mDJZCiWZJ7EV+lWkMPt0OifQZcdKqJhWmYORsw+7u708VxLnclOrqpXCcB2L70sqSabvtr6igrSpA2e8N/Gb3h2uD7K8oooPoX2Oxlo9ecmQOhovaP/sqsMX2RYTVFT9puNK7PaqrbZKRySXg== 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 MW4PR04CA0041.namprd04.prod.outlook.com (2603:10b6:303:6a::16) by MN2PR12MB2943.namprd12.prod.outlook.com (2603:10b6:208:ad::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Wed, 13 Oct 2021 16:57:42 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::c9) by MW4PR04CA0041.outlook.office365.com (2603:10b6:303:6a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81893+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:41 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:39 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 04/32] OvmfPkg/ResetVector: introduce SEV metadata descriptor for VMM use Date: Wed, 13 Oct 2021 11:56:45 -0500 Message-ID: <20211013165713.727815-5-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: afd94a52-9011-4f50-78bb-08d98e6a9233 X-MS-TrafficTypeDiagnostic: MN2PR12MB2943: 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: rnSFmTi1N402klAQdXOEM/XwTJGfLVX8VVXoK9YUcRBCDqkkzijpGQiTIut6xxkPpW9Jbqc7PPouLXXE5CDXhj4wxbcumpotRyAhCwyq52pBaKycyHDpJfOmQt+wxas44Flz1+TKo8+0IDQK94SSa/CHa9UnTcbSZ20Yp7PXNNsd3hoym0I5nKQ12ZqBCtwYcPmXfFE952P9/MIIB4E9fZB6nrkf9I64+ytYPe4ZU019EZPcxXtylib7xwkVW9ENTjdz5JasoUTwCjCWW8EiknYlE+MYV6w725bVSQE3Oeo8sQkPlxMMDRA9lT6Mpe7eLpIg4c3e2mEliEkXR6an49a766uIX/xDA6cpIB1hHNQ3CgZMcJx1Y0ahegoWpLxSDpX1EJz6NZg046kXQejuAJf+WSfkf0tQ8vrdEzaRU/4LNgZ+4Svp9a22aVQhnGy5/A9byj+x6AS17kwlFgCbjKaLVhWr8dXT+PDRrGem0KN4fGDBI0oTN+6jjYtbffbBRDAkyj1O/kuubkNfgVb1eCkv5OLjsuL/t0LwmiTC+71n2Q0bfe3Z5fxTWY9OZyv/vdddMRAGNfEmf/k1rd0oFh/RP5RATFp8geZPwGA/S8jFBDpNb3QDFQJ5gcUKyrEdQcgq1uUBJCmW/uJIjF4bxtwReVKazET4kvqjRJyyBUAfuvVyEZTcLdLOQRgQs5+zFh3iak0qHf5EuAZR/UI4qSo3GNV4+ACXebd1Dekw5he/miVKEJiqPyMFQ3zxP3jJ8CFd95d7GYhfaI9Bro8HXdEi4S8CmMxSJTmLdhB1z80WXUqV3fTSgUy0H34aVgjj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:41.8641 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: afd94a52-9011-4f50-78bb-08d98e6a9233 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2943 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: HtZlQXhRLjFMBIrsG0ldxVGJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144266; bh=A/VGg/og+GQmdHcRwdRsMODnyQl/QlOqzk0jJKmm8Yo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aOiAzAtUudTwORs52i/91/l/tYAq4dPBUYXXesT78y3uiRuzPV282p/LdoCV7lSyGV5 x8Gflh7FsbvX8FJBK5O4Hdlxb1OgwKPAyWOvOVif62SOYUGPh4ikPTqih2Hlhu6HDB1r0 fq4R4CPE0Fv5ts8YloUeZ9dBmy2IDMc/5Rk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144268996100019 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 17 ++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 34 ++++++++++++++++++++ 3 files changed, 52 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 7ec3c6e980c3..2c1f764e9d7d 100644 --- a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -47,6 +47,23 @@ TIMES (15 - ((guidedStructureEnd - guidedStructureStart = + 15) % 16)) DB 0 ; guidedStructureStart: =20 +%ifdef ARCH_X64 +; +; 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 + ; SEV Hash Table Block ; ; This describes the guest ram area where the hypervisor should diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index d1d800c56745..b37bc9c7da64 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -80,6 +80,7 @@ %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.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..c42ad779be49 --- /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: + +_Descriptor: + DB 'A','S','E','V' ; Signature + DD OvmfSevGuidedStructureEnd - _Descriptor ; Length + DD OVMF_SEV_METADATA_VERSION ; Version + DD (OvmfSevGuidedStructureEnd - _Descriptor - 16) / 12 ; Number of secti= ons + +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 (#81893): https://edk2.groups.io/g/devel/message/81893 Mute This Topic: https://groups.io/mt/86292887/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 Tue May 14 12:14:04 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+81894+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414426795262.26054126522524; Wed, 13 Oct 2021 09:57:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7kwxYY1788612xgvll2f7IRU; Wed, 13 Oct 2021 09:57:47 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.43]) by mx.groups.io with SMTP id smtpd.web12.111.1634144266114196516 for ; Wed, 13 Oct 2021 09:57:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ImfLQywkRKs7dO6TaxWGgPzq4o9/ikRwC+ccQJuzGqYWJtPjnXG+J5CBUj1ATQGl3Pnd8fPKhQmFavYYTASBPZs3u+tCT43Rq7/Srsogwnuireiha/G4XPin02YUzLdkZbAz6pjEyooLe10PIkgmGsQjKHAVyrmXWHQtVsVizQC0TJmxbhid6KDARinLcwLt6hDhvpCnVWE2HZArJpPeQODOHjWLZFwONEWQbnqYiK9dL2D6gYWMjOaPko3XvVl7pMJ51YXH5iZQOZlEfziHRZgNt65/ImM4KO8ZuaFk7NJfsw10M8LcAXvezAwadX39goYTezuPnmVaBMpl6awC1w== 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=IB2+jqiM4vJkxbboLXzt6A0xwkGPJAEzceSI+Mb1eDY=; b=YGnHc3lUAeumwHMsmslNaFiqUwc12OUfoXnI0YJSKSPcm0bMnvEHnsYQdZAJx+qPqWr80jqrr5tDlwMOGtozZEV3BF5jIC1nRbzej6XbhozDldqs918uZcGoCRDXeM+FKIUFgRQx0Ljjk5V754edOAoIR9WexsziT5NwvK6koowyZL6hLGYcGm4N1BZugU7ncw4lkNSGCRqeLaBHAUL8nIUEnr1745VknR87/7kEpqQfcSFp9gjo+oK46dNEd4YwXtqxzPGiGup2bLhL1/a+shvQznVYjDP5dJTNS5r6qHZxE1xqF4pV+nxihIkXYIkWmVjXW2Q0xwa8wqT6C3V+zA== 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 MW4PR04CA0040.namprd04.prod.outlook.com (2603:10b6:303:6a::15) by BL1PR12MB5205.namprd12.prod.outlook.com (2603:10b6:208:308::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Wed, 13 Oct 2021 16:57:43 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::f5) by MW4PR04CA0040.outlook.office365.com (2603:10b6:303:6a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Wed, 13 Oct 2021 16:57:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81894+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:42 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:40 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 05/32] OvmfPkg: reserve SNP secrets page Date: Wed, 13 Oct 2021 11:56:46 -0500 Message-ID: <20211013165713.727815-6-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f77c7707-47e2-4871-4e98-08d98e6a92da X-MS-TrafficTypeDiagnostic: BL1PR12MB5205: 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: r66fIXvouN+pIEQWEH50v8afeCGbq6w5Vvyz5EQ7pSSmfonacy30lOSECafWqbuEmyDjx4kv0Q4Kx6jqKJgI1eJhwmZiyfzItnUaAQHIRVDE05DHbLrZ9lSKokfVJG4YXWNhL1flNJOO5aygmHye4zaME3b+9vJEW9kRZnAQVIt9W/9qJ+GRewRtYIw2xRbTNSr5sBxUaVM0B09yDO1rpCW9E9K7psCrtIvUBOl12PxKqIBOLtcdz8T0xz6IiyFjLKR/Zo4+vJPHeXH9tHPM33PbavOy92lXP4a7Zi6kjtycdpYs7x8J9TmAcuErrvQCri3Ey+xYSvQTs5npU/WB+JrkWwEg2sPDKFmQM3wDSV3Khgq8UokN8jrh+nz1svN+FBLrUuKGoFQ3FcCD/lr0q/FPYWVnUgFCHlBAEw4XDm0ZoYH8fMDLqnMgf8QpmS7s/drrbi12mgGOrwbIMdC4NOZUjjD+iCV0DXjhNu5OmfxXgK9i0kVUnhkrd6onQIwHWgtwyKpblVlgCPolVM2088bvl2Lms/4DdBj//yBK8RF1M2nhyNM7WEY3yO1kKzGD1qW1VNSaOByrZomF29CPdawBBC7BGxuUvYUeb1W7KXbqinM0LiPm5PQKl0iZVHjsjOHrBvc109QOs5Tt48zicQTk/gwB0NfdONdM7Od6pBOalRqH4qti96KB+dxs77kZ8PRVCQuYS4rgv/xDuOofADOvjlB/MKUlSFFoaay0Ufd/frfU9VoW8pCsT7fMSOjNBrJUoc9Fwug4f4QCjukvFO457UrWDa4/oMHXUSHFWHj3Pkxn3n5GIIGLJxEjfS/Z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:42.9594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f77c7707-47e2-4871-4e98-08d98e6a92da X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5205 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: sXQaSyLQWvxHV9QmuDHfpVOXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144267; bh=YWxSmfH3458OJOSZzLZePeK90Z1n2cqRkCQXztc5jq4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=i9YSaz20pSWyPGbDJlArHDY2QUHKjvgvDdwzExgc8aqqSsL8AjO5kpk0lxNKgAVmka4 RFLl7sIQ/4QgWdhGn8xvLNKWOV/XFppe2uyO9tUCi3L90Tz/65PmDbFbv/DD02P5gAv9m kN3Cwo1QvwZ6B542uEKO6N6wZ0d0IbuiDCY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144269090100024 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/OvmfPkg.dec | 6 ++++++ OvmfPkg/OvmfPkgX64.fdf | 3 +++ OvmfPkg/ResetVector/ResetVector.inf | 2 ++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++ OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 9 +++++++++ 5 files changed, 22 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 1be8d5dccbc7..3e4e80a1e5a0 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -340,6 +340,12 @@ [PcdsFixedAtBuild] # header definition. gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader|4|= UINT32|0x51 =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|0x52 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize|0|UINT32|0x53 =20 [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 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 a2520dde5508..09454d0797e6 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -50,3 +50,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 b37bc9c7da64..fa785fc44b5b 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -77,6 +77,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)) %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index c42ad779be49..eba861129333 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 @@ _Descriptor: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _Descriptor - 16) / 12 ; Number of secti= ons =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 (#81894): https://edk2.groups.io/g/devel/message/81894 Mute This Topic: https://groups.io/mt/86292888/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 Tue May 14 12:14:04 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+81895+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144268440590.5171254236694; Wed, 13 Oct 2021 09:57:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZRM3YY1788612x86XMUjGUCf; Wed, 13 Oct 2021 09:57:48 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.72]) by mx.groups.io with SMTP id smtpd.web08.112.1634144266476761511 for ; Wed, 13 Oct 2021 09:57:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Og6XYk1jAMp8yxpDCAH71K4YRFjomiN7JPJZWq4lRTiEyg60AIS8ppHtDxRTL4F1vG0f9v0ScpWzg07O8ULfG67wX1OHPwNv/NC6Kpabs9pFWx8raOaApziwPGYLPlXdTHzhLPfphuLqXp84RGC4B/ygxiowczkX/lgPScQoJiwp99SgHJ0FMfck9OiAkt4xRM9+KdiSYqktuRn/uXHbpRBZV8KziHzsYhaxVVm1ZbbFiPcYnKTNyiOISjXmPJqDkofql4IaaERwXaUG5qCBl66/00IdMM32lGgf5WC6878Gb7uBkbnM0WwcTM4mYZ8A8kpFvsfLZ44sj2UWYOIfLg== 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=fxAsnVK/0MxlYXQBSHvN12lspG0Bn+mZWpUmrJOWPRM=; b=a73vC5+ofPvlzzeVuAwMfsnnB/owwWiNB2W7DqvE2znJLkZ/2bf33ST8zEhAGxd9vdnziXmJvaLgR7O42WWupqi+kQEfP/AaqsgtY0h7a5OldhAb+GPldHcP0CaKMJJN9jST75lA228bj6gRV/Ag+yy+i8Cb1hmvQiGZXWrL7mcgI72P638z6XxmIIpXTb7uqvRZC/H/RG+BiuS4FW6rzFy+fyUuQNbNxW3ool0B+IQ2flITvRy76f/QCK4PQRfkUVUffqE4tcz0ngYwCrICATLqZTzda5v3beS/4Wnsawy4WaiF6QT/feE4XVbVY0DI4zCxnj87v6kg7HPH5eWfDw== 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 MW4PR04CA0036.namprd04.prod.outlook.com (2603:10b6:303:6a::11) by CY4PR1201MB0007.namprd12.prod.outlook.com (2603:10b6:903:d4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Wed, 13 Oct 2021 16:57:44 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::59) by MW4PR04CA0036.outlook.office365.com (2603:10b6:303:6a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81895+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:43 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:40 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 06/32] OvmfPkg: reserve CPUID page Date: Wed, 13 Oct 2021 11:56:47 -0500 Message-ID: <20211013165713.727815-7-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f13dd8bd-b36d-44df-96ff-08d98e6a9368 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0007: 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: fQSNtuKZ+fXrm0lka8uKhxvS/IcbwtopqHf0UHgz9C2JDcqqx/gD2c6yyKZ3ALS+WH76jYOqC0XExXwXgrd4gLmFAagUen3Lvz9hPLneIKwsQloV+GJxvkG+pCkJiCNNzlNIloQnf2p3XOhZyDlAT4xdMGrpFs0TkBSdtFZQyBnLS8VEolah8pvHCO4dNfr31BobmXNAHK6cy2RcKS8zPIUXtJ0yaeXVcipPr6GpdlCD7+NAWJ8xd2GqfBYtd3svDrWzhnPbg6JP1IQ7aTLNGt33xTQJWnkRdqcbdsuA5JGVfm9L8djlLxm6sj3B5ZXtEioOc12zB1t+o5IfEVTm8rCsQsR8uTQ3k3wubacHArle3Jmx7eXTQH6Yd/TyuHU6nrU+69s9TVNO32xrcbbTUgcXKZO4k/ajGWEKVkiZPbhD2b0vXX4IyBSzRPliQoUDDiQrll9wwGF/wOTp835v+MQoH3rASfJ+XFKOV4ld1z1kqHiH/alx4BD6sKLFvp1MzhxLTfmJAEBY14zTLeiojjGlI9T8sKQTLrnMONyRUaBPJMsm1YDS/cSPl9QXmTuykedaXOL5M0TZKWlbwXCVIhUXLcgAmqif+oBAj6zNdYrHaDxiyfL7wnd4Eq8YWC6/yr/mM10Or/oXrU0dA1JXQqaaUu0aZf4yzJyFxFXmQToVWd57mTdrQsl0y0280mtocxWLadaBMj08cOihFhIa4Nv+7uuBEdEglqGg7ujjxY4rubOI81AslcXRx7R4Vk42kuKoCMl3qMIa3QDaNBI0xyMB+E2EP2UL0Gritsfbo+nKDzOBWMkvLLX61N54JhCI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:43.8909 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f13dd8bd-b36d-44df-96ff-08d98e6a9368 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0007 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: I8aC7PQuNwPaDOVD6NOyD7grx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144268; bh=oSwcvTsVjYwX+k78VI7Awf3adRdOnt8wUMeQ+IQW35I=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=otPio8iSCCyZHy2mLfh1Kec5/PbmlvH7GWUNnJUMSvU0XeYVY/LvQIKDd2st+faN13/ tj/bRAmNJZPxGqtiYaZ1VEJWVhzF/emU5owtFl/1Q31DC44wsfIVchK7Kt66CkEr0jPYz KoYpImP+f005cze+ml7h01PIw4ChCoN2+Po= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144269061100022 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 3e4e80a1e5a0..ef0f319938b9 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -347,6 +347,13 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase|0|UINT32|0x52 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize|0|UINT32|0x53 =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|0x54 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize|0|UINT32|0x55 + [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 09454d0797e6..4cb81a3233f0 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -46,6 +46,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase =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 fa785fc44b5b..af713826b9a2 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -79,6 +79,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)) %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index eba861129333..38cc8809a7fb 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 (#81895): https://edk2.groups.io/g/devel/message/81895 Mute This Topic: https://groups.io/mt/86292889/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 Tue May 14 12:14:04 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+81896+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144270392901.03851659426; Wed, 13 Oct 2021 09:57:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sR34YY1788612xIlcDUa7kpe; Wed, 13 Oct 2021 09:57:50 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.75]) by mx.groups.io with SMTP id smtpd.web10.97.1634144269234147995 for ; Wed, 13 Oct 2021 09:57:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QV+T5SVmh2npcB82P5P+jzTgIc0hMmVo2CcO0bOuyt2TgJL0MsXUlCarFA+v7POvlo0SEIJpEpLO04HcVU0zbPH9eFm2peT6H7EopPkOw8zwWUbZhb36wc0FWHNp9fZLhkiDszSECH86er+CgH6esqO/tcJJoWrcCKWOObU3zzofCBmI+dBWc8Q+d9fHDybfGWApe0O4UHgGiJqDsPIZHbvkEk5+X24PxSLjHijqfyz2KmwWX6gBB9r5zivqd047DjijMIF28vlUd3EiXw7KZebN+Vav4AWmK4PZc4J32aGRrgUOOV/oYV34SNtCLLb7T+rAqW4WoocHXF3OZ3JxOQ== 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=ReSf33jgNyy8yOC26Qrzog/q5J7NLjQaYVilYdjVyyE=; b=drXvA6ruUpmnN4GxpyRO3OPV7XeN4gtulHV4Pf8nJAGefcw1yIueAvJqv04o45opjQ+jpYkJEB1KH8e5oRMiRQRrLgjPpBppjwb5tEcoBgwp6vRS3WYHFExRlTg+FQSfcwSYTFPLtFKq7MOlkrfio8k1z48w1+ym17vi8iFr0kONhmmVokx71WKCNqqV/S7x1eU4f4fP9NSdKsrtbWJuJ3LAWexurMKCzqpoAKO07J5izxNRnQydI75wwgYKnwYo8uiMdmg0wTsfT5hyX7q4d583HHPmfD14EdBu2w1WJzCR+kuUBpTOSj02vKwD49Wm6s1CkV32qs2rqKne5iCK2w== 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 MW4PR04CA0055.namprd04.prod.outlook.com (2603:10b6:303:6a::30) by BN8PR12MB3332.namprd12.prod.outlook.com (2603:10b6:408:66::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:57:45 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::b0) by MW4PR04CA0055.outlook.office365.com (2603:10b6:303:6a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.26 via Frontend Transport; Wed, 13 Oct 2021 16:57:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81896+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:44 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:41 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 07/32] OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase Date: Wed, 13 Oct 2021 11:56:48 -0500 Message-ID: <20211013165713.727815-8-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6593f96e-f420-492e-6f6f-08d98e6a93eb X-MS-TrafficTypeDiagnostic: BN8PR12MB3332: 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: wSP/fAOit2GVnmHn5/7bOOPmycbP9m0KGX9yV7i8+zC6S/9k+BoFL5BssbBprCcNiPWnT9bV/NrXXkwErEEcYa7Rm231+b8U5OZoOFiKq4cZiKqUnK5GBhYi3Dcm0v+lwcvlj6YiWtekEcBVl6fa5VynJ3ECQt7inLuD0nZ72R0uIIEOSpu//d/+MgEs9OA/umvxLLU9FKQjP2J3eB8vd0/jKiOn3VKV2juZTfW8ea6C7dZloZgACepOredC2Gxrf6fsBo+vnu3Ijr95w4mlG13Ocls/y9nSnf/MsC+QMz3kcVUR2ih5Kr9stdcRc2Kzir6rLX8+cAIfuecixHstPthD7PCclUrn9Uof2y+kFm40AbMYm7g8iW+1qmZtcclr4NztEbO116Xrov/Wnm5uFQtimztGsHrftrjGgX0pqUZCo1B2VweNHKz/sEy80+EmVwQJF5/5yhkdaSo63JFL/3NR8GVkfz1VRUGDrXU0xo/JgN+a2CYX8ufqtTKY5d0C0fjY0X1RVP+cenh6o9DKazlVOp87QU/Rf1t7caeYnW93xdIIxuAkfRQnbXF/w63etMP8Qk4mJZw9pIGJJIiB7ICd/pPEK4emJafJat3KAGjTwF8jyk/0wAlb9lmmS+4LcqRGpwwQVxpE53zHKxvqg0ffnKzSPac5W52o1LDeAuBkcACZAVR+tckFwNdRlz5VF/DvpSiVJDRKWXrcMmHvvw5AqxiesTQuP21mZMd4jyneckVX6t3JGwXUknOExgmjeYqYKphYyB2F4buNcuSNsPkKNr28dmE3a5VBdr1BH4lI827YfX3jA02xgcgWvwvj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:44.7484 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6593f96e-f420-492e-6f6f-08d98e6a93eb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3332 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: Gs1gkIIYQNQqN00GGDqaaIOpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144270; bh=S4wxNBl0rxa+MBtY8720Y7td/ZZYZ5WTlhuCSjm7Glw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tAvMsj+jaGPjsEO8M5/NOQiGBc40bcg5BSavUPd0DwMcV0ki0HqjzqRZZ0zm+8vh+y9 rgubUKGpY9mbTzcK+xokmPMV8eh8JuW0pEvLj+SD85vwimjrwY6VhfYxFzVO3vhHNKcMp h73Q+bNX81NGlOAU23sKOEYICl+IQFCDuCs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144271345100001 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 4cb81a3233f0..278776a0b02e 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -48,6 +48,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 af713826b9a2..f9983fad3268 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -81,6 +81,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) %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 38cc8809a7fb..b869b24e7c1f 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -43,6 +43,16 @@ _Descriptor: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _Descriptor - 16) / 12 ; Number of secti= ons =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 (#81896): https://edk2.groups.io/g/devel/message/81896 Mute This Topic: https://groups.io/mt/86292891/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 Tue May 14 12:14:04 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+81897+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144273110703.6444793736514; Wed, 13 Oct 2021 09:57:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kkdKYY1788612xDoYOTLXhzO; Wed, 13 Oct 2021 09:57:52 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.89]) by mx.groups.io with SMTP id smtpd.web10.98.1634144271838016792 for ; Wed, 13 Oct 2021 09:57:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UFKcU86F+JAZL9R8RwtLMc7uwRvbcnpUJHWDReT8mywl9x1pOMwV+PVsSm1Dw7NST+a3GNGcXE60r71fucfbB186Knq7eWnEmfSqG+ci0yQ01D8wOPU7YIkSbAu1EVqvzVo5hDfXZRykmRooGJ4cGLVJXp/U9DImyaO/XAcsd+JJSc3w92H4DzTldaoA5aT/DFGZGWRjaPVKwlVgqV5jxH3rFtzFVH7Y4BNbPrUgTHHREy0EKcF7xThPm/PMAYtTqm9Ke3yxzmD4c0kYVs4YdGj2kQNGrf2W4pfYle9GkLlgZEqMQA7olDjlJaSxe1I08cRL26Qe2vzurieYgZB07g== 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=fOhtuzdE1beT9H1crVIr6U445PN9KZxkzZL7wczetCk=; b=GnaI1Qiw0bkZkdPdoLrr5Etjoly5qcIxHFHeQtkE03QxjZLjSR20WZPw2Mj+QB6k30g2bXmLOeIGKxNYBQhyOEiE7qtLlzidCv5/htFWjhC8cr+8/YLGAnMRiT4reRg4y7nnfAM2yzyhvrNRperu050c8Mwv/NfeSIkzebzH3EIGQLnuLI2glkjL2GbJx9b9Ns1jJW49ui7/w7iTkUhyJ8AAxmj79vqTmluwROtQ8Fd5FwWUlJ9gxYEaDbSVYC0Lr107IFHYOwkCaJy3B2Pmnura/4B+BUgOU3rL4TJQTn/+JsUqSq0nmqXZGCd5JMsp6klcw7DnS3JawwOL1556GA== 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 MW4PR04CA0031.namprd04.prod.outlook.com (2603:10b6:303:6a::6) by BYAPR12MB2663.namprd12.prod.outlook.com (2603:10b6:a03:72::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Wed, 13 Oct 2021 16:57:46 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::2) by MW4PR04CA0031.outlook.office365.com (2603:10b6:303:6a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 16:57:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81897+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:46 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:42 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Michael Roth , Jiewen Yao , Brijesh Singh Subject: [edk2-devel] [PATCH v9 08/32] OvmfPkg/ResetVector: use SEV-SNP-validated CPUID values Date: Wed, 13 Oct 2021 11:56:49 -0500 Message-ID: <20211013165713.727815-9-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de688705-1413-496d-53fd-08d98e6a94b7 X-MS-TrafficTypeDiagnostic: BYAPR12MB2663: 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: /Tp/ftzpJ+FowDluCpxfvejD8iYlEbeLQqrGgnc+aeSnUGctiOYbtJ7z0mzLY/b/d23xjPRDGODQCi+bng0aIeWVEfQHfif3/a3qgjHRnYOVj/Eko/iKXC9LYrwJcIU9b3jxArTdUlGhvsr7jdmuVsMgD3Y0OEYG/IKUJIM/CpwqgBX8PDotQc06F9PVlaITBP+CascL3D3pbf34PRZRC/7V6P+TDpNw7IGOfQ9IRiX7kEqUpid7t0vuNnAk2nJObh53Jl3uu8p4ahh3qQbdK5cse+lVbg64ZZaAla4MO7EhlOPlZSZru/tLAAIUaOvNzIpDZVg9hnyZdBBaaeuCcoyulYuIwsyx2b3cjRfySj3je4EJGDjCUdvZAW2VpovYtdauzZRHFSt5CkIRKr5txGE1qhRFJeWaXMj1AV47u1Zxu4wX6X08PvYlQOZHNXH7raRINrbjeA669fJrst+32ZTJzXc1tdYEKXKTYE9Nc2oNRUsKnh+jqFA9gkta87fVFd7pGEOEZDMlglDgPLGU+TBH+cnmI0fuqUOQbmXYFAfNLLcfqsFv4brWOWXlKLUOY1mhhr9pCIYaOgfp0M9umyb/vEqx11dOuHExokU2kNKgMOjdHxJFRc/bC/lxWHxvPIVTT4F8NMvoVYunoYzNzGE0Y/6pKhMroSqympStReXtUn7jgoJFfvBGNJXdByzkqliEB9rItchjK1XiFAtocaXCFAUNyF0j/188vwlm4Mg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:46.0846 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: de688705-1413-496d-53fd-08d98e6a94b7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2663 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: 18XL5BmpsN1dbMqBkzyakwjpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144272; bh=/FCPYFTsftXSspxGvB0XTI0J3pAy/iSjdaWhe0mgwSQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=EchzmS9ggNdsl8qOD8CUNB1sqtMW9SpHH9DYkYwkmyc+eSbBGs9TY34QF8nah1bhzTp SrtxtTUblRgAiSleBap8sly6lClXg3Zb3QFRdAZapt1E7N4u6i7+HB9MXv7kvtSMDJStr e+sALWiAHlFvrwOW//PgFUqj30VyROVa8Tg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144273643100008 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 Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 (#81897): https://edk2.groups.io/g/devel/message/81897 Mute This Topic: https://groups.io/mt/86292892/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 Tue May 14 12:14:04 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+81898+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144273590925.3292447326088; Wed, 13 Oct 2021 09:57:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kMOoYY1788612xPJq1obDEnJ; Wed, 13 Oct 2021 09:57:53 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.47]) by mx.groups.io with SMTP id smtpd.web09.105.1634144271966990648 for ; Wed, 13 Oct 2021 09:57:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ngeia0v38L9dvjyEgs6/PWMxHLuITlEZed5Jcaue5iZGxY9No6TucgyB/wvt9STqdt8t2aj8dEgn6xdpWNWIII6yZyoINPyeA0Kgi8ePP/BcmWYDHTApvpSru2HDH+xqS/EU/x/mgIHNEuYhIKtp227K5XqglAHAc5azndKLwl87QdskLgkfwvfLCTiSAAyPBMoweWOcW46P/xAcCSNHAwCB2TmTJZiHcM2viRcJ8+mvknWZTiZSu8ePos+waw6btqz8eyXi5KVjv9ugkvPOVPZT7gZJCxcoRKjuNOXScs6W2CmbD7wihm4syxXyAv10jiga20B3sgHZE/6G29eVjA== 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=h+zekxMSd3+IPW2MUK4+plp82SPJrfYokMHrUtl3hLE=; b=VG6TeAnU872xteENxFRnRq3SB/tsBdbSeRupljpUMkvq8IGoF16mow3b+4nslLD18BD17R9Ra8Wch8m/AnCuO5wtiLPkZJ35Knm7gcxyrlspIKJYqrmRPF655Q9xtUjldsnQpqBB+VW0/4jfqdoQPEM58A+8Zj+hkNwL/XlE/v74TJ4OUXFOmcp8Yt6xDhq9oWM6zOOMaqOWBubqemYOz972bnGuP8YV8j2TrhOlaMuT68UbxUNa2lm56maLUaKirKRX2sWSSOVDM592W2JwoKJLEQfykdVwZeyp/EahRxdM/x7vOStzqDow77oQifEQ3P+Spo7dRi6bQmRYVmTHAQ== 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 MWHPR11CA0009.namprd11.prod.outlook.com (2603:10b6:301:1::19) by CY4PR12MB1493.namprd12.prod.outlook.com (2603:10b6:910:11::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 16:57:50 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::62) by MWHPR11CA0009.outlook.office365.com (2603:10b6:301:1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81898+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:49 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:43 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 09/32] OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() Date: Wed, 13 Oct 2021 11:56:50 -0500 Message-ID: <20211013165713.727815-10-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe292ac4-3786-4df9-f0ae-08d98e6a96c2 X-MS-TrafficTypeDiagnostic: CY4PR12MB1493: 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: CY4b8ku7JEP+2NLF2hyeDABU5Cmn1hJvuBzkbn0gibYmZ4OUMSS67LiuAEXJ4aFOL7/zCU9EbbnaS2lXCM3N7HSzxiNWtMuIxxi7ULvUt44FbFaosiGZX5GidXQC9V1TScXNOtnt2fBDmQrthZ1YIz6UTJ3XCXE9a76zYkDhkIPNCg/2m9+46ZdtWsCLKrX/QLkDfTJIf5MlkTMsuyJxPzHWd6KDrsJ1RxXzuAf/YcY5nOC+NHhsgZs/3X7pFikLeJnkB2vTq4+d2cY04kEx9In/O8kjeIRR2EgoN/PyZtDLB+7ipwp6wLlnUxlxh6prRbyFPEdTkCrgTrckb7prTFIwE4r+g4kYIUNWPm7xroCNYAzcecPyUbHhY7rdW10TLVPEj/ZXXA+4FUEdkA9qXUwY6RoGePV3BN5Uf4PfzcHBNYPeE0ccuSizIWuzkEgFWeDTVdakXuXVxqqEXsdHMXzLYXE1Dio3Ye5yUBYvN2pIOwyfbVxlqdHCQQg8dRNUJzx7se7jOTw5ZoQkCbhDeFprklpApuJK8iyRptv5V6bGrM/tF/TBwk1P7aG5cNSjqwEwzgOqNSk4V9FPuAqDmSf0JCGvnopw5G2WcGt9iTuNN/RIaNtHn0LqHG9g045+K6VtH4+DoOOqPhmGaGk1hrAZcETj380ZUea1Op1iJp0aZaGZjGIVQwUJpnjz+7GIpryEdWRR+r2I8uZ9Y4I/QqepaYSipISje2oshYG1kM/hNy5TNK4qujGUzMNH7uNBPgVtO1F65FEMjA62LRgsUnLY8oY/SsD0mvT2xUpGttEQN4VCe3FgNEKbzEMBDycTSSUzz0QBDIQGiV9eI3VObgEDmfXXPTP35xURzJEATic= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:49.5214 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe292ac4-3786-4df9-f0ae-08d98e6a96c2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1493 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: 3iLo9hSYR73maV0t61yQUEPfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144273; bh=iFjfylB7O+R9/yvxCBIReyVxa4tgjxpIKkWliE2kKm4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=m5il/7QNgDcZDpf5iWhmw/rr6pkWb6AwuCp12xomemnx2RIf03/GMMQ3FccqhmI6Juj hovSbvg30uveoqQVbPOda1wIz9Q9LyJYps3KpHutMWD+gQOTpcQqy75XHjhPYAxONJKxb 3UfIDWRlDJXXGhhP335hXCeuhTDx+P/GpZ0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144275649100011 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 adc490e466ec..796de62ec2f8 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 2816f859a0c4..057129723824 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 e2fd109d120f..b561f211f577 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 56d8f3f3183f..69852779e2ff 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 (#81898): https://edk2.groups.io/g/devel/message/81898 Mute This Topic: https://groups.io/mt/86292893/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 Tue May 14 12:14:04 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+81900+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144274734420.9538127441639; Wed, 13 Oct 2021 09:57:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tWMDYY1788612xweQlJrBGlZ; Wed, 13 Oct 2021 09:57:54 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.41]) by mx.groups.io with SMTP id smtpd.web12.114.1634144273424880717 for ; Wed, 13 Oct 2021 09:57:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S/UkIi/qLjrP4XqXeyCl80rrRG1TTPMzmUmZR9/2KQdWDlsGha5Q/sLaMQQZ93lqZYfhI3LZ4XyEZtcVJlzXWs+P7TqqJXgXJVbLDrjRV9TPv4DvciidBWX7ou+vbmcEzrY+UrK0kMnA4SzhThuweoc2L/oRU26WWb/cw0KwXssKxOMVU06Z2R5f/rLwU3HhSRHH08fDCUdZTaazBrPuaXLjxUmG1vCufAb044gDCnhI7baTkras3pNcDyXVJzGqcp9IZYaRmfoP09JnXnIHdLgDBaM0+QZbXCMxdDV6X1WsNI6H7sjhpy13mippq4mM2Uxb1GuhL0wJksDcHz7ppA== 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=HF2W9/+B9SXNSLgA1UL2ZD5ts2exPEOIUKLe7KETuMA=; b=HBn17RS5Z3SuCvmADip63wiRcb0rDCnCd7XjaJfOx6mqIehJI1Xrm/11vllrLfMHnfKsF3123rDUJ5CBJfndrS8L1qOb+zjpiX7LdVOrNVpSK3q1FgIqd0nZsgQ9b/9uNzvgQrIrCPYuGqG3BiGiroTowoPKb79LTGfxdQk2XJDK2eUJgddvglIplXHsIs+CjquH4uTQavZD2iE2TndFQ+ckQYK+4uUV1z5vyYPwLXDZZOScTqSFVN9K21664yX2K4YaV8JpkpS0JnX0nc4yLO05bUlUncRT6I2K1dRrtwoZ1DNBBtJDs+T8UBFda+foW/SWpEs9pFvYVpmAq+e4kQ== 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 MW4PR04CA0032.namprd04.prod.outlook.com (2603:10b6:303:6a::7) by BY5PR12MB4644.namprd12.prod.outlook.com (2603:10b6:a03:1f9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 16:57:50 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::78) by MW4PR04CA0032.outlook.office365.com (2603:10b6:303:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81900+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:50 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:43 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 10/32] OvmfPkg/SecMain: register GHCB gpa for the SEV-SNP guest Date: Wed, 13 Oct 2021 11:56:51 -0500 Message-ID: <20211013165713.727815-11-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe698e06-216f-4b17-478d-08d98e6a9716 X-MS-TrafficTypeDiagnostic: BY5PR12MB4644: 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: LwXD0IA6JdX2do8yCr6vi7lRdLZcA/oZi+vI/W8WuLcfGasYu8U5E/dgJ8ueWm67WNwqX2ZirypUEE2Tg8ev+SIgBCjH4ym4dQdNlEOxcS7h6K/jTYrdRtrbuhgYKUlfxVs5FEPyEtspTM7mrZq9rxm56qZJwl8zIaSbkRQbZAk9gjMY1dkP5w/S3mzsOTVtan6wJN5A/C3tJSMd2L5ea18fK6TmHSpdyvZOgvcr5R9TVbDVZdKM1v6wIORUaYybTWRhJ9H8BUdBZah5FzYKc+WqXm3V9wNGAqQkYNaf95RL6G/6QQdfFKwqs7/0J/iT/AAf2Catr67Nkb2XrZdr9PRWcgPaTFsdG/NipupJwPfaQ2Nw41CQEzHu8siYDyEYebqos0r8k6ERO2lXc5fajXg9iXrsEGJweTxa4RwuSG7edpkZCqdncWpEJyiSpcicqmIld/oIjwmIPv0Keu33Nbnbf0RJvHszN0rdIyv2cVlDG8bFdfFq8Thj+SfecVyzI3tSrV68M6ODZ48R19JUD901gk1q+hzUPWbELad7rjyhvHljivFEBYiuhHbpgQrzU7gvJ0ZlnxcQX3qJLA/oM2yZhC4IFknhMfmrUjTuNLjztwZBhluBhDDRsiOSkjKDVKRV6uXWnCi0mOyDxtcbybsFe8AYzdxwyXYBARfGjMSSrBAXLCV6S+TcCdrUSmD8KG/fxvbWhtN3OVlI6PhCu2qMZzksZgKrPXx8jzr/L+IhUfCT34xxprP/A3/Q9Zud6tyXWvsPe4kWC1tDO2rXoC4TJ8yBZEAucu2sRsAefZfWOuZld14VfJiX3b8sq64a X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:50.0633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe698e06-216f-4b17-478d-08d98e6a9716 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4644 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: p8tA7Zaymkik6LCqT6IAQs64x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144274; bh=mWQBsF7wB8mb++Z7T7OPkU4+EU2UDYzi+dtTpEvOUUo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=DuDA0nOCDRgeKjk8Y+tJeSnlzuH2xVaxJxdmZ+h+hBd2bVUmBzkOFigYGBiDOOx2EYl ELIQkb+2zFjm3paR2AoyE7WNcal8l0KFpJXf9bzaUZNT/flM85Lk9oOnQjcMcjFTUQpFV I+ZMj9ywOh1MaFJZ5zzRyFAv6kSgGgQtCmY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144275931100018 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/Sec/AmdSev.c | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/OvmfPkg/Sec/AmdSev.c b/OvmfPkg/Sec/AmdSev.c index 7f74e8bfe88e..9dd42b195785 100644 --- a/OvmfPkg/Sec/AmdSev.c +++ b/OvmfPkg/Sec/AmdSev.c @@ -48,6 +48,103 @@ 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 ( + UINTN Address + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + EFI_PHYSICAL_ADDRESS GuestFrameNumber; + + GuestFrameNumber =3D Address >> EFI_PAGE_SHIFT; + + // + // Use the GHCB MSR Protocol to request to register the GPA. + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + Msr.GhcbGpaRegister.GuestFrameNumber =3D GuestFrameNumber; + 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.GhcbGpaRegister.GuestFrameNumber !=3D GuestFrameNumber)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } +} + +/** + Verify that Hypervisor supports the SNP feature. + + */ +STATIC +BOOLEAN +HypervisorSnpFeatureCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // 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); + + if ((Msr.GhcbHypervisorFeatures.Function !=3D GHCB_HYPERVISOR_FEATURES_R= ESPONSE) || + (!(Msr.GhcbHypervisorFeatures.Features & GHCB_HV_FEATURES_SNP))) { + return FALSE; + } + + return TRUE; +} + /** Validate the SEV-ES/GHCB protocol level. =20 @@ -88,6 +185,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 (FixedPcdGet32 (PcdOvmfSecGhcbBase)); + } + // // 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 (#81900): https://edk2.groups.io/g/devel/message/81900 Mute This Topic: https://groups.io/mt/86292897/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 Tue May 14 12:14:04 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+81899+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144274249562.7655892149035; Wed, 13 Oct 2021 09:57:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TaL6YY1788612xizeclusxSl; Wed, 13 Oct 2021 09:57:53 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.84]) by mx.groups.io with SMTP id smtpd.web09.106.1634144273166116059 for ; Wed, 13 Oct 2021 09:57:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P1OSk8EbD1zD8j5YRIi/yekquhtuMTUbkO6dNiYEH8Jz97PCGEyIc2TmzxpwKPRrrD2q3ESS3Mvq7A95cW9XncoGUnMfeghU2EfmP9mhFKQ4XGHZtbjdM3Hz+Am4EmuYKR1P/Ta20yNr9fdWAG18Jcn79NWtVFP+c+51Txa621f5Ipm+0/oPw3RZ3HE3TvfhVcX9g8lQvyNaKkn1YQCx7wvmJ83vqwVuVadexYD0dOUsF3O/RMl5Mo4FbwT/+bhqyeDtRGh1p3aHMvgk3u2+CjIdS2sRF/QXucNynZzpGc9m681MUkPiJHRUKo9GTVzOMFSdDYNKzs3j+tDVmxSJxw== 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=opvn7++wABQrV/KQqQ7rM3nMoEvAIjR0f/9brYR5lUw=; b=fcCuGX7K15AN8fEoTXtHjOkG0REKB8UcS1CpbGda+WVVM0wG/cEstYjVDAlBDIfv6VF/zpAUmk7lsOLi2rU5ts1+acUGrdQ4FNN3JUOOwxiw6nz0io6elWBECsMAZ3+rK5KXK+loNNUQncKIl2fHa4WWaZfd+jnnbFhZEVWxyRdzeuWNONsH75KEznINCxNRQcxy+JZB4EfGMtby9WfL4KtibrYr0xIoyXyGjBxna/FhZn7Xml8tQeQA5xsrqkTEpTi/qV9NX3dQMH4ddGGi/Gbf4TctqW2p8EmsKEguUv/weqHtig8bbFhHb14i2VAD9v9IWA/mlvmUTzJYMyBydw== 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 MWHPR11CA0002.namprd11.prod.outlook.com (2603:10b6:301:1::12) by BYAPR12MB3446.namprd12.prod.outlook.com (2603:10b6:a03:d7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.24; Wed, 13 Oct 2021 16:57:50 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::3c) by MWHPR11CA0002.outlook.office365.com (2603:10b6:301:1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81899+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:50 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:44 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Michael Roth , Jiewen Yao , Brijesh Singh Subject: [edk2-devel] [PATCH v9 11/32] OvmfPkg/VmgExitLib: use SEV-SNP-validated CPUID values Date: Wed, 13 Oct 2021 11:56:52 -0500 Message-ID: <20211013165713.727815-12-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5c132f4-76e6-40dd-1801-08d98e6a9735 X-MS-TrafficTypeDiagnostic: BYAPR12MB3446: 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: ersNqC3hTZYF2OxLKuXdlppHpLZytlEhg43vMhrWAMHMmLnZhUm79kVUb6Sb9F8jBJfazcY0p/QN212+qR+JGdfvB6tcgqIqcCv1XpuI9SUYMUw54sISN+ieDtoyer7/CQSFzm7yzkRarH9WRelc163l25WH/e3c4KWgBnnWhKtJXh5hyFekjbXcbiThGfkxTuhqTgkSpoZqUzHfSlw83KXAVFv4YtBVcSsv/ZV/da1hKi6DY8dRcqVuaNMXLjrsNvCp//23Q8TmOZqPv0nRoMsLyLx7CyKabYxWklp9FzYldmiYczmGuTdr+3aeL74ygt/8KcKCjo2t53vPDuaxiYfY4sp37lkTuJz0vrAQlon82XQZ32rLUYs+QQ4ako0zUknbHz89SUwO5scAGuff6h4YjWjZkN0xib3tY0twFO0ZYS39G3jNpHq73iB7YrgGbgR32ZLCjdFLZbXnRR2a/o17LXJLRCtXgdUz/+1tWmU/kvYCPymFDHGLIXZcqeIarm3u3HerHE5cND9h2LKsirJ2EBX7lfFCsPOUfw3Zmh2+EwWJrQONtkuO6Cd3UMKyUHlwuvSU+ff99QPZTyKaXwaLK3uCTEMp6PzwRo2pJWgglLiwo25po1RJPt9DfAxsJD7PFy8W4mi1KqKou8jsR3L4PNJNwE5LT683vEQ7X4aar6jweqSRVIw0EZf0DWsd7OHidpeYDtwm6Flc3lyyOgEgYfxMn759or8j3X4byxBKW9koUrQFKPgKSaaFatkClMxystAyQA5DLQMAmECy4Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:50.2685 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5c132f4-76e6-40dd-1801-08d98e6a9735 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3446 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: 1b2TXNGOwjmzu5gL5yjanbKZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144273; bh=pcd1BLYTU3axnFpiMQg/410XPeRR1ceWY5twUU+tMh0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=g55MtwjdMHtRflAOInmThFi5es5oqFEP1TyiJGQDi/dwo4jLWio5XvffoWomcBgdF8p A+aqR7QvArp3diU6hVPXntCg34B3dnhxWZI7dsFXMQnDzIp1VRIUDPKfBlTEY2El3A++D 7Cdj6lG4ct5LulJ4Djc3fKbFmyHrzzEr5Tw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144275809100014 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 Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 2 + OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 3 + OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 444 ++++++++++++++++-- 3 files changed, 419 insertions(+), 30 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 41b0c8cc5312..cab4e2b230d0 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,32 @@ 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 @@ -1496,58 +1523,415 @@ InvdExit ( } =20 /** - Handle a CPUID event. + Fetch CPUID leaf/function via hypervisor/VMGEXIT. =20 - Use the VMGEXIT instruction to handle a CPUID event. + @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) =20 - @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation - Block - @param[in, out] Regs x64 processor context - @param[in] InstructionData Instruction parsing context - - @retval 0 Event handled successfully - @return New exception value to propagate + @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. =20 **/ STATIC -UINT64 -CpuidExit ( +BOOLEAN +GetCpuidHyp ( IN OUT GHCB *Ghcb, - IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, - IN SEV_ES_INSTRUCTION_DATA *InstructionData + 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 ) { - UINT64 Status; - - Ghcb->SaveArea.Rax =3D Regs->Rax; + *UnsupportedExit =3D FALSE; + Ghcb->SaveArea.Rax =3D EaxIn; VmgSetOffsetValid (Ghcb, GhcbRax); - Ghcb->SaveArea.Rcx =3D Regs->Rcx; + Ghcb->SaveArea.Rcx =3D EcxIn; VmgSetOffsetValid (Ghcb, GhcbRcx); - if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { - IA32_CR4 Cr4; - - Cr4.UintN =3D AsmReadCr4 (); - Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; + if (EaxIn =3D=3D CPUID_EXTENDED_STATE) { + Ghcb->SaveArea.XCr0 =3D XCr0; VmgSetOffsetValid (Ghcb, GhcbXCr0); } =20 - Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); - if (Status !=3D 0) { - return Status; + *Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (*Status !=3D 0) { + return FALSE; } =20 if (!VmgIsOffsetValid (Ghcb, GhcbRax) || !VmgIsOffsetValid (Ghcb, GhcbRbx) || !VmgIsOffsetValid (Ghcb, GhcbRcx) || !VmgIsOffsetValid (Ghcb, GhcbRdx)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + *UnsupportedExit =3D TRUE; + return FALSE; } - Regs->Rax =3D Ghcb->SaveArea.Rax; - Regs->Rbx =3D Ghcb->SaveArea.Rbx; - Regs->Rcx =3D Ghcb->SaveArea.Rcx; - Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + if (Eax) { + *Eax =3D Ghcb->SaveArea.Rax; + } + if (Ebx) { + *Ebx =3D Ghcb->SaveArea.Rbx; + } + if (Ecx) { + *Ecx =3D Ghcb->SaveArea.Rcx; + } + if (Edx) { + *Edx =3D 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 & (1UL << CpuidFn->EcxIn) || + !(XFeaturesEnabled & (1UL << CpuidFn->EcxIn))) { + continue; + } + + XFeaturesFound |=3D (1UL << 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. + + Use VMGEXIT instruction or CPUID table to handle a CPUID event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +CpuidExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + BOOLEAN Unsupported; + UINT64 Status; + UINT32 EaxIn; + UINT32 EcxIn; + UINT64 XCr0; + UINT32 Eax; + UINT32 Ebx; + UINT32 Ecx; + UINT32 Edx; + + EaxIn =3D Regs->Rax; + EcxIn =3D Regs->Rcx; + + if (EaxIn =3D=3D CPUID_EXTENDED_STATE) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : 1; + } + + 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; + } + } + + 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 (#81899): https://edk2.groups.io/g/devel/message/81899 Mute This Topic: https://groups.io/mt/86292895/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 Tue May 14 12:14:04 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+81901+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144274647569.5376561222799; Wed, 13 Oct 2021 09:57:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qHN7YY1788612xFTxXcoo8dD; Wed, 13 Oct 2021 09:57:54 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.45]) by mx.groups.io with SMTP id smtpd.web12.115.1634144273629375244 for ; Wed, 13 Oct 2021 09:57:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cF+sLqAkr0TgkCchCyoaMQnU2/N8nAog+NcjerV3y/LKi0oD0zoamyLxJBj2jrf6d7UNwMIbEfibKNfE7DWDRrc2tkwX1cswmv3I1flSHhVproTJYLYvxum2P1qwbQRjbZUuI9cI0z9zMZNvd3Z8cPzmgrK1uaYfgH0xxmUWoa5OC4Ew6OHSPmYMBkeNGe4s0PguXst0sy7q9S7Ve90FZ8/Ox393kjKNIfVVLJboHyf8gbtDtEF7V85T9/vF7ERVvMPGnKpQ+PRB+/+t/dOJ7/V5jwSuHITPMMNspb4JSG7ie1lQnRdHhD3nnii+NitxyS9OA3q3Za/E59Ib1/yNWw== 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=HuhGda+6oARJ68tERacVq0XDbULIEzJt/3fCHJL4IjU=; b=QgVM0eHiD5wOMY2rmdqxMQ36GtUP/A6+opVAMAYGlZ42p+EP4eO3EtrfpBR/h8vBwpRneJcbYN18XixyDTuR1V0cCR++d7x34f0BnMKP/RKAjTMkMaYpLEOaRdk4UE0pKUmraHXhZAUHyO1Nk++XEt9/dvYWMOaejGgIYEmPPOc0l/NHnwTgU4Trpf89sV/Kx79jm/8OcAU4ochNoAr/amnKvnfvxGAxhYnZA88nE26vvpeqbtW9acTeoxM2rezJWF/03zfjjUAxHySJHVkOKd5C0ZeQ4zq9/RrnkFWOjUDRyYRuFcQb0H0Fah+PskPbLgmf0jedr5pmPLj3eQTmMQ== 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 MW4PR04CA0032.namprd04.prod.outlook.com (2603:10b6:303:6a::7) by DM6PR12MB4864.namprd12.prod.outlook.com (2603:10b6:5:209::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:51 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::78) by MW4PR04CA0032.outlook.office365.com (2603:10b6:303:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81901+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:51 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:45 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Wed, 13 Oct 2021 11:56:53 -0500 Message-ID: <20211013165713.727815-13-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75cd8f28-815c-4c57-4405-08d98e6a97bd X-MS-TrafficTypeDiagnostic: DM6PR12MB4864: 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: 4T9HBUOcy8NzllOUw4Bd3qXfeItYnCxsT2rJqkoImTiR2fbhXZm67pmgavfbdYBeGVNP2DS0UZMNQRiNDZCjH5UTWeVDTv77grwZbE/MpH0D38hCztqhSLb+G+DTYNvC+QByaXgzbmr3nbbdYyFKMzLTzJ62inEOt1ensvyTYlg56HUAdUrKFmXTHEUv1Gn8qbv2gquA7gbe8+7tvSp1RKBn+ia/IK5iAT04+PCtvqH1gcEBXzrM7uZWJE8HLHhdKmK7nq+CWqdMibEC1pD800+585+a6aBmkYsNbgXD5Xvh6mgOs1n76oDYKWQ5p5sMb9bdwK5Hva4sWlQItpJvtAd8WKr0l9HlhAuyFUPwMjFfdHdDqLsjQW5YMeq6PkhEzLPvCEQMB8G4GaqQQR+dvUzHO9x6RPULHXog+7TgMvzJmqHbZD+wadB69/32fWQRNE6+B+WGv8HlyzgTnZjPuZfyQjezsgVih/PwTdocx+/7M2zfSWiYXK8HhhwG4oXn4r81cVXD0vmtE/MNLxwY4dBROC+gv8SF02eHJAkKYLnAv9Uh5v0bY8fUy0YZR7VtyVFYEXUcUiySo9SXwog+PCEQ/xPPvK3p0GWOsyHgShy4G7lP2kiTccCcFnPHBqs4fVYvzOTmuSaLHhb1TtjwAf3gqS9shTCn2Rm3h5QhGzSLV9pgBbybaGKCClDxJnT2GdkPD26QmTVbCbZywPyZPW8EdRgIW/szH4t7FHxk8VXjnhVahRleuRdrIv3jvW2eblr+CBj00HFlWIOEXBK6nYv2lKvLhLwDbeL0YeNQLD7Uex6B3i+qczwDnuYE+54V X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:51.1577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 75cd8f28-815c-4c57-4405-08d98e6a97bd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4864 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: fV8HUVjvBPK11xnDYlz1BOm3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144274; bh=k4nTNzJVugDKOI4xIWxbkMRgQ8gzXja6ZGjarcUf+bA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Rm7mUXaTzb52WgixnnU8sqcqoKSLSvnzrmK6l373E1DW4TTNPrB52VcHlrvOaqwEmHt mxvKP10o9spTVViwJpaxb3UR+/VT8qtehh6FtZFct9zMlGUX3lMJVt4Tl4ZBe318dNBWc 0qT3eytWnmHNN4UnRwHxpV0zNRY5yLyjHDs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144275883100017 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/AmdSev.c | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a8bf610022ba..de876fdb478e 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -19,9 +19,93 @@ #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; + EFI_PHYSICAL_ADDRESS GuestFrameNumber; + + GuestFrameNumber =3D Address >> EFI_PAGE_SHIFT; + + // + // 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 0; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + Msr.GhcbGpaRegister.GuestFrameNumber =3D GuestFrameNumber; + 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.GhcbGpaRegister.GuestFrameNumber !=3D GuestFrameNumber)) { + 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. @@ -109,6 +193,13 @@ AmdSevEsInitialize ( "SEV-ES is enabled, %lu GHCB backup pages allocated starting at 0x%p\n= ", (UINT64)GhcbBackupPageCount, 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 (#81901): https://edk2.groups.io/g/devel/message/81901 Mute This Topic: https://groups.io/mt/86292898/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 Tue May 14 12:14:04 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+81902+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144277552963.6137129451215; Wed, 13 Oct 2021 09:57:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YNkXYY1788612xUpXGX4dTPI; Wed, 13 Oct 2021 09:57:56 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.40]) by mx.groups.io with SMTP id smtpd.web08.113.1634144276223692366 for ; Wed, 13 Oct 2021 09:57:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Az++nAN/th7R9qBMNCXMqlkXfwvH+LsTs2pVwEXB4NM9x+3h8B0mc5wPrLxqQSdX3EO+lwvt8IoQSg8hS0X8CXgqTAYPR7bwVT7DMzAe/PJNf3GvI+8u6sYmC0TmGq/P1c3g2OehA16She6D75RbuCkRnHRY4vM0T1laVq3q4IwHeW9JR75D7przlNVFRlRVAkah/RlArs6JcVEGBbnV12N7XXgan4YbLSRxl/on7G4kN7oimbKNRS9IMkT471IQ90APxUu4MzqWvoUZRUSFDatlml/A1hjYtZjlc07Za6R8nadYq8BO+2SFo39NmEFdfYRDscydypkHl2t0ZfqcaQ== 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=SBaxmv2h8WOuyxvZ4oQuTsdhg4ZKcCqaHrU7t0JXtVo=; b=TMs/i899QPxwh5R1z99lnYxCy4grEYYppA/Ul7eaOMQ846H8u3nfS52a7lQB1WVYApyy37bH0NrcNyCmlVFKTUth/FCweTZ58lV6/UBzLY5RHdq/IcN9Ig4VwrGk9CmKx57kf9n/kOrr5Mtz9g0nPn6MvSlsND5rauz1ZHKLnbT2Q0URhnEwqxtSszE2E9x6btGJKH5ACk/JTid9Iptrb0GuQnnSvi2T8QEZhE+qT3TUCv0M98TmtCsBNHzIF26lpAOp9XSeKTrngREd9uOBxbkUVPCY3aM2/kCATF7KDO35avU+/OcUHvAgS5Evxj0ijxOaaxLnQuAayQA8Ha9lhw== 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 MW4PR04CA0032.namprd04.prod.outlook.com (2603:10b6:303:6a::7) by DM6PR12MB4372.namprd12.prod.outlook.com (2603:10b6:5:2af::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:53 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::8c) by MW4PR04CA0032.outlook.office365.com (2603:10b6:303:6a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81902+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:52 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:46 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao , Laszlo Ersek Subject: [edk2-devel] [PATCH v9 13/32] OvmfPkg/AmdSevDxe: do not use extended PCI config space Date: Wed, 13 Oct 2021 11:56:54 -0500 Message-ID: <20211013165713.727815-14-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 81980a8b-436d-42cc-d131-08d98e6a9846 X-MS-TrafficTypeDiagnostic: DM6PR12MB4372: 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: S8hV8KJ5hbc66I8wxhjG4RmZUKjsniNRI4Seq3Cd9hdXRSqSUVPm5dvCbfLGutHHm12uy/jkZO5e4zSTi5XPR27Q4vtJCH5qJUeSeStqLayZrdrycZQATH6WeDBd0BkPgy7ozrrd8R2OGsMxnKEjR5c0n6gGzND1FP2L9AJI73DuDXXyWanFC6AzjH5lnI+Qs2uumIR1RSwOjFO0Y5g9i19bEKRQ+kGRGONHCaW12QCioq/Iw0kWIcCmcyoplGUuqSh+AY+VUa7rNKSPr/1nDty1HAYdR4+zfzQNJagPD3DrRP3uaDg5QWBw6kJQaq7zHfGt4pxMEq2u162shASBbjaVW/Z8bgEtOSi+egi6Zse5HPL+3c2PC+vnLhCP56sgNldd8mZNVVDvqOdpqsODcIHp9+kvCaBci0za6c4OVugVc9GYUb5rO6Oe8HA3kAVaHwThkCwS0EVJreY/cC9P1O85cGGWUvIFq0ho1H9zZTZnc2TC9Bur3AbeHHw1FvWH+qx+5zrR3c1nydlWNc6F2D0hJkTpyvXghLAHEMjGKf+8vycUKqUNlRMojB5002DNucsRb6z7M0UEZ+/hG15Z5noPnvONHhVGwi0W2jUNkl8JAEh6ijlhPmJvTtnGbp74JhsasENtJkehT7E8IHEt9i0c2ogDT5ZS7kKiXl4bGVQaU3DU+zxAaf/2ig81zV+M0S/wsfoeMhMn7wzWYlvVCpDWeBzkeQTgjfOiLTpEhwS+sIONsJLgksBAaMqJiSeJBysIMqW/tGZjl/2Y0DYiOKOlYX4CbDRo7+JcL0bErJsYVLAMT6Wm69TaYEHypJ3u X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:52.0592 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81980a8b-436d-42cc-d131-08d98e6a9846 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4372 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: YsRTjS8faZkcIJnYCcg3TX38x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144276; bh=pJoHMostgeeR0q+wZY/XJOfFhrTvEdNjxDR8f+RvdVI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jqnwKu/d7U6ZzQM8Oq6dQiK1MgmR1D2oxByP9K/9E1+ufr+gRXtj0H7Oa6T3mRKAWUH xWM/1Vz/mB+jHF3llpkJ6OxvXOESb01sQUxzHIhQfqnMmC1nm24cmP8kcWTmq+W8fy0M6 jg2syE8AbsCkk8Xp72U1Wzlva+eIkdQB/Pw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144278395100002 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 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 (#81902): https://edk2.groups.io/g/devel/message/81902 Mute This Topic: https://groups.io/mt/86292900/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 Tue May 14 12:14:04 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+81903+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144279851426.65785275747805; Wed, 13 Oct 2021 09:57:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Nz4SYY1788612xRN9G6uAhs9; Wed, 13 Oct 2021 09:57:59 -0700 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.web10.100.1634144277811643942 for ; Wed, 13 Oct 2021 09:57:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYwqCs12Z7EJbX8XYPKF1P1gSCy3nBe1gK1RM8C1AVliypjGJocIAPi2augeSaiqf731YwMt84NCYPjcw+InpVoRraIBeB7CAVRM0EM/AuciXa8/Uz7bdEsG2aEmUUyDGGbB2hJ4hNdGAfaIIp33/EK0raQqnCSfAPLjZ5eV/U5wobNiWRM0ZZw2o2ihqOoJz+TDZhD13KTNeL2G12SzUOmrB+KWfCoKEm5YebVf1t3WuUiJ/LqfqMjIDN1Rn23g98q55yXwxII5GwanYUHjdL2S5Xk8FMJneVqHy5gF+dabdjWXSc72VVHo5uV2qgcTiT2d9q8wsDJFG5odGN5xzA== 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=1XJMdubsr8z8LYR1K4ANKgYP0plsJQGdqAnnTLmUj0k=; b=ZhUccNfxQwoG/T2yscLj+hN3CFb3xmqYKVQ8uz5die93/ZplHS2fKgMg4MQQetGLk7RZHaIXqIb5lxFlYiroaVlflDkXXGSyMegfaKIHoZBanYEJD1hcWYlPUkEm4sXeuEUKfu9oj4Nh4jh81CyioTzbHfJH3TffqIYq1ZGNHrKiWQqMzeJcqP1CU0+WLjvRhR2z6D0+0vORg4KuHeF0gmGtUlFXb/H5eH98u6hQwMvyHwwTGkxtbq1L5ab147ApN74gj9o+36BkZ/5wPlwNQ78uacmjZVa8s3thAi2Nrzdkqexr1WJIO9Ln6BlIiLb8HPdFdovv+aOjftqLoP/cJg== 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 MWHPR11CA0013.namprd11.prod.outlook.com (2603:10b6:301:1::23) by BYAPR12MB2997.namprd12.prod.outlook.com (2603:10b6:a03:db::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 16:57:54 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::e2) by MWHPR11CA0013.outlook.office365.com (2603:10b6:301:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81903+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:54 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:47 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 14/32] OvmfPkg/MemEncryptSevLib: add support to validate system RAM Date: Wed, 13 Oct 2021 11:56:55 -0500 Message-ID: <20211013165713.727815-15-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0726b910-18bb-49b5-1979-08d98e6a99d2 X-MS-TrafficTypeDiagnostic: BYAPR12MB2997: 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: d4daEECnLiqbt6rpVhrG0s5LWKFBpXN0xrpmVEhXTA7ltZVmVpZ1u2ikyV4JADL02Tcg2+wDsEYwI56J33uoA4zBYNSSugZHd6mi2Xb0rCKtI2ynm/eirxDzYNoCTEzRZSjjPgBTAu2OFZGiARZ5gdlfvYyKqVxT4BC2kx/XpcwHQ1GfWOcuF13GbDdtBySyrUFBb4/eTjiCyeZK7naZaoJY3mBi+MfH8QC8lZkmLaLKvm0jgaXnvi/JF9lqM634gKRmvCP9ytwpsXlHMq3iSXAILXVujFZj/NxBAOKstwzIgxJwwpm4xAbK9xZMs/vHr55/oFlbZPWsqCqfKaPoETaO+NXzPHzhPm4Ntag44Y7OhG7D4FU7NS5tLNSIIJ4CcjJoHRf46cGrLHreOSjlyKrhUTUHqXwJY8EpuAgWUibiauJh2lxwm/Nu7LAKkmu9cP52dq8J9yGmRkfh71sT/MAkZwVkZqDnUfwWhtc/guyHYndLsaJbjcIM8CQbfrJ8XqamtUWbV/WQ0+qppAfryaOqf62iNH2pj3MOGT0Oo6g8K7g03X+MYscl0o6vpUt2S5hOOVXt3GUmQPvsPma2eIiYrzeB9LhDDDAhtHTkJ1W7e6tkjhLfLfQ/YW8UDllpsZGH5d8yQS0o09vyA5h7ekogFMwIb7wr/q9F8XzMuAPWmFEvgcBgjzw8n1QwQ7J/g4G5mNwQiTlthAedeuh1qqrzwN8JSCdvt0HD8UdXEQuLjDEA2pF6fxC0zZarQh5oiyWs2NdUUFjip3jv4FAuDacH5KHnHArvAt/a+rT47SUVzaT4yquvuvE9wlSs4O9z X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:54.6539 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0726b910-18bb-49b5-1979-08d98e6a99d2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2997 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: lLSZNpltr22FK5EpdQTZRiZox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144279; bh=NfGwtfNeGsHl5wKY9VtKn26Hfz3PAxrQR+2O8FNJUDg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Kk1Fq4lzz9NGLUljVfqa7PaeTH9mojUcKB9aPvZxAzjWckgiUfVE5qsO/w5qVu/zcJ2 oSiwHUYLrDji4lNjtbBQf7TPkCGY7V5yrsFx7O1si7y7KFtkuqiR+37IwC03tbtZxhJuy Xu2ZZX13hRwAU+564cUGk0aoWDNCeH3jEv0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144281011100004 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 | 31 ++ .../Ia32/MemEncryptSevLib.c | 17 + .../X64/DxeSnpSystemRamValidate.c | 40 +++ .../X64/PeiSnpSystemRamValidate.c | 36 +++ .../X64/SecSnpSystemRamValidate.c | 36 +++ .../X64/SnpPageStateChangeInternal.c | 295 ++++++++++++++++++ 12 files changed, 480 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 796de62ec2f8..f708a0cdaa72 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -215,4 +215,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..8bbdf06468b9 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h @@ -0,0 +1,31 @@ +/** @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 be260e0d1014..df5e4d61513d 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..ad8d8b388dc8 --- /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..64aab7f45b6d --- /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..64aab7f45b6d --- /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..506df12d4e51 --- /dev/null +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -0,0 +1,295 @@ +/** @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_SHIFT; + 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 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 (#81903): https://edk2.groups.io/g/devel/message/81903 Mute This Topic: https://groups.io/mt/86292901/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 Tue May 14 12:14:04 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+81914+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144285487754.9846850178085; Wed, 13 Oct 2021 09:58:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id M2EqYY1788612xqqRfuLBAyr; Wed, 13 Oct 2021 09:58:05 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.57]) by mx.groups.io with SMTP id smtpd.web11.118.1634144282905702923 for ; Wed, 13 Oct 2021 09:58:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KmS8vbWEIKuehqjMPprlIDpTXhGn8Nx1uy30dW7DJ/VEO5NQ+Gh2qk5lX0YNsAbhyvWGu+HB9dArN/ap24IBl8B+O7UVGCGMx+dSUk5Uwc5toR9+Qoe4IPZI/Amk4Kx5HVbB2cR+Z4WkVLG8SFzKnLgvOlhaTVjn82R3nzBUyzKoIy96kSUlxaATQQ2i5CoCcbQdaZk40f0TqlCfjy2E/+ED5VKDnSxTGBfJ7Lvk+X9PdvB0TsrK7ePVOqPvm9eWtff07UP3jewheA1Jcxl1fNkqzdsD/jxdt7km1ldO44+LFJ94PBt0mTD1TqfFTHRkMrEm7QdfnliMOVCWyeMnUQ== 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=K+RAaUEZPM3Oj8CKnpLf/nq1jec9JbPs9dxE2pXN2WM=; b=R/U2i0e0naXhls9IRPEMeYhjb8QhWS18W1Rqrkq+Ljx0OYXv6st2JD7nqSZzc2RdHFoM1PHLbyXhj+Ru/p1JeJnQpED7YChAEOPRSfWs1S2eh/tM1NSPGJfVdGdoEfcX8a+LovQWgwqFL4fi1aks+ai/tIeWtsDj1GgF7wfHl0APVcZchqtc9rQzL9HoVhf3zAzr0aX9jSg3vFIB2wEjQR8W0KYM2Di7xzyhaLypeSJ3BHOKq26vdbVxrMvDBQ1Xx23V4D4CxjfNln/1T2ADCmuG1ePnguJVPI4ZYF/pXzcD29L5xFABAcbrr6inI2pP+U04ecMpPS+yICl792K9zw== 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 MW4PR04CA0054.namprd04.prod.outlook.com (2603:10b6:303:6a::29) by CH2PR12MB3781.namprd12.prod.outlook.com (2603:10b6:610:27::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14; Wed, 13 Oct 2021 16:57:55 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::3b) by MW4PR04CA0054.outlook.office365.com (2603:10b6:303:6a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81914+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:55 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:47 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 15/32] OvmfPkg/MemEncryptSevLib: add function to check the VMPL0 Date: Wed, 13 Oct 2021 11:56:56 -0500 Message-ID: <20211013165713.727815-16-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4ae7c3c-e9c1-4ba8-8099-08d98e6a9a25 X-MS-TrafficTypeDiagnostic: CH2PR12MB3781: 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: 2cdnUCHrbM8JFiLQSPBWVFQmZcQYLtWkRQ4gyKbwzd8ytsDKVNkIUlLIZ9OKZZssUyQfJkodJE5xXBCTyCZy8PUy+mjfLoPTiz+Zme69vW1KX0ft5I+aJ8DNIZqYn5hMZ9KgMu3PhnqFwWaawAtaIR8iD/3DJ/7w4sK38NHN7zdaxfMjTdUX1iEnC34xsY/hS/vGk9YerkPqeyAqdJf9XEzzYWKzNAFlN1Biw/CwrmPYqNF+Kgz4RsiYancZb7QdPt2y9/ATxNt/nSjUCHyL/QSfDUdy0eUv8pwSuphKVBXF7DdYCMrA7AVchBGjk8AvlBRpjeN3MqiKqURQFx48pInGWDo2zNmou2VvHFPT+0n28lAU1sVK90DW2sr9osLHdSIqQGGtM6uxmoqg4pVmE7h8uPIyZZG/mvJaEpb/hhrWL3AQYGBwBILoazI/2T9+ABghfqwSWA4nvkQI32PMxOIwyP4zGeJbuV8mOZe17TXS5icNhZ90GDL0sGwF/vtjqaR9RiYCfg2y6Wuj3eMMAGqJfmjAkpw4LD7t2dp6bQMGOmXVQT6vU/nMVB/9a1uTy6cIcR1LGn5V8K0SDvnv/oLylYd+BWhe3LHQ0gfdjhf/0rV5kwN+jbEbnZv+MtTmGsHD69dECcV7/oMUmEr7C4oH9bpMSMGDHdjnkY8rUDD52+wEb1q61EZ/F8dpMDK/pSb7OyK18EqoPpZIogS5itpSQAvarhy5JSSauSdkUiJBnviLXJE+any6O1I4crcQ+ajHzNan/Krzl/b4Jtr3dYnO7gNLRk7T0QUghuZEeEq2cWHh2mn9TORc4HoSlAV5 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:55.1953 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4ae7c3c-e9c1-4ba8-8099-08d98e6a9a25 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3781 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: JxOO6Udm4JhbGtpqDeTnlCbVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144285; bh=ZUuHBpwxDYWQAbXUNhxUc9SrpohFfbNpDml584THhuQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Vrr+0BqFw9HAEQmp71nFj6weh8mm77xUD71rjNtdhBsfeSvBa4SLGgjuV+d2rzyGylA mB5QE3lNKC1Gjf/BjRrrE2l5oysimCdeOtOVqnmOWxFPXwbd4/hErV/9KtEu4VrqeDh/N qy+qcHwOW/ivUZLCBOYMKXa5r1AX1/cAh/o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144287644100054 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- .../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 8bbdf06468b9..cc1318075523 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h @@ -28,4 +28,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 64aab7f45b6d..3394094a65e5 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 506df12d4e51..653151d4a422 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -40,7 +40,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 (#81914): https://edk2.groups.io/g/devel/message/81914 Mute This Topic: https://groups.io/mt/86292914/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 Tue May 14 12:14:04 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+81904+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414427944446.689457970522994; Wed, 13 Oct 2021 09:57:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eMXLYY1788612xWpDFv8sOyc; Wed, 13 Oct 2021 09:57:59 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.41]) by mx.groups.io with SMTP id smtpd.web09.109.1634144278433689872 for ; Wed, 13 Oct 2021 09:57:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FPXXMz1dNQUlz//XO+NmGmA9kIhvu1r3JslII7V2k5whJirimy0NXMXC9SlkCXvJbj+n8qBk9BHuGt7RGfYxKTTgs//9E/nMDp2YVrdFS/ZxZrcvuTCZ7mDwc09JqYAv5cmGTH4ogL4zI9Uj5+qzXQcDYYzjaNuErEpEVB5e1QIlZJrPQv+6DDUQDR1ZePzJB+uLLuJm4jjNXNgCUwYy6F3M1UTq7VHo5tz4aelz0jURkkpjNHgqBu/kYO5DVtGI9fPYQpUM0FIH6Eg20WKuvUfNfN5tikKdnCsiuIwr6mnesuSeXanvIW/5Q5lADMsjG9K6pX9hxhZ2w3aY/7FWIA== 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=F9IZfEyBQCwgkwo/M4BbnAkmAZEiFI9s+L3lKQBGnkc=; b=POkRxRgJxuwTfBcFnSiQpELZvKdwmeXlF7utDUpXj2Nx1XZc96K1sw5fADuYOJ4W2Mp3hbVXySiGc1q6p4OKLDythMD1NQKmqV5slcMWZPVMzZnQe7OWQlGLzOSttjrMBvS3QTyB9kER9wViJl4RO4R3/rTAwGsaNVBXIRynAIXsEeB+25f9M+enEf+fMq+0KWRJKlY+SftmTnMQkqBZEUMyeKHlBs+fKP/CF2Wr+KuDfOl+4tl738dKjPp3U2CSMoVivG4b1Y4CmwUhvoeGqBanzQBaBJkhbzQpMKz2Kgbzt/VAJ/5Don6WxMmqkaxgEa7vQGm766PR/U8kYghI1g== 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 MWHPR11CA0021.namprd11.prod.outlook.com (2603:10b6:301:1::31) by MN2PR12MB4360.namprd12.prod.outlook.com (2603:10b6:208:266::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::72) by MWHPR11CA0021.outlook.office365.com (2603:10b6:301:1::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81904+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:55 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:48 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 16/32] OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM Date: Wed, 13 Oct 2021 11:56:57 -0500 Message-ID: <20211013165713.727815-17-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4749808-33ce-43a3-01de-08d98e6a9a7b X-MS-TrafficTypeDiagnostic: MN2PR12MB4360: 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: rhhqg5lr1jUhVFGKgcMD6OY5p4TKqdZM41pdizo3BEHFbFGLVIpHP4Juzfn9DR2D5PDLO0cavkkf5UxZkgTVUnS8Pc2dMW0TEBYzsrqrFXVcpqKgOsZDnAruRMLXZZ4GTxcxEQkZvCsuoQU++YzHt0E4odWVHtjhpOAaRpUc/x0f09LXjcK7agRuTGV/2+dLK8eQ0TLkLi6baSG9c8MNzy3+vxtBXj+6O4XzxSzJQ1FfNjSqHP2VRURoKA+NSkxWJyZEyCGfJndDDdGSyyoKz+hrt131EFP7jNAg4PEZkH5bUKbS7PjEwRWJM7e6EJfhyK7fEE7+P3iGtY1/pPQtUr7v3eNiecWzc09a9CBntxd/YHpoAj3Unb93I5/iM/H5FKHKDl+hY7B6YD6slaCi1Y8r4pBeMArDogdMrAzjwMTPx4he/cjb8yyH/iS02TsBrRGFkFJchXsOLdMKjoJV2dS15KDMcCIbmqf8w9ZvUI00iQ0fh8Cr4MST22QAl8mn/uf9O1G6Lj45yt4QBTFX1gsN1RDo1TS2+oqUcu48OUbWdyrA8u3TedpiTg6P9yIDtoEg5GQk9J/+p+7wyNxZbMu1aC1v4/Hrn3gUtzsT53vJav13a3oBY+xNukyc0+mJYhUDQ5zBt8XZ2VsIGHNVg+q2uspgrN+7QQ4YsmA0ZmmCQNXaa+EuGY9u9EtwKL9NAzXyFpFv72K7io+igvsApJN/QZu7+4lPcwhsAWGO5PglWgaFcu7ciroCHEk0u3R0idHLMySWTWcY1tdB+JTS1WU7cvvDtjLFuhB1qmuiCtF7Yhr4fKw41AhOn5JHkVFNpjdmg2lDuoKhvdVT34bGbdzGntQAfu8HYpOZdeMd7bE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:55.7608 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4749808-33ce-43a3-01de-08d98e6a9a7b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4360 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: a7HZ5NTehJlLUmwDQySKmvf8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144279; bh=HcPUJr9yl8mvM2X7NWhmr8tGjyYE0mCz55Amu7xPvfQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wejOau9eeNHwtyojjnbmLGPCIVCuEwTV7PyfVDxXhjDZm83OlZjbi8GimmMQ8OkwepG 65naBVzSF9dRqrEKXoANejhNv3182czEIUT1XY1Tu10Unx/ipOoieM5C5mlY0LvX6L013 wh9TU+Yen9Dhcp51fs2aQ/qFyo78j3mhRkI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144280954100001 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- .../PeiMemEncryptSevLib.inf | 2 + .../X64/PeiSnpSystemRamValidate.c | 66 ++++++++++++++++++- 2 files changed, 67 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 64aab7f45b6d..cea7ecf96563 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -14,6 +14,45 @@ =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 +67,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 (#81904): https://edk2.groups.io/g/devel/message/81904 Mute This Topic: https://groups.io/mt/86292902/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 Tue May 14 12:14:04 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+81907+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144281103357.09832789049494; Wed, 13 Oct 2021 09:58:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mZbtYY1788612xuye2ZxAEol; Wed, 13 Oct 2021 09:58:00 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.72]) by mx.groups.io with SMTP id smtpd.web10.102.1634144279454396258 for ; Wed, 13 Oct 2021 09:57:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eF4OjRFQWtQmA5hpBh0nYqeRkoIb0TGZTMVj4cWzDFcu02ilsTSD27nnx1sdI14CLdSUyxYryjqN+kvH1uGsaBDYTMo+8D6laDUqDJxz6DOk7kU4cbF6FpaOq//3qb0qgLJivrwD+a9WpKWgaxXcgT/wAx1fByEfxuwmtG/6rpxwEl1WfEeOgn63t+yyR3m5qyiRWFJduBzWKTiBCxzSxbRDjCNMW3y27mUYtwvU03GFCjIUUzlBKhlBE6wE7ZAl/OjXL3or/EvDy+T5w0jXAvOmklzBG3Gb0V/KY5pO2pwcyCp/USj7/3C4DXcg1U3gx7DT642kq/cjynIocdJ1uA== 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=F5VYxOo04iydTB8RsH7/6cXOR7WmWK+EWRolXsAYUn8=; b=gZniG+aFiFPMxxTXDaORO4KFaP5RZdZB2esGskfw6P+CsW7boZuzwdWCQxqcUgKaf9Up9WuTA05+kiYOyXtJIg0FJ+agTYycMOIMHPO9O5i9GgxHxuqeVLkQ8C0kMmGh4nvDEPWsQpTXOOARtKDyl5Aa7AAzeOh8EChDdLNfUC0ME0e/HRtZTUCGVCQe9un3FTePCH2kImWhOh+rz1e6qykjIdvpjNQnxLYmTozNe7p9eSvdy0ZDiDXsmvxXRy9AlfhoYv9f7gSTWNBlJhZp1JgHadOj3YXUPKHOg8c4gsF5jZoztqeDsIaN07LFZOyGNSK6xPUU1qB+dD7QwNBwBg== 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 MW4PR04CA0046.namprd04.prod.outlook.com (2603:10b6:303:6a::21) by SN1PR12MB2558.namprd12.prod.outlook.com (2603:10b6:802:2b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::92) by MW4PR04CA0046.outlook.office365.com (2603:10b6:303:6a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81907+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:49 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 17/32] OvmfPkg/MemEncryptSevLib: add support to validate > 4GB memory in PEI phase Date: Wed, 13 Oct 2021 11:56:58 -0500 Message-ID: <20211013165713.727815-18-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 785be223-f9e1-45fd-424e-08d98e6a9aa9 X-MS-TrafficTypeDiagnostic: SN1PR12MB2558: 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: mLTaZX9TUKc9wHUJKMxjBG/W1zQ6LvHwBMq4I/snR2BcD+Mur3pMTMMFi1IHT7K/FtcqBPWYDcvxzIzrMaU6zR4l5l2VMGih38dJu+FEBcd2LHv3nXj22xdGU0YNO0koNdVzHLtBM+7COfYEH4PxsvRBEqf1BmxvzOY196GtNz1KuOoz6690Fgw/FB9MgaOfggP612UTSVfaREIQwR1Bwau8YLTvl2uk9sxSqfovYdR1uk0RceZrfCqLgERvwI3s7qbyhcM0r+rwUzR62srAivaArliL5j8OUdA6cNIorOFAenZIaswhhsoC2B56lONnlU4HyQS8zMHUMQal+ZQg05mvK0ri+9iu22eQ3SvdMA/ZAned/PbnDsLARJqokTR/N6F84VfA3iDNvUih+YgMUz/bYClfovtkoRpdvpGqj+T+OUldRitHEEh2KXf/do+fmg0uSEkA0r+29MypuiOl1g3BR9yaF0qf1iXtZOt3xvChMNTxEbbp09tR8Y7fVMCrzA/idIuDC4OW5WpXwKcLBtHB6/9lMadjyQOj+hNgPcFfoWHFuFQCTZPeK4zlzIwbEv2uQlqpdij9tG5KoPZ7dN8apNnRU4fPoNCz4mLbzQRAG3eDbkuipl0oRKufJWieDsMI4LWvT+dc8StvxTk858Ge5Bp/drALpMnvEzuFREwihQJpqaNbWFxtXQedXCFjDlVUsYMlo7Rj3i9TIVtH/AI7T4Vo3R65tpAnLb8y7ycaReCFAOmd92bSH5kUQ0+i4cBp2PPFkEpkIbfymhqmwggIQWmWveFmw+bM0PfCbCLlrphi1xjcqXHrPC7Os3Hf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.0568 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 785be223-f9e1-45fd-424e-08d98e6a9aa9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2558 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: ZShqrVuPq5d7Qz0le0NTO8NSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144280; bh=61+dP3oGXobY5xGZbp04LGSyVzE/sfO/oU0a+QWKiAU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=m+LSabAAnX22IkGRJrUYQiFdTZL40JBc1484Z1l+RJUpDAegIj4ugQ6/yfz0zdMHQFE JnF1P+FJCGnzKGgVch59e/Dx/XicgAZH7zw1IBGmkTGKk0QNO1OZLRpul34h7mAh42PVh WGI7I24zLa+ltFXyZ7JlahmqmG/gqoDPTSI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144283071100015 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 Signed-off-by: Brijesh Singh --- .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 19 +++ .../X64/PeiDxeVirtualMemory.c | 115 ++++++++++++++++++ .../X64/PeiSnpSystemRamValidate.c | 22 ++++ 3 files changed, 156 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h index 21bbbd1c4f9c..aefef68c30c0 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h @@ -143,4 +143,23 @@ InternalMemEncryptSevClearMmioPageEncMask ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length ); + +/** + Create 1GB identity mapping for the specified virtual address range. + + @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 c696745f9d26..f146f6d61cc5 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -536,6 +536,121 @@ 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.PageTableBaseAddres= s << + 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 | AddressE= ncMask; + } + + 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; +} =20 /** This function either sets or clears memory encryption bit for the memory diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index cea7ecf96563..ee8b5bc8011f 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; @@ -69,6 +72,7 @@ MemEncryptSevSnpPreValidateSystemRam ( { PHYSICAL_ADDRESS EndAddress; SNP_PRE_VALIDATED_RANGE OverlapRange; + EFI_STATUS Status; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; @@ -76,6 +80,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 (#81907): https://edk2.groups.io/g/devel/message/81907 Mute This Topic: https://groups.io/mt/86292905/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 Tue May 14 12:14:04 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+81908+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414428152279.79473156475126; Wed, 13 Oct 2021 09:58:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jJ4bYY1788612xeuXZqYnjq2; Wed, 13 Oct 2021 09:58:01 -0700 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.50]) by mx.groups.io with SMTP id smtpd.web09.110.1634144279532200176 for ; Wed, 13 Oct 2021 09:57:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jj9S/vO0bNmeuztSQkPs0Hg//3/ePjqlpBlK4ejQmt5ayqN9lMVimye437pIu5xx7JC0Zvs9vOKkrlOLl/KQGCA5XeJFP47GDmKCxnlvmknJsCAkkCmC5ZHm4FCS1ZVtQhNtJzglsX6D4Esbbx17+LGLCVo6curROSnvG6Yh+x+IVAQUo+r2Pan0D2CEldx60CAtDDpbu0kkQF+fwtjEzPRg2c7skj33vdfvR8k2EL23Zogl5HxrnbSeeD9n066dcSIAtqaiapVb8HgSW4PyPsIhMna9fwfJHRbVjFSpGWmMthawTmr5UGx9Pf1t8A3q4hgONcfKRRnNCG/BwiKYrA== 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=RP4fBNEeLUJCKypoj4yBqCyXa6qpKs7oV4HX+1zYZ/k=; b=a6M0o27fIaPWy+qYmT7A/sPI1RfM9t7paX0EkoflpPgXm0guuv6BdE1GMVRBjS21XEWDDCFg47Y38IFZkTEZqHvi8cRiwwU4zK/ZEHnYiyyz3aVz8GXzCCYt0ObThR+g3z+Y1ihpplcCbx6DIuEQuyMjcKYc8/ScYOMNdA1Khby03Ec7A0bU1gSLEPfWmrmprG8H+5aoLnc466qU3gMlWZC0L7Ns8DhGbOH8Kngwgyne192dg4C9kC/LAk5k3mDAP/N5VpQdnu1ySv8qNBLVNO6mG16CBHjZsEuHxJyjpdIWzhEk9FYdnZlNhsiAEO/LW+WoANsfWq/Ile/NwmODow== 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 MWHPR15CA0056.namprd15.prod.outlook.com (2603:10b6:301:4c::18) by CY4PR1201MB2468.namprd12.prod.outlook.com (2603:10b6:903:d7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from CO1NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::77) by MWHPR15CA0056.outlook.office365.com (2603:10b6:301:4c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81908+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:50 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 18/32] OvmfPkg/SecMain: validate the memory used for decompressing Fv Date: Wed, 13 Oct 2021 11:56:59 -0500 Message-ID: <20211013165713.727815-19-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a1f180ef-e19c-4132-a74b-08d98e6a9aca X-MS-TrafficTypeDiagnostic: CY4PR1201MB2468: 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: FjcNuxjeqIX+9G4DtntSWzM1bf62wyxfs7XQDa8ZyPGWFUJKISZe5eWlfI0t35plMwZwDCztVHnEcZiXQOqZv2SGttLo/fleT/hg9Kw0xCxn7Haf4ndfvCztMxe35ZfFq/w3+nkxGZv9MstyRnQlMUBBSe42U/Tgwd7XVFBVmqJSO3K5N1IOCmxxXC789mUZ3qzZT6rQ2FKbuHXcKEUnOt54N7VWT9FpeeYVnDPjcmYulb7r9VmB79bQI6xt09LoW2CyTYW0YWBNit9IMFzAZDPSqws01Dx5fJ4v4v5vi3WuarHdsYEiVgfnbvgUD6g598HwIYY1LEu3OfYNBiPnOsNWwRTh9/pWGqFpbwWQKivPs43PycyG2jZOJw29LmDs8B0RYY9kTzaJlEJCbCcacprHRDzfAvz8NJic0FoTSWhFPsF8z4gxyAwO44mrCHzDeYu1fMLjEYYww9Ccr0+LBW1m0XfyhpBJSLfO1epSq9onq2gOWr0k91aLJyRxEzcdQolX99aIBY8caK88Y4YYpOhK013L2ecdTxSFiu1SO94vvHl9FlSOawTREwfapFaWMez2eTs2MbebYdOSjEyV0TGH3UBKTC8StKbu5kI8yt1LA8Cf7yoYRrMie6OrrqLO3CEi17xFB2OH1AlwTv69gcNatnx4Ht2ljOsoTUfXieziB1FsIytwPxp5L7cmVbf1QbQz6gtHlk/9MCF/nNTOgGVMpsPEQEdQxlyJAMms297fIREFyFbi3tESRKyT8aS9KDXdUjlgB6/Al5zVPW+DsJf8q54a+g5sbjcQ91EfgqhWjDoHZOMSNaMZUjuTXdbs X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.2776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1f180ef-e19c-4132-a74b-08d98e6a9aca X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB2468 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: Fvaldw2DZz4JptuBy1qGIGI7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144281; bh=6RexbSYFz3qVAu1VJ9ud1QJsgreuGLmh1EwMWzD0xDk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=AnDR1RLCk+pRVioMB1MXzR4yv2atl0ubHRGu76OdSsXrGv700DqSJMlinojvzsHE+CZ dt5V/IEg0VtEUN5EXg5MvP08AehyQ7YKVJcgDtmM7xONPFPcugFhRHkM+RwXHzOgtobvl bv+K5GNdoVyc6e1g483pqzCCcfynrxSJUfY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144283077100016 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 ef0f319938b9..8dde5198c7cd 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -354,6 +354,10 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|0|UINT32|0x54 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize|0|UINT32|0x55 =20 + ## The range of memory that is validated by the SEC phase. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedStart|0|UINT32|0x56 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecValidatedEnd|0|UINT32|0x57 + [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 9523a8ea6c8f..282e60a2764f 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -51,6 +51,7 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + MemEncryptSevLib CpuExceptionHandlerLib =20 [Ppis] @@ -73,6 +74,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 adad96d23189..411bbedae4cf 100644 --- a/OvmfPkg/Sec/AmdSev.h +++ b/OvmfPkg/Sec/AmdSev.h @@ -69,4 +69,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 ee8b5bc8011f..d3ed8edecb03 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 9dd42b195785..aef27d9727b2 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 @@ -277,3 +276,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) PcdGet32 (PcdOvmfSecValidatedStart); + End =3D (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdOvmfSecValidatedEnd); + + MemEncryptSevSnpPreValidateSystemRam (Start, EFI_SIZE_TO_PAGES (End - = Start)); + } +} diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 406e3a25d0cd..b173ff976073 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -847,6 +847,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 (#81908): https://edk2.groups.io/g/devel/message/81908 Mute This Topic: https://groups.io/mt/86292906/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 Tue May 14 12:14:04 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+81909+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144282994839.2907585362218; Wed, 13 Oct 2021 09:58:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id F3mNYY1788612xdTR6NLEH5l; Wed, 13 Oct 2021 09:58:02 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.49]) by mx.groups.io with SMTP id smtpd.web08.116.1634144279775917405 for ; Wed, 13 Oct 2021 09:58:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=emjEUcP1g9Rizh/C0Omq2/haEUE7QbtuBvMX8EoC21MpZRYUlcVmwqhpLZVr4Y7cd6Xnf1RMtYFfCM9VIt1UHNWaCoFBLY/xvMzp7hYmp7GhaMXP1/Vlql5XBBjjXU9pCVxFFkTKVZ2YqNai7vBV+nXTtfEh4DAQ09MPZPIL8Z1urPG/P3bviksP2ujB01T7koAXrZpr7qn1Rf/OjYlZsb3dbZlVtV6gcLi+3SLvOo9hCfu5n2NsPf45+l5u6PI9y68fd1SxQapYL8mlgLIDLy6thjak9IPdrHqOj/9DP25wW9mxWyhXyjO2TyOoPifQZaYV0q0q9v127Py9gxFThw== 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=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=n+AbagRybidcIWKsBxM2vyJiNXgDuQV/NCze0KZzhGVACFbpc+9xaHVAB9x52VYpp08CPkF6MyyKW2FQ5DFBtUuIZFN/ZPj/ucIoU6nw/HsVoWgjiCD/9wvPhEYV2ZdY+Iz6d/uXeMd36zVTJ5MENAXZIcYHAI9RGGk5LubcyFT1RZJJDs5i77W/GzxMO8SxRIYXjwKzL7h0aWhIRgELeugO8eic6gEL1c8ztuk2nHp0zJyts7nAKD0kYcZkWZFWYOPNxSIGTFcYAOU7YeQZOReqW47obzdU2yuMIcWkFgYCl0r2sc3LH5yTzc55x98hWx0gp7ncA7ECF+NruHR+TA== 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 MWHPR11CA0013.namprd11.prod.outlook.com (2603:10b6:301:1::23) by MWHPR12MB1472.namprd12.prod.outlook.com (2603:10b6:301:11::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::4b) by MWHPR11CA0013.outlook.office365.com (2603:10b6:301:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81909+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:50 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 13 Oct 2021 11:57:00 -0500 Message-ID: <20211013165713.727815-20-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7319f39-ed91-4e09-388d-08d98e6a9ae7 X-MS-TrafficTypeDiagnostic: MWHPR12MB1472: 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: qbltPvTJ7+/UWyOJCF7XCLocLfkrZTNWwzRFllzv5l/9miPsT7T+7AM/AMckk7rN5cCWLKDx4LXtYOkJH9RkOB+4MknriMBWq5Y/dONY+JjCZYZkqH+BslO8ZLwRTvq5+NW9AHIYsff6VXfEArqzsxr01bAJJE2wjKwH3qspb7gZFXRA04oQ3cnIaF7ef8xE31GHVoSzasDLZGKXK/QXX3ufvKxx/8BNANdlcCe6LOhWwVJBV9yRfBOZJSJhAaoQ2pklENa0f6gYVgFjfG40J7zPpWzsDGFHmRHNkCVdVRZO7k2gCVGbR9WU7LBu1JyEHsiZKFXqSxg1t34V6mykvS0PcVy0oXHCqG3InKH622jjaiyF4vxrmUYeLDWYWcVlsYeT8gEPQHvLZgArqbnKZ4jRjJaqLqintmnd3oAA4nSdvQtGHdWhp/b2xvKesvCGSL9UZjlMAbfOp5oWa4xCzKBd0ws+jbYaUv0wcPm+iR2J3rxdIccTCGVcg9OGYfZHGVOQNQKb+5R0hYiF1g9pt459X3vreLIQQ2uwOBGyclVHsqjpZPheyP9cDp4gmnxLtvOLBvH/HNDLPkUKwfic8qczCb3EHxyeJKPhfB47zPltAU3+sFeB37q0reJGiBTcR2J1at419WOR3HxCB02gocKLlhNsoXtAaTtEAvh9VUv8FwTxrcZc14rNd3dmWbC0uF3ZWZuRCryrejAZkhyY9Il/UAgjVkPiupWVTSDFa2lFss9RNili0/OzaYPPFgN0fiIXMGs/Y77q8n4m4VorGvnULL382tbnivcHsOHzIYyFzOMydyYvkgr7+pzw0iwZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.4700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7319f39-ed91-4e09-388d-08d98e6a9ae7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1472 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: tKIT14GoNwV2OrMex16FA7Lfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144282; bh=3H/p40XkY+cnoBrAwp/PolJbLFcYvV4ZOW6MXaw3aNo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PZV7FRI5GNqxB9abyfp74Kg2vRGQiSr5B6gIt8RzvI9zAuk6yk1df77Wuttp61v+j9A oN+uf0YiexeYzfUk7E32CMjBp+HcgPvY9MeAUNZ4PBQ8p7EdfM23GsVEarSRPyNt+ZMaa /+1PBCSDwjlkVJjPqXUAUlOXgIgTdp3Dex0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144283263100021 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/AmdSev.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index de876fdb478e..391e7bbb7dbd 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_RESOUR= CE_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 @@ -240,6 +274,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 (#81909): https://edk2.groups.io/g/devel/message/81909 Mute This Topic: https://groups.io/mt/86292907/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 Tue May 14 12:14:04 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+81906+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414428136457.129488963130825; Wed, 13 Oct 2021 09:58:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5aRNYY1788612x7XjByimRIX; Wed, 13 Oct 2021 09:58:00 -0700 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.66]) by mx.groups.io with SMTP id smtpd.web12.120.1634144279536449003 for ; Wed, 13 Oct 2021 09:57:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CSW/xihWwiZIhA+CWGH+5UnaTuDeUYHw3x+vdJkl/d0PSYLdJT5hBAWl3wbzetqMCDY89Nkbnev8L8fmaOehmMGRN2I0hB9Q/GM81KRUtXP0e9CWCIdkmM7yh/BPy7IwuvQOCUXf4xbPRa18Thhth+w9r/zCgs1s97GUebd+INxVTOU3RqVhRVzZoLZJNWjsdl7S+CM47l2S7dFOuaTPwaCEHaeckJEGtX3Fu/TqwSlP9fdTBDv8l6qqKN/54HwQB77+EkRVH/ZaGkTTj0+SRvk+U3L4ultjrHtY9ETpo3c2p6byLC0N0CZTFdbiyrmwk/tld3uI8XQi2ZwB4qP59w== 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=uaB8yNVdEURv+odmUtP8yoqvcpQEvjjyIo1HTDmu2Xw=; b=QaF53vCZS0WC8THGI08Z3q2bCVJilz/5q4OvGo9fihKQBnLlPyte9V8gUBWDy/R3ga83sUGmxAioiUZql1JkKw5lrs5bCw+05I1Gxlw4acwaYnIIEvRKWR0OR4GB4yvGZlHkchYVU3dw+Edzq3jboLDMg0PSGnwPlMtsBHxz35xS7XeLX+GqJbxbeinKngd/0LPqzlf/66vlYt7VYgFY6TCQQZCwNU69P14TlXosf45higFJT6Tow8BweNP7RPEjm5nzGc5AG/SVtzNYw2OQ0LAxCcAzAwFGJMkD3PfcjTQy4LDn+w3uIBd4aGqXEQ/iXTFhVVG15cV+lv0Ga/vSvA== 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 MW4PR04CA0046.namprd04.prod.outlook.com (2603:10b6:303:6a::21) by DM6PR12MB3195.namprd12.prod.outlook.com (2603:10b6:5:183::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.18; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::1f) by MW4PR04CA0046.outlook.office365.com (2603:10b6:303:6a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81906+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:51 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Ray Ni , Rahul Kumar , Eric Dong Subject: [edk2-devel] [PATCH v9 20/32] UefiCpuPkg: Define ConfidentialComputingGuestAttr Date: Wed, 13 Oct 2021 11:57:01 -0500 Message-ID: <20211013165713.727815-21-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d16544a0-ec47-4e17-019f-08d98e6a9b14 X-MS-TrafficTypeDiagnostic: DM6PR12MB3195: 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: STKtxGhTArg1Z/x9HQLBc2apGpab3ah/h8ndRGdxWAhxgfCZr3gzna7PgDKZ39rd3hbf+ky22XK2HyMTK9pfvV5DUnkTaf0S4VwenbClfWGX3hv3gNE1LBwtlQ2VvHLPfq8kB6NE7Cx4mNYehh7pz4ko0FhAE+GEy6rKTHnmHtDqxl7DODGWCxd2ypUF7ar6ioooElNEoPNNTSCI2kpdmSktPtUp5Bx2H8bo+wH/9tGJYU/s8QqIGVh1ZBtVr1rj5v63ylF0Q9R97ShePFf5oAxMTWEzqXPTIB7MySicJNkeh5piG6Zgb+nusdI+bFCIaU75hzV5PsudqqjCoBReoSbPgqunsBjF6Vx78pzIMTHl6w4kSWdQ4kQfNM1LtSm6JbUIhCZ4up5IHw7TOOT0eqQn/y/EpP9lKNEpRoegW8n6ABOiF1YqFKFq6MAv3JhOKkYcHyMNqZVLunstzfjY9qrTEARtkfkmfXgzyalcyo3WhLUvziZyG0zgy09wKG/kereVyQEc14zDe5UqAwZC+g5Fl+eqTXaiPMKGqw9+dK63dbwJRumNV9/mBy3FluasvF43SPnIDzfNdMTLfsmeh7AeVOMRjroiwk9B0CuhrmRlMM/+tazFIyw5ok/LfAp0AwPUF7RbeIO2ihDbSESD61S4wTYuGr2JokiibePMhXJLTzzBtArqwTSG0nkHIbNuN5x8SLGppmd+xBXLT6+tnQpDtWZMp/ZE4vYZpxj18phOrjX9JS6NBxAWOATR3bmy/4V7EKt1EbXnZhgkUqScHXwWJu6agV0+LxclqyCtEo/xMPt9TkoFVo/9G98kpbIV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.7583 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d16544a0-ec47-4e17-019f-08d98e6a9b14 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3195 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: Pf1a9Hz5I5s5rJnsgtDIoC1Xx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144280; bh=U+60JmyAOKdqRVA1y7cCeNBVmGImehZULzqGwpCiOuA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=U/NkFK4tkFjL/hK26HhDVi4ZwkkXzXhnNVpdUP2pHqvWqj19KP17ZGkFzmnyoICn9q6 67/5h57P2syDMO0IT8/zU3TBN3PiOqGCYfjnERdte2pmjzUxwlHAiGu6UNvLms4ItaAeP UKKQbW9FZNlzdaoCAfpN7Hp1xRdXo1vtz/M= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144283049100014 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 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 Suggested-by: Jiewen Yao Signed-off-by: Brijesh Singh --- UefiCpuPkg/UefiCpuPkg.dec | 4 +++ .../Include/ConfidentialComputingGuestAttr.h | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 UefiCpuPkg/Include/ConfidentialComputingGuestAttr.h diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 62acb291f309..9dbaa407c399 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -396,5 +396,9 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt SEV-ES Status gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x60000016 =20 + ## This dynamic PCD indicates the memory encryption attribute of the gue= st. + # @Prompt Memory encryption attribute + gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0|UINT64|0x6= 0000017 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni diff --git a/UefiCpuPkg/Include/ConfidentialComputingGuestAttr.h b/UefiCpuP= kg/Include/ConfidentialComputingGuestAttr.h new file mode 100644 index 000000000000..495b0df0ac33 --- /dev/null +++ b/UefiCpuPkg/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 (#81906): https://edk2.groups.io/g/devel/message/81906 Mute This Topic: https://groups.io/mt/86292904/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 Tue May 14 12:14:04 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+81905+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144280359504.0970197684969; Wed, 13 Oct 2021 09:58:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lq59YY1788612xqKPQsJ0N22; Wed, 13 Oct 2021 09:58:00 -0700 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.55]) by mx.groups.io with SMTP id smtpd.web12.119.1634144279408499919 for ; Wed, 13 Oct 2021 09:57:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fKNOVnMhakDR8odvwOt3IAfQqK5UfWTl4POYjLzkmRt0/MTduQBSh/nf3R4ikmfkwv/bRYjZWbWVVDK+C5HEj0/qoa68J/s+D07u0skJpuGBE2uXHcS1nfHwwpdC+LiMqVh4jxDFeVAoO3oygVmzR1X5fp6v41iQe/dSvvRlkJrzs4jMC3AVxZSpD3ZySiNu/pXhd/wIa2pmziwBc+N7jSayBsufOvxwUfBUfJSaCoShNjPEx3iYerlDdmaip1O0iGmKw0h9bd0n05HFNjqePMS1m9BtwEHZY1Hy/RjfOTgBHcLkC4ZznTu/PtR55l2/Zw4GmuZqtAp8vVihxTFfWg== 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=wOJEl/2BnNTzs6M6n1+jEHciKBiEz+XWQjIAGNFslTk=; b=gUogGw95Cnzx9Ry29LwAc10CoNPL08kJksIgh8QJ+GF0eb5WhgKEw2uY0O3Nvj0q1FJ4KLCmQehXzT8nbPUtwVGw9Ul5beqTrIPDBIe+5OCpoPqbIfR2lv52rJZpP73tQQJCxocJ8jvmB9VZYKeOTrntYZQi/7ZAbOqzLjpq4AUhm2KcnF5WkcfjVNL1pEUqbQr962FgO/RmuNYbKZfSwkHh9mIgWGKukoZaEur+m4ahxhNcUWx3fQ+NImVFDT5KDedqkFz3mAgftyUO/PHj8hM7/VuH7LlhwDzNnbgQKlDDj2c3T+MXsyFimfh8pi4YKXVdTG8PhTsijvw2zBF7TA== 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 MWHPR11CA0012.namprd11.prod.outlook.com (2603:10b6:301:1::22) by BN9PR12MB5177.namprd12.prod.outlook.com (2603:10b6:408:11a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::86) by MWHPR11CA0012.outlook.office365.com (2603:10b6:301:1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81905+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:52 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Ray Ni , Rahul Kumar , Eric Dong Subject: [edk2-devel] [PATCH v9 21/32] OvmfPkg/PlatformPei: set PcdConfidentialComputingAttr when SEV is active Date: Wed, 13 Oct 2021 11:57:02 -0500 Message-ID: <20211013165713.727815-22-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c55ebf0a-2bbb-4612-9cd5-08d98e6a9b32 X-MS-TrafficTypeDiagnostic: BN9PR12MB5177: 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: 1d9Ecnird5BrhYIlmQSoHW0H82P/vUaW/khIjLR6JyC2Zf+2TQfLNZlGndHHPSZ075f3MEIUdhHfLoNyS2LqNeqooq6NDHKb2N0F0g264yBJSIw8g04E+tyqR8ZR3dEKa0q7wVigb73krn+jTSmHuD/i32OUT/nbhjY4gQeJVzmBhGDQliHzK8LEYoA/oNWef7hKUqyFyhOw14MFpL60SMBixm2KM0t0RJRUTmHxOf7UAx9mv8mm/sCSPDnpbDgFmSNP1/d8CWM6Ax8Bs71wEc/imqnMPfzLa0ali04uCVTbjOp5zI+JMzSdGoOhw6RQcN+TRXeMykLr/g5V0jNCu7mKjkbOJEUksT0y5m3+EXRU11elQkff3lwAbrisBJq3Vq+40TwP7dLmk8GnTeP4QvagpNughxnxu15Lg4zUWmfK5loABQyATjddRRNTIHnZyFcd8NXpx6gR9jZfxX+l8ruS1Lg23tqb37LyCEnXg4+E3gwpAKGXGQS3tFnwlhO87UTNfW8E0j+A5QWdu0OwL9OLqe8kzRbLqVBQ+6XkrvZlLS2v0Jdv85A4SLLYAesxoPQmAGdEpvkRoSvS81G7AoOjFcA028THOyo8SfOMpCHXLBnNLowFX9nKBl/A/X0c753QkK/r7wUs9NfAeWZWRjXzrPf5Mz4bRDmzsnTW0/eirX8UHl3SZ2SfammrUai65OlZE7d0QPLUIyb8vAch+tzhYb+Jgn28lWxuArc7MrihL97kg1PQgmq96S3X1ZL+Xs7GEsJcuo/rPSouHT6aWSg/Ky38/lmPrCtQcuIewcunhtog3571SQGRyQPUCnew X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.9631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c55ebf0a-2bbb-4612-9cd5-08d98e6a9b32 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5177 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: TBu6m2QgaSelyJeyuR0r0VXix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144280; bh=KcXJmO88zrAS2t3T0J2hIPUrmyYd6vi1WCMC7qq0nUA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=RuOjMi1jZuwi0r8HEC2CcxD7hxP65F/Sl+mkvMUQng7eR0/aUtCGVnFlkQWsbbz+oFD pGJ+4JvnHxFdUUcnG36Gy0or+84kX0mHJFo7KgmvnjmvhzztVhUiVpmUsjj26GxpPYrzP N0N2xD0SY+cD5O3W/X3nqgykNDE6Xo9ZlA4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144281029100006 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 Suggested-by: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 67eb7aa7166b..233b9494f64b 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -106,6 +106,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled + gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 391e7bbb7dbd..5e2c891309d4 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 #include "Platform.h" =20 @@ -342,4 +343,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 (#81905): https://edk2.groups.io/g/devel/message/81905 Mute This Topic: https://groups.io/mt/86292903/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 Tue May 14 12:14:04 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+81910+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144283409163.48935658999608; Wed, 13 Oct 2021 09:58:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hIBSYY1788612x8SLMmzvsyL; Wed, 13 Oct 2021 09:58:03 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.45]) by mx.groups.io with SMTP id smtpd.web12.121.1634144280373423647 for ; Wed, 13 Oct 2021 09:58:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XKzdURLgyUKD+sSpCQg4IohFzPM85sQcU6Oo8l+yexLmWb4c5ZuZ7Cgwduk8UnIinOJPfUhGI1ytXodGGsshIleMxtg748Dyi2YYSZIRtQ7zKp4fH5Cy6A/i/ZHgEWeyZ0ScrY+fU7GbuxemjppBPnZcQD/lPLIKISpdxSUeTNijzNjsuBXHIcgJfGyC6sCABcwhYUZqGry+WY/xNZuzeoAPtwoZnHNPIMbE1R5u9Tq8csjAPdX8xbGKK/zo08CWDGRjTm04G8b1HrcWRNRgvgL3XfEOtG4mCthFcdhDHvBkgNU19/3Y2VioqWqZtf2/SDYcjZB6AZEqv9vAZPk1LA== 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=R30K3WwP7vSaKdEkB5HJepUhyo17FpVQOgylv6ZlCmI=; b=dkbjNePEMxD5NlRqIWwLIPowzz7k0iA8fXbwRjpoT4O0mVeGrQvEDrlJhgIa16NiWwApdFfC8yF/hu9EEzkIBpxI3mBUEKzinID5GkroUPdYFyI5SlSqE8dOxJ+feHRbrQbU863kagd7nYH5/b5L//PJHoGkiVgQ/0wkrOZ3vA/hH9L4wnw+kPDOGN6lbT+1thSKjdeWRs4iHc+XtqbLGCV+9dXdKXb+Fxi+6hJlkGectT44z71G6OCSoX8Hy7KbHKZBxj/F/YVo8IRQlJboUQsr5iHvd6wJC2Zwc/zL8xrsYMEtbOQleDPF0a7pE7xe7qX1/T+M88XahKfiPZt5Yg== 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 MWHPR15CA0062.namprd15.prod.outlook.com (2603:10b6:301:4c::24) by BL1PR12MB5192.namprd12.prod.outlook.com (2603:10b6:208:311::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from CO1NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::b5) by MWHPR15CA0062.outlook.office365.com (2603:10b6:301:4c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81910+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:53 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Ray Ni , Rahul Kumar , Eric Dong Subject: [edk2-devel] [PATCH v9 22/32] UefiCpuPkg/MpInitLib: use PcdConfidentialComputingAttr to check SEV status Date: Wed, 13 Oct 2021 11:57:03 -0500 Message-ID: <20211013165713.727815-23-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e25f7148-63a0-46c6-c054-08d98e6a9b5c X-MS-TrafficTypeDiagnostic: BL1PR12MB5192: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1468; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: HYAn21iTgY4S561UVPx6TngWA8YPQJkZI9+m1YvzNA6txj3ItiWWXZqnBmk2io22yAnSrcBuj7sExGljhDlZc4LJtKyv6cOKWQDFi0skpAGKoAl0fTJDQeG9UyC6cekdKBIkmEVRiOES+vFPJj+w2g1keQazlEJVzgJOQhfIplMF8o6pH/UHfZ7RHbPp+V9+HhO99xwSxuL4YrOrODmwrDi1m86OYOEYjdGBtwpcodDyy/G0c6erP9gEr1lsMy8YdMl0VGOfNeQAlzuwjPT9A8D7K14pWalpoVt3A7knlCUjI1HyT+Y9N0D0Bw8Vk5gcnhoLufeK6UYbmagRNUtsnMepK8q1YP3noxPGeJmr3JInFjsdIPgZN0GtXMfM2G5cdMQkxeno6RfX07sboa1mF0/WYu2CCOXg1f6kwh1hRb8XRPvedP9pYMTj9STvdIcYKfgkQlv8l1mEMVRpwvTnn73rkrIz/D4fVXcFvx40+jEyfsajfnMKIqwTy2wgAx9Lu+yAmCXikprar2Lj0L0TpKf47r4yhxMkWJHXYhCmyigFNAQcOu7ga9pZ6EAtDdbWSeFeI+VslR2awrZp+BX2W+DnE/m1OHhY3hN7a7gaJt65SopFxJuTUG767deHqnH5IcSK72JL6W59DWbyT93/cpQBW5+Ofsj2+jPtkNtSDBhf9XI8qnCSY8uOLo6qeCWLMiieJq/ywRJX+51re7ky5wA/ugimuKodre2rN8UScc/EyZ64L/MUgWgdumjX365bxEoWYRKq0jpfuZSPZp7kDk3dSzO/75IIGjhmeQWgu7APrHI0pvqUlomJMCrkndq7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:57.2351 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e25f7148-63a0-46c6-c054-08d98e6a9b5c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5192 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: dN6bo77YhREzPAqE0K7xea5Sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144283; bh=XeRj5dQNn/PXnwzXE6L0iQAaZ995GJ3RrkksmcWGpfk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=mJmu4cjtKpz+ad2YMjFst/ACMkNfwLmRAxZfuTvRVMygfZamx+/qD74pgHp24wzt2e7 RRpd9jEDnS0p0HynabRXSoDdQbyW8ZOsA1jDlK0pbtXGt2Kq8ZG4JY13Lmci+BMrXYiEF Z4GqnJOpAKN1IEC/PYnkr0VHac+orOoAZ10= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285324100029 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 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 | 60 ++++++++++++++++++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 4 +- 6 files changed, 77 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 6e510aa89120..28764418d7c1 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 + gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 2cbd9b8b8acc..cbc3c1460423 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 + gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 3d4446df8ce6..2107f3f705a2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -33,6 +33,7 @@ #include #include #include +#include =20 #include #include @@ -774,5 +775,17 @@ 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 =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 93fc63bf93e3..657a73dca05e 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 // @@ -124,7 +124,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 890945bc5994..16a1602c3079 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 @@ -1046,7 +1046,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. @@ -1816,7 +1816,7 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *) (CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); 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 @@ -2706,3 +2706,57 @@ MpInitLibStartupAllCPUs ( NULL ); } + +/** + The function check if the specified Attr is set in the CurrentAttr. + + @retval TRUE The specified Attr is set. + @retval FALSE The specified Attr is not set. +**/ +STATIC +BOOLEAN +AmdMemEncryptionAttrCheck ( + UINT64 CurrentAttr, + CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr + ) +{ + switch (Attr) { + case CCAttrAmdSev: + return CurrentAttr >=3D CCAttrAmdSev; + case CCAttrAmdSevEs: + return CurrentAttr >=3D CCAttrAmdSevEs; + case CCAttrAmdSevSnp: + return CurrentAttr =3D=3D CCAttrAmdSevSnp; + default: + return FALSE; + } +} + +/** + 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 + ) +{ + UINT64 CurrentAttr; + + // + // Get the current CC attribute. + // + CurrentAttr =3D PcdGet64 (PcdConfidentialComputingGuestAttr); + + // + // If attr is for the AMD group then call AMD specific checks. + // + if (((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 90015c650c68..2f333a00460a 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -222,7 +222,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) { // // SEV-ES Wakeup buffer should be under 1MB and under any previo= us one @@ -253,7 +253,7 @@ GetWakeupBuffer ( DEBUG ((DEBUG_INFO, "WakeupBufferStart =3D %x, WakeupBufferSize = =3D %x\n", WakeupBufferStart, 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 (#81910): https://edk2.groups.io/g/devel/message/81910 Mute This Topic: https://groups.io/mt/86292908/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 Tue May 14 12:14:04 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+81916+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163414428592095.73276374182683; Wed, 13 Oct 2021 09:58:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7oQRYY1788612x6KkjeHaxxt; Wed, 13 Oct 2021 09:58:05 -0700 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.web09.115.1634144284321982374 for ; Wed, 13 Oct 2021 09:58:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PWkxoY8led0/QGe1iIhuRAExEj7kQO6uJPm9fous5IxGj+eNv+zrLOKnoAXiM19796bcuLwvmwZaEiGEEqYmvRwLPBhs+EZr6SVpRFmaElhIt9VkMRoAIFiDFLmNvULnj7CuzCdHI8cynuo+h4IPB0NnwGdPA0Zj0qJ3S2LV5wW/0kTLtbypZx0a+t51KsXdHoWXhjdPKnU8+A/anuqlMNgsOgIvt6skG0u0s6I7ZQMdGRQRPnjJJ/RNIdGeMfzBKAb5O6kuLKu6KwPmBAxUQbWE0mUD/JAsBjW/lNuSxZUSrmchVaSTG3c+K+OjwpmFnpII9IZkAz9NBWs1yV/yEw== 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=HY44Sh9NMsohzjDLbHm4LvZ8epz9mviz2PuMSBm0Vzc=; b=hx844gWMIDvcsWwxWjDfWVkrTaLm4RNHQwhcs7budbOLoWj86aXVIxRnZ4QfcurvUD/TAHWivdweGwbStII2PGrr383jBCCqGvJDAzUr1Dkyg74+L4GriKJYz31NfJ5GeIhAUMqtnrOXl6kNSPXuntg4ld6vaoOt4L2MQqjoBXWHKg8iMp5IZDuFwjnfXDBzvLlNJcrcpc8iFwn4mxKo/XLNDQxYpRdgO//2bBm3I8u9pk/vjO3ui8WrmbDDl8QD7GWUX3T6UiE2fW5Ex9BRngJdTcm7kGQSg1Z1UoUPa+9E7rgCSQkqw87EvknHakYPejmWB/Nif92vRRHtGiNX1A== 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 MW4PR04CA0031.namprd04.prod.outlook.com (2603:10b6:303:6a::6) by BYAPR12MB2663.namprd12.prod.outlook.com (2603:10b6:a03:72::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::e5) by MW4PR04CA0031.outlook.office365.com (2603:10b6:303:6a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81916+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:54 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Ray Ni , Rahul Kumar , Eric Dong Subject: [edk2-devel] [PATCH v9 23/32] UefiCpuPkg: add PcdGhcbHypervisorFeatures Date: Wed, 13 Oct 2021 11:57:04 -0500 Message-ID: <20211013165713.727815-24-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ae9e16b2-8ae2-4a79-8896-08d98e6a9b7d X-MS-TrafficTypeDiagnostic: BYAPR12MB2663: 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: 7uK+OqZx0bNNtEQjJL8oTH/DCVPgTKg2B2bWKarphm03DxA4+JCeze/Tixf4hkkczJIYlVkU6T2hAKRzi1EKHHZNgvuee0/vanx0Xm+UVCLk2PG1o+0vsauGPy9jEXzsBBueqYGqGEolQKVszZXUJPJozuJS5BiWbhmRQNrBzjacEmlNUGuIDQc+k4bYZhtUIkqV8YI7q91q6oTDssAkAogzhvhOfsuKIx6SCDWVamyn+SCXoUxC0VRav6VzUvBfO+aKl+GrsxCubiskUdKQ3bX+wedNNHWaPJzKXlf946whEpjGeTBHpPC5DGSl4z02FaF3EKzu3hpqE4iPKBlRO5zjvo8hkVY1Y4eyjRzqs0eEuObFQKs2gRmZYSyKAnIvr38I7C8Ae4/o0WPNwp1PqoVs8m+71rDQTKPbLdx7l0M/luetMhmRoO6gDXADbv2fraH5ZK/BN0kqyO91EAt/XgTrxkQz9h8TIEwKCReMrcSgJP2DTkvHCl0FlD1DKbgxURfGUZYAX1Yn0bu1wh8GTSsaSXur51HEQsmrJPz6JEBjiUWVTiSCNRN39fGnIcxwXVwcorrOiW/L6Oi3ctRHb+2bMeOy02ZO14lviWMuig3JzrtbbdLLoraTDL5JyeNHZD24J72i++mmGl3fbUflhgQut1PBNsNGSi6UTUOSQSFV835tZCw7ddjQXx4quMoRimI7TjnhO/W2TisxaPd1iCM5+XkKPmfqoslof6CkWtUXj7FZiZ3XU3RFom6vxcI4WLl1NkGHti/lfX3LG0UKjATZ76gH2f09t08S03UIuczjjZn11PDyfTvS4G9k5YmIygyZxlxPZN8szXZ8H/yQTVlxVKfULA8lVuJ9hnvCaUc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:57.4509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae9e16b2-8ae2-4a79-8896-08d98e6a9b7d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2663 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: WlvbpkJAq41Y0btIU1OMwXjHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144285; bh=KpF1D4FkBGafHScZU4Z8mluL4C/GwrE7dd15uQESvPQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=F0Cc7CqPL4lwnTFENvPbBdZISPjdfiH9nSjzO4w61xoWaV2F9xE7WQpQOnMXSYXUXw6 FicLP2tKWwKlyx2JZIeVsK+/F5p/Ks/lAHqbhnz4squUE5eZgxivNDbJXhSsPIOQDadri AZwuiGzmCGyDZCxnEoe+MWpYMRkXQfrgEUs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144287641100051 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- UefiCpuPkg/UefiCpuPkg.dec | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 9dbaa407c399..c979a0a90a0e 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -400,5 +400,10 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt Memory encryption attribute gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr|0|UINT64|0x6= 0000017 =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 (#81916): https://edk2.groups.io/g/devel/message/81916 Mute This Topic: https://groups.io/mt/86292916/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 Tue May 14 12:14:04 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+81918+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144287842343.50321269233075; Wed, 13 Oct 2021 09:58:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XjQSYY1788612xi9Vkog4Ska; Wed, 13 Oct 2021 09:58:07 -0700 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (NAM02-SN1-obe.outbound.protection.outlook.com [40.107.96.83]) by mx.groups.io with SMTP id smtpd.web09.116.1634144286915542979 for ; Wed, 13 Oct 2021 09:58:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ST34NBeWsho7MLpQX/KK+tVrxduufcPvma2LqfO51cem7fdIS/zVdwGiZvQ1/ajfVCItOcKfg0KtKo5EFEgvfIQWk6vLU2tINKAOoBKfYFeUNxgBkuZz3CYQpDvVYUPBukzJnh5gsOMWCeGLwNd8kPtnGkVv9e5tFVfZnjAEv36EoJ2IsAmq3hvGBCbsoA+0f44DyuQkAFfle6OQvY8IpxmUW/TVq0HuNi61OMm2Ho9jGlUqaV09JHafLjOnaVyZUjJxqLRNRl2SWK3EOsuJgRUCnG57XDgPOPZmWnGcOZIXvpK8CNspR7cSJp6UHo7N1ygBqx088cPB4d7kkONV9g== 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=/hdsez3xb2KZTWgM42sW8N43QppxNiNrNubCQQZPUkY=; b=L6igpHMAcYQjMBJUnUHUeNFoxkYlXFObVg6APWiGE4n/GWpohClqc/L5q6phfp2fm2B2f1yjTD5IMFfSGEmDYLa2UO76qZMwN9CZ1dYNcj8hqM6j3L9mN3+rxIW+0AW8W0MzRML8eKLml/SxmghSnJ0adKkrEd/F2PXsLc94OHrBtHT4lDprb8Lv8ghQ9VeIaK7z/rtcP33fxFkeR7sjEuWPJNZC5K/xtJQjKnG6haYhP5U8VOVyCF8+7RJCU0+VFJAllB1PRQcn3/IsGvzN9XmkiIvsTKdHrxnAYZjl0yJlPUf0rUXcoMTx/O7VzFTAuZD1+FocefQk+CKmHHdxlw== 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 MWHPR11CA0008.namprd11.prod.outlook.com (2603:10b6:301:1::18) by DM6PR12MB3244.namprd12.prod.outlook.com (2603:10b6:5:18c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 16:57:58 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1::4) by MWHPR11CA0008.outlook.office365.com (2603:10b6:301:1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81918+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:57 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:55 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Wed, 13 Oct 2021 11:57:05 -0500 Message-ID: <20211013165713.727815-25-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89c3b21c-4a43-4aeb-6fd4-08d98e6a9b9f X-MS-TrafficTypeDiagnostic: DM6PR12MB3244: 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: 6hnlnJxtak4lmxhTUijLw+0F96G+L3j665Dl3/xEKva4ShswZIyrV2DdMSU+f04dtEypmdUslV1VPCvtFweMGc5K4ZSFwD8LQMk8w8niEzsvQEB5sOKWBxOnESuya6IleXuvm5F99O+z+/5t3p24lgwkqljuy9WXPRtZcLoR89Akmf0jKbugkJaqshjFuwtnxStH30sqajBBGOG+3j/mhBkt2UyB8rWpgbGOlxRg0Jt5QFEfQ2NThFmBLfRrYSNLhoG6txjUxC9U3MyYMI56tlBKPwhRnTd9gRb8hkNyQjh0zwvpyIGGqjQxHwlN9f+eU/dZuajFBcanmGizU6RrwpSHCqQ0PTrB/whJWT7/3UGHpOq00Z81KvywwqCb+aHu8gxOriLxxRqvfK9iB0X/AMxQbBdREpzUk7/pMoA40q0SOoFCAif1LRGDmRctCIrTt3+/J+d63Up5pWue3RgnE2lTpuDso1lq9XvhbLf+n0HQIJF9UotZaSGxSUX2HkA6qPxBNyKCxp3H8FIkVXO/hwd3F/opa6z3t2pdw3hdElK8OMqdvCl/+M7NLbUBO5C7I0xuAMwX+HfeibltNAxn0pvEejGv4+vVBCMmdQOUV7V6CFL+AQZAgknPbc69tYsQQ4edHQzFpMEd/09TPpozVfDj1tBzUwDPRUORh8IWe2BVyBHVYxTDJO0WjV6nD2uYZdJn2drszgq4X5wNQt3JSs6o8++5XH9jzOlkwzm1bY+UhnkfgKOS0gtLadkTBHHumqgA51UtXKIC/Q1BE39qZeQ8nUdc5sDCdW9eEEE9CuUwxRA20SudPmN4TbSci7Iz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:57.6768 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89c3b21c-4a43-4aeb-6fd4-08d98e6a9b9f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3244 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: 6X6Plm2mfqqShovzVQG1btT9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144287; bh=SUiv/2CKPJPDOERLDEHCorVJoIWKwJy/fGE+yoR6br0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ex2reGDVoDRaDI6d4UquPkJ+BgCh+erlYvwmypwYQYUBObXkWJXF9+qq47YY6DsTSEI YbfVyV9G6cLFl9VzmrnRoS2LpgV63KKfne/TBQMHa1HYUrj3wGXYp3umzY6GSCJt1pQmQ kdFSDMMBMplf882nSLrGLTNRod5g9aYSCuo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144289750100062 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/PlatformPei.inf | 3 ++ OvmfPkg/PlatformPei/AmdSev.c | 56 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 233b9494f64b..d048b692f155 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,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures + =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 5e2c891309d4..b71a4a7304f7 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,22 @@ 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 +108,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 (#81918): https://edk2.groups.io/g/devel/message/81918 Mute This Topic: https://groups.io/mt/86292919/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 Tue May 14 12:14:04 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+81911+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144283808136.7783977684885; Wed, 13 Oct 2021 09:58:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EZh9YY1788612xMePf5CtnMV; Wed, 13 Oct 2021 09:58:03 -0700 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.60]) by mx.groups.io with SMTP id smtpd.web09.112.1634144280965731920 for ; Wed, 13 Oct 2021 09:58:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lko8U7OZqf/+EEeNPx8D3fpStOSEkZslEMBmpIfhwaGuBEt2q9+tTInLxSANFaPX/7fS3KlUatW2dwNRmZbaBu3OFKd8BCRJ5dqwbGz//O9dLYoMrKhb7wBZF8oXCB0QosSXE+9cw51zqSBg6vHwtmghZhwx6M2Og+sPRIdjgs3TCoZ0BTr9mUOcezwlsGc1zMvP3VsS8sB1pNuE1nZp/JjUrQ4P8Lth7u9eDOUJI7n4cvPJ5nxWZ7TpfZhnCuP6Zb8e1g9/k1MxpaBlgjsB3jxvUZMyyyIzqaPP+R84OvTR1bx5qcmAbw2msLqWZ/2HXi1C7kH8+RTCnHkgEK21/A== 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=1au4NymybOUCLZOK1Z4OBZTvFY9RoRXGV4jdXfDTEm8=; b=V5dc+ni3V8Xagb8QjQpDvQfXod4m5cagSf85lZsE1Jvx/l8AzfX4/8OrWNBxCUXJqrNv887Seq8ebG5OmDWmDJ5MReZ7odBoSq9d2jjsYs2Xgg3t5V0Scoe3uFAiSxMGRzEMD7HTp/9lNQOzPuHmsfkkDleZzHCiIWyRGsNzYELhdhC8Rd+G77O8JCeSDbFBnEydL7QCwb55DnVf+eIk3fbmBnBCFXM015y3LMY1XK7OK1nlxD3bLQ1Xo7BjDpaMmYiuXA14JD6z08eZQw8LhKIgJ5JQHCfLi71p3QVqZtImTkM9EfSYZlhfDCaGklJVT2J/iFz5wTv/DaQALCfInw== 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 MWHPR15CA0059.namprd15.prod.outlook.com (2603:10b6:301:4c::21) by MN2PR12MB4144.namprd12.prod.outlook.com (2603:10b6:208:15f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:59 +0000 X-Received: from CO1NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4c:cafe::7d) by MWHPR15CA0059.outlook.office365.com (2603:10b6:301:4c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81911+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:58 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:55 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Ray Ni , Rahul Kumar , Eric Dong , Jiewen Yao Subject: [edk2-devel] [PATCH v9 25/32] MdePkg/GHCB: increase the GHCB protocol max version Date: Wed, 13 Oct 2021 11:57:06 -0500 Message-ID: <20211013165713.727815-26-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6f5e4c3-301f-45fa-fe02-08d98e6a9c12 X-MS-TrafficTypeDiagnostic: MN2PR12MB4144: 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: gP/S1cj1cFxpvQgECMQzKThmqioHnablJrKK3Vc4JJbZQKVl15Bz5nDHRmyQj5e0paRX2LdOFevoAVZqQBVSmYWvfhmCa7yhLJbbGBwhUqp0EZxq1nbvQJOwGuVngABgOXkdGS9dNOlm+rqE3IDwz0PX4FVwPl8oO5FXIGW4q6t71DetFTwYFkSHCHvQcgAXo7tGq6b96shiGY7PM4VLFS8MO5eomm7sQhTpnwTffYccph8AW5C00zyD5oViXKwdG00Jp2iuXZfopV8u2vsxPueaT9YvNu8PUVrVuB36aRcZvyjR0UxuUH1NlzsWjn2e5Nf2HnrFV8JjjdvdIVTKes7jdYP+6HzUaM6YVkUsa4tLFUDSkO4N9sU59LbYzoHWTwHufB7X0gaWIBqat02SmecEWOwVpmtl/CiPi/fK3Pk3ee+HMKT2Pt36HqaNPLEdgKx/S+LFbMaPTUkv55ZrdMekHY1PYW5GfMsa19tBcEpj+5dRv3UdouTybJ1x9Be6EoNUh/Z8La9H+9NB8gKKHSgqPMkQpXttOKktshcCYxGsUhs5Dd9dL+IO+aqx8NcUvEiUjc3eihq5jvMIiRTGdC8jXd9oxdtdY0GvyAyxPQxTo8jyL3eg7KVBtP7/x/BsMfH5+27bPWucnne/WHCXeWCepaM40YVwUb55Ra5H+j+G3cIjo2Y7lD7v6320As+zihblKXunH2ZqDFfsjikztlWxSAVvhJF0CNSk8KLv2qYdtibcGEqIJQPaXtwJybPaEDpeP+8iLPa+PbvUOQmblMsAq5/TcKSEhJHtjBYUlys2P5M90UQp9IajkRPZi05B X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:58.2425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6f5e4c3-301f-45fa-fe02-08d98e6a9c12 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4144 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: 3bfglO0swvbC0IhIhRcfwAcYx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144283; bh=mjBTCP5IMM5RL4b7Up84je/J6/xCE/WcDzmVazoJ328=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=sBJYK1gs2eKQ/j/yVAAYYanbeX1kzhnQtWECDft71jJ2NMXVIyOQ4uH++K0QryrLh/c gds7CqUO4WrifDJimZVAkjzoqyX2lOytmtgbfwOcEpDnTts+qM+uk4vtdrnvgx3roSJuC +ikAOFRLcu9t4PL2J4NcmwZds50bSgh/EGA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285333100030 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: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 8c5f46e4bb53..071aae0c9e09 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 (#81911): https://edk2.groups.io/g/devel/message/81911 Mute This Topic: https://groups.io/mt/86292909/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 Tue May 14 12:14:04 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+81912+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144284234820.2168024471068; Wed, 13 Oct 2021 09:58:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rEvzYY1788612x6Co8x7xdOw; Wed, 13 Oct 2021 09:58:03 -0700 X-Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.84]) by mx.groups.io with SMTP id smtpd.web12.122.1634144281095518604 for ; Wed, 13 Oct 2021 09:58:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMH6Tc36SoUuDhFgoSJjVDxR2wY2ZZOZGXtusrJKXRTPHBrxWJcSSD+D7GpetdMvrg19/V1jsXqe1bhh9QnJJI6XBVjMNbd5YM3QjFGuu4e+jSN8fNKz6LwW3UYZSwiUYyDajalK4/6iZuOGxCUXOUSIOjSRYHIETf5Kj6qEldMbHhjSSsnDrKI83FTYhFuT6n/MxAu/rrCll2OKNaF8xDz4vpHugTgmaoqOW1CJUHz0Xlo8GrxrWER2d3oorlxF/1T0IiPPWizKzctxhw8XFaj/5OACWi8iGdcIzhRwggL3WgSoODtMAujfWzlFgQUMRwcVjVKr0PyOF8jMXX4UCg== 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=cpFCAz15mEjohd6b0FdFfRDt0LrXz8RKF8IQ3GDbCRo=; b=GzAFqjmKV7J5dMDrxDVrWQaYLWQ7l9emI/iOq4KojIezPlsIDeW+pErZ/lHG6ypZ7FOKF1hgOpgIDQm2r2SmDbM0l7jx4hPNlMWchyOO2mi3ySptchgdbaC1m6mvAGvCrjatRMHk/UsFcdjKe8zaROXfVB9OjfIdA1S/e8AsjDyl72X1qV5TlSE4bdpUSPQ+UTpkXdeWML0mPtfJCXm19xltyZO0ogEf0qhKDURGBE8tbLh+4NbchEd/MEozihDQliDQA4zlmLb6TFrIokg6Tx9wQ3RoXTk/S1NTi5S/uWl/gkJ7j9Ufn4h4QmNrAKZVnvW+hlngQXDoS7oxm9kBbA== 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 MWHPR11CA0016.namprd11.prod.outlook.com (2603:10b6:301:1::26) by MN2PR12MB4142.namprd12.prod.outlook.com (2603:10b6:208:1dd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:57:58 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::56) by MWHPR11CA0016.outlook.office365.com (2603:10b6:301:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:57:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81912+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:58 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:56 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Eric Dong , Ray Ni , Rahul Kumar Subject: [edk2-devel] [PATCH v9 26/32] UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled Date: Wed, 13 Oct 2021 11:57:07 -0500 Message-ID: <20211013165713.727815-27-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 46519f29-34d6-41a2-7e33-08d98e6a9c13 X-MS-TrafficTypeDiagnostic: MN2PR12MB4142: 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: BSo8vRP/ixWmaroBpM33GLGof+WuiXVgV+qU4WQfr6tVGkp/3kHmQyzTg2VQ3X5hW5/I0KVXs6ydFa5f5CqpTwXW3FgjwlJjkxG/offeoPsmi+ZLhoSK9xANqk+vZUq7xlGfkcDnmJJE2nEhrw83FFyiZtGcN3pmHG3T/2i0JxTRuXPPt8IScZV9NivLCJqkjl8tpZXleR1TyVyN/UuPkK3ghzEpzF/cReHZ2lwjLMrfAs6V/ApUrdbDjOtadbJH7fg1TQ/KaJcNlPtGPCX0bf698kP6iy6dfxEpEHmXQdAPV8sxcOlltJISdYz9ie06wbheT4N2ZVurQPEet/8iN0g2DVxkqxGxf9SggCyvwtZywI3I/pRtmGck7lgilh90Y6R7DNoZLO0D9jX9LXhzrvXVjAVnNeoXnbJRezdv8AHu8EtopUd9Uo/LRFWxgWFA0wphrDbQSDc69pBWoRjBbkvHa9WYbkx1NgehQmt+y/oGltlmTbEhUFPpcIOi0u54NTs+KqBY5mFbButlMHI19WuRgf8nGS19OpY+G8I76mY14U9ofYtUsadlfFLzRl595FqVTj04Sz0kX6GBo+x04xgaY3Q6VT2DqY/LuJKUIjeLuTovsG2riyq3ANzL5+RoIPAWtBjl2DHhkc3ME1KB4yiRlqGzIvXDtTRu5N+7LNHPwl133PwLUw0UDWSVKt/yVtg2MNW8GSY6FbOn0w1S3PvaygZ8VmqOSbZUiaDmBZQlw7CrtH+jjypRF+fDDc/7YM5WIF7TjXG5Jf/4ghD4tnlSdzd1hPu7GiwaM5pO3KuKGRiYhS1faphwNCOSLEOJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:58.3056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46519f29-34d6-41a2-7e33-08d98e6a9c13 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4142 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: K5Jk8RESPAV2T34Jx5KttPG4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144283; bh=6EMIGSLwPITBO04/la4wl/jkcYwN4AYQOKS/Ehv1kLQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=v7t3ZvvmQU2/wssgaAZ1bbhpfCZj+Lf18IcxKtpADxrBSQH9I4gt7p6TfkM96oXu8oy /oHgB/iTgiYjKP8ujy1X6774sum83YoM0sdfBZ+ymJndKYzk+WXl0K0QGiu4Twx0moXbQ VaoeuduPDmlh0Hk1aetCtahzwygi2uldCeg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285394100034 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 + UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 54 ++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 2107f3f705a2..45bc1de23e3c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -222,6 +222,7 @@ typedef struct { // BOOLEAN Enable5LevelPaging; BOOLEAN SevEsIsEnabled; + BOOLEAN SevSnpIsEnabled; UINTN GhcbBase; } MP_CPU_EXCHANGE_INFO; =20 @@ -291,6 +292,7 @@ struct _CPU_MP_DATA { BOOLEAN WakeUpByInitSipiSipi; =20 BOOLEAN SevEsIsEnabled; + BOOLEAN SevSnpIsEnabled; UINTN SevEsAPBuffer; UINTN SevEsAPResetStackStart; CPU_MP_DATA *NewCpuMpData; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 16a1602c3079..4dae0974c06a 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -889,6 +889,7 @@ FillExchangeInfoData ( DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->SevSnpIsEnabled =3D CpuMpData->SevSnpIsEnabled; ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; =20 // @@ -1817,6 +1818,7 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); CpuMpData->SevEsIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdSe= vEs); + CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evSnp); CpuMpData->SevEsAPBuffer =3D (UINTN) -1; CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index 2e9368a374a4..01668638f245 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -92,6 +92,7 @@ struc MP_CPU_EXCHANGE_INFO .ModeHighSegment: CTYPE_UINT16 1 .Enable5LevelPaging: CTYPE_BOOLEAN 1 .SevEsIsEnabled: CTYPE_BOOLEAN 1 + .SevSnpIsEnabled CTYPE_BOOLEAN 1 .GhcbBase: CTYPE_UINTN 1 endstruc =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Libr= ary/MpInitLib/X64/AmdSev.nasm index 0ccafe25eca4..0034920b2f6b 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -15,6 +15,57 @@ =20 %define SIZE_4KB 0x1000 =20 +RegisterGhcbGpa: + ; + ; Register GHCB GPA when SEV-SNP is enabled + ; + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)] + cmp byte [edi], 1 ; SevSnpIsEnabled + jne RegisterGhcbGpaDone + + ; Save the rdi and rsi to used for later comparison + push rdi + push rsi + mov edi, eax + mov esi, edx + or eax, 18 ; Ghcb registration request + wrmsr + rep vmmcall + rdmsr + mov r12, rax + and r12, 0fffh + cmp r12, 19 ; Ghcb registration response + jne GhcbGpaRegisterFailure + + ; Verify that GPA is not changed + and eax, 0fffff000h + cmp edi, eax + jne GhcbGpaRegisterFailure + cmp esi, edx + jne GhcbGpaRegisterFailure + pop rsi + pop rdi + jmp RegisterGhcbGpaDone + + ; + ; Request the guest termination + ; +GhcbGpaRegisterFailure: + xor edx, edx + mov eax, 256 ; GHCB terminate + wrmsr + rep vmmcall + + ; We should not return from the above terminate request, but if we do + ; then enter into the hlt loop. +DoHltLoop: + cli + hlt + jmp DoHltLoop + +RegisterGhcbGpaDone: + OneTimeCallRet RegisterGhcbGpa + ; ; The function checks whether SEV-ES is enabled, if enabled ; then setup the GHCB page. @@ -39,6 +90,9 @@ SevEsSetupGhcb: mov rdx, rax shr rdx, 32 mov rcx, 0xc0010130 + + OneTimeCall RegisterGhcbGpa + wrmsr =20 SevEsSetupGhcbExit: --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81912): https://edk2.groups.io/g/devel/message/81912 Mute This Topic: https://groups.io/mt/86292911/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 Tue May 14 12:14:04 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+81913+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144284688705.1435929347125; Wed, 13 Oct 2021 09:58:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dkHhYY1788612xzqLeT2JV9O; Wed, 13 Oct 2021 09:58:04 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.89]) by mx.groups.io with SMTP id smtpd.web08.118.1634144282091649328 for ; Wed, 13 Oct 2021 09:58:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aqoZIGEXtHo6iL5MxIuZ63V5jkUNww5vtyOoQOAVXTb9eK2Ay7lV53qny5ckSdJFwNIrSIixb8S5yoCN/4vYSWGLTz/psEcDBuj1AD6+zg30kQYvhTiSRlxZgBP3YZCdLJgQWcvvBMiDdX7EDS7qwf2g6fR+f+vvQxjeBf3q0SOoKYqj/xvYl/5moTw9OeCesCpaamSroJ121r7V/GaVMu0MYM8rYRtKAaLHXlsRqee8JDyrbYbdvOEGclW9jkcypACfiDxjTXogaXlLjJS/NDwCBp6qzkUqrpA6xUazWsCAV7IqVdYdIBWtbZkrCBeIbVvul7NHlDTde8CtqjLs6w== 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=ELE+Y9hGR88CemRHD9XNPq4tcJgxHGapp/oOW/8dFL0=; b=j/kdQ7aEzOSQOR4gAusEmGlCghx6OO7Z3/df9AYINOqt6/W3T/1dq4YpSFrHukqsr0cCOfxpygwAqN+ZVU2JDS/3l9AHbE3kOnT4TYCi9xQMuoKB13CpKCKXBLYY/bat9QfJr/HJ4z7NTiHQfh9V8czMgKtR+zw7Pbk6KbYtlh43dmoF3trFWA8M5pi7S7Cw/SE68dbxduaoGu/98mvsua1RcwEoj0nCu266oMwAFPw+sOvZQqBxHbepr307dNNYhSB+Ig0W0igZaZuAZmqKfHusOHv09MTR3By3bd1TWXxhkKJMpNq9U/arxgWqUT+ffMMn5SRiP9zY/LRh9jZgxQ== 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 MWHPR11CA0004.namprd11.prod.outlook.com (2603:10b6:301:1::14) by BL0PR12MB4721.namprd12.prod.outlook.com (2603:10b6:208:8e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Wed, 13 Oct 2021 16:57:59 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::10) by MWHPR11CA0004.outlook.office365.com (2603:10b6:301:1::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81913+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:59 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:57 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Michael Roth , Eric Dong , Ray Ni , Rahul Kumar , Brijesh Singh Subject: [edk2-devel] [PATCH v9 27/32] UefiCpuPkg/MpInitLib: use BSP to do extended topology check Date: Wed, 13 Oct 2021 11:57:08 -0500 Message-ID: <20211013165713.727815-28-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bce7be4b-04bc-41ee-cc87-08d98e6a9c85 X-MS-TrafficTypeDiagnostic: BL0PR12MB4721: 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: aTYvkCInisRoIVFmVSYZAX4dTjTyxP4ubCghQX6DRndYbfQ4J0g80xI30ysQ4TADSxL0MJLIIx/nKfL2iN1r3JPvzQzu7y8lAdmB6hSfTEtXQlzS/D9t+vK6u9b0V+Onlsd8y+jShlhpXJw6RMVQru4jQPaIIG8qeBnFLG52QcJjf1A/AkKg4TTvH4hEparc2tyHavnHN/uoeuj+1jvSL5fx+kUxtijA1f8kE3+QFENnIhNvw+e9vpzFipkm4WYnaVP5R7fOje0A3trq9Ic3yeDbshb9ND3STcOYUfBHZHIGhfPkACdGkHst5R6TtUq659c0toiSROr9N0HdqFtInxwaYhbbXtVqHNrO2Fxnuv2X5gSNnDG+U+BDxYOR6QzQEEr/YjQ2E6WWXAl2zn3FawO8F2MTIFu2bEHVt7Xc9s8hfoieFzZqMSouTGrhSlQuGZ9bcyr7zQsEzwYzxiPA0x2KGFC3kt00zxtO70btFp5UCrRjLs9qnUwyoilqu1BABOFwVnzq97y2psKfopBdpikDhkifwXnODq2ehzVK8R1VhnJfkZ7jGnN4z+XMFytMPiohIcG06uW0Q6om11EHP3m+Na416EN5Tyd1F5sSPh6PF23JtNjgiQJ3UggtU7Jv1WogFOFezEe9HxCKmclIJd61NvS7wzEqQMqEZ5Xl9twNEJiJRE9rBuw+wsqPRh/a0ESMxi/OLWeYfJoSRVMM0p7W/vHXYWdxwzBZ3kR3pFVIa/tQBLbLKm0ZWCvGcB60IGrGbQpljbfbCgBSxtaCHQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:59.1865 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bce7be4b-04bc-41ee-cc87-08d98e6a9c85 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4721 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: q6u7eWPdxvhmUyq1zidPG1zPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144284; bh=GMIUxp7MXLijNNPlj0a6u6elTHhxu0OKuH7Xkxl3CNQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CeJ2kumnQmBauWg7U4tRG0fytVLiEb/UUTBSNj3dKJOXP24/5NsW6WvE6l2ynEhYFO+ S5mfF6KzAhxBgcnk/jJtFyJlhtWMRpiKh7ARYQo+82Tc6UDbEij/WIyGNWn6qSI2fA14Q 5m0nl8GMOxfU4L8mkae7DhnF8X81GIcriDM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285419100036 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 Suggested-by: Brijesh Singh Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 ++++++++ UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 27 ++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 45bc1de23e3c..c52b6157429b 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() diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 4dae0974c06a..de94b05e2263 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -853,6 +853,7 @@ FillExchangeInfoData ( UINTN Size; IA32_SEGMENT_DESCRIPTOR *Selector; IA32_CR4 Cr4; + UINT32 StdRangeMax; =20 ExchangeInfo =3D CpuMpData->MpCpuExchangeInfo; ExchangeInfo->StackStart =3D CpuMpData->Buffer; @@ -892,6 +893,16 @@ FillExchangeInfoData ( ExchangeInfo->SevSnpIsEnabled =3D CpuMpData->SevSnpIsEnabled; ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; =20 + if (ExchangeInfo->SevSnpIsEnabled) { + 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, N= ULL); + ExchangeInfo->ExtTopoAvail =3D !!ExtTopoEbx.Bits.LogicalProcessors; + } + } + // // 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 (#81913): https://edk2.groups.io/g/devel/message/81913 Mute This Topic: https://groups.io/mt/86292913/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 Tue May 14 12:14:04 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+81915+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144285091908.0658788184489; Wed, 13 Oct 2021 09:58:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hFBLYY1788612xuxvsvTCCMi; Wed, 13 Oct 2021 09:58:04 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.86]) by mx.groups.io with SMTP id smtpd.web10.105.1634144283064165063 for ; Wed, 13 Oct 2021 09:58:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gx2poHyidZWicU9QWUaXF791HkLsjncIeluZDTF50IClXI6ljrsHA/aq7HD2O45WcLrCSKbx1oSp72W3db5BZMSfzPbkVAwFkBtkLXZulqvvrP8YVO30GiJD2k6xxr6GHJ2pBHrvDV+KgDye5/BLek83g7CwJI1tc8oJYSUEnVd6uN3ndnkYsldJCyncIPSXH3lXlWbnABfHqiJZtZoYS3DsS0AaR96FJBZVZ905xMvsMjni/pjkWun/qooTi5gshTlM7Hr8wYbENUwaW4e3Ap3CfhHuTHUu9cFQQSmU0Xcc7GEMgwDkaMjpl4CuAlNU5Lbn7o75RLjiFvuc1h4aVg== 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=X6r0nD7n4uJBJCtDmtwm4mGO8ZKKhmFquzC2PjW0W9c=; b=FhoKuFAOp0p4E3spjRAofHK275uBauo+8uDRRck98XiYxnumFFMA2ndgNfaBPdyohvFFChoOgxZvna3QJ511GiKfBEwgyHFt6ydrPmUUylCqPR1UDNzavEz+cFRytuMYvJm+NOSRuu+ikG4i+ae3AvGRzvOSEC/7fLk9T4HK/ERu51Fm0996TlwmTghJPiAKRi87HNax5z7Sa6pVNOwRgPhjmB2NA42VbsLvq93SyVbQUsihc8vaAwiwH4Xgs7p9afjkTBB6da+NPoJUjGZqhQbEeWE+omHYAjwjWESJ5EOMqBB4zvyn19h2y/WwGbz4J5WP64Phyg6JGuaNk12rHA== 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 MWHPR11CA0022.namprd11.prod.outlook.com (2603:10b6:301:1::32) by DM6PR12MB3628.namprd12.prod.outlook.com (2603:10b6:5:3d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:58:00 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::78) by MWHPR11CA0022.outlook.office365.com (2603:10b6:301:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Wed, 13 Oct 2021 16:58:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81915+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:00 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:58 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Wed, 13 Oct 2021 11:57:09 -0500 Message-ID: <20211013165713.727815-29-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2206867b-3b6b-42a3-0c93-08d98e6a9d1c X-MS-TrafficTypeDiagnostic: DM6PR12MB3628: 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: b0oSaR4YaYDfln/I5DXxIacM8nPIYsGYWcAnw83FA3bhsh0bJoW5HlpvDK5GltXOGY77E6O0mFVmBiAB+2jdf4bXhtCs9PuIe9K0yokt9hf3LhcNgr/Bn9XwyYBEDeoeJAUvozfsEk/N/cDkJ4bohWX5aFM3GJoKzDVF17PRqv1Tc2vkY3kvH9FttCXwmcnNv3W1qpF90HND9W3HD6mn7AcG0UHk9TSwVEu81KrWoF0kw60TOGs5UoVIJeX/gF2bUSYRYdljoD+XHstAXutafWloSzhtj9l1OrUFXIF9DqVZtnI1afajRw/z8v5esvhPhnK9dWNNn4qG4Uh9qmGktTHuj38qIRz6GfMHFY6Z85DGN0pdwVMG2C3pj0F8r9oXobYVn5nTXbCaLFHmW7oE2FUub47Aa3xFWPNamj9m/OLaDFm5mKRfQXwm7/9+7/TedqeEainki7jjRt7braKMieFTl1gA7SeIa/3/VIDzYATDSXBD6f+tB2x0maD7Pah+cCoXGuH/68hMIFCGipHYZ5Z10W2H1L58shU/daQs65OvgMq1svc1bAqY81aj/cZizeA1vgPGIIjhpHyjQPaSPus0yLhBDpQ7l8+XKCv933+U8DbNK7EdIpht4c6I/NWKYvFkhrdQTBfOhO7b6WJva7xYzt5Wb13zHN1nne+BNxjaMpHeZGEedK+NHzpDEpJbOm9ZP13i83g4xnmkbxgFjHmE3q92ituGx05t1+S6My+qpMKw58ED8zKUpfBl6Y0bIHfh5X2LUhic6+HTEgA5tCJcZG3fjCUcXGldUqmw55MEqm9wCnJiiYjulPc0GEHo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:00.1727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2206867b-3b6b-42a3-0c93-08d98e6a9d1c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3628 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: OIVGeCVYRCdekIRnRd59krYex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144284; bh=iDfmDPKGpHkcirsfhMJ8uimpZbR4XGO6k3ElNEyJYSo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GrTdFB0w6+lqKW11BPiv7whCgjynk/UgaOKYUiPsmBSc36P+bjzDC5PXdtMfW9JEArT JCEJE3Un5egV5QCweYS119JfBNoVkpES+64SVynVBRzwofqGlpwH/CXy5hipsljmvLE18 xIhpmkPwEJKBui4vQvXkvpMlGKcMcM08pC4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285419100035 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- .../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 f146f6d61cc5..56db1e4b6ecf 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; @@ -695,10 +696,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 // @@ -751,6 +754,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) { // @@ -923,6 +942,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 (#81915): https://edk2.groups.io/g/devel/message/81915 Mute This Topic: https://groups.io/mt/86292915/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 Tue May 14 12:14:04 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+81917+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144286440820.8642582688998; Wed, 13 Oct 2021 09:58:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jGYQYY1788612xkoUdzbRP6w; Wed, 13 Oct 2021 09:58:06 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web12.125.1634144284823218618 for ; Wed, 13 Oct 2021 09:58:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B2lIjp2wGrDRktbmiK9iTXXjNSmfI/mdyqRtQn4qpTV+Ayzn1HzN+4UFDByuTzNvO6K9JLcxkR/1S9LRtJ+OjVl0cF+hyWzouSrNC4+Glkof2GKJLBcEgMg3sLs9Dup6A7tJWM1x6HD4pkJj2WjY5QNVPuYHQvXSQNama5Dq2msJpLnlZtWgqEZV2FpnkpOL6N50CmIUiny4cRWBuDugUSqxxj/nduRJdUZ+uxFiLcFvjtw4nV3ZANc43aKJQWxPf8QQxk/SJ7CBxjLeS1PlMfre0X9RL+0NYhZy1OZzEY4US7PBU1OmqE97wM1HUrmHyTgvZA4/N9bapxEbzL+9QA== 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=ssbYYDRnBzgPINFTwLfD1QN9nBJ41Imrw0w8gRmkrZE=; b=mpdQ09sCZcbVEF+6u6JI8M+2vRFBeIAHFxvZJHnw6OxzR35SgPac/3IHYhEyplJtBUlRNHDRtDRuR9MwedB5+F40qq4Ao/vedf0cYB8Bueq6D43IxF3AUwTMZbJRgEg1us1SIb2orvfFuRZvzJ8TOuvl5EwPCf9bzHzY5rVobIrZKMqF+IyBwNkMy9fM05bpuh7Gm29nLNC15xoucKhRH2CvxfHdUMeecXfeB4CnZ24qhfr/Mi1yezjZLAAcW21NN0+oSG2r9EMfpGB2DUOz9SNWp68CTTBCi1a6pbFtQpMcBtWWXQpl6iVTRPNngUuySPeI5FaSMUiiWCfpy/gH4w== 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 MWHPR11CA0011.namprd11.prod.outlook.com (2603:10b6:301:1::21) by BN6PR12MB1858.namprd12.prod.outlook.com (2603:10b6:404:fe::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:58:01 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::93) by MWHPR11CA0011.outlook.office365.com (2603:10b6:301:1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:58:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81917+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by 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.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:01 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:57:59 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Wed, 13 Oct 2021 11:57:10 -0500 Message-ID: <20211013165713.727815-30-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cc15ee2a-9af9-4be8-6f83-08d98e6a9dac X-MS-TrafficTypeDiagnostic: BN6PR12MB1858: 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: wCvfZE/I7dAQnly+PhoDGVrgVi5Jt5RIeMsJCDY1QQcQjbqG/wIH3GmI8f2a+xrW/FingypZcBuiloihsF2K950QEoTVlSst2xS811xJvex6f98bdCbKm+mt/sGtor15t4OK/VtHmEr9JmaQz8PWJ3Z1vlyhOH4bBtk0QDZC2gL1fxI45COeVvqe2m0AMNASNhtzNneYrT4uMQpdq1YJA9u4pjTEtut9JCp5rfjxrThFNyE/Xw9dp8i2ZPlvm2nmox1HbO5hwgPMeRDUyoS8WzUbqwSxxFqAUKEVrSLiabQ3kxxdwkbp6A0TMVX7RE8+DImGHpZjEl8NgbkU2cicJq74RNXTV29wQ2kuNcSl9cNsyBCwJLnyb+k7rldA5gB13c2EEtDBsw1hR2lfbRgNqhnTYsIZq6VDhIZEeJ1DX8t6plDX7aePjALmOefDd/K46D1/UXYH5nQ0oIWg0UfNDMLXEMwPoctVRWNpzW5LjRN8Mb9gNQdBS3hGkdbb3ZmOZwK6Q2/MIr1a/JHU6tHOUQokhcWucAw8fWs0Pt2wgCrDG8N55bksgUKyfK4WDWXLjnC8qEuZ/XghSWNOggjybKAxfNrRGJSYYtIcQLYVLtSARcnYkNLBgRyNIelA/fWi7QJUORieC21U8CBrE3NEUFUgNSnYELlo81R0/vLCe0vm/8nAwmNzKX8viCY/o1AxjFwGRaqtHpdREXR/9O9Tufgd/Qm9WEdO0uTbemPo5Oc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:01.1154 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc15ee2a-9af9-4be8-6f83-08d98e6a9dac X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1858 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: LFAymRfdLmXDg7Cp5idmT73Wx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144286; bh=K9TaZ2JpPEFIbL89KeTVqSOqF3Q4wwhWAaFjmCLggsk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=v+rGgsnUNPB3BYf9bMr6Wmag01yKLx2SqLZ2/tnRme9m5ES6bFMKWGXqCKuml25RVVR uEG8QB3QenAJM25743BaOt3ckt6e5XnvByQbtyKGsrli8WP3aDuajKHRc/nAIQwyLnZeG UJVPcAQohIm8hToXmhNym1xaeOOKUTB2lD4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144287643100053 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: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- .../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 56db1e4b6ecf..0bb86d768017 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -673,6 +673,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. @@ -688,7 +689,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; @@ -711,14 +713,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 // @@ -760,7 +763,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 @@ -998,7 +1001,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1031,7 +1035,8 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1064,6 +1069,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 (#81917): https://edk2.groups.io/g/devel/message/81917 Mute This Topic: https://groups.io/mt/86292918/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 Tue May 14 12:14:04 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+81919+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144290637457.5491006270855; Wed, 13 Oct 2021 09:58:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id E4GsYY1788612xfhyHpSyXGz; Wed, 13 Oct 2021 09:58:10 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.61]) by mx.groups.io with SMTP id smtpd.web11.119.1634144289452090389 for ; Wed, 13 Oct 2021 09:58:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiNOG3zyGT8bV0emfY3YluQnpTed3QAP2DnwD06+V/ERyJAuR5qVYEns66gN8pSBxU+iKyuBgdhsai9UqyrxDyzh9EVv7t+qMMTKSBsYfCvscAodS0bAS9anN3Q3RhbRES8cA6jdEbsXelqjKGF01DMe/01gzmTQzX0QIOMV0K0S0bfIHRKSCw4Dg5PpMBkX23wSoq68IBhWddAoEgmFg9HB2ztnKyO8255Pv4P1h+aL5WtzQ0wOqGtClgkh0bxzw2bu+4p6jeNFaUhZKdCSajeafW1qeI75iEGIifYQb452wetkbwedHZCtPRctsrkxt0cXZi/al1RCblmDmv/cUg== 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=JF/Fi5KmXmZrtStMBqHVQG/xTbyGCtKUx/JrTQUTJKU=; b=ngvsGhMC0Z4Kc/iZC95xkkKa3QNW8yj2P5bg4A7Jdzu4YNMT/FlAC7huXym3ZuSJqYihs7e4mrXquUOXF9hQWGzh4lFhOdCQeiGibK2ZBHLi2zv9MCkmExQcF12uBbTvjZAwPRIooCoWiuS4lcZIbAh8cqUr1XWxJjMFUUxyp/TsCIEc4XFOReRRih58zvaUCOqRfEGoi4z3cSmrr4dQ0dcsszqR2n4gkaBRA0w3tGWhHEUxpYglBSS+a6nlhXeAKZZGSzhihnXLSuKFckyFdE04w6CI2zL+8dbv5jjYR1Wk9gZrM12SC/FwYTK4qE0NX4St7FyjaLLdsH3rC/cq2Q== 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 MWHPR19CA0011.namprd19.prod.outlook.com (2603:10b6:300:d4::21) by PH0PR12MB5481.namprd12.prod.outlook.com (2603:10b6:510:d4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:58:07 +0000 X-Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:300:d4:cafe::c5) by MWHPR19CA0011.outlook.office365.com (2603:10b6:300:d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:58:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81919+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:06 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:58:00 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Wed, 13 Oct 2021 11:57:11 -0500 Message-ID: <20211013165713.727815-31-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b07c2b2-6365-471a-c27e-08d98e6aa0fd X-MS-TrafficTypeDiagnostic: PH0PR12MB5481: 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: ad53KghsOoyYu/TAeL+5WMnLTNnuRut8m1bghhYBqTiiR9LRUP5iIDvARyND5lqUPy5U16qk6UOzi0KZ+nYSWmZeAfGpDUgYLpSSNIW8AgSRR5va9qf+8QPO21YVdmwwdwe244GldvWKFjmSK5mHJ/VwQpJZkxWG3ocaJgoMzhXhFXITZj7psGMLDje+4Q++0wUfkyNPMrC8z2nFWaBtkpFXiKPzWMszpHjirBVrnOkbzXT0+KwBbhtQLf/Fr790/+rSVXz6w/K9RoihdobaDnFHURtWweyHg3TLvUK+OIjVaYdz90Pxq+7IW+7wS0POSn2BZtNP7j1zX/8m7eMP+KwjPdXVzoS0b6YVbLLKd8rYe6yYW9USu6XKQQKRzqlonSGnbW3zfn3BBCsqcMHCDLoCtQIWxa08Q+qmWi3AR9Qa9zeEMxGz7sEv5lEdxLe3U1el9zSYzNzMsqYAUrTd6pWHwBIP+eiVFjgEFH6epT2EUo9Fl+a6W8FpL30RiyirfiZHgSxxz7TRkHPOpVFuWvocguMEErSLuJxq3Xd8TMF/tDbRj+2IjgPj/copD5dYzEM3DZgiPRdWFsK28O9NDq2BU0FCbKVi+TfqoFosfGps/gmBgsFvcA0tKZ9AXXJ0warFAYRtnRd2FadMvh+pjoXvZLjph4kndfTNRon8U0LJZUFUr/pVc8LVKxWPnP3w2NaUrgrgAjSxhhRa7fkGlnBekJrj7+K1zi2AWOzAI1M= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:06.6669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b07c2b2-6365-471a-c27e-08d98e6aa0fd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5481 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: yrqAAxdtEuHS9iEavohpL1Gkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144290; bh=N3/vSnO59PYTk88xM8n8zBwIwpbllnKYVuoc9diYEUA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=OD8gnFS/XhZ5d5vZGyR32HbaQCGsVvpBfiK6OJnsyV5bI/zuem5cs0Ua/9V5/sE/aWy HrpsmkOJOruC42xZAyL8ds2Oak7mLm/Wv8AeETm1LhfRBVJUXIhHr3FAe0/Pm0ed/Nt9A ClYM1BM+zdEur8XLN/C4dU+p37bBTnXStMI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144291968100066 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 d048b692f155..0a89e1a0760e 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -112,6 +112,8 @@ [Pcd] =20 =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory @@ -122,6 +124,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 8b1d270c2b0b..4169019b4c07 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -102,6 +102,11 @@ AmdSevInitialize ( VOID ); =20 +VOID +SevInitializeRam ( + VOID + ); + extern EFI_BOOT_MODE mBootMode; =20 extern BOOLEAN mS3Supported; diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index b71a4a7304f7..133382407bc5 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -414,3 +414,34 @@ AmdSevInitialize ( ASSERT_RETURN_ERROR (PcdStatus); =20 } + +/** + 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 d736b85e0d90..058bb394f0df 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -821,6 +821,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 (#81919): https://edk2.groups.io/g/devel/message/81919 Mute This Topic: https://groups.io/mt/86292921/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 Tue May 14 12:14:04 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+81920+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144291169790.1463938612467; Wed, 13 Oct 2021 09:58:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id m6ubYY1788612xegVBdS2tzP; Wed, 13 Oct 2021 09:58:10 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.81]) by mx.groups.io with SMTP id smtpd.web10.108.1634144289776128955 for ; Wed, 13 Oct 2021 09:58:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CWwSpPjNRVmdZEuRxGoMIGyXuiNrWrmWcFJW6K2ctdXybAXkV+7Mx596t20SRIG2lo44P9X3afRDFnKSF1Ybrk839jjP3i1OponZ1ylOoxM067+baYX6Gv+EWNDyVLzcuERT3btwk6b8ZuBXlC7MrJ3LAJNntQzJBu6tGdAUARp2GkeRg1egzjCsZ482zoQ5Hmof3eUMzdGNVxdZjTvuy0tzW2nu2ZyKuld7AzAtjCsjh52idwpWayoOncjWwaDXxhkCbl6Kz7aiyfCtk4E2ItryEwDnqUW07XslJOp3eOW4hX7r8pdafHSOuhjMce8vcYPfQwPc/TmPjD6hlmApxw== 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=Noy6N5mC5Xf+C76kkIhP1ue0kuYvBcNF+RIOHH86NqQ=; b=Fwuctcgcbxwq0q+6+hQZPUAj3JlrHD93L/n9CPNOb2tq96n7J+fl4vKvccinMuPrkJUKEuqgpv5LMPRha9a/37dLpA83rWxIqWfVItTLmNUKrgoG1nfklinmTZpk/kc69n04bmcquo1QEk/ZjqIIUoPxjJTiSV2uVpAp5AglKzMLQeAVQ9d53WnClBE5w+qb2ZHzvVeq2wZn4hhrxi+frGj/epU77OOR0R2UpM86zKhuTV1VnsaL4k45dLzliqmeqVegP5mxrcEx+SkTt0Bft/Mt2Hrvm39H2pf431KE8rHYBd0eKg/pfkWuJ69ALRca77gwt3fRTgXNh9tGM4QCsA== 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 MWHPR19CA0018.namprd19.prod.outlook.com (2603:10b6:300:d4::28) by BY5PR12MB5015.namprd12.prod.outlook.com (2603:10b6:a03:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14; Wed, 13 Oct 2021 16:58:07 +0000 X-Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:300:d4:cafe::68) by MWHPR19CA0018.outlook.office365.com (2603:10b6:300:d4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81920+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:07 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:58:00 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 31/32] OvmfPkg/AmdSev: expose the SNP reserved pages through configuration table Date: Wed, 13 Oct 2021 11:57:12 -0500 Message-ID: <20211013165713.727815-32-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: badc6321-7410-47a0-73cb-08d98e6aa143 X-MS-TrafficTypeDiagnostic: BY5PR12MB5015: 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: BQAYngtK7y7nxaa6FQfDJjHZVHLTYtW4SrgS3ZvvbE9yePNjL0G9qM7h4vkpiEQvafFxDfBvPAtByNLrXNTJ6rpu2YiVSJX1N58VmkFtRLffih5uDiV5+Ix2I3Qa82j8WDHu3jgMsEFOaq5Ijtrozn+W2CLf/por2YaCO+SvsjBHDtQ67S4S2IrZXVJFcGbPeqR2IQzhQd0pBy0znGRpA0E04H4aSU6I5CV5o32lnZy+ZfnpaVTsiJEuHNJ+KoX4U4cubO6qJQ9TKrP7k9g852K7blr4+GvaMlYGOPqTE6OsjCIcPswIESIAdgm7qpABJt9MB2Sw3L88wdVmYb9mRHthOKws0ts3O11iYqRHBoN4FGy/forlpkEFjInjeUdpuanGbO7MJxHtorbbS3p8/Zm0+wCHWJ8wIn2Uc3FgXHbxWw5GVBEa4Zp/QLMaINsnYlQZhYMIc8Xe+i5NXU0s/Crnt4v7bwXc9DfiHTYFmmVOl2qc1r0EsjB10iIXBoelRv4ex4vmT94eDIKBjpZyraehArCn63KYSHD+JWTI4A61DeVZfMMCNFHxRgw+yGwCfthYy9dU2/OMMAJHI4bVQzKU+pYljaDRs4LdIsYXdKU+uO+SOtt1DdCSkzAwsQowvsF9IkgiNad2q4Wy986SGYfsrOsfPKk5JlqbQXGDJJBMKCc+0E6GSijPuQvwIEurpo9NIJACzvAv7ITurHoPx2wxmDdpPZFgyXy6Y4znQL9iy6Y8TO9l0yDXqiZK+rdV6LYJ+0juYqwdUbDjzNDhOKUehwlT2B4K3jz7LdDOgesKQzRNzyq3RQMHAiQbe58D X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:07.1406 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: badc6321-7410-47a0-73cb-08d98e6aa143 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5015 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: 0BEtbPGTt1OfUOiKDkQFklTsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144290; bh=v6alVbDeughunajdhQqKXLuBjELDAp4tk1o/dFI5V40=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lLiY545ZsqWn3rf4Wzgre2yrfu2lAdvfcuYdgzOoalRxe+i1JdA2BUrp+HsNbXvf2aQ LWi89Eb5BolTAZ3/0j2nnMQQnZnVOrHnJdydAD5q3N0iJeeKHmTAx3EOBBQ5BQ97TRUW7 0n4RcSD8VrMQPd4VviVnyTff9DcFTmGUC88= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144292078100067 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- 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 8dde5198c7cd..79619d585954 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..c98e7a1dcccd --- /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 c66c4e9b9272..6e1ba35e02b8 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 ( @@ -130,5 +142,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 (#81920): https://edk2.groups.io/g/devel/message/81920 Mute This Topic: https://groups.io/mt/86292922/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 Tue May 14 12:14:04 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+81921+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144292096538.2386946865389; Wed, 13 Oct 2021 09:58:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9UbEYY1788612x0kfgmeTvuX; Wed, 13 Oct 2021 09:58:11 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.51]) by mx.groups.io with SMTP id smtpd.web12.126.1634144290704788529 for ; Wed, 13 Oct 2021 09:58:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y4HZDX1oW+Ss4UkUYCh++Y02jwEuqeCJ6fZ0GvrJH600UyIHm5xWOq3Gs2yVXAQpT+iJeOeHEeKJE8IIluIXeL+m3HBRBWAwcsjS2Wz629CsxN/5uUYsSVDVpTvy8GotfKIn0xoRiUzXJDTUt1302DiRaYUV5Q7nC7RuU4fdZ59eZTwATUlmrmTNQm0ksOgOTTBJaDfY0hntLdDS5WY1eEVf8fCIzRmIq1n2uVShiT8w4kVLAShOQzoRcoVF3sAjxo9iT3rF46vA0uyEIixyd+3oBW/PxE2OXDCfNEmKaeRRqBb4io+galWoM7051nYvoO8n6EpXnzDmalnFGTwkOw== 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=nATX3Iuz7rP4lLxfmzIUzkHWFhBc6iGaLK/CAT/My2k=; b=nxARRoiiZUNG4bdyI+1t0c1B8wUyvm0m2xX4EK7aSF1TJ968cSfxARHjFW9V1ME9qm0KU04RAbwIFFXc+SnfclkjN2jZlQn4l9LE2Oob4/vM8/EkUQI8N/BBkPK5qzM3H+Xdv8qJ9COxNm3cQhmLgrY7kBM6ynmjN4pXZHFRp9Ga4+HwmDMTsUQLwOHgUydYm4/lU5+EA5YDBK5s5L/dwRgXvNCoL74D9gxZT5qsn5F7fvJAZaVy+FlW2T2NwfOZdLk+nXhGCZj0tF0lmK/UcWIrjtzFaZf3ff+MjbC95fqB9ZH5mZmv5ioqlc5RMsmcbjmX9NBJi6Abt98oZP3Ctw== 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 MWHPR19CA0024.namprd19.prod.outlook.com (2603:10b6:300:d4::34) by DM4PR12MB5328.namprd12.prod.outlook.com (2603:10b6:5:39f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Wed, 13 Oct 2021 16:58:08 +0000 X-Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:300:d4:cafe::23) by MWHPR19CA0024.outlook.office365.com (2603:10b6:300:d4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Wed, 13 Oct 2021 16:58:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81921+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:07 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:58:01 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Michael Roth , Eric Dong , Ray Ni , Rahul Kumar , Brijesh Singh Subject: [edk2-devel] [PATCH v9 32/32] UefiCpuPkg/MpInitLib: Use SEV-SNP AP Creation NAE event to launch APs Date: Wed, 13 Oct 2021 11:57:13 -0500 Message-ID: <20211013165713.727815-33-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b3c6d79-d690-43e6-351d-08d98e6aa19c X-MS-TrafficTypeDiagnostic: DM4PR12MB5328: 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: Qpvf2GHOoEK0V6LBWcY6iM9Gtb43qDXpyQjFDvFX/wUaft0yAyStTBmbLEQEiI3nA8D/3Cgg+UTjBASRlu51xMHiyS0GaQ6puAOM3entvwNsy5HEsiou2OgrGsLAjiklbiCEcyPa+lKeMGfxqbNvTGulUOaj8dCoecc0VsQ7ijRlUCZxu4wdtlbkZJpnexkUn0ESOD8ax86UA90uPs9UF/6r0HqF348y+V4MaAMHy8Yd7v1FvHBfjCDldxQQsIVejeKXTxFTvVRZb9k7OAFChSRXdw1kpbxCusc8ksInvHwjHPLi2+0nx5MqyBEP3/61vGnDtYG7vBLRxT6xrfV1x7UzN2xthMoKAlYTi5adUiqEVAMFLk0VQGyMm4ShpMPPKzjaMpYi0YMDc2l4RIkttU1b4Dv+rT+W2hrEjt6oyEUC2xPThYjQtNreORORqu++quc9OJ1CsIqvtN4G40gzw5P+8J3qN1uweNSxQmZ6gQGrgtIuYwWo3psBiIDoUENyPRPzAl0WwkC3fWASULkxvWHe5BeDOBf4UyKnk2wmI6ehYBoTXNBIl+ugdn2bMWUihGbIS7kEuCbVfJizoEdtUkrFPyIijiJmagosbFazZfucrs2Kp/KtOLK0q694I6dyN5O9dY7gzDprJfNsYF/8XYk41nc7RV+h3M9ID7B8BqFS3e8PnTKtVDzwXUaZi2mjVtaTOBsCY9I7tcogQqKDjI883SSGa78mBld5w6BJAb0er447DEkwY85iUWKV4mGsPX/m3PRe1qWgGLcXPIHMecbtQQ0lnm7IMs3ywApKv5z3I87rRnUmg2ukuNXaCSRA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:07.7043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b3c6d79-d690-43e6-351d-08d98e6aa19c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5328 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: de3hzgDUQtj8HV6FOdJdRjnNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144291; bh=H8olUvkUB/infII2Uxk/e6WbroTDdl2kBPgIITmcfg4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lUIEp4uWDzuQA5zrpqHO7U37huW8OrUaZmR6A2UvI8roVhESCJcuv1pvHVByOA9Dt9N CFP1jtjiyu0cOep1hwPnQUSJnZ06sx8IwjD73W2egF8PcgqWTOip+FJFSKE8no0z3aqpg IMhJG8O2y6jAzD+fFR+pF1xKElmhbMPzrT0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144294287100074 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 Signed-off-by: Tom Lendacky Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 44 +++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 12 +- UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c | 70 +++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 51 ++-- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 261 ++++++++++++++++++ 7 files changed, 425 insertions(+), 19 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 28764418d7c1..43c104b4da2c 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 cbc3c1460423..859b9a29fc19 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 gUefiCpuPkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONS= UMES =20 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index c52b6157429b..48f6e933bb36 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; @@ -790,5 +793,46 @@ ConfidentialComputingGuestHas ( CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr ); =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 =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 657a73dca05e..7a3ef0015a31 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -93,7 +93,13 @@ 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, whi= ch + // is also considered SEV-ES, uses a different AP startup method, though, + // which does not have the same requirement. + // MemoryType =3D EfiReservedMemoryType; } else { MemoryType =3D EfiBootServicesData; @@ -373,7 +379,7 @@ RelocateApLoop ( MpInitLibWhoAmI (&ProcessorNumber); CpuMpData =3D GetCpuMpData (); MwaitSupport =3D IsMwaitSupport (); - if (CpuMpData->SevEsIsEnabled) { + if (CpuMpData->UseSevEsAPMethod) { StackStart =3D CpuMpData->SevEsAPResetStackStart; } else { StackStart =3D mReservedTopOfApStack; @@ -422,7 +428,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..a4702e298d98 --- /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 de94b05e2263..758412058fe6 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -295,10 +295,11 @@ 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; } @@ -758,7 +759,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->Nu= mApsExecuting); } } @@ -772,7 +773,7 @@ ApWakeupFunction ( // while (TRUE) { DisableInterrupts (); - if (CpuMpData->SevEsIsEnabled) { + if (CpuMpData->UseSevEsAPMethod) { SevEsPlaceApHlt (CpuMpData); } else { CpuSleep (); @@ -1056,9 +1057,12 @@ 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. @@ -1108,7 +1112,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); } } @@ -1144,7 +1148,7 @@ WakeUpAP ( ResetVectorRequired =3D FALSE; =20 if (CpuMpData->WakeUpByInitSipiSipi || - CpuMpData->InitFlag !=3D ApInitDone) { + CpuMpData->InitFlag !=3D ApInitDone) { ResetVectorRequired =3D TRUE; AllocateResetVector (CpuMpData); AllocateSevEsAPMemory (CpuMpData); @@ -1185,7 +1189,7 @@ WakeUpAP ( } 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. // @@ -1195,8 +1199,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 ApInitCon= fig) { + SevSnpCreateAP (CpuMpData, -1); + } else { + SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferSta= rt); + } } if (CpuMpData->InitFlag =3D=3D ApInitConfig) { if (PcdGet32 (PcdCpuBootLogicalProcessorNumber) > 0) { @@ -1286,7 +1296,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. // @@ -1294,10 +1304,14 @@ WakeUpAP ( SetSevEsJumpTable (ExchangeInfo->BufferStart); } =20 - SendInitSipiSipi ( - CpuInfoInHob[ProcessorNumber].ApicId, - (UINT32) ExchangeInfo->BufferStart - ); + if (CpuMpData->SevSnpIsEnabled && CpuMpData->InitFlag !=3D ApInitCon= fig) { + SevSnpCreateAP (CpuMpData, (INTN) ProcessorNumber); + } else { + SendInitSipiSipi ( + CpuInfoInHob[ProcessorNumber].ApicId, + (UINT32) ExchangeInfo->BufferStart + ); + } } // // Wait specified AP waken up @@ -1832,6 +1846,11 @@ MpInitLibInitialize ( CpuMpData->SevSnpIsEnabled =3D ConfidentialComputingGuestHas (CCAttrAmdS= evSnp); 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..303271abdaad --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c @@ -0,0 +1,261 @@ +/** @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->SevEsSaveA= rea, + 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 (#81921): https://edk2.groups.io/g/devel/message/81921 Mute This Topic: https://groups.io/mt/86292923/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-