* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-09 13:36 ` [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback Ilya Maximets
@ 2019-04-09 14:25 ` Jens Freimann
2019-04-10 7:24 ` David Marchand
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Jens Freimann @ 2019-04-09 14:25 UTC (permalink / raw)
To: Ilya Maximets
Cc: dev, Maxime Coquelin, Tiwei Bie, Dariusz Stojaczyk,
David Marchand, stable
On Tue, Apr 09, 2019 at 04:36:22PM +0300, Ilya Maximets 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: stable@dpdk.org
>
>Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>---
> 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.
Reviewed-by: Jens Freimann <jfreimann@redhat.com>
regards,
Jens
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-09 13:36 ` [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback Ilya Maximets
2019-04-09 14:25 ` Jens Freimann
@ 2019-04-10 7:24 ` David Marchand
2019-04-10 7:53 ` Ilya Maximets
2019-04-12 4:39 ` Tiwei Bie
[not found] ` <CGME20190412083233eucas1p181a34d6544869582defba814e4caeb52@eucas1p1.samsung.com>
3 siblings, 1 reply; 11+ messages in thread
From: David Marchand @ 2019-04-10 7:24 UTC (permalink / raw)
To: Ilya Maximets, Maxime Coquelin, Tiwei Bie
Cc: dev, Jens Freimann, Dariusz Stojaczyk, dpdk stable
On Tue, Apr 9, 2019 at 3:36 PM Ilya Maximets <i.maximets@samsung.com> 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: stable@dpdk.org
>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
> 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
>
>
Reviewed-by: David Marchand <david.marchand@redhat.com>
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.
--
David Marchand
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-10 7:24 ` David Marchand
@ 2019-04-10 7:53 ` Ilya Maximets
2019-04-10 8:07 ` David Marchand
0 siblings, 1 reply; 11+ messages in thread
From: Ilya Maximets @ 2019-04-10 7:53 UTC (permalink / raw)
To: David Marchand, Maxime Coquelin, Tiwei Bie
Cc: dev, Jens Freimann, Dariusz Stojaczyk, dpdk stable
On 10.04.2019 10:24, David Marchand wrote:
>
>
> On Tue, Apr 9, 2019 at 3:36 PM Ilya Maximets <i.maximets@samsung.com <mailto:i.maximets@samsung.com>> 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: stable@dpdk.org <mailto:stable@dpdk.org>
>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com <mailto:i.maximets@samsung.com>>
> ---
> 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
>
>
> Reviewed-by: David Marchand <david.marchand@redhat.com <mailto:david.marchand@redhat.com>>
>
> 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.
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-10 7:53 ` Ilya Maximets
@ 2019-04-10 8:07 ` David Marchand
2019-04-11 8:53 ` Ilya Maximets
0 siblings, 1 reply; 11+ messages in thread
From: David Marchand @ 2019-04-10 8:07 UTC (permalink / raw)
To: Ilya Maximets
Cc: Maxime Coquelin, Tiwei Bie, dev, Jens Freimann,
Dariusz Stojaczyk, dpdk stable
On Wed, Apr 10, 2019 at 9:53 AM Ilya Maximets <i.maximets@samsung.com>
wrote:
> On 10.04.2019 10:24, David Marchand wrote:
> > 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.
>
> 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.
--
David Marchand
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-10 8:07 ` David Marchand
@ 2019-04-11 8:53 ` Ilya Maximets
0 siblings, 0 replies; 11+ messages in thread
From: Ilya Maximets @ 2019-04-11 8:53 UTC (permalink / raw)
To: David Marchand
Cc: Maxime Coquelin, Tiwei Bie, dev, Jens Freimann,
Dariusz Stojaczyk, dpdk stable
On 10.04.2019 11:07, David Marchand wrote:
> On Wed, Apr 10, 2019 at 9:53 AM Ilya Maximets <i.maximets@samsung.com <mailto:i.maximets@samsung.com>> wrote:
>
> On 10.04.2019 10:24, David Marchand wrote:
> > 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.
>
> 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.
>
>
> --
> David Marchand
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-09 13:36 ` [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback Ilya Maximets
2019-04-09 14:25 ` Jens Freimann
2019-04-10 7:24 ` David Marchand
@ 2019-04-12 4:39 ` Tiwei Bie
2019-04-12 8:11 ` Ilya Maximets
[not found] ` <CGME20190412083233eucas1p181a34d6544869582defba814e4caeb52@eucas1p1.samsung.com>
3 siblings, 1 reply; 11+ messages in thread
From: Tiwei Bie @ 2019-04-12 4:39 UTC (permalink / raw)
To: Ilya Maximets
Cc: dev, Maxime Coquelin, Jens Freimann, Dariusz Stojaczyk,
David Marchand, stable
On Tue, Apr 09, 2019 at 04:36:22PM +0300, Ilya Maximets 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: stable@dpdk.org
>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
> 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);
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).
> +
> pthread_mutex_lock(&vsocket->conn_mutex);
> TAILQ_REMOVE(&vsocket->conn_list, conn, next);
> pthread_mutex_unlock(&vsocket->conn_mutex);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH] vhost: fix passing destroyed device to destroy callback
2019-04-12 4:39 ` Tiwei Bie
@ 2019-04-12 8:11 ` Ilya Maximets
0 siblings, 0 replies; 11+ messages in thread
From: Ilya Maximets @ 2019-04-12 8:11 UTC (permalink / raw)
To: Tiwei Bie
Cc: dev, Maxime Coquelin, Jens Freimann, Dariusz Stojaczyk,
David Marchand, stable
On 12.04.2019 7:39, Tiwei Bie wrote:
> On Tue, Apr 09, 2019 at 04:36:22PM +0300, Ilya Maximets 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: stable@dpdk.org
>>
>> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>> ---
>> 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);
>
> 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).
Agree. Thanks. Will send v2.
>
>
>> +
>> pthread_mutex_lock(&vsocket->conn_mutex);
>> TAILQ_REMOVE(&vsocket->conn_list, conn, next);
>> pthread_mutex_unlock(&vsocket->conn_mutex);
>> --
>> 2.17.1
>>
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <CGME20190412083233eucas1p181a34d6544869582defba814e4caeb52@eucas1p1.samsung.com>]
* [dpdk-stable] [PATCH v2] vhost: fix passing destroyed device to destroy callback
[not found] ` <CGME20190412083233eucas1p181a34d6544869582defba814e4caeb52@eucas1p1.samsung.com>
@ 2019-04-12 8:32 ` Ilya Maximets
2019-04-15 6:21 ` Tiwei Bie
2019-04-17 7:54 ` Maxime Coquelin
0 siblings, 2 replies; 11+ messages in thread
From: Ilya Maximets @ 2019-04-12 8:32 UTC (permalink / raw)
To: dev, Maxime Coquelin
Cc: Tiwei Bie, Jens Freimann, Dariusz Stojaczyk, David Marchand,
Ilya Maximets, stable
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: stable@dpdk.org
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
Version 2:
* Fixed wrong order of 'destroy_device' and 'destroy_connection'.
lib/librte_vhost/socket.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 3da9de62c..af09dfa17 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -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);
--
2.17.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH v2] vhost: fix passing destroyed device to destroy callback
2019-04-12 8:32 ` [dpdk-stable] [PATCH v2] " Ilya Maximets
@ 2019-04-15 6:21 ` Tiwei Bie
2019-04-17 7:54 ` Maxime Coquelin
1 sibling, 0 replies; 11+ messages in thread
From: Tiwei Bie @ 2019-04-15 6:21 UTC (permalink / raw)
To: Ilya Maximets
Cc: dev, Maxime Coquelin, Jens Freimann, Dariusz Stojaczyk,
David Marchand, stable
On Fri, Apr 12, 2019 at 11:32:28AM +0300, Ilya Maximets 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: stable@dpdk.org
>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
>
> Version 2:
> * Fixed wrong order of 'destroy_device' and 'destroy_connection'.
>
> lib/librte_vhost/socket.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-stable] [PATCH v2] vhost: fix passing destroyed device to destroy callback
2019-04-12 8:32 ` [dpdk-stable] [PATCH v2] " Ilya Maximets
2019-04-15 6:21 ` Tiwei Bie
@ 2019-04-17 7:54 ` Maxime Coquelin
1 sibling, 0 replies; 11+ messages in thread
From: Maxime Coquelin @ 2019-04-17 7:54 UTC (permalink / raw)
To: Ilya Maximets, dev
Cc: Tiwei Bie, Jens Freimann, Dariusz Stojaczyk, David Marchand, stable
On 4/12/19 10:32 AM, Ilya Maximets 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:stable@dpdk.org
>
> Signed-off-by: Ilya Maximets<i.maximets@samsung.com>
> ---
>
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread