From nobody Tue Feb 10 13:16:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83716+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 163673883534443.27730114965141; Fri, 12 Nov 2021 09:40:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id NjMEYY1788612xZ53Amr5iWo; Fri, 12 Nov 2021 09:40:35 -0800 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.46]) by mx.groups.io with SMTP id smtpd.web11.406.1636738833916188539 for ; Fri, 12 Nov 2021 09:40:34 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TcQ36p08rSs4fQYCaEp3aNQ0nLkvmOb6xT57hQ+Y3J2qoDY9pOfQcTf7YTDUNPrZMeu2PiTR+lNRRLLelEe2fp9kGadh6MOONd3FQ6qs64sMeAFKgaEKxVjyisXgw7tMr+Lg08CV7utMU+/lVFEPa2dru6FERFTLSw/Q9WmSc9lqUCgx1/WFxlM15HP7QmkJ2LEggYxLuDbz/XcbwZWYvXWT5SFZtkzSJUE+fFRBizTqTmkNqrMSOpVsZCn0NI8Bud3Jwm/TZThDNSV81R+EcJe6TDwlHOHdg508TBFIa+4Bkebcem3J3MYzjn4cCkBlO8t8oftZ5DBTWxzKYL4hPg== 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=gqmcH/XH1iKjEQq4jwe5bvc0FS4PxpOdaseRluLWgDg=; b=E9wlU9s/laMjJoNVngWGvI1/w+saFsEPOeUR+fnNABUX63K1QrUEb6oBso+vF7Z9KrapxSSvRIa0w3r1Z36APy+fDIt9wS9T7tSXitOaZ4Rw9HPWsh/Ez/srCZ+c3e5f1mWfEbsVKRW4GhjNOdyz6L5pCFTYGHkVkQ15V05v6MU5SB8K8U2lS3N3L/WtrkDpNAfXCtlRKJINC/UZGovRHzsqxOa2P8blXXlRK0QalVITLVQji3i07LqLxwV0umUoCt96qkHHMRd6DqdSyTHRVVQsgxh+5PcaLtpvygzZDuNcU3BtVoJPqF3bwIspn/oR91HUyUaD6Vo/1u2fFhjroA== 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 X-Received: from BN9PR03CA0325.namprd03.prod.outlook.com (2603:10b6:408:112::30) by CH0PR12MB5188.namprd12.prod.outlook.com (2603:10b6:610:bb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Fri, 12 Nov 2021 17:40:29 +0000 X-Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:112:cafe::e2) by BN9PR03CA0325.outlook.office365.com (2603:10b6:408:112::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+83716+1787277+3901457@groups.io; helo=mail02.groups.io; 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; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:29 +0000 X-Received: from sbrijesh-desktop.amd.com (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.2375.17; Fri, 12 Nov 2021 11:40:28 -0600 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v13 15/32] OvmfPkg/MemEncryptSevLib: add function to check the VMPL0 Date: Fri, 12 Nov 2021 11:39:42 -0600 Message-ID: <20211112173959.2505972-16-brijesh.singh@amd.com> In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-1-brijesh.singh@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-Office365-Filtering-Correlation-Id: 8f59d0a7-bd53-43cd-1c62-08d9a603851b X-MS-TrafficTypeDiagnostic: CH0PR12MB5188: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 4MEdMmOZxEF3QCulGs4DrZLt6xtI35QPoPga34vwVmvXhxw9kJVzsF0QkqG4Unp9yHHnIlUHgrm8C924XjNRdxFr9fTNAXjJodDcnsfT4xtvrgJJgo7kAz9PsqBly/C2kttpljWgcSBDLu1hTuwj/SRJdZNYmCc/Zb6SPhyFwnlPHllKttbmo+OgrpwbmbhAN4LYUNfvFZKfPMSnox6j6S9S7tP3WVJkq2jBscDLQHiJYHpwSznj98S3JsDrm/fNoQlcBp2nSu4hgVvORD7b0CLTjOfBzJke5C78qblwwfDNHqX1ggik8+Fk5lbDdPjMvG25w/it3bxyBEDOvvt5cqBwp40do3kHSVZ2lILc2yXOh3lSTDqGvVCO0NqdeTyFOneK4KyvOkhYKmoW1vPejt0iRI1nftl4jPTkWWOYm1zMJNxYSYkABiQrx9xKz3nbPVo2pqML3DfKbX1d4wEaoVDNnNBJ2WT/FkZcKahuFA/LC6ZiOPjTe0Xqx5vhRz7ec+2BZfgeBUJoUbzsIW3QUX1HIF5bDTAfRZayOJZ62hMwxZLXt8/4t83Tfpzj1x08yb9ne4nZ3hNEieoc925c+ridV/Yq338fqVRStqEtRF5AnvYSiKdwUnlRfHyQeqpbmHfERjB/lYKbEHjxyDpP2GoAjDDNAbTRAtZM/AbmZLQPA3NcQoI0pO1/uAbKrCP+9YsPCaGgnGjWSigodgspvHxqzexyx8wKMJ+XpoBw3/TYKH6kzj1x5+u18cUUM4Iir4iqFD5xKjyJj4EyWkvteXd9fBBGgsUvOfB8j7YAEgaSMk5do7cWCj2FNN2lye2I X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:29.7465 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f59d0a7-bd53-43cd-1c62-08d9a603851b 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: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5188 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,brijesh.singh@amd.com X-Gm-Message-State: edXezYvyNXP8qPSlY9Qk24xax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1636738835; bh=+YY0cxSf10g/UABRagUcQvdyM2ggo+a07UwZj/+G7A8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cmI4agk+R5Gw3dK2+OmH7MvJBeqa+IiGzf+ARViaqDiiNMFMBJZC1ZatbXY2oBWs4lN euQDAuXlrvBwDCxQ34zcnwK3/Ru0UQGNPUo74g5av3NsahbdUZ1jzuxzKBIx3lT4wGgkZ jQgg6e63TG3AaQ84IpT/mn8OrglnqdosZ8U= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636738836521100017 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Virtual Machine Privilege Level (VMPL) feature in the SEV-SNP architecture allows a guest VM to divide its address space into four levels. The level can be used to provide the hardware isolated abstraction layers with a VM. The VMPL0 is the highest privilege, and VMPL3 is the least privilege. Certain operations must be done by the VMPL0 software, such as: * Validate or invalidate memory range (PVALIDATE instruction) * Allocate VMSA page (RMPADJUST instruction when VMSA=3D1) The initial SEV-SNP support assumes that the guest is running on VMPL0. Let's add function in the MemEncryptSevLib that can be used for checking whether guest is booted under the VMPL0. 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: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../X64/SnpPageStateChange.h | 5 ++ .../X64/SecSnpSystemRamValidate.c | 46 +++++++++++++++++++ .../X64/SnpPageStateChangeInternal.c | 1 - 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h = b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h index 8bbdf06468b9..cc1318075523 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h @@ -28,4 +28,9 @@ InternalSetPageState ( IN BOOLEAN UseLargeEntry ); =20 +VOID +SnpPageStateFailureTerminate ( + VOID + ); + #endif diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c index 64aab7f45b6d..3394094a65e5 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c @@ -14,6 +14,43 @@ =20 #include "SnpPageStateChange.h" =20 +// +// The variable used for the VMPL check. +// +STATIC UINT8 gVmpl0Data[4096]; + +/** + The function checks whether SEV-SNP guest is booted under VMPL0. + + @retval TRUE The guest is booted under VMPL0 + @retval FALSE The guest is not booted under VMPL0 + **/ +STATIC +BOOLEAN +SevSnpIsVmpl0 ( + VOID + ) +{ + UINT64 Rdx; + EFI_STATUS Status; + + // + // There is no straightforward way to query the current VMPL level. + // The simplest method is to use the RMPADJUST instruction to change + // a page permission to a VMPL level-1, and if the guest kernel is + // launched at a level <=3D 1, then RMPADJUST instruction will return + // an error. + // + Rdx =3D 1; + + Status =3D AsmRmpAdjust ((UINT64) gVmpl0Data, 0, Rdx); + if (EFI_ERROR (Status)) { + return FALSE; + } + + return TRUE; +} + /** Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. =20 @@ -32,5 +69,14 @@ MemEncryptSevSnpPreValidateSystemRam ( return; } =20 + // + // The page state change uses the PVALIDATE instruction. The instruction + // can be run on VMPL-0 only. If its not VMPL-0 guest then terminate + // the boot. + // + if (!SevSnpIsVmpl0 ()) { + SnpPageStateFailureTerminate (); + } + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); } diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInt= ernal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeIntern= al.c index f9ab804a7edc..cffe703de9dd 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c @@ -40,7 +40,6 @@ MemoryStateToGhcbOp ( return Cmd; } =20 -STATIC VOID SnpPageStateFailureTerminate ( VOID --=20 2.25.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 (#83716): https://edk2.groups.io/g/devel/message/83716 Mute This Topic: https://groups.io/mt/87011885/1787277 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-