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>,
	 Jiewen Yao <jiewen.yao@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>
Subject: Re: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap
Date: Wed, 31 Jan 2024 15:55:26 +0100	[thread overview]
Message-ID: <xhvhdo5czxfiulfxkjog25vvwhpk3lolnml3qhw6sdzpamtf7i@qqkahqirqach> (raw)
In-Reply-To: <65a072d8-9f2c-3487-dc26-9a72e9eccc3d@redhat.com>

  Hi,

> > +  if (MemoryCap > MAX_UINT32) {
> > +    MemoryCap = MAX_UINT32;
> > +  }
> > +
> 
> (2) This doesn't look good, for two reasons.
> 
> First, if UINTN is UINT32, then we're too late to check. (If it's intentional that the code be dead on IA32, then that should be documented.)

IA32 has an early exit in this function.

Looking again I see this applies to 32-bit DXE only, so with mixed
32-bit PEI / 64-bit DXE we can still land here.  Hmm, so yes, you
have a point here.

In practice we don't come even close to MAX_UINT32.  With 4096 vcpus the
amount of memory needed for the AP stacks sums up to 128 MB.  The page
table memory wouldn't grow that big too because OVMF will use at most
1 TB of address space if gigabyte pages are not available (to limit page
table memory and boot time needed to set them all up).

> Second, while returning MAX_UINT32 from this function is safe, it's also obscure. After the call site, we've got
> 
>     MemoryBase = PlatformInfoHob->S3Supported && PlatformInfoHob->SmmSmramRequire ?
>                  PcdGet32 (PcdOvmfDecompressionScratchEnd) :
>                  PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);
>     MemorySize = LowerMemorySize - MemoryBase;
>     if (MemorySize > PeiMemoryCap) {
>       MemoryBase = LowerMemorySize - PeiMemoryCap;
>       MemorySize = PeiMemoryCap;
>     }

MemorySize is UINT64.  So I guess the easiest would be to just switch
MemoryCap variable and GetPeiMemoryCap() return value to UINT64 too.
Avoids all the thinking and arguing whenever UINT32 is safe or not.

And maybe add an else branch to log a warning in case
MemorySize < PeiMemoryCap.

take care,
  Gerd



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



  reply	other threads:[~2024-01-31 14:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 11:59 [edk2-devel] [PATCH 0/3] OvmfPkg/PlatformPei: scaleability fixes for GetPeiMemoryCap() Gerd Hoffmann
2024-01-31 11:59 ` [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformPei: consider AP stacks for pei memory cap Gerd Hoffmann
2024-01-31 14:08   ` Laszlo Ersek
2024-01-31 14:55     ` Gerd Hoffmann [this message]
2024-01-31 19:29       ` Laszlo Ersek
2024-01-31 11:59 ` [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformPei: rewrite page table calculation Gerd Hoffmann
2024-01-31 15:13   ` Laszlo Ersek
2024-01-31 15:21     ` Laszlo Ersek
2024-01-31 16:28     ` Gerd Hoffmann
2024-02-01 21:04       ` Laszlo Ersek
2024-01-31 12:00 ` [edk2-devel] [PATCH 3/3] OvmfPkg/PlatformPei: log pei memory cap details Gerd Hoffmann
2024-01-31 15:38   ` 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=xhvhdo5czxfiulfxkjog25vvwhpk3lolnml3qhw6sdzpamtf7i@qqkahqirqach \
    --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