]> git.feebdaed.xyz Git - 0xmirror/dpdk.git/commitdiff
net/mlx5: fix sync HWS flow sample action validation
authorGregory Etelson <getelson@nvidia.com>
Thu, 6 Nov 2025 13:02:28 +0000 (15:02 +0200)
committerRaslan Darawsheh <rasland@nvidia.com>
Tue, 18 Nov 2025 11:33:58 +0000 (12:33 +0100)
The patch validates that sample actions include terminal action.

Fixes: d986f04d6529 ("net/mlx5: add functions for non-template flow sample")
Signed-off-by: Gregory Etelson <getelson@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
drivers/net/mlx5/mlx5_flow.h
drivers/net/mlx5/mlx5_flow_hw.c
drivers/net/mlx5/mlx5_nta_sample.c

index e8b298dd1df40b3606e1e318e3b1323fc28f5222..26d9e80a13a8672c7b7049ec5ff753175e070d27 100644 (file)
@@ -21,6 +21,9 @@
 #include "hws/mlx5dr.h"
 #include "mlx5_tx.h"
 
+#define MLX5_HW_PORT_IS_PROXY(priv) \
+       (!!((priv)->sh->esw_mode && (priv)->master))
+
 /* E-Switch Manager port, used for rte_flow_item_port_id. */
 #define MLX5_PORT_ESW_MGR UINT32_MAX
 
index 208f50fbfdec0a3515c9bb00c6efcba7b5127677..de400536c7d8c8bf1eb610ad3ed516de5915f111 100644 (file)
@@ -62,10 +62,6 @@ static struct rte_flow_fp_ops mlx5_flow_hw_fp_ops;
 #define MLX5_HW_VLAN_PUSH_VID_IDX 1
 #define MLX5_HW_VLAN_PUSH_PCP_IDX 2
 
-#define MLX5_HW_PORT_IS_PROXY(priv) \
-       (!!((priv)->sh->esw_mode && (priv)->master))
-
-
 struct mlx5_indlst_legacy {
        struct mlx5_indirect_list indirect;
        struct rte_flow_action_handle *handle;
index 938108cf4c0d42643c7ff0a405d5b15557f12a40..0b7b3d0c8ee3357e78f746e20707f664f4b57ef4 100644 (file)
@@ -525,6 +525,42 @@ validate_prefix_actions(const struct rte_flow_action *actions)
        return i < MLX5_HW_MAX_ACTS - 1;
 }
 
+static bool
+validate_sample_terminal_actions(const struct rte_eth_dev *dev,
+                                const struct rte_flow_attr *flow_attr,
+                                const struct rte_flow_action *actions)
+{
+       uint32_t i;
+       const struct mlx5_priv *priv = dev->data->dev_private;
+       const struct rte_flow_action_ethdev *port = NULL;
+       bool is_proxy = MLX5_HW_PORT_IS_PROXY(priv);
+       const struct rte_flow_action *a = NULL;
+
+       for (i = 0; actions[i].type != RTE_FLOW_ACTION_TYPE_END; i++) {
+               if (actions[i].type != RTE_FLOW_ACTION_TYPE_VOID)
+                       a = &actions[i];
+       }
+       if (a == NULL)
+               return false;
+       switch (a->type) {
+       case RTE_FLOW_ACTION_TYPE_JUMP:
+       case RTE_FLOW_ACTION_TYPE_QUEUE:
+       case RTE_FLOW_ACTION_TYPE_DROP:
+       case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
+               return true;
+       case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
+               if (!is_proxy || !flow_attr->transfer)
+                       return false;
+               port = a->conf;
+               if (!port || port->port_id != MLX5_REPRESENTED_PORT_ESW_MGR)
+                       return false;
+               return true;
+       default:
+               break;
+       }
+       return false;
+}
+
 static void
 action_append(struct rte_flow_action *actions, const struct rte_flow_action *last)
 {
@@ -829,10 +865,15 @@ mlx5_nta_sample_flow_list_create(struct rte_eth_dev *dev,
        }
        mlx5_nta_parse_sample_actions(actions, &sample, prefix_actions, suffix_actions);
        if (!validate_prefix_actions(prefix_actions)) {
-               rte_flow_error_set(error, -EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
+               rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
                                   NULL, "Too many actions");
                return NULL;
        }
+       if (!validate_sample_terminal_actions(dev, attr, sample)) {
+               rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
+                                  NULL, "Invalid sample actions");
+               return NULL;
+       }
        sample_conf = (const struct rte_flow_action_sample *)sample->conf;
        sample_actions = (struct rte_flow_action *)(uintptr_t)sample_conf->actions;
        mirror_entry = mlx5_create_nta_mirror(dev, attr, sample_actions,