From patchwork Mon Aug 5 16:38:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57465 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E3A3D1BDEE; Mon, 5 Aug 2019 18:38:28 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id AD3791BDE9 for ; Mon, 5 Aug 2019 18:38:27 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id t16so39893194pfe.11 for ; Mon, 05 Aug 2019 09:38:27 -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=kG/sWNTYcUPwVpfu8zp5HpjKmoozQobMP1JSQ8vnIRE=; b=bStvyfbNJdayJPrhOZoMOiZqKxJdk63y/b9jFwtijhE8LWGft9+fiFTU4sZP1vdpS1 einez0W5vvzQQpa4gKCck+6+sCxbiJUNQaXcqV45XLO+hTvoj0VTWU2vuoLgWZZ1cy0M 08R3shT+YLgYsR2Z9sw1wgofT0nzN9hOIwo8f32hxGfw/DchZYmFZgRbRTpEfb/0wH7e 3qmUx1LJj2mQkHLjJEg1VUXBgdmIjXZAQjb54odC7bZITNLIjWvw/eVI3T1MMnkLGDsN X2zHT3G0Uq7zcLrsMTpBi9w9RwiHLCYCkEKVCB4B3/OUbSniT1OrvmFHUcNv4BP81mMW DzHg== 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=kG/sWNTYcUPwVpfu8zp5HpjKmoozQobMP1JSQ8vnIRE=; b=UYS+JNo4vMFCMfiwWbII76lx3oWz3c4bdNiEI5ASazh2Urp6TJ5ooql0j7ceFFNa3J 6x/P9sL9nVEo/v7iPVy8P7FyGm5DyAiU8jTVRUNpwu4c+lapDkutwlvfmH93Z0fhcLB8 XA5tvANzy1Vli3ib7XWDvZDcA2Eh/cbolfkdWBty9m8jC+EikShqBkjQ3eFcgTVH6zzJ P3mb80pYDGcfiwVVkC5EqRAMy0WXCkZCpw1mhDVlqvJk3iw4guD/g7a7sfsXhBLmOLnl dKYMErhnyGdWrf6BYqvfwodGmIFVbbm89IEadgHwuJ3sDnPv5P/Tfq79hE3JAKSA1VIn lE2A== X-Gm-Message-State: APjAAAWEUmqhKuAeCUAwZ6p5IhRrvl/SWmoEHqcSq6tA0QZXX1kKrT5g VG1vFllM4oW+1wQlo2JPXnqZZ15t X-Google-Smtp-Source: APXvYqz+vSyzhi4JCdnwYdQKvlPYzURqXFXN5kIjjRjg7CA2s759R8bj/QtjVFgMDdiLUaudyUbyOQ== X-Received: by 2002:a63:e610:: with SMTP id g16mr133960258pgh.392.1565023106453; Mon, 05 Aug 2019 09:38:26 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t9sm19512797pji.18.2019.08.05.09.38.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 09:38:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 5 Aug 2019 09:38:16 -0700 Message-Id: <20190805163817.3713-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190805163817.3713-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190805163817.3713-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v7 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 | 40 ++++++++++--------- .../client_server_mp/mp_server/args.h | 2 +- .../client_server_mp/mp_server/init.c | 7 +--- 3 files changed, 25 insertions(+), 24 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..3c2ca266b096 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,34 @@ 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; + unsigned long long pm; + 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) + errno = 0; + pm = strtoull(portmask, &end, 16); + if (errno != 0 || end == NULL || *end != '\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 %#llx - ignoring\n", + pm); } return 0; @@ -99,7 +103,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 +116,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; From patchwork Mon Aug 5 16:38:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 57466 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8F7F01BDED; Mon, 5 Aug 2019 18:38:31 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id CF7DD1BDEC for ; Mon, 5 Aug 2019 18:38:28 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id i2so36710729plt.1 for ; Mon, 05 Aug 2019 09:38:28 -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=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=XxPvo+gXYntKoxYBoqs+Ieegp3M0x1eE+hUuzyHx8Eyf/oG3YfqZCA4Kfw9xL2IrSV VnIjLzUySVHruBexxFKdUG2zrBa/JCgyLhVqHlEmzLgI1vRHROMrHIV9xyJhbaWsCOYY USo4hQLwMKF/gRkS73F2Bts2YqkNonA0PCbckWQb1xIurK5y6rnfCQ0D+yzS5o3/spmY DU4qJA2D9baeUMBWXzDdkcH0dYpYTLML5Qdy8sGecyGhq4XcHaPYEP+IURt9k0ISWdt4 2m/kTldZwC107nsRSLaxrJJxpmKruUNU8i3gf/yMHLaz/q0MhFdCewutXHXBlShQ4hMy VnyQ== 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=8v7OSOzARnVHBELM/KAu2BccRvpC7XvWrmT3Mxp8KjI=; b=doeKKvcBP29n8nUUsFcOF7VUFecS3brwRKMRJWKcCm2rququpIVqTSTusqfMHAnAdx wuof4pMTTSSN75q/HvTTX8EzjoHObMVQNL06V+ig9gMienlj/7y9bk00i18+wzeJJWAK zhAnwaXMvASae/Mc89Rf3cGcrj83lWC8u2q1ecHKxY4UdFiVndyyEUcwxWQRGjtKr6E9 bbM5RVTrzBuBl58lJG1QPtY7fddiI/tEP8KOFwA3rARL9bCxx9IGEFSLjlqLKx2L+6W4 IuGvs5m6jpN4VwpWBw/UWyjZi2cQyGDBXtv5AVnR4aG9V0EGg7mOLwa0ssXIhQbgyFQ0 HSZA== X-Gm-Message-State: APjAAAVq425VnekWLY00snvVGdpbdNhrfNLJXquN1hCjAmenTVqYLgso 4LIA9lbxtrA616xNXCbMIkcwdFGx X-Google-Smtp-Source: APXvYqyqdTYYeNOSFNXN3MrzIsK7PNJeqS4v+5Zb0YbTyC7NQNmT6rp9QhAsJooesw+yjGWCtmk4zA== X-Received: by 2002:a17:902:2bcb:: with SMTP id l69mr146370856plb.155.1565023107774; Mon, 05 Aug 2019 09:38:27 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id t9sm19512797pji.18.2019.08.05.09.38.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 09:38:26 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 5 Aug 2019 09:38:17 -0700 Message-Id: <20190805163817.3713-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190805163817.3713-1-stephen@networkplumber.org> References: <20190726165054.24078-1-stephen@networkplumber.org> <20190805163817.3713-1-stephen@networkplumber.org> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v7 2/2] examples/multi_process/client_server_mp - fix crash in mp_client with sparse ports 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_client crashes if run on Azure or any system where ethdev ports are owned. In that case, the tx_buffer and tx_stats for the real port were initialized correctly, but the wrong port was used. For example if the server has Ports 3 and 5. Then calling rte_eth_tx_buffer_flush on any other buffer will dereference null because the tx buffer for that port was not allocated. Also: - the flush code is common enough that it should not be marked unlikely - combine conditions to reduce indentation - avoid unnecessary if() if sent is zero. Fixes: e2366e74e029 ("examples: use buffered Tx") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_client/client.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_client/client.c b/examples/multi_process/client_server_mp/mp_client/client.c index c23dd3f378f7..361d90b54b2d 100644 --- a/examples/multi_process/client_server_mp/mp_client/client.c +++ b/examples/multi_process/client_server_mp/mp_client/client.c @@ -246,19 +246,19 @@ main(int argc, char *argv[]) for (;;) { uint16_t i, rx_pkts; - uint16_t port; rx_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE, NULL); - if (unlikely(rx_pkts == 0)){ - if (need_flush) - for (port = 0; port < ports->num_ports; port++) { - sent = rte_eth_tx_buffer_flush(ports->id[port], client_id, - tx_buffer[port]); - if (unlikely(sent)) - tx_stats->tx[port] += sent; - } + if (rx_pkts == 0 && need_flush) { + for (i = 0; i < ports->num_ports; i++) { + uint16_t port = ports->id[i]; + + sent = rte_eth_tx_buffer_flush(port, + client_id, + tx_buffer[port]); + tx_stats->tx[port] += sent; + } need_flush = 0; continue; }