DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/3] vfio hotplug feature
@ 2015-08-04 11:38 Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Harpal Singh @ 2015-08-04 11:38 UTC (permalink / raw)
  To: dev; +Cc: Harpal Singh

From: Harpal Singh <harpal.sd@samsung.com>

This patch set will provide vfio hotplug removal feature. It include 3 patches:-
1) First patch adds the vfio unmap resource feature, which will release the resources allocated during initialization phase.
2) Second patch adds vfio req interrupt support, which will help vfio kernel module to send signal when device has been removed from pci slot.
3) Third patch has provided a test program to test above two features.

Harpal Singh (3):
  vfio: Added hot removal feature for vfio
  vfio: Added vfio req interrupt support
  vfio: Added hotplug test program

 app/test/Makefile                                  |   2 +-
 app/test/test_hotplug.c                            | 259 +++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h            |   3 +
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       |  67 ++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c              |   4 +-
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |   1 +
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c         |  60 +++++
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |   1 +
 8 files changed, 395 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_hotplug.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio
  2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
@ 2015-08-04 11:38 ` Harpal Singh
  2015-08-04 14:24   ` Burakov, Anatoly
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 2/3] vfio: Added vfio req interrupt support Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program Harpal Singh
  2 siblings, 1 reply; 5+ messages in thread
From: Harpal Singh @ 2015-08-04 11:38 UTC (permalink / raw)
  To: dev; +Cc: Harpal Singh

From: Harpal Singh <harpal.sd@samsung.com>

This patch will add a new API i.e. pci_vfio_unmap_resource.
It will basically cleanup all the vfio resources allocated for a device.
cleanup includes :-
1) removing vfio_res from vfio_res_list
2) unmap mapped bars
3) close device fd
4) close group fd
5) free vfio_res

Signed-off-by: Harpal Singh <harpal.sd@samsung.com>
---
 lib/librte_eal/common/include/rte_pci.h    |  3 ++
 lib/librte_eal/linuxapp/eal/eal_pci.c      |  4 +-
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |  1 +
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 60 ++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 3fb2d3a..fa8c1a8 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -243,6 +243,9 @@ struct mapped_pci_resource {
 	struct rte_pci_addr pci_addr;
 	char path[PATH_MAX];
 	int nb_maps;
+	int vfio_group_fd;
+	int vfio_dev_fd;
+	int iommu_group_no;
 	struct pci_map maps[PCI_MAX_RESOURCE];
 };
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 0e62f65..edabde5 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -158,7 +158,9 @@ pci_unmap_device(struct rte_pci_device *dev)
 	/* try unmapping the NIC resources using VFIO if it exists */
 	switch (dev->kdrv) {
 	case RTE_KDRV_VFIO:
-		RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
+#ifdef VFIO_PRESENT
+		pci_vfio_unmap_resource(dev);
+#endif
 		break;
 	case RTE_KDRV_IGB_UIO:
 	case RTE_KDRV_UIO_GENERIC:
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index a17c708..9a42ea2 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -70,6 +70,7 @@ int pci_vfio_write_config(const struct rte_intr_handle *intr_handle,
 
 /* map VFIO resource prototype */
 int pci_vfio_map_resource(struct rte_pci_device *dev);
+int pci_vfio_unmap_resource(struct rte_pci_device *dev);
 int pci_vfio_get_group_fd(int iommu_group_fd);
 int pci_vfio_get_container_fd(void);
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 0e6c48a..8631653 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -550,6 +550,18 @@ clear_current_group(void)
 }
 
 
+static void
+clear_group_by_number(int iommu_group_no)
+{
+	int i;
+	for (i = 0; i < vfio_cfg.vfio_group_idx; i++)
+		if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no)
+		{
+			vfio_cfg.vfio_groups[i].group_no = 0;
+			vfio_cfg.vfio_groups[i].fd = -1;
+		}
+}
+
 /*
  * map the PCI resources of a PCI device in virtual memory (VFIO version).
  * primary and secondary processes follow almost exactly the same path
@@ -876,6 +888,9 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 		ioctl(vfio_dev_fd, VFIO_DEVICE_RESET);
 	}
 
+	vfio_res->vfio_dev_fd = vfio_dev_fd;
+	vfio_res->vfio_group_fd = vfio_group_fd;
+	vfio_res->iommu_group_no = iommu_group_no;
 	if (internal_config.process_type == RTE_PROC_PRIMARY)
 		TAILQ_INSERT_TAIL(vfio_res_list, vfio_res, next);
 
@@ -883,6 +898,51 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
 }
 
 int
+pci_vfio_unmap_resource(struct rte_pci_device *dev)
+{
+	int i;
+	struct mapped_pci_resource *vfio_res = NULL;
+	struct mapped_pci_res_list *vfio_res_list =
+		RTE_TAILQ_CAST(rte_vfio_tailq.head, mapped_pci_res_list);
+
+	/// Remove TAILQ entry
+	if (internal_config.process_type == RTE_PROC_PRIMARY)
+	{
+		TAILQ_FOREACH(vfio_res, vfio_res_list, next) {
+			if (memcmp(&vfio_res->pci_addr, &dev->addr,
+				   sizeof(dev->addr)))
+				continue;
+			TAILQ_REMOVE(vfio_res_list, vfio_res, next);
+			break;
+		}
+	}
+
+	if(!vfio_res)
+		return -1;
+
+	// /* unmap BARs */
+
+	for (i = 0; i < (int) vfio_res->nb_maps; i++)
+	{
+		/* skip non-mmapable BARs */
+		if (!vfio_res->maps[i].addr)
+			continue;
+		munmap(vfio_res->maps[i].addr, vfio_res->maps[i].size);
+	}
+
+
+	if(TAILQ_EMPTY(vfio_res_list))
+		vfio_cfg.vfio_container_has_dma = 0;
+	close(vfio_res->vfio_dev_fd);
+	close(vfio_res->vfio_group_fd);
+	clear_group_by_number(vfio_res->iommu_group_no);
+	if (internal_config.process_type == RTE_PROC_PRIMARY)
+		rte_free(vfio_res);
+	vfio_res = NULL;
+	return 0;
+}
+
+int
 pci_vfio_enable(void)
 {
 	/* initialize group list */
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH 2/3] vfio: Added vfio req interrupt support
  2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
