qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] vhost: release memory objects in an error path
@ 2023-05-29 11:43 P J P
  2023-05-29 11:43 ` [PATCH v2 1/2] vhost: release memory_listener object in " P J P
  2023-05-29 11:43 ` [PATCH v2 2/2] vhost: release virtqueue objects " P J P
  0 siblings, 2 replies; 7+ messages in thread
From: P J P @ 2023-05-29 11:43 UTC (permalink / raw)
  To: Peter Xu; +Cc: QEMU Developers, Jason Wang, Michael S Tsirkin, Prasad Pandit

From: Prasad Pandit <pjp@fedoraproject.org>

Hi,

vhost_dev_start function does not release memory objects in case of
an error. These couple of patches fix this glitch.

Thank you.
---
Prasad Pandit (2):
  vhost: release memory_listener object in error path
  vhost: release virtqueue objects in error path

 hw/virtio/vhost.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.40.1



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

* [PATCH v2 1/2] vhost: release memory_listener object in error path
  2023-05-29 11:43 [PATCH v2 0/2] vhost: release memory objects in an error path P J P
@ 2023-05-29 11:43 ` P J P
  2023-05-29 15:06   ` Peter Xu
  2023-05-31  1:19   ` Jason Wang
  2023-05-29 11:43 ` [PATCH v2 2/2] vhost: release virtqueue objects " P J P
  1 sibling, 2 replies; 7+ messages in thread
From: P J P @ 2023-05-29 11:43 UTC (permalink / raw)
  To: Peter Xu; +Cc: QEMU Developers, Jason Wang, Michael S Tsirkin, Prasad Pandit

From: Prasad Pandit <pjp@fedoraproject.org>

vhost_dev_start function does not release memory_listener object
in case of an error. This may crash the guest when vhost is unable
to set memory table:

  stack trace of thread 125653:
  Program terminated with signal SIGSEGV, Segmentation fault
  #0  memory_listener_register (qemu-kvm + 0x6cda0f)
  #1  vhost_dev_start (qemu-kvm + 0x699301)
  #2  vhost_net_start (qemu-kvm + 0x45b03f)
  #3  virtio_net_set_status (qemu-kvm + 0x665672)
  #4  qmp_set_link (qemu-kvm + 0x548fd5)
  #5  net_vhost_user_event (qemu-kvm + 0x552c45)
  #6  tcp_chr_connect (qemu-kvm + 0x88d473)
  #7  tcp_chr_new_client (qemu-kvm + 0x88cf83)
  #8  tcp_chr_accept (qemu-kvm + 0x88b429)
  #9  qio_net_listener_channel_func (qemu-kvm + 0x7ac07c)
  #10 g_main_context_dispatch (libglib-2.0.so.0 + 0x54e2f)

Release memory_listener objects in the error path.

Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
---
 hw/virtio/vhost.c | 3 +++
 1 file changed, 3 insertions(+)

v2: split a single patch into two. Mention about vhost set mem table failure
resulting in guest crash.

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 23da579ce2..6be4a0626a 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -2004,6 +2004,9 @@ fail_vq:
     }

 fail_mem:
+    if (vhost_dev_has_iommu(hdev)) {
+        memory_listener_unregister(&hdev->iommu_listener);
+    }
 fail_features:
     vdev->vhost_started = false;
     hdev->started = false;
--
2.40.1



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

* [PATCH v2 2/2] vhost: release virtqueue objects in error path
  2023-05-29 11:43 [PATCH v2 0/2] vhost: release memory objects in an error path P J P
  2023-05-29 11:43 ` [PATCH v2 1/2] vhost: release memory_listener object in " P J P
@ 2023-05-29 11:43 ` P J P
  2023-05-29 15:06   ` Peter Xu
  2023-05-31  1:22   ` Jason Wang
  1 sibling, 2 replies; 7+ messages in thread
From: P J P @ 2023-05-29 11:43 UTC (permalink / raw)
  To: Peter Xu; +Cc: QEMU Developers, Jason Wang, Michael S Tsirkin, Prasad Pandit

From: Prasad Pandit <pjp@fedoraproject.org>

vhost_dev_start function does not release virtqueue objects when
event_notifier_init() function fails. Release virtqueue objects
and log a message about function failure.

Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
---
 hw/virtio/vhost.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

v2: split a single patch into two.

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 6be4a0626a..1de3029ae7 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1942,7 +1942,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
     r = event_notifier_init(
         &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier, 0);
     if (r < 0) {
-        return r;
+        VHOST_OPS_DEBUG(r, "event_notifier_init failed");
+        goto fail_vq;
     }
     event_notifier_test_and_clear(
         &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier);
--
2.40.1



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

* Re: [PATCH v2 1/2] vhost: release memory_listener object in error path
  2023-05-29 11:43 ` [PATCH v2 1/2] vhost: release memory_listener object in " P J P
@ 2023-05-29 15:06   ` Peter Xu
  2023-05-31  1:19   ` Jason Wang
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Xu @ 2023-05-29 15:06 UTC (permalink / raw)
  To: P J P; +Cc: QEMU Developers, Jason Wang, Michael S Tsirkin, Prasad Pandit

On Mon, May 29, 2023 at 05:13:32PM +0530, P J P wrote:
> From: Prasad Pandit <pjp@fedoraproject.org>
> 
> vhost_dev_start function does not release memory_listener object
> in case of an error. This may crash the guest when vhost is unable
> to set memory table:
> 
>   stack trace of thread 125653:
>   Program terminated with signal SIGSEGV, Segmentation fault
>   #0  memory_listener_register (qemu-kvm + 0x6cda0f)
>   #1  vhost_dev_start (qemu-kvm + 0x699301)
>   #2  vhost_net_start (qemu-kvm + 0x45b03f)
>   #3  virtio_net_set_status (qemu-kvm + 0x665672)
>   #4  qmp_set_link (qemu-kvm + 0x548fd5)
>   #5  net_vhost_user_event (qemu-kvm + 0x552c45)
>   #6  tcp_chr_connect (qemu-kvm + 0x88d473)
>   #7  tcp_chr_new_client (qemu-kvm + 0x88cf83)
>   #8  tcp_chr_accept (qemu-kvm + 0x88b429)
>   #9  qio_net_listener_channel_func (qemu-kvm + 0x7ac07c)
>   #10 g_main_context_dispatch (libglib-2.0.so.0 + 0x54e2f)
> 
> Release memory_listener objects in the error path.
>
> Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>

Reviewed-by: Peter Xu <peterx@redhat.com>

Maybe worthwhile too with:

Fixes: c471ad0e9b ("vhost_net: device IOTLB support")

> ---
>  hw/virtio/vhost.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> v2: split a single patch into two. Mention about vhost set mem table failure
> resulting in guest crash.
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 23da579ce2..6be4a0626a 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -2004,6 +2004,9 @@ fail_vq:
>      }
> 
>  fail_mem:
> +    if (vhost_dev_has_iommu(hdev)) {
> +        memory_listener_unregister(&hdev->iommu_listener);
> +    }
>  fail_features:
>      vdev->vhost_started = false;
>      hdev->started = false;
> --
> 2.40.1
> 

-- 
Peter Xu



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

* Re: [PATCH v2 2/2] vhost: release virtqueue objects in error path
  2023-05-29 11:43 ` [PATCH v2 2/2] vhost: release virtqueue objects " P J P
@ 2023-05-29 15:06   ` Peter Xu
  2023-05-31  1:22   ` Jason Wang
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Xu @ 2023-05-29 15:06 UTC (permalink / raw)
  To: P J P; +Cc: QEMU Developers, Jason Wang, Michael S Tsirkin, Prasad Pandit

On Mon, May 29, 2023 at 05:13:33PM +0530, P J P wrote:
> From: Prasad Pandit <pjp@fedoraproject.org>
> 
> vhost_dev_start function does not release virtqueue objects when
> event_notifier_init() function fails. Release virtqueue objects
> and log a message about function failure.
> 
> Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>

Fixes: f9a09ca3ea ("vhost: add support for configure interrupt")
Reviewed-by: Peter Xu <peterx@redhat.com>

> ---
>  hw/virtio/vhost.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> v2: split a single patch into two.
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 6be4a0626a..1de3029ae7 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1942,7 +1942,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
>      r = event_notifier_init(
>          &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier, 0);
>      if (r < 0) {
> -        return r;
> +        VHOST_OPS_DEBUG(r, "event_notifier_init failed");
> +        goto fail_vq;
>      }
>      event_notifier_test_and_clear(
>          &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier);
> --
> 2.40.1
> 

-- 
Peter Xu



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

* Re: [PATCH v2 1/2] vhost: release memory_listener object in error path
  2023-05-29 11:43 ` [PATCH v2 1/2] vhost: release memory_listener object in " P J P
  2023-05-29 15:06   ` Peter Xu
