From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <bounce+27952+114630+7686176+12367111@groups.io>
Received: from mail02.groups.io (mail02.groups.io [66.175.222.108])
	by spool.mail.gandi.net (Postfix) with ESMTPS id E14A5740035
	for <rebecca@openfw.io>; Fri, 26 Jan 2024 22:14:09 +0000 (UTC)
DKIM-Signature: a=rsa-sha256; bh=ffLRpklkRoDfQQs8gDoxBykh+mMY0rYMAFCtSeNrJKs=;
 c=relaxed/simple; d=groups.io;
 h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type;
 s=20140610; t=1706307248; v=1;
 b=uIxKBFkUrXDLKSvGa/LEWzAoeBtSCs59lbfHVOpoJ78KRX3qtiBLpu9kk+LKWyaqmxerU4LH
 8tkXMrhKa7owVApvmdR81EaMgRBJG70+ibEyKIr2N5kZCGs+YEQaF4sjkFQyoqYhWfmlB+N9OZk
 3Yj61SVukd8RflL3dZl3gNvI=
X-Received: by 127.0.0.2 with SMTP id 68MwYY7687511xUxd4qq21z8; Fri, 26 Jan 2024 14:14:08 -0800
X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.74])
 by mx.groups.io with SMTP id smtpd.web11.2946.1706307247935322962
 for <devel@edk2.groups.io>;
 Fri, 26 Jan 2024 14:14:08 -0800
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=lgHyoy+WFWMJn45N1yflreoI8ElTbEw7Jrhpus+qNOtaAofrNjqN0jGM/QyQUFtSkGahowqpfNg6WqzUIod45yuhOuuzL/WFHgiG2E0N4FywS4nrp4NeaBsxuBoE+yNV/gxyaRIbz1PytLfzyaMApboDqaOl85wow3bLEbMFjnRrLmS9VhWQvZysJjQpKDVvTNJpDDjgVsPVX5lmdheqhAOghgNPgvdd97c+R4LEgcIImeieBu+KgtBI30UY8uFVrCBfEvU9kmg6jWUbNXgBrDo8DNFn+MKdY7kLZy80i2uvG28Rr0iOr55nm9B3LTBlzlJ4isz6RudHtXyp6kxG3w==
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=GbmIEjB0m2PtKHvftIjNjsuGOdnIrdtr5VZsgCY+f6k=;
 b=Whn7VvkJw26LEC220BJfl4cwI9VfnRoxUM0RdoK2DIsXZlV/1FNXJRJvcFBH7yprJvfHN82goWR4YEup04YXqmy3WQr08D5iWdB5dMhbBNQCjA2Q1LeLxxvvi4IvBy+QHc3qEYl1KmuEqwEE3uBSXla0mhDypIfk92kV0fa+Fr6xn79jKMocylCr1vMyF9F9gq5DPgYab4KbGcQLClXZS8/xDG1kQb2k6c//yv0YXdCJH0sXotG4remo/Ctns7rGlTFrofyLWmk8kFVP2ZG6ljJM++9vnINsWGwC7Z+Ttq8uJ9G5un2z7tokwRFyThbyeRfTCkrsEMKQYk1PVgJSkQ==
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 (0)
X-Received: from CY5PR04CA0016.namprd04.prod.outlook.com (2603:10b6:930:1e::13)
 by CH0PR12MB5386.namprd12.prod.outlook.com (2603:10b6:610:d5::5) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Fri, 26 Jan
 2024 22:13:59 +0000
X-Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com
 (2603:10b6:930:1e:cafe::c8) by CY5PR04CA0016.outlook.office365.com
 (2603:10b6:930:1e::13) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27 via Frontend
 Transport; Fri, 26 Jan 2024 22:13:59 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17)
 smtp.mailfrom=amd.com; dkim=none (message not signed)
 header.d=none;dmarc=pass action=none header.from=amd.com;
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; pr=C
X-Received: from SATLEXMB04.amd.com (165.204.84.17) by
 CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.145) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 22:13:59 +0000
