vhost-vdpa: Set discarding of RAM broken when initializing the backend
PATCH 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 as planned for VFIO.
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa, vhost_vdpa, vdpa_sim, vdpa_sim_net modules I probe, and in which order, no vdpa devices appear under /sys/bus/vdpa/devices/ or /dev/).
--- hw/virtio/vhost-vdpa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/virtio/vhost-vdpa.c +13 -0
@@ -278,6 +278,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)uint64_t features;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;
@@ -302,6 +313,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.29.2
Quoted 10 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
Quoted 7 lines
In the future, we might be able to support coordinated discarding of RAM as used by virtio-mem and as planned for VFIO.
Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 6 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices appear under/sys/bus/vdpa/devices/or/dev/).
The device creation was switched to use vdpa tool that is integrated with iproue2[1].
Quoted 14 lines
--- hw/virtio/vhost-vdpa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/virtio/vhost-vdpa.c +1
-0@@ -278,6 +278,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)uint64_t features;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA );trace_vhost_vdpa_init (dev, opaque); +int ret;
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) · line 291
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ +/* +* 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; + }
vDPA will support non pinning (shared VM) backend soon[2]. So I guess we need a flag to be advertised to usersapce then we can conditionly enable the discard here.
[2] https://www.spinics.net/lists/netdev/msg723944.html
Thanks
Quoted 12 lines
hw/virtio/vhost-vdpa.c +2
-0v = opaque; v->dev = dev;@@ -302,6 +313,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 ; }
Quoted 32 lines · Jason Wang
Quoted 10 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 issuedQuoted 7 lines
In the future, we might be able to support coordinated discarding of RAM as used by virtio-mem and as planned for VFIO.
Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 6 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices appear under/sys/bus/vdpa/devices/or/dev/).
Quoted 5 lines
The device creation was switched to use vdpa tool that is integrated with iproue2[1].
It would be great to document that somewhere if not already done. I only found older RH documentations that were not aware of that. I'll give it a try - thanks!
Quoted 23 lines
Quoted 23 lines
--- hw/virtio/vhost-vdpa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/virtio/vhost-vdpa.c +8
-0@@ -278,6 +278,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)uint64_t features;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) {
Quoted 8 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) · line 291
Quoted 3 lines
hw/virtio/vhost-vdpa.c +3
-0+error_report ("Cannot set discarding of RAM broken" ); +return ret; + }vDPA will support non pinning (shared VM) backend soon[2]. So I guess we need a flag to be advertised to usersapce then we can conditionly enable the discard here.
I thought that was already the default (because I stumbled over enforcing guest IOMMU) but was surprised when I had a look at the implementation.
Having a flag sounds good.
BTW: I assume iommu support is not fully working yet, right? I don't see special casing for iommu regions, including registering the listener and updating the mapping.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 36 lines · David Hildenbrand
Quoted 35 lines · Jason Wang
Quoted 10 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 issuedQuoted 7 lines
In the future, we might be able to support coordinated discarding of RAM as used by virtio-mem and as planned for VFIO.
Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 6 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices appear under/sys/bus/vdpa/devices/or/dev/).The device creation was switched to use vdpa tool that is integrated with iproue2[1].
Quoted 6 lines
Quoted 2 lines
It would be great to document that somewhere if not already done. I only found older RH documentations that were not aware of that. I'll give it a try - thanks!
Seems to work just fine:
$ sudo ./build/qemu-system-x86_64 -m 2G,maxmem=4G --enable-kvm -object memory-backend-ram,id=mem0,size=2G -device virtio-mem-pci,id=vmem0,memdev=mem0,node=0,requested-size=0G -netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa1 -device virtio-net-pci,netdev=vhost-vdpa1,mac=00:e8:ca:33:ba:05,disable-modern=off,page-per-vq=on -nographic qemu-system-x86_64: -device virtio-mem-pci,id=vmem0,memdev=mem0,node=0,requested-size=0G: Discarding RAM is disabled
I think the -netdev is always processed/initialized before the "-device virtio-mem-pci", which is why we always fail from virtio-mem code right now and not from vhost-vdpa code.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 33 lines · David Hildenbrand
Quoted 32 lines · Jason Wang
Quoted 10 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 issuedQuoted 7 lines
In the future, we might be able to support coordinated discarding of RAM as used by virtio-mem and as planned for VFIO.
Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 6 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices appear under/sys/bus/vdpa/devices/or/dev/).
Quoted 8 lines
Quoted 6 lines
The device creation was switched to use vdpa tool that is integrated with iproue2[1].
It would be great to document that somewhere if not already done. I only found older RH documentations that were not aware of that. I'll give it a try - thanks!
Will think about this. Which RH doc do you refer here? Is this the redhat blog?
Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
---
hw/virtio/vhost-vdpa.c| 13 +++++++++++++1 file changed, 13 insertions(+)hw/virtio/vhost-vdpa.c +8
-0@@ -278,6 +278,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) uint64_t features; 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) {Quoted 8 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque) · line 291
Quoted 3 lines
hw/virtio/vhost-vdpa.c +3
-0+ error_report("Cannot set discarding of RAM broken"); + return ret; + }vDPA will support non pinning (shared VM) backend soon[2]. So I guess we need a flag to be advertised to usersapce then we can conditionly enable the discard here.
Quoted 5 lines
I thought that was already the default (because I stumbled over enforcing guest IOMMU) but was surprised when I had a look at the implementation.
Having a flag sounds good.
BTW: I assume iommu support is not fully working yet, right? I don't see special casing for iommu regions, including registering the listener and updating the mapping.
It's not yet implemented. Yes, it's something like what VFIO did right now, e.g to use IOMMU notifiers.
Thanks
Quoted 47 lines · Jason Wang
Quoted 45 lines · David Hildenbrand
Quoted 43 lines · Jason Wang
Quoted 12 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 issuedQuoted 8 lines
In the future, we might be able to support coordinated discarding of RAM
as used by virtio-mem and as planned for VFIO.Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 8 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices
appear under/sys/bus/vdpa/devices/or/dev/).The device creation was switched to use vdpa tool that is integrated with iproue2[1].
Quoted 7 lines
Quoted 3 lines
It would be great to document that somewhere if not already done. I only found older RH documentations that were not aware of that. I'll give it a try - thanks!
Will think about this. Which RH doc do you refer here? Is this the redhat blog?
https://www.redhat.com/en/blog/hands-vdpa-what-do-you-do-when-you-aint-got-hardware
As it's supposed to be from October 14, 2020 I was surprised to not get it running (even with older kernels IIRC).
Signature · 3 lines
Thanks, David / dhildenb
Quoted 54 lines · David Hildenbrand
Quoted 53 lines · Jason Wang
Quoted 49 lines · David Hildenbrand
Quoted 37 lines · Jason Wang
Quoted 12 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 issuedQuoted 8 lines
In the future, we might be able to support coordinated discarding of RAM
as used by virtio-mem and as planned for VFIO.Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Acked-by Jason Wang <[email protected]>Quoted 8 lines
---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices
appear under/sys/bus/vdpa/devices/or/dev/).Quoted 7 lines
The device creation was switched to use vdpa tool that is integrated with iproue2[1].
It would be great to document that somewhere if not already done. I only found older RH documentations that were not aware of that. I'll give it a try - thanks!
Quoted 7 lines
Quoted 2 lines
Will think about this. Which RH doc do you refer here? Is this the redhat blog?
https://www.redhat.com/en/blog/hands-vdpa-what-do-you-do-when-you-aint-got-hardware
As it's supposed to be from October 14, 2020 I was surprised to not get it running (even with older kernels IIRC).
Right, the mgmt API is just merged. Will try to see if we can fix the blog.
Thanks
Quoted 52 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 issuedIn the future, we might be able to support coordinated discarding of RAM as used by virtio-mem and as planned for VFIO.
Cc Jason Wang <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Cindy Lu <[email protected]>Signed-off-by David Hildenbrand <[email protected]>---
Note: I was not actually able to reproduce/test as I fail to get the vdpa_sim/vdpa_sim_net running on upstream Linux (whetever vdpa,
vhost_vdpa,vdpa_sim,vdpa_sim_netmodules I probe, and in which order, no vdpa devices appear under/sys/bus/vdpa/devices/or/dev/).--- hw/virtio/vhost-vdpa.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/virtio/vhost-vdpa.c +11
-0@@ -278,6 +278,17 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)uint64_t features;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;
hw/virtio/vhost-vdpa.c static int vhost_vdpa_cleanup(struct vhost_dev *dev) · line 320
Quoted 8 lines
hw/virtio/vhost-vdpa.c +2
-0@@ -302,6 +313,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 ; }
@MST, do you have this on your radar? thanks
Signature · 3 lines
Thanks, David / dhildenb