From nobody Mon Sep 16 19:37:56 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+101762+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+101762+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1679647934; cv=none; d=zohomail.com; s=zohoarc; b=avoF0ZXxlazi4nmDhJeiGdzu5nD8y5y310N1k1/c/I3A8R7/oCYNWAFQyJEWoEGFhhjYs2RPN8xpaREV31FKQwzh3Y59ujOLKYJLZl71ZtqssOJa7ffpPmK2p5v8nDxJ8Pu77RzO7jLM5SW0iCUOgHMv5Qb8ggadtQLaN5wI7WM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679647934; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Uda36WWQqiZeMO23dy21Pgdqh3lgGLHsxj3/CxtbPdk=; b=efHjizamXbgsyZncCak1W9sDeFxDc7Zs1RGSKKMkM4VsOedCjio+CXDQwi7cJ/nbxKG5q4ofIz4TQMFJWTw4QfLXPeG6rWcRjJNFZ4gUvfkUxgtSC0sfbvfiMZC6LRFUwTQ9cwbN4zVc03bA1cc32fe5PU/CpsUGakcjyZ+EWsI= 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+101762+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 1679647934012166.93021216153795; Fri, 24 Mar 2023 01:52:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id U3aFYY1788612xDPGloj1RLS; Fri, 24 Mar 2023 01:52:13 -0700 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.96113.1679647930408970241 for ; Fri, 24 Mar 2023 01:52:13 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="323603772" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="323603772" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 01:52:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10658"; a="713010791" X-IronPort-AV: E=Sophos;i="5.98,287,1673942400"; d="scan'208";a="713010791" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.92]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2023 01:52:11 -0700 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V6 04/22] UefiCpuPkg/CpuPageTableLib: Fix the non-1:1 mapping issue Date: Fri, 24 Mar 2023 16:51:50 +0800 Message-Id: <20230324085151.1237-2-dun.tan@intel.com> In-Reply-To: <20230324085151.1237-1-dun.tan@intel.com> References: <20230324085151.1237-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: 6qZhksROlkJWyXUMRZl6B2Bbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679647933; bh=OwIBsJnX9hoWQ4XsyNFDG6pkEXmHXoDY3OUmRfqqxy0=; h=Cc:Date:From:Reply-To:Subject:To; b=OsaG/tj6G0pK9EMY+FAINpjMVLRx5SBnauRsTc8nhiY2RWibJy2BRpVdCHtjvazDkOE QZWCw2K0vT66ofbjYc3ezrTxgB9wZVfMx1b//y3ewLETm96fZZ/MVK7DC6kdNQou0NRgr YLupfupLQKLoh7KwD4vkn+WXJo4pC1ODwbE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679647935050100005 Content-Type: text/plain; charset="utf-8" In previous code logic, when splitting a leaf parent entry to smaller granularity child page table, if the parent entry Attribute&Mask(without PageTableBaseAddress field) is equal to the input attribute&mask(without PageTableBaseAddress field), the split process won't happen. This may lead to failure in non-1:1 mapping. For example, there is a page table in which [0, 1G] is mapped(Lv4[0] ,Lv3[0,0], a non-leaf level4 entry and a leaf level3 entry). And we want to remap [0, 2M] linear address range to [1G, 1G + 2M] with the same attibute. The expected behaviour should be: split Lv3[0,0] entry into 512 level2 entries and remap the first level2 entry to cover [0, 2M]. But the split won't happen in previous code since PageTableBaseAddress of input Attribute is not checked. So, when checking if a leaf parent entry needs to be splitted, we should also check if PageTableBaseAddress calculated by parent entry is equal to the value caculated by input attribute. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Tested-by: Gerd Hoffmann Acked-by: Gerd Hoffmann Reviewed-by: Ray Ni --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/Library/CpuPageTableLib/CpuPageTableMap.c index 127b65183f..b94ef07c56 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -274,6 +274,8 @@ PageTableLibMapInLevel ( IA32_MAP_ATTRIBUTE ChildMask; IA32_MAP_ATTRIBUTE CurrentMask; IA32_MAP_ATTRIBUTE LocalParentAttribute; + UINT64 PhysicalAddrInEntry; + UINT64 PhysicalAddrInAttr; =20 ASSERT (Level !=3D 0); ASSERT ((Attribute !=3D NULL) && (Mask !=3D NULL)); @@ -341,7 +343,15 @@ PageTableLibMapInLevel ( // This function is called when the memory length is less than the r= egion length of the parent level. // No need to split the page when the attributes equal. // - return RETURN_SUCCESS; + if (Mask->Bits.PageTableBaseAddress =3D=3D 0) { + return RETURN_SUCCESS; + } + + PhysicalAddrInEntry =3D IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS (= &PleBAttribute) + MultU64x32 (RegionLength, (UINT32)PagingEntryIndex); + PhysicalAddrInAttr =3D (IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS = (Attribute) + Offset) & (~RegionMask); + if (PhysicalAddrInEntry =3D=3D PhysicalAddrInAttr) { + return RETURN_SUCCESS; + } } =20 ASSERT (Buffer =3D=3D NULL || *BufferSize >=3D SIZE_4KB); --=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 (#101762): https://edk2.groups.io/g/devel/message/101762 Mute This Topic: https://groups.io/mt/97819604/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-