numam-spdk/lib/vhost
Dariusz Stojaczyk 1eac307937 rte_vhost: fix deadlock on rte_vhost_driver_unregister()
2 locks are executed in 2 places in opposite orders.
Consider the following scenario, threads A and B:
(A)
 * fdset_event_dispatch() start
   * pfdentry->busy = 1; (lock #1)
   * vhost_user_read_cb() start
     * vhost_destroy_device() start
(B)
 * rte_vhost_driver_unregister() start
   * pthread_mutex_lock(&vsocket->conn_mutex); (lock #2)
   * fdset_del()
     * endless loop, waiting for pfdentry->busy == 0 (lock #1)
(A)
     * vhost_destroy_device() end
     * pthread_mutex_lock(&vsocket->conn_mutex); (lock #2)
       (mutex already locked - deadlock at this point)

Thread B has locked vsocket->conn_mutex and is in while(1)
loop waiting for given fd to change it's busy flag to 0.
Thread A would have to finish vhost_user_read_cb() in order
to set busy flag back to 0, but that can't happen due to
the vsocket->conn_mutex lock.

This patch defers the fdset_del(), so that it's called outside of
vsocket->conn_mutex.

Change-Id: Ifb5d4699bdafe96a573444c11ad4eae3adc359f5
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/375910
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2017-08-31 19:16:06 -04:00
..
rte_vhost rte_vhost: fix deadlock on rte_vhost_driver_unregister() 2017-08-31 19:16:06 -04:00
Makefile vhost: removed task.h/task.c 2017-06-30 16:32:47 -04:00
test_plan.md test/vhost: Update test plan for vhost 2017-07-25 15:48:46 -04:00
vhost_blk.c log: rename SPDK_TRACELOG to SPDK_DEBUGLOG 2017-08-29 13:25:58 -04:00
vhost_internal.h vhost: removed parse_core_mask function from public API 2017-08-25 12:37:28 -04:00
vhost_iommu.c log: rename SPDK_TRACELOG to SPDK_DEBUGLOG 2017-08-29 13:25:58 -04:00
vhost_iommu.h include: Move the remainder of the code base to stdinc.h 2017-05-08 13:20:36 -07:00
vhost_rpc.c log: remove uses of SPDK_TRACE_DEBUG 2017-08-29 15:07:13 -04:00
vhost_scsi.c log: rename SPDK_TRACELOG to SPDK_DEBUGLOG 2017-08-29 13:25:58 -04:00
vhost.c log: rename SPDK_TRACELOG to SPDK_DEBUGLOG 2017-08-29 13:25:58 -04:00