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 9DA16A0096 for ; Tue, 4 Jun 2019 00:28:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9D55C1B9AE; Tue, 4 Jun 2019 00:28:40 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 1ED661B9AA for ; Tue, 4 Jun 2019 00:28:39 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id q17so11413965pfq.8 for ; Mon, 03 Jun 2019 15:28:39 -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=/CI00bKuGjRiu2szEZF/sipEIOLbbKUiOeeYSU7iBLs=; b=C14rSeudR2wFhdNfBEFkQK7y9hlXNm2TO/WG72QHBUixid4CdmLfDkIILyr567xBZG HqInPK7yqMHrbo+ojia81M0wfN2l8IXtPWN37UD8BeljJamm8pm4kc/PFVOm3Dgz26mp Yk1qgw/qPEVHn/isMLAzOsG/0TKexYYEpv+Kb+j30pu0ujK7jVt6Vgo4IqWkazli4ypM iWb67tvE/YlBwguKvYoeY5tljW6PRV2f2pfvecBKSe93RsUhzb+xtTKPuzvF5p7q/X4z tVw7lLRhqBU6GrkWRWLOWdpMiSW0eAInd+1E/1PKjlJtWjeUhLrJ+t4hX1gNsgiDMMQw RKxA== 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=/CI00bKuGjRiu2szEZF/sipEIOLbbKUiOeeYSU7iBLs=; b=Pvc+qerZma5eJ0lyqvg17ONrFA/1hQ3s0ZJShczzuqYZBF52sFb/Jo2lzM52Y2KUZq 2cuKT+QHXXt8R8iRsHr0oEo/+fgxlq+MqX8AsHiU1amQiJ1RCbz1EtfGfCGqjXEwjmi1 Y4FJrO6I6cRfpgw/EjjwVT9S6jYqcQhLrvxU3amNRS/YUbO1+dRNm5KaMZaHFlfEQA4D HFIaJgLyzJO5ca0s9hVS846jan6JxY1gFhcRnp2Y2q1tyKLkFRMYAw2RY5asbkIb5OGJ LG/SJUjhXLAazTueiRalpH3j8BRo5R1FSgcpPxIzwOZssMbzB7csAILUfkSNHwEqgbez pgtA== X-Gm-Message-State: APjAAAWIxMe9DBWnXCfjTV2VKHNsBgnOPYKoIOJ8UfAW51+7ujLL05Uk KExGpBWE0+JpBmWrEzhz+pW+DQ== X-Google-Smtp-Source: APXvYqyxarzpb8E72p3nl9+1I5PgxcziwmUG/+lfreKevxgUMfK3hnN/tZgn6yUYKYmLiaEHhyp2NQ== X-Received: by 2002:a17:90a:bd8b:: with SMTP id z11mr32075957pjr.39.1559600918279; Mon, 03 Jun 2019 15:28:38 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id v4sm18769347pfe.180.2019.06.03.15.28.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2019 15:28:37 -0700 (PDT) From: Stephen Hemminger To: anatoly.burakov@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Mon, 3 Jun 2019 15:28:35 -0700 Message-Id: <20190603222835.27909-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190529224321.20760-1-stephen@networkplumber.org> References: <20190529224321.20760-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] 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" From: Stephen Hemminger 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 explicitly checks for ownership when parsing the port mask. Fixes: 5b7ba31148a8 ("ethdev: add port ownership") Signed-off-by: Stephen Hemminger --- v2 - fix checkpatch complains about return and else .../client_server_mp/mp_server/args.c | 35 +++++++++++++------ 1 file changed, 24 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..72cb85008c39 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,39 @@ 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); + continue; + } + if (rte_eth_dev_owner_get(count, &owner) < 0) { + printf("ERROR: can not find port %u owner\n", count); + return -1; } - pm = (pm >> 1); - count++; + if (owner.id != RTE_ETH_DEV_NO_OWNER) { + printf("ERROR: requested port %u is owned by device %s\n", + count, owner.name); + return -1; + } + + ports->id[ports->num_ports++] = count; } return 0; -- 2.20.1