[v3] app/testpmd: support age shared action context

Message ID 1605027999-352513-1-git-send-email-matan@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v3] app/testpmd: support age shared action context |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Matan Azrad Nov. 10, 2020, 5:06 p.m. UTC
When an age action becomes aged-out the next call for
rte_flow_get_aged_flows API should return the action context supplied
by the action configuration structure.

In case the age action is created by the shared action API, the shared
action context of the Testpmd application was not set.

In addition, the application handler of the contexts returned by the
rte_flow_get_aged_flows API didn't consider the fact that the action
could be set by the shared action API and considered it as regular flow
context.

This caused a crash in Testpmd when the context is parsed.

This patch set context type in the flow and shared action context and
uses it to parse the aged-out contexts correctly.

Signed-off-by: Matan Azrad <matan@nvidia.com>
Acked-by: Dekel Peled <dekelp@nvidia.com>
---

v3:
update age context to point to the context type field inside the context structures.

 app/test-pmd/config.c  | 89 +++++++++++++++++++++++++++++---------------------
 app/test-pmd/testpmd.h | 13 +++++++-
 2 files changed, 64 insertions(+), 38 deletions(-)
  

Comments

Ferruh Yigit Nov. 11, 2020, 12:51 p.m. UTC | #1
On 11/10/2020 5:06 PM, Matan Azrad wrote:
> When an age action becomes aged-out the next call for
> rte_flow_get_aged_flows API should return the action context supplied
> by the action configuration structure.
> 
> In case the age action is created by the shared action API, the shared
> action context of the Testpmd application was not set.
> 
> In addition, the application handler of the contexts returned by the
> rte_flow_get_aged_flows API didn't consider the fact that the action
> could be set by the shared action API and considered it as regular flow
> context.
> 
> This caused a crash in Testpmd when the context is parsed.
> 
> This patch set context type in the flow and shared action context and
> uses it to parse the aged-out contexts correctly.
> 
> Signed-off-by: Matan Azrad <matan@nvidia.com>
> Acked-by: Dekel Peled <dekelp@nvidia.com>

Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 755d1df..91e7542 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1849,6 +1849,13 @@  void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 	ret = action_alloc(port_id, id, &psa);
 	if (ret)
 		return ret;
+	if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
+		struct rte_flow_action_age *age =
+			(struct rte_flow_action_age *)(uintptr_t)(action->conf);
+
+		psa->age_type = ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION;
+		age->context = &psa->age_type;
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	psa->action = rte_flow_shared_action_create(port_id, conf, action,
@@ -1900,8 +1907,8 @@  void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 				continue;
 			}
 			*tmp = psa->next;
-			free(psa);
 			printf("Shared action #%u destroyed\n", psa->id);
+			free(psa);
 			break;
 		}
 		if (i == n)
@@ -2113,24 +2120,20 @@  struct rte_flow_shared_action *
 	return 0;
 }
 
-/** Update age action context by port_flow pointer. */
-void
-update_age_action_context(const struct rte_flow_action *actions,
-			struct port_flow *pf)
+/** Return age action structure if exists, otherwise NULL. */
+static struct rte_flow_action_age *
+age_action_get(const struct rte_flow_action *actions)
 {
-	struct rte_flow_action_age *age = NULL;
-
 	for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
 		switch (actions->type) {
 		case RTE_FLOW_ACTION_TYPE_AGE:
-			age = (struct rte_flow_action_age *)
+			return (struct rte_flow_action_age *)
 				(uintptr_t)actions->conf;
-			age->context = pf;
-			return;
 		default:
 			break;
 		}
 	}
+	return NULL;
 }
 
 /** Create flow rule. */
@@ -2147,6 +2150,7 @@  struct rte_flow_shared_action *
 	uint32_t id = 0;
 	struct rte_flow_error error;
 	struct port_flow_tunnel *pft = NULL;
+	struct rte_flow_action_age *age = age_action_get(actions);
 
 	port = &ports[port_id];
 	if (port->flow_list) {
@@ -2170,7 +2174,10 @@  struct rte_flow_shared_action *
 	pf = port_flow_new(attr, pattern, actions, &error);
 	if (!pf)
 		return port_flow_complain(&error);
-	update_age_action_context(actions, pf);
+	if (age) {
+		pf->age_type = ACTION_AGE_CONTEXT_TYPE_FLOW;
+		age->context = &pf->age_type;
+	}
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x22, sizeof(error));
 	flow = rte_flow_create(port_id, attr, pattern, actions, &error);
@@ -2379,7 +2386,11 @@  struct rte_flow_shared_action *
 	void **contexts;
 	int nb_context, total = 0, idx;
 	struct rte_flow_error error;
