DPDK patches and discussions
 help / color / Atom feed
From: Ajit Khaparde <ajit.khaparde@broadcom.com>
To: dev@dpdk.org
Cc: Kishore Padmanabha <kishore.padmanabha@broadcom.com>,
	Mike Baucom <michael.baucom@broadcom.com>,
	Shahaji Bhosle <sbhosle@broadcom.com>
Subject: [dpdk-dev] [PATCH 23/25] net/bnxt: add support for locks in flow database
Date: Thu, 10 Sep 2020 18:56:01 -0700
Message-ID: <20200911015603.88359-24-ajit.khaparde@broadcom.com> (raw)
In-Reply-To: <20200911015603.88359-1-ajit.khaparde@broadcom.com>

From: Kishore Padmanabha <kishore.padmanabha@broadcom.com>

Added support for mutex protection for the flow database to prevent
simultaneous access to flow database and protect flow creation and
deletion.

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Mike Baucom <michael.baucom@broadcom.com>
Reviewed-by: Shahaji Bhosle <sbhosle@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/bnxt_ulp.c    | 33 +++++++++++++++++++++++++++
 drivers/net/bnxt/tf_ulp/bnxt_ulp.h    |  7 ++++++
 drivers/net/bnxt/tf_ulp/ulp_flow_db.c | 13 ++++++++++-
 drivers/net/bnxt/tf_ulp/ulp_mapper.c  | 20 +++++++++++++++-
 4 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
index 364853a6e..e8927f629 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
@@ -727,6 +727,9 @@ bnxt_ulp_deinit(struct bnxt *bp,
 					 TF_TUNNEL_ENCAP_NAT,
 					 BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
 
+	/* free the flow db lock */
+	pthread_mutex_destroy(&bp->ulp_ctx->cfg_data->flow_db_lock);
+
 	/* Delete the ulp context and tf session and free the ulp context */
 	ulp_ctx_deinit(bp, session);
 	BNXT_TF_DBG(DEBUG, "ulp ctx has been deinitialized\n");
@@ -750,6 +753,12 @@ bnxt_ulp_init(struct bnxt *bp,
 		goto jump_to_error;
 	}
 
+	rc = pthread_mutex_init(&bp->ulp_ctx->cfg_data->flow_db_lock, NULL);
+	if (rc) {
+		BNXT_TF_DBG(ERR, "Unable to initialize flow db lock\n");
+		goto jump_to_error;
+	}
+
 	/* Initialize ulp dparms with values devargs passed */
 	rc = ulp_dparms_init(bp, bp->ulp_ctx);
 	if (rc) {
@@ -1235,3 +1244,27 @@ bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
 
 	return &ulp_ctx->cfg_data->vfr_rule_info[port_id];
 }
+
+/* Function to acquire the flow database lock from the ulp context. */
+int32_t
+bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context	*ulp_ctx)
+{
+	if (!ulp_ctx || !ulp_ctx->cfg_data)
+		return -1;
+
+	if (pthread_mutex_lock(&ulp_ctx->cfg_data->flow_db_lock)) {
+		BNXT_TF_DBG(ERR, "unable to acquire fdb lock\n");
+		return -1;
+	}
+	return 0;
+}
+
+/* Function to release the flow database lock from the ulp context. */
+void
+bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context	*ulp_ctx)
+{
+	if (!ulp_ctx || !ulp_ctx->cfg_data)
+		return;
+
+	pthread_mutex_unlock(&ulp_ctx->cfg_data->flow_db_lock);
+}
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.h b/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
index ed978734a..36405ae1e 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.h
@@ -47,6 +47,7 @@ struct bnxt_ulp_data {
 	uint32_t			dev_id; /* Hardware device id */
 	uint32_t			ref_cnt;
 	struct bnxt_ulp_flow_db		*flow_db;
+	pthread_mutex_t			flow_db_lock;
 	void				*mapper_data;
 	struct bnxt_ulp_port_db		*port_db;
 	struct bnxt_ulp_fc_info		*fc_info;
@@ -196,4 +197,10 @@ struct bnxt_ulp_vfr_rule_info*
 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
 				     uint32_t port_id);
 