X-Received: from tlendack-t1.amdoffice.net (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.2507.34; Fri, 26 Jan 2024 16:13:58 -0600
From: "Lendacky, Thomas via groups.io" <thomas.lendacky=amd.com@groups.io>
To: <devel@edk2.groups.io>
CC: Ard Biesheuvel <ardb+tianocore@kernel.org>, Erdem Aktas
	<erdemaktas@google.com>, Gerd Hoffmann <kraxel@redhat.com>, Jiewen Yao
	<jiewen.yao@intel.com>, Laszlo Ersek <lersek@redhat.com>, Liming Gao
	<gaoliming@byosoft.com.cn>, Michael D Kinney <michael.d.kinney@intel.com>,
	Min Xu <min.m.xu@intel.com>, Zhiguang Liu <zhiguang.liu@intel.com>, "Rahul
 Kumar" <rahul1.kumar@intel.com>, Ray Ni <ray.ni@intel.com>, Michael Roth
	<michael.roth@amd.com>
Subject: [edk2-devel] [PATCH 04/16] UefiCpuPkg/CcExitLib: Extend the CcExitLib library to support an SVSM
Date: Fri, 26 Jan 2024 16:13:03 -0600
Message-ID: <7061a9fb7a184fa0a2354842e834a260398aedc8.1706307195.git.thomas.lendacky@amd.com>
In-Reply-To: <cover.1706307195.git.thomas.lendacky@amd.com>
References: <cover.1706307195.git.thomas.lendacky@amd.com>
MIME-Version: 1.0
X-Originating-IP: [10.180.168.240]
X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com
 (10.181.40.145)
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D2:EE_|CH0PR12MB5386:EE_
X-MS-Office365-Filtering-Correlation-Id: a4133abd-3826-4319-53de-08dc1ebc18a4
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam-Message-Info: 
	3/IQnUm+wehrlcbjYEqLp6xEPS0qJEPsJAtoJdwPv/3Z4K3H0VsYFAUadtiF+DtFefU+s3daAZ3C5Xx1xGtFNVVSFwdAbvx/g8jXJTGB/pZO5qMXiVH7/BrFWbTyzGJ0ALnWMdp3thPkxHSzUf11243GkzIppqJ7oCNDpfNdw2OGI/B5TVL1Hm2Lgh8yO73lcGz3qV6hMhWI35AD5gP+i3C9AvG6+s4hlbCqHLiBRQNiG/NUTS6ugNkQSRoCCUDqxspzOIkqloaYjb4zoMURsFWtMnUB3MkX/igzmoIZm5fOzlo8qN4o4psYa90zYY3HZxLgv3QnJwUXUz1p+ybjWQFOGO56mcKqVuh1FnhNW5JGdFiZWYlTHbqyctBSD7WoCjIaSm39GpEOGzUUF/A2cPNPERJOqia+eJugThE4Bke2R6bembp97dlsoG8TUhaZynmvmPJSKPD2/otCeen8rEd08/R9LC+IRh2rbueLHJjCk64MfI0hlBCTG9dnYz2203eHl3YgsLSfHCPOn/93eA1Gfn3TpLlcUkVk0RDbFm0dp+5kn0coP5Oc7B60T2MlufKnCP/OlvmP+XXO0SMoQgaA9dTeK6/GmE6JLIOE7qEC8e+fW0sv2zhSWDnN2Jv5gPTqkhtmmrYaIETvNLA3Exr7aYLuZzn+LbqTMKySu9jcNze5UCGf3NQJVsLQwUby4aFk7l8OzHGO9RIrTdokCRMsQS1fsBMvKae2llT+OoQi7GOiE3uNwE4Xs9NwavpBmPaYqOap9TVcLKmhzNstlw==
X-OriginatorOrg: amd.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 22:13:59.4781
 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: a4133abd-3826-4319-53de-08dc1ebc18a4
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: 
	CY4PEPF0000E9D2.namprd03.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5386
Precedence: Bulk
List-Subscribe: <mailto:devel+subscribe@edk2.groups.io>
List-Help: <mailto:devel+help@edk2.groups.io>
Sender: devel@edk2.groups.io
List-Id: <devel.edk2.groups.io>
Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io
Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com
List-Unsubscribe-Post: List-Unsubscribe=One-Click
List-Unsubscribe: <https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/plugh>
X-Gm-Message-State: PpITSIDPCFZkTyBWMEjJl7irx7686176AA=
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain
X-GND-Status: LEGIT
Authentication-Results: spool.mail.gandi.net;
	dkim=pass header.d=groups.io header.s=20140610 header.b=uIxKBFkU;
	dmarc=none;
	spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io;
	arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}")

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654

In order to support an SEV-SNP guest running under an SVSM at VMPL1 or
lower, the CcExitLib library must be extended with new intefaces.

This includes an interface to detect if running under an SVSM, an
interface to return the current VMPL, an interface to perform memory
validation and an interface to set or clear the attribute that allows a
page to be used as a VMSA.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 UefiCpuPkg/Include/Library/CcExitLib.h           | 71 ++++++++++++++++-
 UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c | 82 +++++++++++++++++++-
 2 files changed, 151 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Include/Library/CcExitLib.h b/UefiCpuPkg/Include/Li=
brary/CcExitLib.h
index 3381d583691f..2a9de5d5e8e7 100644
--- a/UefiCpuPkg/Include/Library/CcExitLib.h
+++ b/UefiCpuPkg/Include/Library/CcExitLib.h
@@ -6,7 +6,7 @@
      #VC exceptions.
    - Handle #VE exception in TDX.
=20
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR=
>
+  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights reser=
ved.<BR>
   Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
=20
@@ -147,6 +147,75 @@ CcExitHandleVc (
   IN OUT EFI_SYSTEM_CONTEXT  SystemContext
   );
=20
+/**
+  Report the presence of an Secure Virtual Services Module (SVSM).
+
+  Determines the presence of an SVSM.
+
+  @retval  TRUE                   An SVSM is present
+  @retval  FALSE                  An SVSM is not present
+
+**/
+BOOLEAN
+EFIAPI
+CcExitSnpSvsmPresent (
+  VOID
+  );
+
+/**
+  Report the VMPL level at which the SEV-SNP guest is running.
+
+  Determines the VMPL level at which the guest is running. If an SVSM is
+  not present, then it must be VMPL0, otherwise return what is reported
+  by the SVSM.
+
+  @return                         The VMPL level
+
+**/
+UINT8
+EFIAPI
+CcExitSnpGetVmpl (
+  VOID
+  );
+
+/**
+  Perform a PVALIDATE operation for the page ranges specified.
+
+  Validate or rescind the validation of the specified pages.
+
+  @param[in]       Info           Pointer to a page state change structure
+
+**/
+VOID
+EFIAPI
+CcExitSnpPvalidate (
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  );
+
+/**
+  Perform an RMPADJUST operation to alter the VMSA setting of a page.
+
+  Add or remove the VMSA attribute for a page.
+
+  @param[in]       Vmsa           Pointer to an SEV-ES save area page
+  @param[in]       ApicId         APIC ID associated with the VMSA
+  @param[in]       SetVmsa        Boolean indicator as to whether to set o=
r
+                                  or clear the VMSA setting for the page
+
+  @retval  EFI_SUCCESS            RMPADJUST operation successful
+  @retval  EFI_UNSUPPORTED        Operation is not supported
+  @retval  EFI_INVALID_PARAMETER  RMPADJUST operation failed, an invalid
+                                  parameter was supplied
+
+**/
+EFI_STATUS
+EFIAPI
+CcExitSnpVmsaRmpAdjust (
+  IN SEV_ES_SAVE_AREA  *Vmsa,
+  IN UINT32            ApicId,
+  IN BOOLEAN           SetVmsa
+  );
+
 /**
   Handle a #VE exception.
=20
diff --git a/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c b/UefiCpuPkg/=
Library/CcExitLibNull/CcExitLibNull.c
index 230e50705b4a..60b19c0433c7 100644
--- a/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c
+++ b/UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.c
@@ -1,7 +1,7 @@
 /** @file
   CcExit Base Support Library.
=20
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR=
>
+  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights reser=
ved.<BR>
   Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
=20
@@ -165,6 +165,86 @@ CcExitHandleVc (
   return EFI_UNSUPPORTED;
 }
=20
+/**
+  Report the presence of an Secure Virtual Services Module (SVSM).
+
+  Determines the presence of an SVSM.
+
+  @retval  TRUE                   An SVSM is present
+  @retval  FALSE                  An SVSM is not present
+
+**/
+BOOLEAN
+EFIAPI
+CcExitSnpSvsmPresent (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Report the VMPL level at which the SEV-SNP guest is running.
+
+  Determines the VMPL level at which the guest is running. If an SVSM is
+  not present, then it must be VMPL0, otherwise return what is reported
+  by the SVSM.
+
+  @return                         The VMPL level
+
+**/
+UINT8
+EFIAPI
+CcExitSnpGetVmpl (
+  VOID
+  )
+{
+  return 0;
+}
+
+/**
+  Perform a PVALIDATE operation for the page ranges specified.
+
+  Validate or rescind the validation of the specified pages.
+
+  @param[in]       Info           Pointer to a page state change structure
+
+**/
+VOID
+EFIAPI
+CcExitSnpPvalidate (
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  )
+{
+}
+
+/**
+  Perform an RMPADJUST operation to alter the VMSA setting of a page.
+
+  Add or remove the VMSA attribute for a page.
+
+  @param[in]       Vmsa           Pointer to an SEV-ES save area page
+  @param[in]       ApicId         APIC ID associated with the VMSA
+  @param[in]       SetVmsa        Boolean indicator as to whether to set o=
r
+                                  or clear the VMSA setting for the page
+
+  @retval  EFI_SUCCESS            RMPADJUST operation successful
+  @retval  EFI_UNSUPPORTED        Operation is not supported
+  @retval  EFI_INVALID_PARAMETER  RMPADJUST operation failed, an invalid
+                                  parameter was supplied
+
+**/
+EFI_STATUS
+EFIAPI
+CcExitSnpVmsaRmpAdjust (
+  IN SEV_ES_SAVE_AREA  *Vmsa,
+  IN UINT32            ApicId,
+  IN BOOLEAN           SetVmsa
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
 /**
   Handle a #VE exception.
=20
--=20
2.42.0



-=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 (#114630): https://edk2.groups.io/g/devel/message/114630
Mute This Topic: https://groups.io/mt/103986445/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-