From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 370BF21945DE5 for ; Thu, 7 Mar 2019 09:39:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBFE030718CB; Thu, 7 Mar 2019 17:39:48 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-123-89.rdu2.redhat.com [10.10.123.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39104177B1; Thu, 7 Mar 2019 17:39:47 +0000 (UTC) To: "Dong, Eric" , "Zeng, Star" , "edk2-devel@lists.01.org" Cc: "Ni, Ray" , David Woodhouse References: <20190305020658.23408-1-eric.dong@intel.com> <20190305020658.23408-2-eric.dong@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483104028C545@shsmsx102.ccr.corp.intel.com> From: Laszlo Ersek Message-ID: Date: Thu, 7 Mar 2019 18:39:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 07 Mar 2019 17:39:48 +0000 (UTC) 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 17:39:49 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/07/19 03:53, Dong, Eric wrote: > Hi Star, > > This logic seems much complicated than mine. Also after CSM retired from EDKII, 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. I apologize for my inability to follow the recent developments in this thread. However, what I recall is that we may not retire the CSM from edk2 entirely. Instead, if someone volunteers to maintain the CSM under OvmfPkg for example, then we'll keep it there. Personally I'm not interested in the CSM, but it would be nice if we didn't implement logic in UefiCpuPkg that would be, by design, incompatible with an optional feature that we might carry forward in OvmfPkg. Thanks Laszlo > 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. >> >> 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: Allocate >> buffer and record it to CpuMpData->WakeupBuffer, and always occupy the >> buffer, 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 >> Wake up Buffer. >> >> https://bugzilla.tianocore.org/show_bug.cgi?id=1538 >> >> Current CpuDxe driver "borrows" Wakeup Buffer (through Allocate & free to >> get the buffer pointer, backup the buffer data before using it and restore 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. >> >> In order to fix the above issue, CpuDxe changed to allocate the buffer below >> 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 >> message 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 LegacyBios >> 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/MpInitLib/DxeMpLib.c >> index b2307cbb61..5bc9a47efb 100644 >> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c >> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c >> @@ -76,7 +76,7 @@ SaveCpuMpData ( >> } >> >> /** >> - Get available system memory below 1MB by specified size. >> + Get available system memory below 0x88000 by specified size. >> >> @param[in] WakeupBufferSize Wakeup buffer size required >> >> @@ -91,7 +91,19 @@ GetWakeupBuffer ( >> EFI_STATUS Status; >> EFI_PHYSICAL_ADDRESS StartAddress; >> >> - StartAddress = 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 = BASE_512KB + BASE_32KB; >> Status = gBS->AllocatePages ( >> AllocateMaxAddress, >> EfiBootServicesData, >> @@ -99,17 +111,13 @@ GetWakeupBuffer ( >> &StartAddress >> ); >> ASSERT_EFI_ERROR (Status); >> - if (!EFI_ERROR (Status)) { >> - Status = gBS->FreePages( >> - StartAddress, >> - EFI_SIZE_TO_PAGES (WakeupBufferSize) >> - ); >> - ASSERT_EFI_ERROR (Status); >> - DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize >> = %x\n", >> - (UINTN) StartAddress, WakeupBufferSize)); >> - } else { >> + if (EFI_ERROR (Status)) { >> StartAddress = (EFI_PHYSICAL_ADDRESS) -1; >> } >> + >> + DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize >> = %x\n", >> + (UINTN) StartAddress, WakeupBufferSize)); >> + >> return (UINTN) StartAddress; >> } >> >> -- >> 2.15.0.windows.1 >> >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel