app/testpmd: merge ports list update functions
[dpdk.git] / lib / librte_acl / acl_gen.c
index d3def66..bed66be 100644 (file)
@@ -1,38 +1,8 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 
 #include <rte_acl.h>
-#include "acl_vect.h"
 #include "acl.h"
 
 #define        QRANGE_MIN      ((uint8_t)INT8_MIN)
@@ -63,7 +33,8 @@ struct rte_acl_indices {
 static void
 acl_gen_log_stats(const struct rte_acl_ctx *ctx,
        const struct acl_node_counters *counts,
-       const struct rte_acl_indices *indices)
+       const struct rte_acl_indices *indices,
+       size_t max_size)
 {
        RTE_LOG(DEBUG, ACL, "Gen phase for ACL \"%s\":\n"
                "runtime memory footprint on socket %d:\n"
@@ -71,7 +42,8 @@ acl_gen_log_stats(const struct rte_acl_ctx *ctx,
                "quad nodes/vectors/bytes used: %d/%d/%zu\n"
                "DFA nodes/group64/bytes used: %d/%d/%zu\n"
                "match nodes/bytes used: %d/%zu\n"
-               "total: %zu bytes\n",
+               "total: %zu bytes\n"
+               "max limit: %zu bytes\n",
                ctx->name, ctx->socket_id,
                counts->single, counts->single * sizeof(uint64_t),
                counts->quad, counts->quad_vectors,
@@ -80,7 +52,8 @@ acl_gen_log_stats(const struct rte_acl_ctx *ctx,
                indices->dfa_index * sizeof(uint64_t),
                counts->match,
                counts->match * sizeof(struct rte_acl_match_results),
-               ctx->mem_sz);
+               ctx->mem_sz,
+               max_size);
 }
 
 static uint64_t
@@ -474,7 +447,7 @@ acl_calc_counts_indices(struct acl_node_counters *counts,
 int
 rte_acl_gen(struct rte_acl_ctx *ctx, struct rte_acl_trie *trie,
        struct rte_acl_bld_trie *node_bld_trie, uint32_t num_tries,
-       uint32_t num_categories, uint32_t data_index_sz)
+       uint32_t num_categories, uint32_t data_index_sz, size_t max_size)
 {
        void *mem;
        size_t total_size;
@@ -496,6 +469,14 @@ rte_acl_gen(struct rte_acl_ctx *ctx, struct rte_acl_trie *trie,
                (counts.match + 1) * sizeof(struct rte_acl_match_results) +
                XMM_SIZE;
 
+       if (total_size > max_size) {
+               RTE_LOG(DEBUG, ACL,
+                       "Gen phase for ACL ctx \"%s\" exceeds max_size limit, "
+                       "bytes required: %zu, allowed: %zu\n",
+                       ctx->name, total_size, max_size);
+               return -ERANGE;
+       }
+
        mem = rte_zmalloc_socket(ctx->name, total_size, RTE_CACHE_LINE_SIZE,
                        ctx->socket_id);
        if (mem == NULL) {
@@ -546,6 +527,6 @@ rte_acl_gen(struct rte_acl_ctx *ctx, struct rte_acl_trie *trie,
        ctx->trans_table = node_array;
        memcpy(ctx->trie, trie, sizeof(ctx->trie));
 
-       acl_gen_log_stats(ctx, &counts, &indices);
+       acl_gen_log_stats(ctx, &counts, &indices, max_size);
        return 0;
 }