public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jian J Wang <jian.j.wang@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	"Ware, Ryan R" <ryan.r.ware@intel.com>
Subject: [PATCH 1/4] MdeModulePkg/DxeIpl: disable paging before creating new page table
Date: Mon,  3 Sep 2018 11:15:47 +0800	[thread overview]
Message-ID: <20180903031550.4440-2-jian.j.wang@intel.com> (raw)
In-Reply-To: <20180903031550.4440-1-jian.j.wang@intel.com>

PEI Stack Guard needs to enable paging before DxeIpl. This might cause
#GP in the transition from 32-bit PEI to 64-bit DXE due to the code
trying to write CR3 register with PML4 page table while the processor
is enabled with PAE paging.

Simply disabling paging before updating CR3 can solve this conflict.
There's no such issue for 64-bit PEI so this change applies only to
32-bit code.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: "Ware, Ryan R" <ryan.r.ware@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
 MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
index 8a939b6c24..d28baa3615 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
@@ -325,6 +325,11 @@ HandOffToDxeCore (
     PERF_EVENT_SIGNAL_END (gEndOfPeiSignalPpi.Guid);
     ASSERT_EFI_ERROR (Status);
 
+    //
+    // Paging might be already enabled. To avoid conflict configuration,
+    // disable paging first anyway.
+    //
+    AsmWriteCr0 (AsmReadCr0 () & (~BIT31));
     AsmWriteCr3 (PageTables);
 
     //
@@ -445,6 +450,11 @@ HandOffToDxeCore (
     ASSERT_EFI_ERROR (Status);
 
     if (BuildPageTablesIa32Pae) {
+      //
+      // Paging might be already enabled. To avoid conflict configuration,
+      // disable paging first anyway.
+      //
+      AsmWriteCr0 (AsmReadCr0 () & (~BIT31));
       AsmWriteCr3 (PageTables);
       //
       // Set Physical Address Extension (bit 5 of CR4).
-- 
2.16.2.windows.1



  reply	other threads:[~2018-09-03  3:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03  3:15 [PATCH 0/4] Add PEI Stack Guard feature Jian J Wang
2018-09-03  3:15 ` Jian J Wang [this message]
2018-09-03  3:15 ` [PATCH 2/4] UefiCpuPkg/CpuExceptionHandlerLib: support stack switch for PEI exceptions Jian J Wang
2018-09-06  1:38   ` Dong, Eric
2018-09-03  3:15 ` [PATCH 3/4] UefiCpuPkg/MpInitLib: fix register restore issue in AP wakeup Jian J Wang
2018-09-05  5:29   ` Dong, Eric
2018-09-03  3:15 ` [PATCH 4/4] UefiCpuPkg/CpuMpPei: support stack guard feature Jian J Wang
2018-09-06  1:45   ` Dong, Eric
2018-09-06  2:42     ` Wang, Jian J
2018-09-03  4:14 ` [PATCH 0/4] Add PEI Stack Guard feature Yao, Jiewen
2018-09-03  4:56   ` Wang, Jian J
2018-09-03 14:52 ` 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=20180903031550.4440-2-jian.j.wang@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