DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: anatoly.burakov@intel.com
Cc: dev@dpdk.org, Stephen Hemminger <sthemmin@microsoft.com>
Subject: [dpdk-dev] [PATCH v2] examples/client_server_mp: check port ownership
Date: Mon,  3 Jun 2019 15:28:35 -0700	[thread overview]
Message-ID: <20190603222835.27909-1-stephen@networkplumber.org> (raw)
In-Reply-To: <20190529224321.20760-1-stephen@networkplumber.org>

From: Stephen Hemminger <sthemmin@microsoft.com>

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 <sthemmin@microsoft.com>
---
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 <errno.h>
 
 #include <rte_memory.h>
+#include <rte_ethdev.h>
 #include <rte_string_fns.h>
 
 #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


  reply	other threads:[~2019-06-03 22:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 22:43 [dpdk-dev] [PATCH] " Stephen Hemminger
2019-06-03 22:28 ` Stephen Hemminger [this message]
2019-07-04 20:48   ` [dpdk-dev] [PATCH v2] " Thomas Monjalon
2019-07-07  5:44   ` Matan Azrad
2019-07-07 16:47     ` Stephen Hemminger
2019-07-08  6:37       ` Matan Azrad
2019-07-08 14:49         ` Stephen Hemminger
2019-07-09  5:40           ` Matan Azrad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190603222835.27909-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=sthemmin@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).