qemu-s390x
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH RFCv2 0/4] kvm: Implement atomic memory region resizes


From: David Hildenbrand
Subject: [PATCH RFCv2 0/4] kvm: Implement atomic memory region resizes
Date: Thu, 12 Mar 2020 17:12:13 +0100

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

-- 
2.24.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]