Skip to contentSkip to conversation

vhost-vdpa: Set discarding of RAM broken when initializing the backend

PATCH In review David Hildenbrand 2 participants 2 messages Oct 27, 2021 – Oct 28, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vhost-vdpa: Set discarding of RAM broken when initializing the backend

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.

---

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(+)
hw/virtio/vhost-vdpa.c +13 -0
index 12661fd5b1..0d8051426c 100644
@@ -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;
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · 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.

---

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

Quoted 7 lines

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(+)