From nobody Fri May 17 05:50:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+113518+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113518+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1704873960; cv=none; d=zohomail.com; s=zohoarc; b=CGVJJxiZfi18irzHmbkEXYgddI6YSKGDd4igG8rhb2skHrS+tPB9/HePQB3Fuz1LLe97qi0fX6ehp0eSb4IGHe+FN7fk8Eq0aTi3mc0F4kVEE3u5YrYqQQd1H5q/O+MOFJkqxqBEgGqIFvIiagGEnKm+zW2vsZITJojWzYV+HKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704873960; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=9zwJntgpF0O/OjNccxyzfxd8aIWOV9/ns2LZDmr6yEo=; b=QzOE1BiamIyfyehbagWhztLsUwIr19DD80kpMPoI/oUap+IKM7hcxpTPVoZIDt9ku3+xyG8zOoGoQ2voyv56qVlbkf1Vsz/TDvvywGGwI/+sCfvJQ2RzYXFjxwMXId9pKT5cjiJaZirYt2HKf0CVurKKrUjVFxcrxm+N3fjAYNk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+113518+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1704873960507826.2984214548133; Wed, 10 Jan 2024 00:06:00 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=g1dfjM/YCaw8/uVE0K+PLxfzwPxdhyG6g/8WUZTeHwo=; 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=DEDL8+jtoObiBKo4LivJ4RlbwuRQNhi8WqEy3NV+KVIN3RLfJHbI8ReJ339bTIE2n3+D/Dns F6wQ0WlVEn3NA25CWUGPjeXI1QL0H3bIQFwhUYx946Ft1bUTpQbfrcU4uszq8Dro+I+fkHJtHfS IFQjHGIPG0jRyp9lINt74nog= X-Received: by 127.0.0.2 with SMTP id atp8YY1788612xIETJPJjf0q; 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: WWCDPKZvHRM6LM4mZaKf9BMex1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1704873962333100003 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuD= xeSmm/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. =20 + @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 ( } } =20 + // + // Only [0, 2^48 -1] in 52-bit physical addresses is mapped in page table + // when 5-Level Paging is disabled. + // + ASSERT (PhysicalAddressBits <=3D 52); + if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 48)) { + PhysicalAddressBits =3D 48; + } + return PhysicalAddressBits; } =20 @@ -197,7 +208,7 @@ SmmInitPageTable ( mCpuSmmRestrictedMemoryAccess =3D PcdGetBool (PcdCpuSmmRestrictedMemoryA= ccess); m1GPageTableSupport =3D Is1GPageSupport (); m5LevelPagingNeeded =3D Is5LevelPagingNeeded (); - mPhysicalAddressBits =3D CalculateMaximumSupportAddress (); + mPhysicalAddressBits =3D CalculateMaximumSupportAddress (m5Leve= lPagingNeeded); PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1); if (m5LevelPagingNeeded) { mPagingMode =3D m1GPageTableSupport ? Paging5Level1GB : Paging5Level; --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-