From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: More than 10 MX records returned) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 183AE2216D8CF for ; Thu, 14 Dec 2017 18:34:15 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Dec 2017 18:38:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,402,1508828400"; d="scan'208";a="1792609" Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.42]) by fmsmga002.fm.intel.com with ESMTP; 14 Dec 2017 18:38:55 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Ruiyu Ni , Star Zeng , Eric Dong Date: Fri, 15 Dec 2017 10:38:38 +0800 Message-Id: <20171215023838.9400-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 Subject: [PATCH] MdeModulePkg/DxeIplPeim: fix incorrect page table split during protecting X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2017 02:34:15 -0000 The root cause of this issue is that, during splitting page table, the page size should be the value of next level (smaller one) instead of current level. The wrong page size will then cause wrong page table introduced, which will break the normal boot. Validation works include booting to Windows 10 and Fedora 26 on real Intel platform and OVMF emulated platform in addition to manual checks on page table with JTAG tool. Cc: Ruiyu Ni Cc: Star Zeng Cc: Eric Dong Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index 26116e420c..bbdfa2bb8e 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -472,6 +472,8 @@ SetPageTablePoolReadOnly ( // // The smaller granularity of page must be needed. // + ASSERT (Level > 1); + NewPageTable = AllocatePageTableMemory (1); ASSERT (NewPageTable != NULL); @@ -481,10 +483,10 @@ SetPageTablePoolReadOnly ( ++EntryIndex) { NewPageTable[EntryIndex] = PhysicalAddress | AddressEncMask | IA32_PG_P | IA32_PG_RW; - if (Level > 1) { + if (Level > 2) { NewPageTable[EntryIndex] |= IA32_PG_PS; } - PhysicalAddress += LevelSize[Level]; + PhysicalAddress += LevelSize[Level - 1]; } PageTable[Index] = (UINT64)(UINTN)NewPageTable | AddressEncMask | -- 2.14.1.windows.1