From: Harpal Singh <harpal.sd@samsung.com>
To: dev@dpdk.org
Cc: Harpal Singh <harpal.sd@samsung.com>
Subject: [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio
Date: Tue, 04 Aug 2015 17:08:50 +0530 [thread overview]
Message-ID: <1438688332-3392-2-git-send-email-harpal.sd@samsung.com> (raw)
In-Reply-To: <1438688332-3392-1-git-send-email-harpal.sd@samsung.com>
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
next prev parent reply other threads:[~2015-08-04 11:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-04 11:38 [dpdk-dev] [PATCH 0/3] vfio hotplug feature Harpal Singh
2015-08-04 11:38 ` Harpal Singh [this message]
2015-08-04 14:24 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio 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
[not found] <6F.6F.25195.454C4C55@epcpsbgx4.samsung.com>
2015-08-07 15:23 ` [dpdk-dev] [PATCH 1/3] vfio: Added hot removal feature for vfio Burakov, Anatoly
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=1438688332-3392-2-git-send-email-harpal.sd@samsung.com \
--to=harpal.sd@samsung.com \
--cc=dev@dpdk.org \
/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).