From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 42DF8A045E for ; Thu, 30 May 2019 00:43:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A39F61B944; Thu, 30 May 2019 00:43:27 +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 8AEB1378B for ; Thu, 30 May 2019 00:43:26 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id d21so1679417plr.3 for ; Wed, 29 May 2019 15:43:26 -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:mime-version :content-transfer-encoding; bh=OJNv1vkxzK/R+YjawMrVeHohyEdDuIe+1TM5Rh68V3w=; b=1eGacqFHURQ3OtbtGmVep7pZC4m3oTYT+lAjkMCJR784lAe7Bnb31+CPeDPFlrjc4T LPcp0hQ1pnncI2Q2F56MejROERMODau1ARiusogv4km8vGqObnoshlyuqAZR+iqPoW4Y O3IfG1ZlCPgyGjFCF6mw4VO/oFuQmSFI9OOQKSH8qKnWuX9qjdCqbnaMUWM2M9mA903U obwjSubd16a3+UkjuFgaIBA+jtjOxTF7DI95rePNAURdN5Wpdu9wsq8d8CPgvSD5POZE Vf7dspmDCXqAdm8/g2ThaXNJGdRYeafACPf4fgHnIkwX4503cXgmT8gclSwofVDabFdU 9+/g== 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:mime-version :content-transfer-encoding; bh=OJNv1vkxzK/R+YjawMrVeHohyEdDuIe+1TM5Rh68V3w=; b=PpNZMHydiGdUjcoO/grJwchZfT42mU+oI7GkzmO2OmXZ7s/4N+nG/CcLdZWrNgUqS5 +TeNVOMxFtCJ0NF/W8J6L84vwIrRIpu8BKLQMCOIArUxTfGoYTXQbqnGzvgyVAayT/Hr iJGuYyim6ZzuZB70LV30Bd87vNrhAbzSPgk9HQJEyJWkgLzZ3M7DOVARTtPUwPR24Obf IAujNdboFjLHPJ8OiV2bobdimcDAlDCXppAr8YhJtaOalZrfHTkca7eY0OkzgXJScLgC C1aIipnd7VqeftkUPHckCroVSfgRoDE/ypbWdnNv48FXJggzviQFDtf51P76nalPQVzY PKLw== X-Gm-Message-State: APjAAAUnQD4yeZewfJQ+9o9TZ/nhW+skJPb42+MhUCpaz3cqD5j2e3r6 APWKZJSCMU6wsAXNCDYAvKScHg== X-Google-Smtp-Source: APXvYqzKQ025uBRB7r5CeXGcOvy8xoz7STlW3MzYTeC6/Q+Ii7KM/NkfePm/SsD91960bIxsJc6SEg== X-Received: by 2002:a17:902:b083:: with SMTP id p3mr380020plr.151.1559169805646; Wed, 29 May 2019 15:43:25 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id b18sm743933pfp.32.2019.05.29.15.43.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 15:43:23 -0700 (PDT) From: Stephen Hemminger To: anatoly.burakov@intel.com Cc: dev@dpdk.org, Stephen Hemminger , Stephen Hemminger Date: Wed, 29 May 2019 15:43:21 -0700 Message-Id: <20190529224321.20760-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] examples/client_server_mp: check port ownership 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" The mp_server would accept a port mask that included hidden (owned) ports and which later caused either lost packets or failed initialization. This fixes explictly checks for ownership when parsing the port mask. Fixes: 5b7ba31148a8 ("ethdev: add port ownership") Signed-off-by: Stephen Hemminger --- .../client_server_mp/mp_server/args.c | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 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..933f69a54296 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" @@ -45,27 +46,36 @@ parse_portmask(uint8_t max_ports, const char *portmask) { char *end = NULL; unsigned long pm; - uint16_t count = 0; + uint16_t count; 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; + for (count = 0; pm != 0; pm >>= 1, ++count) { + struct rte_eth_dev_owner owner; + + if ((pm & 0x1) == 0) + continue; + + if (count >= max_ports) { + printf("WARNING: requested port %u not present - ignoring\n", + count); + } else if (rte_eth_dev_owner_get(count, &owner) < 0) { + printf("ERROR: can not find port %u owner\n", count); + return -1; + } else if (owner.id != RTE_ETH_DEV_NO_OWNER) { + printf("ERROR: requested port %u is owned by device %s\n", + count, owner.name); + return -1; + } else { + ports->id[ports->num_ports++] = count; } - pm = (pm >> 1); - count++; } return 0; -- 2.20.1