Skip to content

RFC kvm: implement atomic memslot updates

Emanuele Giuseppe Esposito kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest9 patches 48 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9kvm_main.c: move slot check in kvm_set_memory_regioninclude/linux/kvm_host.h virt/kvm/kvm_main.c+5 -81 reply
2/9kvm.h: introduce KVM_SET_USER_MEMORY_REGION_LIST ioctlinclude/uapi/linux/kvm.h+20 -11 reply
3/9kvm_main.c: introduce kvm_internal_memory_region_listarch/x86/kvm/x86.c include/linux/kvm_host.h virt/kvm/kvm_main.c+51 -191 reply
4/9kvm_main.c: split logic in kvm_set_memslotsvirt/kvm/kvm_main.c+32 -51 reply
5/9kvm_main.c: split __kvm_set_memory_region logic in kvm_check_mem and kvm_prepare_batchvirt/kvm/kvm_main.c+79 -413 replies
6/9kvm_main.c: simplify change-specific callbacksvirt/kvm/kvm_main.c+23 -210 replies
7/9kvm_main.c: duplicate invalid memslot also in inactive listvirt/kvm/kvm_main.c+8 -31 reply
8/9kvm_main.c: find memslots from the inactive memslot listvirt/kvm/kvm_main.c+1 -10 replies
9/9kvm_main.c: handle atomic memslot updateinclude/linux/kvm_host.h virt/kvm/kvm_main.c+179 -108 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/9] kvm: implement atomic memslot updates

KVM is currently capable of receiving a single memslot update through the KVM_SET_USER_MEMORY_REGION ioctl.
The problem arises when we want to atomically perform multiple updates, so that readers of memslot active list avoid seeing incomplete states.

For example, in RHBZ https://bugzilla.redhat.com/show_bug.cgi?id=1979276
we see how non atomic updates cause boot failure, because vcpus will se a partial update (old memslot delete, new one not yet created) and will crash.

In this series we introduce KVM_SET_USER_MEMORY_REGION_LIST, a new ioctl that takes a kvm_userspace_memory_region_list, a list of memslot updates, and performs them atomically.
"atomically" in KVM words just means "apply all modifications to the inactive memslot list, and then perform a single swap to replace the active list with the inactive".
It is slightly more complicated that that, since DELETE and MOVE operations require 2 swaps, but the main idea is the above.

Patch 1-6 are just code movements, in preparation for the following patches. Patch 7 allows the invalid slot to be in both inactive and active memslot lists. Patch 8 allows searching for the existing memslot (old) in the inactive list, and not the active, allowing to perform multiple memslot updates without swapping. Patch 9 implements IOCTL logic.

QEMU userspace logic in preparation for the IOCTL is here:
https://patchew.org/QEMU/[email protected]/
"[RFC PATCH v2 0/3] accel/kvm: extend kvm memory listener to support"

TODOs and ideas:
- limit the size of the ioctl arguments. Right now it is unbounded
- try to reduce the amount of swaps necessary? ie every DELETE/MOVE requires an additional swap
- add selftests
- add documentation

Emanuele Giuseppe Esposito (9):
kvm_main.c: move slot check in kvm_set_memory_region kvm.h: introduce KVM_SET_USER_MEMORY_REGION_LIST ioctl kvm_main.c: introduce kvm_internal_memory_region_list kvm_main.c: split logic in kvm_set_memslots
kvm_main.c: split __kvm_set_memory_region logic in kvm_check_mem and
kvm_prepare_batch
kvm_main.c: simplify change-specific callbacks kvm_main.c: duplicate invalid memslot also in inactive list kvm_main.c: find memslots from the inactive memslot list kvm_main.c: handle atomic memslot update

 arch/x86/kvm/x86.c       |   3 +-
 include/linux/kvm_host.h |  21 +-
 include/uapi/linux/kvm.h |  21 +-
 virt/kvm/kvm_main.c      | 420 +++++++++++++++++++++++++++++++--------
 4 files changed, 377 insertions(+), 88 deletions(-)
Signature · 1 line
2.31.1