3e8fa263a9
Calling __pa() with an ioremap'd address is invalid. If we encounter an efi_memory_desc_t without EFI_MEMORY_WB set in ->attribute we currently call set_memory_uc(), which in turn calls __pa() on a potentially ioremap'd address. On CONFIG_X86_32 this results in the following oops: BUG: unable to handle kernel paging request at f7f22280 IP: [<c10257b9>] reserve_ram_pages_type+0x89/0x210 *pdpt = 0000000001978001 *pde = 0000000001ffb067 *pte = 0000000000000000 Oops: 0000 [#1] PREEMPT SMP Modules linked in: Pid: 0, comm: swapper Not tainted 3.0.0-acpi-efi-0805 #3 EIP: 0060:[<c10257b9>] EFLAGS: 00010202 CPU: 0 EIP is at reserve_ram_pages_type+0x89/0x210 EAX: 0070e280 EBX: 38714000 ECX: f7814000 EDX: 00000000 ESI: 00000000 EDI: 38715000 EBP: c189fef0 ESP: c189fea8 DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 Process swapper (pid: 0, ti=c189e000 task=c18bbe60 task.ti=c189e000) Stack: 80000200 ff108000 00000000 c189ff00 00038714 00000000 00000000 c189fed0 c104f8ca 00038714 00000000 00038715 00000000 00000000 00038715 00000000 00000010 38715000 c189ff48 c1025aff 38715000 00000000 00000010 00000000 Call Trace: [<c104f8ca>] ? page_is_ram+0x1a/0x40 [<c1025aff>] reserve_memtype+0xdf/0x2f0 [<c1024dc9>] set_memory_uc+0x49/0xa0 [<c19334d0>] efi_enter_virtual_mode+0x1c2/0x3aa [<c19216d4>] start_kernel+0x291/0x2f2 [<c19211c7>] ? loglevel+0x1b/0x1b [<c19210bf>] i386_start_kernel+0xbf/0xc8 The only time we can call set_memory_uc() for a memory region is when it is part of the direct kernel mapping. For the case where we ioremap a memory region we must leave it alone. This patch reimplements the fix frome8c7106280
("x86, efi: Calling __pa() with an ioremap()ed address is invalid") which was reverted ine1ad783b12
because it caused a regression on some MacBooks (they hung at boot). The regression was caused because the commit only marked EFI_RUNTIME_SERVICES_DATA as E820_RESERVED_EFI, when it should have marked all regions that have the EFI_MEMORY_RUNTIME attribute. Despite first impressions, it's not possible to use ioremap_cache() to map all cached memory regions on CONFIG_X86_64 because of the way that the memory map might be configured as detailed in the following bug report, https://bugzilla.redhat.com/show_bug.cgi?id=748516 e.g. some of the EFI memory regions *need* to be mapped as part of the direct kernel mapping. Signed-off-by: Matt Fleming <matt.fleming@intel.com> Cc: Matthew Garrett <mjg@redhat.com> Cc: Zhang Rui <rui.zhang@intel.com> Cc: Huang Ying <huang.ying.caritas@gmail.com> Cc: Keith Packard <keithp@keithp.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/r/1350649546-23541-1-git-send-email-matt@console-pimps.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
/*
|
|
* x86_64 specific EFI support functions
|
|
* Based on Extensible Firmware Interface Specification version 1.0
|
|
*
|
|
* Copyright (C) 2005-2008 Intel Co.
|
|
* Fenghua Yu <fenghua.yu@intel.com>
|
|
* Bibo Mao <bibo.mao@intel.com>
|
|
* Chandramouli Narayanan <mouli@linux.intel.com>
|
|
* Huang Ying <ying.huang@intel.com>
|
|
*
|
|
* Code to convert EFI to E820 map has been implemented in elilo bootloader
|
|
* based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table
|
|
* is setup appropriately for EFI runtime code.
|
|
* - mouli 06/14/2007.
|
|
*
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/types.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/bootmem.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/module.h>
|
|
#include <linux/efi.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/io.h>
|
|
#include <linux/reboot.h>
|
|
|
|
#include <asm/setup.h>
|
|
#include <asm/page.h>
|
|
#include <asm/e820.h>
|
|
#include <asm/pgtable.h>
|
|
#include <asm/tlbflush.h>
|
|
#include <asm/proto.h>
|
|
#include <asm/efi.h>
|
|
#include <asm/cacheflush.h>
|
|
#include <asm/fixmap.h>
|
|
|
|
static pgd_t save_pgd __initdata;
|
|
static unsigned long efi_flags __initdata;
|
|
|
|
static void __init early_code_mapping_set_exec(int executable)
|
|
{
|
|
efi_memory_desc_t *md;
|
|
void *p;
|
|
|
|
if (!(__supported_pte_mask & _PAGE_NX))
|
|
return;
|
|
|
|
/* Make EFI service code area executable */
|
|
for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
|
|
md = p;
|
|
if (md->type == EFI_RUNTIME_SERVICES_CODE ||
|
|
md->type == EFI_BOOT_SERVICES_CODE)
|
|
efi_set_executable(md, executable);
|
|
}
|
|
}
|
|
|
|
void __init efi_call_phys_prelog(void)
|
|
{
|
|
unsigned long vaddress;
|
|
|
|
early_code_mapping_set_exec(1);
|
|
local_irq_save(efi_flags);
|
|
vaddress = (unsigned long)__va(0x0UL);
|
|
save_pgd = *pgd_offset_k(0x0UL);
|
|
set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
|
|
__flush_tlb_all();
|
|
}
|
|
|
|
void __init efi_call_phys_epilog(void)
|
|
{
|
|
/*
|
|
* After the lock is released, the original page table is restored.
|
|
*/
|
|
set_pgd(pgd_offset_k(0x0UL), save_pgd);
|
|
__flush_tlb_all();
|
|
local_irq_restore(efi_flags);
|
|
early_code_mapping_set_exec(0);
|
|
}
|
|
|
|
void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
|
|
u32 type, u64 attribute)
|
|
{
|
|
unsigned long last_map_pfn;
|
|
|
|
if (type == EFI_MEMORY_MAPPED_IO)
|
|
return ioremap(phys_addr, size);
|
|
|
|
last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
|
|
if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size) {
|
|
unsigned long top = last_map_pfn << PAGE_SHIFT;
|
|
efi_ioremap(top, size - (top - phys_addr), type, attribute);
|
|
}
|
|
|
|
if (!(attribute & EFI_MEMORY_WB))
|
|
efi_memory_uc((u64)(unsigned long)__va(phys_addr), size);
|
|
|
|
return (void __iomem *)__va(phys_addr);
|
|
}
|