Lines Matching +full:master +full:- +full:kernel
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2004-2009 University of Zagreb
5 * Copyright (c) 2006-2009 FreeBSD Foundation
44 #include <sys/kernel.h>
67 /*-
70 * - Virtual network stack management functions.
72 * - Virtual network stack memory allocator, which virtualizes global
75 * - Virtualized SYSINIT's/SYSUNINIT's, which allow network stack subsystems
80 FEATURE(vimage, "VIMAGE kernel virtualization");
85 * The virtual network stack list has two read-write locks, one sleepable and
112 * virtualization-agnostic.
114 * The virtual network stack allocator handles variables in the base kernel
117 * vnet linker set. These "master" copies of global variables serve two
123 * to zero-filled.
127 * will be used to calculate the location of a per-virtual instance
128 * variable at run-time.
132 * referred to by vnet->vnet_data_mem. Critical to the design is that each
133 * per-instance memory block is laid out identically to the master block so
135 * optimize run-time access, a precalculated 'base' address,
136 * vnet->vnet_data_base, is stored in each vnet, and is the amount that can
137 * be added to the address of a 'master' instance of a variable to get to the
138 * per-vnet instance.
142 * virtualized globals togther, we reserve space in the kernel's linker set
143 * for potential module variables using a per-vnet character array,
146 * linked, allocates portions of the space to specific globals. The kernel
151 * existing virtual network stack instances so that the soon-to-be executing
157 * size of all kernel virtualized global variables, and the malloc(9) type
160 #define VNET_BYTES (VNET_STOP - VNET_START)
167 * array declared as a virtualized global variable in the kernel itself, and
168 * we want the virtualized global variable space to be page-sized, we may
181 * Space to store virtualized global variables from loadable kernel modules,
232 * Run per-vnet sysinits or sysuninits during vnet creation/destruction.
251 vnet->vnet_magic_n = VNET_MAGIC_N; in vnet_alloc()
256 * initial values from our 'master' copy. in vnet_alloc()
258 vnet->vnet_data_mem = malloc(VNET_SIZE, M_VNET_DATA, M_WAITOK); in vnet_alloc()
259 memcpy(vnet->vnet_data_mem, (void *)VNET_START, VNET_BYTES); in vnet_alloc()
262 * All use of vnet-specific data will immediately subtract VNET_START in vnet_alloc()
263 * from the base memory pointer, so pre-calculate that now to avoid in vnet_alloc()
266 vnet->vnet_data_base = (uintptr_t)vnet->vnet_data_mem - VNET_START; in vnet_alloc()
289 KASSERT(vnet->vnet_sockcnt == 0, in vnet_destroy()
297 vnet->vnet_shutdown = true; in vnet_destroy()
308 free(vnet->vnet_data_mem, M_VNET_DATA); in vnet_destroy()
309 vnet->vnet_data_mem = NULL; in vnet_destroy()
310 vnet->vnet_data_base = 0; in vnet_destroy()
311 vnet->vnet_magic_n = 0xdeadbeef; in vnet_destroy()
364 df->vnd_start = (uintptr_t)&VNET_NAME(modspace); in vnet_data_startup()
365 df->vnd_len = VNET_MODMIN; in vnet_data_startup()
385 * should be used only by the kernel linker.
397 if (df->vnd_len < size) in vnet_data_alloc()
399 if (df->vnd_len == size) { in vnet_data_alloc()
400 s = (void *)df->vnd_start; in vnet_data_alloc()
405 s = (void *)df->vnd_start; in vnet_data_alloc()
406 df->vnd_len -= size; in vnet_data_alloc()
407 df->vnd_start = df->vnd_start + size; in vnet_data_alloc()
412 KASSERT(((uintptr_t)s & (VNET_DATAALIGN - 1)) == 0, in vnet_data_alloc()
437 if (df->vnd_start > end) in vnet_data_free()
443 if (df->vnd_start + df->vnd_len == start) { in vnet_data_free()
444 df->vnd_len += size; in vnet_data_free()
446 if (df->vnd_start + df->vnd_len == dn->vnd_start) { in vnet_data_free()
447 df->vnd_len += dn->vnd_len; in vnet_data_free()
455 if (df->vnd_start == end) { in vnet_data_free()
456 df->vnd_start = start; in vnet_data_free()
457 df->vnd_len += size; in vnet_data_free()
463 dn->vnd_start = start; in vnet_data_free()
464 dn->vnd_len = size; in vnet_data_free()
474 * initial value to each already-allocated virtual network stack instance.
483 memcpy((void *)((uintptr_t)vnet->vnet_data_base + in vnet_data_copy()
497 memcpy((void *)(vnet_init_var + ((uintptr_t)start - VNET_START)), in vnet_save_init()
502 * Restore the 'master' copies of virtualized global variables to theirs
512 (void *)(vnet_init_var + ((uintptr_t)start - VNET_START)), size); in vnet_restore_init()
526 KASSERT(vs->subsystem > SI_SUB_VNET, ("vnet sysinit too early")); in vnet_register_sysinit()
531 if (vs2->subsystem > vs->subsystem) in vnet_register_sysinit()
533 if (vs2->subsystem == vs->subsystem && vs2->order > vs->order) in vnet_register_sysinit()
548 vs->func(vs->arg); in vnet_register_sysinit()
578 if (vs2->subsystem > vs->subsystem) in vnet_register_sysuninit()
580 if (vs2->subsystem == vs->subsystem && vs2->order > vs->order) in vnet_register_sysuninit()
606 vs->func(vs->arg); in vnet_deregister_sysuninit()
628 curvnet->vnet_state = vs->subsystem; in vnet_sysinit()
629 vs->func(vs->arg); in vnet_sysinit()
647 curvnet->vnet_state = vs->subsystem; in vnet_sysuninit()
648 vs->func(vs->arg); in vnet_sysuninit()
673 * possible in here so just re-using the variadic version we in vnet_global_eventhandler_iterator_func()
680 ((vimage_iterator_func_t)v_ee->func)(v_ee->ee_arg); in vnet_global_eventhandler_iterator_func()
705 printf("%s() line %d, prev in %s()", vnr->where_fn, vnr->where_line, in vnet_print_recursion()
706 vnr->prev_fn); in vnet_print_recursion()
711 printf("%p -> %p\n", vnr->old_vnet, vnr->new_vnet); in vnet_print_recursion()
721 if (vnr->prev_fn == old_fn && in vnet_log_recursion()
722 vnr->where_fn == curthread->td_vnet_lpush && in vnet_log_recursion()
723 vnr->where_line == line && in vnet_log_recursion()
724 (vnr->old_vnet == vnr->new_vnet) == (curvnet == old_vnet)) in vnet_log_recursion()
730 vnr->prev_fn = old_fn; in vnet_log_recursion()
731 vnr->where_fn = curthread->td_vnet_lpush; in vnet_log_recursion()
732 vnr->where_line = line; in vnet_log_recursion()
733 vnr->old_vnet = old_vnet; in vnet_log_recursion()
734 vnr->new_vnet = curvnet; in vnet_log_recursion()
755 vnet->vnet_magic_n, in db_vnet_print()
756 (vnet->vnet_magic_n == VNET_MAGIC_N) ? in db_vnet_print()
758 db_printf(" vnet_ifcnt = %u\n", vnet->vnet_ifcnt); in db_vnet_print()
759 db_printf(" vnet_sockcnt = %u\n", vnet->vnet_sockcnt); in db_vnet_print()
760 db_printf(" vnet_data_mem = %p\n", vnet->vnet_data_mem); in db_vnet_print()
762 (uintmax_t)vnet->vnet_data_base); in db_vnet_print()
763 db_printf(" vnet_state = %#08x\n", vnet->vnet_state); in db_vnet_print()
764 db_printf(" vnet_shutdown = %#03x\n", vnet->vnet_shutdown); in db_vnet_print()
811 sym = db_search_symbol((vm_offset_t)vs->func, DB_STGY_PROC, &offset); in db_show_vnet_print_vs()
814 xprint(" %#08x %#08x\n", vs->subsystem, vs->order); in db_show_vnet_print_vs()
816 vs->func, (funcname != NULL) ? funcname : "", vs->arg); in db_show_vnet_print_vs()