[v2,RESEND] vfio: fix resource leak when mapping fails

Message ID 1599822484-19100-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2,RESEND] vfio: fix resource leak when mapping fails |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS

Commit Message

Yunjian Wang Sept. 11, 2020, 11:08 a.m. UTC
  From: Yunjian Wang <wangyunjian@huawei.com>

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")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
   Update email address
---
 drivers/bus/pci/linux/pci_vfio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Burakov, Anatoly Sept. 17, 2020, 10:35 a.m. UTC | #1
On 11-Sep-20 12:08 PM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> 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")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---

Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
David Marchand Oct. 5, 2020, 8:12 a.m. UTC | #2
On Fri, Sep 11, 2020 at 1:08 PM wangyunjian <wangyunjian@huawei.com> wrote:
>
> From: Yunjian Wang <wangyunjian@huawei.com>
>
> 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")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks.
  

Patch

diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index c15ed3bad..17350f34d 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -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;
 }