From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E46AEA10DA for ; Sat, 3 Aug 2019 01:52:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 728FE1C437; Sat, 3 Aug 2019 01:52:35 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id DDDCE1C2F5 for ; Sat, 3 Aug 2019 01:52:31 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id p184so36766154pfp.7 for ; Fri, 02 Aug 2019 16:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zc5wLVYzGdBzMnqa1CvBFKrqffPTJWatPwgXmOWAuj4=; b=Cw55S5zOW6WC26lpYPuFHo6DDicO5eUbNHy42RM4p9ZvJwwcwTXdT/TUwl3guo7Puc rli3UR2ClsAw2b76m5P0a8245dVz9vK/Ds8yZIyQ3Nx9c7hfhOU/YzfXPsnr1ISnR8Mq Chx0pj9VsoT4RMm8Q5FRQunLue25F3Ll7Iw8wyvMmAu5KIkFEvH6tlzkHP+J/TtARx4r cVciJX3l1RQ2zug+00ljTXjTTvabAzeOCMPdDWrhkxIkob0HNJz91bjkAUuNUlnZpNsV 3im8Oba/RsYy1F9k9OVeYJHlxk2Wr1K5doualo5Ljl8ZDgSmPXTNga2JyjGXNlN3cdS2 rLuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zc5wLVYzGdBzMnqa1CvBFKrqffPTJWatPwgXmOWAuj4=; b=VvtMVBYwU8+xAwa7iH8/mb/aqi0WuP0KAQ0VT9lbFOG1xuGj/1n35kggQDaDp0vmlC nKzc8+f6MwugI+K9BSSLPhIfzBduLpz1ryIdlN14MdUAQSFmVDFQckenPJmgG8cMo5QW wD4JCpHF3IEITQwgJCiJOf1PRHFcRkIHvnZQ0y0feNkwHT25J6Z+jqzK5qMMptgD7jBr mA9OiRYGvms/CFCn4Vp53AmdqQiRYVg7iDbpm0oA3hc6sjnz2xGaRledVMxOa9TW3pIN GsaWT/W0GT7xwTffwYIN8fZyiqp61iR+DSVGIs8NsPXKGuzwBzAExfjjmRu6mrBI7vRA XwPg== X-Gm-Message-State: APjAAAUrzij/G5C1ethKq1YtbPL7rYwyzwMf9CHl1jeCkbYtnq+oSeGU +s5XCr8AayVTx6lpWLRAsZF4JeRCWgQ= X-Google-Smtp-Source: APXvYqxG6fB5HTlefcsgEJxOSwxZFIpMGELstSlBVj9nRbT0ZRmc5ppFKfZihH4zUrLTniBPNfgq0g== X-Received: by 2002:a17:90a:3ac2:: with SMTP id b60mr6797581pjc.74.1564789950817; Fri, 02 Aug 2019 16:52:30 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t6sm5629229pgu.23.2019.08.02.16.52.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 02 Aug 2019 16:52:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Fri, 2 Aug 2019 16:52:21 -0700 Message-Id: <20190802235222.20682-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190802235222.20682-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190802235222.20682-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 1/2] examples/multi_process/client_server_mp: check port validity X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Stephen Hemminger The mp_server incorrectly allows a port mask that included hidden ports and which later caused either lost packets or failed initialization. This fixes explicitly checking that each bit in portmask is a valid port before using it. Fixes: 5b7ba31148a8 ("ethdev: add port ownership") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_server/args.c | 35 ++++++++++--------- .../client_server_mp/mp_server/args.h | 2 +- .../client_server_mp/mp_server/init.c | 7 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/args.c b/examples/multi_process/client_server_mp/mp_server/args.c index b0d8d7665c85..fdc008b3d677 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.c +++ b/examples/multi_process/client_server_mp/mp_server/args.c @@ -10,6 +10,7 @@ #include #include +#include #include #include "common.h" @@ -41,31 +42,33 @@ usage(void) * array variable */ static int -parse_portmask(uint8_t max_ports, const char *portmask) +parse_portmask(const char *portmask) { char *end = NULL; unsigned long pm; - uint16_t count = 0; + uint16_t id; if (portmask == NULL || *portmask == '\0') return -1; /* convert parameter to a number and verify */ pm = strtoul(portmask, &end, 16); - if (end == NULL || *end != '\0' || pm == 0) + if (end == NULL || *end != '\0' || pm > UINT16_MAX || pm == 0) return -1; - /* loop through bits of the mask and mark ports */ - while (pm != 0){ - if (pm & 0x01){ /* bit is set in mask, use port */ - if (count >= max_ports) - printf("WARNING: requested port %u not present" - " - ignoring\n", (unsigned)count); - else - ports->id[ports->num_ports++] = count; - } - pm = (pm >> 1); - count++; + RTE_ETH_FOREACH_DEV(id) { + unsigned long msk = 1u << id; + + if ((pm & msk) == 0) + continue; + + pm &= ~msk; + ports->id[ports->num_ports++] = id; + } + + if (pm != 0) { + printf("WARNING: leftover ports in mask %#lx - ignoring\n", + pm); } return 0; @@ -99,7 +102,7 @@ parse_num_clients(const char *clients) * on error. */ int -parse_app_args(uint16_t max_ports, int argc, char *argv[]) +parse_app_args(int argc, char *argv[]) { int option_index, opt; char **argvopt = argv; @@ -112,7 +115,7 @@ parse_app_args(uint16_t max_ports, int argc, char *argv[]) &option_index)) != EOF){ switch (opt){ case 'p': - if (parse_portmask(max_ports, optarg) != 0){ + if (parse_portmask(optarg) != 0) { usage(); return -1; } diff --git a/examples/multi_process/client_server_mp/mp_server/args.h b/examples/multi_process/client_server_mp/mp_server/args.h index 79c190a33a37..52c8cc86e6f0 100644 --- a/examples/multi_process/client_server_mp/mp_server/args.h +++ b/examples/multi_process/client_server_mp/mp_server/args.h @@ -5,6 +5,6 @@ #ifndef _ARGS_H_ #define _ARGS_H_ -int parse_app_args(uint16_t max_ports, int argc, char *argv[]); +int parse_app_args(int argc, char *argv[]); #endif /* ifndef _ARGS_H_ */ diff --git a/examples/multi_process/client_server_mp/mp_server/init.c b/examples/multi_process/client_server_mp/mp_server/init.c index 3af5dc6994bf..1b0569937b51 100644 --- a/examples/multi_process/client_server_mp/mp_server/init.c +++ b/examples/multi_process/client_server_mp/mp_server/init.c @@ -238,7 +238,7 @@ init(int argc, char *argv[]) { int retval; const struct rte_memzone *mz; - uint16_t i, total_ports; + uint16_t i; /* init EAL, parsing EAL args */ retval = rte_eal_init(argc, argv); @@ -247,9 +247,6 @@ init(int argc, char *argv[]) argc -= retval; argv += retval; - /* get total number of ports */ - total_ports = rte_eth_dev_count_total(); - /* set up array for port data */ mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports), rte_socket_id(), NO_FLAGS); @@ -259,7 +256,7 @@ init(int argc, char *argv[]) ports = mz->addr; /* parse additional, application arguments */ - retval = parse_app_args(total_ports, argc, argv); + retval = parse_app_args(argc, argv); if (retval != 0) return -1; -- 2.20.1