patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Gregory Etelson <getelson@nvidia.com>
To: <dev@dpdk.org>
Cc: <getelson@nvidia.com>, <rasland@nvidia.com>, <stable@dpdk.org>,
	"Matan Azrad" <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Ferruh Yigit <ferruh.yigit@intel.com>,
	Dekel Peled <dekelp@nvidia.com>
Subject: [PATCH] net/mlx5: fix RSS expansion with explicit next protocol
Date: Thu, 23 Dec 2021 15:08:17 +0200	[thread overview]
Message-ID: <20211223130817.14077-1-getelson@nvidia.com> (raw)

The PMD RSS expansion scheme by default compiles flow rules for all
flow item types that may branch out from a stub supplied
by application.
For example,
ETH can lead to VLAN, IPv4 or IPv6.
IPv4 can lead to UDP, TCP, IPv4 or IPv6.

If application explicitly specified next protocol type, expansion must
use that option only and not create flows with other protocol types.

The PMD ignored explicit next protocol values in GRE and VXLAN-GPE.

The patch updates RSS expansion for GRE and VXLAN-GPE with explicit
next protocol settings.

Fixes: c7870bfe09dc ("ethdev: move RSS expansion code to mlx5 driver")

Cc: stable@dpdk.org

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow.c | 209 ++++++++++++++++++-----------------
 1 file changed, 108 insertions(+), 101 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index f34e4b88aa..4e2ff16e30 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -164,128 +164,135 @@ mlx5_flow_is_rss_expandable_item(const struct rte_flow_item *item)
 	return false;
 }
 
