public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zhiguang Liu" <zhiguang.liu@intel.com>
To: devel@edk2.groups.io
Cc: Zhiguang Liu <zhiguang.liu@intel.com>,
	Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Debkumar De <debkumar.de@intel.com>,
	Catharine West <catharine.west@intel.com>
Subject: [PATCH v6 5/5] UefiCpuPkg/ResetVector: Support 5 level page table in ResetVector
Date: Mon, 15 May 2023 09:41:38 +0800	[thread overview]
Message-ID: <20230515014138.1321-6-zhiguang.liu@intel.com> (raw)
In-Reply-To: <20230515014138.1321-1-zhiguang.liu@intel.com>

Add a macro USE_5_LEVEL_PAGE_TABLE to determine whether to create
5 level page table.
If macro USE_5_LEVEL_PAGE_TABLE is defined, PML5Table is created
at (4G-12K), while PML4Table is at (4G-16K). In runtime check, if
5level paging is supported, use PML5Table, otherwise, use PML4Table.
If macro USE_5_LEVEL_PAGE_TABLE is not defined, to save space, 5level
paging is not created, and 4level paging is at (4G-12K) and be used.

V6:
In previous version, I merge code from Ia32\PageTables64.asm into
Ia32\Flat32ToFlat64.asm to reduce files. However, reset vector from
OvmfPkg\Bhyve\ResetVector needs the code from Flat32ToFlat64.asm, and
needs its OneTimeCall SetCr3ForPageTables64. To be compatible,
in this version, I keep the file PageTables64.asm, and implement
5level paging logic there.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Debkumar De <debkumar.de@intel.com>
Cc: Catharine West <catharine.west@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 .../ResetVector/Vtf0/Ia32/PageTables64.asm    | 20 +++++++++++++++++++
 .../ResetVector/Vtf0/X64/PageTables.asm       |  9 +++++++++
 2 files changed, 29 insertions(+)

diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm b/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
index f188da20ba..165cebcfaa 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
@@ -17,8 +17,28 @@ SetCr3ForPageTables64:
     ;
     ; These pages are built into the ROM image in X64/PageTables.asm
     ;
+%ifdef USE_5_LEVEL_PAGE_TABLE
+    mov     eax, 0
+    cpuid
+    cmp     eax, 07h                    ; check if basic CPUID leaf contains leaf 07
+    jb      NotSupport5LevelPaging      ; 5level paging not support, downgrade to 4level paging
+    mov     eax, 07h                    ; check cpuid leaf 7, subleaf 0
+    mov     ecx, 0
+    cpuid
+    bt      ecx, 16                     ; [Bits 16] Supports 5-level paging if 1.
+    jnc     NotSupport5LevelPaging      ; 5level paging not support, downgrade to 4level paging
+    mov     eax, ADDR_OF(Pml5)
+    mov     cr3, eax
+    mov     eax, cr4
+    bts     eax, 12                     ; Set LA57=1.
+    mov     cr4, eax
+    jmp     SetCr3Done
+NotSupport5LevelPaging:
+%endif
+
     mov     eax, ADDR_OF(Pml4)
     mov     cr3, eax
+SetCr3Done:
 
     OneTimeCallRet SetCr3ForPageTables64
 
diff --git a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm
index d66fb62c34..7960b141be 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm
@@ -81,4 +81,13 @@ Pml4:
     ;
     DQ      PAGE_NLE(Pdp)
     TIMES   0x1000 - ($ - Pml4) DB 0
+
+%ifdef USE_5_LEVEL_PAGE_TABLE
+Pml5:
+    ;
+    ; Pml5 table (only first entry is present, pointing to Pml4)
+    ;
+    DQ      PAGE_NLE(Pml4)
+    TIMES   0x1000 - ($ - Pml5) DB 0
+%endif
 EndOfPageTables:
-- 
2.31.1.windows.1


  parent reply	other threads:[~2023-05-15  1:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15  1:41 [PATCH v6 0/5] UefiCpuPkg/ResetVector: Refine page table creation, and support 5 Level paging Zhiguang Liu
2023-05-15  1:41 ` [PATCH v6 1/5] UefiCpuPkg/ResetVector: Rename macros about page table Zhiguang Liu
2023-05-15  1:41 ` [PATCH v6 2/5] UefiCpuPkg/ResetVector: Simplify page table creation in ResetVector Zhiguang Liu
2023-05-15  1:41 ` [PATCH v6 3/5] UefiCpuPkg/ResetVector: Combine PageTables1G.asm and PageTables2M.asm Zhiguang Liu
2023-05-15  1:41 ` [PATCH v6 4/5] UefiCpuPkg/ResetVector: Modify Page Table in ResetVector Zhiguang Liu
2023-05-15  1:41 ` Zhiguang Liu [this message]
2023-05-16  8:06 ` [edk2-devel] [PATCH v6 0/5] UefiCpuPkg/ResetVector: Refine page table creation, and support 5 Level paging 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=20230515014138.1321-6-zhiguang.liu@intel.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