Skip to content

RFC Add support for restricted guest memory in kvmtool

Fuad Tabba kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest32 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/32Initialize the return value in kvm__for_each_mem_bank()kvm.c+3 -20 replies
2/32Remove newline from end of die() abortsutil/util.c+5 -50 replies
3/32Make mmap_hugetlbfs() staticinclude/kvm/util.h util/util.c+1 -20 replies
4/32Rename parameter in mmap_anon_or_hugetlbfs()util/util.c+5 -50 replies
5/32Add hostmem va to debug printarm/kvm.c+2 -20 replies
6/32Factor out getting the hugetlb block sizeutil/util.c+15 -90 replies
7/32Use memfd for hugetlbfs when allocating guest ramutil/util.c+11 -50 replies
8/32Make blk_size a parameter and pass it to mmap_hugetlbfs()util/util.c+18 -170 replies
9/32Use memfd for all guest ram allocationsinclude/kvm/kvm.h include/kvm/util.h kvm.c +1 more+26 -120 replies
10/32Allocate pvtime memory with memfdarm/aarch64/pvtime.c+15 -30 replies
11/32Allocate vesa memory with memfdframebuffer.c hw/vesa.c include/kvm/framebuffer.h+16 -20 replies
12/32Add a function that allocates aligned memory if specifiedutil/util.c+38 -30 replies
13/32Use new function to align memoryarm/kvm.c riscv/kvm.c+10 -100 replies
14/32Remove struct fields and code used for alignmentarm/include/arm-common/kvm-arch.h arm/kvm.c riscv/include/kvm/kvm-arch.h +1 more+18 -480 replies
15/32Replace kvm__arch_delete_ram() with kvm__delete_ram()arm/kvm.c include/kvm/kvm.h kvm.c +4 more+9 -300 replies
16/32Remove no-longer used macroinclude/kvm/util.h+0 -10 replies
17/32Factor out set_user_memory_region codekvm.c util/util.c+29 -260 replies
18/32Pass the memory file descriptor and offset when registering ramarm/aarch64/pvtime.c arm/kvm.c hw/cfi_flash.c +8 more+28 -220 replies
19/32Add memfd_restricted system callutil/util.c+11 -00 replies
20/32Add kvm linux headers and structure extensions for restricted_fdinclude/linux/kvm.h+19 -00 replies
21/32Add option for enabling restricted memory for guestsarm/kvm.c builtin-run.c include/kvm/kvm-config.h+8 -00 replies
22/32Change guest ram mapping from private to sharedutil/util.c+1 -10 replies
23/32Change pvtime mapping from private to sharedarm/aarch64/pvtime.c+1 -10 replies
24/32Change vesa mapping from private to sharedhw/vesa.c+1 -10 replies
25/32Allocate guest memory as restricted if neededarm/aarch64/pvtime.c hw/vesa.c include/kvm/util.h +1 more+11 -74 replies
26/32Use the new fd-based extended memory regionkvm.c+49 -50 replies
27/32Track the memfd in the bankinclude/kvm/kvm.h kvm.c+4 -00 replies
28/32Add functions for mapping/unmapping guest memoryinclude/kvm/kvm.h kvm.c+187 -00 replies
29/32pkvm: Add option to spawn a protected vm in pkvmarm/aarch64/kvm.c arm/fdt.c arm/include/arm-common/fdt-arch.h +4 more+31 -10 replies
30/32pkvm: Enable exit hypercall capability if supportedarm/aarch32/include/kvm/kvm-arch.h arm/aarch64/include/kvm/kvm-arch.h arm/aarch64/kvm.c +2 more+36 -00 replies
31/32pkvm: Handle (un)share hypercalls coming from the guestarm/aarch64/include/asm/kvm.h arm/kvm-cpu.c+60 -50 replies
32/32pkvm: Unmap all guest memory after initializationbuiltin-run.c+3 -00 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 kvmtool v1 00/32] Add support for restricted guest memory in kvmtool

The main goal of this patch series is to add support for the the restricted guest memory proposali (V9) [1] to kvmtool (V10 was released today [2]). This proposal is still being discussed, but it seems to be close to its final form. The intention is that the restricted guest memory would be used in various confidential computing environments, such as TDX and pKVM.

