From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0613.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe44::613]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DDAB1820E6 for ; Thu, 16 Feb 2017 13:02:28 -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=VHWNCeT0ia2gDyQ8py+AkQk2gvCVzwwqEEp9MzbKrcU=; b=ZINvFki7RVAfHCUJM06KKkH/Wp4rkps10l0d3iIkbDf6ftIf9iaU+tR5Nrx7kuh/gcwebg6pIsMZGuQcCMrmarNW+L3jFNjoGzeGNralTF5yfmyZOUt5gmvNrtcVWFG5lWtmJxn3m2LZ1EFU1IJW2o/XPl41NAOEpUfcbeP1aXg= 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 BN6PR12MB1236.namprd12.prod.outlook.com (10.168.227.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Thu, 16 Feb 2017 21:02:27 +0000 From: Leo Duran To: CC: Leo Duran , Feng Tian , Star Zeng , Laszlo Ersek , Brijesh Singh Date: Thu, 16 Feb 2017 15:02:04 -0600 Message-ID: <1487278926-14303-3-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487278926-14303-1-git-send-email-leo.duran@amd.com> References: <1487278926-14303-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM5PR13CA0037.namprd13.prod.outlook.com (10.168.240.151) To BN6PR12MB1236.namprd12.prod.outlook.com (10.168.227.22) X-MS-Office365-Filtering-Correlation-Id: 15c5adb3-b427-4ba7-9749-08d456af1d6f X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:BN6PR12MB1236; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1236; 3:yMuO6IJR392+pXJIHJzWAyOgaiE/UqEMYIeIdZamRNaZ2J5xjtLosIVnnW7UC7bQai/ua3FnxG4BM0+en+75iaBDA6525lbvJVqYZ9O+unZmxY4P+yNtVaNN+BVNtV05LDwiYulGLOb5fAL5bn5+Nb5qku4GRS6NWQocjWdsl/8rUzhFGbD2hzx7R9mC+8Jd/1L36+1JXKK+fY7UTqEzsdTmDsQx6910RaWkBrnuWFrp47wr8snRPGo0meg7cw6snLZhhbexiWSvX+2HP7y/Yvtmpn4Z5BY35GNvhI3wjdg=; 25:IXGYngTtU8oY4zcdNL87oKnNdMdZwuSVwIC2NgwkhebHaCi4YigZ5X9HnbleSZo7Fao3QRjC1K26pMIvAeNNeqTP3xCOGYMLQvJo+F87YyIfJmJxuMpKyMcC+Ct7kck7WVuUSs6k6EunjgxOedXVwJOHhV7Hmxn+N+mgCD2yI+N/uef8o1+tAhg+sckJ+g/CAztYag0Grid+a/dY9jYUe3ixKXMa51P6eg6jCI6/Dey6L3rR8FcV4GGHVuXlQ0igt5/jyx2O3HeFs6Zq7pundtrFBW1BqQPoPmMrnsypx31WzEYUu7uxEUdpYwfuLjXwn/CAAP2xvWxHQD5EC+gR1LZcesVFh77FOI88B0FEJIQIlSrp6SzGN4FVyyJuZdAdeaxtVVa0Hbm/4aRDoTWH2natda5Ec70MCySzTqNskcYDI+DezqL9CRA+hzFCwEk1Aup3pMNKfuZT20bjkLzWdQ== X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1236; 31:aVakooi1BreuOtCVLlLrXJiZtrpsrwYPSoWennaZq53+CR7Nt5iiYF6fVv5nAVemRjT99Dbn+3Xc8+DhrOYrc1sUIv4RZxA7NNNMhw2N0Is+02yKbh4raEGdu5LZaH/WmU8cNO9SF4ZIgQTGosV6inZPwcec+sx8vnIuskfTzLXTrSdDuRUjwTsiuirNrsrAv2tT+6ihDigzR8TKfYcE1tKK19I2kKoz+MbzeTvUVW0=; 20:wOINSGz7GGY/pzDyKnhWy0p4MdLzn1XlwcA1zNfr3lTxE3GrdrpGUkTS+wOan8hGkc8Ni6wnoTaczyUKknj0Ze0RfBBjyuBieLZa2P/y+UivDSqDeVu5IDtGaPFwkqfygrf3uG6GJTKvl1cRsTcN+w7QC0KShZksu9P1uGSIpod8zs1cv2Gu+fdOXUmx0TRWVrUbTJsz3eM6i4wt9lBCS3ZfuhCKJw9izxyXVAw018xdqwkV2WbmWG/wG4YnupwCtJ6QcYgpqaswwzh62i9L2DzQ1wN2+JOeC+iAsYvJ6a6I3l4V6SZiMjI9/JvThoDVt2Chyi0ceWhWTDAODT1eg4MtLsKacr4383ODvaULdp7AmqShBnnQAxRonSZUuE/GU9SD7+HMKGVGZSBa7SHfl7ZkNjaCDegxIIBwl1Q8JrYTQakSibdmSiEYSEA8BE7NQ/7+pg3sHrkY7gohisvExkAXTIo/3meJWQZr11vETper2C2AF1YH3WJKPZ8/Yap8 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)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123558025)(20161123562025)(6072148); SRVR:BN6PR12MB1236; BCL:0; PCL:0; RULEID:; SRVR:BN6PR12MB1236; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1236; 4:WezIVlZvqSPqray5gpBpUMhnpd/7mXe5XB/g1EVMR9medxOJjC/fVwWZ8uNrcTSuYe6SFeaKsWfWc9DWfWR4xH6GnJxBCn/1JAxzgM/tBwpZwT+S4fTGutli4L3Sq9xJptNzRnZQ9OVmi7FXP8BaAO/xUN3wxJeALrNLly9yPzajtpb4yLPPI0ELIqam2uqqWG9ogtgKx/3SzLvxEQHvk9ySCRXaj0lRuUdfJsNZd8RxCWkKbbUNzkO/pLqXYLI7mJpSESAyt4iYL+gAICpZcWxkcAnFl/Z1Kq0TnySbnqoj+VFjzm0I2WGn3zyITVYo0YFShcKs1/wS0d7QBa8NGx7MqnzfLiM8E87istNTD2n6vtVJQKAopByr/f8qaE7hGBT7QDYjrPtQewEpik1ywqFG0R+7Gu79kO+POgyKPDwGH9ORMjGl9KUPLLPCU/AX7HZgfRqU1lX/6/XDAlaT3AAtRN6lmNjPnzif1Ilg44q3iQkNJTx8M86d9343ZjFZ4lVC2YJzKTb+gZbeHHprPSi9NLklj2blmHS3Bjk3DYEw+JaF2TZJu6fTvTTyRiDHxTJVlzJ/yjsbxXqQDCUaTVoE9LK2fr2GzPcrNK3nWtDjCMO1rMZ+MjLKlSmL7GwB5x1zAGkjRPmBMo19iiIAPMBf1KMY8+bRiBIoZqagfM4a/Gj/jyHmxxJFMlLWoX7Wl3jL2Qqknqhe1/PsgTQDiw== X-Forefront-PRVS: 0220D4B98D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6029001)(7916002)(39840400002)(39410400002)(39450400003)(39860400002)(39850400002)(199003)(189002)(54906002)(8676002)(36756003)(6916009)(68736007)(38730400002)(6666003)(6486002)(97736004)(53936002)(50986999)(110136004)(66066001)(76176999)(101416001)(5003940100001)(50466002)(81166006)(50226002)(92566002)(81156014)(6116002)(106356001)(53416004)(42186005)(33646002)(48376002)(189998001)(575784001)(305945005)(2950100002)(7736002)(5660300001)(105586002)(4326007)(2351001)(2906002)(86362001)(3846002)(25786008)(47776003)(389900003)(213903007)(44824005)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1236; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; BN6PR12MB1236; 23:QheN8t1mXEW5ByNzppzs3JJGz7c6acVQG6g2KL+ky?= =?us-ascii?Q?XJZ6RaJN6OCx2luvO03yRImItcyJ8nGPmkXy+0zzF0royCqhtxPoa/Z2XMwN?= =?us-ascii?Q?h+1PQqrxeyVqKVackYmTiO8sMvSonrVAjUUmF0Z2K2ytk490wSI5++FYA59h?= =?us-ascii?Q?soLIaGTYpx6WKcmpwkVpxFG6pV86N/DxLwIfY9RAP9AX+J8j9No7IDhiayoE?= =?us-ascii?Q?d0FUfIPbMjfi0fErnSJBJHv2dijS91CAWvX7N8arnl7Xir/I2zJIZMDS8ltw?= =?us-ascii?Q?FCpAF+MTrWH9uJavGbhm7ubJKa8pPJHNeN4mxoHbT/hrJvJTIv6x52gC7Iw6?= =?us-ascii?Q?jPgUEeB0YpA8yCqgdryyeK2geeLyy7SpAyshMQaq7ZbqX0oWzrO26tjfg0ny?= =?us-ascii?Q?lquJKkqX+RWw/LiPzuJ7hqNK2yNXc251qHUI0CJEEtaniXKxc0yeg8l3k2kl?= =?us-ascii?Q?aVs3QBwKp+7Ow+PaRH84pU2wOn9dBzetaoHIrarbx8gL6sMIlOf1/cCdmLAc?= =?us-ascii?Q?yv9npWdSVhVm31Dcm+xQyaMLUT7fFSV+e0GZepFYUhHApsuaUY0q+183sI22?= =?us-ascii?Q?a3DEltRNprPxDw4cthnptMIuSVbskj5Wo4aiko2Rl6yL6YInjfwMHj4n7Lsb?= =?us-ascii?Q?3XzPaqoMp2hRy3UC14lUQim4oBU+4AHkqghRyMcsgpFOjj7W5E8iNF5w35Fw?= =?us-ascii?Q?ny4rSscMkVI+KQ1NHjHKYeD6Ylt2x8wCWedlqPxrYKuT8/pFyiH+Y4Kc7o4P?= =?us-ascii?Q?7Op8XVrtbr+sm+KgcivQ9E5UbdwUJ0Y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fyake9yXXxtQTLIX7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2017 21:02:27.4776 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1236 Subject: [PATCH v3 2/4] MdeModulePkg/Universal/CapsulePei: 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: Thu, 16 Feb 2017 21:02:29 -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 4GB tables are created (UefiCapsule.c), and when the tables are expanded on-demand by page-faults above 4GB's (X64Entry.c). 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/Universal/CapsulePei/CapsulePei.inf | 2 ++ .../Universal/CapsulePei/Common/CommonHeader.h | 7 +++++++ MdeModulePkg/Universal/CapsulePei/UefiCapsule.c | 13 ++++++++---- MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c | 23 +++++++++++++++------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf index d2ca0d0..c54bc21 100644 --- a/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf +++ b/MdeModulePkg/Universal/CapsulePei/CapsulePei.inf @@ -7,6 +7,7 @@ # buffer overflow, integer overflow. # # 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 @@ -76,6 +77,7 @@ [Pcd.IA32] gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleCoalesceFile ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES [FeaturePcd.IA32] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES diff --git a/MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h b/MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h index 7298874..0a9761e 100644 --- a/MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h +++ b/MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h @@ -2,6 +2,8 @@ Common header file. Copyright (c) 2011 - 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 @@ -20,6 +22,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // #define EXTRA_PAGE_TABLE_PAGES 8 +#define PAGING_4K_ADDRESS_MASK_64 0x000FFFFFFFFFF000ull +#define PAGING_2M_ADDRESS_MASK_64 0x000FFFFFFFE00000ull +#define PAGING_1G_ADDRESS_MASK_64 0x000FFFFFC0000000ull + // // This capsule PEIM puts its private data at the start of the // coalesced capsule. Here's the structure definition. @@ -60,6 +66,7 @@ typedef struct { EFI_PHYSICAL_ADDRESS MemoryBase64Ptr; EFI_PHYSICAL_ADDRESS MemorySize64Ptr; BOOLEAN Page1GSupport; + UINT64 PteMemoryEncryptionAddressOrMask; } SWITCH_32_TO_64_CONTEXT; typedef struct { diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c index 9ac9d22..7c651f6 100644 --- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c +++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c @@ -2,6 +2,7 @@ Capsule update PEIM for UEFI2.0 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 @@ -145,6 +146,7 @@ Create4GPageTables ( PAGE_TABLE_ENTRY *PageDirectoryEntry; UINTN BigPageAddress; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; + UINT64 AddressSetMask; // // Create 4G page table by default, @@ -168,6 +170,8 @@ Create4GPageTables ( // BigPageAddress = (UINTN) PageTablesAddress; + AddressSetMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask); + // // By architecture only one PageMapLevel4 exists - so lets allocate storage for it. // @@ -187,7 +191,7 @@ Create4GPageTables ( // // Make a PML4 Entry // - PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry; + PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry | (AddressSetMask & PAGING_4K_ADDRESS_MASK_64); PageMapLevel4Entry->Bits.ReadWrite = 1; PageMapLevel4Entry->Bits.Present = 1; @@ -198,7 +202,7 @@ Create4GPageTables ( // // Fill in the Page Directory entries // - PageDirectory1GEntry->Uint64 = (UINT64)PageAddress; + PageDirectory1GEntry->Uint64 = (UINT64)PageAddress | (AddressSetMask & PAGING_1G_ADDRESS_MASK_64); PageDirectory1GEntry->Bits.ReadWrite = 1; PageDirectory1GEntry->Bits.Present = 1; PageDirectory1GEntry->Bits.MustBe1 = 1; @@ -215,7 +219,7 @@ Create4GPageTables ( // // Fill in a Page Directory Pointer Entries // - PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry; + PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry | (AddressSetMask & PAGING_4K_ADDRESS_MASK_64); PageDirectoryPointerEntry->Bits.ReadWrite = 1; PageDirectoryPointerEntry->Bits.Present = 1; @@ -223,7 +227,7 @@ Create4GPageTables ( // // Fill in the Page Directory entries // - PageDirectoryEntry->Uint64 = (UINT64)PageAddress; + PageDirectoryEntry->Uint64 = (UINT64)PageAddress | (AddressSetMask & PAGING_2M_ADDRESS_MASK_64); PageDirectoryEntry->Bits.ReadWrite = 1; PageDirectoryEntry->Bits.Present = 1; PageDirectoryEntry->Bits.MustBe1 = 1; @@ -443,6 +447,7 @@ ModeSwitch ( Context.MemoryBase64Ptr = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemoryBase64; Context.MemorySize64Ptr = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemorySize64; Context.Page1GSupport = Page1GSupport; + Context.PteMemoryEncryptionAddressOrMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask); // // Prepare data for return back diff --git a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c index 5ad95d2..2197502 100644 --- a/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c +++ b/MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c @@ -2,6 +2,8 @@ The X64 entrypoint is used to process capsule in long mode. Copyright (c) 2011 - 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 @@ typedef struct _PAGE_FAULT_CONTEXT { UINT64 PhyMask; UINTN PageFaultBuffer; UINTN PageFaultIndex; + UINT64 PteMemoryEncryptionAddressOrMask; // // Store the uplink information for each page being used. // @@ -114,6 +117,7 @@ AcquirePage ( ) { UINTN Address; + UINT64 AddressSetMask; Address = PageFaultContext->PageFaultBuffer + EFI_PAGES_TO_SIZE (PageFaultContext->PageFaultIndex); ZeroMem ((VOID *) Address, EFI_PAGES_TO_SIZE (1)); @@ -121,14 +125,16 @@ AcquirePage ( // // Cut the previous uplink if it exists and wasn't overwritten. // - if ((PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] != NULL) && ((*PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] & PageFaultContext->PhyMask) == Address)) { + if ((PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] != NULL) && + ((*PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] & PageFaultContext->PhyMask) == Address)) { *PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] = 0; } // // Link & Record the current uplink. // - *Uplink = Address | IA32_PG_P | IA32_PG_RW; + AddressSetMask = PageFaultContext->PteMemoryEncryptionAddressOrMask; + *Uplink = Address | (AddressSetMask & PAGING_4K_ADDRESS_MASK_64) | IA32_PG_P | IA32_PG_RW; PageFaultContext->PageFaultUplink[PageFaultContext->PageFaultIndex] = Uplink; PageFaultContext->PageFaultIndex = (PageFaultContext->PageFaultIndex + 1) % EXTRA_PAGE_TABLE_PAGES; @@ -153,6 +159,7 @@ PageFaultHandler ( UINT64 *PageTable; UINT64 PFAddress; UINTN PTIndex; + UINT64 AddressSetMask; // // Get the IDT Descriptor. @@ -163,6 +170,7 @@ PageFaultHandler ( // PageFaultContext = (PAGE_FAULT_CONTEXT *) (UINTN) (Idtr.Base - sizeof (PAGE_FAULT_CONTEXT)); PhyMask = PageFaultContext->PhyMask; + AddressSetMask = PageFaultContext->PteMemoryEncryptionAddressOrMask; PFAddress = AsmReadCr2 (); DEBUG ((EFI_D_ERROR, "CapsuleX64 - PageFaultHandler: Cr2 - %lx\n", PFAddress)); @@ -179,19 +187,19 @@ PageFaultHandler ( if ((PageTable[PTIndex] & IA32_PG_P) == 0) { AcquirePage (PageFaultContext, &PageTable[PTIndex]); } - PageTable = (UINT64*)(UINTN)(PageTable[PTIndex] & PhyMask); + PageTable = (UINT64*)(UINTN)((PageTable[PTIndex] & ~(AddressSetMask & PAGING_4K_ADDRESS_MASK_64)) & PhyMask); PTIndex = BitFieldRead64 (PFAddress, 30, 38); // PDPTE if (PageFaultContext->Page1GSupport) { - PageTable[PTIndex] = (PFAddress & ~((1ull << 30) - 1)) | IA32_PG_P | IA32_PG_RW | IA32_PG_PS; + PageTable[PTIndex] = ((PFAddress | (AddressSetMask & PAGING_1G_ADDRESS_MASK_64)) & ~((1ull << 30) - 1)) | IA32_PG_P | IA32_PG_RW | IA32_PG_PS; } else { if ((PageTable[PTIndex] & IA32_PG_P) == 0) { AcquirePage (PageFaultContext, &PageTable[PTIndex]); } - PageTable = (UINT64*)(UINTN)(PageTable[PTIndex] & PhyMask); + PageTable = (UINT64*)(UINTN)((PageTable[PTIndex] & ~(AddressSetMask & PAGING_4K_ADDRESS_MASK_64)) & PhyMask); PTIndex = BitFieldRead64 (PFAddress, 21, 29); // PD - PageTable[PTIndex] = (PFAddress & ~((1ull << 21) - 1)) | IA32_PG_P | IA32_PG_RW | IA32_PG_PS; + PageTable[PTIndex] = ((PFAddress | (AddressSetMask & PAGING_2M_ADDRESS_MASK_64)) & ~((1ull << 21) - 1)) | IA32_PG_P | IA32_PG_RW | IA32_PG_PS; } return NULL; @@ -244,6 +252,7 @@ _ModuleEntryPoint ( // Hook page fault handler to handle >4G request. // PageFaultIdtTable.PageFaultContext.Page1GSupport = EntrypointContext->Page1GSupport; + PageFaultIdtTable.PageFaultContext.PteMemoryEncryptionAddressOrMask = EntrypointContext->PteMemoryEncryptionAddressOrMask; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) (X64Idtr.Base + (14 * sizeof (IA32_IDT_GATE_DESCRIPTOR))); HookPageFaultHandler (IdtEntry, &(PageFaultIdtTable.PageFaultContext)); @@ -298,4 +307,4 @@ _ModuleEntryPoint ( // ASSERT (FALSE); return EFI_SUCCESS; -} \ No newline at end of file +} -- 2.7.4