public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gerd Hoffmann" <kraxel@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: devel@edk2.groups.io, Oliver Steffen <osteffen@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: Re: [edk2-devel] [PATCH 2/3] OvmfPkg/ResetVector: add 5-level paging support
Date: Tue, 30 Jan 2024 10:14:19 +0100	[thread overview]
Message-ID: <ji3rualrzcbkab2kcyeq2wr4hffqbr247lqbutntbj5fmced5p@u22kfos5x66p> (raw)
In-Reply-To: <3416850d-8977-5966-97a0-986e1e623e93@redhat.com>

  Hi,

> > +    ;
> > +    ; use 5-level paging with gigabyte pages
> > +    ;

> > +    ; 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
> 
> (2) So this is my problem. I've found this hard to decipher. The
> original (4-level) counterpart is much better commented.
> 
> So you either consulted the documentation to invent this (but then
> didn't write up your thought process), or you just "winged it" (which
> may still be fine, but you need to explain the setup even more).
> 
> As far as I can tell, we're covering the first 4GB of address space with
> 4 pages of 1GB size each, and because of that, we need not go deeper
> than level 3.

Correct.

> That one sentence in a comment (which would have cost you 5 seconds)

Well, there is a comment saying it's 5-level paging with gigabyte pages
(quoted above).  I'll add more details.

> (3) While the macro PAGE_2M_PDE_ATTR might expand to just the right
> constant here, the "2M" in the name is extremely confusing. Please
> introduce a new macro for selecting 1GB pages.

I think rename "2M" to "LARGEPAGE" would be better here.  The page
directory bit essentially says "stop page table walk here, there are no
page tables/page directories below this".  When set in a 4-level page
directory you'll get a 2M page, when set in a 3-level page directory
you'll get a 1G page.

> > +    ; done
> > +    jmp     SetCr3
> 
> (4) Functionality question: is the 5-level branch compatible with SEV
> and/or TDX? Asking because:
> 
> - EDX is still from GetSevCBitMaskAbove31. I don't know what happens if
> SEV is enabled and such an EDX is used at level 5.

Not fully sure.  The 4-level paging code applies edx on all levels, so I
did the same for 5-level paging.

Tom?

> - jumping to the SetCr3 label from here omits the
> "SevClearPageEncMaskForGhcbPage" and "TdxPostBuildPageTables" pieces of
> logic.

Good catch.  That is a bug.

take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114767): https://edk2.groups.io/g/devel/message/114767
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]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-01-30  9:14 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 ` [edk2-devel] [PATCH 2/3] OvmfPkg/ResetVector: add 5-level paging support Gerd Hoffmann
2024-01-29 21:04   ` Laszlo Ersek
2024-01-30  9:14     ` Gerd Hoffmann [this message]
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=ji3rualrzcbkab2kcyeq2wr4hffqbr247lqbutntbj5fmced5p@u22kfos5x66p \
    --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