From nobody Fri May 3 06:35:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1508919169541143.42573218251528; Wed, 25 Oct 2017 01:12:49 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 01F362034A7DE; Wed, 25 Oct 2017 01:09:03 -0700 (PDT) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C9EC3202E6186 for ; Wed, 25 Oct 2017 01:09:01 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2017 01:12:45 -0700 Received: from jwang36-mobl2.ccr.corp.intel.com ([10.239.192.98]) by fmsmga002.fm.intel.com with ESMTP; 25 Oct 2017 01:12:44 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,431,1503385200"; d="scan'208";a="1234995809" From: Jian J Wang To: edk2-devel@lists.01.org Date: Wed, 25 Oct 2017 16:12:42 +0800 Message-Id: <20171025081242.1340-1-jian.j.wang@intel.com> X-Mailer: git-send-email 2.14.1.windows.1 Subject: [edk2] [PATCH v2] UefiCpuPkg/CpuDxe: Fix multiple entries of RT_CODE in memory map X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" > v2 just updated the commit message. Multiple RT_CODE in memory map was introduced by previous commit c1cab54ce57c2608b8b3ea051c7041f036f21153 This commit changed memory capability only based on page type of memory attributes. EDK2's report of memory map to OS is grouped by memory capabilites. This will cause more than on RT_CODE entries in memory map if UEFI image protection is enabled, which will mark memory of code segments of some modules to be read-only. More than one entry of RT_CODE memory will cause boot problem for specific old version of Linux kernel, because it will misplace the code segment and data segment in this situation. The recent major Linux distro have no such problem in boot. This patch will fix this issue to keep OS compatibility as much as possible. From memory paging point of view, all memory block should have the capabili= tes to change paging related memory attributes, if the memory paging has been enabled and well setup, not just those memory blocks having some paging rel= ated attributes set. So this patch will simply add all paging related memory attribtes to the capability of all existing memory blocks if paging is enab= led. As a side effect, it will prevent EDK2 from reporting multple RT_CODE to OS. Cc: Eric Dong Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- UefiCpuPkg/CpuDxe/CpuPageTable.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTa= ble.c index d312eb66f8..0802464b9d 100644 --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c @@ -829,6 +829,15 @@ RefreshGcdMemoryAttributesFromPaging ( // Sync real page attributes to GCD BaseAddress =3D MemorySpaceMap[Index].BaseAddress; MemorySpaceLength =3D MemorySpaceMap[Index].Length; + Capabilities =3D MemorySpaceMap[Index].Capabilities | + EFI_MEMORY_PAGETYPE_MASK; + Status =3D gDS->SetMemorySpaceCapabilities ( + BaseAddress, + MemorySpaceLength, + Capabilities + ); + ASSERT_EFI_ERROR (Status); + while (MemorySpaceLength > 0) { if (PageLength =3D=3D 0) { PageEntry =3D GetPageTableEntry (&PagingContext, BaseAddress, &Pag= eAttribute); @@ -846,7 +855,6 @@ RefreshGcdMemoryAttributesFromPaging ( if (Attributes !=3D (MemorySpaceMap[Index].Attributes & EFI_MEMORY= _PAGETYPE_MASK)) { DoUpdate =3D TRUE; Attributes |=3D (MemorySpaceMap[Index].Attributes & ~EFI_MEMORY_= PAGETYPE_MASK); - Capabilities =3D Attributes | MemorySpaceMap[Index].Capabilities; } else { DoUpdate =3D FALSE; } @@ -854,8 +862,8 @@ RefreshGcdMemoryAttributesFromPaging ( =20 Length =3D MIN (PageLength, MemorySpaceLength); if (DoUpdate) { - gDS->SetMemorySpaceCapabilities (BaseAddress, Length, Capabilities= ); - gDS->SetMemorySpaceAttributes (BaseAddress, Length, Attributes); + Status =3D gDS->SetMemorySpaceAttributes (BaseAddress, Length, Att= ributes); + ASSERT_EFI_ERROR (Status); DEBUG ((DEBUG_INFO, "Update memory space attribute: [%02d] %016lx = - %016lx (%08lx -> %08lx)\r\n", Index, BaseAddress, BaseAddress + Length - 1, MemorySpaceMap[Index].Attributes, Attributes)= ); --=20 2.14.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel