From nobody Sun Dec 29 02:27:51 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; dkim=fail spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1495466629075316.5896497214195; Mon, 22 May 2017 08:23:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3EC4A21969F94; Mon, 22 May 2017 08:23:43 -0700 (PDT) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::60a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 36B8F21969F85 for ; Mon, 22 May 2017 08:23:41 -0700 (PDT) Received: from brijesh-build-machine.amd.com (165.204.77.1) by DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Mon, 22 May 2017 15:23:37 +0000 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=t28XH76/3GJaDjDRvLPvfQNwjSIfoLVZDyXmR7VznvE=; b=UUe1bOGqjEt6HXA8ge2fQvFrNS3COZQlyj0CmTEBnkEfAURGPh0gqQfO+2LqxtdoqRmWRaLwVYvf5Q7oLEP/LjbD9L9TYde08CNEAwzHUqx43PXG0FUq2mBE7SBbGWo+P0SXWQDVbMpItZvAu0o6fM7sVC26Cw1fsDAv7TSbigM= Authentication-Results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=amd.com; From: Brijesh Singh To: , , Date: Mon, 22 May 2017 11:23:03 -0400 Message-ID: <1495466592-21641-6-git-send-email-brijesh.singh@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495466592-21641-1-git-send-email-brijesh.singh@amd.com> References: <1495466592-21641-1-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR17CA0030.namprd17.prod.outlook.com (2603:10b6:404:123::16) To DM2PR12MB0155.namprd12.prod.outlook.com (2a01:111:e400:50ce::18) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM2PR12MB0155: X-MS-Office365-Filtering-Correlation-Id: 6dde42e2-de8c-4164-cdcc-08d4a1268548 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 3:uVKQVPvZFClEYbOIbvBoo+GKtGARDlt5fZ/QozxF0AhH+fFiJ2IKQRYLuDE0zotdzz5BflI0/yxDJ9va4ZrRkuIpltTHcrUsDuXDbe13D/gvzKO6CiKHLZ3S7yoqHbNgn69XKBqDilnhtiQCZ4eNofloomYtdxeUSL9mx/TXq4Fdifc0pbCabWtfqNW3aZXR3J8f5SXX21CpQ5+U0eZEqKkCLyNY2xpdiICqsql6gKBkUVsKTOT1M1X0uexY7YTxSigQSQAu/KeK6jTvNVFM1cTssnabLGFo1Mp8zn+A/m1px9BLTxAIHDxi66up1DN4Q4LjP3AQDf//kz0oCvhrzq/ybFIYxgaXbyMjkkDNzbw=; 25:JJZ2zzVOmrlgo7/zGDMg4bS83L7s1g1epovU/yHJ8ZR1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CAR81xCoXFV6gWW2koK3nLEh7nuoehJAPcB7vLjIeZhfAuEfWlY+WwREVG/q+7DY4pP3jI2YC1f2fPHD/4xFZW4Fq8rkhiWkSi1eBVSWI9NnofcbCM6kFEEEzZwZxBB2QUVPS3l22mYGMZ8U9Xi X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(20161123560025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148); SRVR:DM2PR12MB0155; BCL:0; PCL:0; RULEID:; SRVR:DM2PR12MB0155; X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 4:9A3ZIUl4YJlQHs8x09TzDuDFdAks6In5yFGT5nDuo3OsAYrUW4lEvPChMH766sbvGNvt18+s1eLG0iuVFLjqYUhmxI5SnilN52WeXj1lAuNEzzoMXw4MEly7nXNIyyC7AlDYZTxx+UMZ8UZHEXivYEWXqYtbmuGxGQrPMmTD4yId6/S7xBrngKDqkyt4OpAX0iO1uO3OSks4pDlifb7Ft9OkjULwekt+rmkg+UH5AcQC0F+sobwaOjq56VlV6Qh8ip4JADFmaOIWEX5Z2TMx7X31iFLTniGVSLE5jq6BXemv2VQ6wNaIxvQeABIAP2udV/MmGOpBcbzKktFVbUa2a3sbN7u+dWHrN/pF/dk8y7UPMZyXHNJUxhBPvUfXt2VNNzbvLg8z96vSEpPOJ+3abEIj3YUOCKX0YgzDtlka/sHxx2Q3AmXuCmu0C5YDBVoRor+/p8rDgk+gACIUtkU/+iu6Km56TdI97p1DuuCF9kyodfbT0ywGx8w1JE8M36MsXoBiu6+k16s2gaA5tBnZvXiUKPS9Nwuz15JNPt3C0SIDcqrFh+YwY3eVXWBZO5BedVCdL6KfjzC9LcXaeKQHW7VcqAu5J4zzsgssdPIlIzpOFjBr8dHp1XVUpTjpCk5L1DpFPaOyyqD02F+7l+sTB8/sR92d/er3z7BdN0PGfVPS21f7BccJG0GEWxartYWzhhBZHf+F4P4vaDBeb3ncHv+qxTugEQqXsLcmCujWQQEqLJcvX3Mjjxz74rbk+8+RkLbcGEgeZBOtDGPAgcFVS+XQfMMGyGrOhGG5ITVui0uDtkZZVbXlxGBo9Xwnbaeei/Jod27WzIJXhKiHol00ye9hipG4v7/Gwzw7Ta+9sUUfajY5ju9Ukim6J8Ez/xNr X-Forefront-PRVS: 03152A99FF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39840400002)(39860400002)(39850400002)(39450400003)(39410400002)(39400400002)(6486002)(5003940100001)(54906002)(16799955002)(6666003)(2950100002)(15188155005)(36756003)(53416004)(42186005)(86362001)(47776003)(2201001)(66066001)(2906002)(5660300001)(305945005)(7736002)(50226002)(38730400002)(3846002)(6116002)(189998001)(8676002)(6306002)(76176999)(81166006)(53936002)(50986999)(53376002)(33646002)(4326008)(478600001)(48376002)(50466002)(25786009)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR12MB0155; H:brijesh-build-machine.amd.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR12MB0155; 23:n/R0ZABke/1GO8/9ZraZmfAG6Z1k3T+AqLC5TKM87?= =?us-ascii?Q?sToLS7hW2Hawgu1+B3VZy3wpkor2xiDR1Mf/2SMYiExNJrIot7URvQBNHEM4?= =?us-ascii?Q?lP8Mp+tXeLw1NSoyK9h15qlHjJgC0Uig/EdMw/rbONjc5KS1MD7If/isLNF4?= =?us-ascii?Q?r8lgg1UREcP331I0pZTsNbazXICdPIjD/56FwU4LVYUmRZJmdGFnG9oiWxvs?= =?us-ascii?Q?iA0QRrqQ2LFSGBnKV9nqQ689i61IgjkbkADAWFsRluJbLrxB2HHwjKYFfF3A?= =?us-ascii?Q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Pmd2tplOsMvpZTyw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 6:NxafvajhHBRupZywwBqr7zFnxVlBRblvKpsMpMKCI+04kLHUdGLxNm5A2o50NKEcYCw6vrONRL/dSXJ4K6Pow35u0guChnBdYCFMpauxvXJ74R0T1zIleMAR3nUkoFtDW1Bk1eiS/I+h5he+gM0TVKgFdmmQxJNmijz99FeZDw2H0nTaxkZsTMmo5QAT0La+ts7Bio6jSFqrw+qbjUyh/7a7xowt+43XYqeCsdFIRsPoBAMbpMySrmRV2doVzsN0HZD5OclsIJL/z2LEh7Xck1sOpX3lijy107v9z3Cj04vvyd6ifAEUakNMN+AiYDBh4W236b4e59SQr4z2aFP6SGXLQ9tyULG2qJNpOYcFiANqEbfEYa6tcNkBoGMF6R/JieP5hgnqQg8xKEDW5VVdJb4A2A4H0nVPhX+esTXSExZ8l8vsCDjVto5HLNM0D9mi3Gy3ycawswvO5C2b7qJ7pB0Dgq/SY5h3IE2NWpZcUGlH02DfF7/WKYfzJnsuXgwDRTlX0Qe6AVjGbSBHjy6/ZxBhLaWUfFSmiGeVME744MQ=; 5:h6PgFy+NSZSKsQLEWNmONefmvUvNWbZGODJcul2JFImkYSpUcmJUn/QsW6+zjn9K4MWSCbEvohKoCFLl5cQUTvy8uCLEh0151cUrGxN2A6VZRWlM+c1QjPeAo9qKDnYSs1LweeSbn9SD68Trd+qZdA==; 24:Xb5CtuhxmgMBgq1Vwmj2uI22m53+ORTxP033GK5ECF6ZT1S4KYhseeM+72nyz0zMJiU/IWmQcau7W1U3h09Tt/VNMI+Yi+NSBFh11wrtnFo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR12MB0155; 7:rHSzHw1n6nH2rYZMGuoSUlnIj+ANH7FBZ7tled+phvT7AuqoViByt+g7vPQefuRPb37ja7NlzpI50clUclS6v5bC7ondKBp6Rjs7K+ScSQB01BTJ5t1mA/xkOysb1vBGGTSeZ1GC0GYHdD78RrXnuFQFzmuICYDEd1M2FbI9UX37u6L36Jzw0IrLJnJJw7/Z1rggsivGL2qKTUK0X29EjqHMkAxP+3Si2kT+wGZ8Qrbx+lRgRlqcrnV7L4v170Pyd+q5HC22y8AoXgqgi9zLNP3Z7+irQZuX+5KwzM6YWqlXZWPHs/Z9g5RRbCBPJxDHIvB5fJ/edqHf4r4TSa0pGQ==; 20:6b1vyU8fM5k+goFpdwpgL7spBw77xYynUtQejUG6YqLYD2w3yisAD4nChS/RWPG5+FYHt/+UqIZSuEOwUQs2RjX21n9ld7iZRKcDEgm+zRAcq0BuILTGNGVoAkL9i3WJ2TpHHSXy8tXXBuYYVO3GbG/S/SSl7nM9QjiU0oMvSniLhN0ZnOSVh/NSyLNRV68PvzDhisFt/UCgo8CPv1lL781PwXeAh0Zg9j3sanG2g7KxXPa+FVitSxQGnm9o7t/b X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2017 15:23:37.6958 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR12MB0155 Subject: [edk2] [PATCH v5 05/14] OvmfPkg/PlatformPei: Set memory encryption PCD when SEV is enabled X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas.Lendacky@amd.com, leo.duran@amd.com Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Secure Encrypted Virtualization (SEV) guest VMs have the concept of private and shared memory. Private memory is encrypted with the guest-specific key, while shared memory may be encrypted with hypervisor key. Certain types of memory (namely instruction pages and guest page tables) are always treated as private memory by the hardware. For data memory, SEV guest VMs can choose which pages they would like to be private. The choice is done using the standard CPU page tables using the C-bit. When building the initial page table we mark all the memory as private. The patch sets the memory encryption PCD. The PCD is consumed by the following edk2 modules, which manipulate page tables: - PEI phase modules: CapsulePei, DxeIplPeim, S3Resume2Pei. CapsulePei is not used by OVMF. DxeIplPeim consumes the PCD at the end of the PEI phase, when it builds the initial page tables for the DXE core / DXE phase. S3Resume2Pei does not consume the PCD in its entry point function, only when DxeIplPeim branches to the S3 resume path at the end of the PEI phase, and calls S3Resume2Pei's EFI_PEI_S3_RESUME2_PPI.S3RestoreConfig2() member function. Therefore it is safe to set the PCD for these modules in PlatformPei. - DXE phase modules: BootScriptExecutorDxe, CpuDxe, PiSmmCpuDxeSmm. They are all dispatched after the PEI phase, so setting the PCD for them in PlatformPei is safe. (BootScriptExecutorDxe is launched "for real" in the PEI phase during S3 resume, but it caches the PCD into a static variable when its entry point is originally invoked in DXE.) Cc: Jordan Justen Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brijesh Singh Reviewed-by: Laszlo Ersek --- OvmfPkg/OvmfPkgIa32.dsc | 3 + OvmfPkg/OvmfPkgIa32X64.dsc | 3 + OvmfPkg/OvmfPkgX64.dsc | 3 + OvmfPkg/PlatformPei/PlatformPei.inf | 3 + OvmfPkg/PlatformPei/Platform.h | 5 ++ OvmfPkg/PlatformPei/AmdSev.c | 62 ++++++++++++++++++++ OvmfPkg/PlatformPei/Platform.c | 1 + 7 files changed, 80 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 25b7d73807b6..ce73ddb12d1a 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -532,6 +532,9 @@ [PcdsDynamicDefault] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000 =20 + # Set memory encryption mask + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode|0x01 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout|100000 diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 88bf73b3fa01..ef245635224c 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -540,6 +540,9 @@ [PcdsDynamicDefault] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000 =20 + # Set memory encryption mask + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode|0x01 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout|100000 diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index b34fed16a860..0a693f2772a7 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -539,6 +539,9 @@ [PcdsDynamicDefault] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|64 gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds|50000 =20 + # Set memory encryption mask + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode|0x01 gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout|100000 diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index a1e12c1fc7e2..16a8db7b0bd2 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -29,6 +29,7 @@ [Defines] # =20 [Sources] + AmdSev.c Cmos.c FeatureControl.c Fv.c @@ -60,6 +61,7 @@ [LibraryClasses] QemuFwCfgLib QemuFwCfgS3Lib MtrrLib + MemEncryptSevLib PcdLib =20 [Pcd] @@ -93,6 +95,7 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdPropertiesTableEnable gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 18f42c3f0ea8..a7729b9df44b 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -88,6 +88,11 @@ XenDetect ( VOID ); =20 +VOID +AmdSevInitialize ( + VOID + ); + extern BOOLEAN mXen; =20 VOID diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c new file mode 100644 index 000000000000..26f7c3fdbb13 --- /dev/null +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -0,0 +1,62 @@ +/**@file + Initialize Secure Encrypted Virtualization (SEV) support + + Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD + License which accompanies this distribution. The full text of the licen= se + may be found at http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +// +// The package level header files this module uses +// +#include + +#include +#include +#include +#include +#include + +/** + + Function checks if SEV support is available, if present then it sets + the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption m= ask. + + **/ +VOID +EFIAPI +AmdSevInitialize ( + VOID + ) +{ + CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx; + UINT64 EncryptionMask; + RETURN_STATUS PcdStatus; + + // + // Check if SEV is enabled + // + if (!MemEncryptSevIsEnabled ()) { + return; + } + + // + // 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 + // + PcdStatus =3D PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, Encryption= Mask); + ASSERT_RETURN_ERROR (PcdStatus); + + DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask)); +} diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 3e9fda7c7ab0..ede4a1298558 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -668,6 +668,7 @@ InitializePlatform ( NoexecDxeInitialization (); } =20 + AmdSevInitialize (); MiscInitialization (); InstallFeatureControlCallback (); =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel