From owner-svn-src-head@FreeBSD.ORG Fri Aug 22 05:03:31 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 407EC99; Fri, 22 Aug 2014 05:03:31 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 125CC33DF; Fri, 22 Aug 2014 05:03:31 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7M53U8o008949; Fri, 22 Aug 2014 05:03:30 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7M53UWv008948; Fri, 22 Aug 2014 05:03:30 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201408220503.s7M53UWv008948@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Fri, 22 Aug 2014 05:03:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r270318 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Aug 2014 05:03:31 -0000 Author: hrs Date: Fri Aug 22 05:03:30 2014 New Revision: 270318 URL: http://svnweb.freebsd.org/changeset/base/270318 Log: 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 Modified: head/sys/kern/uipc_socket.c Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Fri Aug 22 01:23:38 2014 (r270317) +++ head/sys/kern/uipc_socket.c Fri Aug 22 05:03:30 2014 (r270318) @@ -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);