RFC kvm: Implement atomic memory region resizes
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 RFC Latest4 patches 1 replyIn review
- v1 RFC4 patches 9 repliesSuperseded
Changes in v2 from the cover letter
- "openpic_kvm: Use kvm_device_ioctl() instead of ioctl()" -- Use now "-ret" instead of errno
- "intc/s390_flic_kvm.c: Use kvm_device_ioctl() instead of ioctl()" -- As -ret now corresponds to errno, we can simplify the code
- "kvm: Implement atomic memory region resizes via region_resize()" -- Use a per-cpu spinlock instead of a global rwsem.
-- Clarify in the description why we cannot deadlock even if holding the
BQL - in contrast to other approaches
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | openpic_kvm: Use kvm_device_ioctl() instead of ioctl()hw/ | +8 | 0 replies | |
| 2/4 | intc/s390_flic_kvm.c: Use kvm_device_ioctl() instead of ioctl()hw/ | +12 | 1 reply | |
| 3/4 | memory: Add region_resize() callback to memory notifierinclude/ memory.c | +85 | 0 replies | |
| 4/4 | kvm: Implement atomic memory region resizes via region_resize()accel/ hw/ include/ | +128 | 0 replies |
Reviews trailers per patch
1 of 4 patches has a Reviewed-by or Acked-by.
| Patch | Christian Borntraeger |
|---|---|
| 1/4 | |
| 2/4 | R-b |
| 3/4 | |
| 4/4 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH RFCv2 0/4] kvm: Implement atomic memory region resizes
Currently, when doing a
memory_region_ram_resize() -> memory_region_set_size()
the old KVM slot will first get removed and the new, resized one, will be re-added. This is fine as long as no IOCTL is currently using any data from such a memory slot (e.g., when building ACPI tables). However, if e.g., a VCPU is in KVM_RUN and tries to access any data on such a slot while we're growing it, we will get wrong faults while the slot is temporarily removed.
Let's allow to resize memory regions while the guest is running and might be using the regions. Inhibit any KVM ioctl while we are replacing the memory slot(s).
This is a preparation for virtio-mem (initially, x86-64 only), which wants to resize (esp., grow, but also shrink) ram memory regions while the guest is running via memory_region_ram_resize().
Using pause_all_vcpus()/resume_all_vcpus() is not possible, as it will temporarily drop the BQL - something most callers can't handle (esp. when called from vcpu context e.g., in virtio code).
Once we can handle resizes in the kernel (e.g., via KVM_SET_USER_MEMORY_REGION), we can make inhibiting optional at runtime. Handling atomic KVM slot resizes in the kernel does not seem to be easy as well and I want to avoid depending on new kernel features.
Instead of inhibiting during the region_resize(), we could inhibit for the hole memory transaction (from begin() to commit()). This could be nice, because also splitting of memory regions would be atomic (I remember there was a BUG report regarding that), however, I am not sure if that might impact any RT users.
Tested so far with x86-64 KVM only.
RFC v1 -> RFC v2:
- "openpic_kvm: Use kvm_device_ioctl() instead of ioctl()" -- Use now "-ret" instead of errno
- "intc/s390_flic_kvm.c: Use kvm_device_ioctl() instead of ioctl()" -- As -ret now corresponds to errno, we can simplify the code
- "kvm: Implement atomic memory region resizes via region_resize()" -- Use a per-cpu spinlock instead of a global rwsem.
-- Clarify in the description why we cannot deadlock even if holding the
BQL - in contrast to other approaches
David Hildenbrand (4):
openpic_kvm: Use kvm_device_ioctl() instead of ioctl() intc/s390_flic_kvm.c: Use kvm_device_ioctl() instead of ioctl()
memory: Add region_resize() callback to memory notifier
kvm: Implement atomic memory region resizes via region_resize()
accel/kvm/kvm-all.c | 129 +++++++++++++++++++++++++++++++++++++--- hw/core/cpu.c | 2 + hw/intc/openpic_kvm.c | 16 ++--- hw/intc/s390_flic_kvm.c | 43 ++++---------- include/exec/memory.h | 18 ++++++ include/hw/core/cpu.h | 4 ++ memory.c | 72 ++++++++++++++++++++-- 7 files changed, 233 insertions(+), 51 deletions(-)
Signature · 1 line
2.24.1