From owner-freebsd-arch@FreeBSD.ORG Mon Oct 3 17:24:45 2005 Return-Path: X-Original-To: arch@FreeBSD.ORG Delivered-To: freebsd-arch@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6C4AB16A41F; Mon, 3 Oct 2005 17:24:45 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id F198E43D46; Mon, 3 Oct 2005 17:24:44 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id j93HOb0r093316; Mon, 3 Oct 2005 11:24:37 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 03 Oct 2005 11:25:26 -0600 (MDT) Message-Id: <20051003.112526.102577313.imp@bsdimp.com> To: jhb@FreeBSD.ORG From: "M. Warner Losh" In-Reply-To: <200510031246.14835.jhb@FreeBSD.org> References: <200510031246.14835.jhb@FreeBSD.org> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Mon, 03 Oct 2005 11:24:37 -0600 (MDT) Cc: arch@FreeBSD.ORG, ru@FreeBSD.ORG Subject: Re: Ethernet driver teardown X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Oct 2005 17:24:45 -0000 In message: <200510031246.14835.jhb@FreeBSD.org> John Baldwin writes: : So, I was thinking about the problem with ethernet driver detach races this : morning and had an idea. What if the sequence for detach() was altered such : that we called ether_ifdetach() before the driver's stop() routine? Thus, : you would end up with something like this: : : foo_detach() : { : : ether_ifdetach(sc->foo_ifp); : FOO_LOCK(sc); : foo_stop(sc); ifp->if_drv_flags &= ~IFF_DRV_RUNNING; /* or does foo_stop do this? */ : FOO_UNLOCK(sc); : callout_drain(...); : bus_teardown_intr(...); : if_free(sc->foo_ifp); : bus_release_resources(...); : ... : } : : Would that solve the various races including letting BPF turn off promiscuous : mode cleanly without requiring detaching flags in each driver to bail out of : foo_ioctl()? I'm unusure. I'm prettys sure that the promisc mode would be turned off correctly, but see below. This does represent an improvement over the current method. I have a couple of concerns. (1) What happens to the packets received when the device is detached. We'll have to make sure that the ifp is in a state that can allow for the input routine to still be called w/o leaking memory. (2) Does this solve the problems that I originally suggested a if_dead() routine for? (3) How do we know that we're out of all the ifp callbacks when ether_ifdetach() returns? If we forced a lock/unlock pair for all ioctl functions, then we could know for sure when we acquire the lock. I'm unsure what to do about if_output, if_start and if_watchdog. Warner