From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: ray.ni@intel.com) Received: from mga09.intel.com (mga09.intel.com []) by groups.io with SMTP; Fri, 26 Jul 2019 20:29:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2019 20:29:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,313,1559545200"; d="scan'208";a="194505174" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.16]) by fmsmga004.fm.intel.com with ESMTP; 26 Jul 2019 20:29:30 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Vanguput Narendra K Subject: [PATCH 2/3] UefiCpuPkg/PiSmmCpu: Refine CR2 save/restore logic Date: Sat, 27 Jul 2019 11:28:49 +0800 Message-Id: <20190727032850.337840-3-ray.ni@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190727032850.337840-1-ray.ni@intel.com> References: <20190727032850.337840-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Eric Dong Cc: Laszlo Ersek Cc: Vanguput Narendra K --- 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