From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: Laszlo Ersek <lersek@redhat.com>,
Oliver Steffen <osteffen@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Michael Roth <michael.roth@amd.com>, Min Xu <min.m.xu@intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Erdem Aktas <erdemaktas@google.com>,
Jiewen Yao <jiewen.yao@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>
Subject: [edk2-devel] [PATCH 2/3] OvmfPkg/ResetVector: add 5-level paging support
Date: Mon, 29 Jan 2024 13:02:00 +0100 [thread overview]
Message-ID: <20240129120201.344234-3-kraxel@redhat.com> (raw)
In-Reply-To: <20240129120201.344234-1-kraxel@redhat.com>
Compile the OVMF ResetVector with 5-level paging support in case
PcdUse5LevelPageTable is TRUE.
When enabled the ResetVector will check at runtime whenever support for
5-level paging and gigabyte pages is available. In case both features
are supported it will run OVMF in 5-level paging mode, otherwise
fallback to 4-level paging.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/ResetVector/ResetVector.inf | 1 +
OvmfPkg/ResetVector/Ia32/PageTables64.asm | 72 +++++++++++++++++++++++
OvmfPkg/ResetVector/ResetVector.nasmb | 1 +
3 files changed, 74 insertions(+)
diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/ResetVector.inf
index a4154ca90c28..65f71b05a02e 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -64,3 +64,4 @@ [FixedPcd]
gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 317cad430f29..0f88d1c71798 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -81,6 +81,78 @@ clearPageTablesMemoryLoop:
mov dword[ecx * 4 + PT_ADDR (0) - 4], eax
loop clearPageTablesMemoryLoop
+%if PG_5_LEVEL
+
+ ; save edx (cpuid changes it)
+ mov edi, edx
+
+ ; check for cpuid leaf 0x07
+ mov eax, 0x00
+ cpuid
+ cmp eax, 0x07
+ jb Paging4Lvl
+
+ ; check for la57 (aka 5-level paging)
+ mov eax, 0x07
+ mov ecx, 0x00
+ cpuid
+ bt ecx, 16
+ jnc Paging4Lvl
+
+ ; check for cpuid leaf 0x80000001
+ mov eax, 0x80000000
+ cpuid
+ cmp eax, 0x80000001
+ jb Paging4Lvl
+
+ ; check for 1g pages
+ mov eax, 0x80000001
+ cpuid
+ bt edx, 26
+ jnc Paging4Lvl
+
+ ;
+ ; use 5-level paging with gigabyte pages
+ ;
+ debugShowPostCode 0x51 ; 5-level paging
+
+ ; restore edx
+ mov edx, edi
+
+ ; level 5
+ mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR
+ mov dword[PT_ADDR (4)], edx
+
+ ; level 4
+ mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDP_ATTR
+ mov dword[PT_ADDR (0x1004)], edx
+
+ ; level 3
+ mov dword[PT_ADDR (0x2000)], (0 << 30) + PAGE_2M_PDE_ATTR
+ mov dword[PT_ADDR (0x2004)], edx
+ mov dword[PT_ADDR (0x2008)], (1 << 30) + PAGE_2M_PDE_ATTR
+ mov dword[PT_ADDR (0x200c)], edx
+ mov dword[PT_ADDR (0x2010)], (2 << 30) + PAGE_2M_PDE_ATTR
+ mov dword[PT_ADDR (0x2014)], edx
+ mov dword[PT_ADDR (0x2018)], (3 << 30) + PAGE_2M_PDE_ATTR
+ mov dword[PT_ADDR (0x201c)], edx
+
+ ; set la57 bit in cr4
+ mov eax, cr4
+ bts eax, 12
+ mov cr4, eax
+
+ ; done
+ jmp SetCr3
+
+Paging4Lvl:
+ debugShowPostCode 0x41 ; 4-level paging
+
+ ; restore edx
+ mov edx, edi
+
+%endif
+
;
; Top level Page Directory Pointers (1 * 512GB entry)
;
diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/ResetVector.nasmb
index 5832aaa8abf7..16b3eee57671 100644
--- a/OvmfPkg/ResetVector/ResetVector.nasmb
+++ b/OvmfPkg/ResetVector/ResetVector.nasmb
@@ -49,6 +49,7 @@
%define WORK_AREA_GUEST_TYPE (FixedPcdGet32 (PcdOvmfWorkAreaBase))
%define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Offset))
+%define PG_5_LEVEL (FixedPcdGetBool (PcdUse5LevelPageTable))
%define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase))
%define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase))
--
2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114689): https://edk2.groups.io/g/devel/message/114689
Mute This Topic: https://groups.io/mt/104029639/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-01-29 12:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 12:01 [edk2-devel] [PATCH 0/3] OvmfPkg: Add support for 5-level paging Gerd Hoffmann
2024-01-29 12:01 ` [edk2-devel] [PATCH 1/3] MdeModulePkg: fix PcdUse5LevelPageTable assert Gerd Hoffmann
2024-01-29 20:15 ` Laszlo Ersek
2024-01-29 12:02 ` Gerd Hoffmann [this message]
2024-01-29 21:04 ` [edk2-devel] [PATCH 2/3] OvmfPkg/ResetVector: add 5-level paging support Laszlo Ersek
2024-01-30 9:14 ` Gerd Hoffmann
2024-01-30 16:48 ` Laszlo Ersek
2024-01-29 12:02 ` [edk2-devel] [PATCH 3/3] OvmfPkg/PlatformInitLib: " Gerd Hoffmann
2024-01-29 21:12 ` Laszlo Ersek
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=20240129120201.344234-3-kraxel@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