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.136; helo=mga12.intel.com; envelope-from=eric.dong@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 56BA921959CB2 for ; Wed, 6 Mar 2019 18:53:34 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Mar 2019 18:53:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,450,1544515200"; d="scan'208";a="150005488" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga004.fm.intel.com with ESMTP; 06 Mar 2019 18:53:33 -0800 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 6 Mar 2019 18:53:32 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 6 Mar 2019 18:53:31 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.163]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.144]) with mapi id 14.03.0415.000; Thu, 7 Mar 2019 10:53:08 +0800 From: "Dong, Eric" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Ni, Ray" , "Laszlo Ersek (lersek@redhat.com)" Thread-Topic: [edk2] [Patch] UefiCpuPkg/MpInitLib: Direct allocate buffer for Wake up Buffer. Thread-Index: AQHU0vg0tMIT11K5/UafwcrOo6yQAqX8H1mAgANb19A= Date: Thu, 7 Mar 2019 02:53:07 +0000 Message-ID: References: <20190305020658.23408-1-eric.dong@intel.com> <20190305020658.23408-2-eric.dong@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483104028C545@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483104028C545@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] UefiCpuPkg/MpInitLib: Direct allocate buffer for Wake up Buffer. 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: Thu, 07 Mar 2019 02:53:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Star, This logic seems much complicated than mine. Also after CSM retired from ED= KII, we will change this code back to only require allocate buffer below 1M= . I will add such notes in the code comments. So I prefer to use my change= . Thanks, Eric > -----Original Message----- > From: Zeng, Star > Sent: Tuesday, March 5, 2019 3:33 PM > To: Dong, Eric ; edk2-devel@lists.01.org > Cc: Ni, Ray ; Laszlo Ersek (lersek@redhat.com) > ; Zeng, Star > Subject: RE: [edk2] [Patch] UefiCpuPkg/MpInitLib: Direct allocate buffer = for > Wake up Buffer. >=20 > Just an idea to avoid hard code value 0x88000. >=20 > Before EndOfDxe: Allocate buffer in AllocateResetVector(), and free buffe= r > in FreeResetVector(). > At EndOfDxe (it is after LegacyBiosDxe driver entry point) callback: Allo= cate > buffer and record it to CpuMpData->WakeupBuffer, and always occupy the > buffer, that means no free. > After EndOfDxe: Use CpuMpData->WakeupBuffer. >=20 >=20 > Thanks, > Star > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Eric Dong > Sent: Tuesday, March 5, 2019 10:07 AM > To: edk2-devel@lists.01.org > Subject: [edk2] [Patch] UefiCpuPkg/MpInitLib: Direct allocate buffer for > Wake up Buffer. >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D1538 >=20 > Current CpuDxe driver "borrows" Wakeup Buffer (through Allocate & free to > get the buffer pointer, backup the buffer data before using it and restor= e it > after using). Now this logic met a problem described in the above BZ > because the test tool and the CpuDxe both use the same memory at the > same time. >=20 > In order to fix the above issue, CpuDxe changed to allocate the buffer be= low > 1M instead of borrow it. After investigation, we found below > 0x88000 is the possible space which can be used. For now, range > 0x60000 ~ 0x88000 used for Legacy OPROMs by LegacyBios driver. And it tri= es > to allocate these range page(4K size) by page. It just reports warning > message if specific page been used by others already. >=20 > Also CpuDxe driver will produce CPU arch protocol and LegacyBios driver h= as > dependency for this protocol. So CpuDxe driver will start before LegacyBi= os > driver and CpuDxe driver can allocate that space successful. >=20 > With this change, CpuDxe driver will use 0x87000 ~ 0x88000 as wakeup buff= er. >=20 > Cc: Ray Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 30 +++++++++++++++++++---- > ------- > 1 file changed, 19 insertions(+), 11 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > index b2307cbb61..5bc9a47efb 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,19 @@ GetWakeupBuffer ( > EFI_STATUS Status; > EFI_PHYSICAL_ADDRESS StartAddress; >=20 > - StartAddress =3D BASE_1MB; > + // > + // Current "Borrow" space mechanism caused potential race condition > + if both // AP and the original owner use the share space. > + // > + // LegacyBios driver tries to allocate 4K pages between 0x60000 ~ > + 0x88000 // space. It will just report an waring message if the page > + has been allocate // by other drivers. > + // LagacyBios driver depends on CPU Arch protocol, so it will start > + after // CpuDxe driver which produce Cpu Arch Protocol and use this > library. > + // So below allocate logic will be trigged before LegacyBios driver > + and it // will always return success. > + // > + StartAddress =3D BASE_512KB + BASE_32KB; > Status =3D gBS->AllocatePages ( > AllocateMaxAddress, > EfiBootServicesData, > @@ -99,17 +111,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.15.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel