app/testpmd: fix invalid Rx queue number setting
authorWei Dai <wei.dai@intel.com>
Fri, 12 Jan 2018 11:31:21 +0000 (19:31 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 17 Jan 2018 17:49:38 +0000 (18:49 +0100)
If an invalid number of RX queues is configured from testpmd run-time
command like "port config all rxq number" or from --rxq in the command
to start testpmd, the global variable nb_rxq is updated by this invalid
value without this patch. It may cause testpmd crash. This patch refuses
invalid rxq setting and keeps its last correct value.

Fixes: ce8d561418d4 ("app/testpmd: add port configuration settings")
Cc: stable@dpdk.org
Signed-off-by: Wei Dai <wei.dai@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Tested-by: Yuan Peng <yuan.peng@intel.com>
app/test-pmd/cmdline.c
app/test-pmd/parameters.c
app/test-pmd/testpmd.c
app/test-pmd/testpmd.h

index 31919ba..122f705 100644 (file)
@@ -1538,6 +1538,8 @@ cmd_config_rx_tx_parsed(void *parsed_result,
                        printf("Warning: Either rx or tx queues should be non zero\n");
                        return;
                }
+               if (check_nb_rxq(res->value) != 0)
+                       return;
                nb_rxq = res->value;
        }
        else if (!strcmp(res->name, "txq")) {
index 878c112..3722ffb 100644 (file)
@@ -539,6 +539,7 @@ launch_args_parse(int argc, char** argv)
        int n, opt;
        char **argvopt;
        int opt_idx;
+       portid_t pid;
        enum { TX, RX };
        /* Default offloads for all ports. */
        uint64_t rx_offloads = rx_mode.offloads;
@@ -925,12 +926,12 @@ launch_args_parse(int argc, char** argv)
                                rss_hf = ETH_RSS_UDP;
                        if (!strcmp(lgopts[opt_idx].name, "rxq")) {
                                n = atoi(optarg);
-                               if (n >= 0 && n <= (int) MAX_QUEUE_ID)
+                               if (n >= 0 && check_nb_rxq((queueid_t)n) == 0)
                                        nb_rxq = (queueid_t) n;
                                else
                                        rte_exit(EXIT_FAILURE, "rxq %d invalid - must be"
-                                                 " >= 0 && <= %d\n", n,
-                                                 (int) MAX_QUEUE_ID);
+                                                 " >= 0 && <= %u\n", n,
+                                                 get_allowed_max_nb_rxq(&pid));
                        }
                        if (!strcmp(lgopts[opt_idx].name, "txq")) {
                                n = atoi(optarg);
index c066cf9..b74b4a4 100644 (file)
@@ -534,6 +534,52 @@ check_socket_id(const unsigned int socket_id)
        return 0;
 }
 
+/*
+ * Get the allowed maximum number of RX queues.
+ * *pid return the port id which has minimal value of
+ * max_rx_queues in all ports.
+ */
+queueid_t
+get_allowed_max_nb_rxq(portid_t *pid)
+{
+       queueid_t allowed_max_rxq = MAX_QUEUE_ID;
+       portid_t pi;
+       struct rte_eth_dev_info dev_info;
+
+       RTE_ETH_FOREACH_DEV(pi) {
+               rte_eth_dev_info_get(pi, &dev_info);
+               if (dev_info.max_rx_queues < allowed_max_rxq) {
+                       allowed_max_rxq = dev_info.max_rx_queues;
+                       *pid = pi;
+               }
+       }
+       return allowed_max_rxq;
+}
+
+/*
+ * Check input rxq is valid or not.
+ * If input rxq is not greater than any of maximum number
+ * of RX queues of all ports, it is valid.
+ * if valid, return 0, else return -1
+ */
+int
+check_nb_rxq(queueid_t rxq)
+{
+       queueid_t allowed_max_rxq;
+       portid_t pid = 0;
+
+       allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
+       if (rxq > allowed_max_rxq) {
+               printf("Fail: input rxq (%u) can't be greater "
+                      "than max_rx_queues (%u) of port %u\n",
+                      rxq,
+                      allowed_max_rxq,
+                      pid);
+               return -1;
+       }
+       return 0;
+}
+
 static void
 init_config(void)
 {
index 9c739e5..eb7697c 100644 (file)
@@ -684,6 +684,9 @@ enum print_warning {
 int port_id_is_invalid(portid_t port_id, enum print_warning warning);
 int new_socket_id(unsigned int socket_id);
 
+queueid_t get_allowed_max_nb_rxq(portid_t *pid);
+int check_nb_rxq(queueid_t rxq);
+
 /*
  * Work-around of a compilation error with ICC on invocations of the
  * rte_be_to_cpu_16() function.