Fix the assert failure in scsi_dma_complete
cover Fix the assert failure in scsi_dma_complete
Currently in 'megasas_map_sgl' when 'iov_count=0' will just return success however the 'cmd' doens't contain any iov. This will cause the assert in 'scsi_dma_complete' failed. This is because in 'dma_blk_cb' the 'dbs->sg_cur_index == dbs->sg->nsg' will be true and just call 'dma_complete'. However now there is no aiocb returned.
This is the LP#1878263:
-->https://bugs.launchpad.net/qemu/+bug/1878263
To solve this we will consider the 'iov_count=0' is an error. In the first patch, I uses -1 to indicate an error and in the second patch I consider 'iov_count=0' is an error.
Li Qiang (2):
hw: megasas: return -1 when 'megasas_map_sgl' fails
hw: megasas: consider 'iov_count=0' is an error in megasas_map_sgl
hw/scsi/megasas.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 hw: megasas: return -1 when 'megasas_map_sgl' fails
The caller of 'megasas_map_sgl' will only check if the return is zero or not. If it return 0 it means success, as in the next patch we will consider 'iov_count=0' is an error, so let's return -1 to indicate a failure.
--- hw/scsi/megasas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/scsi/megasas.c +2 -2
@@ -281,7 +281,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl)if (iov_count >MEGASAS_MAX_SGE ) {trace_megasas_iovec_sgl_overflow (cmd->index, iov_count,MEGASAS_MAX_SGE ); -return iov_count; +return -1 ; }pci_dma_sglist_init (&cmd->qsg,PCI_DEVICE (s), iov_count);for (i =0 ; i < iov_count; i++) {
@@ -311,7 +311,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl)return 0 ; unmap:qemu_sglist_destroy (&cmd->qsg); -return iov_count - i; +return -1 ; }/*
Signature · 1 line
2.17.1
PATCH 2/2 hw: megasas: consider 'iov_count=0' is an error in megasas_map_sgl
In reply to Li QiangCurrently in 'megasas_map_sgl' when 'iov_count=0' will just return success however the 'cmd' doens't contain any iov. This will cause the assert in 'scsi_dma_complete' failed. This is because in 'dma_blk_cb' the 'dbs->sg_cur_index == dbs->sg->nsg' will be true and just call 'dma_complete'. However now there is no aiocb returned.
This fixes the LP#1878263:
-->https://bugs.launchpad.net/qemu/+bug/1878263
--- hw/scsi/megasas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/megasas.c +1 -1
@@ -278,7 +278,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl) cmd->flags =le16_to_cpu (cmd->frame->header.flags); iov_count = cmd->frame->header.sge_count; -if (iov_count >MEGASAS_MAX_SGE ) { +if (!iov_count || iov_count >MEGASAS_MAX_SGE ) {trace_megasas_iovec_sgl_overflow (cmd->index, iov_count,MEGASAS_MAX_SGE );return -1 ;
Signature · 1 line
2.17.1
Re: [PATCH 2/2] hw: megasas: consider 'iov_count=0' is an error in megasas_map_sgl
Oh, sorry to forget to CC Alexander Bulekov.
Thanks,
Li Qiang
Quoted 33 lines · Li Qiang <[email protected]> 于2020年8月15日周六 下午10:20写道:
Currently in '
megasas_map_sgl' when 'iov_count=0' will just return success however the 'cmd' doens't contain any iov. This will cause the assert in 'scsi_dma_complete' failed. This is because in 'dma_blk_cb' the 'dbs->sg_cur_index==dbs->sg->nsg' will be true and just call 'dma_complete'. However now there is no aiocb returned.This fixes the LP#1878263:
-->https://bugs.launchpad.net/qemu/+bug/1878263
Reported-by Alexander Bulekov <[email protected]>Signed-off-by Li Qiang <[email protected]>--- hw/scsi/megasas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/scsi/megasas.c +1
-2@@ -278,7 +278,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl) cmd->flags =le16_to_cpu (cmd->frame->header.flags); iov_count = cmd->frame->header.sge_count; -if (iov_count >MEGASAS_MAX_SGE ) { +if (!iov_count || iov_count >MEGASAS_MAX_SGE ) {trace_megasas_iovec_sgl_overflow (cmd->index, iov_count,MEGASAS_MAX_SGE );return -1 ; --2.17.1
Quoted 14 lines · Li Qiang
Currently in '
megasas_map_sgl' when 'iov_count=0' will just return success however the 'cmd' doens't contain any iov. This will cause the assert in 'scsi_dma_complete' failed. This is because in 'dma_blk_cb' the 'dbs->sg_cur_index==dbs->sg->nsg' will be true and just call 'dma_complete'. However now there is no aiocb returned.This is the LP#1878263:
-->https://bugs.launchpad.net/qemu/+bug/1878263
To solve this we will consider the 'iov_count=0' is an error. In the first patch, I uses -1 to indicate an error and in the second patch I consider 'iov_count=0' is an error.
Quoted 7 lines
Li Qiang (2):
hw: megasas: return -1 when 'megasas_map_sgl' fails
hw: megasas: consider 'iov_count=0' is an error inmegasas_map_sglhw/scsi/megasas.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Queued, thanks. But do you have a qtest for this?
Paolo
Quoted 19 lines · Paolo Bonzini <[email protected]> 于2020年8月18日周二 上午1:05写道:
Quoted 18 lines · Li Qiang
Currently in '
megasas_map_sgl' when 'iov_count=0' will just return success however the 'cmd' doens't contain any iov. This will cause the assert in 'scsi_dma_complete' failed. This is because in 'dma_blk_cb' the 'dbs->sg_cur_index==dbs->sg->nsg' will be true and just call 'dma_complete'. However now there is no aiocb returned.This is the LP#1878263:
-->https://bugs.launchpad.net/qemu/+bug/1878263
To solve this we will consider the 'iov_count=0' is an error. In the first patch, I uses -1 to indicate an error and in the second patch I consider 'iov_count=0' is an error.
Li Qiang (2):
hw: megasas: return -1 when 'megasas_map_sgl' fails
hw: megasas: consider 'iov_count=0' is an error inmegasas_map_sgl
Quoted 6 lines
Quoted 3 lines
hw/scsi/megasas.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Queued, thanks. But do you have a qtest for this?
Okay, I will cook a qtest for this recently.
Thanks,
Li Qiang
Quoted 4 lines
Paolo