+int32_t
+bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context	*ulp_ctx);
+
+void
+bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context	*ulp_ctx);
+
 #endif /* _BNXT_ULP_H_ */
diff --git a/drivers/net/bnxt/tf_ulp/ulp_flow_db.c b/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
index cbdf5df68..9a2d3758d 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_flow_db.c
@@ -793,10 +793,17 @@ int32_t	ulp_flow_db_flush_flows(struct bnxt_ulp_context *ulp_ctx,
 		BNXT_TF_DBG(ERR, "Flow database not found\n");
 		return -EINVAL;
 	}
+	if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+		BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+		return -EINVAL;
+	}
+
 	flow_tbl = &flow_db->flow_tbl[idx];
 	while (!ulp_flow_db_next_entry_get(flow_tbl, &fid))
 		ulp_mapper_resources_free(ulp_ctx, fid, idx);
 
+	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
+
 	return 0;
 }
 
@@ -826,13 +833,17 @@ ulp_flow_db_function_flow_flush(struct bnxt_ulp_context *ulp_ctx,
 		BNXT_TF_DBG(ERR, "Flow database not found\n");
 		return -EINVAL;
 	}
+	if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+		BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+		return -EINVAL;
+	}
 	flow_tbl = &flow_db->flow_tbl[BNXT_ULP_REGULAR_FLOW_TABLE];
 	while (!ulp_flow_db_next_entry_get(flow_tbl, &flow_id)) {
 		if (flow_db->func_id_tbl[flow_id] == func_id)
 			ulp_mapper_resources_free(ulp_ctx, flow_id,
 						  BNXT_ULP_REGULAR_FLOW_TABLE);
 	}
-
+	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
 	return 0;
 }
 
diff --git a/drivers/net/bnxt/tf_ulp/ulp_mapper.c b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
index 732141166..85ae3b5c4 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_mapper.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_mapper.c
@@ -2668,12 +2668,21 @@ int32_t
 ulp_mapper_flow_destroy(struct bnxt_ulp_context	*ulp_ctx, uint32_t fid,
 			enum bnxt_ulp_flow_db_tables flow_tbl_type)
 {
+	int32_t rc;
+
 	if (!ulp_ctx) {
 		BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
 		return -EINVAL;
 	}
+	if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+		BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+		return -EINVAL;
+	}
+
+	rc = ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
+	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
+	return rc;
 
-	return ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
 }
 
 /* Function to handle the default global templates that are allocated during
@@ -2838,6 +2847,12 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
 		return -EINVAL;
 	}
 
+	/* Protect flow creation */
+	if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
+		BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
+		return -EINVAL;
+	}
+
 	/* Allocate a Flow ID for attaching all resources for the flow to.
 	 * Once allocated, all errors have to walk the list of resources and
 	 * free each of them.
@@ -2848,6 +2863,7 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
 				   &parms.fid);
 	if (rc) {
 		BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
+		bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
 		return rc;
 	}
 
@@ -2871,10 +2887,12 @@ ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
 	}
 
 	*flowid = parms.fid;
+	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
 
 	return rc;
 
 flow_error:
+	bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
 	/* Free all resources that were allocated during flow creation */
 	trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid,
 				      BNXT_ULP_REGULAR_FLOW_TABLE);
