Fix Vhost PMD setup
cover Fix Vhost PMD setup
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)
Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfig
drivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/2 net/vhost: fix Vhost setup error path
If for some reason vhost_driver_setup() fails, the list element for the device may be freed without being removed from the internal list of devices.
This patch fixes all the error paths, by unregistering the device from Vhost library it has been registered, remove the device from the list, reset device vring_state pointer from the global table and only free vring state if it had been allocated.
--- drivers/net/vhost/rte_eth_vhost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +14 -7
@@ -878,12 +878,12 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) list =rte_zmalloc_socket (name,sizeof (*list),0 , numa_node);if (list ==NULL ) - goto error; +return -1 ; vring_state =rte_zmalloc_socket (name,sizeof (*vring_state),0 , numa_node);if (vring_state ==NULL ) - goto error; + goto free_list; list->eth_dev = eth_dev;pthread_mutex_lock (&internal_list_lock);
@@ -894,30 +894,37 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) vring_states[eth_dev->data->port_id] = vring_state;if (rte_vhost_driver_register (internal->iface_name, internal->flags)) - goto error; + goto list_remove;if (internal->disable_flags) {if (rte_vhost_driver_disable_features (internal->iface_name, internal->disable_flags)) - goto error; + goto drv_unreg; }if (rte_vhost_driver_callback_register (internal->iface_name, &vhost_ops) <0 ) {VHOST_LOG (ERR ,"Can't register callbacks\n" ); - goto error; + goto drv_unreg; }if (rte_vhost_driver_start (internal->iface_name) <0 ) {VHOST_LOG (ERR ,"Failed to start driver for %s\n" , internal->iface_name); - goto error; + goto drv_unreg; }return 0 ; -error: +drv_unreg: +rte_vhost_driver_unregister (internal->iface_name); +list_remove: + vring_states[eth_dev->data->port_id] =NULL ; +pthread_mutex_lock (&internal_list_lock); +TAILQ_REMOVE (&internal_list, list, next); +pthread_mutex_unlock (&internal_list_lock);rte_free (vring_state); +free_list:rte_free (list);return -1 ;
Signature · 1 line
2.24.1
Re: [dpdk-dev] [PATCH 1/2] net/vhost: fix Vhost setup error path
Quoted 10 lines · Maxime Coquelin
If for some reason
vhost_driver_setup()fails, the list element for the device may be freed without being removed from the internal list of devices.This patch fixes all the error paths, by unregistering the device from Vhost library it has been registered, remove the device from the list, reset device
vring_statepointer from the global table and only free vring state if it had been allocated.
Quoted 7 lines
Fixes 3d01b759d267 ("net/vhost: delay driver setup")Signed-off-by Maxime Coquelin <[email protected]>Reviewed-by David Marchand <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Thanks,
Tiwei
PATCH 2/2 net/vhost: prevent multiple setup on reconfig
In reply to Maxime CoquelinEthdev's .dev_configure callback can be called multiple time during a device life-time, but Vhost makes the wrong assumption that it is not the case and try to setup again the device on reconfiguration.
This patch ensures the device hasn't been already setup before proceeding.
--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/vhost/rte_eth_vhost.c +5 -0
@@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)unsigned int numa_node = eth_dev->device->numa_node;const char *name = eth_dev->device->name; +/* Don't try to setup again if it has already been done. */ + list =find_internal_resource (internal->iface_name); +if (list) +return 0 ; + list =rte_zmalloc_socket (name,sizeof (*list),0 , numa_node);if (list ==NULL )return -1 ;
Signature · 1 line
2.24.1
Re: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig
Quoted 36 lines · Maxime Coquelin
Ethdev's .dev_configure callback can be called multiple time during a device life-time, but Vhost makes the wrong assumption that it is not the case and try to setup again the device on reconfiguration.
This patch ensures the device hasn't been already setup before proceeding.
Fixes 3d01b759d267 ("net/vhost: delay driver setup")Reported-by Yinan Wang <[email protected]>Signed-off-by Maxime Coquelin <[email protected]>Tested-by Yinan Wang <[email protected]>Reviewed-by David Marchand <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +5
-0@@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)unsigned int numa_node = eth_dev->device->numa_node;const char *name = eth_dev->device->name; +/* Don't try to setup again if it has already been done. */ + list =find_internal_resource (internal->iface_name); +if (list) +return 0 ; + list =rte_zmalloc_socket (name,sizeof (*list),0 , numa_node);if (list ==NULL )return -1 ;Signature · 1 line
2.24.1
Thanks Maxime for the fix!
Not related to this fix, it seems there is a potential leak after delaying the driver setup to _configure, as the list won't be registered until users configure the device. So internal->iface_name allocated in _create will leak if the device is released without doing _configure first.
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1058
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1075
It's not a common case and it's quite late in this release, probably it's fine to fix it later.
Thanks,
Tiwei
Re: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig
Hi Tiwei,
Quoted 48 lines · Tiwei Bie
Quoted 36 lines · Maxime Coquelin
Ethdev's .dev_configure callback can be called multiple time during a device life-time, but Vhost makes the wrong assumption that it is not the case and try to setup again the device on reconfiguration.
This patch ensures the device hasn't been already setup before proceeding.
Fixes 3d01b759d267 ("net/vhost: delay driver setup")Reported-by Yinan Wang <[email protected]>Signed-off-by Maxime Coquelin <[email protected]>Tested-by Yinan Wang <[email protected]>Reviewed-by David Marchand <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +5
-0@@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)unsigned int numa_node = eth_dev->device->numa_node;const char *name = eth_dev->device->name; +/* Don't try to setup again if it has already been done. */ + list =find_internal_resource (internal->iface_name); +if (list) +return 0 ; + list =rte_zmalloc_socket (name,sizeof (*list),0 , numa_node);if (list ==NULL )return -1 ;Signature · 1 line
2.24.1Thanks Maxime for the fix!
Reviewed-by Tiwei Bie <[email protected]>Not related to this fix, it seems there is a potential leak after delaying the driver setup to
_configure, as the list won't be registered until users configure the device. Sointernal->iface_nameallocated in_createwill leak if the device is released without doing_configurefirst.
Quoted 5 lines
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1058
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1075It's not a common case and it's quite late in this release, probably it's fine to fix it later.
That's a valid point, and I also agree there is no urgency for v20.02. Itsuro, would you take care of fixing it for v20.05?
Thanks,
Maxime
Quoted 3 lines
Thanks,
Tiwei
Re: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig
Hi Maxime, Tiewi,
Quoted 51 lines · On Wed, 19 Feb 2020 09:17:41 +0100 Maxime Coquelin…
Hi Tiwei,
Quoted 48 lines · Tiwei Bie
Quoted 36 lines · Maxime Coquelin
Ethdev's .dev_configure callback can be called multiple time during a device life-time, but Vhost makes the wrong assumption that it is not the case and try to setup again the device on reconfiguration.
This patch ensures the device hasn't been already setup before proceeding.
Fixes 3d01b759d267 ("net/vhost: delay driver setup")Reported-by Yinan Wang <[email protected]>Signed-off-by Maxime Coquelin <[email protected]>Tested-by Yinan Wang <[email protected]>Reviewed-by David Marchand <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +5
-0@@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)unsigned int numa_node = eth_dev->device->numa_node;const char *name = eth_dev->device->name; +/* Don't try to setup again if it has already been done. */ + list =find_internal_resource (internal->iface_name); +if (list) +return 0 ; + list =rte_zmalloc_socket (name,sizeof (*list),0 , numa_node);if (list ==NULL )return -1 ;Signature · 1 line
2.24.1Thanks Maxime for the fix!
Reviewed-by Tiwei Bie <[email protected]>Not related to this fix, it seems there is a potential leak after delaying the driver setup to
_configure, as the list won't be registered until users configure the device. Sointernal->iface_nameallocated in_createwill leak if the device is released without doing_configurefirst.
Quoted 8 lines
Quoted 5 lines
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1058
https://github.com/DPDK/dpdk/blob/e6c78e736d77/drivers/net/vhost/rte_eth_vhost.c#L1075It's not a common case and it's quite late in this release, probably it's fine to fix it later.
That's a valid point, and I also agree there is no urgency for v20.02. Itsuro, would you take care of fixing it for v20.05?
Sure, I will do it.
Thanks.
Itsuro Oda
Quoted 5 lines
Thanks,
MaximeQuoted 3 lines
Thanks,
Tiwei
Signature · 1 line
Itsuro ODA <[email protected]>
Sorry, just see I missed the v2 prefix.
Quoted 15 lines · Maxime Coquelin
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Hi Yinan, Maxime, David,
Thank you for quick test, fix and review.
It looks good to me.
The original fix has been queued to stable 19.11.1. It should be rejected or applied this fix too.
Thanks.
Itsuto Oda
Quoted 17 lines · On Tue, 18 Feb 2020 18:22:38 +0100 Maxime Coquelin…
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)Signature · 1 line
2.24.1
Signature · 1 line
Itsuro ODA <[email protected]>
Quoted 7 lines · Itsuro ODA
Hi Yinan, Maxime, David,
Thank you for quick test, fix and review.
It looks good to me.The original fix has been queued to stable 19.11.1. It should be rejected or applied this fix too.
Thanks for the heads-up.
I added Cc: [email protected] in the commit messages.
Maxime
Quoted 24 lines
Thanks.
Itsuto OdaQuoted 17 lines · On Tue, 18 Feb 2020 18:22:38 +0100 Maxime Coquelin…
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)Signature · 1 line
2.24.1
Cc'ing stable as the commit it fixes was backported to v19.11 stable branch.
Quoted 15 lines · Maxime Coquelin
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Quoted 3 lines · Maxime Coquelin
Cc'ing stable as the commit it fixes was backported to v19.11 stable branch.
fyi - it is relevant to 18.11 also as 3d01b759d is fixing something introduced in 18.11. I skipped 3d01b759d for now and will take the full set together when available.
Quoted 17 lines · Maxime Coquelin
Quoted 15 lines
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Maxime Coquelin
AppliedQuoted 8 lines · Maxime Coquelin
This series fixes regression introduced in v20.02-rc3. First patch fixes the error path, and second one fix Vhost device reconfigure issue reported by Yinan.
v2:
---
- Fix error path order (David)
Quoted 7 lines
Maxime Coquelin (2):
net/vhost: fix Vhost setup error path
net/vhost: prevent multiple setup on reconfigdrivers/net/vhost/rte_eth_vhost.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Applied to dpdk-next-virtio/master
Thanks,
Maxime