From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by dpdk.org (Postfix) with ESMTP id 39C4E23D for ; Mon, 30 Jul 2018 18:21:04 +0200 (CEST) Received: from 1.general.paelzer.uk.vpn ([10.172.196.172] helo=lap.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fkArd-00009D-AC; Mon, 30 Jul 2018 16:17:41 +0000 From: Christian Ehrhardt To: Qi Zhang Cc: Gaetan Rivet , dpdk stable Date: Mon, 30 Jul 2018 18:12:46 +0200 Message-Id: <20180730161342.16566-121-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180730161342.16566-1-christian.ehrhardt@canonical.com> References: <20180730161342.16566-1-christian.ehrhardt@canonical.com> Subject: [dpdk-stable] patch 'eal: fix hotplug add and remove' has been queued to stable release 18.05.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2018 16:21:04 -0000 Hi, FYI, your patch has been queued to stable release 18.05.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 08/01/18. So please shout if anyone has objections. Thanks. Christian Ehrhardt --- >>From 81c2ea6390212c959872e06b58ed35c790a5aa4f Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Thu, 12 Jul 2018 22:01:41 +0800 Subject: [PATCH] eal: fix hotplug add and remove [ upstream commit 196e9a486cb1a0fd929a15244e7d9169ef5ede00 ] If hotplug add an already plugged PCI device, it will cause rte_pci_device->device.name be corrupted due to unexpected rte_devargs_remove. Also if try to hotplug remove an already unplugged device, it will cause segment fault due to unexpected bus->unplug on a rte_device whose driver is NULL. The patch fix these issues. Fixes: 7e8b26650146 ("eal: fix hotplug add / remove") Signed-off-by: Qi Zhang Acked-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 61cb3b162..0fa8c815d 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -42,18 +42,6 @@ static struct dev_event_cb_list dev_event_cbs; /* spinlock for device callbacks */ static rte_spinlock_t dev_event_lock = RTE_SPINLOCK_INITIALIZER; -static int cmp_detached_dev_name(const struct rte_device *dev, - const void *_name) -{ - const char *name = _name; - - /* skip attached devices */ - if (dev->driver != NULL) - return 1; - - return strcmp(dev->name, name); -} - static int cmp_dev_name(const struct rte_device *dev, const void *_name) { const char *name = _name; @@ -151,14 +139,19 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn if (ret) goto err_devarg; - dev = bus->find_device(NULL, cmp_detached_dev_name, devname); + dev = bus->find_device(NULL, cmp_dev_name, devname); if (dev == NULL) { - RTE_LOG(ERR, EAL, "Cannot find unplugged device (%s)\n", + RTE_LOG(ERR, EAL, "Cannot find device (%s)\n", devname); ret = -ENODEV; goto err_devarg; } + if (dev->driver != NULL) { + RTE_LOG(ERR, EAL, "Device is already plugged\n"); + return -EEXIST; + } + ret = bus->plug(dev); if (ret) { RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", @@ -200,6 +193,11 @@ rte_eal_hotplug_remove(const char *busname, const char *devname) return -EINVAL; } + if (dev->driver == NULL) { + RTE_LOG(ERR, EAL, "Device is already unplugged\n"); + return -ENOENT; + } + ret = bus->unplug(dev); if (ret) RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", -- 2.17.1