@ 2023-05-31  1:19   ` Jason Wang
  1 sibling, 0 replies; 7+ messages in thread
From: Jason Wang @ 2023-05-31  1:19 UTC (permalink / raw)
  To: P J P; +Cc: Peter Xu, QEMU Developers, Michael S Tsirkin, Prasad Pandit

On Mon, May 29, 2023 at 7:41 PM P J P <ppandit@redhat.com> wrote:
>
> From: Prasad Pandit <pjp@fedoraproject.org>
>
> vhost_dev_start function does not release memory_listener object
> in case of an error. This may crash the guest when vhost is unable
> to set memory table:
>
>   stack trace of thread 125653:
>   Program terminated with signal SIGSEGV, Segmentation fault
>   #0  memory_listener_register (qemu-kvm + 0x6cda0f)
>   #1  vhost_dev_start (qemu-kvm + 0x699301)
>   #2  vhost_net_start (qemu-kvm + 0x45b03f)
>   #3  virtio_net_set_status (qemu-kvm + 0x665672)
>   #4  qmp_set_link (qemu-kvm + 0x548fd5)
>   #5  net_vhost_user_event (qemu-kvm + 0x552c45)
>   #6  tcp_chr_connect (qemu-kvm + 0x88d473)
>   #7  tcp_chr_new_client (qemu-kvm + 0x88cf83)
>   #8  tcp_chr_accept (qemu-kvm + 0x88b429)
>   #9  qio_net_listener_channel_func (qemu-kvm + 0x7ac07c)
>   #10 g_main_context_dispatch (libglib-2.0.so.0 + 0x54e2f)
>
> Release memory_listener objects in the error path.
>
> Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>

Cc: qemu-stable@nongnu.org
Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  hw/virtio/vhost.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> v2: split a single patch into two. Mention about vhost set mem table failure
> resulting in guest crash.
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 23da579ce2..6be4a0626a 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -2004,6 +2004,9 @@ fail_vq:
>      }
>
>  fail_mem:
> +    if (vhost_dev_has_iommu(hdev)) {
> +        memory_listener_unregister(&hdev->iommu_listener);
> +    }
>  fail_features:
>      vdev->vhost_started = false;
>      hdev->started = false;
> --
> 2.40.1
>



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

* Re: [PATCH v2 2/2] vhost: release virtqueue objects in error path
  2023-05-29 11:43 ` [PATCH v2 2/2] vhost: release virtqueue objects " P J P
  2023-05-29 15:06   ` Peter Xu
@ 2023-05-31  1:22   ` Jason Wang
  1 sibling, 0 replies; 7+ messages in thread
From: Jason Wang @ 2023-05-31  1:22 UTC (permalink / raw)
  To: P J P; +Cc: Peter Xu, QEMU Developers, Michael S Tsirkin, Prasad Pandit

On Mon, May 29, 2023 at 7:41 PM P J P <ppandit@redhat.com> wrote:
>
> From: Prasad Pandit <pjp@fedoraproject.org>
>
> vhost_dev_start function does not release virtqueue objects when
> event_notifier_init() function fails. Release virtqueue objects
> and log a message about function failure.
>
> Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>

Cc: qemu-stable@nongnu.org
Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  hw/virtio/vhost.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> v2: split a single patch into two.
>
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 6be4a0626a..1de3029ae7 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -1942,7 +1942,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
>      r = event_notifier_init(
>          &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier, 0);
>      if (r < 0) {
> -        return r;
> +        VHOST_OPS_DEBUG(r, "event_notifier_init failed");
> +        goto fail_vq;
>      }
>      event_notifier_test_and_clear(
>          &hdev->vqs[VHOST_QUEUE_NUM_CONFIG_INR].masked_config_notifier);
> --
> 2.40.1
>



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

end of thread, other threads:[~2023-05-31  1:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-29 11:43 [PATCH v2 0/2] vhost: release memory objects in an error path P J P
2023-05-29 11:43 ` [PATCH v2 1/2] vhost: release memory_listener object in " P J P
2023-05-29 15:06   ` Peter Xu
2023-05-31  1:19   ` Jason Wang
2023-05-29 11:43 ` [PATCH v2 2/2] vhost: release virtqueue objects " P J P
2023-05-29 15:06   ` Peter Xu
2023-05-31  1:22   ` Jason Wang

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).