Skip to content

Commit fc09acb

Browse files
doug-gilbertmartinkpetersen
authored andcommitted
scsi: scsi_debug: Fix cmd_per_lun, set to max_queue
Make sure that the cmd_per_lun value placed in the host template never exceeds the can_queue value. If the max_queue driver parameter is not specified then both cmd_per_lun and can_queue are set to CAN_QUEUE. CAN_QUEUE is a compile time constant and is used to dimension an array to hold queued requests. If the max_queue driver parameter is given it is must be less than or equal to CAN_QUEUE and if so, the host template values are adjusted. Remove undocumented code that allowed queue_depth to exceed CAN_QUEUE and cause stack full type errors. There is a documented way to do that with every_nth and echo 0x8000 > /sys/bus/pseudo/drivers/scsi_debug/opts See: https://sg.danny.cz/sg/scsi_debug.html Tweak some formatting, and add a suggestion to the "trim poll_queues" warning. Link: https://lore.kernel.org/r/[email protected] Reported-by: Kashyap Desai <[email protected]> Reviewed-by: John Garry <[email protected]> Signed-off-by: Douglas Gilbert <[email protected]> Signed-off-by: John Garry <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ce4f62f commit fc09acb

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static const char *sdebug_version_date = "20200710";
218218
*/
219219
#define SDEBUG_CANQUEUE_WORDS 3 /* a WORD is bits in a long */
220220
#define SDEBUG_CANQUEUE (SDEBUG_CANQUEUE_WORDS * BITS_PER_LONG)
221-
#define DEF_CMD_PER_LUN 255
221+
#define DEF_CMD_PER_LUN SDEBUG_CANQUEUE
222222

223223
/* UA - Unit Attention; SA - Service Action; SSU - Start Stop Unit */
224224
#define F_D_IN 1 /* Data-in command (e.g. READ) */
@@ -5695,8 +5695,8 @@ MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
56955695
MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
56965696
MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
56975697
MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
5698-
MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
56995698
MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
5699+
MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
57005700
MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to max(def))");
57015701
MODULE_PARM_DESC(medium_error_count, "count of sectors to return follow on MEDIUM error");
57025702
MODULE_PARM_DESC(medium_error_start, "starting sector number to return MEDIUM error");
@@ -5710,7 +5710,7 @@ MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent
57105710
MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
57115711
MODULE_PARM_DESC(per_host_store, "If set, next positive add_host will get new store (def=0)");
57125712
MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
5713-
MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1)");
5713+
MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))");
57145714
MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
57155715
MODULE_PARM_DESC(random, "If set, uniformly randomize command duration between 0 and delay_in_ns");
57165716
MODULE_PARM_DESC(removable, "claim to have removable media (def=0)");
@@ -7165,12 +7165,15 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
71657165
}
71667166
num_in_q = atomic_read(&devip->num_in_q);
71677167

7168+
if (qdepth > SDEBUG_CANQUEUE) {
7169+
qdepth = SDEBUG_CANQUEUE;
7170+
pr_warn("%s: requested qdepth [%d] exceeds canqueue [%d], trim\n", __func__,
7171+
qdepth, SDEBUG_CANQUEUE);
7172+
}
71687173
if (qdepth < 1)
71697174
qdepth = 1;
7170-
/* allow to exceed max host qc_arr elements for testing */
7171-
if (qdepth > SDEBUG_CANQUEUE + 10)
7172-
qdepth = SDEBUG_CANQUEUE + 10;
7173-
scsi_change_queue_depth(sdev, qdepth);
7175+
if (qdepth != sdev->queue_depth)
7176+
scsi_change_queue_depth(sdev, qdepth);
71747177

71757178
if (SDEBUG_OPT_Q_NOISE & sdebug_opts) {
71767179
sdev_printk(KERN_INFO, sdev, "%s: qdepth=%d, num_in_q=%d\n",
@@ -7558,6 +7561,7 @@ static int sdebug_driver_probe(struct device *dev)
75587561
sdbg_host = to_sdebug_host(dev);
75597562

75607563
sdebug_driver_template.can_queue = sdebug_max_queue;
7564+
sdebug_driver_template.cmd_per_lun = sdebug_max_queue;
75617565
if (!sdebug_clustering)
75627566
sdebug_driver_template.dma_boundary = PAGE_SIZE - 1;
75637567

@@ -7593,7 +7597,11 @@ static int sdebug_driver_probe(struct device *dev)
75937597
* If condition not met, trim poll_queues to 1 (just for simplicity).
75947598
*/
75957599
if (poll_queues >= submit_queues) {
7596-
pr_warn("%s: trim poll_queues to 1\n", my_name);
7600+
if (submit_queues < 3)
7601+
pr_warn("%s: trim poll_queues to 1\n", my_name);
7602+
else
7603+
pr_warn("%s: trim poll_queues to 1. Perhaps try poll_queues=%d\n",
7604+
my_name, submit_queues - 1);
75977605
poll_queues = 1;
75987606
}
75997607
if (poll_queues)

0 commit comments

Comments
 (0)