All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug
@ 2019-02-01 11:42 Stefano Garzarella
  2019-02-01 11:42 ` [PATCH v3 1/2] vsock/virtio: fix kernel panic after " Stefano Garzarella
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: virtualization, kvm, netdev, linux-kernel

These patches try to handle the hot-unplug of vsock virtio transport device in
a proper way.

Maybe move the vsock_core_init()/vsock_core_exit() functions in the module_init
and module_exit of vsock_virtio_transport module can't be the best way, but the
architecture of vsock_core forces us to this approach for now.

The vsock_core proto_ops expect a valid pointer to the transport device, so we
can't call vsock_core_exit() until there are open sockets.

v2 -> v3:
 - Rebased on master

v1 -> v2:
 - Fixed commit message of patch 1.
 - Added Reviewed-by, Acked-by tags by Stefan

Stefano Garzarella (2):
  vsock/virtio: fix kernel panic after device hot-unplug
  vsock/virtio: reset connected sockets on device removal

 net/vmw_vsock/virtio_transport.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/2] vsock/virtio: fix kernel panic after device hot-unplug
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
@ 2019-02-01 11:42 ` Stefano Garzarella
  2019-02-01 11:42 ` Stefano Garzarella
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: virtualization, kvm, netdev, linux-kernel

virtio_vsock_remove() invokes the vsock_core_exit() also if there
are opened sockets for the AF_VSOCK protocol family. In this way
the vsock "transport" pointer is set to NULL, triggering the
kernel panic at the first socket activity.

This patch move the vsock_core_init()/vsock_core_exit() in the
virtio_vsock respectively in module_init and module_exit functions,
that cannot be invoked until there are open sockets.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1609699
Reported-by: Yan Fu <yafu@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net/vmw_vsock/virtio_transport.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 5d3cce9e8744..9dae54698737 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -75,6 +75,9 @@ static u32 virtio_transport_get_local_cid(void)
 {
 	struct virtio_vsock *vsock = virtio_vsock_get();
 
+	if (!vsock)
+		return VMADDR_CID_ANY;
+
 	return vsock->guest_cid;
 }
 
@@ -584,10 +587,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
 	virtio_vsock_update_guest_cid(vsock);
 
-	ret = vsock_core_init(&virtio_transport.transport);
-	if (ret < 0)
-		goto out_vqs;
-
 	vsock->rx_buf_nr = 0;
 	vsock->rx_buf_max_nr = 0;
 	atomic_set(&vsock->queued_replies, 0);
@@ -618,8 +617,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 	mutex_unlock(&the_virtio_vsock_mutex);
 	return 0;
 
-out_vqs:
-	vsock->vdev->config->del_vqs(vsock->vdev);
 out:
 	kfree(vsock);
 	mutex_unlock(&the_virtio_vsock_mutex);
@@ -669,7 +666,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
 
 	mutex_lock(&the_virtio_vsock_mutex);
 	the_virtio_vsock = NULL;
-	vsock_core_exit();
 	mutex_unlock(&the_virtio_vsock_mutex);
 
 	vdev->config->del_vqs(vdev);
@@ -702,14 +698,28 @@ static int __init virtio_vsock_init(void)
 	virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0);
 	if (!virtio_vsock_workqueue)
 		return -ENOMEM;
+
 	ret = register_virtio_driver(&virtio_vsock_driver);
 	if (ret)
-		destroy_workqueue(virtio_vsock_workqueue);
+		goto out_wq;
+
+	ret = vsock_core_init(&virtio_transport.transport);
+	if (ret)
+		goto out_vdr;
+
+	return 0;
+
+out_vdr:
+	unregister_virtio_driver(&virtio_vsock_driver);
+out_wq:
+	destroy_workqueue(virtio_vsock_workqueue);
 	return ret;
+
 }
 
 static void __exit virtio_vsock_exit(void)
 {
+	vsock_core_exit();
 	unregister_virtio_driver(&virtio_vsock_driver);
 	destroy_workqueue(virtio_vsock_workqueue);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 1/2] vsock/virtio: fix kernel panic after device hot-unplug
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
  2019-02-01 11:42 ` [PATCH v3 1/2] vsock/virtio: fix kernel panic after " Stefano Garzarella
@ 2019-02-01 11:42 ` Stefano Garzarella
  2019-02-01 11:42 ` [PATCH v3 2/2] vsock/virtio: reset connected sockets on device removal Stefano Garzarella
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: netdev, linux-kernel, kvm, virtualization

