Commit 67da413f authored by Douglas Gilbert's avatar Douglas Gilbert Committed by Martin K. Petersen

scsi: scsi_debug: Weaken rwlock around ramdisk access

The design of this driver is to do any ramdisk access on the same thread
that invoked the queuecommand() call. That is assumed to be user space
context. The command duration is implemented by setting the delay with a
high resolution timer. The hr timer's callback may well be in interrupt
context, but it doesn't touch the ramdisk. So try removing the
_irqsave()/_irqrestore() portion on the read-write lock that protects
ramdisk access.

Link: https://lore.kernel.org/r/20200421151424.32668-5-dgilbert@interlog.comSigned-off-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent c3e2fe92
...@@ -2740,7 +2740,6 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -2740,7 +2740,6 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
u32 num; u32 num;
u32 ei_lba; u32 ei_lba;
int ret; int ret;
unsigned long iflags;
u64 lba; u64 lba;
struct sdeb_store_info *sip = devip2sip(devip); struct sdeb_store_info *sip = devip2sip(devip);
rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck;
...@@ -2827,21 +2826,21 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -2827,21 +2826,21 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
return check_condition_result; return check_condition_result;
} }
read_lock_irqsave(macc_lckp, iflags); read_lock(macc_lckp);
/* DIX + T10 DIF */ /* DIX + T10 DIF */
if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
int prot_ret = prot_verify_read(scp, lba, num, ei_lba); int prot_ret = prot_verify_read(scp, lba, num, ei_lba);
if (prot_ret) { if (prot_ret) {
read_unlock_irqrestore(macc_lckp, iflags); read_unlock(macc_lckp);
mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, prot_ret); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, prot_ret);
return illegal_condition_result; return illegal_condition_result;
} }
} }
ret = do_device_access(sip, scp, 0, lba, num, false); ret = do_device_access(sip, scp, 0, lba, num, false);
read_unlock_irqrestore(macc_lckp, iflags); read_unlock(macc_lckp);
if (unlikely(ret == -1)) if (unlikely(ret == -1))
return DID_ERROR << 16; return DID_ERROR << 16;
...@@ -3050,7 +3049,6 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3050,7 +3049,6 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
u32 num; u32 num;
u32 ei_lba; u32 ei_lba;
int ret; int ret;
unsigned long iflags;
u64 lba; u64 lba;
struct sdeb_store_info *sip = devip2sip(devip); struct sdeb_store_info *sip = devip2sip(devip);
rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck;
...@@ -3110,14 +3108,14 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3110,14 +3108,14 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
ret = check_device_access_params(scp, lba, num, true); ret = check_device_access_params(scp, lba, num, true);
if (ret) if (ret)
return ret; return ret;
write_lock_irqsave(macc_lckp, iflags); write_lock(macc_lckp);
/* DIX + T10 DIF */ /* DIX + T10 DIF */
if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
int prot_ret = prot_verify_write(scp, lba, num, ei_lba); int prot_ret = prot_verify_write(scp, lba, num, ei_lba);
if (prot_ret) { if (prot_ret) {
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, prot_ret); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, prot_ret);
return illegal_condition_result; return illegal_condition_result;
} }
...@@ -3126,7 +3124,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3126,7 +3124,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
ret = do_device_access(sip, scp, 0, lba, num, true); ret = do_device_access(sip, scp, 0, lba, num, true);
if (unlikely(scsi_debug_lbp())) if (unlikely(scsi_debug_lbp()))
map_region(sip, lba, num); map_region(sip, lba, num);
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
if (unlikely(-1 == ret)) if (unlikely(-1 == ret))
return DID_ERROR << 16; return DID_ERROR << 16;
else if (unlikely(sdebug_verbose && else if (unlikely(sdebug_verbose &&
...@@ -3175,7 +3173,6 @@ static int resp_write_scat(struct scsi_cmnd *scp, ...@@ -3175,7 +3173,6 @@ static int resp_write_scat(struct scsi_cmnd *scp,
u32 lb_size = sdebug_sector_size; u32 lb_size = sdebug_sector_size;
u32 ei_lba; u32 ei_lba;
u64 lba; u64 lba;
unsigned long iflags;
int ret, res; int ret, res;
bool is_16; bool is_16;
static const u32 lrd_size = 32; /* + parameter list header size */ static const u32 lrd_size = 32; /* + parameter list header size */
...@@ -3237,7 +3234,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, ...@@ -3237,7 +3234,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
goto err_out; goto err_out;
} }
write_lock_irqsave(macc_lckp, iflags); write_lock(macc_lckp);
sg_off = lbdof_blen; sg_off = lbdof_blen;
/* Spec says Buffer xfer Length field in number of LBs in dout */ /* Spec says Buffer xfer Length field in number of LBs in dout */
cum_lb = 0; cum_lb = 0;
...@@ -3320,7 +3317,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, ...@@ -3320,7 +3317,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
} }
ret = 0; ret = 0;
err_out_unlock: err_out_unlock:
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
err_out: err_out:
kfree(lrdp); kfree(lrdp);
return ret; return ret;
...@@ -3329,7 +3326,6 @@ static int resp_write_scat(struct scsi_cmnd *scp, ...@@ -3329,7 +3326,6 @@ static int resp_write_scat(struct scsi_cmnd *scp,
static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
u32 ei_lba, bool unmap, bool ndob) u32 ei_lba, bool unmap, bool ndob)
{ {
unsigned long iflags;
unsigned long long i; unsigned long long i;
u64 block, lbaa; u64 block, lbaa;
u32 lb_size = sdebug_sector_size; u32 lb_size = sdebug_sector_size;
...@@ -3344,7 +3340,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ...@@ -3344,7 +3340,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
if (ret) if (ret)
return ret; return ret;
write_lock_irqsave(macc_lckp, iflags); write_lock(macc_lckp);
if (unmap && scsi_debug_lbp()) { if (unmap && scsi_debug_lbp()) {
unmap_region(sip, lba, num); unmap_region(sip, lba, num);
...@@ -3362,7 +3358,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ...@@ -3362,7 +3358,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
ret = fetch_to_dev_buffer(scp, fs1p, lb_size); ret = fetch_to_dev_buffer(scp, fs1p, lb_size);
if (-1 == ret) { if (-1 == ret) {
write_unlock_irqrestore(&sip->macc_lck, iflags); write_unlock(&sip->macc_lck);
return DID_ERROR << 16; return DID_ERROR << 16;
} else if (sdebug_verbose && !ndob && (ret < lb_size)) } else if (sdebug_verbose && !ndob && (ret < lb_size))
sdev_printk(KERN_INFO, scp->device, sdev_printk(KERN_INFO, scp->device,
...@@ -3378,7 +3374,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ...@@ -3378,7 +3374,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num,
if (scsi_debug_lbp()) if (scsi_debug_lbp())
map_region(sip, lba, num); map_region(sip, lba, num);
out: out:
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
return 0; return 0;
} }
...@@ -3496,7 +3492,6 @@ static int resp_comp_write(struct scsi_cmnd *scp, ...@@ -3496,7 +3492,6 @@ static int resp_comp_write(struct scsi_cmnd *scp,
u32 dnum; u32 dnum;
u32 lb_size = sdebug_sector_size; u32 lb_size = sdebug_sector_size;
u8 num; u8 num;
unsigned long iflags;
int ret; int ret;
int retval = 0; int retval = 0;
...@@ -3525,7 +3520,7 @@ static int resp_comp_write(struct scsi_cmnd *scp, ...@@ -3525,7 +3520,7 @@ static int resp_comp_write(struct scsi_cmnd *scp,
return check_condition_result; return check_condition_result;
} }
write_lock_irqsave(macc_lckp, iflags); write_lock(macc_lckp);
ret = do_dout_fetch(scp, dnum, arr); ret = do_dout_fetch(scp, dnum, arr);
if (ret == -1) { if (ret == -1) {
...@@ -3543,7 +3538,7 @@ static int resp_comp_write(struct scsi_cmnd *scp, ...@@ -3543,7 +3538,7 @@ static int resp_comp_write(struct scsi_cmnd *scp,
if (scsi_debug_lbp()) if (scsi_debug_lbp())
map_region(sip, lba, num); map_region(sip, lba, num);
cleanup: cleanup:
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
kfree(arr); kfree(arr);
return retval; return retval;
} }
...@@ -3562,8 +3557,6 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3562,8 +3557,6 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck; rwlock_t *macc_lckp = sip ? &sip->macc_lck : &sdeb_fake_rw_lck;
unsigned int i, payload_len, descriptors; unsigned int i, payload_len, descriptors;
int ret; int ret;
unsigned long iflags;
if (!scsi_debug_lbp()) if (!scsi_debug_lbp())
return 0; /* fib and say its done */ return 0; /* fib and say its done */
...@@ -3590,7 +3583,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3590,7 +3583,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
desc = (void *)&buf[8]; desc = (void *)&buf[8];
write_lock_irqsave(macc_lckp, iflags); write_lock(macc_lckp);
for (i = 0 ; i < descriptors ; i++) { for (i = 0 ; i < descriptors ; i++) {
unsigned long long lba = get_unaligned_be64(&desc[i].lba); unsigned long long lba = get_unaligned_be64(&desc[i].lba);
...@@ -3606,7 +3599,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3606,7 +3599,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
ret = 0; ret = 0;
out: out:
write_unlock_irqrestore(macc_lckp, iflags); write_unlock(macc_lckp);
kfree(buf); kfree(buf);
return ret; return ret;
...@@ -3789,7 +3782,6 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3789,7 +3782,6 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
int ret, j; int ret, j;
u32 vnum, a_num, off; u32 vnum, a_num, off;
const u32 lb_size = sdebug_sector_size; const u32 lb_size = sdebug_sector_size;
unsigned long iflags;
u64 lba; u64 lba;
u8 *arr; u8 *arr;
u8 *cmd = scp->cmnd; u8 *cmd = scp->cmnd;
...@@ -3831,7 +3823,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3831,7 +3823,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
return check_condition_result; return check_condition_result;
} }
/* Not changing store, so only need read access */ /* Not changing store, so only need read access */
read_lock_irqsave(macc_lckp, iflags); read_lock(macc_lckp);
ret = do_dout_fetch(scp, a_num, arr); ret = do_dout_fetch(scp, a_num, arr);
if (ret == -1) { if (ret == -1) {
...@@ -3853,7 +3845,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ...@@ -3853,7 +3845,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
goto cleanup; goto cleanup;
} }
cleanup: cleanup:
read_unlock_irqrestore(macc_lckp, iflags); read_unlock(macc_lckp);
kfree(arr); kfree(arr);
return ret; return ret;
} }
...@@ -4501,9 +4493,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, ...@@ -4501,9 +4493,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0; cmnd->result = pfp != NULL ? pfp(cmnd, devip) : 0;
if (cmnd->result & SDEG_RES_IMMED_MASK) { if (cmnd->result & SDEG_RES_IMMED_MASK) {
/*
* This is the F_DELAY_OVERR case. No delay.
*/
cmnd->result &= ~SDEG_RES_IMMED_MASK; cmnd->result &= ~SDEG_RES_IMMED_MASK;
delta_jiff = ndelay = 0; delta_jiff = ndelay = 0;
} }
...@@ -6126,7 +6115,7 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, ...@@ -6126,7 +6115,7 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
pfp = r_pfp; /* if leaf function ptr NULL, try the root's */ pfp = r_pfp; /* if leaf function ptr NULL, try the root's */
fini: fini:
if (F_DELAY_OVERR & flags) if (F_DELAY_OVERR & flags) /* cmds like INQUIRY respond asap */
return schedule_resp(scp, devip, errsts, pfp, 0, 0); return schedule_resp(scp, devip, errsts, pfp, 0, 0);
else if ((flags & F_LONG_DELAY) && (sdebug_jdelay > 0 || else if ((flags & F_LONG_DELAY) && (sdebug_jdelay > 0 ||
sdebug_ndelay > 10000)) { sdebug_ndelay > 10000)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment