From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.76]) by mx.groups.io with SMTP id smtpd.web09.1336.1632163580550735194 for ; Mon, 20 Sep 2021 11:46:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=2amltDA7; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.244.76, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gtXY+vSzx8C13V4rx5J8SSmF1uHvjIsbud2ux0sFhBWmj07sTTjSbtpbb5A5vSin/eOn+5GUiCVqjOCkZNouIve2t+tjzoSjVOG9RMMKZgGXh/zEEs5za1PbBY3QFQ52ubqmYMRee9wXmVDGMiMK8XA/BBH+Y8XYVkayxTy5GYiJrq7pEWnaycMSEFZqckDP96u7HbiBDrRmbmQEhamB4lmnWwrbeLpGLL6/kLENg3jIe1nQzWGg+UdANmUEjy+PyYGnIW0JxwvMrrHlV9831k55rUQFGLH8LzpcfZkaCDM9u4tWLyNT1rqEJzm2sUJncgM99iseehCtjmcBmafnhw== 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; bh=KdziwIaksyReiyMuw6UfqeLz32bN5hIpKOxnP8MDU7Y=; b=Hdo4J3QZpGOzPe/Sjxm/ku+c3MBGf4sdh25lQXs+agmeUWa//Lh1ziQUfRYSC4hfc8WmUVTY80weWk2hvbpXY7nSR/800G0KbubzpB4lZOgBOiqSwNJlb/EB7ZR3bDWXhnb1/D2udvySgx6iR1TnloKrVtHklfv+xcL++tMsr7V7WpeM342sdeZ0ASfNXNUs5VOq8PLYr1xdI9hCFvaG0beXYuHvKF4BgpsHCQP0qNcja5xAV1g7h6Wh3koXbdp9iuAJM1DG8j3k3mGaEyyOa4ySVX6kWxJ9FUBEGu8WkBdnD6xwkdYTojTqLLMhxIIWgrVVqhn2285D496u94h/Zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KdziwIaksyReiyMuw6UfqeLz32bN5hIpKOxnP8MDU7Y=; b=2amltDA7VBiE862x+wegfCdnXAEajFj5yxmH0ac9eetMzgDqUvT7RurXyi+TUAu3hoMEm6en8/7DpCCff8LUazndBT59BBA8BCKFwyb5tDf1odNj/4VDfu0tuNBxp05XVOSjM6ISNsH2eRp3Jqze4LC9/E0is8yy8QK4Yept2yw= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 18:46:19 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 18:46:19 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io 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: [PATCH v8 01/32] OvmfPkg/SecMain: move SEV specific routines in AmdSev.c Date: Mon, 20 Sep 2021 13:45:33 -0500 Message-ID: <20210920184604.31590-2-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184604.31590-1-brijesh.singh@amd.com> References: <20210920184604.31590-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 18:46:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b3276dc5-cf19-43f7-7cf3-08d97c66ef75 X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True 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: BCL:0; X-Microsoft-Antispam-Message-Info: tT30MHcyeLJJ6sqd1hJ+bql/m5DBO9wNhCEvbwixgbErG9GIuQhr4o2YyBUbnp9jHzDV+x6nB9OAavl2Zmw+AsfJp90wPUzyldbLm4poimsTtHlU4r5kC1aOthUUZ5ddaRL0sUCGr9iz1t0jiSvJUMO1kIR7F7u7vcpn5i0o9xA3We3dJHWUvEK7fFryWbskuV90hNqfYTTQVEwDzCu1W6K7bHepfz8WoSb9jHOzZaHt1kGr36Nmo0951qvHpWGqnx44GLXJpmmzKuQ7wTQosYiFbYmpcbBcsPQ8C1ETirWLt+e4Jdf9vNY01GOSKi/R8Myz4MYnrMkyqHrr9wBcjp5iEjeNKoznkjdxuTlkX9oGKwZbiD4Zlp7w1iS7ZGpHUGhxoy1x92EQv3qwYWk6JghkXsl+au2NY9ZHiuW7MOFDQibbMU2m0NeDAB47vfuoVU9CdCmgDyzGFmx1HUA5SM4ishrHvyHOqZcm7Qg9Qtapxm8rMfsj7l9hLZNUa0MOFYY7tT2XdASp4e3aAzQEl9pVJpN0p8RUHVwQtHF3qCPqmn9SopE/UUX9BRhDqhY/Q1O5IrXrUwtvKThu148jhSqlKdb9coM65cAvW/LVC8NsLU5UE+Zp2rUXSfXkWabGuExcEl4SuZQA+j6xVAZTNYY/v0NMqcfXLNPviX68df2wvVGQv0Va2HhVdVqNhaM5EHbJrchU//qtbzJnxOsZn3C9O0z9jIZ6Uu1slGo3IoLM9YuSa8bsasJTaD2cFJBzrdzUHEo29vmr2+9ebykaTh+HSUS+8gHygPdfdvxcE4s= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(44832011)(66476007)(36756003)(5660300002)(508600001)(38350700002)(6916009)(186003)(6666004)(66556008)(7696005)(2616005)(956004)(30864003)(66946007)(6486002)(52116002)(2906002)(4326008)(26005)(83380400001)(966005)(316002)(86362001)(8936002)(19627235002)(54906003)(38100700002)(8676002)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ZHou/innoKTA1XvYOsRc7Jqedr13/ebfpLL8+zVTZMTC6XAeGumah5Ssmv6d?= =?us-ascii?Q?BFU9SxPQiopshIzpte5P3IaaS9QZYXfn8FYdC/6guRhFmge7V1Hk2W43yjmD?= =?us-ascii?Q?Hk4sL1WQbtdGug9PS63kMYeUhdsSOUjysIggVl4t/9foP709LvFsJ46vE8Um?= =?us-ascii?Q?ZQFfeAJDglsHqAiH56NctcfA1vcgCx7nR9IPahYY1RFIzNOhqBARdorXgMWf?= =?us-ascii?Q?H7iV6aHCdP/thCHXHB2TGS+SG2bOEZ+nI9Z01u9e+9n5hWX6AGdtpOTFgvEk?= =?us-ascii?Q?7zNNW/FTapR5gHD6vfQIrIWQVS2JNQzLOnlzBCwec7ksJ/Xw9TSMqIKMbHMt?= =?us-ascii?Q?HVSRIDjZiTz469xM6gPpxjJYjPk6wA1tWjEdUkfYpxPeckjPTBruTQu3hnCY?= =?us-ascii?Q?fzlhxTCDoImZQzs5Aona8y3Xhye31/CMRzBBAUsEG2Q1G85IZ0kIVPW4+nh/?= =?us-ascii?Q?0iXecRWRrF6rYFOGGLdeEpjPYNKR67DZdYMYs+n/jdwoM+XEVgciuu9q2yLA?= =?us-ascii?Q?YRCx32m1jxokvX2yLEuTebHig1sxX3ffobUXxcXWVOFGbg39YhFe9ajoQmiw?= =?us-ascii?Q?WslIKcZzsIYIjvK7tjKE6lxqwcbXVHjuh3i6f2QGUvdkgSyZy1RFO1R1i+/v?= =?us-ascii?Q?+P1wWEj5CmgMRHEDIY0+T9DMPu8BzdfIsD6THGBsDfvSKg9YGo0OdUziwKQO?= =?us-ascii?Q?byLGx8P7I3q1iEbaQa2wSYNbL/7mYMtp8YXTJe+EjRTxONkQMKQcNBBBp1KX?= =?us-ascii?Q?3kGOheS+tiekRi8+XicKXWP3JIwMY2ZKsvUZkQVHV7pp+Z7Wnhgnz9PTIlun?= =?us-ascii?Q?rZL1AKwMZF51itfxQIFQuiDZ7kNU6vW2ILLuqfNbdjJ36HH0G1ztvd/LmYmR?= =?us-ascii?Q?2QsoNnchxJXIe33NSaTMEfE4rSfM3V0+0CQ+4HRptI+R2cVcB1OAjbsdgcKV?= =?us-ascii?Q?UjqW0kOE2PgWtP+FbmS07gyxleuLa9gvPvWQpf/DJnVb0V4ZWSt/4j0phxqu?= =?us-ascii?Q?YTxc3y0pkJgoNgbhdpEK3ah4C4jpyhdOcJq8VMqcEyGOmAr/p/ADHApkASqw?= =?us-ascii?Q?ew2LRCaoj8oke6CTnqZwK5h+G8xHEkvwyxDRrEx9rHxNsX0MK4ClHsFkI47w?= =?us-ascii?Q?U3epsjO/99jHN1IK1Imlyst0PdLZU8Muz+6aol4DVq2GPSRE3qZ0VoEHxm4E?= =?us-ascii?Q?Ij5efNMNcqyRTN/Sd3W1PoqfDkvBTt1IYoV7rjd7UrQVXYkH3dmMFV2rzE8Y?= =?us-ascii?Q?2sjafxJyGSNn2Se0uZg5r8ZEV98VWSAlwWIBQdeN8VkUsV/Fll6zurDXRuze?= =?us-ascii?Q?0FpWbjHu2phylemAOraUEsmA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3276dc5-cf19-43f7-7cf3-08d97c66ef75 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 18:46:19.7157 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NuSWr7yiUTDWVMy6iMw3usnfg+IRpLK0p3la03m0ltsbxFi74dER5tt2/481204JJlDtLkvZw7QzX2J9FAdllQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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 --- 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 gues= t + 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 hyperviso= r + 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 gues= t + 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 hyperviso= r + 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 gues= t - 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 hyperviso= r - 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