From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, ray.ni@intel.com
Cc: Eric Dong <eric.dong@intel.com>
Subject: Re: [edk2-devel] [PATCH 2/4] UefiCpuPkg/CpuDxe: Support parsing 5-level page table
Date: Tue, 23 Jul 2019 11:22:36 +0200 [thread overview]
Message-ID: <5d8ff62d-606e-ecee-ee72-6f7597388ebd@redhat.com> (raw)
In-Reply-To: <20190722081547.56100-3-ray.ni@intel.com>
On 07/22/19 10:15, Ni, Ray wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2008
>
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> ---
> UefiCpuPkg/CpuDxe/CpuPageTable.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> index c369b44f12..8e959eb2b7 100644
> --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c
> +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c
> @@ -1,7 +1,7 @@
> /** @file
> Page table management support.
>
> - Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
>
> SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -276,25 +276,43 @@ GetPageTableEntry (
> UINTN Index2;
> UINTN Index3;
> UINTN Index4;
> + UINTN Index5;
> UINT64 *L1PageTable;
> UINT64 *L2PageTable;
> UINT64 *L3PageTable;
> UINT64 *L4PageTable;
> + UINT64 *L5PageTable;
> UINT64 AddressEncMask;
> + IA32_CR4 Cr4;
> + BOOLEAN Enable5LevelPaging;
>
> ASSERT (PagingContext != NULL);
>
> + Index5 = ((UINTN)RShiftU64 (Address, 48)) & PAGING_PAE_INDEX_MASK;
> Index4 = ((UINTN)RShiftU64 (Address, 39)) & PAGING_PAE_INDEX_MASK;
> Index3 = ((UINTN)Address >> 30) & PAGING_PAE_INDEX_MASK;
> Index2 = ((UINTN)Address >> 21) & PAGING_PAE_INDEX_MASK;
> Index1 = ((UINTN)Address >> 12) & PAGING_PAE_INDEX_MASK;
>
> + Cr4.UintN = AsmReadCr4 ();
> + Enable5LevelPaging = (BOOLEAN) (Cr4.Bits.LA57 == 1);
> +
> // Make sure AddressEncMask is contained to smallest supported address field.
> //
> AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64;
>
> if (PagingContext->MachineType == IMAGE_FILE_MACHINE_X64) {
> - L4PageTable = (UINT64 *)(UINTN)PagingContext->ContextData.X64.PageTableBase;
> + if (Enable5LevelPaging) {
> + L5PageTable = (UINT64 *)(UINTN)PagingContext->ContextData.X64.PageTableBase;
> + if (L5PageTable[Index5] == 0) {
> + *PageAttribute = PageNone;
> + return NULL;
> + }
> +
> + L4PageTable = (UINT64 *)(UINTN)(L5PageTable[Index5] & ~AddressEncMask & PAGING_4K_ADDRESS_MASK_64);
> + } else {
> + L4PageTable = (UINT64 *)(UINTN)PagingContext->ContextData.X64.PageTableBase;
> + }
> if (L4PageTable[Index4] == 0) {
> *PageAttribute = PageNone;
> return NULL;
>
The patch seems to be a no-op if Enable5LevelPaging is FALSE, so that's
good.
Questions:
(1) Same question as under patch #1: is the CR4 check reliable on AMD
processors too?
(2) Should we read CR4 (or call CPUID) every time this function is
invoked? Can we perform the check at CpuDxe startup, and cache the result?
(3) Should we consider the PCD (from patch #3) before accessing the
hardware (CR4 / CPUID alike)?
Thanks
Laszlo
next prev parent reply other threads:[~2019-07-23 9:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 8:15 [PATCH 0/4] Support 5-level paging in DXE long mode Ni, Ray
2019-07-22 8:15 ` [PATCH 1/4] UefiCpuPkg/MpInitLib: Enable 5-level paging for AP when BSP's enabled Ni, Ray
2019-07-23 9:15 ` [edk2-devel] " Laszlo Ersek
2019-07-24 7:02 ` Ni, Ray
2019-07-22 8:15 ` [PATCH 2/4] UefiCpuPkg/CpuDxe: Support parsing 5-level page table Ni, Ray
2019-07-23 9:22 ` Laszlo Ersek [this message]
2019-07-24 7:03 ` [edk2-devel] " Ni, Ray
2019-07-25 17:19 ` Laszlo Ersek
2019-07-22 8:15 ` [PATCH 3/4] MdeModulePkg/DxeIpl: Introduce PCD PcdUse5LevelPageTable Ni, Ray
2019-07-23 2:05 ` [edk2-devel] " Wu, Hao A
2019-07-23 14:20 ` Ni, Ray
2019-07-24 2:02 ` Dong, Eric
2019-07-22 8:15 ` [PATCH 4/4] MdeModulePkg/DxeIpl: Create 5-level page table for long mode Ni, Ray
2019-07-23 2:05 ` [edk2-devel] " Wu, Hao A
2019-07-23 7:48 ` Laszlo Ersek
2019-07-23 19:45 ` Singh, Brijesh
2019-07-23 9:46 ` Laszlo Ersek
2019-07-23 15:29 ` Ni, Ray
2019-07-23 19:20 ` Laszlo Ersek
2019-07-23 23:54 ` Michael D Kinney
2019-07-24 1:40 ` Ni, Ray
[not found] ` <15B3ACB4E8DDF416.7925@groups.io>
2019-07-22 8:28 ` [edk2-devel] [PATCH 3/4] MdeModulePkg/DxeIpl: Introduce PCD PcdUse5LevelPageTable Ni, Ray
[not found] ` <15B3ACB536E52165.29669@groups.io>
2019-07-22 8:28 ` [edk2-devel] [PATCH 4/4] MdeModulePkg/DxeIpl: Create 5-level page table for long mode Ni, Ray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d8ff62d-606e-ecee-ee72-6f7597388ebd@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox