From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on060f.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe49::60f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C7DA682101 for ; Sun, 26 Feb 2017 09:43:21 -0800 (PST) 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=pyPdjWsSID7jCmTZPNkiT2JeL8QXOtloY4t6Qm4AxSc=; b=fNtfPLzxL+QtXsOjReRhm6GeaHXLxdboVOpsTuMOWTPLP4lI0Tr8Iww+6C8nHIx9fLQcvvW2tMLAwstgEAzphAEmMYIjS1/2oHeOnly2XFkSvtm8LPWZfdujTak5J9y2fjGx+EsvSj1HZ9bn9fuDvK1lglsrNOwMTAopKsZ5UpM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by CY4PR12MB1238.namprd12.prod.outlook.com (10.168.167.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.919.13; Sun, 26 Feb 2017 17:43:19 +0000 From: Leo Duran To: CC: Leo Duran , Feng Tian , Star Zeng , Laszlo Ersek , Brijesh Singh Date: Sun, 26 Feb 2017 11:43:03 -0600 Message-ID: <1488130987-2544-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488130987-2544-1-git-send-email-leo.duran@amd.com> References: <1488130987-2544-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR13CA0028.namprd13.prod.outlook.com (10.168.240.142) To CY4PR12MB1238.namprd12.prod.outlook.com (10.168.167.13) X-MS-Office365-Filtering-Correlation-Id: 807f0dd8-946e-47a0-5cb4-08d45e6ef3aa X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:CY4PR12MB1238; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1238; 3:HDxMkRP4EQMT00TWrO07qZuXByX1DDoSZqh8W2tDCuFzg5d142ubIcKY1U3mTGjUkiAXsOQiVe4CBuzpJSSbfAwkyWahHA9gEkBLpweeJz8M6LoAX8aeVrcoyrcbJrwDh6atlbrTlDokr6+Nh6YoqdgzVlMOZVlnWLhKMNl5UuwaL1uvfVek90ZU9rozPVr9Zaaql0P2sz4s4ZHvcVEn8g5ic0R427JEJb4rgpH1ld1/SbOfenA7kB9x6VmUM3c20eN4DIrVmnS715CxpChCPwmDBozcIArYRPMX3FO3jrI=; 25:iyTKICSaHe99s8tTe7T/rtYwxj6HFCInfEc9jRrnAJT3eFVdP9MwzssjuyoJEhYE6fA9FTJvmQE0pb/rxUSluEH0v7Yw+zImG36/o6bgQnY5T7VXB3JpQ9r5EYk4nX7ea35EpcUY4190IZJTJq3oTzyQDfypFcYmS6V8BkY5+STqDJe6ZFbCndQOrOUeHqDzfV/Xr/L9cZesYoVN4ffU9v76sYpzpFYYy+7/rpCP/Baq4i5ejRVsYv9BRKOdp6R+TjSv+L1Ye9z4SPvRgS6pjjls1lNdwurT2s/N+qNGPJUZNxCpSqOnol+lI54tOz86zSHniAjUaDozEn1B14dWXMPqCOxNY4CA2wOMdZJePCbapQIyOJGDGYV6GOSCNeafF19Nslh062EUKPAewreEfh4lECi+8RelELUdhya8uzlDXXPI5Z2EJQ5dbBjdo1OeFEPNig97lf/J/VUhUUKNJg== X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1238; 31:gZd0gCliUI5DcXj+qqcaewFIA9aPBfjD1MXwVv2psLBPq8yQ1ulaYQlxfQs/KRC3u4sqZIkd3K6SlYAyVuGKfudWMOY00S+K7PSxS8rtbhd43JxpnICN1OpcK798f09lUbyFZfeA7ol/h6ZqKSdJHmKtkzqdKfDcekN8PPIhka5W0r1qD4FI5efjcfxtFQENefYL1PyBct3DuJA+S5nKpbtVRmOTg+Dg2HlaTp3vF+U=; 20:nbcePofFwKYkFQ7bKlH/1hORmhk9y2TrHPolbOTqLQRl+oMup6g+SOmBYNA1nEf+QVFUlGQ3MFv58V88yCNNHNxbIUREqk+430mQEzVh8UevavgSgPtX05cBcep0tl0KpjUJ43K8JIqfuVsVdbUSOBFOL/m18+dQBwGPtKl+kZaXqJ7+8AP1FJ+LApUT47zWDNEyCFR8GH01Vnd7a/NPHzQHwQngWrxCabz7awXq4iRfWwfldinFCXxJparm+pt56VV1xQVCBETU5d6hJLWIpbbxO/8zP7pBZx8AZFfSY4OV7EB0LvfwsGTxpuFcUCioWiZo05Z9lJr7cPio3MO/ipEKDpOWJw3SX2dW5laJHwEG7lsvaYd33Vp/7990q2UEWgwo+5lmwoms+xZRxxRbvJUfFjKRQeFuhtV3Tn+ZRbUkteC60l2v5y7pREzF7i/0FGYuX4kcY8uU8KxsmhiyuaoHIGqdPyp8kQS/Nge1IAfycT6GVLt750ULkKjMJ6vS X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(20161123558025)(6072148); SRVR:CY4PR12MB1238; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1238; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1238; 4:Hisd0dRoLZIc5aqKu3k3tuGs/A/UFaBTqqxqvStQitQqn8XA/VRHKoFbcD8G9GmFNq/utGkG/aY8ttM469R3LxM7wESCZKhG90sOGmI2+exLSJ8DOlCiTUZUJAOaRXBFPJWoQ3WYyOyJuJbQolESjeSi7QqNXBygCVA8fRIztY+yl/Sd5VwBwoXor44Q7Oxky6WnW2MrPej6DvWsJt/WdLAsfip1Tw5E15tF3MfLNAjeG2fhi31RDXVeqwUr8wuikcXXmwkyWSp5HYCVnir8pfwK4FTP4d+0T9VWVDDTsGV7aFRaza9N0QESqeuYdsrH1jExobD4Aq5b77THFwOFh//2K3dY7hnnL9uvi1rnBD0DP2/pT2Qh9Vj8iUw/2wtT1po0txfPoMc9DwGNl5k4q5HO5xWrHcLYtFuCC3up/S8sMJ2FJa7HeN0hdAVXhcPLTwd7MRQZw3pZMHCqSVLDGZOVdxhU9BYUWNrgJ8xIDz1ml/fimca3Ta1CpwWOLzfdQT6nkRI817uwGwKY8Py2wGtn0DZdOwmjgIbuDEJ0XybL5JHgmsgJdP1bIrLLQCSfQkeytzFNqNEo9f7ZuEfWKRpiqv1FkD7De9ykWngUmoqBB1W9DJDmoE1Rz17Huv+KYGd5ba0528xXYw+JPAghP/E6nuQkzcVh+bU7h+9lFtYArjntpCgg4ywnb9n5Cgai X-Forefront-PRVS: 0230B09AC4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(7916002)(39450400003)(39840400002)(39410400002)(39850400002)(189002)(199003)(305945005)(53416004)(105586002)(106356001)(68736007)(33646002)(5003940100001)(92566002)(2351001)(189998001)(42186005)(81156014)(86362001)(97736004)(7736002)(6116002)(81166006)(36756003)(8676002)(54906002)(3846002)(50226002)(110136004)(6486002)(47776003)(66066001)(101416001)(25786008)(53936002)(38730400002)(50986999)(48376002)(50466002)(6666003)(76176999)(5660300001)(2906002)(2950100002)(6916009)(4326007)(213903007)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1238; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1238; 23:GzFwS79AeaUHkGLvQyUbNetnzRGkO1Yk0Kq0NRE5y?= =?us-ascii?Q?IA+MMrdBFCn6xYwPpdrKhdqJSCRuctGwfLozK9EB6X5sE4qA9mnmH66DPCXo?= =?us-ascii?Q?45UvE6PeISm8rLgRHX3CN5BGh6HL/6TKnKz0iU9ybuz/kGdWQXZrtVGJssTb?= =?us-ascii?Q?oIhIcHKVoz2C5YW1HOTE/wzMdLQ4gpZ+5Qmxv+1p/1wST+9evlhRW5OP5izl?= =?us-ascii?Q?gfXOQP4xUAXVhGFBLSv8parrjY9ybtE9DdU64QV4DrC62k8YZkz4/lOyhlfF?= =?us-ascii?Q?1EuSEVLPB3jJk4gsFs+M6KT/xJdZNE/lhpO7XC/+teEciLus9o3aWyly0eT+?= =?us-ascii?Q?49wIFydX9NuKSEh7XKgRRXy/pQFNd+f6cPqH6EgDBSh8enc7W8CPPCctBvvc?= =?us-ascii?Q?B/PIRsNwhkuzv8acGJJina0cE/9/qOqEx6r9WJGzRs0X0ndoT9YWJbLrBT5O?= =?us-ascii?Q?8jj8xxVJPWmwASKLwgJpteMGUk92SmlLRMBmnMSh7wEmaNP9kzIx9pKKgwCF?= =?us-ascii?Q?3KP0R6irTKeO3xrw678v7gA1Q//8FCaoA3pSKWA09RfNyk15RIzr8uB9xW7n?= =?us-ascii?Q?CNU1qrLws0peqcHwBO/BEmG4EMm3L++yM7bR8r1kuqbjXYRvHqcEjML6QpOE?= =?us-ascii?Q?On4mBgQSDMDUfdODiebdQmveV3uHwpmMWjeg57tY6ejE3sQCVhOQgHuD/jVV?= =?us-ascii?Q?+6nQOd/OGrLtaErHJTrGxvdXKuF87bRAGdkF3Ymfkna2ba83HyKjA74rV1YM?= =?us-ascii?Q?iWMzXjS2AOtREW4fySDp+kkGv02FYL8wkS3pzTystev5thsQzPuAK0oKqRD6?= =?us-ascii?Q?Jry5nDDRux9zl+K0/x6CZgJugwTE8C7pCaskDZjoXdRrSS/VajDxtsN+70F6?= =?us-ascii?Q?xPtZgHledKyASwPJl1pEI+zQWGhL+se6k6eK85XrAFFdAdrZHwyBSMRHxpu3?= =?us-ascii?Q?1nMogS2IUIFAN70+Y+mi0akj2U+/+Sm1dQaF2ISVUbaYWDh+MTKQNqz7xBIh?= =?us-ascii?Q?swXbEk6mRS4tRnL0coZIbTBBeDCkcokdTG4xgccHuEBv7d0jUHxI+i8djHLR?= =?us-ascii?Q?TZwivs5NL7TKCJjz/PMG0jXq8s+ILCDtO0JJawJlkvHWJWTLaISAWNyQ0JhD?= =?us-ascii?Q?HWWjFFTwf72Ig+8Fyr8HFKSYEokpUM9jD7++L8mlzg+nDEbu+H7erYJSXFy5?= =?us-ascii?Q?g5kFThGrzUTxh1F/yG6f2AhDOpf4ifY6TbhRO4Mf5jZMjyDncJWYZw5j2rin?= =?us-ascii?Q?/gY8CwBQcuIJ9Fq7dJxNIiN0GY61b8MJqvIzkkX?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1238; 6:AjTXK87BBh3U3eyrBmW4qP9LHc35uNB5wkOUQyd590p13s7S28ZNcwOFjzpVnXvNovkRaoEPoPhO102+TDktKjqz1QJaOh26/CMPtUhtNocuUzoHL8YnuKJTxqC6eBn0KnwNAjKX+W/xgeTb6S3v37mG8V6y2XifEvMtcZjeqv09PdEKg0W6dbNWpAbBIWc6ae5JKsohnqZ/1FWi6VzhIgbkfRP/zV04V6PSfTZGtWhUGv4Bplm9AaW/AMcvBx1NeRx4v4vSK8h7cfyIPnzvDaG5Dl+j3TlOM8XdgngYZCZ2bOUBue8KGyqp3v0Hh5G78hh7idXXbrJjCqCQ2mlIo9XxoKjmKRU691wV9vkxC/xY8/AMjHew4sLLQH509+Q1yJ4OHF/lZQlsMR5UARkpIjQvPSNFOFB6qvStOL/JOkw=; 5:ZrCJYIiKNUCr67MwYx/I3kgvAGjqLSGlhPHRMXt7zU6/ef7Q/VmJ8pT1+y9IesDymIk6sA+m1qLx6Hqt6F8ak+CYozQeJiXAgwPSfuPj33slpX69lk10bvN1Xmojv10iNpTyV5gpgEfyBuN36Jky9w==; 24:O0+2k5RTVyMVFnuiBeUClTMMoJTnhmrdcbfCsaLes+VzFAUvHzp+2kTgtzRRPT0365YCI4OZQyVnjorqli8z7J3PHqOynOSOFqbP7livF1k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1238; 7:1dnDl5V5NWSeGnCYe1ocu3JbvjETYk3WAfybgg3cYzj2Rm6lA6tlTQB5jI9iwjUEX1eso2ELM0qjRKy/Y4lPFKL7so08Us/XMGbT9AcpEUROGQXmEG2qFHkJTIndMFz2VdRXjLrfJcGSCwZR4nFq7S18JhDHJhA6Re4MTshSOvsO5bY+QgLGyLo6f+RESR94XbTy0ikuEzxii1uQ9qc/FK6AOLRog49NIW5AvBEralmoXSM58qfCA435z/3n+xqhYBwgV6VRPV4Xdoldqm50cuB/7HDY4K9VEQuwlkHIXxKGvjPKEelTKO+EvlFciGHQceXb2U5Z6yP/G/KgdwSj1g==; 20:9y0eRAd+LoTIDMjAikSqbAEXnvdHN/vPsTe7yo/dfR8JuJ0cLsy474cLdvsA78aaytEzTfQD4xTZlTrLi4MZgGQy7T6liu8uM7HG1Hr68UQ/biso709zTG7VH5cpfYKzzGMUUmTM1OS1D6KTd9ql+3HSECs3LLHoWS/OW/UZFULztwnn4HJ4pr6gYcdMeqvCk2D0e8ybaucG3DrbfEEOxuCHG+NEk6J8I9MnDc2yj1O111/TQbGXrNI32dPpiOQS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2017 17:43:19.0642 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1238 Subject: [PATCH v4 2/6] MdeModulePkg/Core/DxeIplPeim: Add support for PCD PcdPteMemoryEncryptionAddressOrMask X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Feb 2017 17:43:22 -0000 Content-Type: text/plain This PCD holds the address mask for page table entries when memory encryption is enabled on AMD processors supporting the Secure Encrypted Virtualization (SEV) feature. The mask is applied when creating page tables. Cc: Feng Tian Cc: Star Zeng Cc: Laszlo Ersek Cc: Brijesh Singh Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leo Duran Reviewed-by: Star Zeng --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 5 ++- MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 12 ++++++-- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 39 +++++++++++++++++++----- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h | 5 +++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf index 2bc41be..d62bd9b 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -6,6 +6,8 @@ # needed to run the DXE Foundation. # # Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2017, AMD Incorporated. 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 license may be found at @@ -111,7 +113,8 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportUefiDecompress ## CONSUMES [Pcd.IA32,Pcd.X64] - gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 8f6a97a..1957326 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -2,6 +2,8 @@ Ia32-specific functionality for DxeLoad. Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2017, AMD Incorporated. 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 license may be found at @@ -82,6 +84,12 @@ Create4GPageTablesIa32Pae ( PAGE_TABLE_ENTRY *PageDirectoryEntry; UINTN TotalPagesNum; UINTN PageAddress; + UINT64 AddressEncMask; + + // + // Make sure AddressEncMask is contained to smallest supported address field + // + AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; PhysicalAddressBits = 32; @@ -111,7 +119,7 @@ Create4GPageTablesIa32Pae ( // // Fill in a Page Directory Pointer Entries // - PageDirectoryPointerEntry->Uint64 = (UINT64) (UINTN) PageDirectoryEntry; + PageDirectoryPointerEntry->Uint64 = (UINT64) (UINTN) PageDirectoryEntry | AddressEncMask; PageDirectoryPointerEntry->Bits.Present = 1; for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress += SIZE_2MB) { @@ -124,7 +132,7 @@ Create4GPageTablesIa32Pae ( // // Fill in the Page Directory entries // - PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress; + PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress | AddressEncMask; PageDirectoryEntry->Bits.ReadWrite = 1; PageDirectoryEntry->Bits.Present = 1; PageDirectoryEntry->Bits.MustBe1 = 1; diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index 790f6ab..48150be 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -16,6 +16,8 @@ 3) IA-32 Intel(R) Architecture Software Developer's Manual Volume 3:System Programmer's Guide, Intel Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2017, AMD Incorporated. 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 license may be found at @@ -29,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "DxeIpl.h" #include "VirtualMemory.h" + /** Enable Execute Disable Bit. @@ -65,20 +68,27 @@ Split2MPageTo4K ( EFI_PHYSICAL_ADDRESS PhysicalAddress4K; UINTN IndexOfPageTableEntries; PAGE_TABLE_4K_ENTRY *PageTableEntry; + UINT64 AddressEncMask; + + // + // Make sure AddressEncMask is contained to smallest supported address field + // + AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; PageTableEntry = AllocatePages (1); ASSERT (PageTableEntry != NULL); + // // Fill in 2M page entry. // - *PageEntry2M = (UINT64) (UINTN) PageTableEntry | IA32_PG_P | IA32_PG_RW; + *PageEntry2M = (UINT64) (UINTN) PageTableEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW; PhysicalAddress4K = PhysicalAddress; for (IndexOfPageTableEntries = 0; IndexOfPageTableEntries < 512; IndexOfPageTableEntries++, PageTableEntry++, PhysicalAddress4K += SIZE_4KB) { // // Fill in the Page Table entries // - PageTableEntry->Uint64 = (UINT64) PhysicalAddress4K; + PageTableEntry->Uint64 = (UINT64) PhysicalAddress4K | AddressEncMask; PageTableEntry->Bits.ReadWrite = 1; PageTableEntry->Bits.Present = 1; if ((PhysicalAddress4K >= StackBase) && (PhysicalAddress4K < StackBase + StackSize)) { @@ -110,13 +120,20 @@ Split1GPageTo2M ( EFI_PHYSICAL_ADDRESS PhysicalAddress2M; UINTN IndexOfPageDirectoryEntries; PAGE_TABLE_ENTRY *PageDirectoryEntry; + UINT64 AddressEncMask; + + // + // Make sure AddressEncMask is contained to smallest supported address field + // + AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; PageDirectoryEntry = AllocatePages (1); ASSERT (PageDirectoryEntry != NULL); + // // Fill in 1G page entry. // - *PageEntry1G = (UINT64) (UINTN) PageDirectoryEntry | IA32_PG_P | IA32_PG_RW; + *PageEntry1G = (UINT64) (UINTN) PageDirectoryEntry | AddressEncMask | IA32_PG_P | IA32_PG_RW; PhysicalAddress2M = PhysicalAddress; for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += SIZE_2MB) { @@ -129,7 +146,7 @@ Split1GPageTo2M ( // // Fill in the Page Directory entries // - PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress2M; + PageDirectoryEntry->Uint64 = (UINT64) PhysicalAddress2M | AddressEncMask; PageDirectoryEntry->Bits.ReadWrite = 1; PageDirectoryEntry->Bits.Present = 1; PageDirectoryEntry->Bits.MustBe1 = 1; @@ -171,6 +188,12 @@ CreateIdentityMappingPageTables ( VOID *Hob; BOOLEAN Page1GSupport; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; + UINT64 AddressEncMask; + + // + // Make sure AddressEncMask is contained to smallest supported address field + // + AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; Page1GSupport = FALSE; if (PcdGetBool(PcdUse1GPageTable)) { @@ -248,7 +271,7 @@ CreateIdentityMappingPageTables ( // // Make a PML4 Entry // - PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry; + PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | AddressEncMask; PageMapLevel4Entry->Bits.ReadWrite = 1; PageMapLevel4Entry->Bits.Present = 1; @@ -262,7 +285,7 @@ CreateIdentityMappingPageTables ( // // Fill in the Page Directory entries // - PageDirectory1GEntry->Uint64 = (UINT64)PageAddress; + PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | AddressEncMask; PageDirectory1GEntry->Bits.ReadWrite = 1; PageDirectory1GEntry->Bits.Present = 1; PageDirectory1GEntry->Bits.MustBe1 = 1; @@ -280,7 +303,7 @@ CreateIdentityMappingPageTables ( // // Fill in a Page Directory Pointer Entries // - PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry; + PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | AddressEncMask; PageDirectoryPointerEntry->Bits.ReadWrite = 1; PageDirectoryPointerEntry->Bits.Present = 1; @@ -294,7 +317,7 @@ CreateIdentityMappingPageTables ( // // Fill in the Page Directory entries // - PageDirectoryEntry->Uint64 = (UINT64)PageAddress; + PageDirectoryEntry->Uint64 = (UINT64)PageAddress | AddressEncMask; PageDirectoryEntry->Bits.ReadWrite = 1; PageDirectoryEntry->Bits.Present = 1; PageDirectoryEntry->Bits.MustBe1 = 1; diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h index 20c31f5..7c9bb49 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -8,6 +8,8 @@ 4) AMD64 Architecture Programmer's Manual Volume 2: System Programming Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2017, AMD Incorporated. 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 license may be found at @@ -23,6 +25,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define SYS_CODE64_SEL 0x38 + #pragma pack(1) typedef union { @@ -148,6 +151,8 @@ typedef union { #define IA32_PG_P BIT0 #define IA32_PG_RW BIT1 +#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull + /** Enable Execute Disable Bit. -- 2.7.4