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 *);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to