+/**
+ * Network Service Header (NSH) and its next protocol values
+ * are described in RFC-8393.
+ */
+static enum rte_flow_item_type
+mlx5_nsh_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
+{
+	enum rte_flow_item_type type;
+
+	switch (proto_mask & proto_spec) {
+	case RTE_VXLAN_GPE_TYPE_IPV4:
+		type = RTE_FLOW_ITEM_TYPE_IPV4;
+		break;
+	case RTE_VXLAN_GPE_TYPE_IPV6:
+		type = RTE_VXLAN_GPE_TYPE_IPV6;
+		break;
+	case RTE_VXLAN_GPE_TYPE_ETH:
+		type = RTE_FLOW_ITEM_TYPE_ETH;
+		break;
+	default:
+		type = RTE_FLOW_ITEM_TYPE_END;
+	}
+	return type;
+}
+
+static enum rte_flow_item_type
+mlx5_inet_proto_to_item_type(uint8_t proto_spec, uint8_t proto_mask)
+{
+	enum rte_flow_item_type type;
+
+	switch (proto_mask & proto_spec) {
+	case IPPROTO_UDP:
+		type = RTE_FLOW_ITEM_TYPE_UDP;
+		break;
+	case IPPROTO_TCP:
+		type = RTE_FLOW_ITEM_TYPE_TCP;
+		break;
+	case IPPROTO_IP:
+		type = RTE_FLOW_ITEM_TYPE_IPV4;
+		break;
+	case IPPROTO_IPV6:
+		type = RTE_FLOW_ITEM_TYPE_IPV6;
+		break;
+	default:
+		type = RTE_FLOW_ITEM_TYPE_END;
+	}
+	return type;
+}
+
+static enum rte_flow_item_type
+mlx5_ethertype_to_item_type(rte_be16_t type_spec,
+			    rte_be16_t type_mask, bool is_tunnel)
+{
+	enum rte_flow_item_type type;
+
+	switch (rte_be_to_cpu_16(type_spec & type_mask)) {
+	case RTE_ETHER_TYPE_TEB:
+		type = is_tunnel ?
+		       RTE_FLOW_ITEM_TYPE_ETH : RTE_FLOW_ITEM_TYPE_END;
+		break;
+	case RTE_ETHER_TYPE_VLAN:
+		type = !is_tunnel ?
+		       RTE_FLOW_ITEM_TYPE_VLAN : RTE_FLOW_ITEM_TYPE_END;
+		break;
+	case RTE_ETHER_TYPE_IPV4:
+		type = RTE_FLOW_ITEM_TYPE_IPV4;
+		break;
+	case RTE_ETHER_TYPE_IPV6:
+		type = RTE_FLOW_ITEM_TYPE_IPV6;
+		break;
+	default:
+		type = RTE_FLOW_ITEM_TYPE_END;
+	}
+	return type;
+}
+
 static enum rte_flow_item_type
 mlx5_flow_expand_rss_item_complete(const struct rte_flow_item *item)
 {
-	enum rte_flow_item_type ret = RTE_FLOW_ITEM_TYPE_VOID;
-	uint16_t ether_type = 0;
-	uint16_t ether_type_m;
-	uint8_t ip_next_proto = 0;
-	uint8_t ip_next_proto_m;
+#define MLX5_XSET_ITEM_MASK_SPEC(type, fld)                              \
+	do {                                                             \
+		const void *m = item->mask;                              \
+		const void *s = item->spec;                              \
+		mask = m ?                                               \
+			((const struct rte_flow_item_##type *)m)->fld :  \
+			rte_flow_item_##type##_mask.fld;                 \
+		spec = ((const struct rte_flow_item_##type *)s)->fld;    \
+	} while (0)
+
+	enum rte_flow_item_type ret;
+	uint16_t spec, mask;
 
 	if (item == NULL || item->spec == NULL)
-		return ret;
+		return RTE_FLOW_ITEM_TYPE_VOID;
 	switch (item->type) {
 	case RTE_FLOW_ITEM_TYPE_ETH:
-		if (item->mask)
-			ether_type_m = ((const struct rte_flow_item_eth *)
-						(item->mask))->type;
-		else
-			ether_type_m = rte_flow_item_eth_mask.type;
-		if (ether_type_m != RTE_BE16(0xFFFF))
-			break;
-		ether_type = ((const struct rte_flow_item_eth *)
-				(item->spec))->type;
-		if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
-			ret = RTE_FLOW_ITEM_TYPE_IPV4;
-		else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
-			ret = RTE_FLOW_ITEM_TYPE_IPV6;
-		else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
-			ret = RTE_FLOW_ITEM_TYPE_VLAN;
-		else
-			ret = RTE_FLOW_ITEM_TYPE_END;
+		MLX5_XSET_ITEM_MASK_SPEC(eth, type);
+		ret = mlx5_ethertype_to_item_type(spec, mask, false);
 		break;
 	case RTE_FLOW_ITEM_TYPE_VLAN:
-		if (item->mask)
-			ether_type_m = ((const struct rte_flow_item_vlan *)
-						(item->mask))->inner_type;
-		else
-			ether_type_m = rte_flow_item_vlan_mask.inner_type;
-		if (ether_type_m != RTE_BE16(0xFFFF))
-			break;
-		ether_type = ((const struct rte_flow_item_vlan *)
-				(item->spec))->inner_type;
-		if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV4)
-			ret = RTE_FLOW_ITEM_TYPE_IPV4;
-		else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_IPV6)
-			ret = RTE_FLOW_ITEM_TYPE_IPV6;
-		else if (rte_be_to_cpu_16(ether_type) == RTE_ETHER_TYPE_VLAN)
-			ret = RTE_FLOW_ITEM_TYPE_VLAN;
-		else
-			ret = RTE_FLOW_ITEM_TYPE_END;
+		MLX5_XSET_ITEM_MASK_SPEC(vlan, inner_type);
+		ret = mlx5_ethertype_to_item_type(spec, mask, false);
 		break;
 	case RTE_FLOW_ITEM_TYPE_IPV4:
-		if (item->mask)
-			ip_next_proto_m = ((const struct rte_flow_item_ipv4 *)
-					(item->mask))->hdr.next_proto_id;
-		else
-			ip_next_proto_m =
-				rte_flow_item_ipv4_mask.hdr.next_proto_id;
-		if (ip_next_proto_m != 0xFF)
-			break;
-		ip_next_proto = ((const struct rte_flow_item_ipv4 *)
-				(item->spec))->hdr.next_proto_id;
-		if (ip_next_proto == IPPROTO_UDP)
-			ret = RTE_FLOW_ITEM_TYPE_UDP;
-		else if (ip_next_proto == IPPROTO_TCP)
-			ret = RTE_FLOW_ITEM_TYPE_TCP;
-		else if (ip_next_proto == IPPROTO_IP)
-			ret = RTE_FLOW_ITEM_TYPE_IPV4;
-		else if (ip_next_proto == IPPROTO_IPV6)
-			ret = RTE_FLOW_ITEM_TYPE_IPV6;
-		else
-			ret = RTE_FLOW_ITEM_TYPE_END;
+		MLX5_XSET_ITEM_MASK_SPEC(ipv4, hdr.next_proto_id);
+		ret = mlx5_inet_proto_to_item_type(spec, mask);
 		break;
 	case RTE_FLOW_ITEM_TYPE_IPV6:
-		if (item->mask)
-			ip_next_proto_m = ((const struct rte_flow_item_ipv6 *)
-						(item->mask))->hdr.proto;
-		else
-			ip_next_proto_m =
-				rte_flow_item_ipv6_mask.hdr.proto;
-		if (ip_next_proto_m != 0xFF)
-			break;
-		ip_next_proto = ((const struct rte_flow_item_ipv6 *)
-				(item->spec))->hdr.proto;
-		if (ip_next_proto == IPPROTO_UDP)
-			ret = RTE_FLOW_ITEM_TYPE_UDP;
-		else if (ip_next_proto == IPPROTO_TCP)
-			ret = RTE_FLOW_ITEM_TYPE_TCP;
-		else if (ip_next_proto == IPPROTO_IP)
-			ret = RTE_FLOW_ITEM_TYPE_IPV4;
-		else if (ip_next_proto == IPPROTO_IPV6)
-			ret = RTE_FLOW_ITEM_TYPE_IPV6;
-		else
-			ret = RTE_FLOW_ITEM_TYPE_END;
+		MLX5_XSET_ITEM_MASK_SPEC(ipv6, hdr.proto);
+		ret = mlx5_inet_proto_to_item_type(spec, mask);
 		break;
 	case RTE_FLOW_ITEM_TYPE_GENEVE:
-		ether_type_m = item->mask ?
-			       ((const struct rte_flow_item_geneve *)
-			       (item->mask))->protocol :
-			       rte_flow_item_geneve_mask.protocol;
-		ether_type = ((const struct rte_flow_item_geneve *)
-			     (item->spec))->protocol;
-		ether_type_m = rte_be_to_cpu_16(ether_type_m);
-		ether_type = rte_be_to_cpu_16(ether_type);
-		switch (ether_type_m & ether_type) {
-		case RTE_ETHER_TYPE_TEB:
-			ret = RTE_FLOW_ITEM_TYPE_ETH;
-			break;
-		case RTE_ETHER_TYPE_IPV4:
-			ret = RTE_FLOW_ITEM_TYPE_IPV4;
-			break;
-		case RTE_ETHER_TYPE_IPV6:
-			ret = RTE_FLOW_ITEM_TYPE_IPV6;
-			break;
-		default:
-			ret = RTE_FLOW_ITEM_TYPE_END;
-		}
+		MLX5_XSET_ITEM_MASK_SPEC(geneve, protocol);
+		ret = mlx5_ethertype_to_item_type(spec, mask, true);
+		break;
+	case RTE_FLOW_ITEM_TYPE_GRE:
+		MLX5_XSET_ITEM_MASK_SPEC(gre, protocol);
+		ret = mlx5_ethertype_to_item_type(spec, mask, true);
+		break;
+	case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
+		MLX5_XSET_ITEM_MASK_SPEC(vxlan_gpe, protocol);
+		ret = mlx5_nsh_proto_to_item_type(spec, mask);
 		break;
 	default:
 		ret = RTE_FLOW_ITEM_TYPE_VOID;
 		break;
 	}
 	return ret;
+#undef MLX5_XSET_ITEM_MASK_SPEC
 }
 
 static const int *
-- 
2.34.1


             reply	other threads:[~2021-12-23 13:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 13:08 Gregory Etelson [this message]
2022-01-09 11:56 ` Raslan Darawsheh

Reply instructions:

You may reply publicly 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=20211223130817.14077-1-getelson@nvidia.com \
    --to=getelson@nvidia.com \
    --cc=dekelp@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=matan@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=viacheslavo@nvidia.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).