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.126; helo=mga18.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (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 4B2FF211D35F5 for ; Mon, 4 Mar 2019 23:33:21 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2019 23:33:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,443,1544515200"; d="scan'208";a="325490007" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga005.fm.intel.com with ESMTP; 04 Mar 2019 23:33:20 -0800 Received: from fmsmsx151.amr.corp.intel.com (10.18.125.4) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 4 Mar 2019 23:33:20 -0800 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX151.amr.corp.intel.com (10.18.125.4) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 4 Mar 2019 23:33:20 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.163]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.121]) with mapi id 14.03.0415.000; Tue, 5 Mar 2019 15:33:18 +0800 From: "Zeng, Star" To: "Dong, Eric" , "edk2-devel@lists.01.org" CC: "Ni, Ray" , "Laszlo Ersek (lersek@redhat.com)" , "Zeng, Star" Thread-Topic: [edk2] [Patch] UefiCpuPkg/MpInitLib: Direct allocate buffer for Wake up Buffer. Thread-Index: AQHU0vgwNmXSdkgr7k+sf7WnPrX7eqX8oxxw Date: Tue, 5 Mar 2019 07:33:17 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483104028C545@shsmsx102.ccr.corp.intel.com> References: <20190305020658.23408-1-eric.dong@intel.com> <20190305020658.23408-2-eric.dong@intel.com> In-Reply-To: <20190305020658.23408-2-eric.dong@intel.com> Accept-Language: zh-CN, 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: Tue, 05 Mar 2019 07:33:22 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Just an idea to avoid hard code value 0x88000. Before EndOfDxe: Allocate buffer in AllocateResetVector(), and free buffer = in FreeResetVector(). At EndOfDxe (it is after LegacyBiosDxe driver entry point) callback: Alloca= te buffer and record it to CpuMpData->WakeupBuffer, and always occupy the b= uffer, that means no free. After EndOfDxe: Use CpuMpData->WakeupBuffer. 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 Wa= ke up Buffer. https://bugzilla.tianocore.org/show_bug.cgi?id=3D1538 Current CpuDxe driver "borrows" Wakeup Buffer (through Allocate & free to g= et the buffer pointer, backup the buffer data before using it and restore i= t after using). Now this logic met a problem described in the above BZ bec= ause the test tool and the CpuDxe both use the same memory at the same time= . In order to fix the above issue, CpuDxe changed to allocate the buffer belo= w 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 tries= to allocate these range page(4K size) by page. It just reports warning mes= sage if specific page been used by others already. Also CpuDxe driver will produce CPU arch protocol and LegacyBios driver has= dependency for this protocol. So CpuDxe driver will start before LegacyBio= s driver and CpuDxe driver can allocate that space successful. With this change, CpuDxe driver will use 0x87000 ~ 0x88000 as wakeup buffer= . 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(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/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=20 + if both // AP and the original owner use the share space. + // + // LegacyBios driver tries to allocate 4K pages between 0x60000 ~=20 + 0x88000 // space. It will just report an waring message if the page=20 + has been allocate // by other drivers. + // LagacyBios driver depends on CPU Arch protocol, so it will start=20 + after // CpuDxe driver which produce Cpu Arch Protocol and use this libr= ary. + // So below allocate logic will be trigged before LegacyBios driver=20 + 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 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel