From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.28351.1655454513435386166 for ; Fri, 17 Jun 2022 01:28:34 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=U1ZGnQe0; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: zhiguang.liu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655454513; x=1686990513; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iheVwXkUyHTqO3ShmDutJ3wk1qmqF6qFFYeFibn8Wwg=; b=U1ZGnQe0GU9Ek+t1Adqe21stAScdOSHoDJohKsY/rzAM7pD6gzc0i8OK p83+Nzb5FYYqSkSKPTKIUiAUx+zGB62H7zyBHYr4ut4/xCQHhkDL8c96Y zeqICy/sICM9cHoHxtuu+ImE7puy0DFDmiAmcS0I4mPW/E65C/g5wlHdJ MwOUSafiVmR+kLQ8UQzp1DzGhi3PvvqUgRIkXkniN8ZW4pBQ1rzJwKbms HPTDChG1FWtY55v5Igu8AytvOdyzqF8PC7FCmoYsPbtO0mNvjOnVLtDLN Su1359EHnFXIEbEgKYJFIel2YyJw4QD7HT0bs0JFNiyGnWuBkUzc4NiTm A==; X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="304904696" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="304904696" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 01:28:17 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="831949429" Received: from liuzhigu-mobl.ccr.corp.intel.com ([10.255.28.72]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 01:28:15 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Guo Dong , Ray Ni , Maurice Ma , Benjamin You , Sean Rhodes , Gerd Hoffmann Subject: [PATCH v2] UefiPayloadPkg: Always split page table entry to 4K if it covers stack. Date: Fri, 17 Jun 2022 16:28:03 +0800 Message-Id: <20220617082803.4428-1-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit We observed page fault in the following situation: 1.PayloadEntry uses 2M entry in page table to cover DXE stack range. 2.In DXE phase, image protection code needs to mark some sub-range in this 2M entry as readonly. So the the 2M page table entry is split to 512 4K entries, and some of the entries are marked as readonly. (the entries covering stack still remain R/W) 3.Page fault exception happens when trying to access stack. Always split the page table entry to 4K if it covers stack to avoid this issue. More discussion about this issue can be seen at below link https://edk2.groups.io/g/devel/topic/91446026 Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Cc: Sean Rhodes Cc: Gerd Hoffmann Signed-off-by: Zhiguang Liu --- UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c index ac0d58e685..74b667a62a 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/VirtualMemory.c @@ -218,16 +218,8 @@ ToSplitPageTable ( return TRUE; } - if (PcdGetBool (PcdCpuStackGuard)) { - if ((StackBase >= Address) && (StackBase < (Address + Size))) { - return TRUE; - } - } - - if (PcdGetBool (PcdSetNxForStack)) { - if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase)) { - return TRUE; - } + if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase)) { + return TRUE; } if (GhcbBase != 0) { -- 2.16.2.windows.1