@ 2015-08-04 11:38 ` Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program Harpal Singh
  2 siblings, 0 replies; 5+ messages in thread
From: Harpal Singh @ 2015-08-04 11:38 UTC (permalink / raw)
  To: dev; +Cc: Harpal Singh

From: Harpal Singh <harpal.sd@samsung.com>

This patch will add support for req interrupt which will be used
by vfio kernel module to request user space to release allocated resources.
It will provide addtional mechanism in user space to get system notification
about when to release vfio resources.

Signed-off-by: Harpal Singh <harpal.sd@samsung.com>
---
 lib/librte_eal/linuxapp/eal/eal_interrupts.c       | 67 ++++++++++++++++++++++
 .../linuxapp/eal/include/exec-env/rte_interrupts.h |  1 +
 2 files changed, 68 insertions(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
index 3f87875..6aca45f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c
+++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c
@@ -346,6 +346,63 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) {
 
 	return ret;
 }
+
+/* enable req interrupts */
+static int
+vfio_enable_req(struct rte_intr_handle *intr_handle) {
+	struct vfio_irq_set *irq_set;
+	char irq_set_buf[IRQ_SET_BUF_LEN];
+	int len, ret =0;
+	int *fd_ptr;
+	len = sizeof(irq_set_buf);
+
+	/* enable REQx */
+	irq_set = (struct vfio_irq_set *) irq_set_buf;
+	irq_set->argsz = len;
+	irq_set->count = 1;
+	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+	irq_set->index = VFIO_PCI_REQ_IRQ_INDEX;
+	irq_set->start = 0;
+	fd_ptr = (int *) &irq_set->data;
+	*fd_ptr = intr_handle->fd;
+	ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+	if (ret) {
+		RTE_LOG(ERR, EAL, "Error enabling Req interrupts for fd %d\n",
+						intr_handle->fd);
+		return -1;
+	}
+
+	return ret;
+}
+
+/* disable req interrupts */
+static int
+vfio_disable_req(struct rte_intr_handle *intr_handle) {
+	struct vfio_irq_set *irq_set;
+	char irq_set_buf[IRQ_SET_BUF_LEN];
+	int len, ret;
+	int *fd_ptr;
+	len = sizeof(irq_set_buf);
+
+	/* mask interrupts before disabling */
+	irq_set = (struct vfio_irq_set *) irq_set_buf;
+	irq_set->argsz = len;
+	irq_set->count = 1;
+	irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
+	irq_set->index = VFIO_PCI_REQ_IRQ_INDEX;
+	irq_set->start = 0;
+	fd_ptr = (int *) &irq_set->data;
+	*fd_ptr = -1;
+	ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
+
+	if (ret) {
+		RTE_LOG(ERR, EAL, "Error disableing Req interrupts for fd %d\n",
+						intr_handle->fd);
+		return -1;
+	}
+	return 0;
+}
 #endif
 
 static int
@@ -592,6 +649,11 @@ rte_intr_enable(struct rte_intr_handle *intr_handle)
 		if (vfio_enable_intx(intr_handle))
 			return -1;
 		break;
+
+	case RTE_INTR_HANDLE_VFIO_REQ:
+		if (vfio_enable_req(intr_handle))
+			return -1;
+		break;
 #endif
 	/* unknown handle type */
 	default:
@@ -636,6 +698,10 @@ rte_intr_disable(struct rte_intr_handle *intr_handle)
 		if (vfio_disable_intx(intr_handle))
 			return -1;
 		break;
+	case RTE_INTR_HANDLE_VFIO_REQ:
+		if (vfio_disable_req(intr_handle))
+			return -1;
+		break;
 #endif
 	/* unknown handle type */
 	default:
@@ -696,6 +762,7 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
 		case RTE_INTR_HANDLE_VFIO_MSIX:
 		case RTE_INTR_HANDLE_VFIO_MSI:
 		case RTE_INTR_HANDLE_VFIO_LEGACY:
+		case RTE_INTR_HANDLE_VFIO_REQ:
 			bytes_read = sizeof(buf.vfio_intr_count);
 			break;
 #endif
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
index b05f4c8..e9c4729 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_interrupts.h
@@ -48,6 +48,7 @@ enum rte_intr_handle_type {
 	RTE_INTR_HANDLE_VFIO_MSI,     /**< vfio device handle (MSI) */
 	RTE_INTR_HANDLE_VFIO_MSIX,    /**< vfio device handle (MSIX) */
 	RTE_INTR_HANDLE_ALARM,    /**< alarm handle */
+	RTE_INTR_HANDLE_VFIO_REQ, /**< request device handle */
 	RTE_INTR_HANDLE_MAX
 };
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program
  2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 2/3] vfio: Added vfio req interrupt support Harpal Singh
@ 2015-08-04 11:38 ` Harpal Singh
  2 siblings, 0 replies; 5+ messages in thread
From: Harpal Singh @ 2015-08-04 11:38 UTC (permalink / raw)
  To: dev; +Cc: Harpal Singh

From: Harpal Singh <harpal.sd@samsung.com>

Added a new hotplug test program: it has been added to test hot removal of a
vfio device.
1) This test will first deregister all the pci drivers and register its own driver.
2) Then it scan the bus and call probe for all the scanned devices whose vendor
id and device id is registered.
3) Inside driver init it enables req interrupt and then registers a callback for it.
4) After that it trigger the req interrupt by writting on fd.
5) Then req interrupt callback will be called which will create a posix
thread (since interrupt callback cant be deregistered within interrupt callback).
6) Inside posix thread it calls close one driver for the device.
7) After that driver deinit will be called by pci framework. Here we set the flag
to signal success in device removal.

If any of the above steps fails test will not pass.

Signed-off-by: Harpal Singh <harpal.sd@samsung.com>
---
 app/test/Makefile       |   2 +-
 app/test/test_hotplug.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 260 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_hotplug.c

diff --git a/app/test/Makefile b/app/test/Makefile
index e7f148f..e0e4425 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -57,7 +57,7 @@ SRCS-y += test_memzone.c
 SRCS-y += test_ring.c
 SRCS-y += test_ring_perf.c
 SRCS-y += test_pmd_perf.c
-
+SRCS-y += test_hotplug.c
 ifeq ($(CONFIG_RTE_LIBRTE_TABLE),y)
 SRCS-y += test_table.c
 SRCS-$(CONFIG_RTE_LIBRTE_PIPELINE) += test_table_pipeline.c
