scsi: esp: use sg helper to iterate over scatterlist

Unlike the legacy I/O path, scsi-mq preallocates a large array to hold
the scatterlist for each request. This static allocation can consume
substantial amounts of memory on modern controllers which support a
large number of concurrently outstanding requests.

To facilitate a switch to a smaller static allocation combined with a
dynamic allocation for requests that need it, we need to make sure all
SCSI drivers handle chained scatterlists correctly.

Convert remaining drivers that directly dereference the scatterlist
array to using the iterator functions.

[mkp: clarified commit message]

Cc: Christoph Hellwig <hch@lst.de>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Ewan D. Milne <emilne@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Finn Thain <fthain@telegraphics.com.au>
Cc: Guenter Roeck <linux@roeck-us.net>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Ming Lei 2019-06-06 16:34:10 +08:00 committed by Martin K. Petersen
parent 0e9fdd2b31
commit ee5a1dbfec
2 changed files with 15 additions and 7 deletions

View File

@ -370,6 +370,7 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd); struct esp_cmd_priv *spriv = ESP_CMD_PRIV(cmd);
struct scatterlist *sg = scsi_sglist(cmd); struct scatterlist *sg = scsi_sglist(cmd);
int total = 0, i; int total = 0, i;
struct scatterlist *s;
if (cmd->sc_data_direction == DMA_NONE) if (cmd->sc_data_direction == DMA_NONE)
return; return;
@ -380,16 +381,18 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
* a dma address, so perform an identity mapping. * a dma address, so perform an identity mapping.
*/ */
spriv->num_sg = scsi_sg_count(cmd); spriv->num_sg = scsi_sg_count(cmd);
for (i = 0; i < spriv->num_sg; i++) {
sg[i].dma_address = (uintptr_t)sg_virt(&sg[i]); scsi_for_each_sg(cmd, s, spriv->num_sg, i) {
total += sg_dma_len(&sg[i]); s->dma_address = (uintptr_t)sg_virt(s);
total += sg_dma_len(s);
} }
} else { } else {
spriv->num_sg = scsi_dma_map(cmd); spriv->num_sg = scsi_dma_map(cmd);
for (i = 0; i < spriv->num_sg; i++) scsi_for_each_sg(cmd, s, spriv->num_sg, i)
total += sg_dma_len(&sg[i]); total += sg_dma_len(s);
} }
spriv->cur_residue = sg_dma_len(sg); spriv->cur_residue = sg_dma_len(sg);
spriv->prv_sg = NULL;
spriv->cur_sg = sg; spriv->cur_sg = sg;
spriv->tot_residue = total; spriv->tot_residue = total;
} }
@ -443,7 +446,8 @@ static void esp_advance_dma(struct esp *esp, struct esp_cmd_entry *ent,
p->tot_residue = 0; p->tot_residue = 0;
} }
if (!p->cur_residue && p->tot_residue) { if (!p->cur_residue && p->tot_residue) {
p->cur_sg++; p->prv_sg = p->cur_sg;
p->cur_sg = sg_next(p->cur_sg);
p->cur_residue = sg_dma_len(p->cur_sg); p->cur_residue = sg_dma_len(p->cur_sg);
} }
} }
@ -464,6 +468,7 @@ static void esp_save_pointers(struct esp *esp, struct esp_cmd_entry *ent)
return; return;
} }
ent->saved_cur_residue = spriv->cur_residue; ent->saved_cur_residue = spriv->cur_residue;
ent->saved_prv_sg = spriv->prv_sg;
ent->saved_cur_sg = spriv->cur_sg; ent->saved_cur_sg = spriv->cur_sg;
ent->saved_tot_residue = spriv->tot_residue; ent->saved_tot_residue = spriv->tot_residue;
} }
@ -478,6 +483,7 @@ static void esp_restore_pointers(struct esp *esp, struct esp_cmd_entry *ent)
return; return;
} }
spriv->cur_residue = ent->saved_cur_residue; spriv->cur_residue = ent->saved_cur_residue;
spriv->prv_sg = ent->saved_prv_sg;
spriv->cur_sg = ent->saved_cur_sg; spriv->cur_sg = ent->saved_cur_sg;
spriv->tot_residue = ent->saved_tot_residue; spriv->tot_residue = ent->saved_tot_residue;
} }
@ -1646,7 +1652,7 @@ static int esp_msgin_process(struct esp *esp)
spriv = ESP_CMD_PRIV(ent->cmd); spriv = ESP_CMD_PRIV(ent->cmd);
if (spriv->cur_residue == sg_dma_len(spriv->cur_sg)) { if (spriv->cur_residue == sg_dma_len(spriv->cur_sg)) {
spriv->cur_sg--; spriv->cur_sg = spriv->prv_sg;
spriv->cur_residue = 1; spriv->cur_residue = 1;
} else } else
spriv->cur_residue++; spriv->cur_residue++;

View File

@ -251,6 +251,7 @@
struct esp_cmd_priv { struct esp_cmd_priv {
int num_sg; int num_sg;
int cur_residue; int cur_residue;
struct scatterlist *prv_sg;
struct scatterlist *cur_sg; struct scatterlist *cur_sg;
int tot_residue; int tot_residue;
}; };
@ -273,6 +274,7 @@ struct esp_cmd_entry {
struct scsi_cmnd *cmd; struct scsi_cmnd *cmd;
unsigned int saved_cur_residue; unsigned int saved_cur_residue;
struct scatterlist *saved_prv_sg;
struct scatterlist *saved_cur_sg; struct scatterlist *saved_cur_sg;
unsigned int saved_tot_residue; unsigned int saved_tot_residue;