numam-spdk/test/unit/lib
Shuhei Matsumoto 7a9ecf8284 lib/scsi: Free bdev_io just after getting completion from bdev for non-read I/O
Previously, for iSCSI target, freeing bdev_io of SCSI task was deferred
until the reference count of the SCSI task becomes zero.

But this will cause the use-after-free issue when doing LUN hotplug during
large write I/O workload.

The scenario is the following:

- Large iSCSI write I/O is split into multiple I/Os, the first I/O is from immediate,
  and subsetquent I/Os are from R2T.

1. The first I/O allocates iSCSI task as primary, and is submitted to  the bdev layer.
   The first I/O is pending in the bdev layer.
2. The second I/O allocates iSCSI task as secondary (secondary is associated with
   primary by incrementing reference count).
3. Before submitting the second I/O to the bdev layer, LUN hotplug is started.
   LUN hotplug waits for getting completion of the first write I/O from the bdev layer.
4. The bdev layer completes the first I/O. The primary iSCSI task is tried to free,
   but reference count is still one, and is not done yet.
5. LUN hotplug detects completion of the first write I/O, and returns
   LUN I/O channel to the bdev layer.
6. The second I/O is tried to submit to the bdev layer, but LUN is already removed,
   and so free the secondary iSCSI task.
7. Then the reference count of the primary iSCSI task becomes zero,
   and its bdev_io is freed. However, LUN I/O channel is already freed and freeing
   bdev_io fails.

This issue is caused by separating iSCSI task allocation and submission.

For write I/O, we don't have to keep bdev_io after getting completion
of it from the bdev layer.

This applies to other non-read I/O types.

So for non-read I/O, free bdev_io after getting SCSI status in
bdev_scsi_task_complete_cmd(), and for read I/O, set bdev_io to
task as same as before.

The next patch will do the same for management task.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I530fb491514880ce41858e1bea55d422d606dfc4
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471695
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
2019-10-22 17:20:51 +00:00
..
bdev bdev: Fix wrong IO split when child iovs run out 2019-10-11 00:35:34 +00:00
blob ut/cunit: added missing semicolon on CU_ASSERT macros 2019-07-24 18:21:22 +00:00
blobfs blobfs/fuse: put FUSE code in module blobfs_bdev 2019-10-15 16:25:09 +00:00
event RPC: rename start_subsystem_init to framework_start_init 2019-09-30 21:13:41 +00:00
ftl lib/ftl: track defragged bands in ftl_reloc 2019-08-27 18:55:40 +00:00
ioat test/unit: remove duplicate mk/spdk.common.mk includes 2019-02-11 09:30:27 +00:00
iscsi lib/scsi: Check pending tasks for the SCSI device only from the specific initiator 2019-10-18 17:30:13 +00:00
json ut/cunit: added missing semicolon on CU_ASSERT macros 2019-07-24 18:21:22 +00:00
jsonrpc jsonrpc: always allocate response for request 2019-07-19 20:56:54 +00:00
log log: passing user-defined log 2019-06-18 03:56:50 +00:00
lvol ut/lvol: fixed scan-build error on spdk_bs_init 2019-07-01 13:08:33 +00:00
notify lib/notify: rename spdk_notify_get_events to spdk_notify_foreach_event 2019-05-07 06:11:27 +00:00
nvme test/nvme: Add test_doorbell_buffer_config for nvme_ctrlr_cmd. 2019-10-11 18:47:06 +00:00
nvmf rdma: Add tests for spdk_nvmf_rdma_request_parse_sgl with metadata 2019-10-18 17:28:52 +00:00
reduce test/reduce: support iovecs in compress/decompress UT 2019-08-21 22:09:32 +00:00
scsi lib/scsi: Free bdev_io just after getting completion from bdev for non-read I/O 2019-10-22 17:20:51 +00:00
sock sock: Add a function to check if a socket is connected 2019-10-15 16:35:09 +00:00
thread thread: Add a mechanism to exit a lightweight thread 2019-05-22 04:23:17 +00:00
util test/unit: add test for base64 with Arm NEON intrinsics 2019-09-09 05:40:57 +00:00
vhost test/vhost: Remove event function stubs 2019-09-18 16:45:05 +00:00
json_mock.c subsystem: add per module configuration dump 2018-03-23 02:47:40 -04:00
Makefile bdev/nvme: always enable FTL 2019-05-02 08:41:56 +00:00