qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] vhost-vdpa: Set discarding of RAM broken when initializing the backend
@ 2021-10-27 13:03 David Hildenbrand
  2021-10-28  8:45 ` Stefano Garzarella
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand @ 2021-10-27 13:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Michael S . Tsirkin, Cindy Lu, David Hildenbrand

Similar to VFIO, vDPA will go ahead an map+pin all guest memory. Memory
that used to be discarded will get re-populated and if we
discard+re-access memory after mapping+pinning, the pages mapped into the
vDPA IOMMU will go out of sync with the actual pages mapped into the user
space page tables.

Set discarding of RAM broken such that:
- virtio-mem and vhost-vdpa run mutually exclusive
- virtio-balloon is inhibited and no memory discards will get issued

In the future, we might be able to support coordinated discarding of RAM
as used by virtio-mem and already supported by vfio via the
RamDiscardManager.

Acked-by: Jason Wang <jasowang@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Cindy Lu <lulu@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---

Unfortuantely, v1 never got picked up no matter how "hard" I tried to
ping :)

v1 -> v2:
- Add ack from Jason
- Extend patch description now that RamDiscardManager is upstream.

---
 hw/virtio/vhost-vdpa.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 12661fd5b1..0d8051426c 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -331,6 +331,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp)
     struct vhost_vdpa *v;
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
     trace_vhost_vdpa_init(dev, opaque);
+    int ret;
+
+    /*
+     * Similar to VFIO, we end up pinning all guest memory and have to
+     * disable discarding of RAM.
+     */
+    ret = ram_block_discard_disable(true);
+    if (ret) {
+        error_report("Cannot set discarding of RAM broken");
+        return ret;
+    }
 
     v = opaque;
     v->dev = dev;
@@ -442,6 +453,8 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev)
     memory_listener_unregister(&v->listener);
 
     dev->opaque = NULL;
+    ram_block_discard_disable(false);
+
     return 0;
 }
 
-- 
2.31.1



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

* Re: [PATCH v2] vhost-vdpa: Set discarding of RAM broken when initializing the backend
  2021-10-27 13:03 [PATCH v2] vhost-vdpa: Set discarding of RAM broken when initializing the backend David Hildenbrand
@ 2021-10-28  8:45 ` Stefano Garzarella
  0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2021-10-28  8:45 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: Jason Wang, qemu-devel, Cindy Lu, Michael S . Tsirkin

On Wed, Oct 27, 2021 at 03:03:24PM +0200, David Hildenbrand wrote:
>Similar to VFIO, vDPA will go ahead an map+pin all guest memory. Memory
>that used to be discarded will get re-populated and if we
>discard+re-access memory after mapping+pinning, the pages mapped into the
>vDPA IOMMU will go out of sync with the actual pages mapped into the user
>space page tables.
>
>Set discarding of RAM broken such that:
>- virtio-mem and vhost-vdpa run mutually exclusive
>- virtio-balloon is inhibited and no memory discards will get issued
>
>In the future, we might be able to support coordinated discarding of RAM
>as used by virtio-mem and already supported by vfio via the
>RamDiscardManager.
>
>Acked-by: Jason Wang <jasowang@redhat.com>
>Cc: Jason Wang <jasowang@redhat.com>
>Cc: Michael S. Tsirkin <mst@redhat.com>
>Cc: Cindy Lu <lulu@redhat.com>
>Signed-off-by: David Hildenbrand <david@redhat.com>
>---
>
>Unfortuantely, v1 never got picked up no matter how "hard" I tried to
>ping :)
>
>v1 -> v2:
>- Add ack from Jason
>- Extend patch description now that RamDiscardManager is upstream.
>
>---
> hw/virtio/vhost-vdpa.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>



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

end of thread, other threads:[~2021-10-28  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-27 13:03 [PATCH v2] vhost-vdpa: Set discarding of RAM broken when initializing the backend David Hildenbrand
2021-10-28  8:45 ` Stefano Garzarella

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