From nobody Wed Feb 11 06:00:00 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+81915+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 1634144285091908.0658788184489; Wed, 13 Oct 2021 09:58:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hFBLYY1788612xuxvsvTCCMi; Wed, 13 Oct 2021 09:58:04 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.86]) by mx.groups.io with SMTP id smtpd.web10.105.1634144283064165063 for ; Wed, 13 Oct 2021 09:58:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gx2poHyidZWicU9QWUaXF791HkLsjncIeluZDTF50IClXI6ljrsHA/aq7HD2O45WcLrCSKbx1oSp72W3db5BZMSfzPbkVAwFkBtkLXZulqvvrP8YVO30GiJD2k6xxr6GHJ2pBHrvDV+KgDye5/BLek83g7CwJI1tc8oJYSUEnVd6uN3ndnkYsldJCyncIPSXH3lXlWbnABfHqiJZtZoYS3DsS0AaR96FJBZVZ905xMvsMjni/pjkWun/qooTi5gshTlM7Hr8wYbENUwaW4e3Ap3CfhHuTHUu9cFQQSmU0Xcc7GEMgwDkaMjpl4CuAlNU5Lbn7o75RLjiFvuc1h4aVg== 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=X6r0nD7n4uJBJCtDmtwm4mGO8ZKKhmFquzC2PjW0W9c=; b=FhoKuFAOp0p4E3spjRAofHK275uBauo+8uDRRck98XiYxnumFFMA2ndgNfaBPdyohvFFChoOgxZvna3QJ511GiKfBEwgyHFt6ydrPmUUylCqPR1UDNzavEz+cFRytuMYvJm+NOSRuu+ikG4i+ae3AvGRzvOSEC/7fLk9T4HK/ERu51Fm0996TlwmTghJPiAKRi87HNax5z7Sa6pVNOwRgPhjmB2NA42VbsLvq93SyVbQUsihc8vaAwiwH4Xgs7p9afjkTBB6da+NPoJUjGZqhQbEeWE+omHYAjwjWESJ5EOMqBB4zvyn19h2y/WwGbz4J5WP64Phyg6JGuaNk12rHA== 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 MWHPR11CA0022.namprd11.prod.outlook.com (2603:10b6:301:1::32) by DM6PR12MB3628.namprd12.prod.outlook.com (2603:10b6:5:3d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:58:00 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::78) by MWHPR11CA0022.outlook.office365.com (2603:10b6:301:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Wed, 13 Oct 2021 16:58:00 +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+81915+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 CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:00 +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.2308.8; Wed, 13 Oct 2021 11:57:58 -0500 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 , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v9 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Wed, 13 Oct 2021 11:57:09 -0500 Message-ID: <20211013165713.727815-29-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2206867b-3b6b-42a3-0c93-08d98e6a9d1c X-MS-TrafficTypeDiagnostic: DM6PR12MB3628: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: b0oSaR4YaYDfln/I5DXxIacM8nPIYsGYWcAnw83FA3bhsh0bJoW5HlpvDK5GltXOGY77E6O0mFVmBiAB+2jdf4bXhtCs9PuIe9K0yokt9hf3LhcNgr/Bn9XwyYBEDeoeJAUvozfsEk/N/cDkJ4bohWX5aFM3GJoKzDVF17PRqv1Tc2vkY3kvH9FttCXwmcnNv3W1qpF90HND9W3HD6mn7AcG0UHk9TSwVEu81KrWoF0kw60TOGs5UoVIJeX/gF2bUSYRYdljoD+XHstAXutafWloSzhtj9l1OrUFXIF9DqVZtnI1afajRw/z8v5esvhPhnK9dWNNn4qG4Uh9qmGktTHuj38qIRz6GfMHFY6Z85DGN0pdwVMG2C3pj0F8r9oXobYVn5nTXbCaLFHmW7oE2FUub47Aa3xFWPNamj9m/OLaDFm5mKRfQXwm7/9+7/TedqeEainki7jjRt7braKMieFTl1gA7SeIa/3/VIDzYATDSXBD6f+tB2x0maD7Pah+cCoXGuH/68hMIFCGipHYZ5Z10W2H1L58shU/daQs65OvgMq1svc1bAqY81aj/cZizeA1vgPGIIjhpHyjQPaSPus0yLhBDpQ7l8+XKCv933+U8DbNK7EdIpht4c6I/NWKYvFkhrdQTBfOhO7b6WJva7xYzt5Wb13zHN1nne+BNxjaMpHeZGEedK+NHzpDEpJbOm9ZP13i83g4xnmkbxgFjHmE3q92ituGx05t1+S6My+qpMKw58ED8zKUpfBl6Y0bIHfh5X2LUhic6+HTEgA5tCJcZG3fjCUcXGldUqmw55MEqm9wCnJiiYjulPc0GEHo X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:00.1727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2206867b-3b6b-42a3-0c93-08d98e6a9d1c 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3628 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: OIVGeCVYRCdekIRnRd59krYex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144284; bh=iDfmDPKGpHkcirsfhMJ8uimpZbR4XGO6k3ElNEyJYSo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GrTdFB0w6+lqKW11BPiv7whCgjynk/UgaOKYUiPsmBSc36P+bjzDC5PXdtMfW9JEArT JCEJE3Un5egV5QCweYS119JfBNoVkpES+64SVynVBRzwofqGlpwH/CXy5hipsljmvLE18 xIhpmkPwEJKBui4vQvXkvpMlGKcMcM08pC4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144285419100035 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSev{Set,Clear}PageEncMask() functions are used to set or clear the memory encryption attribute in the page table. When SEV-SNP is active, we also need to change the page state in the RMP table so that it is in sync with the memory encryption attribute change. 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: Jiewen Yao Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- .../X64/PeiDxeVirtualMemory.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index f146f6d61cc5..56db1e4b6ecf 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -17,6 +17,7 @@ #include =20 #include "VirtualMemory.h" +#include "SnpPageStateChange.h" =20 STATIC BOOLEAN mAddressEncMaskChecked =3D FALSE; STATIC UINT64 mAddressEncMask; @@ -695,10 +696,12 @@ SetMemoryEncDec ( PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; PAGE_TABLE_ENTRY *PageDirectory2MEntry; + PHYSICAL_ADDRESS OrigPhysicalAddress; PAGE_TABLE_4K_ENTRY *PageTableEntry; UINT64 PgTableMask; UINT64 AddressEncMask; BOOLEAN IsWpEnabled; + UINTN OrigLength; RETURN_STATUS Status; =20 // @@ -751,6 +754,22 @@ SetMemoryEncDec ( =20 Status =3D EFI_SUCCESS; =20 + // + // To maintain the security gurantees we must set the page to shared in = the RMP + // table before clearing the memory encryption mask from the current pag= e table. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); + } + + // + // Save the specified length and physical address (we need it later). + // + OrigLength =3D Length; + OrigPhysicalAddress =3D PhysicalAddress; + while (Length !=3D 0) { // @@ -923,6 +942,21 @@ SetMemoryEncDec ( // CpuFlushTlb(); =20 + // + // SEV-SNP requires that all the private pages (i.e pages mapped encrypt= ed) must be + // added in the RMP table before the access. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D SetCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState ( + OrigPhysicalAddress, + EFI_SIZE_TO_PAGES (OrigLength), + SevSnpPagePrivate, + FALSE + ); + } + Done: // // Restore page table write protection, if any. --=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 (#81915): https://edk2.groups.io/g/devel/message/81915 Mute This Topic: https://groups.io/mt/86292915/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-