public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ray" <ray.ni@intel.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Laszlo Ersek <lersek@redhat.com>,
	Vanguput Narendra K <narendra.k.vanguput@intel.com>
Subject: [PATCH 2/3] UefiCpuPkg/PiSmmCpu: Refine CR2 save/restore logic
Date: Sat, 27 Jul 2019 11:28:49 +0800	[thread overview]
Message-ID: <20190727032850.337840-3-ray.ni@intel.com> (raw)
In-Reply-To: <20190727032850.337840-1-ray.ni@intel.com>

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.
@@ -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);
-  }
-}
-- 
2.21.0.windows.1


  parent reply	other threads:[~2019-07-27  3:29 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 ` Ni, Ray [this message]
2019-07-29 11:33   ` [PATCH 2/3] UefiCpuPkg/PiSmmCpu: Refine CR2 save/restore logic Dong, Eric
2019-07-29 11:42   ` [edk2-devel] " Laszlo Ersek
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=20190727032850.337840-3-ray.ni@intel.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