From patchwork Wed Nov 7 09:41:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Guo, Jia" X-Patchwork-Id: 47922 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 ED63D49E0; Wed, 7 Nov 2018 10:37:33 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 5F461325F for ; Wed, 7 Nov 2018 10:37:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 01:37:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,475,1534834800"; d="scan'208";a="83978887" Received: from jeffguo-s2600wt2.sh.intel.com (HELO localhost.localdomain) ([10.67.110.10]) by fmsmga007.fm.intel.com with ESMTP; 07 Nov 2018 01:37:29 -0800 From: Jeff Guo To: ferruh.yigit@intel.com, konstantin.ananyev@intel.com, anatoly.burakov@intel.com, thomas@monjalon.net, bernard.iremonger@intel.com Cc: dev@dpdk.org, jia.guo@intel.com, helin.zhang@intel.com, stephen@networkplumber.org, gaetan.rivet@6wind.com, qi.z.zhang@intel.com, arybchenko@solarflare.com, bruce.richardson@intel.com, matan@mellanox.com, shaopeng.he@intel.com Date: Wed, 7 Nov 2018 17:41:30 +0800 Message-Id: <1541583691-145432-2-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541583691-145432-1-git-send-email-jia.guo@intel.com> References: <1541583691-145432-1-git-send-email-jia.guo@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] eal: expose device states in rte device 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" Since the hotplug API and device event API have make public, so in order to let applications or driver deal with device directly, it would be helpful if the states of device could be exposed, especially for hotplug process. This patch will add some devices states in rte device structure to recode the device's current status, such as “RTE_DEV_UNUSED”, “RTE_DEV_ATTACHED” and “RTE_DEV_REMOVED”. Signed-off-by: Jeff Guo --- lib/librte_eal/common/include/rte_dev.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index cd6c187..1bab0dd 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -151,6 +151,18 @@ struct rte_driver { #define RTE_DEV_NAME_MAX_LEN 64 /** + * Possible states of an rte devcie. + */ +enum rte_dev_state { + /** Device is unused before being hotplug add. */ + RTE_DEV_UNUSED = 0, + /** Device is attached when allocated in probing. */ + RTE_DEV_ATTACHED, + /** Device is in removed state when plug-out is detected. */ + RTE_DEV_REMOVED, +}; + +/** * A structure describing a generic device. */ struct rte_device { @@ -160,6 +172,7 @@ struct rte_device { const struct rte_bus *bus; /**< Bus handle assigned on scan */ int numa_node; /**< NUMA node connection */ struct rte_devargs *devargs; /**< Arguments for latest probing */ + enum rte_dev_state state; /**< Flag indicating the device state */ }; /** From patchwork Wed Nov 7 09:41:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Jia" X-Patchwork-Id: 47923 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 6F0B64C9C; Wed, 7 Nov 2018 10:37:35 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id BC8A14C8C for ; Wed, 7 Nov 2018 10:37:34 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 01:37:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,475,1534834800"; d="scan'208";a="83978901" Received: from jeffguo-s2600wt2.sh.intel.com (HELO localhost.localdomain) ([10.67.110.10]) by fmsmga007.fm.intel.com with ESMTP; 07 Nov 2018 01:37:32 -0800 From: Jeff Guo To: ferruh.yigit@intel.com, konstantin.ananyev@intel.com, anatoly.burakov@intel.com, thomas@monjalon.net, bernard.iremonger@intel.com Cc: dev@dpdk.org, jia.guo@intel.com, helin.zhang@intel.com, stephen@networkplumber.org, gaetan.rivet@6wind.com, qi.z.zhang@intel.com, arybchenko@solarflare.com, bruce.richardson@intel.com, matan@mellanox.com, shaopeng.he@intel.com Date: Wed, 7 Nov 2018 17:41:31 +0800 Message-Id: <1541583691-145432-3-git-send-email-jia.guo@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1541583691-145432-1-git-send-email-jia.guo@intel.com> References: <1541583691-145432-1-git-send-email-jia.guo@intel.com> Subject: [dpdk-dev] [PATCH 2/2] but/pci: fix fd close for hot-unplug 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" When device is hot-unplugged, the device fd will be deleted in kernel. Then in the progress of detaching device, if it try to close the fd, it will cause a kernel crash, which shown a kernel null pointer error. This patch aim to fix this issue by checking the device state to decide whether the fd need to be closed or not. Fixes: 5a60a7ffc801 ("pci: introduce functions to alloc and free uio resource") Fixes: 9b957f378abf ("pci: merge uio functions for linux and bsd") Fixes: 0fc54536b14a ("eal: add failure handling for hot-unplug") Signed-off-by: Jeff Guo --- drivers/bus/pci/linux/pci_uio.c | 3 +++ drivers/bus/pci/pci_common_uio.c | 16 +++++++++------- lib/librte_eal/linuxapp/eal/eal_dev.c | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index a7c1442..7844ed4 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -199,6 +199,9 @@ pci_uio_free_resource(struct rte_pci_device *dev, { rte_free(uio_res); + if (dev->device.state == RTE_DEV_REMOVED) + return; + if (dev->intr_handle.uio_cfg_fd >= 0) { close(dev->intr_handle.uio_cfg_fd); dev->intr_handle.uio_cfg_fd = -1; diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 7ea73db..bc329b5 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -227,12 +227,14 @@ pci_uio_unmap_resource(struct rte_pci_device *dev) rte_free(uio_res); /* close fd if in primary process */ - close(dev->intr_handle.fd); - if (dev->intr_handle.uio_cfg_fd >= 0) { - close(dev->intr_handle.uio_cfg_fd); - dev->intr_handle.uio_cfg_fd = -1; - } + if (dev->device.state != RTE_DEV_REMOVED && dev->intr_handle.fd >= 0) { + close(dev->intr_handle.fd); + if (dev->intr_handle.uio_cfg_fd >= 0) { + close(dev->intr_handle.uio_cfg_fd); + dev->intr_handle.uio_cfg_fd = -1; + } - dev->intr_handle.fd = -1; - dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; + dev->intr_handle.fd = -1; + dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; + } } diff --git a/lib/librte_eal/linuxapp/eal/eal_dev.c b/lib/librte_eal/linuxapp/eal/eal_dev.c index 2830c86..030e639 100644 --- a/lib/librte_eal/linuxapp/eal/eal_dev.c +++ b/lib/librte_eal/linuxapp/eal/eal_dev.c @@ -269,6 +269,7 @@ dev_uev_handler(__rte_unused void *param) goto failure_handle_err; } + dev->state = RTE_DEV_REMOVED; ret = bus->hot_unplug_handler(dev); if (ret) { RTE_LOG(ERR, EAL, "Can not handle hot-unplug "