mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-01-14 23:36:30 +07:00
b8f2c21db3
Update efi_call_phys_prelog to install an identity mapping of all available memory. This corrects a bug on very large systems with more then 512 GB in which bios would not be able to access addresses above not in the mapping. The result is a crash that looks much like this. BUG: unable to handle kernel paging request at 000000effd870020 IP: [<0000000078bce331>] 0x78bce330 PGD 0 Oops: 0000 [#1] SMP Modules linked in: CPU 0 Pid: 0, comm: swapper/0 Tainted: G W 3.8.0-rc1-next-20121224-medusa_ntz+ #2 Intel Corp. Stoutland Platform RIP: 0010:[<0000000078bce331>] [<0000000078bce331>] 0x78bce330 RSP: 0000:ffffffff81601d28 EFLAGS: 00010006 RAX: 0000000078b80e18 RBX: 0000000000000004 RCX: 0000000000000004 RDX: 0000000078bcf958 RSI: 0000000000002400 RDI: 8000000000000000 RBP: 0000000078bcf760 R08: 000000effd870000 R09: 0000000000000000 R10: 0000000000000000 R11: 00000000000000c3 R12: 0000000000000030 R13: 000000effd870000 R14: 0000000000000000 R15: ffff88effd870000 FS: 0000000000000000(0000) GS:ffff88effe400000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000effd870020 CR3: 000000000160c000 CR4: 00000000000006b0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process swapper/0 (pid: 0, threadinfo ffffffff81600000, task ffffffff81614400) Stack: 0000000078b80d18 0000000000000004 0000000078bced7b ffff880078b81fff 0000000000000000 0000000000000082 0000000078bce3a8 0000000000002400 0000000060000202 0000000078b80da0 0000000078bce45d ffffffff8107cb5a Call Trace: [<ffffffff8107cb5a>] ? on_each_cpu+0x77/0x83 [<ffffffff8102f4eb>] ? change_page_attr_set_clr+0x32f/0x3ed [<ffffffff81035946>] ? efi_call4+0x46/0x80 [<ffffffff816c5abb>] ? efi_enter_virtual_mode+0x1f5/0x305 [<ffffffff816aeb24>] ? start_kernel+0x34a/0x3d2 [<ffffffff816ae5ed>] ? repair_env_string+0x60/0x60 [<ffffffff816ae2be>] ? x86_64_start_reservations+0xba/0xc1 [<ffffffff816ae120>] ? early_idt_handlers+0x120/0x120 [<ffffffff816ae419>] ? x86_64_start_kernel+0x154/0x163 Code: Bad RIP value. RIP [<0000000078bce331>] 0x78bce330 RSP <ffffffff81601d28> CR2: 000000effd870020 ---[ end trace ead828934fef5eab ]--- Cc: stable@vger.kernel.org Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Nathan Zimmer <nzimmer@sgi.com> Signed-off-by: Robin Holt <holt@sgi.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
115 lines
3.0 KiB
C
115 lines
3.0 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;
|
|
int pgd;
|
|
int n_pgds;
|
|
|
|
early_code_mapping_set_exec(1);
|
|
local_irq_save(efi_flags);
|
|
|
|
n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
|
|
save_pgd = kmalloc(n_pgds * sizeof(pgd_t), GFP_KERNEL);
|
|
|
|
for (pgd = 0; pgd < n_pgds; pgd++) {
|
|
save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE);
|
|
vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
|
|
set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *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.
|
|
*/
|
|
int pgd;
|
|
int n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT) , PGDIR_SIZE);
|
|
for (pgd = 0; pgd < n_pgds; pgd++)
|
|
set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
|
|
kfree(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);
|
|
}
|