public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, ray.ni@intel.com
Cc: Eric Dong <eric.dong@intel.com>,
	Vanguput Narendra K <narendra.k.vanguput@intel.com>
Subject: Re: [edk2-devel] [PATCH 2/3] UefiCpuPkg/PiSmmCpu: Refine CR2 save/restore logic
Date: Mon, 29 Jul 2019 13:42:06 +0200	[thread overview]
Message-ID: <37b7800b-589b-9ac8-5758-cf9deb5029bf@redhat.com> (raw)
In-Reply-To: <20190727032850.337840-3-ray.ni@intel.com>

On 07/27/19 05:28, Ni, Ray wrote:
> Because IsStaticPageTableEnabled() is added for both IA32 and x64
> build, the CR2 save/restore logic can be refined:
> 1. Remove arch specific SaveCr2() /  RestoreCr2() implementation;
> 2. Conditionally save and restore CR2 in SmiRendezvous().
> 
> Signed-off-by: Ray Ni <ray.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Vanguput Narendra K <narendra.k.vanguput@intel.com>
> ---
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c   | 25 -------------------
>  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c      |  8 ++++--
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 22 ----------------
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c    | 29 ----------------------
>  4 files changed, 6 insertions(+), 78 deletions(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
> index 2a9af4b77d..cae23d6d1d 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
> @@ -327,28 +327,3 @@ SetPageTableAttributes (
>    return ;
>  }
>  
> -/**
> -  This function returns with no action for 32 bit.
> -
> -  @param[out]  *Cr2  Pointer to variable to hold CR2 register value.
> -**/
> -VOID
> -SaveCr2 (
> -  OUT UINTN  *Cr2
> -  )
> -{
> -  return ;
> -}
> -
> -/**
> -  This function returns with no action for 32 bit.
> -
> -  @param[in]  Cr2  Value to write into CR2 register.
> -**/
> -VOID
> -RestoreCr2 (
> -  IN UINTN  Cr2
> -  )
> -{
> -  return ;
> -}
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> index ef16997547..5d0124b368 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> @@ -1575,7 +1575,9 @@ SmiRendezvous (
>    // when using on-demand paging for above 4G memory.
>    //
>    Cr2 = 0;
> -  SaveCr2 (&Cr2);
> +  if (!IsStaticPageTableEnabled ()) {
> +    Cr2 = AsmReadCr2 ();
> +  }
>  
>    //
>    // Call the user register Startup function first.

So, because this patch is supposed to only refactor / simplify the code,
it should not change behavior.

But, because in patch#1 we return FALSE for IA32, the condition above
will evaluate to TRUE. And so we will massage CR2 (= fault address),
even though the IA32 build shouldn't do that (and doesn't do it, at the
moment).

This should be fixed by returning constant TRUE from
IsStaticPageTableEnabled(), in patch#1, on IA32.

(Note: in the message of commit d47b85a621ad ("Revert
"UefiCpuPkg/PiSmmCpu: Allow SMM access-out when static paging is OFF"",
2019-07-26), I wrote that "The IA32 implementation should return a
constant value". I didn't say either "constant TRUE" or "constant
FALSE". And that's because I couldn't know the right value, without
actually looking at the code. Determining the correct IA32 value was out
of scope for the revert.)

More below:

> @@ -1725,7 +1727,9 @@ Exit:
>    //
>    // Restore Cr2
>    //
> -  RestoreCr2 (Cr2);
> +  if (!IsStaticPageTableEnabled ()) {
> +    AsmWriteCr2 (Cr2);
> +  }
>  }
>  
>  /**
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
> index 14b7676c16..5a97733def 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
> @@ -1282,28 +1282,6 @@ IsStaticPageTableEnabled (
>    )
>  ;
>  
> -/**
> -  This function reads CR2 register when on-demand paging is enabled
> -  for 64 bit and no action for 32 bit.
> -
> -  @param[out]  *Cr2  Pointer to variable to hold CR2 register value.
> -**/
> -VOID
> -SaveCr2 (
> -  OUT UINTN  *Cr2
> -  );
> -
> -/**
> -  This function writes into CR2 register when on-demand paging is enabled
> -  for 64 bit and no action for 32 bit.
> -
> -  @param[in]  Cr2  Value to write into CR2 register.
> -**/
> -VOID
> -RestoreCr2 (
> -  IN UINTN  Cr2
> -  );
> -
>  /**
>    Schedule a procedure to run on the specified CPU.
>  
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> index 18e3f9e08d..8259b01a95 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
> @@ -1209,32 +1209,3 @@ SetPageTableAttributes (
>    return ;
>  }
>  
> -/**
> -  This function reads CR2 register when on-demand paging is enabled.
> -
> -  @param[out]  *Cr2  Pointer to variable to hold CR2 register value.
> -**/
> -VOID
> -SaveCr2 (
> -  OUT UINTN  *Cr2
> -  )
> -{
> -  if (!mCpuSmmStaticPageTable) {
> -    *Cr2 = AsmReadCr2 ();
> -  }
> -}
> -
> -/**
> -  This function restores CR2 register when on-demand paging is enabled.
> -
> -  @param[in]  Cr2  Value to write into CR2 register.
> -**/
> -VOID
> -RestoreCr2 (
> -  IN UINTN  Cr2
> -  )
> -{
> -  if (!mCpuSmmStaticPageTable) {
> -    AsmWriteCr2 (Cr2);
> -  }
> -}
> 

For this patch:

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

Thanks
Laszlo

  parent reply	other threads:[~2019-07-29 11:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27  3:28 [PATCH 0/3] Allow SMM access-out when static paging is OFF Ni, Ray
2019-07-27  3:28 ` [PATCH 1/3] UefiCpuPkg/PiSmmCpu: Add Internal function IsStaticPageTableEnabled Ni, Ray
2019-07-29 11:33   ` [edk2-devel] " Dong, Eric
2019-07-29 11:33   ` Laszlo Ersek
2019-07-30 15:20     ` Ni, Ray
2019-07-31  9:57       ` Laszlo Ersek
2019-07-31 16:40         ` Ni, Ray
2019-07-27  3:28 ` [PATCH 2/3] UefiCpuPkg/PiSmmCpu: Refine CR2 save/restore logic Ni, Ray
2019-07-29 11:33   ` Dong, Eric
2019-07-29 11:42   ` Laszlo Ersek [this message]
2019-07-27  3:28 ` [PATCH 3/3] UefiCpuPkg/PiSmmCpu: Allow SMM access-out when static paging is OFF Ni, Ray
2019-07-29 11:33   ` Dong, Eric
2019-07-29 11:49   ` [edk2-devel] " 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=37b7800b-589b-9ac8-5758-cf9deb5029bf@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