Skip to content

RFC New KVM ioctl to link a gmem inode to a new gmem file

Ackerley Tng kvm linux-kselftest lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest11 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11KVM: guest_mem: Refactor out kvm_gmem_alloc_file()virt/kvm/guest_mem.c+32 -210 replies
2/11KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFDinclude/uapi/linux/kvm.h virt/kvm/guest_mem.c virt/kvm/kvm_main.c +1 more+98 -02 replies
3/11KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctltools/testing/selftests/kvm/guest_memfd_test.c tools/testing/selftests/kvm/include/kvm_util_base.h+60 -00 replies
4/11KVM: selftests: Test transferring private memory to another VMtools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/x86_64/private_mem_migrate_tests.c+88 -00 replies
5/11KVM: x86: Refactor sev's flag migration_in_progress to kvm structarch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.h include/linux/kvm_host.h+7 -120 replies
6/11KVM: x86: Refactor common code out of sev.carch/x86/kvm/svm/sev.c arch/x86/kvm/x86.c arch/x86/kvm/x86.h+82 -450 replies
7/11KVM: x86: Refactor common migration preparation code out of sev_vm_move_enc_context_fromarch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c arch/x86/kvm/svm/svm.h +1 more+43 -360 replies
8/11KVM: x86: Let moving encryption context be configurablearch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c arch/x86/kvm/x86.c+12 -12 replies
9/11KVM: x86: Handle moving of memory context for intra-host migrationarch/x86/kvm/x86.c include/linux/kvm_host.h virt/kvm/guest_mem.c+152 -00 replies
10/11KVM: selftests: Generalize migration functions from sev_migrate_tests.ctools/testing/selftests/kvm/include/kvm_util_base.h tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c+30 -310 replies
11/11KVM: selftests: Add tests for migration of private memtools/testing/selftests/kvm/x86_64/private_mem_migrate_tests.c+30 -240 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 00/11] New KVM ioctl to link a gmem inode to a new gmem file

Hello,

This patchset builds upon the code at
https://lore.kernel.org/lkml/[email protected]/T/.

This code is available at
https://github.com/googleprodkernel/linux-cc/tree/kvm-gmem-link-migrate-rfcv1.

In guest_mem v11, a split file/inode model was proposed, where memslot bindings belong to the file and pages belong to the inode. This model lends itself well to having different VMs use separate files pointing to the same inode.

This RFC proposes an ioctl, KVM_LINK_GUEST_MEMFD, that takes a VM and a gmem fd, and returns another gmem fd referencing a different file and associated with VM. This RFC also includes an update to KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM to migrate memory context (slot->arch.lpage_info and kvm->mem_attr_array) from source to destination vm, intra-host.

Intended usage of the two ioctls:

1. Source VM’s fd is passed to destination VM via unix sockets
2. Destination VM uses new ioctl KVM_LINK_GUEST_MEMFD to link source VM’s fd to a new fd.
3. Destination VM will pass new fds to KVM_SET_USER_MEMORY_REGION, which will bind the new file, pointing to the same inode that the source VM’s file points to, to memslots
4. Use KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM to move kvm->mem_attr_array and slot->arch.lpage_info to the destination VM.
5. Run the destination VM as per normal

Some other approaches considered were:

+ Using the linkat() syscall, but that requires a mount/directory for a source fd to be linked to
+ Using the dup() syscall, but that only duplicates the fd, and both fds point to the same file

---

Ackerley Tng (11):
KVM: guest_mem: Refactor out kvm_gmem_alloc_file()
KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFD
KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctl
KVM: selftests: Test transferring private memory to another VM
KVM: x86: Refactor sev's flag migration_in_progress to kvm struct
KVM: x86: Refactor common code out of sev.c
KVM: x86: Refactor common migration preparation code out of
sev_vm_move_enc_context_from
KVM: x86: Let moving encryption context be configurable
KVM: x86: Handle moving of memory context for intra-host migration
KVM: selftests: Generalize migration functions from
sev_migrate_tests.c
KVM: selftests: Add tests for migration of private mem

 arch/x86/include/asm/kvm_host.h               |   4 +-
 arch/x86/kvm/svm/sev.c                        |  85 ++-----
 arch/x86/kvm/svm/svm.h                        |   3 +-
 arch/x86/kvm/x86.c                            | 221 +++++++++++++++++-
 arch/x86/kvm/x86.h                            |   6 +
 include/linux/kvm_host.h                      |  18 ++
 include/uapi/linux/kvm.h                      |   8 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../testing/selftests/kvm/guest_memfd_test.c  |  42 ++++
 .../selftests/kvm/include/kvm_util_base.h     |  31 +++
 .../kvm/x86_64/private_mem_migrate_tests.c    |  93 ++++++++
 .../selftests/kvm/x86_64/sev_migrate_tests.c  |  48 ++--
 virt/kvm/guest_mem.c                          | 151 ++++++++++--
 virt/kvm/kvm_main.c                           |  10 +
 virt/kvm/kvm_mm.h                             |   7 +
 15 files changed, 596 insertions(+), 132 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86_64/private_mem_migrate_tests.c

--
2.41.0.640.ga95def55d0-goog