[v2] vdpa/ifc: fix update_datapath error handling

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

Checks

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

Commit Message

Taekyung Kim Nov. 7, 2022, 5:34 a.m. UTC
  Stop and return the error code when 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.

Fixes: a3f8150eac6d ("net/ifcvf: add ifcvf vDPA driver")
Cc: stable@dpdk.org

Signed-off-by: Taekyung Kim <kim.tae.kyung@navercorp.com>
---
v2:
* Revert the prepared resources before returning an error
* Rebase to 22.11 rc2
* Add fixes and cc for backport

---
 drivers/vdpa/ifc/ifcvf_vdpa.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
  

Patch

diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c
index 8dfd49336e..e25fb16106 100644
--- a/drivers/vdpa/ifc/ifcvf_vdpa.c
+++ b/drivers/vdpa/ifc/ifcvf_vdpa.c
@@ -1098,7 +1098,11 @@  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 for vDPA device %s", vdev->device->name);
+		rte_atomic32_set(&internal->dev_attached, 0);
+		return -1;
+	}
 
 	hw = &internal->hw;
 	for (i = 0; i < hw->nr_vring; i++) {
@@ -1146,7 +1150,11 @@  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 for vDPA device %s", vdev->device->name);
+			internal->configured = 0;
+			return -1;
+		}
 	}
 
 	internal->configured = 0;
@@ -1752,7 +1760,14 @@  ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	}
 
 	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);
+		rte_atomic32_set(&internal->started, 0);
+		pthread_mutex_lock(&internal_list_lock);
+		TAILQ_REMOVE(&internal_list, list, next);
+		pthread_mutex_unlock(&internal_list_lock);
+		goto error;
+	}
 
 	rte_kvargs_free(kvlist);
 	return 0;
@@ -1781,7 +1796,9 @@  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);
+	}
 
 	rte_pci_unmap_device(internal->pdev);
 	rte_vfio_container_destroy(internal->vfio_container_fd);