Skip to content

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

Ryan Afranji kvm linux-kselftest lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 RFC Latest13 patches 0 repliesNew

Changes in v2 from the cover letter

+ Adds patches to make guest mem use guest mem inodes instead of anonymous inodes.
+ Changed the name of factored out gmem allocating function to kvm_gmem_alloc_view().
+ Changed the flag name vm_move_enc_ctxt_supported to use_vm_enc_ctxt_op.
+ Various small changes to make patchset compatible with latest version of kvm/next.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13fs: Refactor to provide function that allocates a secure anonymous inodefs/anon_inodes.c include/linux/fs.h mm/secretmem.c+24 -210 replies
2/13KVM: guest_memfd: Make guest mem use guest mem inodes instead of anonymous inodesinclude/uapi/linux/magic.h virt/kvm/guest_memfd.c virt/kvm/kvm_main.c +1 more+124 -250 replies
3/13KVM: guest_mem: Refactor out kvm_gmem_alloc_view()virt/kvm/guest_memfd.c+27 -340 replies
4/13KVM: guest_mem: Add ioctl KVM_LINK_GUEST_MEMFDinclude/uapi/linux/kvm.h virt/kvm/guest_memfd.c virt/kvm/kvm_main.c +1 more+82 -00 replies
5/13KVM: selftests: Add tests for KVM_LINK_GUEST_MEMFD ioctltools/testing/selftests/kvm/guest_memfd_test.c tools/testing/selftests/kvm/include/kvm_util.h+61 -00 replies
6/13KVM: selftests: Test transferring private memory to another VMtools/testing/selftests/kvm/x86/private_mem_migrate_tests.c+87 -00 replies
7/13KVM: 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
8/13KVM: x86: Refactor common code out of sev.carch/x86/kvm/svm/sev.c arch/x86/kvm/x86.c arch/x86/kvm/x86.h+82 -460 replies
9/13KVM: 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 -290 replies
10/13KVM: x86: Let moving encryption context be configurablearch/x86/include/asm/kvm_host.h arch/x86/kvm/svm/sev.c arch/x86/kvm/x86.c+11 -10 replies
11/13KVM: x86: Handle moving of memory context for intra-host migrationarch/x86/kvm/x86.c include/linux/kvm_host.h virt/kvm/guest_memfd.c+152 -00 replies
12/13KVM: selftests: Generalize migration functions from sev_migrate_tests.ctools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/x86/sev_migrate_tests.c+30 -310 replies
13/13KVM: selftests: Add tests for migration of private memtools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/x86/private_mem_migrate_tests.c+32 -250 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [RFC PATCH v2 00/13] New KVM ioctl to link a gmem inode to a new gmem file

Hello,

RFC v2 addresses comments in RFC v1 [1]. This series is also rebased on kvm/next (v6.15-rc4).

Here's the series stitched together for your convenience:
https://github.com/googleprodkernel/linux-cc/tree/kvm-gmem-link-migrate-rfcv2

Changes from RFC v1:
+ Adds patches to make guest mem use guest mem inodes instead of anonymous inodes.
+ Changed the name of factored out gmem allocating function to kvm_gmem_alloc_view().
+ Changed the flag name vm_move_enc_ctxt_supported to use_vm_enc_ctxt_op.
+ Various small changes to make patchset compatible with latest version of kvm/next.

As a refresher, split file/inode model was proposed in guest_mem v11, 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.

The split file/inode model has also been used by the other following recent patch series:

+ mmap support for guest_memfd: [2]
+ NUMA mempolicy support for guest_memfd: [3]
+ HugeTLB support for guest_memfd: [4]

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

[1] https://lore.kernel.org/all/[email protected]/T/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/c1ee659c212b5a8b0e7a7f4d1763699176dd3a62.1747264138.git.ackerleytng@google.com/

---

Ackerley Tng (12):
KVM: guest_memfd: Make guest mem use guest mem inodes instead of
anonymous inodes
KVM: guest_mem: Refactor out kvm_gmem_alloc_view()
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

David Hildenbrand (1):
fs: Refactor to provide function that allocates a secure anonymous
inode

 arch/x86/include/asm/kvm_host.h               |   3 +-
 arch/x86/kvm/svm/sev.c                        |  82 +------
 arch/x86/kvm/svm/svm.h                        |   3 +-
 arch/x86/kvm/x86.c                            | 218 ++++++++++++++++-
 arch/x86/kvm/x86.h                            |   6 +
 fs/anon_inodes.c                              |  23 +-
 include/linux/fs.h                            |  13 +-
 include/linux/kvm_host.h                      |  18 ++
 include/uapi/linux/kvm.h                      |   8 +
 include/uapi/linux/magic.h                    |   1 +
 mm/secretmem.c                                |   9 +-
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../testing/selftests/kvm/guest_memfd_test.c  |  43 ++++
 .../testing/selftests/kvm/include/kvm_util.h  |  31 +++
 .../kvm/x86/private_mem_migrate_tests.c       |  93 ++++++++
 .../selftests/kvm/x86/sev_migrate_tests.c     |  48 ++--
 virt/kvm/guest_memfd.c                        | 225 +++++++++++++++---
 virt/kvm/kvm_main.c                           |  17 +-
 virt/kvm/kvm_mm.h                             |  14 +-
 19 files changed, 697 insertions(+), 159 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86/private_mem_migrate_tests.c
Signature · 1 line
2.49.0.1101.gccaa498523-goog