vhost: fix passing destroyed device to destroy callback
A message that is not in the archive (sent off-list or not yet received): CGME20190409133629eucas1p2ecfe7c4771bb6add694596cf75cf3e70@eucas1p2.samsung.com
PATCH 1/1 vhost: fix passing destroyed device to destroy callback
Application should be able to obtain information like 'ifname' from the 'vid' passed to 'destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.
--- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_vhost/socket.c +2 -1
@@ -297,11 +297,12 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)if (ret <0 ) {close (connfd); *remove =1 ; -vhost_destroy_device (conn->vid);if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection (conn->vid); +vhost_destroy_device (conn->vid); +pthread_mutex_lock (&vsocket->conn_mutex);TAILQ_REMOVE (&vsocket->conn_list, conn, next);pthread_mutex_unlock (&vsocket->conn_mutex);
Signature · 1 line
2.17.1
Quoted 4 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.
Quoted 8 lines
Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")Signed-off-by Ilya Maximets <[email protected]>---
lib/librte_vhost/socket.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)
Because the device is destroyed before the callback is done, vid is not a valid index to look up device information any more. So, yes we should destroy the device after the callback.
regards,
Jens
Quoted 31 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")Signed-off-by Ilya Maximets <[email protected]>--- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_vhost/socket.c +2
-1@@ -297,11 +297,12 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)if (ret <0 ) {close (connfd); *remove =1 ; -vhost_destroy_device (conn->vid);if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection (conn->vid); +vhost_destroy_device (conn->vid); +pthread_mutex_lock (&vsocket->conn_mutex);TAILQ_REMOVE (&vsocket->conn_list, conn, next);pthread_mutex_unlock(&vsocket->conn_mutex);
Quoted 4 lines
--
2.17.1
For vhost maintainers, looking at vhost_user_add_connection, aren't we leaking a vid on errors ? either when new_connection notifier returns an error, or after calling destroy_connection.
Signature · 1 line
David Marchand
Quoted 38 lines · David Marchand
On Tue, Apr 9, 2019 at 3:36 PM Ilya Maximets <[email protected] <mailto:[email protected]>> wrote:
Application should be able to obtain information like 'ifname' from the 'vid' passed to 'destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'. Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close") Cc: [email protected] <mailto:[email protected]> Signed-off-by: Ilya Maximets <[email protected] <mailto:[email protected]>> --- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 3da9de62c..43f091d10 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -297,11 +297,12 @@ vhost_user_read_cb(int connfd, void *dat, int *remove) if (ret < 0) { close(connfd); *remove = 1; - vhost_destroy_device(conn->vid); if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection(conn->vid); + vhost_destroy_device(conn->vid); + pthread_mutex_lock(&vsocket->conn_mutex); TAILQ_REMOVE(&vsocket->conn_list, conn, next); pthread_mutex_unlock(&vsocket->conn_mutex); -- 2.17.1
Quoted 3 lines
Reviewed-by David Marchand <[email protected] <mailto:[email protected]>>For vhost maintainers, looking at
vhost_user_add_connection, aren't we leaking a vid on errors ? either whennew_connectionnotifier returns an error, or after callingdestroy_connection.
I think that you're right.
I spotted that too yesterday while preparing this patch, just had no time to check deeper. It should be safe to call 'vhost_destroy_device' in these cases.
Best regards, Ilya Maximets.
Quoted 11 lines · Ilya Maximets
Quoted 1 line · David Marchand
For vhost maintainers, looking at
vhost_user_add_connection, aren't weleaking a vid on errors ? either when
new_connectionnotifier returns an error, or after callingdestroy_connection.I think that you're right.
I spotted that too yesterday while preparing this patch, just had no time to
check deeper. It should be safe to call 'vhost_destroy_device' in these cases.
Yes, that's my understanding too.
Signature · 1 line
David Marchand
Quoted 11 lines · David Marchand
On Wed, Apr 10, 2019 at 9:53 AM Ilya Maximets <[email protected] <mailto:[email protected]>> wrote:
On 10.04.2019 10:24, David Marchand wrote:
> For vhost maintainers, looking atvhost_user_add_connection, aren't we leaking a vid on errors ? either whennew_connectionnotifier returns an error, or after callingdestroy_connection.I think that you're right.
I spotted that too yesterday while preparing this patch, just had no time to check deeper. It should be safe to call 'vhost_destroy_device' in these cases.Yes, that's my understanding too.
I'll prepare the patch for this.
Quoted 4 lines
Signature · 2 lines
-- David Marchand
Quoted 17 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")Signed-off-by Ilya Maximets <[email protected]>--- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_vhost/socket.c +0
-0
lib/librte_vhost/socket.c vhost_user_read_cb(int connfd, void *dat, int *remove) · line 304
Quoted 9 lines
lib/librte_vhost/socket.c +1
-1@@ -297,11 +297,12 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)if (ret <0 ) {close (connfd); *remove =1 ; -vhost_destroy_device (conn->vid);if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection (conn->vid); +vhost_destroy_device (conn->vid);
By design, notify_ops->destroy_device() should be called before notify_ops->destroy_connection(). I.e. something like:
vhost_destroy_device_notify(...); // device stop if (vsocket->notify_ops->destroy_connection) // socket close vsocket->notify_ops->destroy_connection(conn->vid); vhost_destroy_device(conn->vid); // free
As destroy_device() callback means device stop (which also happens in e.g. GET_VRING_BASE).
Quoted 7 lines
lib/librte_vhost/socket.c +1
-0+pthread_mutex_lock (&vsocket->conn_mutex);TAILQ_REMOVE (&vsocket->conn_list, conn, next);pthread_mutex_unlock (&vsocket->conn_mutex);Signature · 1 line
2.17.1
Quoted 38 lines · Tiwei Bie
Quoted 17 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")Signed-off-by Ilya Maximets <[email protected]>--- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_vhost/socket.c +0
-0lib/librte_vhost/socket.c vhost_user_read_cb(int connfd, void *dat, int *remove) · line 304
Quoted 9 lines
lib/librte_vhost/socket.c +1
-1@@ -297,11 +297,12 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)if (ret <0 ) {close (connfd); *remove =1 ; -vhost_destroy_device (conn->vid);if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection (conn->vid); +vhost_destroy_device (conn->vid);By design,
notify_ops->destroy_device()should be called beforenotify_ops->destroy_connection(). I.e. something like:vhost_destroy_device_notify(...); // device stop if (vsocket->notify_ops->destroy_connection) // socket close vsocket->notify_ops->destroy_connection(conn->vid); vhost_destroy_device(conn->vid); // free
Quoted 2 lines
As
destroy_device()callback means device stop (which also happens in e.g.GET_VRING_BASE).
Agree. Thanks. Will send v2.
Quoted 11 lines
Quoted 9 lines
lib/librte_vhost/socket.c +1
-0+pthread_mutex_lock (&vsocket->conn_mutex);TAILQ_REMOVE (&vsocket->conn_list, conn, next);pthread_mutex_unlock (&vsocket->conn_mutex);Signature · 1 line
2.17.1
PATCH v2 1/1 vhost: fix passing destroyed device to destroy callback
In reply to Ilya MaximetsApplication should be able to obtain information like 'ifname' from the 'vid' passed to 'destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.
---
Version 2:
* Fixed wrong order of 'destroy_device' and 'destroy_connection'.
lib/librte_vhost/socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/librte_vhost/socket.c +7 -1
@@ -295,13 +295,19 @@ vhost_user_read_cb(int connfd, void *dat, int *remove) ret =vhost_user_msg_handler (conn->vid, connfd);if (ret <0 ) { +struct virtio_net *dev =get_device (conn->vid); +close (connfd); *remove =1 ; -vhost_destroy_device (conn->vid); + +if (dev) +vhost_destroy_device_notify (dev);if (vsocket->notify_ops->destroy_connection) vsocket->notify_ops->destroy_connection (conn->vid); +vhost_destroy_device (conn->vid); +pthread_mutex_lock (&vsocket->conn_mutex);TAILQ_REMOVE (&vsocket->conn_list, conn, next);pthread_mutex_unlock (&vsocket->conn_mutex);
Signature · 1 line
2.17.1
Quoted 7 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")
Quoted 8 lines
Signed-off-by Ilya Maximets <[email protected]>---
Version 2:
* Fixed wrong order of 'destroy_device' and 'destroy_connection'.lib/librte_vhost/socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Maxime Coquelin
AppliedQuoted 7 lines · Ilya Maximets
Application should be able to obtain information like 'ifname' from the 'vid' passed to '
destroy_connection' callback. Currently, all the API calls with passed 'vid' fails with 'device not found'.Fixes efba12a78ddf ("vhost: add user callbacks for socket open/close")
Quoted 8 lines
Signed-off-by Ilya Maximets<[email protected]>---
Version 2:
* Fixed wrong order of 'destroy_device' and 'destroy_connection'.lib/librte_vhost/socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Applied to dpdk-next-virtio/master.
Thanks,
Maxime