Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: core: Initialize scsi midlayer limits before allocating the queue

Turn __scsi_init_queue() into scsi_init_limits() which initializes
queue_limits structure that can be passed to blk_mq_alloc_queue().

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240409143748.980206-5-hch@lst.de
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Christoph Hellwig and committed by
Martin K. Petersen
afd53a3d 9042fb6d

+28 -27
+15 -17
drivers/scsi/scsi_lib.c
··· 32 32 #include <scsi/scsi_driver.h> 33 33 #include <scsi/scsi_eh.h> 34 34 #include <scsi/scsi_host.h> 35 - #include <scsi/scsi_transport.h> /* __scsi_init_queue() */ 35 + #include <scsi/scsi_transport.h> /* scsi_init_limits() */ 36 36 #include <scsi/scsi_dh.h> 37 37 38 38 #include <trace/events/scsi.h> ··· 1965 1965 blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); 1966 1966 } 1967 1967 1968 - void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) 1968 + void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim) 1969 1969 { 1970 1970 struct device *dev = shost->dma_dev; 1971 1971 1972 - /* 1973 - * this limit is imposed by hardware restrictions 1974 - */ 1975 - blk_queue_max_segments(q, min_t(unsigned short, shost->sg_tablesize, 1976 - SG_MAX_SEGMENTS)); 1972 + memset(lim, 0, sizeof(*lim)); 1973 + lim->max_segments = 1974 + min_t(unsigned short, shost->sg_tablesize, SG_MAX_SEGMENTS); 1977 1975 1978 1976 if (scsi_host_prot_dma(shost)) { 1979 1977 shost->sg_prot_tablesize = 1980 1978 min_not_zero(shost->sg_prot_tablesize, 1981 1979 (unsigned short)SCSI_MAX_PROT_SG_SEGMENTS); 1982 1980 BUG_ON(shost->sg_prot_tablesize < shost->sg_tablesize); 1983 - blk_queue_max_integrity_segments(q, shost->sg_prot_tablesize); 1981 + lim->max_integrity_segments = shost->sg_prot_tablesize; 1984 1982 } 1985 1983 1986 - blk_queue_max_hw_sectors(q, shost->max_sectors); 1987 - blk_queue_segment_boundary(q, shost->dma_boundary); 1988 - dma_set_seg_boundary(dev, shost->dma_boundary); 1989 - 1990 - blk_queue_max_segment_size(q, shost->max_segment_size); 1991 - blk_queue_virt_boundary(q, shost->virt_boundary_mask); 1992 - dma_set_max_seg_size(dev, queue_max_segment_size(q)); 1984 + lim->max_hw_sectors = shost->max_sectors; 1985 + lim->seg_boundary_mask = shost->dma_boundary; 1986 + lim->max_segment_size = shost->max_segment_size; 1987 + lim->virt_boundary_mask = shost->virt_boundary_mask; 1993 1988 1994 1989 /* 1995 1990 * Set a reasonable default alignment: The larger of 32-byte (dword), ··· 1993 1998 * 1994 1999 * Devices that require a bigger alignment can increase it later. 1995 2000 */ 1996 - blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1); 2001 + lim->dma_alignment = max(4, dma_get_cache_alignment()) - 1; 2002 + 2003 + dma_set_seg_boundary(dev, shost->dma_boundary); 2004 + dma_set_max_seg_size(dev, shost->max_segment_size); 1997 2005 } 1998 - EXPORT_SYMBOL_GPL(__scsi_init_queue); 2006 + EXPORT_SYMBOL_GPL(scsi_init_limits); 1999 2007 2000 2008 static const struct blk_mq_ops scsi_mq_ops_no_commit = { 2001 2009 .get_budget = scsi_mq_get_budget,
+3 -2
drivers/scsi/scsi_scan.c
··· 283 283 struct request_queue *q; 284 284 int display_failure_msg = 1, ret; 285 285 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 286 + struct queue_limits lim; 286 287 287 288 sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size, 288 289 GFP_KERNEL); ··· 333 332 334 333 sdev->sg_reserved_size = INT_MAX; 335 334 336 - q = blk_mq_alloc_queue(&sdev->host->tag_set, NULL, NULL); 335 + scsi_init_limits(shost, &lim); 336 + q = blk_mq_alloc_queue(&sdev->host->tag_set, &lim, NULL); 337 337 if (IS_ERR(q)) { 338 338 /* release fn is set up in scsi_sysfs_device_initialise, so 339 339 * have to free and put manually here */ ··· 345 343 kref_get(&sdev->host->tagset_refcnt); 346 344 sdev->request_queue = q; 347 345 q->queuedata = sdev; 348 - __scsi_init_queue(sdev->host, q); 349 346 350 347 depth = sdev->host->cmd_per_lun ?: 1; 351 348
+6 -5
drivers/scsi/scsi_transport_fc.c
··· 4276 4276 { 4277 4277 struct device *dev = &shost->shost_gendev; 4278 4278 struct fc_internal *i = to_fc_internal(shost->transportt); 4279 + struct queue_limits lim; 4279 4280 struct request_queue *q; 4280 4281 char bsg_name[20]; 4281 4282 ··· 4287 4286 4288 4287 snprintf(bsg_name, sizeof(bsg_name), 4289 4288 "fc_host%d", shost->host_no); 4290 - 4291 - q = bsg_setup_queue(dev, bsg_name, NULL, fc_bsg_dispatch, 4289 + scsi_init_limits(shost, &lim); 4290 + q = bsg_setup_queue(dev, bsg_name, &lim, fc_bsg_dispatch, 4292 4291 fc_bsg_job_timeout, i->f->dd_bsg_size); 4293 4292 if (IS_ERR(q)) { 4294 4293 dev_err(dev, ··· 4296 4295 shost->host_no); 4297 4296 return PTR_ERR(q); 4298 4297 } 4299 - __scsi_init_queue(shost, q); 4300 4298 blk_queue_rq_timeout(q, FC_DEFAULT_BSG_TIMEOUT); 4301 4299 fc_host->rqst_q = q; 4302 4300 return 0; ··· 4311 4311 { 4312 4312 struct device *dev = &rport->dev; 4313 4313 struct fc_internal *i = to_fc_internal(shost->transportt); 4314 + struct queue_limits lim; 4314 4315 struct request_queue *q; 4315 4316 4316 4317 rport->rqst_q = NULL; ··· 4319 4318 if (!i->f->bsg_request) 4320 4319 return -ENOTSUPP; 4321 4320 4322 - q = bsg_setup_queue(dev, dev_name(dev), NULL, fc_bsg_dispatch_prep, 4321 + scsi_init_limits(shost, &lim); 4322 + q = bsg_setup_queue(dev, dev_name(dev), &lim, fc_bsg_dispatch_prep, 4323 4323 fc_bsg_job_timeout, i->f->dd_bsg_size); 4324 4324 if (IS_ERR(q)) { 4325 4325 dev_err(dev, "failed to setup bsg queue\n"); 4326 4326 return PTR_ERR(q); 4327 4327 } 4328 - __scsi_init_queue(shost, q); 4329 4328 blk_queue_rq_timeout(q, BLK_DEFAULT_SG_TIMEOUT); 4330 4329 rport->rqst_q = q; 4331 4330 return 0;
+3 -2
drivers/scsi/scsi_transport_iscsi.c
··· 1535 1535 { 1536 1536 struct device *dev = &shost->shost_gendev; 1537 1537 struct iscsi_internal *i = to_iscsi_internal(shost->transportt); 1538 + struct queue_limits lim; 1538 1539 struct request_queue *q; 1539 1540 char bsg_name[20]; 1540 1541 ··· 1543 1542 return -ENOTSUPP; 1544 1543 1545 1544 snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no); 1546 - q = bsg_setup_queue(dev, bsg_name, NULL, iscsi_bsg_host_dispatch, NULL, 1545 + scsi_init_limits(shost, &lim); 1546 + q = bsg_setup_queue(dev, bsg_name, &lim, iscsi_bsg_host_dispatch, NULL, 1547 1547 0); 1548 1548 if (IS_ERR(q)) { 1549 1549 shost_printk(KERN_ERR, shost, "bsg interface failed to " 1550 1550 "initialize - no request queue\n"); 1551 1551 return PTR_ERR(q); 1552 1552 } 1553 - __scsi_init_queue(shost, q); 1554 1553 1555 1554 ihost->bsg_q = q; 1556 1555 return 0;
+1 -1
include/scsi/scsi_transport.h
··· 83 83 + shost->transportt->device_private_offset; 84 84 } 85 85 86 - void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q); 86 + void scsi_init_limits(struct Scsi_Host *shost, struct queue_limits *lim); 87 87 88 88 #endif /* SCSI_TRANSPORT_H */