Skip to contentSkip to conversation

scsi: libsas: Reset num_scatter if libata mark qc as NODATA

PATCH Superseded Jolly Shah 3 participants 7 messages Mar 16, 2021 – Mar 18, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jolly Shah

author
#0 lore raw

PATCH 1/1 scsi: libsas: Reset num_scatter if libata mark qc as NODATA

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
 drivers/scsi/libsas/sas_ata.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +4 -2
index 024e5a550759..94ec08cebbaa 100644
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
 		task->num_scatter = si;
 	}
 
-	if (qc->tf.protocol == ATA_PROT_NODATA)
+	if (qc->tf.protocol == ATA_PROT_NODATA) {
 		task->data_dir = DMA_NONE;
-	else
+		task->num_scatter = 0;
+	} else {
 		task->data_dir = qc->dma_dir;
+	}
 	task->scatter = qc->sg;
 	task->ata_task.retry_count = 1;
 	task->task_state_flags = SAS_TASK_STATE_PENDING;
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 40 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
  drivers/scsi/libsas/sas_ata.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -1
index 024e5a550759..94ec08cebbaa 100644
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
  		task->num_scatter = si;
  	}
 
-	if (qc->tf.protocol == ATA_PROT_NODATA)

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 220

Quoted 10 lines
drivers/scsi/libsas/sas_ata.c +4 -1
+	if (qc->tf.protocol == ATA_PROT_NODATA) {
  		task->data_dir = DMA_NONE;
-	else
+		task->num_scatter = 0;
+	} else {
  		task->data_dir = qc->dma_dir;
+	}
  	task->scatter = qc->sg;
  	task->ata_task.retry_count = 1;
  	task->task_state_flags = SAS_TASK_STATE_PENDING;

Thanks for the patch. Except the warning, any functional errors?

The code looks good to me,

author
#2 lore raw

Hi Jason,

Thanks for the review.

Quoted 41 lines · Jason Yan
Quoted 38 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
  drivers/scsi/libsas/sas_ata.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -0
index 024e5a550759..94ec08cebbaa 100644
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
              task->num_scatter = si;
      }
 
Quoted 15 lines

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 220

Quoted 12 lines
drivers/scsi/libsas/sas_ata.c +4 -2
-     if (qc->tf.protocol == ATA_PROT_NODATA)
+     if (qc->tf.protocol == ATA_PROT_NODATA) {
              task->data_dir = DMA_NONE;
-     else
+             task->num_scatter = 0;
+     } else {
              task->data_dir = qc->dma_dir;
+     }
      task->scatter = qc->sg;
      task->ata_task.retry_count = 1;
      task->task_state_flags = SAS_TASK_STATE_PENDING;

Thanks for the patch. Except the warning, any functional errors?

No functional errors observed.

Thanks,
Jolly Shah

Quoted 3 lines

The code looks good to me,

#3 lore raw
In reply to Jolly Shah
Quoted 4 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command

Quoted 8 lines

reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue).

So if we don't perform the dma_map_sg() on the sgl at this point, then it seems to me that we should not perform for_each_sg() on it either, right? That is still what happens in sas_ata_qc_issue() in this case.

Quoted 24 lines

Unfortunately,
when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
  drivers/scsi/libsas/sas_ata.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -0
index 024e5a550759..94ec08cebbaa 100644

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 214

Quoted 8 lines
drivers/scsi/libsas/sas_ata.c +2 -2
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
  		task->num_scatter = si;
  	}
 
-	if (qc->tf.protocol == ATA_PROT_NODATA)
+	if (qc->tf.protocol == ATA_PROT_NODATA) {
  		task->data_dir = DMA_NONE;
-	else
+		task->num_scatter = 0;

task->num_scatter has already been set in this function. Best not set it twice.

Thanks,
John

Quoted 7 lines
drivers/scsi/libsas/sas_ata.c +2 -0
+	} else {
  		task->data_dir = qc->dma_dir;
+	}
  	task->scatter = qc->sg;
  	task->ata_task.retry_count = 1;
  	task->task_state_flags = SAS_TASK_STATE_PENDING;
author
#4 lore raw

Hi John,

Thanks for the review.

Quoted 15 lines · John Garry
Quoted 4 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command

Quoted 8 lines

reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue).

Quoted 4 lines

So if we don't perform the dma_map_sg() on the sgl at this point, then it seems to me that we should not perform for_each_sg() on it either, right? That is still what happens in sas_ata_qc_issue() in this case.

Yes that's right. To avoid that, I can add elseif block for ATA_PROT_NODATA before for_each_sg() is performed. Currently there's existing code block for ATA_PROT_NODATA after for_each_sg() is performed,
reused that to reset num_scatter. Please suggest.

Quoted 27 lines
Quoted 27 lines

Unfortunately,
when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
  drivers/scsi/libsas/sas_ata.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -0
index 024e5a550759..94ec08cebbaa 100644
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
              task->num_scatter = si;
      }
 
Quoted 9 lines

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 214

Quoted 5 lines
drivers/scsi/libsas/sas_ata.c +2 -2
-     if (qc->tf.protocol == ATA_PROT_NODATA)
+     if (qc->tf.protocol == ATA_PROT_NODATA) {
              task->data_dir = DMA_NONE;
-     else
+             task->num_scatter = 0;

task->num_scatter has already been set in this function. Best not set it twice.

Sure. Please suggest if I should update patch to above suggested approach. That will avoid setting num_scatter twice.

Thanks,
Jolly Shah

Quoted 11 lines

Thanks,
John

Quoted 7 lines
drivers/scsi/libsas/sas_ata.c +2 -0
+     } else {
              task->data_dir = qc->dma_dir;
+     }
      task->scatter = qc->sg;
      task->ata_task.retry_count = 1;
      task->task_state_flags = SAS_TASK_STATE_PENDING;
