From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 15 17:37:28 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1B4C4C68; Thu, 15 Nov 2012 17:37:28 +0000 (UTC) (envelope-from zec@fer.hr) Received: from mail.zvne.fer.hr (mail.zvne.fer.hr [161.53.66.5]) by mx1.freebsd.org (Postfix) with ESMTP id 5987F8FC08; Thu, 15 Nov 2012 17:37:26 +0000 (UTC) Received: from munja.zvne.fer.hr (161.53.66.248) by mail.zvne.fer.hr (161.53.66.5) with Microsoft SMTP Server id 14.2.318.4; Thu, 15 Nov 2012 18:36:14 +0100 Received: from sluga.fer.hr ([161.53.66.244]) by munja.zvne.fer.hr with Microsoft SMTPSVC(6.0.3790.4675); Thu, 15 Nov 2012 18:36:14 +0100 Received: from localhost ([161.53.19.8]) by sluga.fer.hr over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 15 Nov 2012 18:36:14 +0100 From: Marko Zec To: Adrian Chadd Subject: Re: VIMAGE crashes on 9.x with hotplug net80211 devices Date: Thu, 15 Nov 2012 18:36:04 +0100 User-Agent: KMail/1.9.10 References: <201210291115.23845.zec@fer.hr> In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary-00=_EgSpQL+nIDcE64N" Message-ID: <201211151836.04709.zec@fer.hr> X-OriginalArrivalTime: 15 Nov 2012 17:36:14.0549 (UTC) FILETIME=[B5EE8050:01CDC357] Cc: freebsd-net@freebsd.org, Hans Petter Selasky , freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Nov 2012 17:37:28 -0000 --Boundary-00=_EgSpQL+nIDcE64N Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thursday 15 November 2012 07:18:31 Adrian Chadd wrote: > Hi, > > Here's what I have thus far. Please ignore the device_printf() change. > > This works for me, both for hotplug cardbus wireless devices as well > as (inadvertently!) a USB bluetooth device. > > What do you think? It looks that you've hit the right spot to set curvnet context in device_probe_and_attach(). Could you try out a slightly revised verstion (attached) - this one also removes now redundant curvnet setting from linker routines (kldload / kldunload), and adds a few extra bits which might be necessary for a broader range of drivers to work. Note that I haven't tested this myself as I don't have a -CURRENT machine ATM, but a similar patch for 8.3 apparently works fine, though I don't have hotplugabble network cards to play with (neither cardbus nor USB)... Cheers, Marko --Boundary-00=_EgSpQL+nIDcE64N Content-Type: text/x-diff; charset="iso 8859-15"; name="hotplug_vnet_20121115.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hotplug_vnet_20121115.diff" Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c (revision 243091) +++ sys/kern/subr_bus.c (working copy) @@ -53,6 +53,8 @@ #include #include +#include + #include #include @@ -2735,7 +2737,11 @@ return (0); else if (error != 0) return (error); - return (device_attach(dev)); + + CURVNET_SET_QUIET(vnet0); + error = device_attach(dev); + CURVNET_RESTORE(); + return (error); } /** Index: sys/kern/kern_linker.c =================================================================== --- sys/kern/kern_linker.c (revision 243091) +++ sys/kern/kern_linker.c (working copy) @@ -53,8 +53,6 @@ #include #include -#include - #include #include "linker_if.h" @@ -1019,12 +1017,6 @@ return (error); /* - * It is possible that kldloaded module will attach a new ifnet, - * so vnet context must be set when this ocurs. - */ - CURVNET_SET(TD_TO_VNET(td)); - - /* * If file does not contain a qualified name or any dot in it * (kldname.ko, or kldname.ver.ko) treat it as an interface * name. @@ -1041,7 +1033,7 @@ error = linker_load_module(kldname, modname, NULL, NULL, &lf); if (error) { KLD_UNLOCK(); - goto done; + return (error); } lf->userrefs++; if (fileid != NULL) @@ -1055,9 +1047,6 @@ #else KLD_UNLOCK(); #endif - -done: - CURVNET_RESTORE(); return (error); } @@ -1095,7 +1084,6 @@ if ((error = priv_check(td, PRIV_KLD_UNLOAD)) != 0) return (error); - CURVNET_SET(TD_TO_VNET(td)); KLD_LOCK(); lf = linker_find_file_by_id(fileid); if (lf) { @@ -1137,7 +1125,6 @@ #else KLD_UNLOCK(); #endif - CURVNET_RESTORE(); return (error); } Index: sys/netgraph/bluetooth/socket/ng_btsocket.c =================================================================== --- sys/netgraph/bluetooth/socket/ng_btsocket.c (revision 243091) +++ sys/netgraph/bluetooth/socket/ng_btsocket.c (working copy) @@ -46,6 +46,8 @@ #include #include +#include + #include #include #include @@ -285,4 +287,4 @@ return (error); } /* ng_btsocket_modevent */ -DOMAIN_SET(ng_btsocket_); +VNET_DOMAIN_SET(ng_btsocket_); Index: sys/net/if.c =================================================================== --- sys/net/if.c (revision 243091) +++ sys/net/if.c (working copy) @@ -504,6 +504,7 @@ ifp->if_flags |= IFF_DYING; /* XXX: Locking */ + CURVNET_SET_QUIET(ifp->if_vnet); IFNET_WLOCK(); KASSERT(ifp == ifnet_byindex_locked(ifp->if_index), ("%s: freeing unallocated ifnet", ifp->if_xname)); @@ -511,9 +512,9 @@ ifindex_free_locked(ifp->if_index); IFNET_WUNLOCK(); - if (!refcount_release(&ifp->if_refcount)) - return; - if_free_internal(ifp); + if (refcount_release(&ifp->if_refcount)) + if_free_internal(ifp); + CURVNET_RESTORE(); } /* @@ -793,7 +794,9 @@ if_detach(struct ifnet *ifp) { + CURVNET_SET_QUIET(ifp->if_vnet); if_detach_internal(ifp, 0); + CURVNET_RESTORE(); } static void --Boundary-00=_EgSpQL+nIDcE64N--