From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org 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 77CFE211F1E30 for ; Tue, 2 Apr 2019 20:01:00 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Apr 2019 20:00:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,303,1549958400"; d="scan'208";a="160885521" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga001.fm.intel.com with ESMTP; 02 Apr 2019 20:00:59 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 2 Apr 2019 20:00:59 -0700 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 2 Apr 2019 20:00:58 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.92]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.21]) with mapi id 14.03.0415.000; Wed, 3 Apr 2019 11:00:56 +0800 From: "Ni, Ray" To: "Dong, Eric" , "edk2-devel@lists.01.org" Thread-Topic: [Patch v2] UefiCpuPkg/MpInitLib: Fix MemTest86 failure. Thread-Index: AQHU6cd2co5Cu854t0S/k0S2r4Q5raYpvw3Q Date: Wed, 3 Apr 2019 03:00:55 +0000 Deferred-Delivery: Wed, 3 Apr 2019 03:00:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C0C6FC9@SHSMSX104.ccr.corp.intel.com> References: <20190403024620.15228-1-eric.dong@intel.com> In-Reply-To: <20190403024620.15228-1-eric.dong@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiN2RmYWYwMWEtOWRlZi00NGJhLWIyYTktNDRlZTJjNTliZjE5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiRWZvaDE1KzVtSng4ZzdJNUJjZTh3cTZETHNreVlOM253WVwvZ2NvMk1ORjhqUHJMbWV6cDZhbDg3QjdrUnRZTUkifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v2] UefiCpuPkg/MpInitLib: Fix MemTest86 failure. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Apr 2019 03:01:00 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Dong, Eric > Sent: Wednesday, April 3, 2019 10:46 AM > To: edk2-devel@lists.01.org > Cc: Ni, Ray > Subject: [Patch v2] UefiCpuPkg/MpInitLib: Fix MemTest86 failure. >=20 > V2 changes: > Update the commit message and comments in the code. >=20 > When waking vector buffer allocated by CpuDxe is tested by MemTest86 > in MP mode, an error is reported because the same range of memory is > modified by both CpuDxe driver and MemTest86. >=20 > The waking vector buffer is not expected to be tested by MemTest86 if > it is allocated out because MemTest86 only tests free memory. But > current CpuDxe driver "borrows" buffer instead of allocate buffer for > waking vector buffer (through allocate & free to get the buffer > pointer, backup the buffer data before using it and restore it after > using). With this implementation, if the buffer borrowed is not used > by any other drivers, MemTest86 tool will treat it as free memory > and test it. >=20 > In order to fix the above issue, CpuDxe changes to allocate the > buffer below 1M instead of borrowing it. But directly allocating > memory below 1MB causes LegacyBios driver fails to start. LegacyBios > driver allocates memory range from > "0xA0000 - PcdEbdaReservedMemorySize" to 0xA0000 as Ebda Reserved > Memory. The minimum value for "0xA0000 - PcdEbdaReservedMemorySize" > is 0x88000. If LegacyBios driver allocate this range failed, it > asserts. >=20 > LegacyBios also reserves range from 0x60000 to > "0x60000 + PcdOpromReservedMemorySize", it will be used as Oprom > Reserve Memory. The maximum value for "0x60000 + > PcdOpromReservedMemorySize" is 0x88000. LegacyBios driver tries to > allocate these range page(4K size) by page. It just reports warning > message if some pages are already allocated by others. > Base on above investigation, one page in range 0x60000 ~ 0x88000 can > be used as the waking vector buffer. >=20 > LegacyBios driver only reports warning when page allocation in range > [0x60000, 0x88000) fails. This library is consumed by CpuDxe driver > to produce CPU Arch protocol. LagacyBios driver depends on CPU Arch > protocol which guarantees below allocation runs earlier than > LegacyBios driver. >=20 > Cc: Ray Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 26 ++++++++++++++----------- > 1 file changed, 15 insertions(+), 11 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > index b2307cbb61..cef5b49dde 100644 > --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > @@ -76,7 +76,7 @@ SaveCpuMpData ( > } >=20 > /** > - Get available system memory below 1MB by specified size. > + Get available system memory below 0x88000 by specified size. >=20 > @param[in] WakeupBufferSize Wakeup buffer size required >=20 > @@ -91,7 +91,15 @@ GetWakeupBuffer ( > EFI_STATUS Status; > EFI_PHYSICAL_ADDRESS StartAddress; >=20 > - StartAddress =3D BASE_1MB; > + // > + // Try to allocate buffer below 1M for waking vector. > + // LegacyBios driver only reports warning when page allocation in rang= e > + // [0x60000, 0x88000) fails. > + // This library is consumed by CpuDxe driver to produce CPU Arch proto= col. > + // LagacyBios driver depends on CPU Arch protocol which guarantees bel= ow > + // allocation runs earlier than LegacyBios driver. > + // > + StartAddress =3D 0x88000; > Status =3D gBS->AllocatePages ( > AllocateMaxAddress, > EfiBootServicesData, > @@ -99,17 +107,13 @@ GetWakeupBuffer ( > &StartAddress > ); > ASSERT_EFI_ERROR (Status); > - if (!EFI_ERROR (Status)) { > - Status =3D gBS->FreePages( > - StartAddress, > - EFI_SIZE_TO_PAGES (WakeupBufferSize) > - ); > - ASSERT_EFI_ERROR (Status); > - DEBUG ((DEBUG_INFO, "WakeupBufferStart =3D %x, WakeupBufferSize =3D = %x\n", > - (UINTN) StartAddress, WakeupBufferSize)); > - } else { > + if (EFI_ERROR (Status)) { > StartAddress =3D (EFI_PHYSICAL_ADDRESS) -1; > } > + > + DEBUG ((DEBUG_INFO, "WakeupBufferStart =3D %x, WakeupBufferSize =3D %x= \n", > + (UINTN) StartAddress, WakeupBufferSize)); > + > return (UINTN) StartAddress; > } >=20 > -- > 2.21.0.windows.1