From nobody Fri Dec 19 19:20:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57842+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1587577351332348.8067063016738; Wed, 22 Apr 2020 10:42:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8pQ3YY1788612xFH89OjidJU; Wed, 22 Apr 2020 10:42:30 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.45]) by mx.groups.io with SMTP id smtpd.web12.476.1587577349670673050 for ; Wed, 22 Apr 2020 10:42:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UMDOldhUKNKMOfAVmyyGjgzQzGBOFY3HQNrOQP9gFgCpf613VrqXbhlY/8ClBB7eBKmTv73xPyXqFXRu8Z6Zprn6Pv1abW6f5ptnZyH0uHomCytS2uLytPusDXxYRluoODjqt1XbEfVmKIV2IfHjkCFj2ooQoQhkM8gkYy4DkoUSsc6ZnCrh3sYXTBDke4kK2yT0kAzbdBPWkdqOYkcIka23xAeSMs7nlUCFL1KugEmN1X5E2KFs55ZMdxc5NZ4VQa1Ghjvmd8yIZL5AA319xfe/3f6Mkk5oxJKdYLp0I8+ib8F/+iAINQTIdVcmJshi4IjwIXVU7ga44WAq7JOrLg== 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-SenderADCheck; bh=Fg+9FNTUorv77wF8spqYwZwQ2gl5HinrNZO9jtKtSSg=; b=LhQP83ycvkZQSeThf6Zygq47c30DrZdsJLBe2JEGUDBkpE8fDRM/SFH3ZKfoyG4cagm+fSUrL3rOYoEENdZzMCR9yQyKY7AzxxFezujTsKR70bzjlyTwky7q+VtnrAZDJhGVQ6wS/BmynL5pOPXqqnbw0Y8YtVq6VzlzGqm5kM17sa1A1TKnW36JFv1zOobH0wPEUu4fdMi3AcX6xi55A7E6ulGTGxJDEQF0YMW6cetzp74gvvFuZs/amNfMwr5PDDhv2fCWnMWBcejOeiHxZDg6Q3IYHczlv75Xw6SOLi3RpSyzO+TwIMLnLn+lxuye7o9SlClKxOA+0lxjGl8Rrw== 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 X-Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3449.namprd12.prod.outlook.com (2603:10b6:5:3b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.25; Wed, 22 Apr 2020 17:42:27 +0000 X-Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:42:27 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [PATCH v7 11/43] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Wed, 22 Apr 2020 12:41:26 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:26 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8e057f86-932c-4a03-78fe-08d7e6e485d8 X-MS-TrafficTypeDiagnostic: DM6PR12MB3449:|DM6PR12MB3449: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57842+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: JziV/bO77x67tIsn2mLc1/S7IcpAJD9OqacHTBt2JvpysfnEdSn3W6CwzNay1z6rQM9r4SJCRhRGZviNoaJ+yFiiM1QuJlyTd0tsNZdz/Fw5IGmBxQO+emMunGZNYYqYguMSJXwnBvwWJPcehsYZeZCQ5/6SD+54sBkMh0i+cgGyxUJbLnQNfX/pxYDi8n0DDMFQp1hmUNu+17e9FElu7/S6k9/q2HwUqt8SMYk00ePQUnOjk3MKxD/vx+sJEh6t693VDPhAK9P3TgRjfIm+cP3ONlNwPsbazgVE6jXspXsOVLmVVqTZk4ohKnHk4eJrYzOrgxgo5eaLTS9/YcftJQhovqazElhvNotujR0Vfnz7qDJSo9pHVZbZCtQpLWOarPX/R8GFcMF1gJqB7mTEf14czlY4XQYRCTLZJUeVChGKCjZYM4CVxxPV/0C4UOq4Jt5GRvZkhCHOh0SUhzEenLoXocPbhZXuJc1iFjDRe89hda5n1YDH5Ors+AbjfPXm5v3s84sIsdbIC/8pANIVutgpdoukZFNqz59HN4uNmeAU/Fo/eHV+Al22YTzKhs5MWWKg5tgDwdZrTQEyIh2qHw== X-MS-Exchange-AntiSpam-MessageData: PiCFDvXTdjBR9pdF4PzXTo29EHPCWWt9OZuf3omPznDZ9S3y9v5yH5A8qKktcX1aQAIPGklch8PjUqP0MQ9uz5wth6U8Qz6Xi4yLt39edjyX1vFXkvMSWympIY0SMs8w92R99WNO54dGocYrynn/8Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e057f86-932c-4a03-78fe-08d7e6e485d8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:27.1571 (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: TA/R9jUqfMPIZGpf68Qd3go22DuslQy3hJnMGSeyNk8Of9ZPFcR7JR4lxcubewr1kEeqVBtKs5WbM6nhizEYvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3449 Precedence: Bulk List-Unsubscribe: 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,thomas.lendacky@amd.com X-Gm-Message-State: CbTDNeLisQjg2k62h5b9Q6vrx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1587577350; bh=AK3jVDAiK90KjsaAQyFHl4w5kn6JRRuIYMSA+2V1nuc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=N6Mt7RWUPMYq+33t5CDqy5wRurtxFuFtKZGah24jySf2V/8ifbmPAIExvJDHS0KV8u7 97ZZhQDXG0DsE6ss7/gBLkxno/SHo6zjWErQV1kMLjHcKGsO2AgqYB6dmLCpw8mz58vWa McYJ87iFl1qkkMgIwQzBkEfzuGUPO/ZJit4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add base support to handle #VC exceptions. This includes a stub routine to invoke when a #VC exception occurs and special checks in the common exception handlers to invoke the #VC exception handler routine. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Signed-off-by: Tom Lendacky --- .../DxeCpuExceptionHandlerLib.inf | 5 ++ .../PeiCpuExceptionHandlerLib.inf | 5 ++ .../SecPeiCpuExceptionHandlerLib.inf | 5 ++ .../SmmCpuExceptionHandlerLib.inf | 5 ++ .../CpuExceptionHandlerLib/AMDSevVcCommon.h | 49 ++++++++++++++ .../CpuExceptionCommon.h | 2 + .../CpuExceptionHandlerLib/AMDSevVcHandler.c | 40 ++++++++++++ .../CpuExceptionCommon.c | 2 +- .../Ia32/ArchAMDSevVcHandler.c | 38 +++++++++++ .../PeiDxeSmmCpuException.c | 16 +++++ .../SecPeiCpuException.c | 16 +++++ .../X64/ArchAMDSevVcHandler.c | 64 +++++++++++++++++++ 12 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommo= n.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcHandl= er.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchAMDS= evVcHandler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSe= vVcHandler.c diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index e41383573043..4d79c4910b18 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ArchAMDSevVcHandler.c =20 [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/ArchAMDSevVcHandler.c =20 [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiDxeSmmCpuException.c DxeException.c + AMDSevVcHandler.c + AMDSevVcCommon.h =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard @@ -57,3 +61,4 @@ [LibraryClasses] PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index f31423ac0f91..e8445e47eaa3 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ArchAMDSevVcHandler.c =20 [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/ArchAMDSevVcHandler.c =20 [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiCpuException.c PeiDxeSmmCpuException.c + AMDSevVcHandler.c + AMDSevVcCommon.h =20 [Packages] MdePkg/MdePkg.dec @@ -52,6 +56,7 @@ [LibraryClasses] HobLib MemoryAllocationLib SynchronizationLib + VmgExitLib =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 6d25cafe2ca3..a15bf71b4052 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -26,16 +26,20 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ArchAMDSevVcHandler.c =20 [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/ArchAMDSevVcHandler.c =20 [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c SecPeiCpuException.c + AMDSevVcHandler.c + AMDSevVcCommon.h =20 [Packages] MdePkg/MdePkg.dec @@ -48,3 +52,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 66c7f59e3c91..190d7dfcd42a 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -26,17 +26,21 @@ [Sources.Ia32] Ia32/ExceptionTssEntryAsm.nasm Ia32/ArchExceptionHandler.c Ia32/ArchInterruptDefs.h + Ia32/ArchAMDSevVcHandler.c =20 [Sources.X64] X64/ExceptionHandlerAsm.nasm X64/ArchExceptionHandler.c X64/ArchInterruptDefs.h + X64/ArchAMDSevVcHandler.c =20 [Sources.common] CpuExceptionCommon.h CpuExceptionCommon.c PeiDxeSmmCpuException.c SmmException.c + AMDSevVcHandler.c + AMDSevVcCommon.h =20 [Packages] MdePkg/MdePkg.dec @@ -51,4 +55,5 @@ [LibraryClasses] LocalApicLib PeCoffGetEntryPointLib DebugLib + VmgExitLib =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h b/U= efiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h new file mode 100644 index 000000000000..e4b8f3147add --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommon.h @@ -0,0 +1,49 @@ +/** @file + Common header file for SEV-ES #VC Exception Handler Support. + + Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _AMD_SEV_VC_COMMON_H_ +#define _AMD_SEV_VC_COMMON_H_ + +#include +#include + +/** + #VC exception handling routine. + + Called by the UefiCpuPkg exception handling support when a #VC is encoun= tered. + + @param[in, out] Context Pointer to EFI_SYSTEM_CONTEXT. + + @retval 0 Exception handled + @retval Others New exception value to propagate + +**/ +UINTN +DoVcException ( + IN OUT EFI_SYSTEM_CONTEXT Context + ); + +/** + Common #VC exception handling routine. + + Used to bridge different phases of UEFI execution. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication B= lock + @param[in, out] Context Pointer to EFI_SYSTEM_CONTEXT. + + @retval 0 Exception handled + @retval Others New exception value to propagate + +**/ +UINTN +DoVcCommon ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT Context + ); + +#endif diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h index 805dd9cbb4ff..0f274e7ea328 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h @@ -24,6 +24,8 @@ #define CPU_INTERRUPT_NUM 256 #define HOOKAFTER_STUB_SIZE 16 =20 +#define VC_EXCEPTION 29 + // // Exception Error Code of Page-Fault Exception // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcHandler.c b/= UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcHandler.c new file mode 100644 index 000000000000..fc91cf119f3e --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcHandler.c @@ -0,0 +1,40 @@ +/** @file + SEV-ES #VC Exception Handler functon. + + Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" + +/** + #VC exception handling routine. + + Called by the UefiCpuPkg exception handling support when a #VC is encoun= tered. + + @param[in, out] Context Pointer to EFI_SYSTEM_CONTEXT. + + @retval 0 Exception handled + @retval Others New exception value to propagate + +**/ +UINTN +DoVcException ( + IN OUT EFI_SYSTEM_CONTEXT Context + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Ghcb =3D Msr.Ghcb; + + return DoVcCommon (Ghcb, Context); +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 8adbd43fefb4..39e4dd9e9417 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -14,7 +14,7 @@ // // 1 means an error code will be pushed, otherwise 0 // -CONST UINT32 mErrorCodeFlag =3D 0x00227d00; +CONST UINT32 mErrorCodeFlag =3D 0x20227d00; =20 // // Define the maximum message length diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchAMDSevVcHan= dler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchAMDSevVcHandler= .c new file mode 100644 index 000000000000..d988fe620d53 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchAMDSevVcHandler.c @@ -0,0 +1,38 @@ +/** @file + IA32 SEV-ES #VC Exception Handler functons. + + Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include "AMDSevVcCommon.h" + +/** + Common #VC exception handling routine. + + Used to bridge different phases of UEFI execution. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication B= lock + @param[in, out] Context Pointer to EFI_SYSTEM_CONTEXT. + + @retval 0 Exception handled + @retval Others New exception value to propagate + +**/ +UINTN +DoVcCommon ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT Context + ) +{ + EFI_SYSTEM_CONTEXT_IA32 *Regs; + + Regs =3D Context.SystemContextIa32; + + Regs->ExceptionData =3D 0; + + return GP_EXCEPTION; +} diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuExceptio= n.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 6a2670d55918..d565db547808 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" #include =20 /** @@ -86,6 +87,21 @@ CommonExceptionHandlerWorker ( break; } =20 + if (ExceptionType =3D=3D VC_EXCEPTION) { + UINTN Status; + // + // #VC must be handled for an SEV-ES guest + // + Status =3D DoVcException (SystemContext); + if (Status) { + // Exception not handled - Status contains the desired exception now + ExceptionType =3D Status; + } else { + // Exception handled + return; + } + } + if (ExternalInterruptHandler !=3D NULL && ExternalInterruptHandler[ExceptionType] !=3D NULL) { (ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContex= t); diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 20148db74cf8..0716680d2f50 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include "CpuExceptionCommon.h" +#include "AMDSevVcCommon.h" =20 CONST UINTN mDoFarReturnFlag =3D 0; =20 @@ -24,6 +25,21 @@ CommonExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { + if (ExceptionType =3D=3D VC_EXCEPTION) { + UINTN Status; + // + // #VC must be handled for an SEV-ES guest + // + Status =3D DoVcException (SystemContext); + if (Status) { + // Exception not handled - Status contains the desired exception now + ExceptionType =3D Status; + } else { + // Exception handled + return; + } + } + // // Initialize the serial port before dumping. // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHand= ler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c new file mode 100644 index 000000000000..c0a0eee319bf --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -0,0 +1,64 @@ +/** @file + X64 SEV-ES #VC Exception Handler functons. + + Copyright (c) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include "AMDSevVcCommon.h" + +/** + Common #VC exception handling routine. + + Used to bridge different phases of UEFI execution. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication B= lock + @param[in, out] Context Pointer to EFI_SYSTEM_CONTEXT. + + @retval 0 Exception handled + @retval Others New exception value to propagate + +**/ +UINTN +DoVcCommon ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT Context + ) +{ + EFI_SYSTEM_CONTEXT_X64 *Regs; + UINT64 Status; + UINTN ExitCode, VcRet; + + Regs =3D Context.SystemContextX64; + + VmgInit (Ghcb); + + ExitCode =3D Regs->ExceptionData; + switch (ExitCode) { + default: + Status =3D VmgExit (Ghcb, SvmExitUnsupported, ExitCode, 0); + if (Status =3D=3D 0) { + Regs->ExceptionData =3D 0; + VcRet =3D GP_EXCEPTION; + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; + } else { + Regs->ExceptionData =3D 0; + } + + VcRet =3D Event.Elements.Vector; + } + } + + VmgDone (Ghcb); + + return VcRet; +} --=20 2.17.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 (#57842): https://edk2.groups.io/g/devel/message/57842 Mute This Topic: https://groups.io/mt/73201900/1787277 Mute #vc: https://groups.io/mk?hashtag=3Dvc&subid=3D3901457 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-