git: b72ae900d434 - main - sys: make the kernel metadata pointer global
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 24 Jan 2025 21:37:12 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=b72ae900d4348118829fe04abdc11b620930c30f commit b72ae900d4348118829fe04abdc11b620930c30f Author: Ahmad Khalifa <ahmadkhalifa570@gmail.com> AuthorDate: 2024-08-22 19:05:38 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2025-01-24 21:25:51 +0000 sys: make the kernel metadata pointer global The way we got the kernel metadata pointer was by calling preload_search_by_type with one of the following three: "elf kernel", "elf32 kernel" and "elf64 kernel". Which one(s) we used wasn't consistent though. Sometimes we would only try "elf kernel", and other times we would try one of the latter two if the first failed. However, the loader only ever sets "elf kernel" as the kernel type. Now, the kmdp is a global, preload_kmdp, and it's initialized using preload_initkmdp in machdep.c (or machdep_boot.c on arm/64). preload_initkmdp takes a single boolean argument that tells us whether not finding the kmdp is fatal or not. Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394 --- sys/amd64/amd64/machdep.c | 65 ++++++++++---------------- sys/arm/arm/machdep.c | 8 ++-- sys/arm/arm/machdep_boot.c | 20 ++++---- sys/arm64/arm64/machdep.c | 21 ++++----- sys/arm64/arm64/machdep_boot.c | 20 ++++---- sys/compat/linuxkpi/common/include/linux/efi.h | 8 +--- sys/dev/efidev/efirt.c | 6 +-- sys/dev/hyperv/vmbus/vmbus.c | 8 +--- sys/dev/nvdimm/nvdimm_e820.c | 6 +-- sys/dev/vt/hw/efifb/efifb.c | 12 +---- sys/dev/vt/hw/vbefb/vbefb.c | 12 +---- sys/dev/vt/vt_core.c | 18 ++----- sys/i386/i386/machdep.c | 20 +++----- sys/kern/link_elf.c | 24 ++++------ sys/kern/subr_module.c | 11 ++++- sys/opencrypto/crypto.c | 9 +--- sys/powerpc/powerpc/machdep.c | 55 +++++++++++----------- sys/riscv/riscv/machdep.c | 24 ++++------ sys/sys/linker.h | 5 +- sys/x86/include/init.h | 4 +- sys/x86/x86/fdt_machdep.c | 7 +-- sys/x86/x86/nexus.c | 8 +--- sys/x86/xen/hvm.c | 13 +----- sys/x86/xen/pv.c | 59 +++++++++-------------- 24 files changed, 169 insertions(+), 274 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 73bfdd4d07f5..6d9bc8b7c573 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -169,10 +169,10 @@ SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL); static void native_clock_source_init(void); /* Preload data parse function */ -static caddr_t native_parse_preload_data(u_int64_t); +static void native_parse_preload_data(u_int64_t); /* Native function to fetch and parse the e820 map */ -static void native_parse_memmap(caddr_t, vm_paddr_t *, int *); +static void native_parse_memmap(vm_paddr_t *, int *); /* Default init_ops implementation. */ struct init_ops init_ops = { @@ -814,7 +814,7 @@ add_efi_map_entries(struct efi_map_header *efihdr, vm_paddr_t *physmap, } static void -native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) +native_parse_memmap(vm_paddr_t *physmap, int *physmap_idx) { struct bios_smap *smap; struct efi_map_header *efihdr; @@ -828,9 +828,9 @@ native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) * ie: an int32_t immediately precedes smap. */ - efihdr = (struct efi_map_header *)preload_search_info(kmdp, + efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP); - smap = (struct bios_smap *)preload_search_info(kmdp, + smap = (struct bios_smap *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP); if (efihdr == NULL && smap == NULL) panic("No BIOS smap or EFI map info from loader!"); @@ -858,7 +858,7 @@ native_parse_memmap(caddr_t kmdp, vm_paddr_t *physmap, int *physmap_idx) * XXX first should be vm_paddr_t. */ static void -getmemsize(caddr_t kmdp, u_int64_t first) +getmemsize(u_int64_t first) { int i, physmap_idx, pa_indx, da_indx; vm_paddr_t pa, physmap[PHYS_AVAIL_ENTRIES]; @@ -877,7 +877,7 @@ getmemsize(caddr_t kmdp, u_int64_t first) bzero(physmap, sizeof(physmap)); physmap_idx = 0; - init_ops.parse_memmap(kmdp, physmap, &physmap_idx); + init_ops.parse_memmap(physmap, &physmap_idx); physmap_idx -= 2; /* @@ -1127,10 +1127,9 @@ do_next: TSEXIT(); } -static caddr_t +static void native_parse_preload_data(u_int64_t modulep) { - caddr_t kmdp; char *envp; #ifdef DDB vm_offset_t ksym_start; @@ -1139,22 +1138,19 @@ native_parse_preload_data(u_int64_t modulep) preload_metadata = (caddr_t)(uintptr_t)(modulep + KERNBASE); preload_bootstrap_relocate(KERNBASE); - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); - envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); + preload_initkmdp(true); + boothowto = MD_FETCH(preload_kmdp, MODINFOMD_HOWTO, int); + envp = MD_FETCH(preload_kmdp, MODINFOMD_ENVP, char *); if (envp != NULL) envp += KERNBASE; init_static_kenv(envp, 0); #ifdef DDB - ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t); - ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t); + ksym_start = MD_FETCH(preload_kmdp, MODINFOMD_SSYM, uintptr_t); + ksym_end = MD_FETCH(preload_kmdp, MODINFOMD_ESYM, uintptr_t); db_fetch_ksymtab(ksym_start, ksym_end, 0); #endif - efi_systbl_phys = MD_FETCH(kmdp, MODINFOMD_FW_HANDLE, vm_paddr_t); - - return (kmdp); + efi_systbl_phys = MD_FETCH(preload_kmdp, MODINFOMD_FW_HANDLE, + vm_paddr_t); } static void @@ -1287,7 +1283,6 @@ amd64_loadaddr(void) u_int64_t hammer_time(u_int64_t modulep, u_int64_t physfree) { - caddr_t kmdp; int gsel_tss, x; struct pcpu *pc; uint64_t rsp0; @@ -1302,9 +1297,10 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) physfree += kernphys; - kmdp = init_ops.parse_preload_data(modulep); + /* Initializes preload_kmdp */ + init_ops.parse_preload_data(modulep); - efi_boot = preload_search_info(kmdp, MODINFO_METADATA | + efi_boot = preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP) != NULL; if (!efi_boot) { @@ -1350,7 +1346,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave); } - link_elf_ireloc(kmdp); + link_elf_ireloc(); /* * This may be done better later if it gets more high level @@ -1535,7 +1531,7 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) amd64_kdb_init(); } - getmemsize(kmdp, physfree); + getmemsize(physfree); init_param2(physmem); /* now running on new page tables, configured,and u/iom is accessible */ @@ -1635,19 +1631,15 @@ smap_sysctl_handler(SYSCTL_HANDLER_ARGS) { struct bios_smap *smapbase; struct bios_smap_xattr smap; - caddr_t kmdp; uint32_t *smapattr; int count, error, i; /* Retrieve the system memory map from the loader. */ - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - smapbase = (struct bios_smap *)preload_search_info(kmdp, + smapbase = (struct bios_smap *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP); if (smapbase == NULL) return (0); - smapattr = (uint32_t *)preload_search_info(kmdp, + smapattr = (uint32_t *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP_XATTR); count = *((uint32_t *)smapbase - 1) / sizeof(*smapbase); error = 0; @@ -1672,13 +1664,9 @@ static int efi_map_sysctl_handler(SYSCTL_HANDLER_ARGS) { struct efi_map_header *efihdr; - caddr_t kmdp; uint32_t efisize; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - efihdr = (struct efi_map_header *)preload_search_info(kmdp, + efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP); if (efihdr == NULL) return (0); @@ -1694,13 +1682,8 @@ static int efi_arch_sysctl_handler(SYSCTL_HANDLER_ARGS) { char *arch; - caddr_t kmdp; - - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - arch = (char *)preload_search_info(kmdp, + arch = (char *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_ARCH); if (arch == NULL) return (0); diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index fdaf5d3dade8..e45ef9834e81 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -421,7 +421,6 @@ initarm(struct arm_boot_params *abp) vm_paddr_t lastaddr; vm_offset_t dtbp, kernelstack, dpcpu; char *env; - void *kmdp; int err_devmap, mem_regions_sz; phandle_t root; char dts_version[255]; @@ -439,8 +438,7 @@ initarm(struct arm_boot_params *abp) /* * Find the dtb passed in by the boot loader. */ - kmdp = preload_search_by_type("elf kernel"); - dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t); + dtbp = MD_FETCH(preload_kmdp, MODINFOMD_DTBP, vm_offset_t); #if defined(FDT_DTB_STATIC) /* * In case the device tree blob was not retrieved (from metadata) try @@ -461,7 +459,7 @@ initarm(struct arm_boot_params *abp) #endif #ifdef EFI - efihdr = (struct efi_map_header *)preload_search_info(kmdp, + efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP); if (efihdr != NULL) { arm_add_efi_map_entries(efihdr, mem_regions, &mem_regions_sz); @@ -571,7 +569,7 @@ initarm(struct arm_boot_params *abp) #endif debugf("initarm: console initialized\n"); - debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)kmdp); + debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)preload_kmdp); debugf(" boothowto = 0x%08x\n", boothowto); debugf(" dtbp = 0x%08x\n", (uint32_t)dtbp); debugf(" lastaddr1: 0x%08x\n", lastaddr); diff --git a/sys/arm/arm/machdep_boot.c b/sys/arm/arm/machdep_boot.c index 475da7b47ac8..534d34acabe2 100644 --- a/sys/arm/arm/machdep_boot.c +++ b/sys/arm/arm/machdep_boot.c @@ -270,7 +270,6 @@ freebsd_parse_boot_param(struct arm_boot_params *abp) { vm_offset_t lastaddr = 0; void *mdp; - void *kmdp; #ifdef DDB vm_offset_t ksym_start; vm_offset_t ksym_end; @@ -287,17 +286,19 @@ freebsd_parse_boot_param(struct arm_boot_params *abp) if ((mdp = (void *)(abp->abp_r0 & ~PAGE_MASK)) == NULL) return 0; preload_metadata = mdp; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) + + /* Initialize preload_kmdp */ + preload_initkmdp(false); + if (preload_kmdp == NULL) return 0; - boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); - loader_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); + boothowto = MD_FETCH(preload_kmdp, MODINFOMD_HOWTO, int); + loader_envp = MD_FETCH(preload_kmdp, MODINFOMD_ENVP, char *); init_static_kenv(loader_envp, 0); - lastaddr = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t); + lastaddr = MD_FETCH(preload_kmdp, MODINFOMD_KERNEND, vm_offset_t); #ifdef DDB - ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t); - ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t); + ksym_start = MD_FETCH(preload_kmdp, MODINFOMD_SSYM, uintptr_t); + ksym_end = MD_FETCH(preload_kmdp, MODINFOMD_ESYM, uintptr_t); db_fetch_ksymtab(ksym_start, ksym_end, 0); #endif return lastaddr; @@ -381,6 +382,9 @@ fake_preload_metadata(struct arm_boot_params *abp __unused, void *dtb_ptr, fake_preload[i] = 0; preload_metadata = (void *)fake_preload; + /* Initialize preload_kmdp */ + preload_initkmdp(true); + init_static_kenv(NULL, 0); return (lastaddr); diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index ff7a88edfe61..22c74b21cf48 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -734,11 +734,11 @@ exclude_efi_memreserve(vm_offset_t efi_systbl_phys) #ifdef FDT static void -try_load_dtb(caddr_t kmdp) +try_load_dtb(void) { vm_offset_t dtbp; - dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t); + dtbp = MD_FETCH(preload_kmdp, MODINFOMD_DTBP, vm_offset_t); #if defined(FDT_DTB_STATIC) /* * In case the device tree blob was not retrieved (from metadata) try @@ -900,7 +900,6 @@ initarm(struct arm64_bootparams *abp) char dts_version[255]; #endif vm_offset_t lastaddr; - caddr_t kmdp; bool valid; TSRAW(&thread0, TS_ENTER, __func__, NULL); @@ -910,11 +909,6 @@ initarm(struct arm64_bootparams *abp) /* Parse loader or FDT boot parameters. Determine last used address. */ lastaddr = parse_boot_param(abp); - /* Find the kernel address */ - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - identify_cpu(0); identify_hypervisor_smbios(); @@ -936,15 +930,16 @@ initarm(struct arm64_bootparams *abp) PCPU_SET(curthread, &thread0); PCPU_SET(midr, get_midr()); - link_elf_ireloc(kmdp); + link_elf_ireloc(); #ifdef FDT - try_load_dtb(kmdp); + try_load_dtb(); #endif - efi_systbl_phys = MD_FETCH(kmdp, MODINFOMD_FW_HANDLE, vm_paddr_t); + efi_systbl_phys = MD_FETCH(preload_kmdp, MODINFOMD_FW_HANDLE, + vm_paddr_t); /* Load the physical memory ranges */ - efihdr = (struct efi_map_header *)preload_search_info(kmdp, + efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP); if (efihdr != NULL) add_efi_map_entries(efihdr); @@ -962,7 +957,7 @@ initarm(struct arm64_bootparams *abp) #endif /* Exclude the EFI framebuffer from our view of physical memory. */ - efifb = (struct efi_fb *)preload_search_info(kmdp, + efifb = (struct efi_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_FB); if (efifb != NULL) physmem_exclude_region(efifb->fb_addr, efifb->fb_size, diff --git a/sys/arm64/arm64/machdep_boot.c b/sys/arm64/arm64/machdep_boot.c index b8e0c734bbb4..029ae23530ff 100644 --- a/sys/arm64/arm64/machdep_boot.c +++ b/sys/arm64/arm64/machdep_boot.c @@ -124,6 +124,9 @@ fake_preload_metadata(void *dtb_ptr, size_t dtb_size) preload_metadata = (caddr_t)(uintptr_t)fake_preload; + /* Initialize preload_kmdp */ + preload_initkmdp(true); + init_static_kenv(NULL, 0); return (lastaddr); @@ -188,7 +191,6 @@ static vm_offset_t freebsd_parse_boot_param(struct arm64_bootparams *abp) { vm_offset_t lastaddr = 0; - void *kmdp; #ifdef DDB vm_offset_t ksym_start; vm_offset_t ksym_end; @@ -198,17 +200,19 @@ freebsd_parse_boot_param(struct arm64_bootparams *abp) return (0); preload_metadata = (caddr_t)(uintptr_t)(abp->modulep); - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) + + /* Initialize preload_kmdp */ + preload_initkmdp(false); + if (preload_kmdp == NULL) return (0); - boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); - loader_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); + boothowto = MD_FETCH(preload_kmdp, MODINFOMD_HOWTO, int); + loader_envp = MD_FETCH(preload_kmdp, MODINFOMD_ENVP, char *); init_static_kenv(loader_envp, 0); - lastaddr = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t); + lastaddr = MD_FETCH(preload_kmdp, MODINFOMD_KERNEND, vm_offset_t); #ifdef DDB - ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t); - ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t); + ksym_start = MD_FETCH(preload_kmdp, MODINFOMD_SSYM, uintptr_t); + ksym_end = MD_FETCH(preload_kmdp, MODINFOMD_ESYM, uintptr_t); db_fetch_ksymtab(ksym_start, ksym_end, 0); #endif return (lastaddr); diff --git a/sys/compat/linuxkpi/common/include/linux/efi.h b/sys/compat/linuxkpi/common/include/linux/efi.h index a485b4b1fd94..aa33371bd0e8 100644 --- a/sys/compat/linuxkpi/common/include/linux/efi.h +++ b/sys/compat/linuxkpi/common/include/linux/efi.h @@ -41,9 +41,6 @@ static inline bool __efi_enabled(int feature) { -#if defined(MODINFOMD_EFI_MAP) && !defined(__amd64__) - caddr_t kmdp; -#endif bool enabled = false; switch (feature) { @@ -52,10 +49,7 @@ __efi_enabled(int feature) /* Use cached value on amd64 */ enabled = efi_boot; #elif defined(MODINFOMD_EFI_MAP) - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - enabled = preload_search_info(kmdp, + enabled = preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP) != NULL; #endif break; diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c index fcbed48af395..5dff2258725d 100644 --- a/sys/dev/efidev/efirt.c +++ b/sys/dev/efidev/efirt.c @@ -167,7 +167,6 @@ efi_init(void) struct efi_map_header *efihdr; struct efi_md *map; struct efi_rt *rtdm; - caddr_t kmdp; size_t efisz; int ndesc, rt_disabled; @@ -197,10 +196,7 @@ efi_init(void) printf("EFI config table is not present\n"); } - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - efihdr = (struct efi_map_header *)preload_search_info(kmdp, + efihdr = (struct efi_map_header *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_MAP); if (efihdr == NULL) { if (bootverbose) diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c index 1c620a1f5d84..115d4af599ee 100644 --- a/sys/dev/hyperv/vmbus/vmbus.c +++ b/sys/dev/hyperv/vmbus/vmbus.c @@ -1305,18 +1305,14 @@ vmbus_fb_mmio_res(device_t dev) #endif /* aarch64 */ rman_res_t fb_start, fb_end, fb_count; int fb_height, fb_width; - caddr_t kmdp; struct vmbus_softc *sc = device_get_softc(dev); int rid = 0; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - efifb = (struct efi_fb *)preload_search_info(kmdp, + efifb = (struct efi_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_FB); #if !defined(__aarch64__) - vbefb = (struct vbe_fb *)preload_search_info(kmdp, + vbefb = (struct vbe_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_VBE_FB); #endif /* aarch64 */ if (efifb != NULL) { diff --git a/sys/dev/nvdimm/nvdimm_e820.c b/sys/dev/nvdimm/nvdimm_e820.c index 2a6f29ebad21..6f9bb4c70f7a 100644 --- a/sys/dev/nvdimm/nvdimm_e820.c +++ b/sys/dev/nvdimm/nvdimm_e820.c @@ -257,7 +257,6 @@ static void nvdimm_e820_identify(driver_t *driver, device_t parent) { device_t child; - caddr_t kmdp; if (resource_disabled(driver->name, 0)) return; @@ -265,10 +264,7 @@ nvdimm_e820_identify(driver_t *driver, device_t parent) if (device_find_child(parent, driver->name, -1) != NULL) return; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - smapbase = (const void *)preload_search_info(kmdp, + smapbase = (const void *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP); /* Only supports BIOS SMAP for now. */ diff --git a/sys/dev/vt/hw/efifb/efifb.c b/sys/dev/vt/hw/efifb/efifb.c index cac6f93b7af1..eda05ec3d203 100644 --- a/sys/dev/vt/hw/efifb/efifb.c +++ b/sys/dev/vt/hw/efifb/efifb.c @@ -77,17 +77,13 @@ vt_efifb_probe(struct vt_device *vd) { int disabled; struct efi_fb *efifb; - caddr_t kmdp; disabled = 0; TUNABLE_INT_FETCH("hw.syscons.disable", &disabled); if (disabled != 0) return (CN_DEAD); - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - efifb = (struct efi_fb *)preload_search_info(kmdp, + efifb = (struct efi_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_FB); if (efifb == NULL) return (CN_DEAD); @@ -100,7 +96,6 @@ vt_efifb_init(struct vt_device *vd) { struct fb_info *info; struct efi_fb *efifb; - caddr_t kmdp; int memattr; int roff, goff, boff; char attr[16]; @@ -132,10 +127,7 @@ vt_efifb_init(struct vt_device *vd) if (info == NULL) info = vd->vd_softc = (void *)&local_info; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - efifb = (struct efi_fb *)preload_search_info(kmdp, + efifb = (struct efi_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_EFI_FB); if (efifb == NULL) return (CN_DEAD); diff --git a/sys/dev/vt/hw/vbefb/vbefb.c b/sys/dev/vt/hw/vbefb/vbefb.c index 2d6ada6002d0..0f9d9257948c 100644 --- a/sys/dev/vt/hw/vbefb/vbefb.c +++ b/sys/dev/vt/hw/vbefb/vbefb.c @@ -77,17 +77,13 @@ vt_vbefb_probe(struct vt_device *vd) { int disabled; struct vbe_fb *vbefb; - caddr_t kmdp; disabled = 0; TUNABLE_INT_FETCH("hw.syscons.disable", &disabled); if (disabled != 0) return (CN_DEAD); - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - vbefb = (struct vbe_fb *)preload_search_info(kmdp, + vbefb = (struct vbe_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_VBE_FB); if (vbefb == NULL) return (CN_DEAD); @@ -100,17 +96,13 @@ vt_vbefb_init(struct vt_device *vd) { struct fb_info *info; struct vbe_fb *vbefb; - caddr_t kmdp; int format, roff, goff, boff; info = vd->vd_softc; if (info == NULL) info = vd->vd_softc = (void *)&local_vbe_info; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - vbefb = (struct vbe_fb *)preload_search_info(kmdp, + vbefb = (struct vbe_fb *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_VBE_FB); if (vbefb == NULL) return (CN_DEAD); diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index 1be98466112e..b0f58b38a6f1 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -1675,15 +1675,11 @@ vtterm_done(struct terminal *tm) static void vtterm_splash(struct vt_device *vd) { - caddr_t kmdp; struct splash_info *si; uintptr_t image; vt_axis_t top, left; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - si = MD_FETCH(kmdp, MODINFOMD_SPLASH, struct splash_info *); + si = MD_FETCH(preload_kmdp, MODINFOMD_SPLASH, struct splash_info *); if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) { if (si == NULL) { top = (vd->vd_height - vt_logo_height) / 2; @@ -1806,14 +1802,10 @@ parse_font_info(struct font_info *fi) static void vt_init_font(void *arg) { - caddr_t kmdp; struct font_info *fi; struct vt_font *font; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - fi = MD_FETCH(kmdp, MODINFOMD_FONT, struct font_info *); + fi = MD_FETCH(preload_kmdp, MODINFOMD_FONT, struct font_info *); font = parse_font_info(fi); if (font != NULL) @@ -1825,14 +1817,10 @@ SYSINIT(vt_init_font, SI_SUB_KMEM, SI_ORDER_ANY, vt_init_font, &vt_consdev); static void vt_init_font_static(void) { - caddr_t kmdp; struct font_info *fi; struct vt_font *font; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - fi = MD_FETCH(kmdp, MODINFOMD_FONT, struct font_info *); + fi = MD_FETCH(preload_kmdp, MODINFOMD_FONT, struct font_info *); font = parse_font_info_static(fi); if (font != NULL) diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 008d67017f68..6aac0e968362 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -903,7 +903,6 @@ getmemsize(int first) struct vm86context vmc; vm_paddr_t pa; struct bios_smap *smap, *smapbase; - caddr_t kmdp; has_smap = 0; bzero(&vmf, sizeof(vmf)); @@ -924,10 +923,7 @@ getmemsize(int first) * use that and do not make any VM86 calls. */ physmap_idx = 0; - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf32 kernel"); - smapbase = (struct bios_smap *)preload_search_info(kmdp, + smapbase = (struct bios_smap *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP); if (smapbase != NULL) { add_smap_entries(smapbase, physmap, &physmap_idx); @@ -1388,7 +1384,6 @@ init386(int first) int gsel_tss, metadata_missing, x, pa; struct pcpu *pc; struct xstate_hdr *xhdr; - caddr_t kmdp; vm_offset_t addend; size_t ucode_len; @@ -1547,8 +1542,9 @@ init386(int first) TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave); } - kmdp = preload_search_by_type("elf kernel"); - link_elf_ireloc(kmdp); + /* Initialize preload_kmdp */ + preload_initkmdp(!metadata_missing); + link_elf_ireloc(); vm86_initialize(); getmemsize(first); @@ -1734,19 +1730,15 @@ smap_sysctl_handler(SYSCTL_HANDLER_ARGS) { struct bios_smap *smapbase; struct bios_smap_xattr smap; - caddr_t kmdp; uint32_t *smapattr; int count, error, i; /* Retrieve the system memory map from the loader. */ - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf32 kernel"); - smapbase = (struct bios_smap *)preload_search_info(kmdp, + smapbase = (struct bios_smap *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP); if (smapbase == NULL) return (0); - smapattr = (uint32_t *)preload_search_info(kmdp, + smapattr = (uint32_t *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_SMAP_XATTR); count = *((u_int32_t *)smapbase - 1) / sizeof(*smapbase); error = 0; diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c index 9f9c10456b60..23a924636ca2 100644 --- a/sys/kern/link_elf.c +++ b/sys/kern/link_elf.c @@ -450,18 +450,14 @@ link_elf_init(void* arg) Elf_Dyn *dp; Elf_Addr *ctors_addrp; Elf_Size *ctors_sizep; - caddr_t modptr, baseptr, sizeptr; + caddr_t baseptr, sizeptr; elf_file_t ef; const char *modname; linker_add_class(&link_elf_class); dp = (Elf_Dyn *)&_DYNAMIC; - modname = NULL; - modptr = preload_search_by_type("elf" __XSTRING(__ELF_WORD_SIZE) " kernel"); - if (modptr == NULL) - modptr = preload_search_by_type("elf kernel"); - modname = (char *)preload_search_info(modptr, MODINFO_NAME); + modname = (char *)preload_search_info(preload_kmdp, MODINFO_NAME); if (modname == NULL) modname = "kernel"; linker_kernel_file = linker_make_file(modname, &link_elf_class); @@ -493,17 +489,17 @@ link_elf_init(void* arg) linker_kernel_file->size = -(intptr_t)linker_kernel_file->address; #endif - if (modptr != NULL) { - ef->modptr = modptr; - baseptr = preload_search_info(modptr, MODINFO_ADDR); + if (preload_kmdp != NULL) { + ef->modptr = preload_kmdp; + baseptr = preload_search_info(preload_kmdp, MODINFO_ADDR); if (baseptr != NULL) linker_kernel_file->address = *(caddr_t *)baseptr; - sizeptr = preload_search_info(modptr, MODINFO_SIZE); + sizeptr = preload_search_info(preload_kmdp, MODINFO_SIZE); if (sizeptr != NULL) linker_kernel_file->size = *(size_t *)sizeptr; - ctors_addrp = (Elf_Addr *)preload_search_info(modptr, + ctors_addrp = (Elf_Addr *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_CTORS_ADDR); - ctors_sizep = (Elf_Size *)preload_search_info(modptr, + ctors_sizep = (Elf_Size *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_CTORS_SIZE); if (ctors_addrp != NULL && ctors_sizep != NULL) { linker_kernel_file->ctors_addr = ef->address + @@ -2016,7 +2012,7 @@ elf_lookup_ifunc(linker_file_t lf, Elf_Size symidx, int deps __unused, } void -link_elf_ireloc(caddr_t kmdp) +link_elf_ireloc(void) { struct elf_file eff; elf_file_t ef; @@ -2026,7 +2022,7 @@ link_elf_ireloc(caddr_t kmdp) bzero_early(ef, sizeof(*ef)); - ef->modptr = kmdp; + ef->modptr = preload_kmdp; ef->dynamic = (Elf_Dyn *)&_DYNAMIC; #ifdef RELOCATABLE_KERNEL diff --git a/sys/kern/subr_module.c b/sys/kern/subr_module.c index 7f56ed72e1ac..14272bd913f8 100644 --- a/sys/kern/subr_module.c +++ b/sys/kern/subr_module.c @@ -44,7 +44,16 @@ */ vm_offset_t preload_addr_relocate = 0; -caddr_t preload_metadata; +caddr_t preload_metadata, preload_kmdp; + +void +preload_initkmdp(bool fatal) +{ + preload_kmdp = preload_search_by_type("elf kernel"); + + if (preload_kmdp == NULL && fatal) + panic("unable to find kernel metadata"); +} /* * Search for the preloaded module (name) diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index e840d514fcd5..3c7299780a38 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -253,14 +253,7 @@ static struct keybuf empty_keybuf = { static void keybuf_init(void) { - caddr_t kmdp; - - kmdp = preload_search_by_type("elf kernel"); - - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - - keybuf = (struct keybuf *)preload_search_info(kmdp, + keybuf = (struct keybuf *)preload_search_info(preload_kmdp, MODINFO_METADATA | MODINFOMD_KEYBUF); if (keybuf == NULL) diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c index 899fb430e5d9..96f3b292854d 100644 --- a/sys/powerpc/powerpc/machdep.c +++ b/sys/powerpc/powerpc/machdep.c @@ -264,7 +264,6 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, struct cpuref bsp; vm_offset_t startkernel, endkernel; char *env; - void *kmdp = NULL; bool ofw_bootargs = false; #ifdef DDB bool symbols_provided = false; @@ -336,33 +335,34 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, preload_metadata += md_offset; preload_bootstrap_relocate(md_offset); } - kmdp = preload_search_by_type("elf kernel"); - if (kmdp != NULL) { - boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int); - envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); - if (envp != NULL) - envp += md_offset; - init_static_kenv(envp, 0); - if (fdt == 0) { - fdt = MD_FETCH(kmdp, MODINFOMD_DTBP, uintptr_t); - if (fdt != 0) - fdt += md_offset; - } - /* kernelstartphys is already relocated. */ - kernelendphys = MD_FETCH(kmdp, MODINFOMD_KERNEND, - vm_offset_t); - if (kernelendphys != 0) - kernelendphys += md_offset; - endkernel = ulmax(endkernel, kernelendphys); + + /* Initialize preload_kmdp */ + preload_initkmdp(true); + + boothowto = MD_FETCH(preload_kmdp, MODINFOMD_HOWTO, int); + envp = MD_FETCH(preload_kmdp, MODINFOMD_ENVP, char *); + if (envp != NULL) + envp += md_offset; + init_static_kenv(envp, 0); + if (fdt == 0) { + fdt = MD_FETCH(preload_kmdp, MODINFOMD_DTBP, uintptr_t); + if (fdt != 0) + fdt += md_offset; + } + /* kernelstartphys is already relocated. */ + kernelendphys = MD_FETCH(preload_kmdp, MODINFOMD_KERNEND, + vm_offset_t); + if (kernelendphys != 0) + kernelendphys += md_offset; + endkernel = ulmax(endkernel, kernelendphys); #ifdef DDB - ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t); - ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t); + ksym_start = MD_FETCH(preload_kmdp, MODINFOMD_SSYM, uintptr_t); + ksym_end = MD_FETCH(preload_kmdp, MODINFOMD_ESYM, uintptr_t); - db_fetch_ksymtab(ksym_start, ksym_end, md_offset); - /* Symbols provided by loader. */ - symbols_provided = true; + db_fetch_ksymtab(ksym_start, ksym_end, md_offset); + /* Symbols provided by loader. */ + symbols_provided = true; #endif - } } else { /* * Self-loading kernel, we have to fake up metadata. @@ -372,7 +372,8 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, * preload_boostrap_relocate(). */ fake_preload_metadata(); - kmdp = preload_search_by_type("elf kernel"); + /* Initialize preload_kmdp */ + preload_initkmdp(true); init_static_kenv(init_kenv, sizeof(init_kenv)); ofw_bootargs = true; } @@ -466,7 +467,7 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, * Bring up MMU */ pmap_mmu_init(); - link_elf_ireloc(kmdp); + link_elf_ireloc(); pmap_bootstrap(startkernel, endkernel); mtmsr(psl_kernset & ~PSL_EE); diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index c0d4b7cc2726..a17cff55f2cc 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -307,11 +307,11 @@ init_proc0(vm_offset_t kstack) #ifdef FDT static void -try_load_dtb(caddr_t kmdp) +try_load_dtb(void) { vm_offset_t dtbp; - dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t); + dtbp = MD_FETCH(preload_kmdp, MODINFOMD_DTBP, vm_offset_t); #if defined(FDT_DTB_STATIC) /* @@ -434,34 +434,30 @@ parse_fdt_bootargs(void) static vm_offset_t parse_metadata(void) { - caddr_t kmdp; vm_offset_t lastaddr; #ifdef DDB vm_offset_t ksym_start, ksym_end; #endif char *kern_envp; - /* Find the kernel address */ - kmdp = preload_search_by_type("elf kernel"); - if (kmdp == NULL) - kmdp = preload_search_by_type("elf64 kernel"); - KASSERT(kmdp != NULL, ("No preload metadata found!")); + /* Initialize preload_kmdp */ + preload_initkmdp(true); *** 306 LINES SKIPPED ***