vdpa/ifc: fix update_datapath error handling

Message ID 20221018072240.128791-1-kim.tae.kyung@navercorp.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series vdpa/ifc: fix update_datapath error handling |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Taekyung Kim Oct. 18, 2022, 7:22 a.m. UTC
  Stop and return the error code if update_datapath fails.
update_datapath prepares resources for the vdpa device.
The driver should not perform any further actions
if update_datapath returns an error.

Signed-off-by: Taekyung Kim <kim.tae.kyung@navercorp.com>
---
 drivers/vdpa/ifc/ifcvf_vdpa.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
  

Comments

Maxime Coquelin Nov. 2, 2022, 9:12 a.m. UTC | #1
Hi,

On 10/18/22 09:22, Taekyung Kim wrote:
> Stop and return the error code if update_datapath fails.
> update_datapath prepares resources for the vdpa device.
> The driver should not perform any further actions
> if update_datapath returns an error.

You need to add Fixes tag and Cc stable@dpdk.org, so that it is
backported to relevant LTS branches.

> 
> Signed-off-by: Taekyung Kim <kim.tae.kyung@navercorp.com>
> ---
>   drivers/vdpa/ifc/ifcvf_vdpa.c | 20 ++++++++++++++++----
>   1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
> index d5ac583589..795967e998 100644
> --- a/drivers/vdpa/ifc/ifcvf_vdpa.c
> +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
> @@ -1063,7 +1063,10 @@ ifcvf_dev_config(int vid)
>   	internal = list->internal;
>   	internal->vid = vid;
>   	rte_atomic32_set(&internal->dev_attached, 1);
> -	update_datapath(internal);
> +	if (update_datapath(internal) < 0) {
> +		DRV_LOG(ERR, "failed to update datapath: %p", vdev);
> +		return -1;
> +	}
>   
>   	if (rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true) != 0)
>   		DRV_LOG(NOTICE, "vDPA (%s): software relay is used.",
> @@ -1105,7 +1108,10 @@ ifcvf_dev_close(int vid)
>   		internal->sw_fallback_running = false;
>   	} else {
>   		rte_atomic32_set(&internal->dev_attached, 0);
> -		update_datapath(internal);
> +		if (update_datapath(internal) < 0) {
> +			DRV_LOG(ERR, "failed to update datapath: %p", vdev);
> +			return -1;
> +		}
>   	}
>   
>   	internal->configured = 0;
> @@ -1632,7 +1638,10 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
>   	pthread_mutex_unlock(&internal_list_lock);
>   
>   	rte_atomic32_set(&internal->started, 1);
> -	update_datapath(internal);
> +	if (update_datapath(internal) < 0) {
> +		DRV_LOG(ERR, "failed to update datapath: %s", pci_dev->name);
> +		return -1;
> +	}

This is not enough, you need to free resources allocated before,
otherwise you introduce memory leaks.

Basically, you should goto error instead o directly returning -1.

>   
>   	rte_kvargs_free(kvlist);
>   	return 0;
> @@ -1661,7 +1670,10 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev)
>   
>   	internal = list->internal;
>   	rte_atomic32_set(&internal->started, 0);
> -	update_datapath(internal);
> +	if (update_datapath(internal) < 0) {
> +		DRV_LOG(ERR, "failed to update datapath: %s", pci_dev->name);
> +		return -1;
> +	}

I think we should not return early here, because we still want to clean
as much as possible on remove. maybe just keep the error message.

>   	rte_pci_unmap_device(internal->pdev);
>   	rte_vfio_container_destroy(internal->vfio_container_fd);

Thanks,
Maxime
  

Patch

diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
index d5ac583589..795967e998 100644
--- a/drivers/vdpa/ifc/ifcvf_vdpa.c
+++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
@@ -1063,7 +1063,10 @@  ifcvf_dev_config(int vid)
 	internal = list->internal;
 	internal->vid = vid;
 	rte_atomic32_set(&internal->dev_attached, 1);
-	update_datapath(internal);
+	if (update_datapath(internal) < 0) {
+		DRV_LOG(ERR, "failed to update datapath: %p", vdev);
+		return -1;
+	}
 
 	if (rte_vhost_host_notifier_ctrl(vid, RTE_VHOST_QUEUE_ALL, true) != 0)
 		DRV_LOG(NOTICE, "vDPA (%s): software relay is used.",
@@ -1105,7 +1108,10 @@  ifcvf_dev_close(int vid)
 		internal->sw_fallback_running = false;
 	} else {
 		rte_atomic32_set(&internal->dev_attached, 0);
-		update_datapath(internal);
+		if (update_datapath(internal) < 0) {
+			DRV_LOG(ERR, "failed to update datapath: %p", vdev);
+			return -1;
+		}
 	}
 
 	internal->configured = 0;
@@ -1632,7 +1638,10 @@  ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	pthread_mutex_unlock(&internal_list_lock);
 
 	rte_atomic32_set(&internal->started, 1);
-	update_datapath(internal);
+	if (update_datapath(internal) < 0) {
+		DRV_LOG(ERR, "failed to update datapath: %s", pci_dev->name);
+		return -1;
+	}
 
 	rte_kvargs_free(kvlist);
 	return 0;
@@ -1661,7 +1670,10 @@  ifcvf_pci_remove(struct rte_pci_device *pci_dev)
 
 	internal = list->internal;
 	rte_atomic32_set(&internal->started, 0);
-	update_datapath(internal);
+	if (update_datapath(internal) < 0) {
+		DRV_LOG(ERR, "failed to update datapath: %s", pci_dev->name);
+		return -1;
+	}
 
 	rte_pci_unmap_device(internal->pdev);
 	rte_vfio_container_destroy(internal->vfio_container_fd);