-	struct port_flow *pf;
+	enum age_action_context_type *type;
+	union {
+		struct port_flow *pf;
+		struct port_shared_action *psa;
+	} ctx;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
 	    port_id == (portid_t)RTE_PORT_ALL)
@@ -2397,7 +2408,7 @@  struct rte_flow_shared_action *
 		printf("Cannot allocate contexts for aged flow\n");
 		return;
 	}
-	printf("ID\tGroup\tPrio\tAttr\n");
+	printf("%-20s\tID\tGroup\tPrio\tAttr\n", "Type");
 	nb_context = rte_flow_get_aged_flows(port_id, contexts, total, &error);
 	if (nb_context != total) {
 		printf("Port:%d get aged flows count(%d) != total(%d)\n",
@@ -2405,37 +2416,41 @@  struct rte_flow_shared_action *
 		free(contexts);
 		return;
 	}
+	total = 0;
 	for (idx = 0; idx < nb_context; idx++) {
-		pf = (struct port_flow *)contexts[idx];
-		if (!pf) {
+		if (!contexts[idx]) {
 			printf("Error: get Null context in port %u\n", port_id);
 			continue;
 		}
-		printf("%" PRIu32 "\t%" PRIu32 "\t%" PRIu32 "\t%c%c%c\t\n",
-		       pf->id,
-		       pf->rule.attr->group,
-		       pf->rule.attr->priority,
-		       pf->rule.attr->ingress ? 'i' : '-',
-		       pf->rule.attr->egress ? 'e' : '-',
-		       pf->rule.attr->transfer ? 't' : '-');
-	}
-	if (destroy) {
-		int ret;
-		uint32_t flow_id;
-
-		total = 0;
-		printf("\n");
-		for (idx = 0; idx < nb_context; idx++) {
-			pf = (struct port_flow *)contexts[idx];
-			if (!pf)
-				continue;
-			flow_id = pf->id;
-			ret = port_flow_destroy(port_id, 1, &flow_id);
-			if (!ret)
+		type = (enum age_action_context_type *)contexts[idx];
+		switch (*type) {
+		case ACTION_AGE_CONTEXT_TYPE_FLOW:
+			ctx.pf = container_of(type, struct port_flow, age_type);
+			printf("%-20s\t%" PRIu32 "\t%" PRIu32 "\t%" PRIu32
+								 "\t%c%c%c\t\n",
+			       "Flow",
+			       ctx.pf->id,
+			       ctx.pf->rule.attr->group,
+			       ctx.pf->rule.attr->priority,
+			       ctx.pf->rule.attr->ingress ? 'i' : '-',
+			       ctx.pf->rule.attr->egress ? 'e' : '-',
+			       ctx.pf->rule.attr->transfer ? 't' : '-');
+			if (destroy && !port_flow_destroy(port_id, 1,
+							  &ctx.pf->id))
 				total++;
+			break;
+		case ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION:
+			ctx.psa = container_of(type, struct port_shared_action,
+					       age_type);
+			printf("%-20s\t%" PRIu32 "\n", "Shared action",
+			       ctx.psa->id);
+			break;
+		default:
+			printf("Error: invalid context type %u\n", port_id);
+			break;
 		}
-		printf("%d flows be destroyed\n", total);
 	}
+	printf("\n%d flows destroyed\n", total);
 	free(contexts);
 }
 
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 519d551..6b901a8 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -143,13 +143,23 @@  struct fwd_stream {
 	struct pkt_burst_stats tx_burst_stats;
 };
 
+/**
+ * Age action context types, must be included inside the age action
+ * context structure.
+ */
+enum age_action_context_type {
+	ACTION_AGE_CONTEXT_TYPE_FLOW,
+	ACTION_AGE_CONTEXT_TYPE_SHARED_ACTION,
+};
+
 /** Descriptor for a single flow. */
 struct port_flow {
 	struct port_flow *next; /**< Next flow in list. */
 	struct port_flow *tmp; /**< Temporary linking. */
 	uint32_t id; /**< Flow rule ID. */
 	struct rte_flow *flow; /**< Opaque flow object returned by PMD. */
-	struct rte_flow_conv_rule rule; /* Saved flow rule description. */
+	struct rte_flow_conv_rule rule; /**< Saved flow rule description. */
+	enum age_action_context_type age_type; /**< Age action context type. */
 	uint8_t data[]; /**< Storage for flow rule description */
 };
 
@@ -159,6 +169,7 @@  struct port_shared_action {
 	uint32_t id; /**< Shared action ID. */
 	enum rte_flow_action_type type; /**< Action type. */
 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
+	enum age_action_context_type age_type; /**< Age action context type. */
 };
 
 struct port_flow_tunnel {