#5 lore raw
Quoted 25 lines · Jolly Shah

Hi John,

Thanks for the review.

Quoted 19 lines · John Garry
Quoted 4 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command

Quoted 8 lines

reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue).

So if we don't perform the dma_map_sg() on the sgl at this point, then it seems to me that we should not perform for_each_sg() on it either, right? That is still what happens in sas_ata_qc_issue() in this case.

Hi Jolly Shah,

Quoted 7 lines

Yes that's right. To avoid that, I can add elseif block for ATA_PROT_NODATA before for_each_sg() is performed. Currently there's existing code block for ATA_PROT_NODATA after for_each_sg() is performed,
reused that to reset num_scatter. Please suggest.

How about just combine the 2x if-else statements into 1x if-elif-else statement, like:

if (ata_is_atapi(qc->tf.protocol)) {
	memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
	task->total_xfer_len = qc->nbytes;
	task->num_scatter = qc->n_elem;
	task->data_dir = qc->dma_dir;
} else if (qc->tf.protocol == ATA_PROT_NODATA) {
	task->data_dir = DMA_NONE;
} else {
	for_each_sg(qc->sg, sg, qc->n_elem, si)
		xfer += sg_dma_len(sg);

	task->total_xfer_len = xfer;
	task->num_scatter = si;
	task->data_dir = qc->dma_dir;
}
Quoted 37 lines
Quoted 27 lines
Quoted 27 lines

Unfortunately,
when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
   drivers/scsi/libsas/sas_ata.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -0
index 024e5a550759..94ec08cebbaa 100644
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
               task->num_scatter = si;
       }
 
Quoted 9 lines

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 214

Quoted 5 lines
drivers/scsi/libsas/sas_ata.c +2 -2
-     if (qc->tf.protocol == ATA_PROT_NODATA)
+     if (qc->tf.protocol == ATA_PROT_NODATA) {
               task->data_dir = DMA_NONE;
-     else
+             task->num_scatter = 0;

task->num_scatter has already been set in this function. Best not set it twice.

Quoted 3 lines

Sure. Please suggest if I should update patch to above suggested approach. That will avoid setting num_scatter twice.

Thanks,
John

BTW, could we add a fixes tag?

author
#6 lore raw

Hi John,

Quoted 42 lines · John Garry
Quoted 25 lines · Jolly Shah

Hi John,

Thanks for the review.

Quoted 19 lines · John Garry
Quoted 4 lines · Jolly Shah

When the cache_type for the scsi device is changed, the scsi layer issues a MODE_SELECT command. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set as DMA_TO_DEVICE (scsi_mode_select). When this command

Quoted 8 lines

reaches the libata layer, as a part of generic initial setup, libata layer sets up the scatterlist for the command using the scsi command (ata_scsi_qc_new). This command is then translated by the libata layer into ATA_CMD_SET_FEATURES (ata_scsi_mode_select_xlat). The libata layer treats this as a non data command (ata_mselect_caching), since it only needs an ata taskfile to pass the caching on/off information to the device. It does not need the scatterlist that has been setup, so it does not perform dma_map_sg on the scatterlist (ata_qc_issue).

So if we don't perform the dma_map_sg() on the sgl at this point, then it seems to me that we should not perform for_each_sg() on it either, right? That is still what happens in sas_ata_qc_issue() in this case.

Hi Jolly Shah,

Quoted 7 lines

Yes that's right. To avoid that, I can add elseif block for ATA_PROT_NODATA before for_each_sg() is performed. Currently there's existing code block for ATA_PROT_NODATA after for_each_sg() is performed,
reused that to reset num_scatter. Please suggest.

How about just combine the 2x if-else statements into 1x if-elif-else statement, like:

Quoted 16 lines
if (ata_is_atapi(qc->tf.protocol)) {
        memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
        task->total_xfer_len = qc->nbytes;
        task->num_scatter = qc->n_elem;
        task->data_dir = qc->dma_dir;
} else if (qc->tf.protocol == ATA_PROT_NODATA) {
        task->data_dir = DMA_NONE;
} else {
        for_each_sg(qc->sg, sg, qc->n_elem, si)
                xfer += sg_dma_len(sg);

        task->total_xfer_len = xfer;
        task->num_scatter = si;
        task->data_dir = qc->dma_dir;
}

Updated in v2.

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 24 lines

Unfortunately,
when this command reaches the libsas layer(sas_ata_qc_issue), libsas layer sees it as a non data command with a scatterlist. It cannot extract the correct dma length, since the scatterlist has not been mapped with dma_map_sg for a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.

"pm80xx_chip_sata_req 6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"

This patch assigns appropriate value to num_sectors for ata non data commands.

---
   drivers/scsi/libsas/sas_ata.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/scsi/libsas/sas_ata.c +0 -0
index 024e5a550759..94ec08cebbaa 100644

drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 214

Quoted 8 lines
drivers/scsi/libsas/sas_ata.c +2 -2
@@ -209,10 +209,12 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
               task->num_scatter = si;
       }
 
-     if (qc->tf.protocol == ATA_PROT_NODATA)
+     if (qc->tf.protocol == ATA_PROT_NODATA) {
               task->data_dir = DMA_NONE;
-     else
+             task->num_scatter = 0;

task->num_scatter has already been set in this function. Best not set it twice.

Quoted 8 lines
Quoted 3 lines

Sure. Please suggest if I should update patch to above suggested approach. That will avoid setting num_scatter twice.

Thanks,
John

BTW, could we add a fixes tag?

Added in v2.

Thanks,
Jolly