From patchwork Thu Jul 12 14:01:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 42974 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4B1801B450; Thu, 12 Jul 2018 16:01:12 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 834C71B443; Thu, 12 Jul 2018 16:01:08 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2018 07:01:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,343,1526367600"; d="scan'208";a="56361024" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by orsmga008.jf.intel.com with ESMTP; 12 Jul 2018 07:01:06 -0700 From: Qi Zhang To: thomas@monjalon.net, anatoly.burakov@intel.com, gaetan.rivet@6wind.com Cc: dev@dpdk.org, Qi Zhang , stable@dpdk.org Date: Thu, 12 Jul 2018 22:01:41 +0800 Message-Id: <20180712140144.18146-2-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180712140144.18146-1-qi.z.zhang@intel.com> References: <20180712140144.18146-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH 1/4] eal: fix hotplug add and hotplug remove 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" 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") Cc: stable@dpdk.org 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",