From nobody Mon Nov 25 12:15:52 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+69865+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+69865+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 1609968197853373.8560401789914; Wed, 6 Jan 2021 13:23:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 03jMYY1788612xVlseUoNrW6; Wed, 06 Jan 2021 13:23:17 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.55]) by mx.groups.io with SMTP id smtpd.web12.495.1609968193589323093 for ; Wed, 06 Jan 2021 13:23:13 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a/6fosukDC9KwoUSrT1YZ/akfIo0yD8LnyHTP6hm0c9ohRADSXQ2Ai1RycihSnsXUdhm9uC6kpyLYNYiXWEXcuxe524mhstRAwJy6cadXz4yeoclHDEMGTIYhUnbCfqJIO8Ec2CY3flr3s3RiYLRAQFyYjC0DwQG6UlHmtrcm1Dxe+XqVRt1ix4x55AcZkveqmF8sCE/PwqxUnIPkQyomjMz4STl8bl9mE6guWAaOSNRVFqJHAKCKcdRJSDZfiGiSJQetXC2RpCh9EUtuu+WcyHzUrzBOEPywZ8rYCA45Ma1UXfoNt6Fh0IpL0TThUQk2IqHmHHU6hDL9N92dsab0A== 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=jeEgzUb8t61v+Ua9D81FBAr9Kebe9Nr/1KOjQARlENE=; b=Ox6HpGQH9+p96K5voApQarW6MpVD0FTjfP3zrz3so0Wwm8Cy9755LxU7O2daH0V/PsyYUblqBj9oN8bbjyMTfWKtbJVGDVb6LbqkgoSbFc9wz8z+nTf+lbHKEIeEcaNcfpIQgqlKhSWC1+7cC8u7XQvfGloBgngDOfA0n5tNoCU39q91F6IalTUdRZjWEPQOL6DPK+MEjj2c9PoPjrNvwip6VsewumlIUX6oH5bC5nmBLKnsEnwMdW3o1oOadlBBOF3cjRr2Ynch5AK/YqL28rLoAR7shbLFbgVMx7zyPH6Bg/5y5no+WqeIWt5dn/bVTst8SWWci3q1MulKdngvwg== 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1259.namprd12.prod.outlook.com (2603:10b6:3:75::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Wed, 6 Jan 2021 21:23:12 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Wed, 6 Jan 2021 21:23:12 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran , Peter Grehan , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v2 07/15] OvmfPkg/MemEncryptSevLib: Obtain encryption mask using the new interface Date: Wed, 6 Jan 2021 15:21:33 -0600 Message-ID: In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0043.namprd11.prod.outlook.com (2603:10b6:806:d0::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0043.namprd11.prod.outlook.com (2603:10b6:806:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 21:23:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d666010c-63c6-41e9-c8ed-08d8b2894592 X-MS-TrafficTypeDiagnostic: DM5PR12MB1259: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 2Vcjn8HhfGH32Dni6EUYre+bm1AaISPULxaG+EpuM1Kgyv8q5ACiHrSyqPcrYtZNUoy37IKZRSz1y2NdmuUAToqyr+f8SfXMV6rCuxvMoKG7okO2Rh9sPnxh4JSNBhUsIHdRv44tHvT3sGu3vbXLqF7VOHc/bpuCgG8g0jIutWHRRq7VG5bwZNGlMh8XfaX1C0yI21++VpIzoDoFIQbpLjAFYmA73jL7jvmtHOzp+TFn76ICOJGSGtHTndjHAT6Yy/6Ufj1Wq8pFUPMYDsu99Mltlo+LxgMlZENMOEydIalsuq5iL/I13V8DtfMf0M008paPGiNvyJkDbcDUzASRABqwio6SpDZWL5nKSXGD0n7BnKy5NwUo7QrL8jOwyRC4gKz041se7WmLDP6VvZiKM3RLeitkNr7FEDjRo5IfL38/l4kNYX85u2DNtSwqbOPEEhDi9S66Z1tnPlD4TYnCEg== X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?I2ppsACoPR/dIOJsnCIhSod1DrA8h3umLzV72f1Hoe/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TfhNoJtNwq7HZaecb/qcS30Yo7VmvZPKLO?= =?us-ascii?Q?fy6Uz1l/x5t4VwnCPmQOYoblgH5Wb456uX+TDLv11trKj5VXVWpqkj6HkfB/?= =?us-ascii?Q?Zr4d?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2021 21:23:11.9047 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: d666010c-63c6-41e9-c8ed-08d8b2894592 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KiVmcUlZE7Gk6+jHk2IhxQaelJExNleQ+LB2Sx0NP8yhEl1yKqbML3lMTZS8StS1+rpiqJoIs7lEZpy2qg001Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1259 Precedence: Bulk List-Unsubscribe: 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,thomas.lendacky@amd.com X-Gm-Message-State: 1DtXxkVCnDZigu0CqIzMLiP4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1609968197; bh=LKPFdDWDA9qQMYP6OVkmQvw7gOR/tARWzF398XaRsuc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=kdbQeyUkosOshuacnccy/hcdbS/R2BCEIBBMJyrOhFyfmDz+6Lvcf3OztHhM7T2uER8 aez9PD8p+mK4IERFVdSo6RDqiexctUg3CWoi6CBrPdFzk6Y2S7VPPsmzkPfwWBuPKNTbl fxsygLsLtcIugLkHuW09y7BnZUg/UygPrtY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 The early assembler code performs validation for some of the SEV-related information, specifically the encryption bit position. The new MemEncryptSevGetEncryptionMask() interface provides access to this validated value. To ensure that we always use a validated encryption mask for an SEV-ES guest, update all locations that use CPUID to calculate the encryption mask to use the new interface. Also, clean up some call areas where extra masking was being performed and where a function call was being used instead of the local variable that was just set using the function. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Rebecca Cran Cc: Peter Grehan Cc: Brijesh Singh Cc: Anthony Perard Cc: Julien Grall Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- OvmfPkg/Bhyve/PlatformPei/AmdSev.c | 12 ++---------- OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c | 15 +++++-------= --- OvmfPkg/PlatformPei/AmdSev.c | 12 ++---------- OvmfPkg/XenPlatformPei/AmdSev.c | 12 ++---------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/OvmfPkg/Bhyve/PlatformPei/AmdSev.c b/OvmfPkg/Bhyve/PlatformPei= /AmdSev.c index e484f4b311fe..e3ed78581c1b 100644 --- a/OvmfPkg/Bhyve/PlatformPei/AmdSev.c +++ b/OvmfPkg/Bhyve/PlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -15,8 +15,6 @@ #include #include #include -#include -#include #include =20 #include "Platform.h" @@ -32,7 +30,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -43,15 +40,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/Ovm= fPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c index 5e110c84ff81..6422bc53bd5d 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c @@ -3,7 +3,7 @@ Virtual Memory Management Services to set or clear the memory encryption= bit =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
- Copyright (c) 2017, AMD Incorporated. All rights reserved.
+ Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -12,6 +12,7 @@ **/ =20 #include +#include #include #include =20 @@ -39,17 +40,12 @@ GetMemEncryptionAddressMask ( ) { UINT64 EncryptionMask; - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; =20 if (mAddressEncMaskChecked) { return mAddressEncMask; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); =20 mAddressEncMask =3D EncryptionMask & PAGING_1G_ADDRESS_MASK_64; mAddressEncMaskChecked =3D TRUE; @@ -289,8 +285,7 @@ SetPageTablePoolReadOnly ( LevelSize[3] =3D SIZE_1GB; LevelSize[4] =3D SIZE_512GB; =20 - AddressEncMask =3D GetMemEncryptionAddressMask() & - PAGING_1G_ADDRESS_MASK_64; + AddressEncMask =3D GetMemEncryptionAddressMask(); PageTable =3D (UINT64 *)(UINTN)PageTableBase; PoolUnitSize =3D PAGE_TABLE_POOL_UNIT_SIZE; =20 @@ -437,7 +432,7 @@ Split1GPageTo2M ( =20 AddressEncMask =3D GetMemEncryptionAddressMask (); ASSERT (PageDirectoryEntry !=3D NULL); - ASSERT (*PageEntry1G & GetMemEncryptionAddressMask ()); + ASSERT (*PageEntry1G & AddressEncMask); // // Fill in 1G page entry. // diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4a515a484720..954d53eba4e8 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> =20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -17,9 +17,7 @@ #include #include #include -#include #include -#include #include =20 #include "Platform.h" @@ -116,7 +114,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -127,15 +124,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 diff --git a/OvmfPkg/XenPlatformPei/AmdSev.c b/OvmfPkg/XenPlatformPei/AmdSe= v.c index 7ebbb5cc1fd2..4ed448632ae2 100644 --- a/OvmfPkg/XenPlatformPei/AmdSev.c +++ b/OvmfPkg/XenPlatformPei/AmdSev.c @@ -1,7 +1,7 @@ /**@file Initialize Secure Encrypted Virtualization (SEV) support =20 - Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.<= BR> Copyright (c) 2019, Citrix Systems, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -14,8 +14,6 @@ #include #include #include -#include -#include =20 #include "Platform.h" =20 @@ -30,7 +28,6 @@ AmdSevInitialize ( VOID ) { - CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; UINT64 EncryptionMask; RETURN_STATUS PcdStatus; =20 @@ -41,15 +38,10 @@ AmdSevInitialize ( return; } =20 - // - // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position) - // - AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL); - EncryptionMask =3D LShiftU64 (1, Ebx.Bits.PtePosBits); - // // Set Memory Encryption Mask PCD // + EncryptionMask =3D MemEncryptSevGetEncryptionMask (); PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); ASSERT_RETURN_ERROR (PcdStatus); =20 --=20 2.30.0 -=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 (#69865): https://edk2.groups.io/g/devel/message/69865 Mute This Topic: https://groups.io/mt/79485057/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-