diff options
author | hrs <hrs@FreeBSD.org> | 2014-08-22 05:03:30 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2014-08-22 05:03:30 +0000 |
commit | afe0ab6d8e9739a48635f1c816a2ce530541da71 (patch) | |
tree | 27d09382fd84b9dea644ae18dba20c0fb6e513d2 | |
parent | 746cb605d6fcbc1f45b38cb0471dbfab2e3c16a7 (diff) | |
download | FreeBSD-src-afe0ab6d8e9739a48635f1c816a2ce530541da71.zip FreeBSD-src-afe0ab6d8e9739a48635f1c816a2ce530541da71.tar.gz |
Fix a panic which occurs in a VIMAGE-enabled kernel after r270158, and
separate socket_hhook_register() part and put it into VNET_SYS{,UN}INIT()
handler.
Discussed with: marcel
-rw-r--r-- | sys/kern/uipc_socket.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 7ff7b40..eb769a1 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -271,9 +271,16 @@ socket_hhook_register(int subtype) } static void +socket_hhook_deregister(int subtype) +{ + + if (hhook_head_deregister(V_socket_hhh[subtype]) != 0) + printf("%s: WARNING: unable to deregister hook\n", __func__); +} + +static void socket_init(void *tag) { - int i; socket_zone = uma_zcreate("socket", sizeof(struct socket), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); @@ -281,13 +288,31 @@ socket_init(void *tag) uma_zone_set_warning(socket_zone, "kern.ipc.maxsockets limit reached"); EVENTHANDLER_REGISTER(maxsockets_change, socket_zone_change, NULL, EVENTHANDLER_PRI_FIRST); +} +SYSINIT(socket, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, socket_init, NULL); + +static void +socket_vnet_init(const void *unused __unused) +{ + int i; /* We expect a contiguous range */ - for (i = 0; i <= HHOOK_SOCKET_LAST; i++) { + for (i = 0; i <= HHOOK_SOCKET_LAST; i++) socket_hhook_register(i); - } } -SYSINIT(socket, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, socket_init, NULL); +VNET_SYSINIT(socket_vnet_init, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, + socket_vnet_init, NULL); + +static void +socket_vnet_uninit(const void *unused __unused) +{ + int i; + + for (i = 0; i <= HHOOK_SOCKET_LAST; i++) + socket_hhook_deregister(i); +} +VNET_SYSUNINIT(socket_vnet_uninit, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, + socket_vnet_uninit, NULL); /* * Initialise maxsockets. This SYSINIT must be run after @@ -376,12 +401,15 @@ soalloc(struct vnet *vnet) #endif mtx_unlock(&so_global_mtx); + CURVNET_SET(vnet); /* We shouldn't need the so_global_mtx */ if (V_socket_hhh[HHOOK_SOCKET_CREATE]->hhh_nhooks > 0) { if (hhook_run_socket(so, NULL, HHOOK_SOCKET_CREATE)) /* Do we need more comprehensive error returns? */ - return (NULL); + so = NULL; } + CURVNET_RESTORE(); + return (so); } @@ -418,8 +446,10 @@ sodealloc(struct socket *so) #ifdef MAC mac_socket_destroy(so); #endif + CURVNET_SET(so->so_vnet); if (V_socket_hhh[HHOOK_SOCKET_CLOSE]->hhh_nhooks > 0) hhook_run_socket(so, NULL, HHOOK_SOCKET_CLOSE); + CURVNET_RESTORE(); crfree(so->so_cred); khelp_destroy_osd(&so->osd); |