Skip to contentSkip to conversation

scsi_debug: Support configuring the maximum segment size

PATCH Superseded Bart Van Assche 2 participants 3 messages Mar 23 – Mar 24 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi_debug: Support configuring the maximum segment size

Add a kernel module parameter for configuring the maximum segment size. This patch enables testing SCSI support for segments smaller than the page size. A test that uses this functionality is available here:
https://lore.kernel.org/linux-block/[email protected]/

Cc John Garry <[email protected]>
Cc Doug Gilbert <[email protected]>
---
 drivers/scsi/scsi_debug.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/scsi_debug.c +4 -0
index 1515495fd9ea..641cc0e01dfc 100644
@@ -915,6 +915,7 @@ static int sdebug_host_max_queue;	/* per host */
 static int sdebug_lowest_aligned = DEF_LOWEST_ALIGNED;
 static int sdebug_max_luns = DEF_MAX_LUNS;
 static int sdebug_max_queue = SDEBUG_CANQUEUE;	/* per submit queue */
+static unsigned int sdebug_max_segment_size = BLK_MAX_SEGMENT_SIZE;
 static unsigned int sdebug_medium_error_start = OPT_MEDIUM_ERR_ADDR;
 static int sdebug_medium_error_count = OPT_MEDIUM_ERR_NUM;
 static int sdebug_ndelay = DEF_NDELAY;	/* if > 0 then unit is nanoseconds */
@@ -7366,6 +7367,7 @@ module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO);
 module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR);
 module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR);
 module_param_named(max_queue, sdebug_max_queue, int, S_IRUGO | S_IWUSR);
+module_param_named(max_segment_size, sdebug_max_segment_size, uint, S_IRUGO);
 module_param_named(medium_error_count, sdebug_medium_error_count, int,
 		   S_IRUGO | S_IWUSR);
 module_param_named(medium_error_start, sdebug_medium_error_start, int,
@@ -7449,6 +7451,7 @@ MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)");
 MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method");
 MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
 MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to max(def))");
+MODULE_PARM_DESC(max_segment_size, "max bytes in a single segment");
 MODULE_PARM_DESC(medium_error_count, "count of sectors to return follow on MEDIUM error");
 MODULE_PARM_DESC(medium_error_start, "starting sector number to return MEDIUM error");
 MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)");
@@ -9566,6 +9569,7 @@ static int sdebug_driver_probe(struct device *dev)
 	}
 	hpnt->can_queue = sdebug_max_queue;
 	hpnt->cmd_per_lun = sdebug_max_queue;
+	hpnt->max_segment_size = sdebug_max_segment_size;
 	if (!sdebug_clustering)
 		hpnt->dma_boundary = PAGE_SIZE - 1;
 
#1 lore raw
Quoted 8 lines · Bart Van Assche

Add a kernel module parameter for configuring the maximum segment size. This patch enables testing SCSI support for segments smaller than the page size. A test that uses this functionality is available here:
https://lore.kernel.org/linux-block/20260323200751.1238583-1- [email protected]/

Did you consider sanitizing this value? Maybe we should ensure that it is a power-of-2 or UINT_MAX or BLK_MAX_SEGMENT_SIZE

BTW, I don't think that we still need to set a value in sdebug_driver_template.max_segment_size now.

#2 lore raw
Quoted 1 line · John Garry

Did you consider sanitizing this value? Maybe we should ensure that it is a power-of-2 or UINT_MAX or BLK_MAX_SEGMENT_SIZE

That's a good question.

max_segment_size does not have to be a power of two. From drivers/ata/sata_inic162x.c:255:

	.max_segment_size	= 65536 - 512,

I think the only invalid value is zero. blk_validate_limits() considers zero as the default and changes it into something else (UINT_MAX or BLK_MAX_SEGMENT_SIZE).

Quoted 1 line

BTW, I don't think that we still need to set a value in sdebug_driver_template.max_segment_size now.

If nobody objects I will integrate the change below into this patch:

drivers/scsi/scsi_debug.c +0 -1
index 641cc0e01dfc..0d3e0ba537c4 100644
@@ -9542,7 +9542,6 @@ static const struct scsi_host_template sdebug_driver_template = {
        .sg_tablesize =         SG_MAX_SEGMENTS,
        .cmd_per_lun =          DEF_CMD_PER_LUN,
        .max_sectors =          -1U,
-       .max_segment_size =     -1U,
        .module =               THIS_MODULE,
        .skip_settle_delay =    1,
        .track_queue_depth =    1,

Thanks,

Bart.