diff --git a/UPDATING b/UPDATING --- a/UPDATING +++ b/UPDATING @@ -27,6 +27,11 @@ world, or to merely disable the most expensive debugging functionality at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20230506: + Enable vnet sysctl variables be loader tunable. SYSCTLs which belong to + VNETs can be initialized during early boot if thay are marked with CTLFLAG_TUN + and there are corresponding kernel environment variables. + 20230422: Remove portsnap(8). Users are encouraged to obtain the ports tree using git instead. diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -473,6 +473,9 @@ } modules = !TAILQ_EMPTY(&lf->modules); linker_file_register_sysctls(lf, false); +#ifdef VIMAGE + LINKER_PROPAGATE_VNETS(lf); +#endif linker_file_sysinit(lf); lf->flags |= LINKER_FILE_LINKED; diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -512,9 +512,6 @@ RB_INSERT(sysctl_oid_list, parent, oidp); if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE && -#ifdef VIMAGE - (oidp->oid_kind & CTLFLAG_VNET) == 0 && -#endif (oidp->oid_kind & CTLFLAG_TUN) != 0 && (oidp->oid_kind & CTLFLAG_NOFETCH) == 0) { /* only fetch value once */ diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c --- a/sys/kern/link_elf.c +++ b/sys/kern/link_elf.c @@ -161,6 +161,9 @@ static void link_elf_reloc_local(linker_file_t); static long link_elf_symtab_get(linker_file_t, const Elf_Sym **); static long link_elf_strtab_get(linker_file_t, caddr_t *); +#ifdef VIMAGE +static void link_elf_propagate_vnets(linker_file_t); +#endif static int elf_lookup(linker_file_t, Elf_Size, int, Elf_Addr *); static kobj_method_t link_elf_methods[] = { @@ -179,6 +182,9 @@ KOBJMETHOD(linker_ctf_get, link_elf_ctf_get), KOBJMETHOD(linker_symtab_get, link_elf_symtab_get), KOBJMETHOD(linker_strtab_get, link_elf_strtab_get), +#ifdef VIMAGE + KOBJMETHOD(linker_propagate_vnets, link_elf_propagate_vnets), +#endif KOBJMETHOD_END }; @@ -719,6 +725,7 @@ ef->vnet_start = 0; ef->vnet_stop = 0; + ef->vnet_base = 0; error = link_elf_lookup_set(&ef->lf, "vnet", (void ***)&ef->vnet_start, (void ***)&ef->vnet_stop, NULL); /* Error just means there is no vnet data set to relocate. */ @@ -761,7 +768,6 @@ return (ENOSPC); } memcpy((void *)ef->vnet_base, (void *)ef->vnet_start, size); - vnet_data_copy((void *)ef->vnet_base, size); elf_set_add(&set_vnet_list, ef->vnet_start, ef->vnet_stop, ef->vnet_base); @@ -1920,6 +1926,21 @@ return (ef->ddbstrcnt); } +#ifdef VIMAGE +static void +link_elf_propagate_vnets(linker_file_t lf) +{ + elf_file_t ef = (elf_file_t)lf; + int size; + + if (ef->vnet_base != 0) { + size = (uintptr_t)ef->vnet_stop - (uintptr_t)ef->vnet_start; + KASSERT(size > 0, ("Invalid size")); + vnet_data_copy((void *)ef->vnet_base, size); + } +} +#endif + #if defined(__i386__) || defined(__amd64__) || defined(__aarch64__) || defined(__powerpc__) /* * Use this lookup routine when performing relocations early during boot. diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -152,6 +152,9 @@ static int link_elf_reloc_local(linker_file_t, bool); static long link_elf_symtab_get(linker_file_t, const Elf_Sym **); static long link_elf_strtab_get(linker_file_t, caddr_t *); +#ifdef VIMAGE +static void link_elf_propagate_vnets(linker_file_t); +#endif static int elf_obj_lookup(linker_file_t lf, Elf_Size symidx, int deps, Elf_Addr *); @@ -172,6 +175,9 @@ KOBJMETHOD(linker_ctf_get, link_elf_ctf_get), KOBJMETHOD(linker_symtab_get, link_elf_symtab_get), KOBJMETHOD(linker_strtab_get, link_elf_strtab_get), +#ifdef VIMAGE + KOBJMETHOD(linker_propagate_vnets, link_elf_propagate_vnets), +#endif KOBJMETHOD_END }; @@ -542,7 +548,6 @@ } memcpy(vnet_data, ef->progtab[pb].addr, ef->progtab[pb].size); - vnet_data_copy(vnet_data, shdr[i].sh_size); ef->progtab[pb].addr = vnet_data; #endif } else if ((ef->progtab[pb].name != NULL && @@ -1109,18 +1114,11 @@ error = EINVAL; goto out; } - /* Initialize the per-cpu or vnet area. */ + /* Initialize the per-cpu area. */ if (ef->progtab[pb].addr != (void *)mapbase && !strcmp(ef->progtab[pb].name, DPCPU_SETNAME)) dpcpu_copy(ef->progtab[pb].addr, shdr[i].sh_size); -#ifdef VIMAGE - else if (ef->progtab[pb].addr != - (void *)mapbase && - !strcmp(ef->progtab[pb].name, VNET_SETNAME)) - vnet_data_copy(ef->progtab[pb].addr, - shdr[i].sh_size); -#endif } else bzero(ef->progtab[pb].addr, shdr[i].sh_size); @@ -1850,7 +1848,7 @@ return (0); return (ef->ddbsymcnt); } - + static long link_elf_strtab_get(linker_file_t lf, caddr_t *strtab) { @@ -1861,3 +1859,25 @@ return (0); return (ef->ddbstrcnt); } + +#ifdef VIMAGE +static void +link_elf_propagate_vnets(linker_file_t lf) +{ + elf_file_t ef = (elf_file_t) lf; + + if (ef->progtab) { + for (int i = 0; i < ef->nprogtab; i++) { + if (ef->progtab[i].size == 0) + continue; + if (ef->progtab[i].name == NULL) + continue; + if (strcmp(ef->progtab[i].name, VNET_SETNAME) == 0) { + vnet_data_copy(ef->progtab[i].addr, + ef->progtab[i].size); + break; + } + } + } +} +#endif diff --git a/sys/kern/linker_if.m b/sys/kern/linker_if.m --- a/sys/kern/linker_if.m +++ b/sys/kern/linker_if.m @@ -155,3 +155,12 @@ METHOD int link_preload_finish { linker_file_t file; }; + +#ifdef VIMAGE +# +# Propagate system tunable values to all vnets. +# +METHOD void propagate_vnets { + linker_file_t file; +}; +#endif