From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.16147.1620419954580423372 for ; Fri, 07 May 2021 13:39:15 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=AZCyAKDA; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FyDNXdiGaFUWulU6Qj00DX96KJxvNUmT0GseQqvIaZPNd3sBBn6/wzqBWO1rothmd2NHXnWeFU2oSwyPAUH8gJqJY8g9MPxNbrVK66UyhCLE+RLB04aL7oIWqZiyjuRUPZRDyagjPw7Yu2gDxNfLaKjzL8yCRlVIDuewKoYsSrFZS88sMoNBN4vzsmLTRl1CrEXjibVuHtH4DzC+04G52BQxM5twAExOkAMCRoNzWS4QjhWtnh+pWHPa6qCHgCNFCR27TiFYBsWLYZKZC45EABhUvTnstVPtTQ7l4g0QP00Q81rGNdi4seyFHimkSu1tQtQzjnc81VRRUaLSSU+YiA== 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=a5LDNPkPybCfl+Jy7a4VeUk/EFwxHswnit1m7bw3mtU=; b=VbNUCeTEH+nx/ojpxFuPQnJxcrSJ1oLy/JmxV86EhKr1SUeI2rOH0Ao8We83EkIwfmVTuRbrxD/TnblEZZ6IHykHekE60yFRFA7WAANxxwJugxNQiqQf7lG+1sY+ipWNBekBECzUQj15+PaqN5yrmX9aJU88Ye0QOO8v1CuyfvBIba5/c/dF8cn1K2GI6u+GQgV9AdvW9EcqedAZCuX5FLey5xF0Y/j0npuUCFM4nWSnKKptl/vJ9MTC2O9O3JotliOBhm5DkP4o0ax66Owj42qfU0bSxTn+hhsze9fOMkuZlMADAoMSwboWoKoEs2K3IGP2x8E+6tLXG+F+fQw1wA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a5LDNPkPybCfl+Jy7a4VeUk/EFwxHswnit1m7bw3mtU=; b=AZCyAKDA8XW01EwzEIMdw4Gs8AxuHUnU2cLTZX/vm8iN9Bk2CBKh9jm+Q2AaEjgKns+tNf9VJkoPBGEPnojDsC1YEC3qLRs03Ead8CGZTxifsFL6XWTvpwifQokTUQ5lXbl2aSLggvsg0l6iVpiYablBddR2swuqqwVorzLcXGY= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2829.namprd12.prod.outlook.com (2603:10b6:805:e8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Fri, 7 May 2021 20:39:14 +0000 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.4108.029; Fri, 7 May 2021 20:39:14 +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: [PATCH 09/13] OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask() Date: Fri, 7 May 2021 15:38:34 -0500 Message-ID: <20210507203838.23706-10-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210507203838.23706-1-brijesh.singh@amd.com> References: <20210507203838.23706-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0020.namprd04.prod.outlook.com (2603:10b6:806:f2::25) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN7PR04CA0020.namprd04.prod.outlook.com (2603:10b6:806:f2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 20:39:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dc5d5ed6-6c29-4693-78c7-08d911982d37 X-MS-TrafficTypeDiagnostic: SN6PR12MB2829: 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: BCL:0; X-Microsoft-Antispam-Message-Info: NxTtj16iiE2+BkofrmzT3fO7m3Sgj11Mr5gIWDnEkgdIkDepbvvjIq8J8r7zavRM+es3eWRIKkZ8Cq71IX5CxW38/JyVcXqm6QDNW4QlXrRySDyX0N1ou3Wcu39WSrr29/b0g8TanFNhqr4IZ0b/A+ZMo0tishDTVAoju1AY2yIxCzFEbBb4eK2xxtb7t5U8IRs9nuUZ2VTmTp3Y7p6s9btNdfAf2AV9z/ig3z4+o/2OAsMQc0P252ll5PB7C9FW/l1dthQ00PihfXbFAe6ikUjSwCIc7KvESVecAQNwIAOXSkeDtYTMm4OWGB925vmQGwFQCgaFywV9xFETTbTaS8TyM20wPqxrVBKWG5s2jujKdmEFQx52qAKwSyIps+yPZGIgocFM3BudSHEWv2zVGchXjxaY1vx+HpjM3brBOTR/Q7iZ2BhGJNvumsjioPVXw8ZiV1ZOR89HidZ/VMu/QkwndZ4CDxUml56anFCTYdcLHsO4nlqh/TEqmaMO58VblruYji4164xQnYF1rEfVT8Xth7z1Tx6Ti2I185fc7auLlnrdz4w+zi2aCa5Sf6nQUxttiqYazZ4qUZDwsYbMOEjQps5YJbH4BoWEplHUU5UWb9ePxXwA1UKlu/ADiYsh8a8kSiqtA1VSBD4NNzJVcQIHCm5RjlNtyD/IcciR2xKLNoqSwojUTyPanilXKGxRqi6vHZRf6enn9cdtT1ozprYRJ8QdbGuDBzkM7xGepUjKjQD6zl1PRITM4DUUvoGv X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(376002)(366004)(136003)(346002)(39860400002)(2906002)(45954011)(1076003)(86362001)(44832011)(8936002)(6916009)(186003)(8676002)(6666004)(956004)(478600001)(26005)(7696005)(2616005)(83380400001)(19627235002)(16526019)(52116002)(316002)(36756003)(66946007)(66476007)(54906003)(38100700002)(66556008)(38350700002)(4326008)(966005)(6486002)(5660300002)(213903007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?gWmM2r1Hju7l7SAscmIao1xARMiOoj+QtSXWEIHRQp2MqhqT8RA04zPXZPlv?= =?us-ascii?Q?NOJTSL9Prz0hKiOSTLyW5PkjeNQSVygh9cAvW15S2QNC1iCXJy/WeD5TpYlG?= =?us-ascii?Q?REiaD2/zrQY86Y6ZrfjEu12NDg5JOZDOoI0Xus8hKRRJtZPYGAHxMFJYbVBc?= =?us-ascii?Q?zcw9dVRGfgl7mvJ19S7b7HEOO0hR4q1VItYVxhJwapZ15nxTsM21ddxLFP4K?= =?us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qlYXrh24gWZ1CCD3WbQney2jWiV37f?= =?us-ascii?Q?9/vCMn9g4ceSYriWt4CYb2ob27rkDQEDS73E76V+77pCgibEYDsY67SQgwPA?= =?us-ascii?Q?jQVyJcWhSOd5Oane0aWh/uYIBBc45XDeZFPq1Me8w66bOvd0PvenKOu83yLq?= =?us-ascii?Q?fLJ9iZEZJLvrKQlUefquzZCjsf3p4eb51o7eIxpV8j9/4JcXmUW5eNhbrucq?= =?us-ascii?Q?lU2cQ9FROWoKDwY0zSqFwGLM?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc5d5ed6-6c29-4693-78c7-08d911982d37 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 20:39:14.2516 (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: NnWVgKyyRSXsjcK5gk10ISWBOUSnb5VcBNtVjXuoSqr599C1DP8oGapvuDGA5NreRDPCv2AYa5KTvBI/vOzGdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2829 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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. The MemEncryptSevClearMmioPageEncMask() is a simplifies version of MemEncryptSevClearPageEncMask() -- it does not flush the caches after clearing the page encryption mask. 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 ++++++++++++++ .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 23 +++++++++++++ .../Ia32/MemEncryptSevLib.c | 31 +++++++++++++++++ .../X64/MemEncryptSevLib.c | 33 +++++++++++++++++++ .../X64/PeiDxeVirtualMemory.c | 33 +++++++++++++++++++ 5 files changed, 145 insertions(+) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 99f15a7d1271..b91490d5d44d 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. + + @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 memor= y + 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/X64/VirtualMemory.h b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h index fe2a0b2826cd..8dc39e647b90 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. + + @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 Length 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 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b= /OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c index 12a5bf495bd7..169d3118e44f 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. + + @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 memor= y + 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 4fea6a6be0ac..a2bf698bcde7 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. + + @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 memor= y + 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 d3455e812bd1..a18d336a8789 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -891,3 +891,36 @@ InternalMemEncryptSevSetMemoryEncrypted ( Flush ); } + +/** + This function clears memory encryption bit for the MMIO region specified= by + PhysicalAddress and Length. + + @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 Length 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 + ); +} --=20 2.17.1