linux/drivers/target
Bodo Stroesser ed212ca878 scsi: target: tcmu: Fix and simplify timeout handling
During cmd timeout handling in check_timedout_devices(), due to a race, it
can happen that tcmu_set_next_deadline() does not start a timer as
expected:

 1) Either tcmu_check_expired_ring_cmd() checks the inflight_queue or
    tcmu_check_expired_queue_cmd() checks the qfull_queue while jiffies has
    the value X

 2) At the end of the check the queue contains one remaining command with
    deadline X (time_after(X, X) is false and thus the command is not
    handled as being timed out).

 3) After tcmu_check_expired_xxxxx_cmd() a timer interrupt happens and
    jiffies is incremented to X+1.

 4) Now tcmu_set_next_deadline() is called, but it skips the command, since
    time_after(X+1, X) is true. Therefore tcmu_set_next_deadline() finds no
    new deadline and stops the timer, which it shouldn't.

Since commands that time out are removed from inflight_queue or
qfull_queue, we don't need the check with time_after() in
tcmu_set_next_deadline() but can use the deadline from the first cmd in
the queue.

Additionally, replace the remaining time_after() calls in
tcmu_check_expired_xxxxx_cmd() with time_after_eq(), because it is not
useful to set the timeout to deadline but then check for jiffies being
greater than deadline.

Simplify the end of tcmu_handle_completions() and change the check for no
more pending commands from

	mb->cmd_tail == mb->cmd_head
to

	idr_is_empty(&udev->commands)

because the old check doesn't work correctly if paddings or in the future
TMRs are in the ring.

Finally tcmu_set_next_deadline() was shifted in the source as
preparation for later implementation of tmr_notify callback.

Link: https://lore.kernel.org/r/20200726153510.13077-7-bstroesser@ts.fujitsu.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2020-07-28 22:25:29 -04:00
..
iscsi scsi: target: iscsi: Fix inconsistent debug message 2020-07-28 22:15:31 -04:00
loopback scsi: target: loopback: Fix READ with data and sensebytes 2020-05-11 22:20:19 -04:00
sbp
tcm_fc scsi: libfc: remove unnecessary assertion on ep variable 2019-12-19 22:08:55 -05:00
Kconfig
Makefile
target_core_alua.c scsi: target: Make transport_flags per device 2020-05-07 22:39:21 -04:00
target_core_alua.h
target_core_configfs.c scsi: target: tcmu: Make pgr_support and alua_support attributes writable 2020-05-07 22:39:22 -04:00
target_core_device.c scsi: target: Initialize LUN in transport_init_se_cmd() 2020-06-09 21:57:26 -04:00
target_core_fabric_configfs.c
target_core_fabric_lib.c scsi: target: Handle short iSIDs 2020-07-08 00:14:34 -04:00
target_core_file.c
target_core_file.h
target_core_hba.c
target_core_iblock.c scsi: target/iblock: fix WRITE SAME zeroing 2020-04-22 00:02:13 -04:00
target_core_iblock.h
target_core_internal.h scsi: target: Fix xcopy sess release leak 2020-07-08 00:14:34 -04:00
target_core_pr.c scsi: target: Remove unused variable 'tpg' 2020-07-13 23:11:15 -04:00
target_core_pr.h
target_core_pscsi.c scsi: target: Make transport_flags per device 2020-05-07 22:39:21 -04:00
target_core_pscsi.h
target_core_rd.c
target_core_rd.h
target_core_sbc.c
target_core_spc.c scsi: target: use an enum to track emulate_ua_intlck_ctrl 2020-02-21 17:37:16 -05:00
target_core_stat.c
target_core_tmr.c scsi: target: Add tmr_notify backend function 2020-07-28 22:25:26 -04:00
target_core_tpg.c scsi: target: Make transport_flags per device 2020-05-07 22:39:21 -04:00
target_core_transport.c scsi: target: Add tmr_notify backend function 2020-07-28 22:25:26 -04:00
target_core_ua.c scsi: target: use an enum to track emulate_ua_intlck_ctrl 2020-02-21 17:37:16 -05:00
target_core_ua.h
target_core_user.c scsi: target: tcmu: Fix and simplify timeout handling 2020-07-28 22:25:29 -04:00
target_core_xcopy.c scsi: target: Fix xcopy sess release leak 2020-07-08 00:14:34 -04:00
target_core_xcopy.h scsi: target: use the stack for XCOPY passthrough cmds 2020-03-29 18:10:59 -04:00