patch 'net/mlx5: fix non full word sample fields in flex item' has been queued to stable release 21.11.9

Kevin Traynor ktraynor at redhat.com
Wed Nov 27 18:18:27 CET 2024


Hi,

FYI, your patch has been queued to stable release 21.11.9

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/02/24. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/f07214079b7d6e07f9fbc40a5550599c1495263f

Thanks.

Kevin

---
>From f07214079b7d6e07f9fbc40a5550599c1495263f Mon Sep 17 00:00:00 2001
From: Viacheslav Ovsiienko <viacheslavo at nvidia.com>
Date: Thu, 31 Oct 2024 14:44:33 +0200
Subject: [PATCH] net/mlx5: fix non full word sample fields in flex item

[ upstream commit 97e19f0762e5235d6914845a59823d4ea36925bb ]

If the sample field in flex item did not cover the entire
32-bit word (width was not verified 32 bits) or was not aligned
on the byte boundary the match on this sample in flows
happened to be ignored or wrongly missed. The field mask
"def" was build in wrong endianness, and non-byte aligned
shifts were wrongly performed for the pattern masks and values.

Fixes: 6dac7d7ff2bf ("net/mlx5: translate flex item pattern into matcher")

Signed-off-by: Viacheslav Ovsiienko <viacheslavo at nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski at nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_flex.c | 32 ++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_flex.c b/drivers/net/mlx5/mlx5_flow_flex.c
index 3ef46db1f6..e696c0cd7b 100644
--- a/drivers/net/mlx5/mlx5_flow_flex.c
+++ b/drivers/net/mlx5/mlx5_flow_flex.c
@@ -119,5 +119,5 @@ mlx5_flex_get_bitfield(const struct rte_flow_item_flex *item,
 {
 	const uint8_t *ptr = item->pattern + pos / CHAR_BIT;
-	uint32_t val, vbits;
+	uint32_t val, vbits, skip = pos % CHAR_BIT;
 
 	/* Proceed the bitfield start byte. */
@@ -126,19 +126,23 @@ mlx5_flex_get_bitfield(const struct rte_flow_item_flex *item,
 	if (item->length <= pos / CHAR_BIT)
 		return 0;
-	val = *ptr++ >> (pos % CHAR_BIT);
+	/* Bits are enumerated in byte in network order: 01234567 */
+	val = *ptr++;
 	vbits = CHAR_BIT - pos % CHAR_BIT;
-	pos = (pos + vbits) / CHAR_BIT;
+	pos = RTE_ALIGN_CEIL(pos, CHAR_BIT) / CHAR_BIT;
 	vbits = RTE_MIN(vbits, width);
-	val &= RTE_BIT32(vbits) - 1;
+	/* Load bytes to cover the field width, checking pattern boundary */
 	while (vbits < width && pos < item->length) {
 		uint32_t part = RTE_MIN(width - vbits, (uint32_t)CHAR_BIT);
 		uint32_t tmp = *ptr++;
 
-		pos++;
-		tmp &= RTE_BIT32(part) - 1;
-		val |= tmp << vbits;
+		val |= tmp << RTE_ALIGN_CEIL(vbits, CHAR_BIT);
 		vbits += part;
+		pos++;
 	}
-	return rte_bswap32(val <<= shift);
+	val = rte_cpu_to_be_32(val);
+	val <<= skip;
+	val >>= shift;
+	val &= (RTE_BIT64(width) - 1) << (sizeof(uint32_t) * CHAR_BIT - shift - width);
+	return val;
 }
 
@@ -236,9 +240,8 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
 	tp = (struct mlx5_flex_item *)spec->handle;
 	MLX5_ASSERT(mlx5_flex_index(dev->data->dev_private, tp) >= 0);
-	for (i = 0; i < tp->mapnum; i++) {
+	for (i = 0; i < tp->mapnum && pos < (spec->length * CHAR_BIT); i++) {
 		struct mlx5_flex_pattern_field *map = tp->map + i;
 		uint32_t id = map->reg_id;
-		uint32_t def = (RTE_BIT64(map->width) - 1) << map->shift;
-		uint32_t val, msk;
+		uint32_t val, msk, def;
 
 		/* Skip placeholders for DUMMY fields. */
@@ -247,6 +250,9 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
 			continue;
 		}
+		def = (uint32_t)(RTE_BIT64(map->width) - 1);
+		def <<= (sizeof(uint32_t) * CHAR_BIT - map->shift - map->width);
 		val = mlx5_flex_get_bitfield(spec, pos, map->width, map->shift);
-		msk = mlx5_flex_get_bitfield(mask, pos, map->width, map->shift);
+		msk = pos < (mask->length * CHAR_BIT) ?
+		      mlx5_flex_get_bitfield(mask, pos, map->width, map->shift) : def;
 		MLX5_ASSERT(map->width);
 		MLX5_ASSERT(id < tp->devx_fp->num_samples);
@@ -259,5 +265,5 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
 		}
 		mlx5_flex_set_match_sample(misc4_m, misc4_v,
-					   def, msk & def, val & msk & def,
+					   def, msk, val & msk,
 					   tp->devx_fp->sample_ids[id], id);
 		pos += map->width;
-- 
2.47.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2024-11-27 17:17:40.781662155 +0000
+++ 0080-net-mlx5-fix-non-full-word-sample-fields-in-flex-ite.patch	2024-11-27 17:17:38.283269674 +0000
@@ -1 +1 @@
-From 97e19f0762e5235d6914845a59823d4ea36925bb Mon Sep 17 00:00:00 2001
+From f07214079b7d6e07f9fbc40a5550599c1495263f Mon Sep 17 00:00:00 2001
@@ -3 +3 @@
-Date: Wed, 18 Sep 2024 16:46:22 +0300
+Date: Thu, 31 Oct 2024 14:44:33 +0200
@@ -5,0 +6,2 @@
+[ upstream commit 97e19f0762e5235d6914845a59823d4ea36925bb ]
+
@@ -14 +15,0 @@
-Cc: stable at dpdk.org
@@ -19,5 +20,2 @@
- drivers/net/mlx5/hws/mlx5dr_definer.c |  4 +--
- drivers/net/mlx5/mlx5.h               |  5 ++-
- drivers/net/mlx5/mlx5_flow_dv.c       |  5 ++-
- drivers/net/mlx5/mlx5_flow_flex.c     | 47 +++++++++++++--------------
- 4 files changed, 29 insertions(+), 32 deletions(-)
+ drivers/net/mlx5/mlx5_flow_flex.c | 32 ++++++++++++++++++-------------
+ 1 file changed, 19 insertions(+), 13 deletions(-)
@@ -25,58 +22,0 @@
-diff --git a/drivers/net/mlx5/hws/mlx5dr_definer.c b/drivers/net/mlx5/hws/mlx5dr_definer.c
-index 2dfcc5eba6..10b986d66b 100644
---- a/drivers/net/mlx5/hws/mlx5dr_definer.c
-+++ b/drivers/net/mlx5/hws/mlx5dr_definer.c
-@@ -575,5 +575,5 @@ mlx5dr_definer_flex_parser_set(struct mlx5dr_definer_fc *fc,
- 	byte_off -= idx * sizeof(uint32_t);
- 	ret = mlx5_flex_get_parser_value_per_byte_off(flex, flex->handle, byte_off,
--						      false, is_inner, &val);
-+						      is_inner, &val);
- 	if (ret == -1 || !val)
- 		return;
-@@ -2826,5 +2826,5 @@ mlx5dr_definer_conv_item_flex_parser(struct mlx5dr_definer_conv_data *cd,
- 		byte_off = base_off - i * sizeof(uint32_t);
- 		ret = mlx5_flex_get_parser_value_per_byte_off(m, v->handle, byte_off,
--							      true, is_inner, &mask);
-+							      is_inner, &mask);
- 		if (ret == -1) {
- 			rte_errno = EINVAL;
-diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
-index 399923b443..18b4c15a26 100644
---- a/drivers/net/mlx5/mlx5.h
-+++ b/drivers/net/mlx5/mlx5.h
-@@ -2603,9 +2603,8 @@ void mlx5_flex_flow_translate_item(struct rte_eth_dev *dev, void *matcher,
- 				   bool is_inner);
- int mlx5_flex_get_sample_id(const struct mlx5_flex_item *tp,
--			    uint32_t idx, uint32_t *pos,
--			    bool is_inner, uint32_t *def);
-+			    uint32_t idx, uint32_t *pos, bool is_inner);
- int mlx5_flex_get_parser_value_per_byte_off(const struct rte_flow_item_flex *item,
- 					    void *flex, uint32_t byte_off,
--					    bool is_mask, bool tunnel, uint32_t *value);
-+					    bool tunnel, uint32_t *value);
- int mlx5_flex_get_tunnel_mode(const struct rte_flow_item *item,
- 			      enum rte_flow_item_flex_tunnel_mode *tunnel_mode);
-diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
-index 4451b114ae..5f71573a86 100644
---- a/drivers/net/mlx5/mlx5_flow_dv.c
-+++ b/drivers/net/mlx5/mlx5_flow_dv.c
-@@ -1527,5 +1527,4 @@ mlx5_modify_flex_item(const struct rte_eth_dev *dev,
- 	uint32_t offset = data->offset;
- 	uint32_t width_left = width;
--	uint32_t def;
- 	uint32_t cur_width = 0;
- 	uint32_t tmp_ofs;
-@@ -1552,5 +1551,5 @@ mlx5_modify_flex_item(const struct rte_eth_dev *dev,
- 	for (j = i; i < flex->mapnum && width_left > 0; ) {
- 		map = flex->map + i;
--		id = mlx5_flex_get_sample_id(flex, i, &pos, false, &def);
-+		id = mlx5_flex_get_sample_id(flex, i, &pos, false);
- 		if (id == -1) {
- 			i++;
-@@ -1571,5 +1570,5 @@ mlx5_modify_flex_item(const struct rte_eth_dev *dev,
- 			 */
- 			for (j = i + 1; j < flex->mapnum; j++) {
--				tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false, &def);
-+				tmp_id = mlx5_flex_get_sample_id(flex, j, &pos, false);
- 				if (tmp_id == -1) {
- 					i = j;
@@ -84 +24 @@
-index 0c41b956b0..bf38643a23 100644
+index 3ef46db1f6..e696c0cd7b 100644
@@ -125,55 +65 @@
-@@ -212,6 +216,4 @@ mlx5_flex_set_match_sample(void *misc4_m, void *misc4_v,
-  * @param[in] is_inner
-  *   For inner matching or not.
-- * @param[in, def] def
-- *   Mask generated by mapping shift and width.
-  *
-  * @return
-@@ -220,11 +222,9 @@ mlx5_flex_set_match_sample(void *misc4_m, void *misc4_v,
- int
- mlx5_flex_get_sample_id(const struct mlx5_flex_item *tp,
--			uint32_t idx, uint32_t *pos,
--			bool is_inner, uint32_t *def)
-+			uint32_t idx, uint32_t *pos, bool is_inner)
- {
- 	const struct mlx5_flex_pattern_field *map = tp->map + idx;
- 	uint32_t id = map->reg_id;
- 
--	*def = (RTE_BIT64(map->width) - 1) << map->shift;
- 	/* Skip placeholders for DUMMY fields. */
- 	if (id == MLX5_INVALID_SAMPLE_REG_ID) {
-@@ -253,6 +253,4 @@ mlx5_flex_get_sample_id(const struct mlx5_flex_item *tp,
-  * @param[in] byte_off
-  *   Mlx5 flex item format_select_dw.
-- * @param[in] is_mask
-- *   Spec or mask.
-  * @param[in] tunnel
-  *   Tunnel mode or not.
-@@ -266,9 +264,9 @@ int
- mlx5_flex_get_parser_value_per_byte_off(const struct rte_flow_item_flex *item,
- 					void *flex, uint32_t byte_off,
--					bool is_mask, bool tunnel, uint32_t *value)
-+					bool tunnel, uint32_t *value)
- {
- 	struct mlx5_flex_pattern_field *map;
- 	struct mlx5_flex_item *tp = flex;
--	uint32_t def, i, pos, val;
-+	uint32_t i, pos, val;
- 	int id;
- 
-@@ -276,5 +274,5 @@ mlx5_flex_get_parser_value_per_byte_off(const struct rte_flow_item_flex *item,
- 	for (i = 0, pos = 0; i < tp->mapnum && pos < item->length * CHAR_BIT; i++) {
- 		map = tp->map + i;
--		id = mlx5_flex_get_sample_id(tp, i, &pos, tunnel, &def);
-+		id = mlx5_flex_get_sample_id(tp, i, &pos, tunnel);
- 		if (id == -1)
- 			continue;
-@@ -283,6 +281,4 @@ mlx5_flex_get_parser_value_per_byte_off(const struct rte_flow_item_flex *item,
- 		if (byte_off == tp->devx_fp->sample_info[id].sample_dw_data * sizeof(uint32_t)) {
- 			val = mlx5_flex_get_bitfield(item, pos, map->width, map->shift);
--			if (is_mask)
--				val &= RTE_BE32(def);
- 			*value |= val;
- 		}
-@@ -356,8 +352,8 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
- 	mask = item->mask;
+@@ -236,9 +240,8 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
@@ -180,0 +67 @@
+ 	MLX5_ASSERT(mlx5_flex_index(dev->data->dev_private, tp) >= 0);
@@ -184,3 +71,4 @@
- 		uint32_t val, msk, def;
--		int id = mlx5_flex_get_sample_id(tp, i, &pos, is_inner, &def);
-+		int id = mlx5_flex_get_sample_id(tp, i, &pos, is_inner);
+ 		uint32_t id = map->reg_id;
+-		uint32_t def = (RTE_BIT64(map->width) - 1) << map->shift;
+-		uint32_t val, msk;
++		uint32_t val, msk, def;
@@ -188,4 +76,4 @@
- 		if (id == -1)
-@@ -367,9 +363,12 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
- 		    id >= MLX5_GRAPH_NODE_SAMPLE_NUM)
- 			return;
+ 		/* Skip placeholders for DUMMY fields. */
+@@ -247,6 +250,9 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
+ 			continue;
+ 		}
@@ -198 +86,4 @@
- 		sample_id = tp->devx_fp->sample_ids[id];
+ 		MLX5_ASSERT(map->width);
+ 		MLX5_ASSERT(id < tp->devx_fp->num_samples);
+@@ -259,5 +265,5 @@ mlx5_flex_flow_translate_item(struct rte_eth_dev *dev,
+ 		}
@@ -202 +93 @@
- 					   sample_id, id);
+ 					   tp->devx_fp->sample_ids[id], id);



More information about the stable mailing list