net/mlx5: control flow rules with identical pattern
authorJiawei Wang <jiaweiw@nvidia.com>
Tue, 6 Jul 2021 08:12:27 +0000 (11:12 +0300)
committerRaslan Darawsheh <rasland@nvidia.com>
Thu, 8 Jul 2021 20:09:35 +0000 (22:09 +0200)
In order to allow\disallow configuring rules with identical
patterns, the new device argument 'allow_duplicate_pattern'
is introduced.
If allow, these rules be inserted successfully and only the
first rule take affect.
If disallow, the first rule will be inserted and other rules
be rejected.

The default is to allow.
Set it to 0 if disallow, for example:
-a <PCI_BDF>,allow_duplicate_pattern=0

Signed-off-by: Jiawei Wang <jiaweiw@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
doc/guides/nics/mlx5.rst
doc/guides/rel_notes/release_21_08.rst
drivers/common/mlx5/linux/meson.build
drivers/common/mlx5/linux/mlx5_glue.c
drivers/common/mlx5/linux/mlx5_glue.h
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow_dv.c

index 41ae239..5a3c4f1 100644 (file)
@@ -1071,6 +1071,20 @@ Driver options
 
   By default, the PMD will set this value to 1.
 
+- ``allow_duplicate_pattern`` parameter [int]
+
+  There are two options to choose:
+
+  - 0. Prevent insertion of rules with the same pattern items on non-root table.
+    In this case, only the first rule is inserted and the following rules are
+    rejected and error code EEXIST is returned.
+
+  - 1. Allow insertion of rules with the same pattern items.
+    In this case, all rules are inserted but only the first rule takes effect,
+    the next rule takes effect only if the previous rules are deleted.
+
+  By default, the PMD will set this value to 1.
+
 .. _mlx5_firmware_config:
 
 Firmware configuration
index ddd172b..276feaa 100644 (file)
@@ -87,6 +87,7 @@ New Features
 * **Updated Mellanox mlx5 driver.**
 
   * Added support for meter hierarchy.
+  * Added devargs options ``allow_duplicate_pattern``.
 
 * **Added support for Marvell CNXK crypto driver.**
 
index 007834a..3a3cb93 100644 (file)
@@ -191,6 +191,8 @@ has_sym_args = [
             'mlx5dv_dump_dr_rule' ],
         [ 'HAVE_MLX5_DR_ACTION_ASO_CT', 'infiniband/mlx5dv.h',
             'MLX5DV_DR_ACTION_FLAGS_ASO_CT_DIRECTION_INITIATOR' ],
+        [ 'HAVE_MLX5_DR_ALLOW_DUPLICATE', 'infiniband/mlx5dv.h',
+            'mlx5dv_dr_domain_allow_duplicate_rules' ],
 ]
 config = configuration_data()
 foreach arg:has_sym_args
index d3bd645..145cf83 100644 (file)
@@ -1321,6 +1321,17 @@ mlx5_glue_dv_alloc_pp(struct ibv_context *context,
 #endif
 }
 
+static void
+mlx5_glue_dr_allow_duplicate_rules(void *domain, uint32_t allow)
+{
+#ifdef HAVE_MLX5_DR_ALLOW_DUPLICATE
+       mlx5dv_dr_domain_allow_duplicate_rules(domain, allow);
+#else
+       (void)(allow);
+       (void)(domain);
+#endif
+}
+
 static void
 mlx5_glue_dv_free_pp(struct mlx5dv_pp *pp)
 {
@@ -1441,6 +1452,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
                mlx5_glue_dr_create_flow_action_sampler,
        .dr_create_flow_action_dest_array =
                mlx5_glue_dr_action_create_dest_array,
+       .dr_allow_duplicate_rules = mlx5_glue_dr_allow_duplicate_rules,
        .devx_query_eqn = mlx5_glue_devx_query_eqn,
        .devx_create_event_channel = mlx5_glue_devx_create_event_channel,
        .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
index 97462e9..56246bc 100644 (file)
@@ -336,6 +336,7 @@ struct mlx5_glue {
                         struct mlx5dv_devx_async_event_hdr *event_data,
                         size_t event_resp_len);
        void (*dr_reclaim_domain_memory)(void *domain, uint32_t enable);
+       void (*dr_allow_duplicate_rules)(void *domain, uint32_t allow);
        struct mlx5dv_pp *(*dv_alloc_pp)(struct ibv_context *context,
                                         size_t pp_context_sz,
                                         const void *pp_context,
index 21b6214..b94696b 100644 (file)
@@ -355,6 +355,15 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
                        mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1);
        }
        sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
