Skip to contentSkip to conversation

vfio: fix resource leak when mapping fails

PATCH New Yunjian Wang 4 participants 4 messages Jun 21, 2020 – Oct 5, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio: fix resource leak when mapping fails

Currently, only the 'vfio_dev_fd' is closed in failure path, so some resources are not released(such as 'vfio_group_fd'). The rte_vfio_release_device() should be used to avoid this problem.

Fixes 33604c31354a ("vfio: refactor PCI BAR mapping")
---
 drivers/bus/pci/linux/pci_vfio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bus/pci/linux/pci_vfio.c +4 -2
index 64cd84a68..c87373b90 100644
@@ -789,7 +789,8 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 err_vfio_res:
 	rte_free(vfio_res);
 err_vfio_dev_fd:
-	close(vfio_dev_fd);
+	rte_vfio_release_device(rte_pci_get_sysfs_path(),
+				pci_addr, vfio_dev_fd);
 	return -1;
 }
 
@@ -857,7 +858,8 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
 
 	return 0;
 err_vfio_dev_fd:
-	close(vfio_dev_fd);
+	rte_vfio_release_device(rte_pci_get_sysfs_path(),
+				pci_addr, vfio_dev_fd);
 	return -1;
 }
 
Signature · 1 line
2.18.1
#1 lore raw

PATCH RESEND v2 1/1 vfio: fix resource leak when mapping fails

From: Yunjian Wang <[email protected]>

Currently, only the 'vfio_dev_fd' is closed in failure path, so some resources are not released(such as 'vfio_group_fd'). The rte_vfio_release_device() should be used to avoid this problem.

Fixes 33604c31354a ("vfio: refactor PCI BAR mapping")

---
v2:
Update email address

---
 drivers/bus/pci/linux/pci_vfio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/bus/pci/linux/pci_vfio.c +4 -2
index c15ed3bad..17350f34d 100644
@@ -826,7 +826,8 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 err_vfio_res:
 	rte_free(vfio_res);
 err_vfio_dev_fd:
-	close(vfio_dev_fd);
+	rte_vfio_release_device(rte_pci_get_sysfs_path(),
+			pci_addr, vfio_dev_fd);
 	return -1;
 }
 
@@ -894,7 +895,8 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
 
 	return 0;
 err_vfio_dev_fd:
-	close(vfio_dev_fd);
+	rte_vfio_release_device(rte_pci_get_sysfs_path(),
+			pci_addr, vfio_dev_fd);
 	return -1;
 }
 
Signature · 1 line
2.23.0
Reviewed-by on v2 1/1
#2 lore raw
Quoted 11 lines · wangyunjian

From: Yunjian Wang <[email protected]>

Currently, only the 'vfio_dev_fd' is closed in failure path, so some resources are not released(such as 'vfio_group_fd'). The rte_vfio_release_device() should be used to avoid this problem.

Fixes 33604c31354a ("vfio: refactor PCI BAR mapping")

---

Signature · 2 lines
Thanks,
Anatoly
Reviewed-by Anatoly Burakov on v2 1/1 Applied
#3 lore raw
In reply to wangyunjian
Quoted 11 lines · wangyunjian

From: Yunjian Wang <[email protected]>

Currently, only the 'vfio_dev_fd' is closed in failure path, so some resources are not released(such as 'vfio_group_fd'). The rte_vfio_release_device() should be used to avoid this problem.

Fixes 33604c31354a ("vfio: refactor PCI BAR mapping")

Applied, thanks.

Signature · 1 line
David Marchand