From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by dpdk.org (Postfix) with ESMTP id 61B465595 for ; Fri, 7 Oct 2016 15:01:22 +0200 (CEST) Received: by mail-wm0-f45.google.com with SMTP id b201so37053460wmb.0 for ; Fri, 07 Oct 2016 06:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=L+fb3mFNCu+7Rbufe1n4SfImWrhR84J4zH9DG1rs+Bc=; b=pte26iTOH3Vovzz7M8a3cRSXvlT0iae00NhMIIzdn3Ogooy+YSxXoZ2rvqmITUpUu/ dgw1b8XigEkBgWMt0J10G+HCzfbL16SP7wyv/8uatrcsJ0QC9g57aKqQpUVpTFqu7Zo+ LBU/oBxQRsGqMUsfzH/V+2Ckz8Tn0jlfUIj+06csZfVVToxv3ff2reJUlVYAJyk6ziam Ag+HI5Jnw7g8MrAWyL4YcQ6F+skLQYkEyY4yow4ouy19uJDvzChSoj+rE9ZghfQlpQKD 4x0v0g6+YExGoGEb53FgJe/BWzty5oD8L0SU/Ot8CwMizwwy7MGS3secvKoRq1bcnOs6 Sx9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=L+fb3mFNCu+7Rbufe1n4SfImWrhR84J4zH9DG1rs+Bc=; b=ZBm5TB6ofpO6zgDx615jkaC0vYZ/VyTghXVu/5FXJDukj6d4jacoP8zhkFxmScGiYa O2nhjhtByWDwom34a+0vKhJeIWdnr+mLgFlNH6lvfRexIBLL+Pjo3u48wA99ELxjInLa MvvhVDRd/YVIW59PhtvTsFQ97ogznYa9OwHaNEe070w2JoFd1E1dlTSierxK0lkLjOEJ lW+Qa1x6zGpXNuwlcVwjt1PNTrfFn4Zlz2J7Zi64L5G1AUs+fhB5YHNN0OV8xMyNIs6p IvkTmt2mumAef9Jtdz191jezE3G5VSLeZFGhm4yM7Yv9apoaD/bQCPQCcbDJZ2FQbDVL T0jA== X-Gm-Message-State: AA6/9RmAKoGfkUx9jsNgYm/vKPlji4D6fri/TOupy6GB0Ed9Sy8ZD0O5/VV32kIFqM4Ag4Di X-Received: by 10.28.60.2 with SMTP id j2mr32678890wma.46.1475845282099; Fri, 07 Oct 2016 06:01:22 -0700 (PDT) Received: from gloops.dev.6wind.com (89.156.119.78.rev.sfr.net. [78.119.156.89]) by smtp.gmail.com with ESMTPSA id zz9sm19602199wjb.36.2016.10.07.06.01.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Oct 2016 06:01:21 -0700 (PDT) From: David Marchand To: thomas.monjalon@6wind.com Cc: dev@dpdk.org, danielx.t.mrzyglod@intel.com, shreyansh.jain@nxp.com Date: Fri, 7 Oct 2016 15:01:15 +0200 Message-Id: <1475845276-25527-1-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH 1/2] ethdev: fix hotplug attach X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2016 13:01:22 -0000 If a pci probe operation creates a port but, for any reason, fails to finish this operation and decides to delete the newly created port, then the last created port id can not be trusted anymore and any subsequent attach operations will fail. This problem was noticed while working on a vm that had a virtio-net management interface bound to the virtio-net kernel driver and no port whitelisted in the commandline: root@ubuntu1404:~/dpdk# ./build/app/testpmd -c 0x6 -- -i --total-num-mbufs=2049 EAL: Detected 3 lcore(s) EAL: Probing VFIO support... EAL: Debug logs available - lower performance EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles ! EAL: PCI device 0000:00:03.0 on NUMA socket -1 EAL: probe driver: 1af4:1000 (null) rte_eth_dev_pci_probe: driver (null): eth_dev_init(vendor_id=0x6900 device_id=0x1000) failed EAL: No probed ethernet devices ^ | Here, rte_eth_dev_pci_probe() fails since vtpci_init() reports an error. This results in a rte_eth_dev_release_port() right after a rte_eth_dev_allocate(). Then, if we try to attach a port using rte_eth_dev_attach: testpmd> port attach net_ring0 Attaching a new port... PMD: Initializing pmd_ring for net_ring0 PMD: Creating rings-backed ethdev on numa socket 0 Two solutions: - either update the last created port index to something invalid (when freeing a ethdev port), - or rely on the port count, before and after the eal attach. The latter solution seems (well not really more robust but at least) less fragile than the former. We still have some issues with drivers that create multiple ethdev ports with a single probe operation, but this was already the case. Fixes: b0fb26685570 ("ethdev: convert to EAL hotplug") Reported-by: Daniel Mrzyglod Signed-off-by: David Marchand --- lib/librte_ether/rte_ethdev.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index c517e88..24029f0 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -421,7 +421,7 @@ int rte_eth_dev_attach(const char *devargs, uint8_t *port_id) { int ret = -1; - int current = eth_dev_last_created_port; + int current = rte_eth_dev_count(); char *name = NULL; char *args = NULL; @@ -438,9 +438,9 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id) if (ret < 0) goto err; - /* no point looking at eth_dev_last_created_port if no port exists */ - if (!nb_ports) { - RTE_LOG(ERR, EAL, "No ports found for device (%s)\n", name); + /* no point looking at the port count if no port exists */ + if (!rte_eth_dev_count()) { + RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name); ret = -1; goto err; } @@ -448,7 +448,7 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id) /* if nothing happened, there is a bug here, since some driver told us * it did attach a device, but did not create a port. */ - if (current == eth_dev_last_created_port) { + if (current == rte_eth_dev_count()) { ret = -1; goto err; } -- 2.7.4