From owner-svn-src-all@FreeBSD.ORG Wed Mar 2 19:27:01 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9D0D6106564A; Wed, 2 Mar 2011 19:27:01 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 726668FC0C; Wed, 2 Mar 2011 19:27:01 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p22JR1SU040256; Wed, 2 Mar 2011 19:27:01 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p22JR1Sp040254; Wed, 2 Mar 2011 19:27:01 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201103021927.p22JR1Sp040254@svn.freebsd.org> From: John Baldwin Date: Wed, 2 Mar 2011 19:27:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219188 - stable/8/sys/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2011 19:27:01 -0000 Author: jhb Date: Wed Mar 2 19:27:01 2011 New Revision: 219188 URL: http://svn.freebsd.org/changeset/base/219188 Log: MFC 217805: Fix a LOR by dropping the global ifnet locks while allocating a new ifnet table in if_grow(). The order of the SYSINIT's for ifnet state were swapped so that the various locks were initialized before being used. Modified: stable/8/sys/net/if.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/net/if.c ============================================================================== --- stable/8/sys/net/if.c Wed Mar 2 19:09:49 2011 (r219187) +++ stable/8/sys/net/if.c Wed Mar 2 19:27:01 2011 (r219188) @@ -275,6 +275,7 @@ ifindex_alloc_locked(u_short *idxp) IFNET_WLOCK_ASSERT(); +retry: /* * Try to find an empty slot below V_if_index. If we fail, take the * next slot. @@ -287,10 +288,12 @@ ifindex_alloc_locked(u_short *idxp) /* Catch if_index overflow. */ if (idx < 1) return (ENOSPC); + if (idx >= V_if_indexlim) { + if_grow(); + goto retry; + } if (idx > V_if_index) V_if_index = idx; - if (V_if_index >= V_if_indexlim) - if_grow(); *idxp = idx; return (0); } @@ -360,10 +363,12 @@ vnet_if_init(const void *unused __unused TAILQ_INIT(&V_ifnet); TAILQ_INIT(&V_ifg_head); + IFNET_WLOCK(); if_grow(); /* create initial table */ + IFNET_WUNLOCK(); vnet_if_clone_init(); } -VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_FIRST, vnet_if_init, +VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, vnet_if_init, NULL); /* ARGSUSED*/ @@ -374,7 +379,7 @@ if_init(void *dummy __unused) IFNET_LOCK_INIT(); if_clone_init(); } -SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_SECOND, if_init, NULL); +SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_FIRST, if_init, NULL); #ifdef VIMAGE @@ -394,16 +399,25 @@ VNET_SYSUNINIT(vnet_if_uninit, SI_SUB_IN static void if_grow(void) { + int oldlim; u_int n; struct ifindex_entry *e; - V_if_indexlim <<= 1; - n = V_if_indexlim * sizeof(*e); + IFNET_WLOCK_ASSERT(); + oldlim = V_if_indexlim; + IFNET_WUNLOCK(); + n = (oldlim << 1) * sizeof(*e); e = malloc(n, M_IFNET, M_WAITOK | M_ZERO); + IFNET_WLOCK(); + if (V_if_indexlim != oldlim) { + free(e, M_IFNET); + return; + } if (V_ifindex_table != NULL) { memcpy((caddr_t)e, (caddr_t)V_ifindex_table, n/2); free((caddr_t)V_ifindex_table, M_IFNET); } + V_if_indexlim <<= 1; V_ifindex_table = e; }