From nobody Fri Apr 26 16:17:58 2024 Delivered-To: importer@patchew.org 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+74633+1787277+3901457@groups.io; helo=mail02.groups.io; 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+74633+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=amd.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1619783552507590.3286598591052; Fri, 30 Apr 2021 04:52:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id v3RAYY1788612x3Oghs1q6hv; Fri, 30 Apr 2021 04:52:32 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.10434.1619783538721945423 for ; Fri, 30 Apr 2021 04:52:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KDJYC74QAJEiYNeQ4pmGY7IrwSofAWI22aD6KT0bYQgAToPxLhOO9RatsLmqizYVei72v+L2d8k70xOqjpK0NGPcDqUa9m2k2vnmzygpS4CqOPZPRSiVPYja5OtwDaf1NVeCmjnY57Jo7ylOq4rcKOtpBu/aT7PpA2KGK7K7qeC7DM3BKg/fS4+KdJTvChEmKuHQQubWhb8JvRvXJ1jAfqaF4ZDjuCTPKT9p+QSZroam8r2rDJv+YbnOXCDUbD4R56luv6Es5nxJZptT53lf5J0kfatp5oTHoffImKEpJnBmvfvhqSXEQ6WVCmmOE5ueJng1OU/2zIzxZNAZmsk42w== 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-SenderADCheck; bh=loYcD+XSmt8gvowWGk69EVI4XXvJ4j0QQit+DUxbmRw=; b=ci8piOq48J05uJRivM1/IAyUxR3tqN3XURpFrvV32qD3hL3HrJl6FbM6nJcKhUF8+PDnUZmeXSUTjq8R3277bcisFhuCx7nNTQXwG8E8EgN32h6ul9NLcQQHGCQ0tpFLUQGSlAsreQFCZxE9dDLcjZC/lAd21jGYb6f7SzOeI38qjSHkSeS+2GTDZR4IaLPsUwYpp8mYys/MJm1WrDjQSSEhakfiSZUSKWNA7GZidhRmNFT5BFp1i5aGr6DSW9wqrdq1yTavlir7ud5KlQ32C8lQ5AX8w7dWreeGaiBZbvpbcUm8drd2ll6BQu6hXb466Pj3pGniSG6Qikhkxqr5kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Fri, 30 Apr 2021 11:52:19 +0000 X-Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4065.027; Fri, 30 Apr 2021 11:52:19 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io Cc: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas Subject: [edk2-devel] [PATCH RFC v2 06/28] OvmfPkg/BaseMemEncryptSevLib: Introduce MemEncryptSevClearMmioPageEncMask() Date: Fri, 30 Apr 2021 06:51:26 -0500 Message-Id: <20210430115148.22267-7-brijesh.singh@amd.com> In-Reply-To: <20210430115148.22267-1-brijesh.singh@amd.com> References: <20210430115148.22267-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 11:52:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf3998f0-48f4-4557-2c63-08d90bce6823 X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: r3tXmzhNNDIOyOOD1DgmywDPgXEuFdIRRpNT4MsY0d8hWc7RQdJ5Bakqc8/EJtH/1BZMVQGLnvTnNoB1MkQTzt8IOZVbMok4Oaj1nYwTk1wcYVexqxYOLuur22OTbxtLDL4g5c3HHwice9ceCbsL35rrIkYBAVlwQ1DLX2BI0qzCsnY/Rf3fU5trB8A4M8f24EU9r6AaUfoiaHS49CDEG9H6UgB6DrbuXd6YF9/XxA5Lhf9ji9KEhlw8nMJ2WnDvUlWsNtNWpTmUIz/owmvtI6g7cMAagYRAx+l4YwVKyDlMV1CaEpzSERM65XM53MuF4PdK2Xh1UMnym/70FlEo2G410ipm/EkniPY2wUVXvvFt5Nqx/NF1LdPURubqoBSd0mOOmfwiFDZs3HIvp3kMYm3l3K57y+TOyOK5CB5xAcivzehDnKHSNekCYQD47mXftqQeY6Ebbxf3Lt647q318x+RuZJBo/8w2zk8V+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= =?us-ascii?Q?7kViI3obDeoFX4hZNlzJbpzzu7rzhXwqilTcqx5FwxXU3GIfrn2cwqE3VFcN?= =?us-ascii?Q?iTe8vtJ5KYzPp2RgzdQgMfp2ypSGo2BaZMIM/1XYEOa0RytgKk43iN3Z7W+c?= =?us-ascii?Q?qxCYS8rLRhIgVxdvLeDiu1NlbzYIa7T/abJJ+BTrotb6UgODSfXB/WwAUYwV?= =?us-ascii?Q?xAv4d/JnpxixyFn5dUo7B+WetZG+wNgVW//FJDjM7eY6duNqHQ7ECzpCIPJm?= =?us-ascii?Q?kfKdHBxdahHWtKtgUUMlosiTL1yQM0DaAsDRVVz6jV0ydRBY5ktZP6vZOtjv?= =?us-ascii?Q?Sc8VNr93pGmj2501x8efXi6g4wq3xf9j90LBEn7G9s2c/czXLz7It419F70R?= =?us-ascii?Q?LaiZ8RmGYlm1j1Bea6Y4ZGMh/by4mxqBYx0n2iIlSKLA0A/hnKpgGFKH/lDT?= =?us-ascii?Q?GmzfldkrA4NEpOWlyZIYa5pVKJKB4dme9Ulpo36cDAqyOH8BBTerNEiP9/6K?= =?us-ascii?Q?U1mZwQXbCOLvDXLVfcmruZQ1qzcQ3w9jOkw8ppHuDBOg1DeTP9D154u/9Yej?= =?us-ascii?Q?6LIYUFQRFkrfBlMJYFGmqBx6RkduokLznGG9gF/6VXPba7sHVPeIu0doIInJ?= =?us-ascii?Q?4Ol3gb7JeZ9gudaE2hKB9VwMJL6ucwuLA88rodsg78r78lqkqO/Be105MjKk?= =?us-ascii?Q?5FDBo4cCzl0A6veORNYvauJ/m5yd1TJ25bFtb0a/IPLHmesmHHSO+zTfirwA?= =?us-ascii?Q?qbyii4P/vOiiGuf/mHvE7ajw?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf3998f0-48f4-4557-2c63-08d90bce6823 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 11:52:19.0058 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FkzuXnHA0P44Nc6eG77WPWZ37YuR8zwQKbhgoVS3PmyPx0YjJ5xQJopDIMnjzbgNiPpeIIbnGZs/O855iBr5Uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 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: xNxiScA3DC58k92TKeFjU3B3x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1619783552; bh=X3evxvVhwApQDSJoPPSH5cc2bhHd/zC4R5tjbaMa5Rg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=m6bfxFr87Kd04ibxPMmCLMOkQAZGum7V367ID4SP1kLN6itZRQggJGR9vtuyrEDgquS vMtg5AkXQDXsyzn8hsZOyny94Go8mp5IWlA0e0pQHCfTkeotoQNXRTkSFmeJnAkHkx21Z n51SbNcv9cgouRdn21FDhLpuOB3v2IqMgnU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSevClearMmioPageEncMask() helper can be used for clearing the memory encryption mask for the Mmio region from the current page table context. Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 25 ++++++= +++++ OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c | 31 ++++++= ++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c | 33 ++++++= +++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c | 44 ++++++= ++++++++++++-- OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h | 23 ++++++= ++++ 5 files changed, 153 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 99f15a7d12..c19f92afc6 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -203,4 +203,29 @@ MemEncryptSevGetAddressRangeState ( IN UINTN Length ); =20 +/** + This function clears memory encryption bit for the mmio region specified= by + BaseAddress and NumPages from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress The physical address that is the sta= rt + address of a mmio region. + @param[in] NumPages The number of pages from start memory + region. + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encryption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +MemEncryptSevClearMmioPageEncMask ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ); + #endif // _MEM_ENCRYPT_SEV_LIB_H_ diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b= /OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c index 12a5bf495b..4e8a997d42 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c @@ -111,3 +111,34 @@ MemEncryptSevGetAddressRangeState ( // return MemEncryptSevAddressRangeEncrypted; } + +/** + This function clears memory encryption bit for the mmio region specified= by + BaseAddress and NumPages from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress The physical address that is the sta= rt + address of a mmio region. + @param[in] NumPages The number of pages from start memory + region. + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encryption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +MemEncryptSevClearMmioPageEncMask ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + // + // Memory encryption bit is not accessible in 32-bit mode + // + return RETURN_UNSUPPORTED; +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c b/= OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c index 4fea6a6be0..6786573aea 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c @@ -118,3 +118,36 @@ MemEncryptSevGetAddressRangeState ( Length ); } + +/** + This function clears memory encryption bit for the mmio region specified= by + BaseAddress and NumPages from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] BaseAddress The physical address that is the sta= rt + address of a mmio region. + @param[in] NumPages The number of pages from start memory + region. + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encryption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +MemEncryptSevClearMmioPageEncMask ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS BaseAddress, + IN UINTN NumPages + ) +{ + return InternalMemEncryptSevClearMmioPageEncMask ( + Cr3BaseAddress, + BaseAddress, + EFI_PAGES_TO_SIZE (NumPages) + ); + +} diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index d3455e812b..3bcc92f2e9 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -557,6 +557,7 @@ EnableReadOnlyPageWriteProtect ( @param[in] Mode Set or Clear mode @param[in] CacheFlush Flush the caches before applying the encryption mask + @param[in] IsMmio The address is Mmio address. =20 @retval RETURN_SUCCESS The attributes were cleared for the memory region. @@ -572,7 +573,8 @@ SetMemoryEncDec ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length, IN MAP_RANGE_MODE Mode, - IN BOOLEAN CacheFlush + IN BOOLEAN CacheFlush, + IN BOOLEAN Mmio ) { PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; @@ -852,7 +854,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - Flush + Flush, + FALSE ); } =20 @@ -888,6 +891,41 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - Flush + Flush, + FALSE + ); +} + +/** + This function clears memory encryption bit for the Mmio region specified= by + PhysicalAddress and Length from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] PhysicalAddress The physical address that is the sta= rt + address of a mmio region. + @param[in] Length The length of memory region + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encyrption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +InternalMemEncryptSevClearMmioPageEncMask ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length + ) +{ + return SetMemoryEncDec ( + Cr3BaseAddress, + PhysicalAddress, + Length, + ClearCBit, + FALSE, + TRUE ); } diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h index fe2a0b2826..99ee7ea0e8 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h @@ -126,4 +126,27 @@ InternalMemEncryptSevGetAddressRangeState ( IN UINTN Length ); =20 +/** + This function clears memory encryption bit for the Mmio region specified= by + PhysicalAddress and Length from the current page table context. + + @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use + current CR3) + @param[in] PhysicalAddress The physical address that is the sta= rt + address of a mmio region. + @param[in] Length The length of memory region + + @retval RETURN_SUCCESS The attributes were cleared for the + memory region. + @retval RETURN_INVALID_PARAMETER Number of pages is zero. + @retval RETURN_UNSUPPORTED Clearing the memory encyrption attri= bute + is not supported +**/ +RETURN_STATUS +EFIAPI +InternalMemEncryptSevClearMmioPageEncMask ( + IN PHYSICAL_ADDRESS Cr3BaseAddress, + IN PHYSICAL_ADDRESS PhysicalAddress, + IN UINTN Length + ); #endif --=20 2.17.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 (#74633): https://edk2.groups.io/g/devel/message/74633 Mute This Topic: https://groups.io/mt/82479053/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-