Skip to content

Commit 223f91b

Browse files
doug-gilbertmartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix scp is NULL errors
John Garry reported 'sdebug_q_cmd_complete: scp is NULL' failures that were mainly seen on aarch64 machines (e.g. RPi 4 with four A72 CPUs). The problem was tracked down to a missing critical section on a "short circuit" path. Namely, the time to process the current command so far has already exceeded the requested command duration (i.e. the number of nanoseconds in the ndelay parameter). The random=1 parameter setting was pivotal in finding this error. The failure scenario involved first taking that "short circuit" path (due to a very short command duration) and then taking the more likely hrtimer_start() path (due to a longer command duration). With random=1 each command's duration is taken from the uniformly distributed [0..ndelay) interval. The fio utility also helped by reliably generating the error scenario at about once per minute on a RPi 4 (64 bit OS). Link: https://lore.kernel.org/r/[email protected] Reported-by: John Garry <[email protected]> Reviewed-by: Lee Duncan <[email protected]> Signed-off-by: Douglas Gilbert <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 2d9a2c5 commit 223f91b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,9 +5490,11 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
54905490
u64 d = ktime_get_boottime_ns() - ns_from_boot;
54915491

54925492
if (kt <= d) { /* elapsed duration >= kt */
5493+
spin_lock_irqsave(&sqp->qc_lock, iflags);
54935494
sqcp->a_cmnd = NULL;
54945495
atomic_dec(&devip->num_in_q);
54955496
clear_bit(k, sqp->in_use_bm);
5497+
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
54965498
if (new_sd_dp)
54975499
kfree(sd_dp);
54985500
/* call scsi_done() from this thread */

0 commit comments

Comments
 (0)