[v2] net/virtio: unregister virtio user memory event to fix memory leak problem

Message ID 20211220124929.1309369-1-baymaxhuang@gmail.com (mailing list archive)
State Superseded, archived
Headers
Series [v2] net/virtio: unregister virtio user memory event to fix memory leak problem |

Checks

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

Commit Message

Harold Huang Dec. 20, 2021, 12:49 p.m. UTC
  When eth_virtio_dev_init is failed, the registered virtio user memory is
not released and creating a new virtio user dev could be failed because the
new dev could use the same address pointer and the register virtio user
memory to the same address is not allowed.

Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
---
 drivers/net/virtio/virtio_user_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Harold Huang Dec. 20, 2021, 2:08 p.m. UTC | #1
The problem which this patch wants to solve can be reproduced via ovs 2.16:

1. add a port with an invalid speed parameter:
ovs-vsctl add-port ovs-br0 virtiouser0 -- set Interface virtiouser0
type=dpdk options:dpdk-devargs=virtio_user0,path=/dev/vhost-net,queue_size=1024,queues=1,speed=1000

2. delete the failed virtiouser0 port:
ovs-vsctl del-port virtiouser0

3. add a new port with valid parameters:
ovs-vsctl add-port ovs-br0 virtiouser0 -- set Interface virtiouser0
type=dpdk options:dpdk-devargs=virtio_user0,path=/dev/vhost-net,queue_size=1024,queues=1

The newly added port is always failed because of an existing memory event error.
  

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;
 	}