From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id CC4367803D0 for ; Wed, 10 Jan 2024 08:06:01 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ZosoGKPCAELnK21Z5YhYPNRY18WamQ24Q4JeJf/j2JA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704873960; v=1; b=C2RbBc1+jWMC8nFZ8/l4tUFgZEYxUtN8R/YBO3T/8PZw5yD5yC85lBrq6ECHMAuurBttUqRu XGyuPWgt0dz0waK61XoY7wzAVDdKy0NdAkwIrV8aG8vBggoghpTeZCOHvmWY+/08qCCfeHXcULB Lmn7gFJDyd0cdL9geq6rbc4I= X-Received: by 127.0.0.2 with SMTP id JcwjYY7687511xspNALsHYxr; Wed, 10 Jan 2024 00:06:00 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.7423.1704873959402925132 for ; Wed, 10 Jan 2024 00:05:59 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="484624059" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="484624059" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 00:05:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10947"; a="731777835" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="731777835" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 00:05:56 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH] UefiCpuPkg:Limit PhysicalAddressBits in speicial case Date: Wed, 10 Jan 2024 16:05:44 +0800 Message-Id: <20240110080544.1350-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: WdYVrpOIrv7cnrUP9YN3s7c9x7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=C2RbBc1+; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io When creating smm page table, limit maximum supported physical address bits returned by CalculateMaximumSupportAddress() to 48 if 5-Level Paging is disabled. When 5-Level Paging is disabled and the PhysicalAddressBits retrived from CPU HOB or CpuId is bigger than 48, only [0, 2^48 -1] range in 52-bit physical address is mapped in page table. Signed-off-by: Dun Tan Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c index ddd9be66b5..e6f174ca10 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -137,11 +137,13 @@ GetSubEntriesNum ( /** Calculate the maximum support address. + @param[in] Is5LevelPagingNeeded If 5-level paging enabling is needed. + @return the maximum support address. **/ UINT8 CalculateMaximumSupportAddress ( - VOID + BOOLEAN Is5LevelPagingNeeded ) { UINT32 RegEax; @@ -164,6 +166,15 @@ CalculateMaximumSupportAddress ( } } + // + // Only [0, 2^48 -1] in 52-bit physical addresses is mapped in page table + // when 5-Level Paging is disabled. + // + ASSERT (PhysicalAddressBits <= 52); + if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 48)) { + PhysicalAddressBits = 48; + } + return PhysicalAddressBits; } @@ -197,7 +208,7 @@ SmmInitPageTable ( mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess); m1GPageTableSupport = Is1GPageSupport (); m5LevelPagingNeeded = Is5LevelPagingNeeded (); - mPhysicalAddressBits = CalculateMaximumSupportAddress (); + mPhysicalAddressBits = CalculateMaximumSupportAddress (m5LevelPagingNeeded); PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1); if (m5LevelPagingNeeded) { mPagingMode = m1GPageTableSupport ? Paging5Level1GB : Paging5Level; -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113518): https://edk2.groups.io/g/devel/message/113518 Mute This Topic: https://groups.io/mt/103637402/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-