+       if (!priv->config.allow_duplicate_pattern) {
+#ifndef HAVE_MLX5_DR_ALLOW_DUPLICATE
+               DRV_LOG(WARNING, "Disallow duplicate pattern is not supported - maybe old rdma-core version?");
+#endif
+               mlx5_glue->dr_allow_duplicate_rules(sh->rx_domain, 0);
+               mlx5_glue->dr_allow_duplicate_rules(sh->tx_domain, 0);
+               if (sh->fdb_domain)
+                       mlx5_glue->dr_allow_duplicate_rules(sh->fdb_domain, 0);
+       }
 #endif /* HAVE_MLX5DV_DR */
        sh->default_miss_action =
                        mlx5_glue->dr_create_flow_action_default_miss();
@@ -2375,6 +2384,7 @@ mlx5_os_pci_probe_pf(struct rte_pci_device *pci_dev,
                dev_config.dv_flow_en = 1;
                dev_config.decap_en = 1;
                dev_config.log_hp_size = MLX5_ARG_UNSET;
+               dev_config.allow_duplicate_pattern = 1;
                list[i].eth_dev = mlx5_dev_spawn(&pci_dev->device,
                                                 &list[i],
                                                 &dev_config,
index abd573e..44fbc2d 100644 (file)
 /* Decap will be used or not. */
 #define MLX5_DECAP_EN "decap_en"
 
+/* Device parameter to configure allow or prevent duplicate rules pattern. */
+#define MLX5_ALLOW_DUPLICATE_PATTERN "allow_duplicate_pattern"
+
 /* Shared memory between primary and secondary processes. */
 struct mlx5_shared_data *mlx5_shared_data;
 
@@ -1946,6 +1949,8 @@ mlx5_args_check(const char *key, const char *val, void *opaque)
                config->sys_mem_en = !!tmp;
        } else if (strcmp(MLX5_DECAP_EN, key) == 0) {
                config->decap_en = !!tmp;
+       } else if (strcmp(MLX5_ALLOW_DUPLICATE_PATTERN, key) == 0) {
+               config->allow_duplicate_pattern = !!tmp;
        } else {
                DRV_LOG(WARNING, "%s: unknown parameter", key);
                rte_errno = EINVAL;
@@ -2005,6 +2010,7 @@ mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs)
                MLX5_RECLAIM_MEM,
                MLX5_SYS_MEM_EN,
                MLX5_DECAP_EN,
+               MLX5_ALLOW_DUPLICATE_PATTERN,
                NULL,
        };
        struct rte_kvargs *kvlist;
index 2c8a956..f864c1d 100644 (file)
@@ -244,6 +244,8 @@ struct mlx5_dev_config {
        unsigned int sys_mem_en:1; /* The default memory allocator. */
        unsigned int decap_en:1; /* Whether decap will be used or not. */
        unsigned int dv_miss_info:1; /* restore packet after partial hw miss */
+       unsigned int allow_duplicate_pattern:1;
+       /* Allow/Prevent the duplicate rules pattern. */
        struct {
                unsigned int enabled:1; /* Whether MPRQ is enabled. */
                unsigned int stride_num_n; /* Number of strides. */
index 2e56e7c..fa05882 100644 (file)
@@ -13362,10 +13362,14 @@ flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
                                               (void *)&dv->value, n,
                                               dv->actions, &dh->drv_flow);
                if (err) {
-                       rte_flow_error_set(error, errno,
-                                          RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                          NULL,
-                                          "hardware refuses to create flow");
+                       rte_flow_error_set
+                               (error, errno,
+                               RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                               NULL,
+                               (!priv->config.allow_duplicate_pattern &&
+                               errno == EEXIST) ?
+                               "duplicating pattern is not allowed" :
+                               "hardware refuses to create flow");
                        goto error;
                }
                if (priv->vmwa_context &&