diff options
| author | Niklas Cassel <cassel@kernel.org> | 2026-09-29 10:25:02 +0200 |
|---|---|---|
| committer | Martin K. Petersen (Oracle) <mkp@kernel.org> | 2026-10-03 10:14:29 -0400 |
| commit | 1809f9bf3da24d513613e3bfbb97db91fd4928b4 (patch) | |
| tree | d667d8bdc6ffbefa187b814d345b3883078cddcf | |
| parent | c9aedbcbff0fe31fabdea09600609eb30e05441d (diff) | |
| download | linux-next-1809f9bf3da24d513613e3bfbb97db91fd4928b4.tar.gz linux-next-1809f9bf3da24d513613e3bfbb97db91fd4928b4.zip | |
scsi: scsi_debug: Evaluate scsi_debug_lbp() only once
corrupt_lbas(), resp_write_dt0() and resp_write_same() call
scsi_debug_lbp() to decide whether to take the zone metadata lock, and call
it again to decide whether to touch the provisioning map that the lock
protects.
The result is not constant: scsi_debug_lbp() is false while fake_rw is set,
and fake_rw is writable at runtime, both as a module parameter and through
its driver attribute. The second call can therefore touch the map after the
first decided not to take the lock.
Call it once and use the result throughout.
Assisted-by: LLM
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: John Garry <john.garry@linux.dev>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Link: https://patch.msgid.link/20260929082456.857423-20-cassel@kernel.org
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
| -rw-r--r-- | drivers/scsi/scsi_debug.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 7152496952da..92458bf1568b 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4953,12 +4953,11 @@ static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num, { struct sdeb_store_info *sip = devip2sip(devip, false); bool meta_data_locked = false; + bool lbp = scsi_debug_lbp(); u32 block, num_mapped, b, i; int error = 0; - if (sdebug_dev_is_zoned(devip) || - sdebug_dix || - scsi_debug_lbp()) { + if (sdebug_dev_is_zoned(devip) || sdebug_dix || lbp) { sdeb_meta_write_lock(sip); meta_data_locked = true; } @@ -4975,8 +4974,7 @@ static int corrupt_lbas(struct sdebug_dev_info *devip, u64 lba, u32 num, goto out_unlock; } - if (scsi_debug_lbp() && - (!map_state(sip, lba, &num_mapped) || num > num_mapped)) { + if (lbp && (!map_state(sip, lba, &num_mapped) || num > num_mapped)) { pr_err("can't modify unmapped logical blocks: %llu:%u", lba, num); error = -EINVAL; @@ -5035,6 +5033,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; bool meta_data_locked = false; + bool lbp = scsi_debug_lbp(); if (unlikely(sdebug_opts & SDEBUG_OPT_UNALIGNED_WRITE && atomic_read(&sdeb_inject_pending))) { @@ -5101,8 +5100,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } if (sdebug_dev_is_zoned(devip) || - (sdebug_dix && scsi_prot_sg_count(scp)) || - scsi_debug_lbp()) { + (sdebug_dix && scsi_prot_sg_count(scp)) || lbp) { sdeb_meta_write_lock(sip); meta_data_locked = true; } @@ -5147,7 +5145,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } ret = do_device_access(sip, scp, 0, lba, num, group, true, false); - if (unlikely(scsi_debug_lbp())) + if (unlikely(lbp)) map_region(sip, lba, num); /* If ZBC zone then bump its write pointer */ @@ -5374,8 +5372,9 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u8 *fs1p; u8 *fsp; bool meta_data_locked = false; + bool lbp = scsi_debug_lbp(); - if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) { + if (sdebug_dev_is_zoned(devip) || lbp) { sdeb_meta_write_lock(sip); meta_data_locked = true; } @@ -5384,7 +5383,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, if (ret) goto out; - if (unmap && scsi_debug_lbp()) { + if (unmap && lbp) { unmap_region(sip, lba, num); goto out; } @@ -5414,7 +5413,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, block = do_div(lbaa, sdebug_store_sectors); memmove(fsp + (block * lb_size), fs1p, lb_size); } - if (scsi_debug_lbp()) + if (lbp) map_region(sip, lba, num); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) |
