[PATCH v3 7/8] bus/pci: fix leaked device FD warning on VFIO unmap

Burakov, Anatoly anatoly.burakov at intel.com
Fri Oct 23 15:49:31 CEST 2026


On 10/23/2026 3:39 PM, Anatoly Burakov wrote:
> 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 <anatoly.burakov at intel.com>
> ---
>   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);

Those intr_dev_fd_set's should've been put after the 
dev_vfio_device_release. I'll send a v4 fixing that.

-- 
Thanks,
Anatoly


More information about the dev mailing list