From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.78]) by mx.groups.io with SMTP id smtpd.web10.11887.1667572498762175753 for ; Fri, 04 Nov 2022 07:34:59 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=M0S66shh; 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.93.78, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CT3WwKJbyuukMDN9vZLESflj7sjRD8sKly7XK2g8QR2r9ru8hNu+x/jlArQMTD8CMe2gPXYCkQ3HS3RP5xzVY36KMuFdHbvs1dTjBx63O3ggsu3ulR6+3uwgGlyLkekk2cw2LET8G2TQhzp1H1GiiYjTanIEcuf20OHpdg8ezFeAGyszcxFnJJPHoCm9CX4qdDb4jHjQSKeKmTr5WyBc710UYYnEOIvfHs3fQy+MX2emUcOUvgdF5fsrsnh/7dtrjAcyJ0fkMmDIu9w+o2hYHTvWIV4cBLaF9LUwiPyA182GnIPCQAAgF9W3oNmbsiZ1hWB5H9EaeZvEyeD8Dy5YKQ== 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=tpwpVzx68GlJpUX9i6bYUlb7XCIcYRJs8UsPbAFYENU=; b=HjEQl6JnkPGeXOpl9JGpZaXKep9/2dIuOqqxdaM6vP3UyMWjV9/q9A+rutwhfr5hSsBbD/SPOvu5qhxabhXKsSE5378a8VrzKKudO+KDxnTvGGGXNZoQUwyWZ8Ek/QV5VfH24QhRzm0Q6JtuzAWd5ONNTGcJtIY1cXQpRwINB8nwvjh3zPF5Kfy0u4JrcQdU2KNS95PG2R4soDw/eZaDtqh6ngEGDHTmnPUn+F0whZsKdkZl5VWP+Y+/+cdteGxSF5kqUbSkf7/TpStnTQ5l28xvDT1UgX7PBrJD/qJIQkiXx2h+aNDwE6cGlQ1GlwDBGxXm/VzQeBNdm+b/lTyvfQ== 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=tpwpVzx68GlJpUX9i6bYUlb7XCIcYRJs8UsPbAFYENU=; b=M0S66shhcyoi2XOLXy9ZtTpPeArPtr+KMu6xrfuJ3QnIDQ/fN7jbjr3FkJa3zypKLMysz0fRuf8ocl2rHFXIT+WVpH/u9pC8c0RlKSPmmXieQQu/AEgAQxT//znWOr/0kipFNrTFLcFRcOerhy/FancG0snolPj7BBcy0/k7tw8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by PH7PR12MB8037.namprd12.prod.outlook.com (2603:10b6:510:27d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.16; Fri, 4 Nov 2022 14:34:56 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::4da8:e3eb:20eb:f00]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::4da8:e3eb:20eb:f00%2]) with mapi id 15.20.5791.022; Fri, 4 Nov 2022 14:34:56 +0000 Message-ID: <605a9164-ddfa-8400-70a6-c72d6458676c@amd.com> Date: Fri, 4 Nov 2022 09:34:53 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [edk2-devel] [PATCH V2 1/9] UefiCpuPkg: Add CcExitLib To: devel@edk2.groups.io, min.m.xu@intel.com Cc: Eric Dong , Ray Ni , Brijesh Singh , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao References: <20221103231955.1365-1-min.m.xu@intel.com> <20221103231955.1365-2-min.m.xu@intel.com> From: "Lendacky, Thomas" In-Reply-To: <20221103231955.1365-2-min.m.xu@intel.com> X-ClientProxiedBy: BL1P222CA0006.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::11) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|PH7PR12MB8037:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a538d66-0c0c-4704-7e3a-08dabe71be28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 877cIqcMaGAdPmDiKH7dKrXcUeveg4DaDWHgUNHB+4lZwM18TimkMWND/vRnSzHJyqCQuKbjzimH8ippV6QNmln35qCuFk24pgdxVqedRATD9GQC3tIp2FzzeR7tkeqSs5JpKanJue/W6BTvVUWhlrKFMgrP/wMSAGN38Tb4Qk7Q7HVYD4fTcU2X8rk53O/MKdnCsfCbIv3KMNldxJONz/sCd4K0CKdyuI3skah1DMxwF7sh6B4FlolXNXi+0vs5idCSEaE/Oxj17VMWr8hU1rvMuO4smXiQW1ClojQOYRXeZyE9fOMbDZLaOQlS7dxrNImZUhwO0WuincTwGjQqs6wfzPzt7m07d6hNkOWoo32k8diVnMxElSSX0FbBKdJLYi6XMfBI2p1hdxShdcCd9XixVFvHUNk4xIE+4+7LCMPQs8XJCKVunSSuAySwlaer9DUWxD7OW8qyxLWUGeT/JTiP7T4WkcUA/fjjwmTPXsZEA6wEhBM7wQIfP6AOgBMbFkRc445h/nSk3EVFev5VuvJukN4DjIQGfJQHoOaMTauf4ahULPqcb3L4V6kL4p76VHF9DmdYZtKEfo/IgHXxHJvWnGI3HSSrr2uPy2MyJg+CwsCSzJawHCjBkPTSsQmvK7iYOyevUBvgX7IGZiP3V794ts3tKBfabgJSwybgU0sC9j83hZFAhBVjI9gRUUpkEB6rml/bEoHFy+oHf5mw4gwaZNZk/8/IlSBCg86nRacNX9Lpc+tJkFOB0eN9JJiGBaFhtrAJD8rn3Ugr42AJyJwYrtzWwu9pxtKctvqIUI5l4ljQEfY+QdYlX55D6FmBOCCAq/flGRDoY68HSPvJ5w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(6029001)(4636009)(376002)(396003)(136003)(39860400002)(366004)(346002)(451199015)(966005)(31696002)(6486002)(54906003)(2616005)(36756003)(86362001)(4326008)(6506007)(8676002)(186003)(66476007)(66556008)(53546011)(66946007)(316002)(6512007)(478600001)(31686004)(8936002)(6666004)(38100700002)(26005)(5660300002)(2906002)(41300700001)(30864003)(83380400001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TVZISG5JOFdiZU15V1dPUWpoOVRIc2l0NUs4bHlCcDZwK0JGVHFKMDNhb1Az?= =?utf-8?B?d0hUTWJ5WlQyNUlWVUh3TVZzUE8vRm5xM0dJNjcrSER5WTk5VHkwSkltb3dt?= =?utf-8?B?d3EvU1FzZytxZEVPU2JMb0hHd1J3NFFFYy9rTHFxRjJ1Y2lvTE9FRVpKMXJ5?= =?utf-8?B?T2d0Qm93MmRpTEpWdkpXbzZQTlVMUVBnUG5id0VLYWRD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MelpVeXJDZXhhUHFzQVlmUWdXOEY5aHNl?= =?utf-8?B?dW16WFEwdU1VQjd6VGlpaTdpMzE3K3F1S09hU0tHZXVzb0xnZll2UHFML3Fm?= =?utf-8?Q?owTZRL4vgqogHp1EG4y36r/03?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a538d66-0c0c-4704-7e3a-08dabe71be28 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 14:34:56.0701 (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: hAixbNuaLWTYMd3HZ8HC1yw9BK8g3R2p7egVbNer5ShHiuQZrB/7/r55PFb2O+XRTgADJ+AY9Fe6p4TxmjsfZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8037 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/3/22 18:19, Min Xu via groups.io wrote: > From: Min M Xu > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4123 > > CcExitLib is designed to support handling #VC/#VE exceptions and issuing > VMGEXIT instructions. It can be used to perform these: > - Handling #VC exceptions > - Handling #VE exceptions > - Preparing for and issuing a VMGEXIT > - Performing MMIO-related write operations to support flash emulation > - Performing AP related boot opeations > > The base functions in this driver will not do anything and will return > an error if a return value is required. It is expected that other packages > (like OvmfPkg) will create a version of the library to fully support an > CC gueste (such as SEV-ES and TDX). > > Cc: Eric Dong > Cc: Ray Ni > Cc: Brijesh Singh > Cc: Erdem Aktas > Cc: Gerd Hoffmann > Cc: James Bottomley > Cc: Jiewen Yao > Cc: Tom Lendacky > Signed-off-by: Min Xu > --- > UefiCpuPkg/Include/Library/CcExitLib.h | 176 ++++++++++++++++ > .../Library/CcExitLibNull/CcExitLibNull.c | 194 ++++++++++++++++++ > .../Library/CcExitLibNull/CcExitLibNull.inf | 28 +++ > .../Library/CcExitLibNull/CcExitLibNull.uni | 14 ++ > UefiCpuPkg/UefiCpuPkg.dec | 3 + > 5 files changed, 415 insertions(+) > create mode 100644 UefiCpuPkg/Include/Library/CcExitLib.h > create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c > create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf > create mode 100644 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.uni > > diff --git a/UefiCpuPkg/Include/Library/CcExitLib.h b/UefiCpuPkg/Include/Library/CcExitLib.h > new file mode 100644 > index 000000000000..40372e10b39e > --- /dev/null > +++ b/UefiCpuPkg/Include/Library/CcExitLib.h > @@ -0,0 +1,176 @@ > +/** @file > + Public header file for the CcExitLib. > + > + This library class defines some routines used for below CcExit handler. > + - Invoking the VMGEXIT instruction in support of SEV-ES and to handle > + #VC exceptions. > + - Handle #VE exception in TDX. > + > + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> + Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef CC_EXIT_LIB_H_ > +#define CC_EXIT_LIB_H_ > + > +#include > +#include > + > +#define VE_EXCEPTION 20 > + > +/** > + Perform VMGEXIT. > + > + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and > + then handles the return actions. > + > + @param[in, out] 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. > + @return Exception number to be propagated, VMGEXIT > + processing did not succeed. > + > +**/ > +UINT64 > +EFIAPI > +CcExitLibVmgExit ( > + IN OUT GHCB *Ghcb, > + IN UINT64 ExitCode, > + IN UINT64 ExitInfo1, > + IN UINT64 ExitInfo2 > + ); > + > +/** > + Perform pre-VMGEXIT initialization/preparation. > + > + Performs the necessary steps in preparation for invoking VMGEXIT. Must be > + called before setting any fields within the GHCB. > + > + @param[in, out] Ghcb A pointer to the GHCB > + @param[in, out] InterruptState A pointer to hold the current interrupt > + state, used for restoring in CcExitLibVmgDone () > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgInit ( > + IN OUT GHCB *Ghcb, > + IN OUT BOOLEAN *InterruptState > + ); > + > +/** > + Perform post-VMGEXIT cleanup. > + > + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be > + called after obtaining needed fields within the GHCB. > + > + @param[in, out] Ghcb A pointer to the GHCB > + @param[in] InterruptState An indicator to conditionally (re)enable > + interrupts > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgDone ( > + IN OUT GHCB *Ghcb, > + IN BOOLEAN InterruptState > + ); > + > +/** > + Marks a specified offset as valid in the GHCB. > + > + The ValidBitmap area represents the areas of the GHCB that have been marked > + valid. Set the bit in ValidBitmap for the input offset. > + > + @param[in, out] Ghcb A pointer to the GHCB > + @param[in] Offset Qword offset in the GHCB to mark valid > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgSetOffsetValid ( > + IN OUT GHCB *Ghcb, > + IN GHCB_REGISTER Offset > + ); > + > +/** > + Checks if a specified offset is valid in the GHCB. > + > + The ValidBitmap area represents the areas of the GHCB that have been marked > + valid. Return whether the bit in the ValidBitmap is set for the input offset. > + > + @param[in] Ghcb A pointer to the GHCB > + @param[in] Offset Qword offset in the GHCB to mark valid > + > + @retval TRUE Offset is marked valid in the GHCB > + @retval FALSE Offset is not marked valid in the GHCB > + > +**/ > +BOOLEAN > +EFIAPI > +CcExitLibVmgIsOffsetValid ( > + IN GHCB *Ghcb, > + IN GHCB_REGISTER Offset > + ); > + > +/** > + Handle a #VC exception. > + > + Performs the necessary processing to handle a #VC exception. > + > + The base library function returns an error equal to VC_EXCEPTION, > + to be propagated to the standard exception handling stack. > + > + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set > + as value to use on error. > + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT > + > + @retval EFI_SUCCESS Exception handled > + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to > + propagate provided > + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to > + propagate provided > + > +**/ > +EFI_STATUS > +EFIAPI > +CcExitHandleVc ( Sorry I didn't pick up on this before, but any reason this isn't CcExitLibHandleVc() to match the other APIs or have the other APIs just be CcExit (since the "Lib" part seems a bit excessive)? (Same for CcExitHandleVe below) Thanks, Tom > + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, > + IN OUT EFI_SYSTEM_CONTEXT SystemContext > + ); > + > +/** > + Handle a #VE exception. > + > + Performs the necessary processing to handle a #VE exception. > + > + The base library function returns an error equal to VE_EXCEPTION, > + to be propagated to the standard exception handling stack. > + > + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set > + as value to use on error. > + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT > + > + @retval EFI_SUCCESS Exception handled > + @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to > + propagate provided > + @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to > + propagate provided > + > +**/ > +EFI_STATUS > +EFIAPI > +CcExitHandleVe ( > + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, > + IN OUT EFI_SYSTEM_CONTEXT SystemContext > + ); > + > +#endif > diff --git a/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c > new file mode 100644 > index 000000000000..bd23793f1e04 > --- /dev/null > +++ b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c > @@ -0,0 +1,194 @@ > +/** @file > + CcExit Base Support Library. > + > + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> + Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > + > +/** > + Perform VMGEXIT. > + > + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and > + then handles the return actions. > + > + The base library function returns an error in the form of a > + GHCB_EVENT_INJECTION representing a GP_EXCEPTION. > + > + @param[in, out] 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. > + @return Exception number to be propagated, VMGEXIT > + processing did not succeed. > + > +**/ > +UINT64 > +EFIAPI > +CcExitLibVmgExit ( > + IN OUT GHCB *Ghcb, > + IN UINT64 ExitCode, > + IN UINT64 ExitInfo1, > + IN UINT64 ExitInfo2 > + ) > +{ > + GHCB_EVENT_INJECTION Event; > + > + Event.Uint64 = 0; > + Event.Elements.Vector = GP_EXCEPTION; > + Event.Elements.Type = GHCB_EVENT_INJECTION_TYPE_EXCEPTION; > + Event.Elements.Valid = 1; > + > + return Event.Uint64; > +} > + > +/** > + Perform pre-VMGEXIT initialization/preparation. > + > + Performs the necessary steps in preparation for invoking VMGEXIT. Must be > + called before setting any fields within the GHCB. > + > + @param[in, out] Ghcb A pointer to the GHCB > + @param[in, out] InterruptState A pointer to hold the current interrupt > + state, used for restoring in CcExitLibVmgDone () > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgInit ( > + IN OUT GHCB *Ghcb, > + IN OUT BOOLEAN *InterruptState > + ) > +{ > +} > + > +/** > + Perform post-VMGEXIT cleanup. > + > + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be > + called after obtaining needed fields within the GHCB. > + > + @param[in, out] Ghcb A pointer to the GHCB > + @param[in] InterruptState An indicator to conditionally (re)enable > + interrupts > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgDone ( > + IN OUT GHCB *Ghcb, > + IN BOOLEAN InterruptState > + ) > +{ > +} > + > +/** > + Marks a field at the specified offset as valid in the GHCB. > + > + The ValidBitmap area represents the areas of the GHCB that have been marked > + valid. Set the bit in ValidBitmap for the input offset. > + > + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication Block > + @param[in] Offset Qword offset in the GHCB to mark valid > + > +**/ > +VOID > +EFIAPI > +CcExitLibVmgSetOffsetValid ( > + IN OUT GHCB *Ghcb, > + IN GHCB_REGISTER Offset > + ) > +{ > +} > + > +/** > + Checks if a specified offset is valid in the GHCB. > + > + The ValidBitmap area represents the areas of the GHCB that have been marked > + valid. Return whether the bit in the ValidBitmap is set for the input offset. > + > + @param[in] Ghcb A pointer to the GHCB > + @param[in] Offset Qword offset in the GHCB to mark valid > + > + @retval TRUE Offset is marked valid in the GHCB > + @retval FALSE Offset is not marked valid in the GHCB > + > +**/ > +BOOLEAN > +EFIAPI > +CcExitLibVmgIsOffsetValid ( > + IN GHCB *Ghcb, > + IN GHCB_REGISTER Offset > + ) > +{ > + return FALSE; > +} > + > +/** > + Handle a #VC exception. > + > + Performs the necessary processing to handle a #VC exception. > + > + The base library function returns an error equal to VC_EXCEPTION, > + to be propagated to the standard exception handling stack. > + > + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set > + as value to use on error. > + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT > + > + @retval EFI_SUCCESS Exception handled > + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value to > + propagate provided > + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception value to > + propagate provided > + > +**/ > +EFI_STATUS > +EFIAPI > +CcExitHandleVc ( > + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, > + IN OUT EFI_SYSTEM_CONTEXT SystemContext > + ) > +{ > + *ExceptionType = VC_EXCEPTION; > + > + return EFI_UNSUPPORTED; > +} > + > +/** > + Handle a #VE exception. > + > + Performs the necessary processing to handle a #VE exception. > + > + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be set > + as value to use on error. > + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT > + > + @retval EFI_SUCCESS Exception handled > + @retval EFI_UNSUPPORTED #VE not supported, (new) exception value to > + propagate provided > + @retval EFI_PROTOCOL_ERROR #VE handling failed, (new) exception value to > + propagate provided > + > +**/ > +EFI_STATUS > +EFIAPI > +CcExitHandleVe ( > + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, > + IN OUT EFI_SYSTEM_CONTEXT SystemContext > + ) > +{ > + *ExceptionType = VE_EXCEPTION; > + > + return EFI_UNSUPPORTED; > +} > diff --git a/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf > new file mode 100644 > index 000000000000..c1f53e42dbe4 > --- /dev/null > +++ b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf > @@ -0,0 +1,28 @@ > +## @file > +# CcExit Base Support Library. > +# > +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> +# Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = CcExitLibNull > + MODULE_UNI_FILE = CcExitLibNull.uni > + FILE_GUID = 4029bbf2-ed6c-4cf6-ac17-a0213684ae41 > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = CcExitLib > + > +[Sources.common] > + CcExitLibNull.c > + > +[Packages] > + MdePkg/MdePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + > diff --git a/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.uni b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.uni > new file mode 100644 > index 000000000000..b18ae8792ed7 > --- /dev/null > +++ b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.uni > @@ -0,0 +1,14 @@ > +// /** @file > +// CcExitLib instance. > +// > +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> +// Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
> +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "CcExitLib NULL instance" > + > +#string STR_MODULE_DESCRIPTION #language en-US "CcExitLib NULL instance." > + > diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec > index 718323d9042c..8058b679412f 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dec > +++ b/UefiCpuPkg/UefiCpuPkg.dec > @@ -56,6 +56,9 @@ > ## @libraryclass Provides function to support VMGEXIT processing. > VmgExitLib|Include/Library/VmgExitLib.h > > + ## @libraryclass Provides function to support CcExit processing. > + CcExitLib|Include/Library/CcExitLib.h > + > ## @libraryclass Provides function to get CPU cache information. > CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h >