-- 
2.21.1 (Apple Git-122.3)


  parent reply index

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11  1:55 [dpdk-dev] [PATCH 00/25] patchset for bnxt Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 01/25] net/bnxt: fix port stop process and cleanup resources Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 02/25] net/bnxt: fix the drop action flow to support count action Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 03/25] net/bnxt: reject offload flows with invalid MAC address Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 04/25] net/bnxt: reduce debug log messages Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 05/25] net/bnxt: fix to break the ipv4 and ipv6 ingress rule Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 06/25] net/bnxt: free the em index on failure Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 07/25] net/bnxt: add a null ptr check for the resource manager Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 08/25] net/bnxt: change default flow rule to use 8B encap Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 09/25] net/bnxt: fix the function id used in the flow flush Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 10/25] net/bnxt: vfr port clean up during port stop Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 11/25] net/bnxt: fix crash in VF rep queue selection Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 12/25] net/bnxt: fix to conditionally rollback added VF-rep ports Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 13/25] net/bnxt: update resource allocation settings Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 14/25] net/bnxt: move IF tbl from tunneled to direct HWRM msg Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 15/25] net/bnxt: remove VLAN pop action for egress flows Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 16/25] net/bnxt: increase counter support from 8K to 16K Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 17/25] net/bnxt: fix to explicitly check and set for start cntr ID Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 18/25] net/bnxt: enable support for VXLAN ipv6 encapsulation Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 19/25] net/bnxt: enable support for nat action with tagged traffic Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 20/25] net/bnxt: fix out of bound access in action bit handling Ajit Khaparde
2020-09-11  1:55 ` [dpdk-dev] [PATCH 21/25] net/bnxt: provide switch info while VF-Reps are configured Ajit Khaparde
2020-09-11  1:56 ` [dpdk-dev] [PATCH 22/25] net/bnxt: fix bugs in representor data path Ajit Khaparde
2020-09-11  1:56 ` Ajit Khaparde [this message]
2020-09-11  1:56 ` [dpdk-dev] [PATCH 24/25] net/bnxt: fix to check for vnic ptr in bnxt shutdown path Ajit Khaparde
2020-09-11  1:56 ` [dpdk-dev] [PATCH 25/25] net/bnxt: fix to have a separate mutex for FW health check Ajit Khaparde
2020-09-16  4:28 ` [dpdk-dev] [PATCH v2 00/25] patchset for bnxt Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 01/25] net/bnxt: fix resource cleanup in port stop Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 02/25] net/bnxt: fix the drop action flow to support count Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 03/25] net/bnxt: reject flow offload with invalid MAC Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 04/25] net/bnxt: reduce debug log messages Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 05/25] net/bnxt: fix coexistence of ipv4 and ipv6 ingress rules Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 06/25] net/bnxt: free the EM index on failure Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 07/25] net/bnxt: add null pointer check for resource manager Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 08/25] net/bnxt: modify default flow rule creation Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 09/25] net/bnxt: fix the function id used in flow flush Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 10/25] net/bnxt: refactor VFR port clean up Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 11/25] net/bnxt: fix crash in VFR queue select Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 12/25] net/bnxt: fix VFR cleanup during init failure Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 13/25] net/bnxt: update resource settings Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 14/25] net/bnxt: use direct HWRM message for interface table Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 15/25] net/bnxt: remove VLAN pop action for egress flows Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 16/25] net/bnxt: increase counter support from 8K to 16K Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 17/25] net/bnxt: check and set initial counter ID Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 18/25] net/bnxt: enable VXLAN ipv6 encapsulation Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 19/25] net/bnxt: enable NAT action with tagged traffic Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 20/25] net/bnxt: fix out of bound access in bit handling Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 21/25] net/bnxt: provide switch info if VFR are configured Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 22/25] net/bnxt: fix bugs in representor data path Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 23/25] net/bnxt: add locks in flow database Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 24/25] net/bnxt: fix to check VNIC in shutdown path Ajit Khaparde
2020-09-16  4:28   ` [dpdk-dev] [PATCH v2 25/25] net/bnxt: add separate mutex for FW health check Ajit Khaparde
2020-09-16 16:21   ` [dpdk-dev] [PATCH v2 00/25] patchset for bnxt Ajit Khaparde
2020-09-16 23:57     ` Ferruh Yigit
2020-09-17  0:13       ` Ajit Khaparde
2020-09-17  7:39         ` Ferruh Yigit

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200911015603.88359-24-ajit.khaparde@broadcom.com \
    --to=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=kishore.padmanabha@broadcom.com \
    --cc=michael.baucom@broadcom.com \
    --cc=sbhosle@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox