From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.65]) by mx.groups.io with SMTP id smtpd.web12.10094.1581702972543732834 for ; Fri, 14 Feb 2020 09:56:12 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=BiQoyEwH; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.70.65, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gwbWtm+IPV2GbHgTPY9L3YZ6MhxjKvvhPjRULjiZWFQ3IbYVQjTaHmRTQiN0TzoXtOoQvXx1XwTi5AAN113cKRqdGdPjjq3xAwT4rxAZwmRthg7KKQx+ppynIlEJdNnrWBEykiXy28xlC7hN7rO/q7pT9nN+DiLgPS0zL8rHuVBGxZyn+iqBQjul/rIg4MfETmjQ3HexZ+p5a+fUAS8VtGDRpOUNNaWmjPKSeu1Xh83uYF/sq1fjMrwD8xB7eLYzXxiKGefzHW955jLaG/3rx2sICDucoko045Kd6JwTsnk9d6uYq9g7x//d3jTRxewyizTXZmQ3NJbRfWw9wsuAkw== 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=zSJvUBJZVBuki4FZLR36lxq0D/p2cemSo8EUK1c1o9U=; b=Zmeo4w7FMIYTUAaVqTLRKK7JxmIPoj1dN3G+L39JuGtgHBWGALfwd0FQBd97XVOQ//SEoopS1/LCINkMSO1+nnvWocbrbaGvcEJreafBxOoddztMMx2D0sODRBVJBcjE7kQPccgVaJjFL5u50E3MsJl3pLDkHrMN9l853Mlh57w9HXP31YjmvXjmzMcoORgNwQKe3MDCZkCuvnClNo56ntNkUYmghIzBiaga9LXsnd9O8h/KAIJB/+lblHvEUMlsv3yODGKMmZ2jjBPLj68m33W50yZhtBE0UTbQYZ3hX7sd6ClVQQLtTAAaXEvx4acTWufhGbBZOcldjDLstDQITA== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zSJvUBJZVBuki4FZLR36lxq0D/p2cemSo8EUK1c1o9U=; b=BiQoyEwHIfaDveyHRm2ZoNgRxxQIDn5+Do1eoiTDus9oo7piyL9htCO1Tb+IdvLNVERyHJRqg0q/ZaSWk/ehJ8HcI/84btjPyTlonhKYImWZH5lpe8y15lY8YJ7TLqrmUja4H063mpndgkEBYZ34ChBYOfsRziA1wH7EwNWEapw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from BN8PR12MB3154.namprd12.prod.outlook.com (20.179.67.74) by BN8PR12MB3220.namprd12.prod.outlook.com (20.179.65.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Fri, 14 Feb 2020 17:56:10 +0000 Received: from BN8PR12MB3154.namprd12.prod.outlook.com ([fe80::19c8:ed30:f4ea:a010]) by BN8PR12MB3154.namprd12.prod.outlook.com ([fe80::19c8:ed30:f4ea:a010%3]) with mapi id 15.20.2707.032; Fri, 14 Feb 2020 17:56:10 +0000 Subject: Re: [edk2-devel] [PATCH v4 07/40] UefiCpuPkg: Implement library support for VMGEXIT To: "Dong, Eric" , "devel@edk2.groups.io" Cc: "Justen, Jordan L" , Laszlo Ersek , Ard Biesheuvel , "Kinney, Michael D" , "Gao, Liming" , "Ni, Ray" , Brijesh Singh References: From: "Lendacky, Thomas" Message-ID: <3023d667-90f2-9cf7-295f-1e72b64bca7a@amd.com> Date: Fri, 14 Feb 2020 11:56:07 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 In-Reply-To: X-ClientProxiedBy: DM6PR02CA0120.namprd02.prod.outlook.com (2603:10b6:5:1b4::22) To BN8PR12MB3154.namprd12.prod.outlook.com (2603:10b6:408:6d::10) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 Received: from [10.236.30.74] (165.204.77.1) by DM6PR02CA0120.namprd02.prod.outlook.com (2603:10b6:5:1b4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25 via Frontend Transport; Fri, 14 Feb 2020 17:56:09 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1d636011-44b8-41eb-4de1-08d7b1772c8c X-MS-TrafficTypeDiagnostic: BN8PR12MB3220:|BN8PR12MB3220: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 03137AC81E X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(376002)(396003)(136003)(39860400002)(366004)(189003)(199004)(478600001)(66556008)(86362001)(36756003)(66476007)(66946007)(53546011)(26005)(4326008)(16526019)(30864003)(966005)(6486002)(31686004)(186003)(956004)(2906002)(16576012)(54906003)(316002)(110136005)(81156014)(8676002)(81166006)(52116002)(31696002)(2616005)(8936002)(45080400002)(5660300002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN8PR12MB3220;H:BN8PR12MB3154.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kjr9OHAkbYe66/Ccg42CbMKbFFI2HR3nYbCb/JNh8a5XbzMmpqHIIzpNRt4+dgxNZM4liGpi4RXwIZA1T+nArQXpomt+noeeaii7a3pwEyJB4P1rYMhMhw6WheQBe+Pu0EXMkPsP/TGCRrqYtJ5y6nYhSFFf65QxGpWhVFYkF7pRBbTnl1XXy1oGDL8Tt2cS8OyrHmlJ0Fv1mpGIIVelI/1AbrcT68YloJMv7O1F06FtJIVzFcKduKk0IFqFC3zekpWYcpMutGKx9VT/ypeXVoWLPsrUfXuYvxclWLDv3ab/dDa5ySdsvrWB/jC6iq+P4zb2FXPk5dVcMmuP3xO5uJPA8FD/l650/buqqV5x8vHVDVL25C563wqWPFWK2h6fvT+wDi2cvLPYyPSLIoxDcaTT/fICMWcIZmLkT/NffgmN0fRzLfqcJsyteYXwrDBF6EXXazHWxhp9/LuY0q3uD6v9JgsU8BI3Ws5SWkYGFnM1GW/aEB0SNfjatqlLBk2M6VxT71c9o2+nTOIS6KyvqQ== X-MS-Exchange-AntiSpam-MessageData: YpY1YeRGIilcEsMnpfxu8uI9S9APfR5bOaj+mDDV7vPs7OgVqdH9j3FDJmwUp08w6JFzjNO3kpMnmSSokG9AUBc5R+uPGvTa2QZ+/k57z6G3jbuRK5mhFI9Wg0dICr2F/lNQBooRRx+uhw7DizcSyg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d636011-44b8-41eb-4de1-08d7b1772c8c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Feb 2020 17:56:10.5210 (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: Xd7BrTcbWWyK2uJSjviCIgFyhgC6l0KQH9Nr28KeJb/vIrldA9pFN0ptO5C4iN3nl2sSY6hC+ONAS43PPNSibQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3220 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 2/13/20 6:42 PM, Dong, Eric wrote: > Hi Tom, > > For this patch, I found the function implementations not have function header comments for them. This is not follow edk2 coding style, please update them. Yup, missed them, will do. Thanks, Tom > > Thanks, > Eric > > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Lendacky, Thomas > Sent: Wednesday, February 5, 2020 7:01 AM > To: devel@edk2.groups.io > Cc: Justen, Jordan L ; Laszlo Ersek ; Ard Biesheuvel ; Kinney, Michael D ; Gao, Liming ; Dong, Eric ; Ni, Ray ; Brijesh Singh > Subject: [edk2-devel] [PATCH v4 07/40] UefiCpuPkg: Implement library support for VMGEXIT > > BZ: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Cthomas.lendacky%40amd.com%7Ca5720d7a6a5d4e744f9108d7b0e6bf80%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637172377418610890&sdata=OpW4YzwW9NW4qr9PRvh%2FTgWO28Dt3vGXxA7%2FnYwUsjw%3D&reserved=0 > > To support issuing a VMGEXIT instruction, create a library that can be used to perform GHCB and VMGEXIT related operations and to issue the actual VMGEXIT instruction when using the GHCB. > > Additionally, two VMGEXIT / MMIO related functions are created to support flash emulation. Flash emulation currently is done by marking the flash area as read-only and taking a nested page fault to perform the emulation of the instruction. However, emulation cannot be performed because there is no instruction decode assist support when SEV-ES is enabled. Provide routines to initiate an MMIO request to perform actual writes to flash. > > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Acked-by: Laszlo Ersek > Signed-off-by: Tom Lendacky > --- > UefiCpuPkg/UefiCpuPkg.dec | 3 + > UefiCpuPkg/UefiCpuPkg.dsc | 5 + > UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf | 33 ++++ > UefiCpuPkg/Include/Library/VmgExitLib.h | 111 +++++++++++ > UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c | 187 +++++++++++++++++++ > UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni | 15 ++ > 6 files changed, 354 insertions(+) > create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h > create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c > create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni > > diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 005703d8a3e7..893d2d06b0f2 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dec > +++ b/UefiCpuPkg/UefiCpuPkg.dec > @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] > ## > MpInitLib|Include/Library/MpInitLib.h > > + ## @libraryclass Provides function to support VMGEXIT processing. > + VmgExitLib|Include/Library/VmgExitLib.h > + > [Guids] > gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} > gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index d28cb5cccb52..5ab7e423e8ab 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -63,6 +63,7 @@ [LibraryClasses.common.SEC] > HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf > PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > > [LibraryClasses.common.PEIM] > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > @@ -74,6 +75,7 @@ [LibraryClasses.common.PEIM] [LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] > PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf > + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > > [LibraryClasses.common.DXE_DRIVER] > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf > @@ -81,12 +83,14 @@ [LibraryClasses.common.DXE_DRIVER] > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf > MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf > + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > > [LibraryClasses.common.DXE_SMM_DRIVER] > SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf > + VmgExitLib|UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > > [LibraryClasses.common.UEFI_APPLICATION] > UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf > @@ -136,6 +140,7 @@ [Components.IA32, Components.X64] > UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf > UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf > UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf > + UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf > UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf > UefiCpuPkg/SecCore/SecCore.inf > diff --git a/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > new file mode 100644 > index 000000000000..6acfa779e75a > --- /dev/null > +++ b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf > @@ -0,0 +1,33 @@ > +## @file > +# VMGEXIT Support Library. > +# > +# Copyright (c) 2019, Advanced Micro Devices, Inc. All rights > +reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = VmgExitLib > + MODULE_UNI_FILE = VmgExitLib.uni > + FILE_GUID = 3cd7368f-ef9b-4a9b-9571-2ed93813677e > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = VmgExitLib > + > +# > +# The following information is for reference only and not required by the build tools. > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources] > + VmgExitLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + > diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h b/UefiCpuPkg/Include/Library/VmgExitLib.h > new file mode 100644 > index 000000000000..602b213f1f63 > --- /dev/null > +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h > @@ -0,0 +1,111 @@ > +/** @file > + Public header file for the VMGEXIT Support library class. > + > + This library class defines some routines used when invoking the > + VMGEXIT instruction in support of SEV-ES. > + > + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights > + reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef __VMG_EXIT_LIB_H__ > +#define __VMG_EXIT_LIB_H__ > + > +#include > + > + > +/** > + Perform VMGEXIT. > + > + Sets the necessary fields of the GHCB, invokes the VMGEXIT > + instruction and then handles the return actions. > + > + @param[in] GHCB A pointer to the GHCB > + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode field of > + the GHCB. > + @param[in] ExitInfo1 VMGEXIT information to be assigned to the SwExitInfo1 > + field of the GHCB. > + @param[in] ExitInfo2 VMGEXIT information to be assigned to the SwExitInfo2 > + field of the GHCB. > + > + @retval 0 VMGEXIT succeeded. > + @retval Others VMGEXIT processing did not succeed. Exception number to > + be issued. > + > +**/ > +UINTN > +EFIAPI > +VmgExit ( > + GHCB *Ghcb, > + UINT64 ExitCode, > + UINT64 ExitInfo1, > + UINT64 ExitInfo2 > + ); > + > +/** > + Perform pre-VMGEXIT initialization/preparation. > + > + Performs the necessary steps in preparation for invoking VMGEXIT. > + > + @param[in] GHCB A pointer to the GHCB > + > +**/ > +VOID > +EFIAPI > +VmgInit ( > + GHCB *Ghcb > + ); > + > +/** > + Perform post-VMGEXIT cleanup. > + > + Performs the necessary steps to cleanup after invoking VMGEXIT. > + > + @param[in] GHCB A pointer to the GHCB > + > +**/ > +VOID > +EFIAPI > +VmgDone ( > + GHCB *Ghcb > + ); > + > +#define VMGMMIO_READ False > +#define VMGMMIO_WRITE True > + > +/** > + Perform MMIO write of a buffer to a non-MMIO marked range. > + > + Performs an MMIO write without taking a #VC. This is useful for > + Flash devices, which are marked read-only. > + > + @param[in] UINT8 A pointer to the destination buffer > + @param[in] UINTN The immediate value to write > + @param[in] UINTN Number of bytes to write > + > +**/ > +VOID > +EFIAPI > +VmgMmioWrite ( > + UINT8 *Dest, > + UINT8 *Src, > + UINTN Bytes > + ); > + > +/** > + Issue the GHCB set AP Jump Table VMGEXIT. > + > + Performs a VMGEXIT using the GHCB AP Jump Table exit code to save the > + AP Jump Table address with the hypervisor for retrieval at a later time. > + > + @param[in] EFI_PHYSICAL_ADDRESS Physical address of the AP Jump > + Table > + > +**/ > +UINTN > +EFIAPI > +VmgExitSetAPJumpTable ( > + EFI_PHYSICAL_ADDRESS Address > + ); > + > +#endif > diff --git a/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c > new file mode 100644 > index 000000000000..4e7315a58202 > --- /dev/null > +++ b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c > @@ -0,0 +1,187 @@ > +/** @file > + VMGEXIT Support Library. > + > + Copyright (c) 2019, Advanced Micro Devices, Inc. All rights > + reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > + > +STATIC > +UINT64 > +VmgExitErrorCheck ( > + GHCB *Ghcb > + ) > +{ > + GHCB_EVENT_INJECTION Event; > + GHCB_EXIT_INFO ExitInfo; > + UINT64 Status; > + > + ExitInfo.Uint64 = Ghcb->SaveArea.SwExitInfo1; ASSERT > + ((ExitInfo.Elements.Lower32Bits == 0) || > + (ExitInfo.Elements.Lower32Bits == 1)); > + > + Status = 0; > + if (ExitInfo.Elements.Lower32Bits == 0) { > + return Status; > + } > + > + if (ExitInfo.Elements.Lower32Bits == 1) { > + ASSERT (Ghcb->SaveArea.SwExitInfo2 != 0); > + > + // Check that the return event is valid > + Event.Uint64 = Ghcb->SaveArea.SwExitInfo2; > + if (Event.Elements.Valid && > + Event.Elements.Type == GHCB_EVENT_INJECTION_TYPE_EXCEPTION) { > + switch (Event.Elements.Vector) { > + case GP_EXCEPTION: > + case UD_EXCEPTION: > + // Use returned event as return code > + Status = Event.Uint64; > + } > + } > + } > + > + if (Status == 0) { > + GHCB_EVENT_INJECTION Event; > + > + Event.Uint64 = 0; > + Event.Elements.Vector = GP_EXCEPTION; > + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION; > + Event.Elements.Valid = 1; > + > + Status = Event.Uint64; > + } > + > + return Status; > +} > + > +UINT64 > +EFIAPI > +VmgExit ( > + GHCB *Ghcb, > + UINT64 ExitCode, > + UINT64 ExitInfo1, > + UINT64 ExitInfo2 > + ) > +{ > + Ghcb->SaveArea.SwExitCode = ExitCode; > + Ghcb->SaveArea.SwExitInfo1 = ExitInfo1; > + Ghcb->SaveArea.SwExitInfo2 = ExitInfo2; > + > + // > + // Guest memory is used for the guest-hypervisor communication, so > + fence // the invocation of the VMGEXIT instruction to ensure GHCB > + accesses are // synchronized properly. > + // > + MemoryFence (); > + AsmVmgExit (); > + MemoryFence (); > + > + return VmgExitErrorCheck (Ghcb); > +} > + > +VOID > +EFIAPI > +VmgInit ( > + GHCB *Ghcb > + ) > +{ > + SetMem (&Ghcb->SaveArea, sizeof (Ghcb->SaveArea), 0); } > + > +VOID > +EFIAPI > +VmgDone ( > + GHCB *Ghcb > + ) > +{ > +} > + > +UINTN > +EFIAPI > +VmgMmio ( > + UINT8 *MmioAddress, > + UINT8 *Buffer, > + UINTN Bytes, > + BOOLEAN Write > + ) > +{ > + UINT64 MmioOp, ExitInfo1, ExitInfo2, Status; > + GHCB *Ghcb; > + MSR_SEV_ES_GHCB_REGISTER Msr; > + > + Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB); Ghcb = > + Msr.Ghcb; > + > + VmgInit (Ghcb); > + > + if (Write) { > + MmioOp = SvmExitMmioWrite; > + } else { > + MmioOp = SvmExitMmioRead; > + } > + > + ExitInfo1 = (UINT64) (UINTN) MmioAddress; > + ExitInfo2 = Bytes; > + > + if (Write) { > + CopyMem (Ghcb->SharedBuffer, Buffer, Bytes); } > + > + Ghcb->SaveArea.SwScratch = (UINT64) (UINTN) Ghcb->SharedBuffer; > + Status = VmgExit (Ghcb, MmioOp, ExitInfo1, ExitInfo2); if (Status != > + 0) { > + return Status; > + } > + > + if (!Write) { > + CopyMem (Buffer, Ghcb->SharedBuffer, Bytes); } > + > + VmgDone (Ghcb); > + > + return 0; > +} > + > +VOID > +EFIAPI > +VmgMmioWrite ( > + UINT8 *Dest, > + UINT8 *Src, > + UINTN Bytes > + ) > +{ > + VmgMmio (Dest, Src, Bytes, TRUE); > +} > + > +UINTN > +EFIAPI > +VmgExitSetAPJumpTable ( > + EFI_PHYSICAL_ADDRESS Address > + ) > +{ > + UINT64 ExitInfo1, ExitInfo2, Status; > + GHCB *Ghcb; > + MSR_SEV_ES_GHCB_REGISTER Msr; > + > + Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB); Ghcb = > + Msr.Ghcb; > + > + VmgInit (Ghcb); > + > + ExitInfo1 = 0; > + ExitInfo2 = (UINT64) (UINTN) Address; > + > + Status = VmgExit (Ghcb, SvmExitApJumpTable, ExitInfo1, ExitInfo2); > + > + VmgDone (Ghcb); > + > + return Status; > +} > + > diff --git a/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni > new file mode 100644 > index 000000000000..e8656aae4726 > --- /dev/null > +++ b/UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni > @@ -0,0 +1,15 @@ > +// /** @file > +// VMGEXIT support library instance. > +// > +// VMGEXIT support library instance. > +// > +// Copyright (c) 2019, Advanced Micro Devices, Inc. All rights > +reserved.
// SPDX-License-Identifier: BSD-2-Clause-Patent // // **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT Support Library." > + > +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT Support Library." > + > -- > 2.17.1 > > > >