From owner-svn-src-head@FreeBSD.ORG Mon Sep 8 09:04:23 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EE2C4235; Mon, 8 Sep 2014 09:04:22 +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 DA2A71CD9; Mon, 8 Sep 2014 09:04:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8894MWm045577; Mon, 8 Sep 2014 09:04:22 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8894M9H045576; Mon, 8 Sep 2014 09:04:22 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201409080904.s8894M9H045576@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Mon, 8 Sep 2014 09:04:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271254 - 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: Mon, 08 Sep 2014 09:04:23 -0000 Author: hrs Date: Mon Sep 8 09:04:22 2014 New Revision: 271254 URL: http://svnweb.freebsd.org/changeset/base/271254 Log: - Make hhook_run_socket() vnet-aware instead of adding CURVNET_SET() around the function calls. - Fix a memory leak and stats in the case that hhook_run_socket() fails in soalloc(). PR: 193265 Modified: head/sys/kern/uipc_socket.c Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Mon Sep 8 08:44:50 2014 (r271253) +++ head/sys/kern/uipc_socket.c Mon Sep 8 09:04:22 2014 (r271254) @@ -391,25 +391,24 @@ soalloc(struct vnet *vnet) sx_init(&so->so_snd.sb_sx, "so_snd_sx"); sx_init(&so->so_rcv.sb_sx, "so_rcv_sx"); TAILQ_INIT(&so->so_aiojobq); - mtx_lock(&so_global_mtx); - so->so_gencnt = ++so_gencnt; - ++numopensockets; #ifdef VIMAGE VNET_ASSERT(vnet != NULL, ("%s:%d vnet is NULL, so=%p", __func__, __LINE__, so)); - vnet->vnet_sockcnt++; so->so_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? */ - so = NULL; + if (hhook_run_socket(so, NULL, HHOOK_SOCKET_CREATE)) { + /* Do we need more comprehensive error returns? */ + uma_zfree(socket_zone, so); + return (NULL); } - CURVNET_RESTORE(); + mtx_lock(&so_global_mtx); + so->so_gencnt = ++so_gencnt; + ++numopensockets; +#ifdef VIMAGE + vnet->vnet_sockcnt++; +#endif + mtx_unlock(&so_global_mtx); return (so); } @@ -447,10 +446,7 @@ 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(); + hhook_run_socket(so, NULL, HHOOK_SOCKET_CLOSE); crfree(so->so_cred); khelp_destroy_osd(&so->osd); @@ -2406,10 +2402,13 @@ hhook_run_socket(struct socket *so, void struct socket_hhook_data hhook_data = { .so = so, .hctx = hctx, - .m = NULL + .m = NULL, + .status = 0 }; - hhook_run_hooks(V_socket_hhh[h_id], &hhook_data, &so->osd); + CURVNET_SET(so->so_vnet); + HHOOKS_RUN_IF(V_socket_hhh[h_id], &hhook_data, &so->osd); + CURVNET_RESTORE(); /* Ugly but needed, since hhooks return void for now */ return (hhook_data.status); @@ -3245,7 +3244,6 @@ static int filt_soread(struct knote *kn, long hint) { struct socket *so; - int ret; so = kn->kn_fp->f_data; SOCKBUF_LOCK_ASSERT(&so->so_rcv); @@ -3266,14 +3264,8 @@ filt_soread(struct knote *kn, long hint) return 1; } - CURVNET_SET(so->so_vnet); - if (V_socket_hhh[HHOOK_FILT_SOREAD]->hhh_nhooks > 0) - ret = hhook_run_socket(so, NULL, HHOOK_FILT_SOREAD); - else - ret = 0; - CURVNET_RESTORE(); - - return (ret); + /* This hook returning non-zero indicates an event, not error */ + return (hhook_run_socket(so, NULL, HHOOK_FILT_SOREAD)); } static void @@ -3298,10 +3290,7 @@ filt_sowrite(struct knote *kn, long hint SOCKBUF_LOCK_ASSERT(&so->so_snd); kn->kn_data = sbspace(&so->so_snd); - CURVNET_SET(so->so_vnet); - if (V_socket_hhh[HHOOK_FILT_SOWRITE]->hhh_nhooks > 0) - hhook_run_socket(so, kn, HHOOK_FILT_SOWRITE); - CURVNET_RESTORE(); + hhook_run_socket(so, kn, HHOOK_FILT_SOWRITE); if (so->so_snd.sb_state & SBS_CANTSENDMORE) { kn->kn_flags |= EV_EOF;