From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754781Ab2CGKbQ (ORCPT ); Wed, 7 Mar 2012 05:31:16 -0500 Received: from mga12.intel.com ([143.182.124.36]:50666 "EHLO azsmga102.ch.intel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754106Ab2CGKbN (ORCPT ); Wed, 7 Mar 2012 05:31:13 -0500 Subject: Re: [tip:x86/urgent] x86, efi: Delete efi_ioremap() and fix CONFIG_X86_32 oops From: Matt Fleming To: "H. Peter Anvin" Cc: Yinghai Lu , mingo@redhat.com, mjg@redhat.com, linux-kernel@vger.kernel.org, keithp@keithp.com, rui.zhang@intel.com, huang.ying.caritas@gmail.com, stable@vger.kernel.org, tglx@linutronix.de, linux-tip-commits@vger.kernel.org In-Reply-To: <4F4C3BA2.1070708@kernel.org> References: <1329744626-5036-1-git-send-email-matt@console-pimps.org> <4F45B35D.1010702@zytor.com> <4F471651.3080609@zytor.com> <4F4C3BA2.1070708@kernel.org> Content-Type: text/plain; charset="UTF-8" Organization: Intel Corporation (UK) Ltd. - Registered No. 1134945 - Pipers Way, Swindon SN3 1RJ Date: Wed, 07 Mar 2012 10:30:50 +0000 Message-ID: <1331116250.3539.35.camel@mfleming-mobl1.ger.corp.intel.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-1.fc14) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2012-02-27 at 18:27 -0800, H. Peter Anvin wrote: > On 02/23/2012 08:47 PM, H. Peter Anvin wrote: > >> > >> please check attach patch for tip/efi branch. > > > > That doesn't do anything like what I noted above. > > > > We should get rid of dependencies on legacy PC memory layouts, not add > > more hacks. What is so hard about "when we create the initial mappings, > > only create for RAM/ACPI/EFI regions" (if we even need to do so for > > ACPI, I think ACPI might use ioremap() already)? > > > > Hi Yinghai, > > Can you please answer my question? Did you have something like this in mind? Note that it doesn't go all the way to removing the add_do_memmap boot parameter because I'm not sure how to do that for GPL exported symbols. The only testing I've done with this is to ensure that it boots under qemu (both for EFI and BIOS) on 32/64-bit. This is on top of tip/x86/efi. diff --git a/arch/x86/include/asm/page_types.h b/arch/x86/include/asm/page_types.h index bce688d..4f95f23 100644 --- a/arch/x86/include/asm/page_types.h +++ b/arch/x86/include/asm/page_types.h @@ -51,8 +51,9 @@ static inline phys_addr_t get_max_mapped(void) return (phys_addr_t)max_pfn_mapped << PAGE_SHIFT; } -extern unsigned long init_memory_mapping(unsigned long start, - unsigned long end); +extern unsigned long init_memory_mapping(void); +extern unsigned long __init_memory_mapping(unsigned long start, + unsigned long end); extern void initmem_init(void); extern void free_initmem(void); diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c index b1e7c7f..f52ced2 100644 --- a/arch/x86/kernel/amd_gart_64.c +++ b/arch/x86/kernel/amd_gart_64.c @@ -769,7 +769,7 @@ int __init gart_iommu_init(void) if (end_pfn > max_low_pfn_mapped) { start_pfn = (aper_base>>PAGE_SHIFT); - init_memory_mapping(start_pfn<>PAGE_SHIFT, E820_RESERVED_EFI); - if (efi_end > end_pfn) - end_pfn = efi_end; - } -#endif - - max_low_pfn_mapped = init_memory_mapping(0, end_pfn << PAGE_SHIFT); - max_pfn_mapped = max_low_pfn_mapped; + /* max_low_pfn_mapped is updated here */ + max_pfn_mapped = init_memory_mapping(); #ifdef CONFIG_X86_64 if (max_pfn > max_low_pfn) { - max_pfn_mapped = init_memory_mapping(1UL<<32, - max_pfn<> PAGE_SHIFT; } +/* + * Traverse the E820 memory map and add RAM/ACPI/EFI regions to the + * initial memory mapping. + */ +unsigned long __init_refok init_memory_mapping(void) +{ + struct e820entry *entry; + unsigned long last_pfn_mapped = 0; + unsigned long start, end; + int i; + + /* Map the legacy region until we fix all drivers */ + __init_memory_mapping(0, 1 << 20); + + for (i = 0; i < e820.nr_map; i++) { + entry = &e820.map[i]; + start = entry->addr; + end = start + entry->size; + + /* We've already mapped below 1MB */ + if (end < (1 << 20)) + continue; + + if (start < (1 << 20)) + start = 1 << 20; +#ifdef CONFIG_X86_32 + /* + * The map is sorted, so bail once we hit a region + * that's above max_low_pfn. + */ + if (start >= max_low_pfn << PAGE_SHIFT) + break; + + if (end > max_low_pfn << PAGE_SHIFT) + end = max_low_pfn << PAGE_SHIFT; +#endif + switch (entry->type) { + case E820_RAM: + case E820_RESERVED_EFI: + case E820_ACPI: + case E820_NVS: + last_pfn_mapped = __init_memory_mapping(start, end); + break; + default: + continue; + } + + if (end <= max_low_pfn << PAGE_SHIFT) + max_low_pfn_mapped = last_pfn_mapped; + } + + return last_pfn_mapped; +} /* * devmem_is_allowed() checks to see if /dev/mem access to a certain address diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 436a030..e86e370 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -659,7 +659,7 @@ int arch_add_memory(int nid, u64 start, u64 size) unsigned long nr_pages = size >> PAGE_SHIFT; int ret; - last_mapped_pfn = init_memory_mapping(start, start + size); + last_mapped_pfn = __init_memory_mapping(start, start + size); if (last_mapped_pfn > max_pfn_mapped) max_pfn_mapped = last_mapped_pfn; diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 264cc6e..ef0a725 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -573,8 +573,7 @@ void __init efi_init(void) printk(KERN_WARNING "Kernel-defined memdesc doesn't match the one from EFI!\n"); - if (add_efi_memmap) - do_add_efi_memmap(); + do_add_efi_memmap(); #ifdef CONFIG_X86_32 x86_platform.get_wallclock = efi_get_time;