Index: sys/dev/scsipi/scsipi_base.c =================================================================== RCS file: /cvsroot/src/sys/dev/scsipi/scsipi_base.c,v retrieving revision 1.170 diff -u -p -r1.170 scsipi_base.c --- sys/dev/scsipi/scsipi_base.c 16 Dec 2016 15:00:52 -0000 1.170 +++ sys/dev/scsipi/scsipi_base.c 18 Dec 2016 13:41:25 -0000 @@ -1462,8 +1462,8 @@ scsipi_done(struct scsipi_xfer *xs) * completion queue, and wake up the completion thread. */ TAILQ_INSERT_TAIL(&chan->chan_complete, xs, channel_q); - mutex_exit(chan_mtx(chan)); cv_broadcast(chan_cv_complete(chan)); + mutex_exit(chan_mtx(chan)); out: /* @@ -2138,21 +2138,17 @@ scsipi_completion_thread(void *arg) mutex_enter(chan_mtx(chan)); chan->chan_flags |= SCSIPI_CHAN_TACTIVE; - mutex_exit(chan_mtx(chan)); for (;;) { - mutex_enter(chan_mtx(chan)); xs = TAILQ_FIRST(&chan->chan_complete); if (xs == NULL && chan->chan_tflags == 0) { /* nothing to do; wait */ cv_wait(chan_cv_complete(chan), chan_mtx(chan)); - mutex_exit(chan_mtx(chan)); continue; } if (chan->chan_tflags & SCSIPI_CHANT_CALLBACK) { /* call chan_callback from thread context */ chan->chan_tflags &= ~SCSIPI_CHANT_CALLBACK; chan->chan_callback(chan, chan->chan_callback_arg); - mutex_exit(chan_mtx(chan)); continue; } if (chan->chan_tflags & SCSIPI_CHANT_GROWRES) { @@ -2164,6 +2160,7 @@ scsipi_completion_thread(void *arg) scsipi_channel_thaw(chan, 1); if (chan->chan_tflags & SCSIPI_CHANT_GROWRES) kpause("scsizzz", FALSE, hz/10, NULL); + mutex_enter(chan_mtx(chan)); continue; } if (chan->chan_tflags & SCSIPI_CHANT_KICK) { @@ -2171,10 +2168,10 @@ scsipi_completion_thread(void *arg) chan->chan_tflags &= ~SCSIPI_CHANT_KICK; mutex_exit(chan_mtx(chan)); scsipi_run_queue(chan); + mutex_enter(chan_mtx(chan)); continue; } if (chan->chan_tflags & SCSIPI_CHANT_SHUTDOWN) { - mutex_exit(chan_mtx(chan)); break; } if (xs) { @@ -2191,8 +2188,7 @@ scsipi_completion_thread(void *arg) * for some reason. */ scsipi_run_queue(chan); - } else { - mutex_exit(chan_mtx(chan)); + mutex_enter(chan_mtx(chan)); } } @@ -2200,6 +2196,7 @@ scsipi_completion_thread(void *arg) /* In case parent is waiting for us to exit. */ cv_broadcast(chan_cv_thread(chan)); + mutex_exit(chan_mtx(chan)); kthread_exit(0); }