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.
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: +pthread_mutex_lock (&internal_list_lock); +TAILQ_REMOVE (&internal_list, list, next); +pthread_mutex_unlock (&internal_list_lock); + vring_states[eth_dev->data->port_id] =NULL ;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 65 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.Fixes 3d01b759d267 ("net/vhost: delay driver setup")Signed-off-by Maxime Coquelin <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/net/vhost/rte_eth_vhost.c +6
-6@@ -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; }
drivers/net/vhost/rte_eth_vhost.c vhost_driver_setup(struct rte_eth_dev *eth_dev) · line 925
Quoted 10 lines
drivers/net/vhost/rte_eth_vhost.c +7
-1return 0 ; -error: +drv_unreg: +rte_vhost_driver_unregister (internal->iface_name); +list_remove: +pthread_mutex_lock (&internal_list_lock); +TAILQ_REMOVE (&internal_list, list, next); +pthread_mutex_unlock (&internal_list_lock); + vring_states[eth_dev->data->port_id] =NULL ;
We allocate/store in vring_states after inserting list in &internal_list. Probably nitpicking but I would expect the opposite order on cleanup.
Quoted 8 lines
drivers/net/vhost/rte_eth_vhost.c +1
-1rte_free (vring_state); +free_list:rte_free (list);return -1 ; --2.24.1
In any case,
--
David Marchand
Re: [dpdk-dev] [PATCH 1/2] net/vhost: fix Vhost setup error path
Quoted 69 lines · David Marchand
Quoted 67 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.Fixes 3d01b759d267 ("net/vhost: delay driver setup")Signed-off-by Maxime Coquelin <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/net/vhost/rte_eth_vhost.c +6
-6@@ -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 ;
Quoted 11 lines
drivers/net/vhost/rte_eth_vhost.c vhost_driver_setup(struct rte_eth_dev *eth_dev) · line 925
Quoted 8 lines
drivers/net/vhost/rte_eth_vhost.c +7
-1-error: +drv_unreg: +rte_vhost_driver_unregister (internal->iface_name); +list_remove: +pthread_mutex_lock (&internal_list_lock); +TAILQ_REMOVE (&internal_list, list, next); +pthread_mutex_unlock (&internal_list_lock); + vring_states[eth_dev->data->port_id] =NULL ;We allocate/store in
vring_statesafter inserting list in&internal_list. Probably nitpicking but I would expect the opposite order on cleanup.
No nitpicking, it is a good practice to cleanup in opposite order. I will post a v2.
Quoted 5 lines
Quoted 5 lines
drivers/net/vhost/rte_eth_vhost.c +1
-0rte_free (vring_state); +free_list:rte_free (list);
Quoted 8 lines
Quoted 4 lines
drivers/net/vhost/rte_eth_vhost.c +0
-1return -1 ; --2.24.1
In any case,
Reviewed-by David Marchand <[email protected]>
Thanks!
Maxime
Quoted 4 lines
--
David Marchand
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 23 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]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +0
-0@@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)unsigned int numa_node = eth_dev->device->numa_node;
drivers/net/vhost/rte_eth_vhost.c vhost_driver_setup(struct rte_eth_dev *eth_dev) · line 886
Quoted 10 lines
drivers/net/vhost/rte_eth_vhost.c +5
-0const 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 ;
Following Yinan's reply to cover letter:
Re: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig
In reply to Maxime CoquelinQuoted 41 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: 2020年2月18日 22:35
To: [email protected]; [email protected]; Wang, Yinan <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH 2/2] net/vhost: prevent multiple setup on reconfigEthdev'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]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +5
-1@@ -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 ; --2.24.1
Re: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig
In reply to Maxime CoquelinQuoted 34 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]>--- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/vhost/rte_eth_vhost.c +5
-1@@ -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 ; --
Quoted 2 lines
2.24.1
Signature · 1 line
David Marchand
This patch set can fix Vhost device reconfigure issue, thanks!
Quoted 21 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: 2020年2月18日 22:35
To: [email protected]; [email protected]; Wang, Yinan <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH 0/2] Fix Vhost PMD setupThis 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.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(-)--
2.24.1
Quoted 1 line · Yinan
This patch set can fix Vhost device reconfigure issue, thanks!
Thanks for the quick test, I'll ask your Tested-by on patch 2.
Maxime
Quoted 23 lines
Quoted 22 lines
-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: 2020年2月18日 22:35
To: [email protected]; [email protected]; Wang, Yinan <[email protected]>; Bie, Tiwei <[email protected]>; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH 0/2] Fix Vhost PMD setupThis 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.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(-)--
2.24.1