From cda94419964ff5874f84b2564cb904f2d16d58c6 Mon Sep 17 00:00:00 2001 From: Jeff Guo Date: Tue, 16 Oct 2018 19:42:33 +0800 Subject: [PATCH] vfio: fix build with Linux < 4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since the older kernel version do not implement the device request interface for vfio, so when build on the kernel < v4.0.0, which is the version begin to add the device request interface, it will throw the error to show “VFIO_PCI_REQ_IRQ_INDEX” is undeclared. This patch aim to fix this compile issue by add the macro “HAVE_VFIO_DEV_REQ_INTERFACE” after checking the kernel version. Fixes: 0eb8a1c4c786 ("vfio: add request notifier interrupt") Fixes: c115fd000c32 ("vfio: handle hotplug request notifier") Signed-off-by: Jeff Guo Reviewed-by: Ferruh Yigit --- drivers/bus/pci/linux/pci_vfio.c | 12 ++++++++++++ drivers/bus/pci/pci_common.c | 2 ++ lib/librte_eal/common/include/rte_vfio.h | 3 +++ lib/librte_eal/linuxapp/eal/eal_interrupts.c | 17 ++++++++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 72d77bfc68..cc2387eb0c 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -279,6 +279,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) return -1; } +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE static void pci_vfio_req_handler(void *param) { @@ -384,6 +385,7 @@ pci_vfio_disable_notifier(struct rte_pci_device *dev) return 0; } +#endif static int pci_vfio_is_ioport_bar(int vfio_dev_fd, int bar_index) @@ -625,7 +627,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) struct pci_map *maps; dev->intr_handle.fd = -1; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE dev->vfio_req_intr_handle.fd = -1; +#endif /* store PCI address string */ snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, @@ -736,11 +740,13 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) goto err_vfio_res; } +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE if (pci_vfio_enable_notifier(dev, vfio_dev_fd) != 0) { RTE_LOG(ERR, EAL, "Error setting up notifier!\n"); goto err_vfio_res; } +#endif TAILQ_INSERT_TAIL(vfio_res_list, vfio_res, next); return 0; @@ -766,7 +772,9 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) struct pci_map *maps; dev->intr_handle.fd = -1; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE dev->vfio_req_intr_handle.fd = -1; +#endif /* store PCI address string */ snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, @@ -807,7 +815,9 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) /* we need save vfio_dev_fd, so it can be used during release */ dev->intr_handle.vfio_dev_fd = vfio_dev_fd; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE dev->vfio_req_intr_handle.vfio_dev_fd = vfio_dev_fd; +#endif return 0; err_vfio_dev_fd: @@ -880,12 +890,14 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev) snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, loc->domain, loc->bus, loc->devid, loc->function); +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE ret = pci_vfio_disable_notifier(dev); if (ret) { RTE_LOG(ERR, EAL, "fail to disable req notifier.\n"); return -1; } +#endif if (close(dev->intr_handle.fd) < 0) { RTE_LOG(INFO, EAL, "Error when closing eventfd file descriptor for %s\n", pci_addr); diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 5085c344ae..4b3749a9a1 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -444,6 +444,7 @@ pci_hot_unplug_handler(struct rte_device *dev) return -1; switch (pdev->kdrv) { +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE case RTE_KDRV_VFIO: /* * vfio kernel module guaranty the pci device would not be @@ -454,6 +455,7 @@ pci_hot_unplug_handler(struct rte_device *dev) rte_dev_event_callback_process(dev->name, RTE_DEV_EVENT_REMOVE); break; +#endif case RTE_KDRV_IGB_UIO: case RTE_KDRV_UIO_GENERIC: case RTE_KDRV_NIC_UIO: diff --git a/lib/librte_eal/common/include/rte_vfio.h b/lib/librte_eal/common/include/rte_vfio.h index f6617e004c..7d66438b59 100644 --- a/lib/librte_eal/common/include/rte_vfio.h +++ b/lib/librte_eal/common/include/rte_vfio.h @@ -24,6 +24,9 @@ extern "C" { #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) #define VFIO_PRESENT #endif /* kernel version >= 3.6.0 */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) +#define HAVE_VFIO_DEV_REQ_INTERFACE +#endif /* kernel version >= 4.0.0 */ #endif /* RTE_EAL_VFIO */ #ifdef VFIO_PRESENT diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index 7f611b3398..767b508804 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -309,6 +309,7 @@ vfio_disable_msix(const struct rte_intr_handle *intr_handle) { return ret; } +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE /* enable req notifier */ static int vfio_enable_req(const struct rte_intr_handle *intr_handle) @@ -367,6 +368,7 @@ vfio_disable_req(const struct rte_intr_handle *intr_handle) return ret; } #endif +#endif static int uio_intx_intr_disable(const struct rte_intr_handle *intr_handle) @@ -614,10 +616,12 @@ rte_intr_enable(const struct rte_intr_handle *intr_handle) if (vfio_enable_intx(intr_handle)) return -1; break; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE case RTE_INTR_HANDLE_VFIO_REQ: if (vfio_enable_req(intr_handle)) return -1; break; +#endif #endif /* not used at this moment */ case RTE_INTR_HANDLE_DEV_EVENT: @@ -668,11 +672,12 @@ rte_intr_disable(const struct rte_intr_handle *intr_handle) if (vfio_disable_intx(intr_handle)) return -1; break; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE case RTE_INTR_HANDLE_VFIO_REQ: if (vfio_disable_req(intr_handle)) return -1; break; - +#endif #endif /* not used at this moment */ case RTE_INTR_HANDLE_DEV_EVENT: @@ -739,6 +744,12 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) case RTE_INTR_HANDLE_VFIO_LEGACY: bytes_read = sizeof(buf.vfio_intr_count); break; +#ifdef HAVE_VFIO_DEV_REQ_INTERFACE + case RTE_INTR_HANDLE_VFIO_REQ: + bytes_read = 0; + call = true; + break; +#endif #endif case RTE_INTR_HANDLE_VDEV: case RTE_INTR_HANDLE_EXT: @@ -749,10 +760,6 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds) bytes_read = 0; call = true; break; - case RTE_INTR_HANDLE_VFIO_REQ: - bytes_read = 0; - call = true; - break; default: bytes_read = 1; break; -- 2.20.1