public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: Kun Qin <kuqin12@gmail.com>, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>
Subject: Re: [PATCH v2 1/1] UefiCpuPkg: PiSmmCpuDxeSmm: Not to Change Bitwidth During Static Paging
Date: Thu, 15 Apr 2021 12:41:18 +0200	[thread overview]
Message-ID: <9a412dd6-e026-8741-35d7-7943eab7be63@redhat.com> (raw)
In-Reply-To: <20210414202547.394-2-kuqin12@gmail.com>

On 04/14/21 22:25, Kun Qin wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3300
> 
> Current implementation of SetStaticPageTable routine in PiSmmCpuDxeSmm
> driver will check a global variable mPhysicalAddressBits, and eventually
> cap any value larger than 39 at 39.
> 
> This global variable is used in ConvertMemoryPageAttributes, which backs
> SmmSetMemoryAttributes and SmmClearMemoryAttributes. Thus for a processor
> that supports more than 39 bits width, trying to mark page table regions
> higher than 39-bit will always return EFI_UNSUPPROTED.
> 
> This change updated the interface of SetStaticPageTable function to take
> PhysicalAddressBits as an input parameter, in order to avoid changing/
> accessing the global variable.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> 
> Fixes: 4eee0cc7cc0db74489b99c19eba056b53eda6358
> Signed-off-by: Kun Qin <kuqin12@gmail.com>
> ---
> 
> Notes:
>     v2:
>     - SetStaticPageTable interface update [Ray]
>     - Commit message updates, variable type change [Laszlo]
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 30 +++++++++++---------
>  1 file changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> index 6902584b1fbd..d6f8dd94d303 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> @@ -211,11 +211,13 @@ CalculateMaximumSupportAddress (
>  /**
>    Set static page table.
>  
> -  @param[in] PageTable     Address of page table.
> +  @param[in] PageTable              Address of page table.
> +  @param[in] PhysicalAddressBits    The maximum physical address bits supported.
>  **/
>  VOID
>  SetStaticPageTable (
> -  IN UINTN               PageTable
> +  IN UINTN               PageTable,
> +  IN UINT8               PhysicalAddressBits
>    )
>  {
>    UINT64                                        PageAddress;
> @@ -237,26 +239,26 @@ SetStaticPageTable (
>    // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses
>    //  when 5-Level Paging is disabled.
>    //
> -  ASSERT (mPhysicalAddressBits <= 52);
> -  if (!m5LevelPagingNeeded && mPhysicalAddressBits > 48) {
> -    mPhysicalAddressBits = 48;
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (!m5LevelPagingNeeded && PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
>    }
>  
>    NumberOfPml5EntriesNeeded = 1;
> -  if (mPhysicalAddressBits > 48) {
> -    NumberOfPml5EntriesNeeded = (UINTN) LShiftU64 (1, mPhysicalAddressBits - 48);
> -    mPhysicalAddressBits = 48;
> +  if (PhysicalAddressBits > 48) {
> +    NumberOfPml5EntriesNeeded = (UINTN) LShiftU64 (1, PhysicalAddressBits - 48);
> +    PhysicalAddressBits = 48;
>    }
>  
>    NumberOfPml4EntriesNeeded = 1;
> -  if (mPhysicalAddressBits > 39) {
> -    NumberOfPml4EntriesNeeded = (UINTN) LShiftU64 (1, mPhysicalAddressBits - 39);
> -    mPhysicalAddressBits = 39;
> +  if (PhysicalAddressBits > 39) {
> +    NumberOfPml4EntriesNeeded = (UINTN) LShiftU64 (1, PhysicalAddressBits - 39);
> +    PhysicalAddressBits = 39;
>    }
>  
>    NumberOfPdpEntriesNeeded = 1;
> -  ASSERT (mPhysicalAddressBits > 30);
> -  NumberOfPdpEntriesNeeded = (UINTN) LShiftU64 (1, mPhysicalAddressBits - 30);
> +  ASSERT (PhysicalAddressBits > 30);
> +  NumberOfPdpEntriesNeeded = (UINTN) LShiftU64 (1, PhysicalAddressBits - 30);
>  
>    //
>    // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.
> @@ -438,7 +440,7 @@ SmmInitPageTable (
>      // When access to non-SMRAM memory is restricted, create page table
>      // that covers all memory space.
>      //
> -    SetStaticPageTable ((UINTN)PTEntry);
> +    SetStaticPageTable ((UINTN)PTEntry, mPhysicalAddressBits);
>    } else {
>      //
>      // Add pages to page pool
> 

Last time I checked the variable renames carefully, now I'm trusting
that those have not been broken/modified since v1.

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


  reply	other threads:[~2021-04-15 10:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14 20:25 [PATCH v2 0/1] Not to Update Bitwidth Variable in Static Paging Kun Qin
2021-04-14 20:25 ` [PATCH v2 1/1] UefiCpuPkg: PiSmmCpuDxeSmm: Not to Change Bitwidth During " Kun Qin
2021-04-15 10:41   ` Laszlo Ersek [this message]
2021-04-16  5:17     ` Kun Qin
2021-04-19 22:28   ` [edk2-devel] " Ni, Ray
2021-04-20 20:12     ` Kun Qin
     [not found] ` <1675D34B1BADE93C.32393@groups.io>
2021-04-19 17:24   ` Kun Qin

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=9a412dd6-e026-8741-35d7-7943eab7be63@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