Spdk/module/bdev
Shuhei Matsumoto 077ae9152d bdev/raid: Fix race issue among multiple threads to free RAID bdev
The following issue was observed.

The first thread returned the last IO channel and the second thread
then removed the first base device, but raid_bdev_cleanup() was
called before raid_bdev_destroy_cb() was called.

raid_bdev_destroy_cb() was accessed to the raid bdev already freed
by raid_bdev_cleanup() and caused segmentation fault.

The call sequence was as follows:

The first thread:
 spdk_put_io_channel() -> ch->destroy_cb -> raid_bdev_destroy_cb
-> access raid bdev

The second thread:
 raid_bdev_remove_base_devices() -> raid_bdev_deconfigure() ->
spdk_bdev_unregister() -> spdk_io_device_unregister() ->
spdk_bdev_destroy_cb() -> raid_bdev_destruct() -> raid_bdev_cleanup()
-> free raid bdev

The fix is to hold number of created channels in struct
raid_bdev_io_channel and use it in raid_bdev_destroy_cb().

Bdev layer, IO device/channel layer, and NVMe-oF layer  already
process this case correctly.

    Fixes #884.

Reported-by: yidong0635 <dongx.yi@intel.com>

Signed-off-by: yidong0635 <dongx.yi@intel.com>
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463249 (master)

(cherry picked from commit 284aca9e36)
Change-Id: Ie9d61bdddca479ce7f491ff9a08db45e71f16a8d
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467130
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2019-09-09 21:55:22 +00:00
..
aio mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
compress mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
crypto mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
delay mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
error mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
gpt mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
iscsi mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
lvol mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
malloc mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
null mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
nvme mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
ocf lib/mk: update OCF build. 2019-09-06 02:19:41 +00:00
passthru mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
pmem mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
raid bdev/raid: Fix race issue among multiple threads to free RAID bdev 2019-09-09 21:55:22 +00:00
rbd mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
rpc mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
split mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
uring mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
virtio mk: move the bdev modules under module directory. 2019-09-06 02:19:41 +00:00
Makefile lib/mk: update OCF build. 2019-09-06 02:19:41 +00:00