net/mlx5: fix count query when flow has not counter
authorNelio Laranjeiro <nelio.laranjeiro@6wind.com>
Wed, 25 Jul 2018 08:46:14 +0000 (10:46 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 26 Jul 2018 12:05:52 +0000 (14:05 +0200)
Querying a counters on a flow without counter is ending with a
segmentation fault.

Fixes: 60bd8c9747e8 ("net/mlx5: add count flow action")

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Acked-by: Ori Kam <orika@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
drivers/net/mlx5/mlx5_flow.c

index c156f01..b94c442 100644 (file)
@@ -3301,32 +3301,40 @@ mlx5_flow_query_count(struct rte_flow *flow __rte_unused,
                      struct rte_flow_error *error)
 {
 #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT
-       struct rte_flow_query_count *qc = data;
-       uint64_t counters[2] = {0, 0};
-       struct ibv_query_counter_set_attr query_cs_attr = {
-               .cs = flow->counter->cs,
-               .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
-       };
-       struct ibv_counter_set_data query_out = {
-               .out = counters,
-               .outlen = 2 * sizeof(uint64_t),
-       };
-       int err = mlx5_glue->query_counter_set(&query_cs_attr, &query_out);
+       if (flow->modifier & MLX5_FLOW_MOD_COUNT) {
+               struct rte_flow_query_count *qc = data;
+               uint64_t counters[2] = {0, 0};
+               struct ibv_query_counter_set_attr query_cs_attr = {
+                       .cs = flow->counter->cs,
+                       .query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
+               };
+               struct ibv_counter_set_data query_out = {
+                       .out = counters,
+                       .outlen = 2 * sizeof(uint64_t),
+               };
+               int err = mlx5_glue->query_counter_set(&query_cs_attr,
+                                                      &query_out);
 
-       if (err)
-               return rte_flow_error_set(error, err,
-                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-                                         NULL,
-                                         "cannot read counter");
-       qc->hits_set = 1;
-       qc->bytes_set = 1;
-       qc->hits = counters[0] - flow->counter->hits;
-       qc->bytes = counters[1] - flow->counter->bytes;
-       if (qc->reset) {
-               flow->counter->hits = counters[0];
-               flow->counter->bytes = counters[1];
+               if (err)
+                       return rte_flow_error_set
+                               (error, err,
+                                RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                NULL,
+                                "cannot read counter");
+               qc->hits_set = 1;
+               qc->bytes_set = 1;
+               qc->hits = counters[0] - flow->counter->hits;
+               qc->bytes = counters[1] - flow->counter->bytes;
+               if (qc->reset) {
+                       flow->counter->hits = counters[0];
+                       flow->counter->bytes = counters[1];
+               }
+               return 0;
        }
-       return 0;
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL,
+                                 "flow does not have counter");
 #endif
        return rte_flow_error_set(error, ENOTSUP,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,