public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: 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 3/3] OvmfPkg/PlatformInitLib: add 5-level paging support
Date: Mon, 29 Jan 2024 22:12:58 +0100	[thread overview]
Message-ID: <290291cc-fc01-fd5d-f12d-eced42e378ca@redhat.com> (raw)
In-Reply-To: <20240129120201.344234-4-kraxel@redhat.com>

On 1/29/24 13:02, Gerd Hoffmann wrote:
> Adjust physical address space logic for la57 mode (5-level paging).
> With a larger logical address space we can identity-map a larger
> physical address space.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  OvmfPkg/Library/PlatformInitLib/MemDetect.c | 57 ++++++++++++++-------
>  1 file changed, 38 insertions(+), 19 deletions(-)
> 
> diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> index f042517bb64a..b882d9b82fa8 100644
> --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
> @@ -628,11 +628,12 @@ PlatformAddressWidthFromCpuid (
>    IN     BOOLEAN                QemuQuirk
>    )
>  {
> -  UINT32   RegEax, RegEbx, RegEcx, RegEdx, Max;
> -  UINT8    PhysBits;
> -  CHAR8    Signature[13];
> -  BOOLEAN  Valid         = FALSE;
> -  BOOLEAN  Page1GSupport = FALSE;
> +  UINT32    RegEax, RegEbx, RegEcx, RegEdx, Max;
> +  UINT8     PhysBits;
> +  CHAR8     Signature[13];
> +  IA32_CR4  Cr4;
> +  BOOLEAN   Valid         = FALSE;
> +  BOOLEAN   Page1GSupport = FALSE;

Initialization of locals breaks the edk2 coding conventions.

... Well, I now realize this is preexistent code, only shown as
"different" due to visual realignment. Ignore.

>  
>    ZeroMem (Signature, sizeof (Signature));
>  
> @@ -670,30 +671,48 @@ PlatformAddressWidthFromCpuid (
>      }
>    }
>  
> +  Cr4.UintN = AsmReadCr4 ();
> +
>    DEBUG ((
>      DEBUG_INFO,
> -    "%a: Signature: '%a', PhysBits: %d, QemuQuirk: %a, Valid: %a\n",
> +    "%a: Signature: '%a', PhysBits: %d, QemuQuirk: %a, la57: %a, Valid: %a\n",
>      __func__,
>      Signature,
>      PhysBits,
>      QemuQuirk ? "On" : "Off",
> +    Cr4.Bits.LA57 ? "On" : "Off",
>      Valid ? "Yes" : "No"
>      ));
>  
>    if (Valid) {
> -    if (PhysBits > 46) {
> -      /*
> -       * Avoid 5-level paging altogether for now, which limits
> -       * PhysBits to 48.  Also avoid using address bit 48, due to sign
> -       * extension we can't identity-map these addresses (and lots of
> -       * places in edk2 assume we have everything identity-mapped).
> -       * So the actual limit is 47.
> -       *
> -       * Also some older linux kernels apparently have problems handling
> -       * phys-bits > 46 correctly, so use that as limit.
> -       */
> -      DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 46 (avoid 5-level paging)\n", __func__));
> -      PhysBits = 46;
> +    /*
> +     * Due to the sign extension we can use only the lower half of the
> +     * virtual address space to identity-map physical address space,
> +     * which gives us a 47 bit wide address space with 4 paging levels
> +     * and a 56 bit wide address space with 5 paging levels.
> +     */
> +    if (Cr4.Bits.LA57) {
> +      if (PhysBits > 48) {
> +        /*
> +         * Some Intel CPUs support 5-level paging, have more than 48
> +         * phys-bits but support only 4-level EPT, which effectively
> +         * limits guest phys-bits to 48.  Until we have some way to
> +         * communicate that limitation from hypervisor to guest limit

(1) Very nice comment, but please insert a comma "," between the words
"guest" and "limit".

> +         * phys-bits to 48 unconditionally.
> +         */
> +        DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 48 (5-level paging)\n", __func__));
> +        PhysBits = 48;
> +      }
> +    } else {
> +      if (PhysBits > 46) {
> +        /*
> +         * Some older linux kernels apparently have problems handling
> +         * phys-bits > 46 correctly, so use that instead of 47 as
> +         * limit.
> +         */
> +        DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 46 (4-level paging)\n", __func__));
> +        PhysBits = 46;
> +      }
>      }
>  
>      if (!Page1GSupport && (PhysBits > 40)) {

Reviewed-by: Laszlo Ersek <lersek@redhat.com>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114747): https://edk2.groups.io/g/devel/message/114747
Mute This Topic: https://groups.io/mt/104029638/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



      reply	other threads:[~2024-01-29 21:13 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
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 [this message]

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=290291cc-fc01-fd5d-f12d-eced42e378ca@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