From nobody Tue Feb 10 13:16:33 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+83727+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 163673884447645.61113387484477; Fri, 12 Nov 2021 09:40:44 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id T1dFYY1788612xcRFxkaDYHo; Fri, 12 Nov 2021 09:40:44 -0800 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.69]) by mx.groups.io with SMTP id smtpd.web12.449.1636738843286962205 for ; Fri, 12 Nov 2021 09:40:43 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ais7OPTaGWydNG5HCq2MebkRb1qeF5SxGpPWSQ7nP18PtP73YbckVRV07vQvRzEZkR/SEUnv/lVsZ+/1DxgIqd08T+OIrK4TPGy298YwfcIh6EAVG56aK00MgvfGBD0QlzJNZQMEHRwjbNw57Up06F4iL8d4yeCRXqNz9SzyL3o4W4i63tYunYa5UYKUhX6u2deTNgttgkvFbropVOH13nNkxyiQpwqloKraeCsZzXBVfflJ0NIJpa0GeNZFRZqjjXw9Qb+PRhFy+l0s4Al96lo+ih7FG3l1ybPf8CRL+lmlbPMtu0qngnPY9xy2udnu2gReEfB+xPo5EnI9s6goEA== 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=AAcfYlxvUwlQEaM0iBzjpB3n0oarjVEg++IMGJfyqoo=; b=HxRWznMmHQY5D7nBonBMFm6k+gcrqQTGN2FokbLUuMftS8OHl8RVnGu9ztNAEIR8NCzgI73rVtKRyURq1ennA2aN6c/47ueXA/R8BahQcwnuS0/oaOcyx4nzsQd/64TC96rV1AnCuaxYGO59nTDho3lMlC2LxphzF3MgpyQSD7KLA3NFKyki4ZVORJbeHEUAaZveBXOw7rOOG2rGmqjnsDjH1W19/BQxIE/uriQDLN0ZtQQQp4alUfTkifp/hFBnH0XweEs/uHDy1i5HmFXgdg4/znmFJwtjhHI2TlgZhm2vONFFqdAZyQzFY3bHDZ2x6N0+e+CUbL3hKbQzLQB7vQ== 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 BN6PR19CA0080.namprd19.prod.outlook.com (2603:10b6:404:133::18) by MN2PR12MB3759.namprd12.prod.outlook.com (2603:10b6:208:163::24) 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:40 +0000 X-Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:404:133:cafe::fd) by BN6PR19CA0080.outlook.office365.com (2603:10b6:404:133::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13 via Frontend Transport; Fri, 12 Nov 2021 17:40:40 +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+83727+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 BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) 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:40 +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:38 -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 v13 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Fri, 12 Nov 2021 11:39:55 -0600 Message-ID: <20211112173959.2505972-29-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: 2cd20dfb-995d-4374-3955-08d9a6038b41 X-MS-TrafficTypeDiagnostic: MN2PR12MB3759: 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: AfSZ6aKArebE1cZ5jWB4Ch1UFaPoxHMRIXBm3iArCQBVfd7QJd0NB/dATJOQexYFWv6/MmHC8DW/Fz3ejtDoUxlL5L1MPJ+g+0h9BLtEiAkDRFDk8zM6SmaqqQ8I6RdRpbe36J6R5C+029CuoH15RNxTBRzEfbVWjI21jQZxFcOvO5wjYwyQOZ6xsI/acfuQ/5TT2g6WvhJhBqZzhYT9kb2FO7Bd1r6ZOVWhmZ7GA31TyHN6mXT8nGEnypOpHBGTwhQbbZJGa3AlhXfVYXKuoxKjzf5Nn0+3Khb7uCIInGfNpI/z1F3Tg6YUzG5FTvQleAptkpjc2nXWBrlW5EQZyBzZLW5sX3gWILPDJ0VPeRBlPARevRSjg/it3n5S/OnPkZcObhMR134skUnLonQ2YAATcf9AVvn8KeR3ISmnQbSFmR796nlZ6CEc7GTcbMC0cJ3vL9skFeTpfybDpo3uOVABgoznN6Xzd+zGQMzP+BrP6+adWw2NL2EW6MqWLOh0meHcwmdSxOFWUz1i4ne0utVZx2TYCuicWmnkEMM1MYtcPLOzy9H1yqTfGcHjcaeEUap+IdFv90QSU8WeS6Q8oYqfumsXE5+52HOEIc9j+EDTgUDMjOmRA/t8F3E/rX587qT1moTA36r6tO+bcBBdIlzjqIqn1j71nPjyG0ToBuLElObie8zEDLdeSjdppQXE+GQ6KrF6B8OgP0PBifALnHCIJYGn5cYTayG298WA5MFg1a1VmRzOF5p1SiBDujlWbOBmZIun6j7lkCJaqoonZi2KmxwCYcvoEbKsMtiP4E9Vng4CjAMo2LDb4kZtiCJ3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:40.0616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2cd20dfb-995d-4374-3955-08d9a6038b41 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: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3759 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: ng0qaicXJToxYTx3GfnIP8TKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1636738844; bh=QbWc1Jj3ZQdLQIM2ej/tEQIBrDXHGKPH6F33ng8WuZY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=F/bHASXC+yT+6j5DZJpUcC9V95EO/G4Me9JwrndFqaYnS73O/FARDrhGtyATC8KM/YR iRP8whfznui+Z2J8r+iiouSvo/TQf/En5j8DDAcl2dGw8Lkha/5I9WnsNEqpebz654Dan 0XWbhlp/KvSYRISpuEtCn0pW9W3/zWFNye4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636738846329100016 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 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 (#83727): https://edk2.groups.io/g/devel/message/83727 Mute This Topic: https://groups.io/mt/87011902/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-