[v2,08/25] net/mlx5: make VLAN network interface thread safe
diff mbox series

Message ID 1603437295-119083-9-git-send-email-suanmingm@nvidia.com
State Superseded
Delegated to: Raslan Darawsheh
Headers show
Series
  • *net/mlx5: support multiple-thread flow operations
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Suanming Mou Oct. 23, 2020, 7:14 a.m. UTC
This commit protects the VLAN VM workaround area using a spinlock
in multiple-thread flow insertion to make it thread safe.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/common/mlx5/linux/mlx5_nl.h   | 1 +
 drivers/net/mlx5/linux/mlx5_vlan_os.c | 5 +++++
 2 files changed, 6 insertions(+)

Patch
diff mbox series

diff --git a/drivers/common/mlx5/linux/mlx5_nl.h b/drivers/common/mlx5/linux/mlx5_nl.h
index 53021e1..15129ff 100644
--- a/drivers/common/mlx5/linux/mlx5_nl.h
+++ b/drivers/common/mlx5/linux/mlx5_nl.h
@@ -25,6 +25,7 @@  struct mlx5_nl_vlan_dev {
 struct mlx5_nl_vlan_vmwa_context {
 	int nl_socket;
 	uint32_t vf_ifindex;
+	rte_spinlock_t sl;
 	struct mlx5_nl_vlan_dev vlan_dev[4096];
 };
 
diff --git a/drivers/net/mlx5/linux/mlx5_vlan_os.c b/drivers/net/mlx5/linux/mlx5_vlan_os.c
index 92fc17d..40e895e 100644
--- a/drivers/net/mlx5/linux/mlx5_vlan_os.c
+++ b/drivers/net/mlx5/linux/mlx5_vlan_os.c
@@ -44,12 +44,14 @@ 
 	if (!vlan->created || !vmwa)
 		return;
 	vlan->created = 0;
+	rte_spinlock_lock(&vmwa->sl);
 	MLX5_ASSERT(vlan_dev[vlan->tag].refcnt);
 	if (--vlan_dev[vlan->tag].refcnt == 0 &&
 	    vlan_dev[vlan->tag].ifindex) {
 		mlx5_nl_vlan_vmwa_delete(vmwa, vlan_dev[vlan->tag].ifindex);
 		vlan_dev[vlan->tag].ifindex = 0;
 	}
+	rte_spinlock_unlock(&vmwa->sl);
 }
 
 /**
@@ -72,6 +74,7 @@ 
 	MLX5_ASSERT(priv->vmwa_context);
 	if (vlan->created || !vmwa)
 		return;
+	rte_spinlock_lock(&vmwa->sl);
 	if (vlan_dev[vlan->tag].refcnt == 0) {
 		MLX5_ASSERT(!vlan_dev[vlan->tag].ifindex);
 		vlan_dev[vlan->tag].ifindex =
@@ -82,6 +85,7 @@ 
 		vlan_dev[vlan->tag].refcnt++;
 		vlan->created = 1;
 	}
+	rte_spinlock_unlock(&vmwa->sl);
 }
 
 /*
@@ -131,6 +135,7 @@ 
 			" for VLAN workaround context");
 		return NULL;
 	}
+	rte_spinlock_init(&vmwa->sl);
 	vmwa->nl_socket = mlx5_nl_init(NETLINK_ROUTE);
 	if (vmwa->nl_socket < 0) {
 		DRV_LOG(WARNING,