When unmapping a VFIO device, the interrupt handle FD is closed but the
reference to the VFIO device FD is left in the handle. The device FD is
owned by the VFIO layer and released separately, so freeing the handle
later reports it as leaked.

Clear the reference once the device FD has been retrieved, as is already
done for the request notifier handle.

Fixes: d770ee9caed0 ("interrupts: warn on leaked FDs")

Signed-off-by: Anatoly Burakov <[email protected]>
---
 drivers/bus/pci/linux/pci_vfio.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index fb35bc1d491..1116603f43f 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -1091,6 +1091,8 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device 
*dev)
        vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle);
        if (vfio_dev_fd < 0)
                return -1;
+       /* vfio_dev_fd is managed by VFIO layer, only clear reference here. */
+       rte_intr_dev_fd_set(dev->intr_handle, -1);
 
        if (rte_pci_set_bus_master(dev, false)) {
                PCI_LOG(ERR, "%s cannot unset bus mastering for PCI device!", 
pci_addr);
@@ -1135,6 +1137,8 @@ pci_vfio_unmap_resource_secondary(struct rte_pci_device 
*dev)
        vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle);
        if (vfio_dev_fd < 0)
                return -1;
+       /* vfio_dev_fd is managed by VFIO layer, only clear reference here. */
+       rte_intr_dev_fd_set(dev->intr_handle, -1);
 
        ret = dev_vfio_release_device(rte_pci_get_sysfs_path(), pci_addr,
                                      vfio_dev_fd);
-- 
2.52.0

Reply via email to