scsi: libsas: Reset num_scatter if libata mark qc as NODATA
Subsystems (2)
PATCH v2 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 updates code to handle ata non data commands separately so num_scatter and total_xfer_len remain 0.
---
v2:
- reorganized code to avoid setting num_scatter twice
drivers/scsi/libsas/sas_ata.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/scsi/libsas/sas_ata.c +4 -5
@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)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; - } - -if (qc->tf.protocol ==ATA_PROT_NODATA ) - task->data_dir =DMA_NONE ; -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
Jason Yan
reviewerQuoted 39 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning."
pm80xx_chip_sata_req6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"This patch updates code to handle ata non data commands separately so
num_scatterandtotal_xfer_lenremain 0.Fixes 53de092f47ff ("scsi: libsas: Set data_dir as DMA_NONE if libata marks qc as NODATA")Signed-off-by Jolly Shah <[email protected]>---
v2:
- reorganized code to avoid settingnum_scattertwicedrivers/scsi/libsas/sas_ata.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/scsi/libsas/sas_ata.c +0
-0
drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 206
Quoted 6 lines
drivers/scsi/libsas/sas_ata.c +3
-0@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)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 ;
Hi Jolly & John,
We only set DMA_NONE for ATA_PROT_NODATA, I'm curious about why ATA_PROT_NCQ_NODATA and ATAPI_PROT_NODATA do not need to set DMA_NONE?
Thanks,
Jason
Quoted 17 lines
drivers/scsi/libsas/sas_ata.c +1
-5}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; - } - -if (qc->tf.protocol ==ATA_PROT_NODATA ) - task->data_dir =DMA_NONE ; -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 ;
John Garry
Reviewed-byQuoted 25 lines · Jason Yan
Quoted 22 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning."
pm80xx_chip_sata_req6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"
Quoted 5 lines
Quoted 5 lines
This patch updates code to handle ata non data commands separately so
num_scatterandtotal_xfer_lenremain 0.Fixes 53de092f47ff ("scsi: libsas: Set data_dir as DMA_NONE if libata marks qc as NODATA")Signed-off-by Jolly Shah <[email protected]>
@luojiaxing, can you please test this?
Quoted 22 lines
Quoted 12 lines
---
v2:
- reorganized code to avoid settingnum_scattertwice
drivers/scsi/libsas/sas_ata.c| 9 ++++-----1 file changed, 4 insertions(+), 5 deletions(-)drivers/scsi/libsas/sas_ata.c +0
-0drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct · line 207
Quoted 7 lines
drivers/scsi/libsas/sas_ata.c +3
-0@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) 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;Hi Jolly & John,
Quoted 1 line
We only set
DMA_NONEforATA_PROT_NODATA, I'm curious about whyATA_PROT_NCQ_NODATAandATAPI_PROT_NODATAdo not need to setDMA_NONE?
So we can see something like atapi_eh_tur() -> ata_exec_internal(), which is a ATAPI NONDATA and has DMA_NONE, so should be ok.
Other cases, like those using the xlate function on the qc for ATA_PROT_NCQ_NODATA, could be checked further.
For now, we're just trying to fix the fix.
Quoted 22 lines
Thanks,
JasonQuoted 6 lines
drivers/scsi/libsas/sas_ata.c +0
-0} 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;drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 217
Quoted 10 lines
drivers/scsi/libsas/sas_ata.c +1
-5- } - - if (qc->tf.protocol == ATA_PROT_NODATA) - task->data_dir = DMA_NONE; - 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;.
Quoted 29 lines · John Garry
Quoted 28 lines · Jason Yan
Quoted 25 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning."
pm80xx_chip_sata_req6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"This patch updates code to handle ata non data commands separately so
num_scatterandtotal_xfer_lenremain 0.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Fixes 53de092f47ff ("scsi: libsas: Set data_dir as DMA_NONE if libata marks qc as NODATA")Signed-off-by Jolly Shah <[email protected]>Reviewed-by John Garry <[email protected]>@luojiaxing, can you please test this?
Sure, let me take a look, and reply the test result here later
Thanks
Jiaxing
Quoted 57 lines
Quoted 23 lines
Quoted 13 lines
---
v2:
- reorganized code to avoid settingnum_scattertwice
drivers/scsi/libsas/sas_ata.c| 9 ++++-----1 file changed, 4 insertions(+), 5 deletions(-)drivers/scsi/libsas/sas_ata.c +0
-0drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct · line 207
Quoted 7 lines
drivers/scsi/libsas/sas_ata.c +3
-0@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) 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;Hi Jolly & John,
Quoted 1 line
We only set
DMA_NONEforATA_PROT_NODATA, I'm curious about whyATA_PROT_NCQ_NODATAandATAPI_PROT_NODATAdo not need to setDMA_NONE?So we can see something like
atapi_eh_tur()->ata_exec_internal(), which is a ATAPI NONDATA and hasDMA_NONE, so should be ok.Other cases, like those using the xlate function on the qc for
ATA_PROT_NCQ_NODATA, could be checked further.For now, we're just trying to fix the fix.
Quoted 21 lines
Thanks,
JasonQuoted 6 lines
drivers/scsi/libsas/sas_ata.c +0
-0} 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;drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) · line 217
Quoted 10 lines
drivers/scsi/libsas/sas_ata.c +1
-5- } - - if (qc->tf.protocol == ATA_PROT_NODATA) - task->data_dir = DMA_NONE; - 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;Quoted 1 line
.
.
Hi Luojiaxing,
Quoted 38 lines · luojiaxing
Quoted 35 lines · John Garry
Quoted 33 lines · Jason Yan
Quoted 30 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately,
when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning."
pm80xx_chip_sata_req6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"This patch updates code to handle ata non data commands separately so
num_scatterandtotal_xfer_lenremain 0.Fixes 53de092f47ff ("scsi: libsas: Set data_dir as DMA_NONE iflibata marks qc as NODATA")
Signed-off-by Jolly Shah <[email protected]>
Quoted 7 lines
Quoted 3 lines
Reviewed-by John Garry <[email protected]>@luojiaxing, can you please test this?
Sure, let me take a look, and reply the test result here later
Wanted to follow up on test results. Any updates?
Thanks,
Jolly
Quoted 69 lines
Thanks
Jiaxing
Quoted 62 lines
Quoted 25 lines
Quoted 14 lines
---
v2:
- reorganized code to avoid settingnum_scattertwicedrivers/scsi/libsas/sas_ata.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/scsi/libsas/sas_ata.c +0
-0drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct · line 208
Quoted 8 lines
drivers/scsi/libsas/sas_ata.c +3
-0@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) 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 ;Hi Jolly & John,
Quoted 2 lines
We only set
DMA_NONEforATA_PROT_NODATA, I'm curious about whyATA_PROT_NCQ_NODATAandATAPI_PROT_NODATAdo not need to setDMA_NONE?So we can see something like
atapi_eh_tur()->ata_exec_internal(), which is a ATAPI NONDATA and hasDMA_NONE, so should be ok.Other cases, like those using the xlate function on the qc for
ATA_PROT_NCQ_NODATA, could be checked further.For now, we're just trying to fix the fix.
Quoted 21 lines
Thanks,
JasonQuoted 14 lines
drivers/scsi/libsas/sas_ata.c +1
-5}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; - } - -if (qc->tf.protocol ==ATA_PROT_NODATA ) - task->data_dir =DMA_NONE ; -else task->data_dir = qc->dma_dir; + } task->scatter = qc->sg; task->ata_task.retry_count =1 ;Quoted 2 lines
task->task_state_flags = SAS_TASK_STATE_PENDING;Quoted 1 line
.
.
luojiaxing
Tested-byQuoted 39 lines · Jolly Shah
Hi Luojiaxing,
Quoted 35 lines · luojiaxing
Quoted 33 lines · John Garry
Quoted 32 lines · Jason Yan
Quoted 30 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately,
when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning."
pm80xx_chip_sata_req6058: The sg list address start_addr=0x0000000000000000 data_len=0x0end_addr_high=0xffffffff end_addr_low=0xffffffff has crossed 4G boundary"This patch updates code to handle ata non data commands separately so
num_scatterandtotal_xfer_lenremain 0.Fixes 53de092f47ff ("scsi: libsas: Set data_dir as DMA_NONE iflibata marks qc as NODATA")
Signed-off-by Jolly Shah <[email protected]>
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Reviewed-by John Garry <[email protected]>@luojiaxing, can you please test this?
Sure, let me take a look, and reply the test result here later
Wanted to follow up on test results. Any updates?
Sorry for reply to you so late.
I use sdparm to change cache type of SATA disk, and it's ok with my test.
In addition, some other functional tests result have no problem too, So I think this patch is ok to me.
Thanks
Jiaxing
Quoted 68 lines
Thanks,
JollyQuoted 62 lines
Thanks
Jiaxing
Quoted 57 lines
Quoted 23 lines
Quoted 13 lines
---
v2:
- reorganized code to avoid settingnum_scattertwicedrivers/scsi/libsas/sas_ata.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/scsi/libsas/sas_ata.c +0
-0drivers/scsi/libsas/sas_ata.c static unsigned int sas_ata_qc_issue(struct · line 208
Quoted 8 lines
drivers/scsi/libsas/sas_ata.c +3
-0@@ -201,18 +201,17 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) 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 ;Hi Jolly & John,
Quoted 2 lines
We only set
DMA_NONEforATA_PROT_NODATA, I'm curious about whyATA_PROT_NCQ_NODATAandATAPI_PROT_NODATAdo not need to setDMA_NONE?So we can see something like
atapi_eh_tur()->ata_exec_internal(), which is a ATAPI NONDATA and hasDMA_NONE, so should be ok.Other cases, like those using the xlate function on the qc for
ATA_PROT_NCQ_NODATA, could be checked further.For now, we're just trying to fix the fix.
Quoted 20 lines
Thanks,
JasonQuoted 14 lines
drivers/scsi/libsas/sas_ata.c +1
-5}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; - } - -if (qc->tf.protocol ==ATA_PROT_NODATA ) - task->data_dir =DMA_NONE ; -else task->data_dir = qc->dma_dir; + } task->scatter = qc->sg; task->ata_task.retry_count =1 ;Quoted 2 lines
task->task_state_flags = SAS_TASK_STATE_PENDING;Quoted 1 line
.
.
.
Martin K. Petersen
AppliedQuoted 18 lines · Jolly Shah
When the
cache_typefor the scsi device is changed, the scsi layer issues aMODE_SELECTcommand. The caching mode details are communicated via a request buffer associated with the scsi command with data direction set asDMA_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 intoATA_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 performdma_map_sgon the scatterlist (ata_qc_issue). Unfortunately, when this command reaches the libsaslayer(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 withdma_map_sgfor a DMA operation. When this partially constructed SAS task reaches pm80xx LLDD, it results in below warning.
Quoted 1 line
[...]
Applied to 5.12/scsi-fixes, thanks!
[1/1] scsi: libsas: Reset num_scatter if libata mark qc as NODATA
https://git.kernel.org/mkp/scsi/c/176ddd89171d
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering