From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 B7DB920359A8E for ; Thu, 9 Nov 2017 17:00:34 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP; 09 Nov 2017 17:04:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,371,1505804400"; d="scan'208";a="358349" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by FMSMGA003.fm.intel.com with ESMTP; 09 Nov 2017 17:04:36 -0800 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 9 Nov 2017 17:04:36 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 9 Nov 2017 17:04:35 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.152]) with mapi id 14.03.0319.002; Fri, 10 Nov 2017 09:04:33 +0800 From: "Wang, Jian J" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: Laszlo Ersek , "Yao, Jiewen" , "Dong, Eric" Thread-Topic: [edk2] [PATCH] UefiCpuPkg/CpuDxe: Fix multiple entries of RT_CODE in memory map Thread-Index: AQHTWby+K7eSkIfdokqYX6XCOudzLqMMy/PA Date: Fri, 10 Nov 2017 01:04:33 +0000 Message-ID: References: <20171110004149.9128-1-jian.j.wang@intel.com> In-Reply-To: <20171110004149.9128-1-jian.j.wang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTcwMmM1NWMtZmM3Ni00M2U1LWEwZjYtMTdiMGZhZGQzYmYxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJIVU42OTBldnN6TVFqR2RlS3BJcVdFRlRaK0lrdUpwMnhaQnMzZTFlOXhqN1Y4VXVISGRYZk1WM09kSlZvbk8rIn0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] 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: , X-List-Received-Date: Fri, 10 Nov 2017 01:00:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Sorry guys. I did update the title but v5 is still missing. A new one will = be sent out. > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ji= an J > Wang > Sent: Friday, November 10, 2017 8:42 AM > To: edk2-devel@lists.01.org > Cc: Laszlo Ersek ; Yao, Jiewen ; > Dong, Eric > Subject: [edk2] [PATCH] UefiCpuPkg/CpuDxe: Fix multiple entries of RT_COD= E in > memory map >=20 > > v5: > > Coding style clean-up >=20 > > v4: > > a. Remove DoUpdate and check attributes mismatch all the time to avoid > > a logic hole > > b. Add warning message if failed to update capability > > c. Add local variable to hold new attributes to make code cleaner >=20 > > v3: > > a. Add comment to explain more on updating memory capabilities > > b. Fix logic hole in updating attributes > > c. Instead of checking illegal memory space address and size, use retur= n > > status of gDS->SetMemorySpaceCapabilities() to skip memory block whi= ch > > cannot be updated with new capabilities. >=20 > > v2 > > a. Fix an issue which will cause setting capability failure if size is = smaller > > than a page. >=20 > More than one entry of RT_CODE memory might cause boot problem for some > old OSs. This patch will fix this issue to keep OS compatibility as much > as possible. >=20 > More detailed information, please refer to > https://bugzilla.tianocore.org/show_bug.cgi?id=3D753 >=20 > Cc: Eric Dong > Cc: Jiewen Yao > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/CpuDxe/CpuPageTable.c | 69 +++++++++++++++++++++++++++++-- > --------- > 1 file changed, 50 insertions(+), 19 deletions(-) >=20 > diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c > b/UefiCpuPkg/CpuDxe/CpuPageTable.c > index d312eb66f8..61537838b7 100644 > --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c > +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c > @@ -789,8 +789,7 @@ RefreshGcdMemoryAttributesFromPaging ( > UINT64 BaseAddress; > UINT64 PageStartAddress; > UINT64 Attributes; > - UINT64 Capabilities; > - BOOLEAN DoUpdate; > + UINT64 NewAttributes; > UINTN Index; >=20 > // > @@ -802,9 +801,8 @@ RefreshGcdMemoryAttributesFromPaging ( >=20 > GetCurrentPagingContext (&PagingContext); >=20 > - DoUpdate =3D FALSE; > - Capabilities =3D 0; > Attributes =3D 0; > + NewAttributes =3D 0; > BaseAddress =3D 0; > PageLength =3D 0; >=20 > @@ -813,6 +811,34 @@ RefreshGcdMemoryAttributesFromPaging ( > continue; > } >=20 > + // > + // Sync the actual paging related capabilities back to GCD service f= irst. > + // As a side effect (good one), this can also help to avoid unnecess= ary > + // memory map entries due to the different capabilities of the same = type > + // memory, such as multiple RT_CODE and RT_DATA entries in memory ma= p, > + // which could cause boot failure of some old Linux distro (before v= 4.3). > + // > + Status =3D gDS->SetMemorySpaceCapabilities ( > + MemorySpaceMap[Index].BaseAddress, > + MemorySpaceMap[Index].Length, > + MemorySpaceMap[Index].Capabilities | > + EFI_MEMORY_PAGETYPE_MASK > + ); > + if (EFI_ERROR (Status)) { > + // > + // If we cannot udpate the capabilities, we cannot update its > + // attributes either. So just simply skip current block of memory. > + // > + DEBUG (( > + DEBUG_WARN, > + "Failed to update capability: [%lu] %016lx - %016lx (%016lx -> %= 016lx)\r\n", > + (UINT64)Index, BaseAddress, BaseAddress + Length - 1, > + MemorySpaceMap[Index].Capabilities, > + MemorySpaceMap[Index].Capabilities | EFI_MEMORY_PAGETYPE_MASK > + )); > + continue; > + } > + > if (MemorySpaceMap[Index].BaseAddress >=3D (BaseAddress + PageLength= )) { > // > // Current memory space starts at a new page. Resetting PageLength= will > @@ -826,7 +852,9 @@ RefreshGcdMemoryAttributesFromPaging ( > PageLength -=3D (MemorySpaceMap[Index].BaseAddress - BaseAddress); > } >=20 > - // Sync real page attributes to GCD > + // > + // Sync actual page attributes to GCD > + // > BaseAddress =3D MemorySpaceMap[Index].BaseAddress; > MemorySpaceLength =3D MemorySpaceMap[Index].Length; > while (MemorySpaceLength > 0) { > @@ -842,23 +870,26 @@ RefreshGcdMemoryAttributesFromPaging ( > PageStartAddress =3D (*PageEntry) & > (UINT64)PageAttributeToMask(PageAttribute); > PageLength =3D PageAttributeToLength (PageAttribute) - (B= aseAddress - > PageStartAddress); > Attributes =3D GetAttributesFromPageEntry (PageEntry); > - > - 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].Capabiliti= es; > - } else { > - DoUpdate =3D FALSE; > - } > } >=20 > Length =3D MIN (PageLength, MemorySpaceLength); > - if (DoUpdate) { > - gDS->SetMemorySpaceCapabilities (BaseAddress, Length, Capabiliti= es); > - gDS->SetMemorySpaceAttributes (BaseAddress, Length, Attributes); > - DEBUG ((DEBUG_INFO, "Update memory space attribute: [%02d] %016l= x - > %016lx (%08lx -> %08lx)\r\n", > - Index, BaseAddress, BaseAddress + Length - = 1, > - MemorySpaceMap[Index].Attributes, Attribute= s)); > + if (Attributes !=3D (MemorySpaceMap[Index].Attributes & > + EFI_MEMORY_PAGETYPE_MASK)) { > + NewAttributes =3D (MemorySpaceMap[Index].Attributes & > + ~EFI_MEMORY_PAGETYPE_MASK) | Attributes; > + Status =3D gDS->SetMemorySpaceAttributes ( > + BaseAddress, > + Length, > + NewAttributes > + ); > + ASSERT_EFI_ERROR (Status); > + DEBUG (( > + DEBUG_INFO, > + "Updated memory space attribute: [%lu] %016lx - %016lx (%016lx= - > > %016lx)\r\n", > + (UINT64)Index, BaseAddress, BaseAddress + Length - 1, > + MemorySpaceMap[Index].Attributes, > + NewAttributes > + )); > } >=20 > PageLength -=3D Length; > -- > 2.14.1.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel