From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 66034821E5 for ; Mon, 20 Feb 2017 01:11:12 -0800 (PST) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC4F3635C4; Mon, 20 Feb 2017 09:11:12 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-112.phx2.redhat.com [10.3.116.112]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1K9BAmv015807; Mon, 20 Feb 2017 04:11:11 -0500 To: Jeff Fan , edk2-devel@ml01.01.org References: <20170220084005.21924-1-jeff.fan@intel.com> Cc: Michael D Kinney , Feng Tian , Jiewen Yao From: Laszlo Ersek Message-ID: Date: Mon, 20 Feb 2017 10:11:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20170220084005.21924-1-jeff.fan@intel.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 20 Feb 2017 09:11:12 +0000 (UTC) Subject: Re: [PATCH] UefiCpuPkg/CpuDxe: Add Local APIC memory mapped space in gDS X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Feb 2017 09:11:12 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Hi Jeff, On 02/20/17 09:40, Jeff Fan wrote: > Local APIC memory mapped space should be added into gDS and be allocated. > Otherwise, UEFI firmware cannot get correct memory map for it. For example, > SMM profile feature needs to get the completed MMIO map to protect them. > > https://bugzilla.tianocore.org/show_bug.cgi?id=390 > > Cc: Jiewen Yao > Cc: Feng Tian > Cc: Michael D Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jeff Fan > --- > UefiCpuPkg/CpuDxe/CpuDxe.c | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c > index 9fb6d76..71a08cd 100644 > --- a/UefiCpuPkg/CpuDxe/CpuDxe.c > +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c > @@ -887,6 +887,40 @@ IdleLoopEventCallback ( > CpuSleep (); > } > > +/** > + Add and allocate CPU local APIC memory mapped space. > + > + @param[in]ImageHandle Image handle this driver. > + > +**/ > +VOID > +AddLocalApicMemorySpace ( > + IN EFI_HANDLE ImageHandle > + ) > +{ > + EFI_STATUS Status; > + EFI_PHYSICAL_ADDRESS BaseAddress; > + > + BaseAddress = (EFI_PHYSICAL_ADDRESS) GetLocalApicBaseAddress (); > + Status = gDS->AddMemorySpace ( > + EfiGcdMemoryTypeMemoryMappedIo, > + BaseAddress, > + SIZE_4KB, > + EFI_MEMORY_UC > + ); > + ASSERT_EFI_ERROR (Status); (1) This would break OVMF: > Loading driver at 0x0007F510000 EntryPoint=0x0007F51027B CpuDxe.efi > InstallProtocolInterface: [EfiLoadedImageDevicePathProtocol] 7EE08498 > InstallProtocolInterface: [EfiCpuArchProtocol] 7F522480 > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > Flushing GCD > > ASSERT_EFI_ERROR (Status = Access Denied) > ASSERT .../UefiCpuPkg/CpuDxe/CpuDxe.c(891): !EFI_ERROR (Status) The reason for the assertion failure is that we add an uncacheable MMIO resource descriptor HOB for the LAPIC range earlier, in OvmfPkg/PlatformPei. When DXE starts up, it initializes the GCD memory space accordingly, hence the above addition failure. There was a similar issue in PciHostBridgeDxe: originally it tried to add uncacheable MMIO space for the PCI bridges' apertures, unconditionally. The solution was to check the GCD memory space map, and: - for any existing, overlapping entries, check if their attributes were compatible with UC, - missing gaps were filled with new additions. Please see commit 6474f1f156ee ("MdeModulePkg/PciHostBridge: Don't assume resources are fully NonExistent", 2016-02-25). (2) After the memory space addition, the allocation should be attempted, I agree. But for that too, if it fails, that shouldn't be a fatal error. Thanks Laszlo > + > + Status = gDS->AllocateMemorySpace ( > + EfiGcdAllocateAddress, > + EfiGcdMemoryTypeMemoryMappedIo, > + 0, > + SIZE_4KB, > + &BaseAddress, > + ImageHandle, > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > +} > > /** > Initialize the state information for the CPU Architectural Protocol. > @@ -947,6 +981,11 @@ InitializeCpu ( > RefreshGcdMemoryAttributes (); > > // > + // Add and allocate local APIC memory mapped space > + // > + AddLocalApicMemorySpace (ImageHandle); > + > + // > // Setup a callback for idle events > // > Status = gBS->CreateEventEx ( >