virtio_vsock_remove() invokes the vsock_core_exit() also if there
are opened sockets for the AF_VSOCK protocol family. In this way
the vsock "transport" pointer is set to NULL, triggering the
kernel panic at the first socket activity.

This patch move the vsock_core_init()/vsock_core_exit() in the
virtio_vsock respectively in module_init and module_exit functions,
that cannot be invoked until there are open sockets.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1609699
Reported-by: Yan Fu <yafu@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net/vmw_vsock/virtio_transport.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 5d3cce9e8744..9dae54698737 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -75,6 +75,9 @@ static u32 virtio_transport_get_local_cid(void)
 {
 	struct virtio_vsock *vsock = virtio_vsock_get();
 
+	if (!vsock)
+		return VMADDR_CID_ANY;
+
 	return vsock->guest_cid;
 }
 
@@ -584,10 +587,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 
 	virtio_vsock_update_guest_cid(vsock);
 
-	ret = vsock_core_init(&virtio_transport.transport);
-	if (ret < 0)
-		goto out_vqs;
-
 	vsock->rx_buf_nr = 0;
 	vsock->rx_buf_max_nr = 0;
 	atomic_set(&vsock->queued_replies, 0);
@@ -618,8 +617,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
 	mutex_unlock(&the_virtio_vsock_mutex);
 	return 0;
 
-out_vqs:
-	vsock->vdev->config->del_vqs(vsock->vdev);
 out:
 	kfree(vsock);
 	mutex_unlock(&the_virtio_vsock_mutex);
@@ -669,7 +666,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
 
 	mutex_lock(&the_virtio_vsock_mutex);
 	the_virtio_vsock = NULL;
-	vsock_core_exit();
 	mutex_unlock(&the_virtio_vsock_mutex);
 
 	vdev->config->del_vqs(vdev);
@@ -702,14 +698,28 @@ static int __init virtio_vsock_init(void)
 	virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0);
 	if (!virtio_vsock_workqueue)
 		return -ENOMEM;
+
 	ret = register_virtio_driver(&virtio_vsock_driver);
 	if (ret)
-		destroy_workqueue(virtio_vsock_workqueue);
+		goto out_wq;
+
+	ret = vsock_core_init(&virtio_transport.transport);
+	if (ret)
+		goto out_vdr;
+
+	return 0;
+
+out_vdr:
+	unregister_virtio_driver(&virtio_vsock_driver);
+out_wq:
+	destroy_workqueue(virtio_vsock_workqueue);
 	return ret;
+
 }
 
 static void __exit virtio_vsock_exit(void)
 {
+	vsock_core_exit();
 	unregister_virtio_driver(&virtio_vsock_driver);
 	destroy_workqueue(virtio_vsock_workqueue);
 }
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/2] vsock/virtio: reset connected sockets on device removal
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
                   ` (2 preceding siblings ...)
  2019-02-01 11:42 ` [PATCH v3 2/2] vsock/virtio: reset connected sockets on device removal Stefano Garzarella
@ 2019-02-01 11:42 ` Stefano Garzarella
  2019-02-03 19:06 ` [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug David Miller
  2019-02-03 19:06 ` David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: virtualization, kvm, netdev, linux-kernel

When the virtio transport device disappear, we should reset all
connected sockets in order to inform the users.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net/vmw_vsock/virtio_transport.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 9dae54698737..15eb5d3d4750 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -634,6 +634,9 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
 	flush_work(&vsock->event_work);
 	flush_work(&vsock->send_pkt_work);
 
+	/* Reset all connected sockets when the device disappear */
+	vsock_for_each_connected_socket(virtio_vsock_reset_sock);
+
 	vdev->config->reset(vdev);
 
 	mutex_lock(&vsock->rx_lock);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/2] vsock/virtio: reset connected sockets on device removal
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
  2019-02-01 11:42 ` [PATCH v3 1/2] vsock/virtio: fix kernel panic after " Stefano Garzarella
  2019-02-01 11:42 ` Stefano Garzarella
@ 2019-02-01 11:42 ` Stefano Garzarella
  2019-02-01 11:42 ` Stefano Garzarella
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: netdev, linux-kernel, kvm, virtualization

When the virtio transport device disappear, we should reset all
connected sockets in order to inform the users.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net/vmw_vsock/virtio_transport.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 9dae54698737..15eb5d3d4750 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -634,6 +634,9 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
 	flush_work(&vsock->event_work);
 	flush_work(&vsock->send_pkt_work);
 
+	/* Reset all connected sockets when the device disappear */
+	vsock_for_each_connected_socket(virtio_vsock_reset_sock);
+
 	vdev->config->reset(vdev);
 
 	mutex_lock(&vsock->rx_lock);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
                   ` (3 preceding siblings ...)
  2019-02-01 11:42 ` Stefano Garzarella
@ 2019-02-03 19:06 ` David Miller
  2019-02-03 19:06 ` David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2019-02-03 19:06 UTC (permalink / raw)
  To: sgarzare; +Cc: stefanha, virtualization, kvm, netdev, linux-kernel

From: Stefano Garzarella <sgarzare@redhat.com>
Date: Fri,  1 Feb 2019 12:42:05 +0100

> These patches try to handle the hot-unplug of vsock virtio transport device in
> a proper way.
> 
> Maybe move the vsock_core_init()/vsock_core_exit() functions in the module_init
> and module_exit of vsock_virtio_transport module can't be the best way, but the
> architecture of vsock_core forces us to this approach for now.
> 
> The vsock_core proto_ops expect a valid pointer to the transport device, so we
> can't call vsock_core_exit() until there are open sockets.
> 
> v2 -> v3:
>  - Rebased on master
> 
> v1 -> v2:
>  - Fixed commit message of patch 1.
>  - Added Reviewed-by, Acked-by tags by Stefan

Series applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug
  2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
                   ` (4 preceding siblings ...)
  2019-02-03 19:06 ` [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug David Miller
@ 2019-02-03 19:06 ` David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2019-02-03 19:06 UTC (permalink / raw)
  To: sgarzare; +Cc: netdev, linux-kernel, kvm, stefanha, virtualization

From: Stefano Garzarella <sgarzare@redhat.com>
Date: Fri,  1 Feb 2019 12:42:05 +0100

> These patches try to handle the hot-unplug of vsock virtio transport device in
> a proper way.
> 
> Maybe move the vsock_core_init()/vsock_core_exit() functions in the module_init
> and module_exit of vsock_virtio_transport module can't be the best way, but the
> architecture of vsock_core forces us to this approach for now.
> 
> The vsock_core proto_ops expect a valid pointer to the transport device, so we
> can't call vsock_core_exit() until there are open sockets.
> 
> v2 -> v3:
>  - Rebased on master
> 
> v1 -> v2:
>  - Fixed commit message of patch 1.
>  - Added Reviewed-by, Acked-by tags by Stefan

Series applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug
@ 2019-02-01 11:42 Stefano Garzarella
  0 siblings, 0 replies; 8+ messages in thread
From: Stefano Garzarella @ 2019-02-01 11:42 UTC (permalink / raw)
  To: Stefan Hajnoczi, David S. Miller
  Cc: netdev, linux-kernel, kvm, virtualization

These patches try to handle the hot-unplug of vsock virtio transport device in
a proper way.

Maybe move the vsock_core_init()/vsock_core_exit() functions in the module_init
and module_exit of vsock_virtio_transport module can't be the best way, but the
architecture of vsock_core forces us to this approach for now.

The vsock_core proto_ops expect a valid pointer to the transport device, so we
can't call vsock_core_exit() until there are open sockets.

v2 -> v3:
 - Rebased on master

v1 -> v2:
 - Fixed commit message of patch 1.
 - Added Reviewed-by, Acked-by tags by Stefan

Stefano Garzarella (2):
  vsock/virtio: fix kernel panic after device hot-unplug
  vsock/virtio: reset connected sockets on device removal

 net/vmw_vsock/virtio_transport.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-02-03 19:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-01 11:42 [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug Stefano Garzarella
2019-02-01 11:42 ` [PATCH v3 1/2] vsock/virtio: fix kernel panic after " Stefano Garzarella
2019-02-01 11:42 ` Stefano Garzarella
2019-02-01 11:42 ` [PATCH v3 2/2] vsock/virtio: reset connected sockets on device removal Stefano Garzarella
2019-02-01 11:42 ` Stefano Garzarella
2019-02-03 19:06 ` [PATCH v3 0/2] vsock/virtio: fix issues on device hot-unplug David Miller
2019-02-03 19:06 ` David Miller
2019-02-01 11:42 Stefano Garzarella

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.