From owner-svn-src-head@freebsd.org Thu Jul 14 07:39:35 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7EBA4B98518; Thu, 14 Jul 2016 07:39:35 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 59E891FAA; Thu, 14 Jul 2016 07:39:35 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6E7dYmO087017; Thu, 14 Jul 2016 07:39:34 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6E7dYXj087013; Thu, 14 Jul 2016 07:39:34 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201607140739.u6E7dYXj087013@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Thu, 14 Jul 2016 07:39:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r302816 - head/sys/dev/hyperv/vmbus 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.22 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: Thu, 14 Jul 2016 07:39:35 -0000 Author: sephe Date: Thu Jul 14 07:39:34 2016 New Revision: 302816 URL: https://svnweb.freebsd.org/changeset/base/302816 Log: hyperv/vmbus: Release vmbus channel lock before detach devices Device detach method may sleep. While I'm here, rename the function, fix indentation and function comment. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7110 Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h head/sys/dev/hyperv/vmbus/vmbus.c head/sys/dev/hyperv/vmbus/vmbus_var.h Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jul 14 07:31:43 2016 (r302815) +++ head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Thu Jul 14 07:39:34 2016 (r302816) @@ -398,27 +398,27 @@ vmbus_channel_on_offers_delivered(struct vmbus_scan_done(sc); } -/** - * @brief Release channels that are unattached/unconnected (i.e., no drivers associated) +/* + * Detach all devices and destroy the corresponding primary channels. */ void -hv_vmbus_release_unattached_channels(struct vmbus_softc *sc) +vmbus_chan_destroy_all(struct vmbus_softc *sc) { - hv_vmbus_channel *channel; + struct hv_vmbus_channel *chan; mtx_lock(&sc->vmbus_chlist_lock); + while ((chan = TAILQ_FIRST(&sc->vmbus_chlist)) != NULL) { + KASSERT(VMBUS_CHAN_ISPRIMARY(chan), ("not primary channel")); + TAILQ_REMOVE(&sc->vmbus_chlist, chan, ch_link); + mtx_unlock(&sc->vmbus_chlist_lock); - while (!TAILQ_EMPTY(&sc->vmbus_chlist)) { - channel = TAILQ_FIRST(&sc->vmbus_chlist); - KASSERT(VMBUS_CHAN_ISPRIMARY(channel), ("not primary channel")); - TAILQ_REMOVE(&sc->vmbus_chlist, channel, ch_link); + hv_vmbus_child_device_unregister(chan); + vmbus_chan_free(chan); - hv_vmbus_child_device_unregister(channel); - vmbus_chan_free(channel); + mtx_lock(&sc->vmbus_chlist_lock); } bzero(sc->vmbus_chmap, sizeof(struct hv_vmbus_channel *) * VMBUS_CHAN_MAX); - mtx_unlock(&sc->vmbus_chlist_lock); } Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jul 14 07:31:43 2016 (r302815) +++ head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Thu Jul 14 07:39:34 2016 (r302816) @@ -146,9 +146,6 @@ void hv_ring_buffer_read_begin( uint32_t hv_ring_buffer_read_end( hv_vmbus_ring_buffer_info *ring_info); -void hv_vmbus_release_unattached_channels( - struct vmbus_softc *); - int hv_vmbus_child_device_register( struct hv_vmbus_channel *chan); int hv_vmbus_child_device_unregister( Modified: head/sys/dev/hyperv/vmbus/vmbus.c ============================================================================== --- head/sys/dev/hyperv/vmbus/vmbus.c Thu Jul 14 07:31:43 2016 (r302815) +++ head/sys/dev/hyperv/vmbus/vmbus.c Thu Jul 14 07:39:34 2016 (r302816) @@ -1239,7 +1239,7 @@ vmbus_detach(device_t dev) { struct vmbus_softc *sc = device_get_softc(dev); - hv_vmbus_release_unattached_channels(sc); + vmbus_chan_destroy_all(sc); vmbus_disconnect(sc); Modified: head/sys/dev/hyperv/vmbus/vmbus_var.h ============================================================================== --- head/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jul 14 07:31:43 2016 (r302815) +++ head/sys/dev/hyperv/vmbus/vmbus_var.h Thu Jul 14 07:39:34 2016 (r302816) @@ -138,6 +138,7 @@ void vmbus_handle_intr(struct trapframe void vmbus_et_intr(struct trapframe *); void vmbus_chan_msgproc(struct vmbus_softc *, const struct vmbus_message *); +void vmbus_chan_destroy_all(struct vmbus_softc *); struct vmbus_msghc *vmbus_msghc_get(struct vmbus_softc *, size_t); void vmbus_msghc_put(struct vmbus_softc *, struct vmbus_msghc *);