From owner-svn-src-all@FreeBSD.ORG Wed Apr 6 18:03:49 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 F13AA106566B; Wed, 6 Apr 2011 18:03:49 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C5B228FC17; Wed, 6 Apr 2011 18:03:49 +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 p36I3nQN008493; Wed, 6 Apr 2011 18:03:49 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p36I3n9k008491; Wed, 6 Apr 2011 18:03:49 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201104061803.p36I3n9k008491@svn.freebsd.org> From: Gleb Smirnoff Date: Wed, 6 Apr 2011 18:03:49 +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: r220397 - 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, 06 Apr 2011 18:03:50 -0000 Author: glebius Date: Wed Apr 6 18:03:49 2011 New Revision: 220397 URL: http://svn.freebsd.org/changeset/base/220397 Log: MFhead 220317: When removing ifnets, we should first remove the reference to ifnet from the interface index, then decrease refcount, not vice versa. Otherwise there is a race (reproducible) when if_free_internal() contests on IFNET_WLOCK(), and we got a zero-refed ifnet in the index for a long time. It may be picked by some other thread, that runs ifnet_byindex_ref(), who takes the ifnet from index, and bumps refcount. When reader drops the lock, if_free_internal() proceeds with free. Then reader tries to free it a second time. 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 Apr 6 18:00:26 2011 (r220396) +++ stable/8/sys/net/if.c Wed Apr 6 18:03:49 2011 (r220397) @@ -484,8 +484,8 @@ if_alloc(u_char type) } /* - * Do the actual work of freeing a struct ifnet, associated index, and layer - * 2 common structure. This call is made when the last reference to an + * Do the actual work of freeing a struct ifnet, and layer 2 common + * structure. This call is made when the last reference to an * interface is released. */ static void @@ -495,13 +495,6 @@ if_free_internal(struct ifnet *ifp) KASSERT((ifp->if_flags & IFF_DYING), ("if_free_internal: interface not dying")); - IFNET_WLOCK(); - KASSERT(ifp == ifnet_byindex_locked(ifp->if_index), - ("%s: freeing unallocated ifnet", ifp->if_xname)); - - ifindex_free_locked(ifp->if_index); - IFNET_WUNLOCK(); - if (if_com_free[ifp->if_alloctype] != NULL) if_com_free[ifp->if_alloctype](ifp->if_l2com, ifp->if_alloctype); @@ -532,6 +525,14 @@ if_free_type(struct ifnet *ifp, u_char t ifp->if_alloctype)); ifp->if_flags |= IFF_DYING; /* XXX: Locking */ + + IFNET_WLOCK(); + KASSERT(ifp == ifnet_byindex_locked(ifp->if_index), + ("%s: freeing unallocated ifnet", ifp->if_xname)); + + ifindex_free_locked(ifp->if_index); + IFNET_WUNLOCK(); + if (!refcount_release(&ifp->if_refcount)) return; if_free_internal(ifp);