* [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume
@ 2022-04-28 13:22 Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 1/2] vsock/virtio: factor our the code to initialize and delete VQs Stefano Garzarella
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-04-28 13:22 UTC (permalink / raw)
To: netdev
Cc: Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel,
Stefano Garzarella, Jakub Kicinski, Michael S. Tsirkin
Vilas reported that virtio-vsock no longer worked properly after
suspend/resume (echo mem >/sys/power/state).
It was impossible to connect to the host and vice versa.
Indeed, the support has never been implemented.
This series implement .freeze and .restore callbacks of struct virtio_driver
to support device suspend/resume.
The first patch factors our the code to initialize and delete VQs.
The second patch uses that code to support device suspend/resume.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Stefano Garzarella (2):
vsock/virtio: factor our the code to initialize and delete VQs
vsock/virtio: add support for device suspend/resume
net/vmw_vsock/virtio_transport.c | 197 ++++++++++++++++++++-----------
1 file changed, 131 insertions(+), 66 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next 1/2] vsock/virtio: factor our the code to initialize and delete VQs
2022-04-28 13:22 [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
@ 2022-04-28 13:22 ` Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 2/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-04-28 13:22 UTC (permalink / raw)
To: netdev
Cc: Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel,
Stefano Garzarella, Jakub Kicinski, Michael S. Tsirkin
Add virtio_vsock_vqs_init() and virtio_vsock_vqs_del() with the code
that was in virtio_vsock_probe() and virtio_vsock_remove to initialize
and delete VQs.
These new functions will be used in the next commit to support device
suspend/resume
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vmw_vsock/virtio_transport.c | 150 +++++++++++++++++--------------
1 file changed, 84 insertions(+), 66 deletions(-)
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index ba1c8cc0c467..31f4f6f40614 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -566,67 +566,28 @@ static void virtio_transport_rx_work(struct work_struct *work)
mutex_unlock(&vsock->rx_lock);
}
-static int virtio_vsock_probe(struct virtio_device *vdev)
+static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
{
- vq_callback_t *callbacks[] = {
- virtio_vsock_rx_done,
- virtio_vsock_tx_done,
- virtio_vsock_event_done,
- };
+ struct virtio_device *vdev = vsock->vdev;
static const char * const names[] = {
"rx",
"tx",
"event",
};
- struct virtio_vsock *vsock = NULL;
+ vq_callback_t *callbacks[] = {
+ virtio_vsock_rx_done,
+ virtio_vsock_tx_done,
+ virtio_vsock_event_done,
+ };
int ret;
- ret = mutex_lock_interruptible(&the_virtio_vsock_mutex);
- if (ret)
- return ret;
-
- /* Only one virtio-vsock device per guest is supported */
- if (rcu_dereference_protected(the_virtio_vsock,
- lockdep_is_held(&the_virtio_vsock_mutex))) {
- ret = -EBUSY;
- goto out;
- }
-
- vsock = kzalloc(sizeof(*vsock), GFP_KERNEL);
- if (!vsock) {
- ret = -ENOMEM;
- goto out;
- }
-
- vsock->vdev = vdev;
-
- ret = virtio_find_vqs(vsock->vdev, VSOCK_VQ_MAX,
- vsock->vqs, callbacks, names,
+ ret = virtio_find_vqs(vdev, VSOCK_VQ_MAX, vsock->vqs, callbacks, names,
NULL);
if (ret < 0)
- goto out;
+ return ret;
virtio_vsock_update_guest_cid(vsock);
- vsock->rx_buf_nr = 0;
- vsock->rx_buf_max_nr = 0;
- atomic_set(&vsock->queued_replies, 0);
-
- mutex_init(&vsock->tx_lock);
- mutex_init(&vsock->rx_lock);
- mutex_init(&vsock->event_lock);
- spin_lock_init(&vsock->send_pkt_list_lock);
- INIT_LIST_HEAD(&vsock->send_pkt_list);
- INIT_WORK(&vsock->rx_work, virtio_transport_rx_work);
- INIT_WORK(&vsock->tx_work, virtio_transport_tx_work);
- INIT_WORK(&vsock->event_work, virtio_transport_event_work);
- INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
-
- if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
- vsock->seqpacket_allow = true;
-
- vdev->priv = vsock;
-
virtio_device_ready(vdev);
mutex_lock(&vsock->tx_lock);
@@ -643,30 +604,15 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
vsock->event_run = true;
mutex_unlock(&vsock->event_lock);
- rcu_assign_pointer(the_virtio_vsock, vsock);
-
- mutex_unlock(&the_virtio_vsock_mutex);
-
return 0;
-
-out:
- kfree(vsock);
- mutex_unlock(&the_virtio_vsock_mutex);
- return ret;
}
-static void virtio_vsock_remove(struct virtio_device *vdev)
+static void virtio_vsock_vqs_del(struct virtio_vsock *vsock)
{
- struct virtio_vsock *vsock = vdev->priv;
+ struct virtio_device *vdev = vsock->vdev;
struct virtio_vsock_pkt *pkt;
- mutex_lock(&the_virtio_vsock_mutex);
-
- vdev->priv = NULL;
- rcu_assign_pointer(the_virtio_vsock, NULL);
- synchronize_rcu();
-
- /* Reset all connected sockets when the device disappear */
+ /* Reset all connected sockets when the VQs disappear */
vsock_for_each_connected_socket(&virtio_transport.transport,
virtio_vsock_reset_sock);
@@ -711,6 +657,78 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
/* Delete virtqueues and flush outstanding callbacks if any */
vdev->config->del_vqs(vdev);
+}
+
+static int virtio_vsock_probe(struct virtio_device *vdev)
+{
+ struct virtio_vsock *vsock = NULL;
+ int ret;
+
+ ret = mutex_lock_interruptible(&the_virtio_vsock_mutex);
+ if (ret)
+ return ret;
+
+ /* Only one virtio-vsock device per guest is supported */
+ if (rcu_dereference_protected(the_virtio_vsock,
+ lockdep_is_held(&the_virtio_vsock_mutex))) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ vsock = kzalloc(sizeof(*vsock), GFP_KERNEL);
+ if (!vsock) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ vsock->vdev = vdev;
+
+ vsock->rx_buf_nr = 0;
+ vsock->rx_buf_max_nr = 0;
+ atomic_set(&vsock->queued_replies, 0);
+
+ mutex_init(&vsock->tx_lock);
+ mutex_init(&vsock->rx_lock);
+ mutex_init(&vsock->event_lock);
+ spin_lock_init(&vsock->send_pkt_list_lock);
+ INIT_LIST_HEAD(&vsock->send_pkt_list);
+ INIT_WORK(&vsock->rx_work, virtio_transport_rx_work);
+ INIT_WORK(&vsock->tx_work, virtio_transport_tx_work);
+ INIT_WORK(&vsock->event_work, virtio_transport_event_work);
+ INIT_WORK(&vsock->send_pkt_work, virtio_transport_send_pkt_work);
+
+ if (virtio_has_feature(vdev, VIRTIO_VSOCK_F_SEQPACKET))
+ vsock->seqpacket_allow = true;
+
+ vdev->priv = vsock;
+
+ ret = virtio_vsock_vqs_init(vsock);
+ if (ret < 0)
+ goto out;
+
+ rcu_assign_pointer(the_virtio_vsock, vsock);
+
+ mutex_unlock(&the_virtio_vsock_mutex);
+
+ return 0;
+
+out:
+ kfree(vsock);
+ mutex_unlock(&the_virtio_vsock_mutex);
+ return ret;
+}
+
+static void virtio_vsock_remove(struct virtio_device *vdev)
+{
+ struct virtio_vsock *vsock = vdev->priv;
+
+ mutex_lock(&the_virtio_vsock_mutex);
+
+ vdev->priv = NULL;
+ rcu_assign_pointer(the_virtio_vsock, NULL);
+ synchronize_rcu();
+
+ virtio_vsock_vqs_del(vsock);
/* Other works can be queued before 'config->del_vqs()', so we flush
* all works before to free the vsock object to avoid use after free.
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net-next 2/2] vsock/virtio: add support for device suspend/resume
2022-04-28 13:22 [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 1/2] vsock/virtio: factor our the code to initialize and delete VQs Stefano Garzarella
@ 2022-04-28 13:22 ` Stefano Garzarella
2022-05-02 21:35 ` [PATCH net-next 0/2] " Jakub Kicinski
2022-05-02 22:20 ` Michael S. Tsirkin
3 siblings, 0 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-04-28 13:22 UTC (permalink / raw)
To: netdev
Cc: Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel,
Stefano Garzarella, Jakub Kicinski, Michael S. Tsirkin
Implement .freeze and .restore callbacks of struct virtio_driver
to support device suspend/resume.
During suspension all connected sockets are reset and VQs deleted.
During resume the VQs are re-initialized.
Reported by: Vilas R K <vilas.r.k@intel.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vmw_vsock/virtio_transport.c | 47 ++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 31f4f6f40614..ad64f403536a 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -743,6 +743,49 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
kfree(vsock);
}
+#ifdef CONFIG_PM_SLEEP
+static int virtio_vsock_freeze(struct virtio_device *vdev)
+{
+ struct virtio_vsock *vsock = vdev->priv;
+
+ mutex_lock(&the_virtio_vsock_mutex);
+
+ rcu_assign_pointer(the_virtio_vsock, NULL);
+ synchronize_rcu();
+
+ virtio_vsock_vqs_del(vsock);
+
+ mutex_unlock(&the_virtio_vsock_mutex);
+
+ return 0;
+}
+
+static int virtio_vsock_restore(struct virtio_device *vdev)
+{
+ struct virtio_vsock *vsock = vdev->priv;
+ int ret;
+
+ mutex_lock(&the_virtio_vsock_mutex);
+
+ /* Only one virtio-vsock device per guest is supported */
+ if (rcu_dereference_protected(the_virtio_vsock,
+ lockdep_is_held(&the_virtio_vsock_mutex))) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ ret = virtio_vsock_vqs_init(vsock);
+ if (ret < 0)
+ goto out;
+
+ rcu_assign_pointer(the_virtio_vsock, vsock);
+
+out:
+ mutex_unlock(&the_virtio_vsock_mutex);
+ return ret;
+}
+#endif /* CONFIG_PM_SLEEP */
+
static struct virtio_device_id id_table[] = {
{ VIRTIO_ID_VSOCK, VIRTIO_DEV_ANY_ID },
{ 0 },
@@ -760,6 +803,10 @@ static struct virtio_driver virtio_vsock_driver = {
.id_table = id_table,
.probe = virtio_vsock_probe,
.remove = virtio_vsock_remove,
+#ifdef CONFIG_PM_SLEEP
+ .freeze = virtio_vsock_freeze,
+ .restore = virtio_vsock_restore,
+#endif
};
static int __init virtio_vsock_init(void)
--
2.35.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume
2022-04-28 13:22 [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 1/2] vsock/virtio: factor our the code to initialize and delete VQs Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 2/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
@ 2022-05-02 21:35 ` Jakub Kicinski
2022-05-02 22:20 ` Michael S. Tsirkin
3 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-05-02 21:35 UTC (permalink / raw)
To: Stefano Garzarella
Cc: netdev, Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel,
Michael S. Tsirkin
On Thu, 28 Apr 2022 15:22:39 +0200 Stefano Garzarella wrote:
> Vilas reported that virtio-vsock no longer worked properly after
> suspend/resume (echo mem >/sys/power/state).
> It was impossible to connect to the host and vice versa.
>
> Indeed, the support has never been implemented.
>
> This series implement .freeze and .restore callbacks of struct virtio_driver
> to support device suspend/resume.
>
> The first patch factors our the code to initialize and delete VQs.
> The second patch uses that code to support device suspend/resume.
This set got a "Not Applicable" in patchwork, I'm not sure why.
Michael I presume net-next is fine? Can we get an Ack?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume
2022-04-28 13:22 [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
` (2 preceding siblings ...)
2022-05-02 21:35 ` [PATCH net-next 0/2] " Jakub Kicinski
@ 2022-05-02 22:20 ` Michael S. Tsirkin
2022-05-02 23:07 ` Jakub Kicinski
3 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2022-05-02 22:20 UTC (permalink / raw)
To: Stefano Garzarella
Cc: netdev, Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel,
Jakub Kicinski
On Thu, Apr 28, 2022 at 03:22:39PM +0200, Stefano Garzarella wrote:
> Vilas reported that virtio-vsock no longer worked properly after
> suspend/resume (echo mem >/sys/power/state).
> It was impossible to connect to the host and vice versa.
>
> Indeed, the support has never been implemented.
>
> This series implement .freeze and .restore callbacks of struct virtio_driver
> to support device suspend/resume.
>
> The first patch factors our the code to initialize and delete VQs.
> The second patch uses that code to support device suspend/resume.
>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> Stefano Garzarella (2):
> vsock/virtio: factor our the code to initialize and delete VQs
> vsock/virtio: add support for device suspend/resume
>
> net/vmw_vsock/virtio_transport.c | 197 ++++++++++++++++++++-----------
> 1 file changed, 131 insertions(+), 66 deletions(-)
>
> --
> 2.35.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume
2022-05-02 22:20 ` Michael S. Tsirkin
@ 2022-05-02 23:07 ` Jakub Kicinski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2022-05-02 23:07 UTC (permalink / raw)
To: Michael S. Tsirkin, Stefano Garzarella
Cc: netdev, Stefan Hajnoczi, Jason Wang, kvm, virtualization,
David S. Miller, Paolo Abeni, Vilas R K, linux-kernel
On Mon, 2 May 2022 18:20:51 -0400 Michael S. Tsirkin wrote:
> On Thu, Apr 28, 2022 at 03:22:39PM +0200, Stefano Garzarella wrote:
> > Vilas reported that virtio-vsock no longer worked properly after
> > suspend/resume (echo mem >/sys/power/state).
> > It was impossible to connect to the host and vice versa.
> >
> > Indeed, the support has never been implemented.
> >
> > This series implement .freeze and .restore callbacks of struct virtio_driver
> > to support device suspend/resume.
> >
> > The first patch factors our the code to initialize and delete VQs.
> > The second patch uses that code to support device suspend/resume.
> >
> > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
Commit 0530a683fc85 ("Merge branch
'vsock-virtio-add-support-for-device-suspend-resume'") in net-next, now.
Thank you!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-05-02 23:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 13:22 [PATCH net-next 0/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 1/2] vsock/virtio: factor our the code to initialize and delete VQs Stefano Garzarella
2022-04-28 13:22 ` [PATCH net-next 2/2] vsock/virtio: add support for device suspend/resume Stefano Garzarella
2022-05-02 21:35 ` [PATCH net-next 0/2] " Jakub Kicinski
2022-05-02 22:20 ` Michael S. Tsirkin
2022-05-02 23:07 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).