diff --git a/app/test/test_hotplug.c b/app/test/test_hotplug.c
new file mode 100644
index 0000000..698069c
--- /dev/null
+++ b/app/test/test_hotplug.c
@@ -0,0 +1,259 @@
+/*-
+ *  BSD LICENSE
+ *
+ *  Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    * Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    * Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in
+ *      the documentation and/or other materials provided with the
+ *      distribution.
+ *    * Neither the name of Intel Corporation nor the names of its
+ *      contributors may be used to endorse or promote products derived
+ *      from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <rte_common.h>
+#include <rte_cycles.h>
+#include <rte_interrupts.h>
+#include <string.h>
+#include <sys/queue.h>
+#include <rte_pci.h>
+#include <rte_ethdev.h>
+#include <rte_devargs.h>
+#include "test.h"
+
+
+#define TEST_INTERRUPT_CHECK_INTERVAL 1000 /* ms */
+#define NUM_MAX_DRIVERS 256
+
+/* flag of if removal is called */
+static volatile int flag;
+static struct rte_intr_handle req_handle;
+
+union intr_pipefds{
+	struct {
+		int pipefd[2];
+	};
+	struct {
+		int readfd;
+		int writefd;
+	};
+};
+
+static union intr_pipefds pfds;
+
+static unsigned pci_dev_count;
+
+#ifdef RTE_EXEC_ENV_LINUXAPP
+/**
+ * Initialization for req interrupt test.
+ */
+static int
+test_req_interrupt_init(void)
+{
+	if (pipe(pfds.pipefd) < 0)
+		return -1;
+
+	req_handle.fd = pfds.readfd;
+	req_handle.type = RTE_INTR_HANDLE_VFIO_REQ;
+
+	return 0;
+}
+
+/**
+ * Deinitialization for req interrupt test.
+ */
+static int
+test_req_interrupt_deinit(void)
+{
+	close(pfds.pipefd[0]);
+	close(pfds.pipefd[1]);
+	return 0;
+}
+
+/**
+ * Write the pipe to simulate an req interrupt.
+ */
+
+static int
+test_req_trigger_interrupt(void)
+{
+	if (write(pfds.writefd, "1", 1) < 0)
+		return -1;
+	return 0;
+}
+#else
+
+static int
+test_req_interrupt_init(void)
+{
+	return 0;
+}
+
+static int
+test_req_interrupt_deinit(void)
+{
+	return 0;
+}
+
+static int
+test_req_interrupt_trigger_interrupt(void)
+{
+	return 0;
+}
+#endif /* RTE_EXEC_ENV_LINUXAPP */
+
+
+/**
+ * Callback for the test req interrupt.
+ */
+static void *bh_test_req_interrupt_callback(void *arg)
+{
+	printf("Removal Callback is called\n");
+	struct rte_pci_device *dev = (struct rte_pci_device *)arg;
+	rte_eal_pci_close_one(&dev->addr);
+	return 0;
+}
+
+static void
+test_req_interrupt_callback(__attribute__((unused))struct rte_intr_handle *intr_handle, void *arg)
+{
+	pthread_t p_thread;
+	pthread_create(&p_thread,NULL, bh_test_req_interrupt_callback, arg);
+}
+
+
+
+struct rte_pci_id pci_driver_id[] = {
+#include <rte_pci_dev_ids.h>
+{ .vendor_id = 0, /* sentinel */ },
+};
+
+static int pci_driver_init(__attribute__((unused)) struct rte_pci_driver *dr
+					,struct rte_pci_device *dev);
+static int pci_driver_uninit(struct rte_pci_device *dev);
+
+struct rte_pci_driver pci_driver = {
+	.name = "test_driver",
+	.devinit = pci_driver_init,
+	.devuninit= pci_driver_uninit,
+	.id_table = pci_driver_id,
+	.drv_flags = 0,
+};
+
+static int
+pci_driver_init(__attribute__((unused)) struct rte_pci_driver *dr, struct rte_pci_device *dev)
+{
+	printf("My driver init called in %s\n", dr->name);
+	printf("%x:%x:%x.%d", dev->addr.domain, dev->addr.bus,
+	       dev->addr.devid, dev->addr.function);
+	printf(" - vendor:%x device:%x\n", dev->id.vendor_id, dev->id.device_id);
+
+	if (test_req_interrupt_init() < 0) {
+		printf("fail to initialize for testing req interrupt\n");
+		return -1;
+	}
+
+	printf("start req interrupt enable/disable test\n");
+	rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+	/* register req interrupt callback function */
+	if (rte_intr_callback_register(&req_handle,
+			test_req_interrupt_callback, (void *)dev) < 0) {
+		printf("fail to register callback\n");
+		return -1;
+	}
+	printf("Device is initialized and REQ interrupt is registered\n");
+	rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+	/* trigger req interruprt */
+	if (test_req_trigger_interrupt() < 0)
+		return -1;
+	printf("REQ interrupt is triggered, now device removal request will be called\n");
+	pci_dev_count ++;
+	return 0;
+}
+
+
+static int
+pci_driver_uninit(struct rte_pci_device *dev)
+{
+	printf("My driver Removal is called \n");
+	printf("%x:%x:%x.%d", dev->addr.domain, dev->addr.bus,
+	       dev->addr.devid, dev->addr.function);
+	printf(" - vendor:%x device:%x\n", dev->id.vendor_id, dev->id.device_id);
+	if (rte_intr_callback_unregister(&req_handle,
+			test_req_interrupt_callback, (void *)dev) < 0)
+		return -1;
+	test_req_interrupt_deinit();
+	flag = 1;
+	pci_dev_count --;
+	return 0;
+}
+
+static int
+test_hotplug(void)
+{
+	struct rte_pci_driver *dr = NULL;
+	struct rte_pci_driver *save_pci_driver_list[NUM_MAX_DRIVERS];
+	unsigned i,num_drivers = 0;
+	int count;
+
+	/* Unregister all previous drivers */
+	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+		rte_eal_pci_unregister(dr);
+		save_pci_driver_list[num_drivers++] = dr;
+	}
+	rte_eal_pci_register(&pci_driver);
+	flag = 0;
+	pci_dev_count = 0;
+	printf("Scan bus\n");
+	rte_eal_pci_scan();
+	rte_eal_pci_probe();
+
+	if (pci_dev_count == 0) {
+		printf("no device detected\n");
+		return -1;
+	}
+	/* check flag in 3 seconds */
+	for (count = 0; flag == 0 && count < 3; count++)
+		rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
+
+	if (flag == 0) {
+		printf("callback has not been called\n");
+		return -1;
+	}
+	rte_eal_pci_unregister(&pci_driver);
+	/* Restore original driver list */
+	for (i = 0; i < num_drivers; i++)
+		rte_eal_pci_register(save_pci_driver_list[i]);
+
+	return 0;
+}
+
+static struct test_command hotplug_cmd = {
+	.command = "hotplug_autotest",
+	.callback = test_hotplug,
+};
+REGISTER_TEST_COMMAND(hotplug_cmd);
+
-- 
1.9.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio
  2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
@ 2015-08-04 14:24   ` Burakov, Anatoly
  0 siblings, 0 replies; 5+ messages in thread
From: Burakov, Anatoly @ 2015-08-04 14:24 UTC (permalink / raw)
  To: Harpal Singh, dev

Hi Harpal,

> This patch will add a new API i.e. pci_vfio_unmap_resource.
> It will basically cleanup all the vfio resources allocated for a device.
> cleanup includes :-
> 1) removing vfio_res from vfio_res_list
> 2) unmap mapped bars
> 3) close device fd
> 4) close group fd
> 5) free vfio_res

Do I understand it correctly that your code assumes that there is always a single PCI device per group? From what I understand, unless we're only using a single port from the NIC, this won't be the case. 

Also, extraneous comment symbols:

> +	// /* unmap BARs */

Best regards,
Anatoly

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-04 14:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
2015-08-04 11:38 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Harpal Singh
2015-08-04 14:24   ` Burakov, Anatoly
2015-08-04 11:38 ` [dpdk-dev] [PATCH 2/3] vfio: Added vfio req interrupt support Harpal Singh
2015-08-04 11:38 ` [dpdk-dev] [PATCH 3/3] vfio: Added hotplug test program Harpal Singh

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).