vhost: fix unchecked return value
PATCH 1/1 vhost: fix unchecked return value
This patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().
Coverity issue: 379066
--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +5 -1
@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)return -1 ; } -rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { +VHOST_LOG_CONFIG (ERR ,"Fail to get DMA %d information.\n" , dma_id); +return -1 ; + } +if (vchan_id >= info.max_vchans) {VHOST_LOG_CONFIG (ERR ,"Invalid DMA %d vChannel %u.\n" , dma_id, vchan_id);return -1 ;
Signature · 1 line
2.25.1
Hi Jiayu,
Quoted 8 lines
-----Original Message-----
From: Hu, Jiayu <[email protected]>
Sent: Thursday, June 23, 2022 9:09 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH] vhost: fix unchecked return value
Quoted 5 lines
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")
Missed CC stable tag
With this fixed:
Quoted 28 lines
Signed-off-by Jiayu Hu <[email protected]>--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/vhost/vhost.c +5
-1@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)return -1 ; } -rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { +VHOST_LOG_CONFIG (ERR ,"Fail to get DMA %d information.\n" , dma_id); +return -1 ; + } +if (vchan_id >= info.max_vchans) {VHOST_LOG_CONFIG(ERR, "Invalid DMA %d vChannel %u.\n",
dma_id,vchan_id);
return -1;
--
2.25.1
PATCH v2 1/1 vhost: fix unchecked return value
In reply to Jiayu HuThis patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().
Coverity issue: 379066
---
v2:
- add cc stable tag
--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +5 -1
@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)return -1 ; } -rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { +VHOST_LOG_CONFIG (ERR ,"Fail to get DMA %d information.\n" , dma_id); +return -1 ; + } +if (vchan_id >= info.max_vchans) {VHOST_LOG_CONFIG (ERR ,"Invalid DMA %d vChannel %u.\n" , dma_id, vchan_id);return -1 ;
Signature · 1 line
2.25.1
Quoted 23 lines · Jiayu Hu
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")Signed-off-by Jiayu Hu <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
v2:
- add cc stable tag--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/vhost/vhost.c +0
-0@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)return -1 ; }
lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id) · line 1878
Quoted 10 lines
lib/vhost/vhost.c +5
-1-rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { +VHOST_LOG_CONFIG (ERR ,"Fail to get DMA %d information.\n" , dma_id); +return -1 ; + } +if (vchan_id >= info.max_vchans) {VHOST_LOG_CONFIG (ERR ,"Invalid DMA %d vChannel %u.\n" , dma_id, vchan_id);return -1 ;
The patch itself looks good, but rte_vhost_async_dma_configure() should be protected by a lock, as concurrent calls of this function would lead to undefined behavior.
Can you cook something?
David, is that the issue you mentioned me this week or was it another one?
Thanks,
Maxime
Hi Maxime,
Quoted 47 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, June 30, 2022 5:57 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]; David Marchand <[email protected]>
Subject: Re: [PATCH v2] vhost: fix unchecked return valuelib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t
Quoted 22 lines · Jiayu Hu
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronousdata-path")
Cc: [email protected]Signed-off-by Jiayu Hu <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
v2:
- add cc stable tag--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/vhost/vhost.c index renamed from lib/vhost/vhost.c +0
-0
b14521e4d1..70c04c036e100644lib/vhost/vhost.c +0
-0@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t
dma_id,uint16_tvchan_id)lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)
Quoted 6 lines
lib/vhost/vhost.c +2
-1return -1 ; } -rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { + VHOST_LOG_CONFIG(ERR, "Fail to get DMA %dinformation.\n",
dma_id);lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)
Quoted 5 lines
lib/vhost/vhost.c +3
-0+return -1 ; + } +if (vchan_id >= info.max_vchans) { VHOST_LOG_CONFIG(ERR, "Invalid DMA %d vChannel %u.\n",
dma_id,vchan_id);
Quoted 5 lines
lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t · line 1878
Quoted 1 line
lib/vhost/vhost.c +0
-0return -1 ;The patch itself looks good, but
rte_vhost_async_dma_configure()should be protected by a lock, as concurrent calls of this function would lead to undefined behavior.
This function is expected to be called only once. Is there any use case to cause it called concurrently?
Thanks,
Jiayu
Quoted 7 lines
Can you cook something?
David, is that the issue you mentioned me this week or was it another one?
Thanks,
Maxime
Quoted 49 lines · Jiayu
Hi Maxime,
Quoted 47 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Thursday, June 30, 2022 5:57 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]; David Marchand <[email protected]>
Subject: Re: [PATCH v2] vhost: fix unchecked return valuelib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t
Quoted 22 lines · Jiayu Hu
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronousdata-path")
Cc: [email protected]Signed-off-by Jiayu Hu <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
v2:
- add cc stable tag--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)lib/vhost/vhost.c index renamed from lib/vhost/vhost.c +0
-0
b14521e4d1..70c04c036e100644lib/vhost/vhost.c +0
-0@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t
dma_id,uint16_tvchan_id)lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)
Quoted 6 lines
lib/vhost/vhost.c +2
-1return -1 ; } -rte_dma_info_get (dma_id, &info); +if (rte_dma_info_get (dma_id, &info) !=0 ) { + VHOST_LOG_CONFIG(ERR, "Fail to get DMA %dinformation.\n",
dma_id);lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)
Quoted 5 lines
lib/vhost/vhost.c +3
-0+return -1 ; + } +if (vchan_id >= info.max_vchans) { VHOST_LOG_CONFIG(ERR, "Invalid DMA %d vChannel %u.\n",
dma_id,vchan_id);
Quoted 8 lines
Quoted 5 lines
lib/vhost/vhost.c rte_vhost_async_dma_configure(int16_t · line 1878
Quoted 1 line
lib/vhost/vhost.c +0
-0return -1 ;The patch itself looks good, but
rte_vhost_async_dma_configure()should be protected by a lock, as concurrent calls of this function would lead to undefined behavior.This function is expected to be called only once. Is there any use case to cause it called concurrently?
Ok, so what about:
================================================================
static bool dma_configured:
intrte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id)
{
struct rte_dma_info info;
void *pkts_cmpl_flag_addr;
uint16_t max_desc;
if (dma_configured)
return -1;
dma_configured = true;================================================================
If this is called only once, this should be OK. ;)
Maxime
Quoted 10 lines
Thanks,
JiayuQuoted 7 lines
Can you cook something?
David, is that the issue you mentioned me this week or was it another one?
Thanks,
Maxime
Maxime Coquelin
AppliedQuoted 7 lines · Jiayu Hu
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")
Quoted 9 lines
Signed-off-by Jiayu Hu <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
v2:
- add cc stable tag--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Applied to dpdk-next-virtio/main.
Please propose something to protect DMA channels registration & also consider introducing a function to unregister.
Thanks,
Maxime
Quoted 31 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Friday, July 1, 2022 10:00 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Xia, Chenbo <[email protected]>; [email protected]
Subject: Re: [PATCH v2] vhost: fix unchecked return valueQuoted 8 lines · Jiayu Hu
This patch checks the return value of
rte_dma_info_get()called inrte_vhost_async_dma_configure().Coverity issue: 379066
Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronousdata-path")
Cc: [email protected]Quoted 9 lines
Signed-off-by Jiayu Hu <[email protected]>Reviewed-by Chenbo Xia <[email protected]>---
v2:
- add cc stable tag--- lib/vhost/vhost.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 4 lines
Applied to dpdk-next-virtio/main.
Please propose something to protect DMA channels registration & also consider introducing a function to unregister.
Thanks Maxime. Will do.
Regards,
Jiayu
Quoted 3 lines
Thanks,
Maxime