diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-07-14 22:48:30 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-07-14 22:48:30 +0000 |
commit | 57ca4583e728cab422fba8f15de10bd0b637b3dd (patch) | |
tree | 13848f891fb2f7a396281b31633563d0f764ff65 /sys/net/route.c | |
parent | ef443476d9706035ac219f0280ef0b817dda7a6d (diff) | |
download | FreeBSD-src-57ca4583e728cab422fba8f15de10bd0b637b3dd.zip FreeBSD-src-57ca4583e728cab422fba8f15de10bd0b637b3dd.tar.gz |
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)
Diffstat (limited to 'sys/net/route.c')
-rw-r--r-- | sys/net/route.c | 70 |
1 files changed, 10 insertions, 60 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index 750829a..59a5912 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -63,7 +63,6 @@ #include <netinet/in.h> #include <netinet/ip_mroute.h> -#include <netinet/vinet.h> #include <vm/uma.h> @@ -88,68 +87,29 @@ SYSCTL_INT(_net, OID_AUTO, add_addr_allfibs, CTLFLAG_RW, &rt_add_addr_allfibs, 0, ""); TUNABLE_INT("net.add_addr_allfibs", &rt_add_addr_allfibs); -#ifdef VIMAGE_GLOBALS -struct radix_node_head *rt_tables; -static uma_zone_t rtzone; /* Routing table UMA zone. */ -int rttrash; /* routes not in table but not freed */ -struct rtstat rtstat; -#endif - -#ifndef VIMAGE_GLOBALS -struct vnet_rtable { - struct radix_node_head *_rt_tables; - uma_zone_t _rtzone; - int _rttrash; - struct rtstat _rtstat; -}; - -/* Size guard. See sys/vimage.h. */ -VIMAGE_CTASSERT(SIZEOF_vnet_rtable, sizeof(struct vnet_rtable)); - -#ifndef VIMAGE -static struct vnet_rtable vnet_rtable_0; -#endif -#endif - -/* - * Symbol translation macros - */ -#define INIT_VNET_RTABLE(vnet) \ - INIT_FROM_VNET(vnet, VNET_MOD_RTABLE, struct vnet_rtable, vnet_rtable) +VNET_DEFINE(struct radix_node_head *, rt_tables); +static VNET_DEFINE(uma_zone_t, rtzone); /* Routing table UMA zone. */ +VNET_DEFINE(int, rttrash); /* routes not in table but not freed */ +VNET_DEFINE(struct rtstat, rtstat); -#define VNET_RTABLE(sym) VSYM(vnet_rtable, sym) - -#define V_rt_tables VNET_RTABLE(rt_tables) -#define V_rtstat VNET_RTABLE(rtstat) -#define V_rttrash VNET_RTABLE(rttrash) -#define V_rtzone VNET_RTABLE(rtzone) +#define V_rt_tables VNET_GET(rt_tables) +#define V_rtzone VNET_GET(rtzone) +#define V_rttrash VNET_GET(rttrash) +#define V_rtstat VNET_GET(rtstat) static void rt_maskedcopy(struct sockaddr *, struct sockaddr *, struct sockaddr *); static int vnet_route_iattach(const void *); #ifdef VIMAGE static int vnet_route_idetach(const void *); -#endif - -#ifndef VIMAGE_GLOBALS -static struct vnet_symmap vnet_rtable_symmap[] = { - VNET_SYMMAP(rtable, rt_tables), - VNET_SYMMAP(rtable, rtstat), - VNET_SYMMAP(rtable, rttrash), - VNET_SYMMAP_END -}; static const vnet_modinfo_t vnet_rtable_modinfo = { .vmi_id = VNET_MOD_RTABLE, .vmi_name = "rtable", - .vmi_size = sizeof(struct vnet_rtable), - .vmi_symmap = vnet_rtable_symmap, .vmi_iattach = vnet_route_iattach, -#ifdef VIMAGE .vmi_idetach = vnet_route_idetach -#endif }; -#endif /* !VIMAGE_GLOBALS */ +#endif /* compare two sockaddr structures */ #define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0) @@ -192,7 +152,6 @@ SYSCTL_PROC(_net, OID_AUTO, my_fibnum, CTLTYPE_INT|CTLFLAG_RD, static __inline struct radix_node_head ** rt_tables_get_rnh_ptr(int table, int fam) { - INIT_VNET_RTABLE(curvnet); struct radix_node_head **rnh; KASSERT(table >= 0 && table < rt_numfibs, ("%s: table out of bounds.", @@ -226,7 +185,7 @@ route_init(void) rt_numfibs = 1; rn_init(); /* initialize all zeroes, all ones, mask table */ -#ifndef VIMAGE_GLOBALS +#ifdef VIMAGE vnet_mod_register(&vnet_rtable_modinfo); #else vnet_route_iattach(NULL); @@ -236,7 +195,6 @@ route_init(void) static int vnet_route_iattach(const void *unused __unused) { - INIT_VNET_RTABLE(curvnet); struct domain *dom; struct radix_node_head **rnh; int table; @@ -382,7 +340,6 @@ struct rtentry * rtalloc1_fib(struct sockaddr *dst, int report, u_long ignflags, u_int fibnum) { - INIT_VNET_RTABLE(curvnet); struct radix_node_head *rnh; struct rtentry *rt; struct radix_node *rn; @@ -452,7 +409,6 @@ done: void rtfree(struct rtentry *rt) { - INIT_VNET_RTABLE(curvnet); struct radix_node_head *rnh; KASSERT(rt != NULL,("%s: NULL rt", __func__)); @@ -551,7 +507,6 @@ rtredirect_fib(struct sockaddr *dst, struct sockaddr *src, u_int fibnum) { - INIT_VNET_RTABLE(curvnet); struct rtentry *rt, *rt0 = NULL; int error = 0; short *stat = NULL; @@ -880,7 +835,6 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum) int rtexpunge(struct rtentry *rt) { - INIT_VNET_RTABLE(curvnet); struct radix_node *rn; struct radix_node_head *rnh; struct ifaddr *ifa; @@ -1018,8 +972,6 @@ gwdelete: RT_LOCK(rt); RT_ADDREF(rt); if (req == RTM_DELETE) { - INIT_VNET_RTABLE(curvnet); - rt->rt_flags &= ~RTF_UP; /* * One more rtentry floating around that is not @@ -1027,7 +979,6 @@ gwdelete: * when RTFREE(rt) is eventually called. */ V_rttrash++; - } nondelete: @@ -1054,7 +1005,6 @@ int rtrequest1_fib(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt, u_int fibnum) { - INIT_VNET_RTABLE(curvnet); int error = 0, needlock = 0; register struct rtentry *rt; register struct radix_node *rn; |