net/virtio: fix unreleased resource when creating virtio user dev is failed

Message ID 20211223044237.52037-1-baymaxhuang@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: fix unreleased resource when creating virtio user dev is failed |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Harold Huang Dec. 23, 2021, 4:42 a.m. UTC
  When eth_virtio_dev_init is failed, the registered virtio user memory event
cb is not released and the backend created tap device is not destroyed.
It would cause some residual tap device existed in the host and creating
a new vdev could be failed because the new virtio_user_dev could use the
same address pointer and register memory event cb to the same address is
not allowed.

Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
---
Compared to patch v3, commit log is changed because this bug could
cause residual tap device in the host.
 drivers/net/virtio/virtio_user_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Chenbo Xia Jan. 14, 2022, 7:48 a.m. UTC | #1
> -----Original Message-----
> From: Harold Huang <baymaxhuang@gmail.com>
> Sent: Thursday, December 23, 2021 12:43 PM
> To: dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; Xia, Chenbo
> <chenbo.xia@intel.com>
> Subject: [PATCH] net/virtio: fix unreleased resource when creating virtio user
> dev is failed
> 
> When eth_virtio_dev_init is failed, the registered virtio user memory event
> cb is not released and the backend created tap device is not destroyed.
> It would cause some residual tap device existed in the host and creating
> a new vdev could be failed because the new virtio_user_dev could use the
> same address pointer and register memory event cb to the same address is
> not allowed.
> 
> Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
> ---
> Compared to patch v3, commit log is changed because this bug could
> cause residual tap device in the host.
>  drivers/net/virtio/virtio_user_ethdev.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index 0271098f0d..16eca2f940 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -666,6 +666,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
>  	/* previously called by pci probing for physical dev */
>  	if (eth_virtio_dev_init(eth_dev) < 0) {
>  		PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
> +		virtio_user_dev_uninit(dev);
>  		virtio_user_eth_dev_free(eth_dev);
>  		goto end;
>  	}
> --
> 2.27.0

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  
Chenbo Xia Jan. 27, 2022, 5:23 a.m. UTC | #2
> -----Original Message-----
> From: Harold Huang <baymaxhuang@gmail.com>
> Sent: Thursday, December 23, 2021 12:43 PM
> To: dev@dpdk.org
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; Xia, Chenbo
> <chenbo.xia@intel.com>
> Subject: [PATCH] net/virtio: fix unreleased resource when creating virtio user
> dev is failed
> 
> When eth_virtio_dev_init is failed, the registered virtio user memory event
> cb is not released and the backend created tap device is not destroyed.
> It would cause some residual tap device existed in the host and creating
> a new vdev could be failed because the new virtio_user_dev could use the
> same address pointer and register memory event cb to the same address is
> not allowed.
> 
> Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
> ---
> Compared to patch v3, commit log is changed because this bug could
> cause residual tap device in the host.
>  drivers/net/virtio/virtio_user_ethdev.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index 0271098f0d..16eca2f940 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -666,6 +666,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
>  	/* previously called by pci probing for physical dev */
>  	if (eth_virtio_dev_init(eth_dev) < 0) {
>  		PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
> +		virtio_user_dev_uninit(dev);
>  		virtio_user_eth_dev_free(eth_dev);
>  		goto end;
>  	}
> --
> 2.27.0

Applied to next-virtio/main with headline shortened and fix tag added.

Thanks!
  

Patch

diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 0271098f0d..16eca2f940 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -666,6 +666,7 @@  virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 	/* previously called by pci probing for physical dev */
 	if (eth_virtio_dev_init(eth_dev) < 0) {
 		PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
+		virtio_user_dev_uninit(dev);
 		virtio_user_eth_dev_free(eth_dev);
 		goto end;
 	}