Skip to contentSkip to conversation

vhost: fix unchecked return value

PATCH Superseded Jiayu Hu 3 participants 8 messages Jun 23, 2022 – Jul 1, 2022

lore
Share & tools
lore

Jiayu Hu

author
#0 lore raw

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

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")
---
 lib/vhost/vhost.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +5 -1
index b14521e4d1..70c04c036e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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 in rte_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
---
 lib/vhost/vhost.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +5 -1
index b14521e4d1..70c04c036e 100644
@@ -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

author
#2 lore raw

PATCH v2 1/1 vhost: fix unchecked return value

In reply to Jiayu Hu

This patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")

---
v2:
- add cc stable tag

---
 lib/vhost/vhost.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +5 -1
index b14521e4d1..70c04c036e 100644
@@ -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
#3 lore raw
Quoted 23 lines · Jiayu Hu

This patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")

---
v2:
- add cc stable tag

---
  lib/vhost/vhost.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
lib/vhost/vhost.c +0 -0
index b14521e4d1..70c04c036e 100644
@@ -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

author
#4 lore raw

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 value

lib/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 in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous

data-path")
Cc: [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..70c04c036e 100644

lib/vhost/vhost.c +0 -0
@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t

dma_id, uint16_t vchan_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 -1
  		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);

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 -0
  		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.

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

#5 lore raw
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 value

lib/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 in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous

data-path")
Cc: [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..70c04c036e 100644

lib/vhost/vhost.c +0 -0
@@ -1868,7 +1868,11 @@ rte_vhost_async_dma_configure(int16_t

dma_id, uint16_t vchan_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 -1
   		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);

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 -0
   		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.

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:

int
rte_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,
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

#6 lore raw
In reply to Jiayu Hu
Quoted 7 lines · Jiayu Hu

This patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous data-path")
Quoted 9 lines

---
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

author
#7 lore raw
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 value

Quoted 8 lines · Jiayu Hu

This patch checks the return value of rte_dma_info_get() called in rte_vhost_async_dma_configure().

Coverity issue: 379066

Fixes 53d3f4778c1d ("vhost: integrate dmadev in asynchronous

data-path")
Cc: [email protected]

Quoted 9 lines

---
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