From nobody Mon Feb 9 20:34:54 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+84565+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020567581203.42174806220635; Wed, 8 Dec 2021 19:29:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dSwQYY1788612xZNYYyUvK88; Wed, 08 Dec 2021 19:29:27 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.43]) by mx.groups.io with SMTP id smtpd.web11.6945.1639020566617812919 for ; Wed, 08 Dec 2021 19:29:26 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PyhFknOm8LHz+zSdJ0Sb8WQS90R+LEhCip1NkwlJyHSI6ehTKm2fD4/1NWNRWRVVYhEllb283BFjOlbBWURZhO0dgwK0mjz7qwbu9xBdJ4HNOzIAewAzGrWPgFD3xR9XK/OVdRV1CajdUeBTvmJOFNhtoKccjeRSYAz29xiDa/6JeBxDIppWcFmj/JILPOLEAOw6CTcsBODrWBRN4s81xg0dcyesjNcH+AsGerZGgTOZge9/Od+PktK/UGu+OQrDM52pY9Ld3PFzFNitW854wfrRy/27q1XQAtkH/CeF/w7kuC6VDIsVzZTNkcK54HZFim8dgBJJ4VqJzWarMO3evg== 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=U5IHDWwx5eEvEn+S9y8BqdCO1Vpl2Bp91uBmvKjsET0=; b=KvmDGP/rWGqojJ9hF+7MqkChP9jMaTHUlZ5+Q+4cQX46TrsMsfVTZWDBTXKth1uW4TAm3ekmSnIuVfZI4qisULzkO+XjvJdspGOMaYNq+42l8bRQP9Exsge3hH4ULHfP9kh00TwYTJeNH0D9POInG+EAJ1zXjap92oc/SjvUEocrDGgSMO1jWE06BDS+yaOY9V41ObNncgAlSPPs7qAdWRbZrcyw4ySmz8qwNqpTdykk4X2p2VenJkM7AEY9QbmeYrSzINZ52efACCy4FbYqV+kIBVRo0UgeRhU8UT7RKQRt9pY4OuARrCJyuEa/yb3RWP7ZUPQ0j8qUWP/VG61xOQ== 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 CO2PR04CA0201.namprd04.prod.outlook.com (2603:10b6:104:5::31) by SA0PR12MB4574.namprd12.prod.outlook.com (2603:10b6:806:94::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.19; Thu, 9 Dec 2021 03:29:23 +0000 X-Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::5a) by CO2PR04CA0201.outlook.office365.com (2603:10b6:104:5::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12 via Frontend Transport; Thu, 9 Dec 2021 03:29:23 +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 (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84565+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT031.mail.protection.outlook.com (10.13.174.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 03:29:23 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 8 Dec 2021 21:29:20 -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 , Jiewen Yao Subject: [edk2-devel] [PATCH v14 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Wed, 8 Dec 2021 21:27:56 -0600 Message-ID: <20211209032800.3802995-29-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d75a11c9-ba06-4ef3-0e63-08d9bac4183e X-MS-TrafficTypeDiagnostic: SA0PR12MB4574:EE_ 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: 8JZttarudDzvB8usqvWWgxjx2oUKpvlCfy86FSCLZLJU3frFMf1BJYZSVV7NDLvsa1qmMtpinQNOaJM4tAzLkI/fNJK7bdXI/PN89JkOs8uklkrM05bXUkJBGepx+rZ9vQUrq5eSnc/8mHYy+JMIPfGbThFfm97kexIzcOqIZLYuZxPDXcxR62W4scpxvs+xH8sjba9rxeVAphgJJKo/ml9/FzpSTLCUZmUKyeYwgugqJQNTq+KYH1LNYHSeYBw+V4Vbk/WD/86zjCa702CKCwSFLqydEt1xGhXR+Sw4YBnEme6t0tMPfdeL88jH6lCGfLoTTkZHiKuiqUHF7wXji+C6M3uZpIjdBHELzHsI+jsyg2uy3VPrJdCiBPyDyPW+DXDzX7eOaI3ZKWWMqfaVdgCsdZfXyARoZB4/wdfAosLbiur0v0DHS7d59CjKzlo+lSilT9XSqXiAaNU+ak6OMrewBb3H7i1PytBt/8ft9JNSIqUd2oIyWpJ7mxP+vkBr144rPBQuBTwNvc9++aOM+AZFcToqdFSfA8k2SY99Qg2dn68oq/BZQKLxUkwc2zW65T4We1yTxkCwVQB4i1kdauCPAcnDKmRKKhbuGwuJEe2njL3Pfv9jtqa2PrmqCTAuUlISsM1/3gjwPWKeENrOO8p3Uehmx/ifzAhGVutw7UboN9kYipVM+WuaDo5ERvUcK0N791idgjQ13r658ylM5VlhkdMKJDQ1DPD8CCbKNmKMYk8Q1z8tEq5ZSByR1qqm/2A0RfiUJL2ye9QST8SOfSlbLIKJPCFKE/ddINvor9k5RiNnajG7brgdUfp4sLWxMewbExGLWub33hBGC9alM2Vk9zprGHnanI6C1M71QLRyiJKweEMJRR4griuEXOW6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:23.1149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d75a11c9-ba06-4ef3-0e63-08d9bac4183e 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4574 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: 5hSTpPN2ieXeWs2WxI9QWHFwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020567; bh=OoUoIxxS7fMb2vN1qkuXnafn1MWw9YtOBgVrldfbAbU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aWmmo+xE1sR76Bnk59ZL6d9Vfu2r2b2KpKxqFAAeN6ehX33kqp+OQ23CQOfImJ7Qvon D6HOPeaRHfsr7/gFn7DmCEtNMVWEUPTQvgI7jDXhZuziUiisHKVZT4+OknddsnH52PpjJ kkitX2uSrCLgH58EowOhnJ2VZz0vsxI6zeY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020568049100021 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 Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../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 f1485722f7cf..814f814035fa 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; @@ -693,10 +694,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 // @@ -749,6 +752,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) { // // If Cr3BaseAddress is not specified then read the current CR3 @@ -922,6 +941,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 (#84565): https://edk2.groups.io/g/devel/message/84565 Mute This Topic: https://groups.io/mt/87605563/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-