diff mbox series

[24/25] net/mlx5: make VLAN network interface thread safe

Message ID 1601984948-313027-25-git-send-email-suanmingm@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers show
Series net/mlx5: support multiple-thread flow operations | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Suanming Mou Oct. 6, 2020, 11:49 a.m. UTC
This commit takes advantage of the atomic operation with the VLAN VM
workaround object reference count to make sure the object to be thread
safe and not to be created or destroyed in parallel.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_vlan_os.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/mlx5/linux/mlx5_vlan_os.c b/drivers/net/mlx5/linux/mlx5_vlan_os.c
index 92fc17d..00e160f 100644
--- a/drivers/net/mlx5/linux/mlx5_vlan_os.c
+++ b/drivers/net/mlx5/linux/mlx5_vlan_os.c
@@ -45,10 +45,11 @@ 
 		return;
 	vlan->created = 0;
 	MLX5_ASSERT(vlan_dev[vlan->tag].refcnt);
-	if (--vlan_dev[vlan->tag].refcnt == 0 &&
-	    vlan_dev[vlan->tag].ifindex) {
+	if (!__atomic_sub_fetch(&vlan_dev[vlan->tag].refcnt,
+	    1, __ATOMIC_RELAXED)) {
 		mlx5_nl_vlan_vmwa_delete(vmwa, vlan_dev[vlan->tag].ifindex);
-		vlan_dev[vlan->tag].ifindex = 0;
+		__atomic_store_n(&vlan_dev[vlan->tag].ifindex,
+				 0, __ATOMIC_RELAXED);
 	}
 }
 
@@ -72,16 +73,21 @@ 
 	MLX5_ASSERT(priv->vmwa_context);
 	if (vlan->created || !vmwa)
 		return;
-	if (vlan_dev[vlan->tag].refcnt == 0) {
-		MLX5_ASSERT(!vlan_dev[vlan->tag].ifindex);
+	if (__atomic_add_fetch
+	    (&vlan_dev[vlan->tag].refcnt, 1, __ATOMIC_RELAXED) == 1) {
+		/* Make sure ifindex is destroyed. */
+		rte_wait_until_equal_32(&vlan_dev[vlan->tag].ifindex,
+					0, __ATOMIC_RELAXED);
 		vlan_dev[vlan->tag].ifindex =
 			mlx5_nl_vlan_vmwa_create(vmwa, vmwa->vf_ifindex,
 						 vlan->tag);
+		if (!vlan_dev[vlan->tag].ifindex) {
+			__atomic_store_n(&vlan_dev[vlan->tag].refcnt,
+					 0, __ATOMIC_RELAXED);
+			return;
+		}
 	}
-	if (vlan_dev[vlan->tag].ifindex) {
-		vlan_dev[vlan->tag].refcnt++;
-		vlan->created = 1;
-	}
+	vlan->created = 1;
 }
 
 /*