From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.827.1660094701706544740 for ; Tue, 09 Aug 2022 18:25:02 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=S/gxmpHY; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660094701; x=1691630701; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=lSdkI7O+IdwV6wI778FlHyIPBqxMBSg5T6KatKA1Apg=; b=S/gxmpHY3YYd0ymajLJch5KRfcjgTR7L7u9aJzXrY+GhLj5tgaKQ4pWs cmDJy4yKufcD1scTdVXPxJMdrcZzO5X4YX4cTjtdpcHOOUJBaM3R30Civ uOWeko/ScGdBgdTRRHe5s8ks4+RQX7yam3kCEy/owmOIB22G5pFsp2rce X0x6oDjkRP3Vm2ZL3UKBRyvQ1COFBvJ4MvHliV94/66+rcWRUUQmUNcxv sCbWIGuWDXJK7uZn6OaRLeVv8ev6ufuuKWlp5Ys1aGHvByHF7SstNj3qx EoDGHDzIbWPlbhMHS8hfc9ZEFc6CgfJn7lJQbNwao5JWto/iszJ8SlYn5 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10434"; a="271356121" X-IronPort-AV: E=Sophos;i="5.93,225,1654585200"; d="scan'208";a="271356121" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 18:25:01 -0700 X-IronPort-AV: E=Sophos;i="5.93,225,1654585200"; d="scan'208";a="664673427" Received: from duntan-mobl.ccr.corp.intel.com ([10.239.157.47]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 18:25:00 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Dandan Bi , Liming Gao , Ray Ni Subject: [PATCH] MdeModulePkg/DxeIpl: Remove clearing CR0.WP when protecting pagetable Date: Wed, 10 Aug 2022 09:24:47 +0800 Message-Id: <20220810012447.1425-1-dun.tan@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Remove clearing CR0.WP when marking the memory used for page table to be read-only in the page table itself created by DxeIpl or UefiPayloadEntry/UniversalPayloadEntry. This page table address is written to Cr3 after these protection steps. Till this, the page table is always RW. Change-Id: Ibd65fb68ddfa3ea2931004d2d27b6023f457ab46 Signed-off-by: Dun Tan Cc: Dandan Bi Cc: Liming Gao Cc: Ray Ni --- MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 7 +------ UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index a451ca1604..18b121d768 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -626,12 +626,7 @@ EnablePageTableProtection ( } // - // Disable write protection, because we need to mark page table to be write - // protected. - // - AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP); - - // + // No need to clear CR0.WP since PageTableBase has't been written to CR3 yet. // SetPageTablePoolReadOnly might update mPageTablePool. It's safer to // remember original one in advance. // diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c index 74b667a62a..a586941352 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -622,12 +622,7 @@ EnablePageTableProtection ( } // - // Disable write protection, because we need to mark page table to be write - // protected. - // - AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP); - - // + // No need to clear CR0.WP since PageTableBase has't been written to CR3 yet. // SetPageTablePoolReadOnly might update mPageTablePool. It's safer to // remember original one in advance. // -- 2.31.1.windows.1