/* * These are the four main kernel memory regions, we put them into * the resource tree so that kdump tools and other debugging tools * recover it:
*/
if (ramdisk_size == 0)
ramdisk_size = phys_initrd_size;
return ramdisk_size;
}
staticvoid __init relocate_initrd(void)
{ /* Assume only end is not page aligned */
u64 ramdisk_image = get_ramdisk_image();
u64 ramdisk_size = get_ramdisk_size();
u64 area_size = PAGE_ALIGN(ramdisk_size); int ret = 0;
/* We need to move the initrd down into directly mapped mem */
u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
PFN_PHYS(max_pfn_mapped)); if (!relocated_ramdisk)
panic("Cannot find place for new RAMDISK of size %lld\n",
ramdisk_size);
switch (data_type) { case SETUP_E820_EXT:
e820__memory_setup_extended(pa_data, data_len); break; case SETUP_DTB:
add_dtb(pa_data); break; case SETUP_EFI:
parse_efi_setup(pa_data, data_len); break; case SETUP_IMA:
add_early_ima_buffer(pa_data); break; case SETUP_KEXEC_KHO:
add_kho(pa_data, data_len); break; case SETUP_RNG_SEED:
data = early_memremap(pa_data, data_len);
add_bootloader_randomness(data->data, data->len); /* Zero seed for forward secrecy. */
memzero_explicit(data->data, data->len); /* Zero length in case we find ourselves back here by accident. */
memzero_explicit(&data->len, sizeof(data->len));
early_memunmap(data, data_len); break; default: break;
}
pa_data = pa_next;
}
}
if (data->type == SETUP_INDIRECT) {
len += data->len;
early_memunmap(data, sizeof(*data));
data = early_memremap(pa_data, len); if (!data) {
pr_warn("setup: failed to memremap indirect setup_data\n"); return;
}
indirect = (struct setup_indirect *)data->data;
if (indirect->type != SETUP_INDIRECT)
memblock_reserve_kern(indirect->addr, indirect->len);
}
pa_data = pa_next;
early_memunmap(data, len);
}
}
staticvoid __init arch_reserve_crashkernel(void)
{ unsignedlonglong crash_base, crash_size, low_size = 0, cma_size = 0; bool high = false; int ret;
if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) return;
ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
&crash_size, &crash_base,
&low_size, &cma_size, &high); if (ret) return;
if (xen_pv_domain()) {
pr_info("Ignoring crashkernel for a Xen PV domain\n"); return;
}
void __init reserve_standard_io_resources(void)
{ int i;
/* request I/O space for devices used on all i[345]86 PCs */ for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
request_resource(&ioport_resource, &standard_io_resources[i]);
/* * SandyBridge integrated graphics devices have a bug that prevents * them from accessing certain memory ranges, namely anything below * 1M and in the pages listed in bad_pages[] above. * * To avoid these pages being ever accessed by SNB gfx devices reserve * bad_pages that have not already been reserved at boot time. * All memory below the 1 MB mark is anyway reserved later during * setup_arch(), so there is no need to reserve it here.
*/
for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { if (memblock_reserve(bad_pages[i], PAGE_SIZE))
printk(KERN_WARNING "failed to reserve 0x%08lx\n",
bad_pages[i]);
}
}
staticvoid __init trim_bios_range(void)
{ /* * A special case is the first 4Kb of memory; * This is a BIOS owned area, not kernel ram, but generally * not listed as such in the E820 table. * * This typically reserves additional memory (64KiB by default) * since some BIOSes are known to corrupt low memory. See the * Kconfig help text for X86_RESERVE_LOW.
*/
e820__range_update(0, PAGE_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
/* * special case: Some BIOSes report the PC BIOS * area (640Kb -> 1Mb) as RAM even though it is not. * take them out.
*/
e820__range_remove(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_TYPE_RAM, 1);
e820__update_table(e820_table);
}
/* called before trim_bios_range() to spare extra sanitize */ staticvoid __init e820_add_kernel_range(void)
{
u64 start = __pa_symbol(_text);
u64 size = __pa_symbol(_end) - start;
/* * Complain if .text .data and .bss are not marked as E820_TYPE_RAM and * attempt to fix it by adding the range. We may have a confused BIOS, * or the user may have used memmap=exactmap or memmap=xxM$yyM to * exclude kernel range. If we really are running on top non-RAM, * we will crash later anyways.
*/ if (e820__mapped_all(start, start + size, E820_TYPE_RAM)) return;
pr_warn(".text .data .bss are not marked as E820_TYPE_RAM!\n");
e820__range_remove(start, size, E820_TYPE_RAM, 0);
e820__range_add(start, size, E820_TYPE_RAM);
}
staticvoid __init early_reserve_memory(void)
{ /* * Reserve the memory occupied by the kernel between _text and * __end_of_kernel_reserve symbols. Any kernel sections after the * __end_of_kernel_reserve symbol must be explicitly reserved with a * separate memblock_reserve() or they will be discarded.
*/
memblock_reserve_kern(__pa_symbol(_text),
(unsignedlong)__end_of_kernel_reserve - (unsignedlong)_text);
/* * The first 4Kb of memory is a BIOS owned area, but generally it is * not listed as such in the E820 table. * * Reserve the first 64K of memory since some BIOSes are known to * corrupt low memory. After the real mode trampoline is allocated the * rest of the memory below 640k is reserved. * * In addition, make sure page 0 is always reserved because on * systems with L1TF its contents can be leaked to user processes.
*/
memblock_reserve(0, SZ_64K);
early_reserve_initrd();
memblock_x86_reserve_range_setup_data();
reserve_bios_regions();
trim_snb_memory();
}
/* * Dump out kernel offset information on panic.
*/ staticint
dump_kernel_offset(struct notifier_block *self, unsignedlong v, void *p)
{ if (kaslr_enabled()) {
pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
kaslr_offset(),
__START_KERNEL,
__START_KERNEL_map,
MODULES_VADDR-1);
} else {
pr_emerg("Kernel Offset: disabled\n");
}
/* * Determine if we were loaded by an EFI loader. If so, then we have also been * passed the efi memmap, systab, etc., so we should use these data structures * for initialization. Note, the efi init code path is determined by the * global efi_enabled. This allows the same kernel image to be used on existing * systems (with a traditional BIOS) as well as on EFI systems.
*/ /* * setup_arch - architecture-specific boot-time initializations * * Note: On x86_64, fixmaps are ready for use even before this is called.
*/
/* * copy kernel address range established so far and switch * to the proper swapper page table
*/
clone_pgd_range(swapper_pg_dir + KERNEL_PGD_BOUNDARY,
initial_page_table + KERNEL_PGD_BOUNDARY,
KERNEL_PGD_PTRS);
load_cr3(swapper_pg_dir); /* * Note: Quark X1000 CPUs advertise PGE incorrectly and require * a cr3 based tlb flush, so the following __flush_tlb_all() * will not flush anything because the CPU quirk which clears * X86_FEATURE_PGE has not been invoked yet. Though due to the * load_cr3() above the TLB has been flushed already. The * quirk is invoked before subsequent calls to __flush_tlb_all() * so proper operation is guaranteed.
*/
__flush_tlb_all(); #else
printk(KERN_INFO "Command line: %s\n", boot_command_line);
boot_cpu_data.x86_phys_bits = MAX_PHYSMEM_BITS; #endif
/* * If we have OLPC OFW, we might end up relocating the fixmap due to * reserve_top(), so do this before touching the ioremap area.
*/
olpc_ofw_detect();
/* * Do some memory reservations *before* memory is added to memblock, so * memblock allocations won't overwrite it. * * After this point, everything still needed from the boot loader or * firmware or kernel text should be early reserved or marked not RAM in * e820. All other memory is free game. * * This call needs to happen before e820__memory_setup() which calls the * xen_memory_setup() on Xen dom0 which relies on the fact that those * early reservations have happened already.
*/
early_reserve_memory();
/* * x86_configure_nx() is called before parse_early_param() to detect * whether hardware doesn't support NX (so that the early EHCI debug * console setup can safely call set_fixmap()).
*/
x86_configure_nx();
parse_early_param();
if (efi_enabled(EFI_BOOT))
efi_memblock_x86_reserve_range();
/* * VMware detection requires dmi to be available, so this * needs to be done after dmi_setup(), for the boot CPU. * For some guest types (Xen PV, SEV-SNP, TDX) it is required to be * called before cache_bp_init() for setting up MTRR state.
*/
init_hypervisor_platform();
/* * Add resources for kernel text and data to the iomem_resource. * Do it after parse_early_param, so it can be debugged.
*/
setup_kernel_resources();
/* * partially used pages are not usable - thus * we are rounding upwards:
*/
max_pfn = e820__end_of_ram_pfn();
/* update e820 for memory not covered by WB MTRRs */
cache_bp_init(); if (mtrr_trim_uncached_memory(max_pfn))
max_pfn = e820__end_of_ram_pfn();
max_possible_pfn = max_pfn;
/* * Define random base addresses for memory sections after max_pfn is * defined and before each memory section base is used.
*/
kernel_randomize_memory();
#ifdef CONFIG_X86_32 /* max_low_pfn get updated here */
find_low_pfn_range(); #else
check_x2apic();
/* How many end-of-memory variables you have, grandma! */ /* need this before calling reserve_initrd */ if (max_pfn > (1UL<<(32 - PAGE_SHIFT)))
max_low_pfn = e820__end_of_low_ram_pfn(); else
max_low_pfn = max_pfn; #endif
/* Find and reserve MPTABLE area */
x86_init.mpparse.find_mptable();
early_alloc_pgt_buf();
/* * Need to conclude brk, before e820__memblock_setup() * it could use memblock_find_in_range, could overlap with * brk area.
*/
reserve_brk();
cleanup_highmap();
e820__memblock_setup();
/* * Needs to run after memblock setup because it needs the physical * memory size.
*/
mem_encrypt_setup_arch();
cc_random_init();
/* * The EFI specification says that boot service code won't be * called after ExitBootServices(). This is, in fact, a lie.
*/
efi_reserve_boot_services();
/* preallocate 4k for mptable mpc */
e820__memblock_alloc_reserved_mpc_new();
/* * Find free memory for the real mode trampoline and place it there. If * there is not enough free memory under 1M, on EFI-enabled systems * there will be additional attempt to reclaim the memory for the real * mode trampoline at efi_free_boot_services(). * * Unconditionally reserve the entire first 1M of RAM because BIOSes * are known to corrupt low memory and several hundred kilobytes are not * worth complex detection what memory gets clobbered. Windows does the * same thing for very similar reasons. * * Moreover, on machines with SandyBridge graphics or in setups that use * crashkernel the entire 1M is reserved anyway. * * Note the host kernel TDX also requires the first 1MB being reserved.
*/
x86_platform.realmode_reserve();
init_mem_mapping();
/* * init_mem_mapping() relies on the early IDT page fault handling. * Now either enable FRED or install the real page fault handler * for 64-bit in the IDT.
*/
cpu_init_replace_early_idt();
/* * Update mmu_cr4_features (and, indirectly, trampoline_cr4_features) * with the current CR4 value. This may not be necessary, but * auditing all the early-boot CR4 manipulation would be needed to * rule it out. * * Mask off features that don't work outside long mode (just * PCIDE for now).
*/
mmu_cr4_features = __read_cr4() & ~X86_CR4_PCIDE;
memblock_set_current_limit(get_max_mapped());
/* * NOTE: On x86-32, only from this point on, fixmaps are ready for use.
*/
if (efi_enabled(EFI_BOOT)) { switch (boot_params.secure_boot) { case efi_secureboot_mode_disabled:
pr_info("Secure boot disabled\n"); break; case efi_secureboot_mode_enabled:
pr_info("Secure boot enabled\n"); break; default:
pr_info("Secure boot could not be determined\n"); break;
}
}
reserve_initrd();
acpi_table_upgrade(); /* Look for ACPI tables and reserve memory occupied by them. */
acpi_boot_table_init();
vsmp_init();
io_delay_init();
early_platform_quirks();
/* Some platforms need the APIC registered for NUMA configuration */
early_acpi_boot_init();
x86_init.mpparse.early_parse_smp_cfg();
/* * This needs to run before setup_local_APIC() which soft-disables the * local APIC temporarily and that masks the thermal LVT interrupt, * leading to softlockups on machines which have configured SMI * interrupt delivery.
*/
therm_lvt_init();
mcheck_init();
register_refined_jiffies(CLOCK_TICK_RATE);
#ifdef CONFIG_EFI if (efi_enabled(EFI_BOOT))
efi_apply_memmap_quirks(); #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.