DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jeff Guo <jia.guo@intel.com>
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
Subject: [dpdk-dev] [PATCH 2/2] but/pci: fix fd close for hot-unplug
Date: Wed,  7 Nov 2018 17:41:31 +0800	[thread overview]
Message-ID: <1541583691-145432-3-git-send-email-jia.guo@intel.com> (raw)
In-Reply-To: <1541583691-145432-1-git-send-email-jia.guo@intel.com>

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 <jia.guo@intel.com>
---
 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 "
-- 
2.7.4

  parent reply	other threads:[~2018-11-07  9:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-07  9:41 [dpdk-dev] [PATCH 0/2] expose device states " Jeff Guo
2018-11-07  9:41 ` [dpdk-dev] [PATCH 1/2] eal: expose device states in rte device Jeff Guo
2018-11-07 19:32   ` Stephen Hemminger
2018-11-09  7:35     ` Jeff Guo
2018-11-07  9:41 ` Jeff Guo [this message]
2018-11-07 19:33   ` [dpdk-dev] [PATCH 2/2] but/pci: fix fd close for hot-unplug Stephen Hemminger
2018-11-08  3:10     ` Jeff Guo
2018-11-08 21:55       ` Stephen Hemminger
2018-11-09  3:26         ` Jeff Guo

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=1541583691-145432-3-git-send-email-jia.guo@intel.com \
    --to=jia.guo@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=arybchenko@solarflare.com \
    --cc=bernard.iremonger@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=gaetan.rivet@6wind.com \
    --cc=helin.zhang@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=matan@mellanox.com \
    --cc=qi.z.zhang@intel.com \
    --cc=shaopeng.he@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /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).