This series is intended to work with the kernel in of the V9 proposal [1], in addition to work to port it to pKVM [3]. It has been tested on qemu/arm64.

The patch series is divided as follows:

Patches 1--4:
General fixes and tidying up

Patches 5--18:
Move kvmtool from allocating guest vm memory using anonymous mmap to using memfd/ftruncate. The main motivation is to support the fd-based kvm guest memory proposal [1, 2]. It also facilitates using ipc memory sharing should that be needed in the future. It also moves kvmtool to using only a file based backend for guest memory allocation, with the file descriptor being the canonical reference to guest memory. The idea is to refer to all allocated guest memory via a file descriptor.

Patches 19--28:
Add architecture-independent framework to support restricted guest memory.

Patches 29--32:
Add pKVM-specific (arm64) support for restricted guest memory.

I had posted a subset of this series earlier covering patches 1--18 [4]. This series incorporates fixes and suggestions from Alex into those patches.

Cheers,
/fuad

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://android-kvm.googlesource.com/kvmtool/+/refs/heads/tabba/fdmem-v9-core
[4] https://lore.kernel.org/all/[email protected]/

Fuad Tabba (31):
Initialize the return value in kvm__for_each_mem_bank() Remove newline from end of die() aborts
Make mmap_hugetlbfs() static
Rename parameter in mmap_anon_or_hugetlbfs()
Add hostmem va to debug print
Factor out getting the hugetlb block size
Use memfd for hugetlbfs when allocating guest ram Make blk_size a parameter and pass it to mmap_hugetlbfs() Use memfd for all guest ram allocations
Allocate pvtime memory with memfd
Allocate vesa memory with memfd
Add a function that allocates aligned memory if specified Use new function to align memory
Remove struct fields and code used for alignment Replace kvm__arch_delete_ram() with kvm__delete_ram() Remove no-longer used macro
Factor out set_user_memory_region code
Pass the memory file descriptor and offset when registering ram Add memfd_restricted system call
Add kvm linux headers and structure extensions for restricted_fd Add option for enabling restricted memory for guests Change guest ram mapping from private to shared Change pvtime mapping from private to shared
Change vesa mapping from private to shared
Allocate guest memory as restricted if needed
Use the new fd-based extended memory region
Track the memfd in the bank
Add functions for mapping/unmapping guest memory
pkvm: Enable exit hypercall capability if supported
pkvm: Handle (un)share hypercalls coming from the guest
pkvm: Unmap all guest memory after initialization

Will Deacon (1):
pkvm: Add option to spawn a protected vm in pkvm

 arm/aarch32/include/kvm/kvm-arch.h |   1 +
 arm/aarch64/include/asm/kvm.h      |   7 +
 arm/aarch64/include/kvm/kvm-arch.h |   1 +
 arm/aarch64/kvm.c                  |  26 +++
 arm/aarch64/pvtime.c               |  20 +-
 arm/fdt.c                          |  18 ++
 arm/include/arm-common/fdt-arch.h  |   2 +-
 arm/include/arm-common/kvm-arch.h  |   7 -
 arm/kvm-cpu.c                      |  58 ++++++
 arm/kvm.c                          |  41 ++--
 arm/pci.c                          |   3 +
 builtin-run.c                      |   7 +
 framebuffer.c                      |   2 +
 hw/cfi_flash.c                     |   4 +-
 hw/vesa.c                          |  17 +-
 include/kvm/framebuffer.h          |   1 +
 include/kvm/kvm-config.h           |   2 +
 include/kvm/kvm.h                  |  25 ++-
 include/kvm/util.h                 |   5 +-
 include/linux/kvm.h                |  19 ++
 kvm.c                              | 301 ++++++++++++++++++++++++++---
 mips/kvm.c                         |  11 +-
 powerpc/kvm.c                      |   7 +-
 riscv/include/kvm/kvm-arch.h       |   7 -
 riscv/kvm.c                        |  26 +--
 util/util.c                        | 131 ++++++++++---
 vfio/core.c                        |   3 +-
 virtio/pci-modern.c                |   3 +
 x86/kvm.c                          |  11 +-
 29 files changed, 606 insertions(+), 160 deletions(-)

base-commit: e17d182ad3f797f01947fc234d95c96c050c534b

Signature · 1 line
2.39.0.rc0.267.gcb52ba06e7-goog