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) 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. 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. Thoughts? Anything important I am missing? Any alternatives that don't require kernel changes? 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 | 121 +++++++++++++++++++++++++++++++++++++--- hw/intc/openpic_kvm.c | 8 +-- hw/intc/s390_flic_kvm.c | 22 ++++---- include/exec/memory.h | 18 ++++++ include/hw/core/cpu.h | 3 + memory.c | 72 ++++++++++++++++++++++-- 6 files changed, 217 insertions(+), 27 deletions(-) -- 2.24.1