Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2009-08-01 19:26:27 +00:00
|
|
|
* Copyright (c) 2006-2009 University of Zagreb
|
|
|
|
* Copyright (c) 2006-2009 FreeBSD Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the University of Zagreb and the
|
|
|
|
* FreeBSD Foundation under sponsorship by the Stichting NLnet and the
|
|
|
|
* FreeBSD Foundation.
|
|
|
|
*
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
* Copyright (c) 2009 Jeffrey Roberson <jeff@freebsd.org>
|
|
|
|
* Copyright (c) 2009 Robert N. M. Watson
|
2009-07-15 00:56:15 +00:00
|
|
|
* All rights reserved.
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-07-15 00:56:15 +00:00
|
|
|
*
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2009-07-30 12:41:19 +00:00
|
|
|
/*-
|
|
|
|
* This header file defines several sets of interfaces supporting virtualized
|
|
|
|
* network stacks:
|
|
|
|
*
|
2009-08-01 19:26:27 +00:00
|
|
|
* - Definition of 'struct vnet' and functions and macros to allocate/free/
|
|
|
|
* manipulate it.
|
|
|
|
*
|
2009-07-30 12:41:19 +00:00
|
|
|
* - A virtual network stack memory allocator, which provides support for
|
|
|
|
* virtualized global variables via a special linker set, set_vnet.
|
|
|
|
*
|
|
|
|
* - Virtualized sysinits/sysuninits, which allow constructors and
|
|
|
|
* destructors to be run for each network stack subsystem as virtual
|
|
|
|
* instances are created and destroyed.
|
|
|
|
*
|
|
|
|
* If VIMAGE isn't compiled into the kernel, virtualized global variables
|
|
|
|
* compile to normal global variables, and virtualized sysinits to regular
|
|
|
|
* sysinits.
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
*/
|
|
|
|
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
#ifndef _NET_VNET_H_
|
2009-05-23 21:43:44 +00:00
|
|
|
#define _NET_VNET_H_
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
2009-07-30 12:41:19 +00:00
|
|
|
/*
|
2009-08-01 19:26:27 +00:00
|
|
|
* struct vnet describes a virtualized network stack, and is primarily a
|
|
|
|
* pointer to storage for virtualized global variables. Expose to userspace
|
|
|
|
* as required for libkvm.
|
2009-07-30 12:41:19 +00:00
|
|
|
*/
|
2009-07-20 07:50:50 +00:00
|
|
|
#if defined(_KERNEL) || defined(_WANT_VNET)
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
struct vnet {
|
|
|
|
LIST_ENTRY(vnet) vnet_le; /* all vnets list */
|
|
|
|
u_int vnet_magic_n;
|
|
|
|
u_int vnet_ifcnt;
|
|
|
|
u_int vnet_sockcnt;
|
2020-02-17 11:08:50 +00:00
|
|
|
u_int vnet_state; /* SI_SUB_* */
|
2009-08-01 19:26:27 +00:00
|
|
|
void *vnet_data_mem;
|
|
|
|
uintptr_t vnet_data_base;
|
2020-02-17 11:08:50 +00:00
|
|
|
bool vnet_shutdown; /* Shutdown in progress. */
|
|
|
|
} __aligned(CACHE_LINE_SIZE);
|
|
|
|
#define VNET_MAGIC_N 0x5e4a6f28
|
2009-08-01 19:26:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These two virtual network stack allocator definitions are also required
|
|
|
|
* for libkvm so that it can evaluate virtualized global variables.
|
|
|
|
*/
|
2009-07-20 07:50:50 +00:00
|
|
|
#define VNET_SETNAME "set_vnet"
|
|
|
|
#define VNET_SYMPREFIX "vnet_entry_"
|
|
|
|
#endif
|
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#ifdef _KERNEL
|
2009-08-01 19:26:27 +00:00
|
|
|
|
2013-07-09 09:37:21 +00:00
|
|
|
#define VNET_PCPUSTAT_DECLARE(type, name) \
|
|
|
|
VNET_DECLARE(counter_u64_t, name[sizeof(type) / sizeof(uint64_t)])
|
|
|
|
|
|
|
|
#define VNET_PCPUSTAT_DEFINE(type, name) \
|
|
|
|
VNET_DEFINE(counter_u64_t, name[sizeof(type) / sizeof(uint64_t)])
|
2018-07-24 16:31:16 +00:00
|
|
|
#define VNET_PCPUSTAT_DEFINE_STATIC(type, name) \
|
|
|
|
VNET_DEFINE_STATIC(counter_u64_t, name[sizeof(type) / sizeof(uint64_t)])
|
2013-07-09 09:37:21 +00:00
|
|
|
|
|
|
|
#define VNET_PCPUSTAT_ALLOC(name, wait) \
|
|
|
|
COUNTER_ARRAY_ALLOC(VNET(name), \
|
|
|
|
sizeof(VNET(name)) / sizeof(counter_u64_t), (wait))
|
|
|
|
|
|
|
|
#define VNET_PCPUSTAT_FREE(name) \
|
|
|
|
COUNTER_ARRAY_FREE(VNET(name), sizeof(VNET(name)) / sizeof(counter_u64_t))
|
|
|
|
|
|
|
|
#define VNET_PCPUSTAT_ADD(type, name, f, v) \
|
|
|
|
counter_u64_add(VNET(name)[offsetof(type, f) / sizeof(uint64_t)], (v))
|
|
|
|
|
2016-01-27 00:20:07 +00:00
|
|
|
#define VNET_PCPUSTAT_FETCH(type, name, f) \
|
|
|
|
counter_u64_fetch(VNET(name)[offsetof(type, f) / sizeof(uint64_t)])
|
|
|
|
|
2013-07-09 09:37:21 +00:00
|
|
|
#define VNET_PCPUSTAT_SYSINIT(name) \
|
|
|
|
static void \
|
|
|
|
vnet_##name##_init(const void *unused) \
|
|
|
|
{ \
|
|
|
|
VNET_PCPUSTAT_ALLOC(name, M_WAITOK); \
|
|
|
|
} \
|
Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.
Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.
Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.
For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.
Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.
For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).
Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.
Approved by: re (hrs)
Obtained from: projects/vnet
Reviewed by: gnn, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
|
|
|
VNET_SYSINIT(vnet_ ## name ## _init, SI_SUB_INIT_IF, \
|
|
|
|
SI_ORDER_FIRST, vnet_ ## name ## _init, NULL)
|
2013-07-09 09:37:21 +00:00
|
|
|
|
|
|
|
#define VNET_PCPUSTAT_SYSUNINIT(name) \
|
|
|
|
static void \
|
|
|
|
vnet_##name##_uninit(const void *unused) \
|
|
|
|
{ \
|
|
|
|
VNET_PCPUSTAT_FREE(name); \
|
|
|
|
} \
|
Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.
Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.
Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.
For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.
Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.
For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).
Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.
Approved by: re (hrs)
Obtained from: projects/vnet
Reviewed by: gnn, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
|
|
|
VNET_SYSUNINIT(vnet_ ## name ## _uninit, SI_SUB_INIT_IF, \
|
|
|
|
SI_ORDER_FIRST, vnet_ ## name ## _uninit, NULL)
|
2013-07-09 09:37:21 +00:00
|
|
|
|
2014-11-07 09:39:05 +00:00
|
|
|
#ifdef SYSCTL_OID
|
2013-07-09 09:37:21 +00:00
|
|
|
#define SYSCTL_VNET_PCPUSTAT(parent, nbr, name, type, array, desc) \
|
|
|
|
static int \
|
|
|
|
array##_sysctl(SYSCTL_HANDLER_ARGS) \
|
|
|
|
{ \
|
|
|
|
type s; \
|
2013-07-09 15:10:27 +00:00
|
|
|
CTASSERT((sizeof(type) / sizeof(uint64_t)) == \
|
|
|
|
(sizeof(VNET(array)) / sizeof(counter_u64_t))); \
|
2013-07-09 09:37:21 +00:00
|
|
|
COUNTER_ARRAY_COPY(VNET(array), &s, sizeof(type) / sizeof(uint64_t));\
|
|
|
|
if (req->newptr) \
|
|
|
|
COUNTER_ARRAY_ZERO(VNET(array), \
|
|
|
|
sizeof(type) / sizeof(uint64_t)); \
|
|
|
|
return (SYSCTL_OUT(req, &s, sizeof(type))); \
|
|
|
|
} \
|
2020-02-26 14:26:36 +00:00
|
|
|
SYSCTL_PROC(parent, nbr, name, \
|
|
|
|
CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT, \
|
2014-11-07 09:39:05 +00:00
|
|
|
NULL, 0, array ## _sysctl, "I", desc)
|
|
|
|
#endif /* SYSCTL_OID */
|
2013-07-09 09:37:21 +00:00
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#ifdef VIMAGE
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/proc.h> /* for struct thread */
|
|
|
|
#include <sys/rwlock.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
|
2010-04-14 23:06:07 +00:00
|
|
|
/*
|
|
|
|
* Location of the kernel's 'set_vnet' linker set.
|
|
|
|
*/
|
|
|
|
extern uintptr_t *__start_set_vnet;
|
2010-11-22 19:32:54 +00:00
|
|
|
__GLOBL(__start_set_vnet);
|
2010-04-14 23:06:07 +00:00
|
|
|
extern uintptr_t *__stop_set_vnet;
|
2010-11-22 19:32:54 +00:00
|
|
|
__GLOBL(__stop_set_vnet);
|
2010-04-14 23:06:07 +00:00
|
|
|
|
|
|
|
#define VNET_START (uintptr_t)&__start_set_vnet
|
|
|
|
#define VNET_STOP (uintptr_t)&__stop_set_vnet
|
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
/*
|
|
|
|
* Functions to allocate and destroy virtual network stacks.
|
|
|
|
*/
|
|
|
|
struct vnet *vnet_alloc(void);
|
|
|
|
void vnet_destroy(struct vnet *vnet);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The current virtual network stack -- we may wish to move this to struct
|
|
|
|
* pcpu in the future.
|
|
|
|
*/
|
|
|
|
#define curvnet curthread->td_vnet
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various macros -- get and set the current network stack, but also
|
|
|
|
* assertions.
|
|
|
|
*/
|
2011-02-11 13:27:00 +00:00
|
|
|
#if defined(INVARIANTS) || defined(VNET_DEBUG)
|
|
|
|
#define VNET_ASSERT(exp, msg) do { \
|
|
|
|
if (!(exp)) \
|
|
|
|
panic msg; \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define VNET_ASSERT(exp, msg) do { \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
#ifdef VNET_DEBUG
|
2010-02-04 07:55:42 +00:00
|
|
|
void vnet_log_recursion(struct vnet *, const char *, int);
|
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
#define CURVNET_SET_QUIET(arg) \
|
2011-02-11 13:27:00 +00:00
|
|
|
VNET_ASSERT((arg) != NULL && (arg)->vnet_magic_n == VNET_MAGIC_N, \
|
|
|
|
("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p", \
|
|
|
|
__FILE__, __LINE__, __func__, curvnet, (arg))); \
|
2009-08-01 19:26:27 +00:00
|
|
|
struct vnet *saved_vnet = curvnet; \
|
|
|
|
const char *saved_vnet_lpush = curthread->td_vnet_lpush; \
|
|
|
|
curvnet = arg; \
|
2011-02-11 12:56:05 +00:00
|
|
|
curthread->td_vnet_lpush = __func__;
|
2009-08-01 19:26:27 +00:00
|
|
|
|
|
|
|
#define CURVNET_SET_VERBOSE(arg) \
|
|
|
|
CURVNET_SET_QUIET(arg) \
|
|
|
|
if (saved_vnet) \
|
2010-02-04 07:55:42 +00:00
|
|
|
vnet_log_recursion(saved_vnet, saved_vnet_lpush, __LINE__);
|
2009-08-01 19:26:27 +00:00
|
|
|
|
|
|
|
#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
|
|
|
|
|
|
|
|
#define CURVNET_RESTORE() \
|
2011-02-11 13:27:00 +00:00
|
|
|
VNET_ASSERT(curvnet != NULL && (saved_vnet == NULL || \
|
|
|
|
saved_vnet->vnet_magic_n == VNET_MAGIC_N), \
|
|
|
|
("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p", \
|
|
|
|
__FILE__, __LINE__, __func__, curvnet, saved_vnet)); \
|
2009-08-01 19:26:27 +00:00
|
|
|
curvnet = saved_vnet; \
|
|
|
|
curthread->td_vnet_lpush = saved_vnet_lpush;
|
|
|
|
#else /* !VNET_DEBUG */
|
|
|
|
|
2011-02-11 14:17:58 +00:00
|
|
|
#define CURVNET_SET_QUIET(arg) \
|
|
|
|
VNET_ASSERT((arg) != NULL && (arg)->vnet_magic_n == VNET_MAGIC_N, \
|
|
|
|
("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p", \
|
|
|
|
__FILE__, __LINE__, __func__, curvnet, (arg))); \
|
2009-08-01 19:26:27 +00:00
|
|
|
struct vnet *saved_vnet = curvnet; \
|
|
|
|
curvnet = arg;
|
|
|
|
|
2011-02-11 14:17:58 +00:00
|
|
|
#define CURVNET_SET_VERBOSE(arg) \
|
|
|
|
CURVNET_SET_QUIET(arg)
|
|
|
|
|
|
|
|
#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
|
2009-08-01 19:26:27 +00:00
|
|
|
|
|
|
|
#define CURVNET_RESTORE() \
|
2011-02-11 14:17:58 +00:00
|
|
|
VNET_ASSERT(curvnet != NULL && (saved_vnet == NULL || \
|
|
|
|
saved_vnet->vnet_magic_n == VNET_MAGIC_N), \
|
|
|
|
("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p", \
|
|
|
|
__FILE__, __LINE__, __func__, curvnet, saved_vnet)); \
|
2009-08-01 19:26:27 +00:00
|
|
|
curvnet = saved_vnet;
|
|
|
|
#endif /* VNET_DEBUG */
|
|
|
|
|
|
|
|
extern struct vnet *vnet0;
|
|
|
|
#define IS_DEFAULT_VNET(arg) ((arg) == vnet0)
|
|
|
|
|
|
|
|
#define CRED_TO_VNET(cr) (cr)->cr_prison->pr_vnet
|
|
|
|
#define TD_TO_VNET(td) CRED_TO_VNET((td)->td_ucred)
|
|
|
|
#define P_TO_VNET(p) CRED_TO_VNET((p)->p_ucred)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global linked list of all virtual network stacks, along with read locks to
|
|
|
|
* access it. If a caller may sleep while accessing the list, it must use
|
|
|
|
* the sleepable lock macros.
|
|
|
|
*/
|
|
|
|
LIST_HEAD(vnet_list_head, vnet);
|
|
|
|
extern struct vnet_list_head vnet_head;
|
|
|
|
extern struct rwlock vnet_rwlock;
|
|
|
|
extern struct sx vnet_sxlock;
|
|
|
|
|
|
|
|
#define VNET_LIST_RLOCK() sx_slock(&vnet_sxlock)
|
|
|
|
#define VNET_LIST_RLOCK_NOSLEEP() rw_rlock(&vnet_rwlock)
|
|
|
|
#define VNET_LIST_RUNLOCK() sx_sunlock(&vnet_sxlock)
|
|
|
|
#define VNET_LIST_RUNLOCK_NOSLEEP() rw_runlock(&vnet_rwlock)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iteration macros to walk the global list of virtual network stacks.
|
|
|
|
*/
|
|
|
|
#define VNET_ITERATOR_DECL(arg) struct vnet *arg
|
|
|
|
#define VNET_FOREACH(arg) LIST_FOREACH((arg), &vnet_head, vnet_le)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Virtual network stack memory allocator, which allows global variables to
|
|
|
|
* be automatically instantiated for each network stack instance.
|
|
|
|
*/
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#define VNET_NAME(n) vnet_entry_##n
|
|
|
|
#define VNET_DECLARE(t, n) extern t VNET_NAME(n)
|
2018-07-30 12:44:44 +00:00
|
|
|
/* struct _hack is to stop this from being used with static data */
|
2018-07-24 16:31:16 +00:00
|
|
|
#define VNET_DEFINE(t, n) \
|
2018-07-30 12:44:44 +00:00
|
|
|
struct _hack; t VNET_NAME(n) __section(VNET_SETNAME) __used
|
2019-06-25 17:15:44 +00:00
|
|
|
#if defined(KLD_MODULE) && (defined(__aarch64__) || defined(__riscv) \
|
|
|
|
|| defined(__powerpc64__))
|
2018-07-30 15:05:07 +00:00
|
|
|
/*
|
|
|
|
* As with DPCPU_DEFINE_STATIC we are unable to mark this data as static
|
|
|
|
* in modules on some architectures.
|
|
|
|
*/
|
|
|
|
#define VNET_DEFINE_STATIC(t, n) \
|
|
|
|
t VNET_NAME(n) __section(VNET_SETNAME) __used
|
|
|
|
#else
|
2018-07-24 16:31:16 +00:00
|
|
|
#define VNET_DEFINE_STATIC(t, n) \
|
|
|
|
static t VNET_NAME(n) __section(VNET_SETNAME) __used
|
2018-07-30 15:05:07 +00:00
|
|
|
#endif
|
2010-11-22 19:32:54 +00:00
|
|
|
#define _VNET_PTR(b, n) (__typeof(VNET_NAME(n))*) \
|
|
|
|
((b) + (uintptr_t)&VNET_NAME(n))
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
|
2009-07-16 21:13:04 +00:00
|
|
|
#define _VNET(b, n) (*_VNET_PTR(b, n))
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
/*
|
|
|
|
* Virtualized global variable accessor macros.
|
|
|
|
*/
|
|
|
|
#define VNET_VNET_PTR(vnet, n) _VNET_PTR((vnet)->vnet_data_base, n)
|
2009-07-16 21:13:04 +00:00
|
|
|
#define VNET_VNET(vnet, n) (*VNET_VNET_PTR((vnet), n))
|
2009-06-29 19:46:29 +00:00
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#define VNET_PTR(n) VNET_VNET_PTR(curvnet, n)
|
2009-07-16 21:13:04 +00:00
|
|
|
#define VNET(n) VNET_VNET(curvnet, n)
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
2009-07-30 12:41:19 +00:00
|
|
|
/*
|
|
|
|
* Virtual network stack allocator interfaces from the kernel linker.
|
|
|
|
*/
|
|
|
|
void *vnet_data_alloc(int size);
|
|
|
|
void vnet_data_copy(void *start, int size);
|
|
|
|
void vnet_data_free(void *start_arg, int size);
|
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
/*
|
2009-07-30 12:41:19 +00:00
|
|
|
* Virtual sysinit mechanism, allowing network stack components to declare
|
|
|
|
* startup and shutdown methods to be run when virtual network stack
|
|
|
|
* instances are created and destroyed.
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
*/
|
2009-07-30 12:41:19 +00:00
|
|
|
#include <sys/kernel.h>
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
/*
|
2009-07-30 12:41:19 +00:00
|
|
|
* SYSINIT/SYSUNINIT variants that provide per-vnet constructors and
|
|
|
|
* destructors.
|
|
|
|
*/
|
|
|
|
struct vnet_sysinit {
|
|
|
|
enum sysinit_sub_id subsystem;
|
|
|
|
enum sysinit_elem_order order;
|
|
|
|
sysinit_cfunc_t func;
|
|
|
|
const void *arg;
|
|
|
|
TAILQ_ENTRY(vnet_sysinit) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VNET_SYSINIT(ident, subsystem, order, func, arg) \
|
2019-10-07 14:24:59 +00:00
|
|
|
CTASSERT((subsystem) > SI_SUB_VNET && \
|
|
|
|
(subsystem) <= SI_SUB_VNET_DONE); \
|
2009-07-30 12:41:19 +00:00
|
|
|
static struct vnet_sysinit ident ## _vnet_init = { \
|
|
|
|
subsystem, \
|
|
|
|
order, \
|
|
|
|
(sysinit_cfunc_t)(sysinit_nfunc_t)func, \
|
|
|
|
(arg) \
|
|
|
|
}; \
|
|
|
|
SYSINIT(vnet_init_ ## ident, subsystem, order, \
|
|
|
|
vnet_register_sysinit, &ident ## _vnet_init); \
|
|
|
|
SYSUNINIT(vnet_init_ ## ident, subsystem, order, \
|
|
|
|
vnet_deregister_sysinit, &ident ## _vnet_init)
|
|
|
|
|
|
|
|
#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \
|
2019-10-07 14:24:59 +00:00
|
|
|
CTASSERT((subsystem) > SI_SUB_VNET && \
|
|
|
|
(subsystem) <= SI_SUB_VNET_DONE); \
|
2009-07-30 12:41:19 +00:00
|
|
|
static struct vnet_sysinit ident ## _vnet_uninit = { \
|
|
|
|
subsystem, \
|
|
|
|
order, \
|
|
|
|
(sysinit_cfunc_t)(sysinit_nfunc_t)func, \
|
|
|
|
(arg) \
|
|
|
|
}; \
|
|
|
|
SYSINIT(vnet_uninit_ ## ident, subsystem, order, \
|
|
|
|
vnet_register_sysuninit, &ident ## _vnet_uninit); \
|
|
|
|
SYSUNINIT(vnet_uninit_ ## ident, subsystem, order, \
|
|
|
|
vnet_deregister_sysuninit, &ident ## _vnet_uninit)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run per-vnet sysinits or sysuninits during vnet creation/destruction.
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
*/
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
void vnet_sysinit(void);
|
|
|
|
void vnet_sysuninit(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interfaces for managing per-vnet constructors and destructors.
|
|
|
|
*/
|
|
|
|
void vnet_register_sysinit(void *arg);
|
|
|
|
void vnet_register_sysuninit(void *arg);
|
|
|
|
void vnet_deregister_sysinit(void *arg);
|
|
|
|
void vnet_deregister_sysuninit(void *arg);
|
2009-05-23 21:43:44 +00:00
|
|
|
|
2010-03-19 19:51:03 +00:00
|
|
|
/*
|
|
|
|
* EVENTHANDLER(9) extensions.
|
|
|
|
*/
|
|
|
|
#include <sys/eventhandler.h>
|
|
|
|
|
|
|
|
void vnet_global_eventhandler_iterator_func(void *, ...);
|
|
|
|
#define VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG(tag, name, func, arg, priority) \
|
|
|
|
do { \
|
|
|
|
if (IS_DEFAULT_VNET(curvnet)) { \
|
|
|
|
(tag) = vimage_eventhandler_register(NULL, #name, func, \
|
|
|
|
arg, priority, \
|
|
|
|
vnet_global_eventhandler_iterator_func); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#define VNET_GLOBAL_EVENTHANDLER_REGISTER(name, func, arg, priority) \
|
|
|
|
do { \
|
|
|
|
if (IS_DEFAULT_VNET(curvnet)) { \
|
|
|
|
vimage_eventhandler_register(NULL, #name, func, \
|
|
|
|
arg, priority, \
|
|
|
|
vnet_global_eventhandler_iterator_func); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#else /* !VIMAGE */
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
/*
|
|
|
|
* Various virtual network stack macros compile to no-ops without VIMAGE.
|
|
|
|
*/
|
|
|
|
#define curvnet NULL
|
|
|
|
|
2011-02-11 13:27:00 +00:00
|
|
|
#define VNET_ASSERT(exp, msg)
|
2009-08-01 19:26:27 +00:00
|
|
|
#define CURVNET_SET(arg)
|
|
|
|
#define CURVNET_SET_QUIET(arg)
|
|
|
|
#define CURVNET_RESTORE()
|
|
|
|
|
|
|
|
#define VNET_LIST_RLOCK()
|
|
|
|
#define VNET_LIST_RLOCK_NOSLEEP()
|
|
|
|
#define VNET_LIST_RUNLOCK()
|
|
|
|
#define VNET_LIST_RUNLOCK_NOSLEEP()
|
|
|
|
#define VNET_ITERATOR_DECL(arg)
|
|
|
|
#define VNET_FOREACH(arg)
|
|
|
|
|
|
|
|
#define IS_DEFAULT_VNET(arg) 1
|
|
|
|
#define CRED_TO_VNET(cr) NULL
|
|
|
|
#define TD_TO_VNET(td) NULL
|
|
|
|
#define P_TO_VNET(p) NULL
|
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
/*
|
|
|
|
* Versions of the VNET macros that compile to normal global variables and
|
|
|
|
* standard sysctl definitions.
|
|
|
|
*/
|
2010-11-22 19:32:54 +00:00
|
|
|
#define VNET_NAME(n) n
|
|
|
|
#define VNET_DECLARE(t, n) extern t n
|
2018-07-24 16:31:16 +00:00
|
|
|
#define VNET_DEFINE(t, n) struct _hack; t n
|
|
|
|
#define VNET_DEFINE_STATIC(t, n) static t n
|
2010-11-22 19:32:54 +00:00
|
|
|
#define _VNET_PTR(b, n) &VNET_NAME(n)
|
2009-03-01 11:01:00 +00:00
|
|
|
|
2009-07-30 12:41:19 +00:00
|
|
|
/*
|
|
|
|
* Virtualized global variable accessor macros.
|
|
|
|
*/
|
|
|
|
#define VNET_VNET_PTR(vnet, n) (&(n))
|
|
|
|
#define VNET_VNET(vnet, n) (n)
|
|
|
|
|
|
|
|
#define VNET_PTR(n) (&(n))
|
|
|
|
#define VNET(n) (n)
|
|
|
|
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
/*
|
2009-07-30 12:41:19 +00:00
|
|
|
* When VIMAGE isn't compiled into the kernel, VNET_SYSINIT/VNET_SYSUNINIT
|
|
|
|
* map into normal sysinits, which have the same ordering properties.
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
*/
|
2009-07-30 12:41:19 +00:00
|
|
|
#define VNET_SYSINIT(ident, subsystem, order, func, arg) \
|
|
|
|
SYSINIT(ident, subsystem, order, func, arg)
|
|
|
|
#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \
|
|
|
|
SYSUNINIT(ident, subsystem, order, func, arg)
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
|
2010-03-19 19:51:03 +00:00
|
|
|
/*
|
|
|
|
* Without VIMAGE revert to the default implementation.
|
|
|
|
*/
|
|
|
|
#define VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG(tag, name, func, arg, priority) \
|
|
|
|
(tag) = eventhandler_register(NULL, #name, func, arg, priority)
|
|
|
|
#define VNET_GLOBAL_EVENTHANDLER_REGISTER(name, func, arg, priority) \
|
|
|
|
eventhandler_register(NULL, #name, func, arg, priority)
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
#endif /* VIMAGE */
|
|
|
|
#endif /* _KERNEL */
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
|
|
|
#endif /* !_NET_VNET_H_ */
|