qemu: KVM VM Planes host support for VBS
v2 cover qemu: KVM VM Planes host support for VBS
This RFC adds the QEMU support needed to run Virtualization-Based Security (VBS) across KVM VM Planes. It handles the guest's plane configure and activate hypercalls in userspace: allocating and mapping each plane's RAM, creating the plane and its sibling vCPUs, and initialising them to enter the loaded plane kernel.
This is v2 of the series. Based on feedback from maintainers, the KVM host, guest, and QEMU changes are now being posted as three separate, layered RFCs to make it easier to understand the context of these changes as they pertain to the KVM host, guest, and QEMU. This patchset does not yet include memory protection between planes; that will be added in a future version.
This series is based on the QEMU VM Planes prerequisite patchset obtained from Joerg Roedel's tree (qemu-planes-linux-v7.1).
This is the userspace counterpart to the separately posted four-patch KVM host RFC. This remains prototype code and is not intended for production use.
The implementation and integration tooling are available at:
Linux and KVM support:
https://github.com/safe-tee/linux/tree/vm-planes-layered
QEMU support:
https://github.com/safe-tee/qemu/tree/vm-planes-layered
Build, test, and integration tooling:
https://github.com/safe-tee/lvbs
Acknowledgments
===============
This work stands on top of, and is indebted to, several prior efforts:
- Joerg Roedel, whose QEMU and KVM VM Planes work provides the infrastructure that the VBS/VSM secure plane relies on.
- Paolo Bonzini, whose "[RFC PATCH 00/29] KVM: VM planes" introduced the VM Plane concept to KVM as a common in-kernel model for AMD VMPLs, Intel TDX partitions, Hyper-V VTLs, and Arm CCA planes.
https://lwn.net/Articles/1016113/
- James Bottomley and James Morris, for their ongoing VSM-on-KVM work, which informed the design and direction of this series.
Feedback on the plane configuration/activation handling and the memory/vCPU setup it performs is welcome.
Sriram Nambakam (1):
kvm: handle VM-plane configure/activate hypercalls
accel/kvm/kvm-all.c | 20 + include/standard-headers/linux/kvm_para.h | 2 + include/system/kvm_int.h | 20 + target/i386/kvm/kvm.c | 517 ++++++++++++++++++++++ 4 files changed, 559 insertions(+)
base-commit: e94b8abef8617a074fac3cfc2797c0c2359ceb8c
Signature · 1 line
2.55.0
RFC PATCH v2 1/1 kvm: handle VM-plane configure/activate hypercalls
The guest plane bootstrap issues KVM_HC_VM_PLANES_CONFIG then KVM_HC_VM_PLANES_ACTIVATE, which the host exits to userspace. Handle them
here: CONFIG reads the per-plane vm_plane_config from guest memory, creates the plane (KVM_CREATE_PLANE) and one sibling vCPU per plane-0 vCPU, and maps the plane's RAM; ACTIVATE builds identity page tables, a minimal GDT and a boot zero-page in that RAM and initialises each plane vCPU to enter the loaded plane kernel in 64-bit mode.
The plane vCPUs are created and initialised on their owning plane-0 vCPU threads (they share the plane-0 kvm_vcpu_common) and are left STOPPED. QEMU never runs them: the secure plane boots lazily and in-kernel the first time the normal plane issues a VBS/VTL call.
Enable userspace exit for the two plane hypercalls; KVM_HC_VBS_VTL_CALL is handled in-kernel and is intentionally not enabled here.
--- accel/kvm/kvm-all.c | 20 + include/standard-headers/linux/kvm_para.h | 2 + include/system/kvm_int.h | 20 + target/i386/kvm/kvm.c | 517 ++++++++++++++++++++++ 4 files changed, 559 insertions(+)
accel/kvm/kvm-all.c +20 -0
@@ -822,6 +822,26 @@ void kvm_close(void)close (kvm_get_plane_fd (kvm_state, plane_id));kvm_set_plane_fd (kvm_state, plane_id,-1 ); }while (plane_id !=0 ); +if (kvm_state->vm_planes) { +unsigned int i, j; +for (i =1 ; i < kvm_state->vm_plane_count; i++) { +struct kvm_vm_plane_state *ps = &kvm_state->vm_planes[i]; +if (ps->vcpu_fds) { +for (j =0 ; j < ps->vcpu_count; j++) { +if (ps->vcpu_fds[j] >=0 ) { +close (ps->vcpu_fds[j]); + } + } +g_free (ps->vcpu_fds); + ps->vcpu_fds =NULL ; + } +g_free (ps->vcpu_cpu_index); + ps->vcpu_cpu_index =NULL ; + } +g_free (kvm_state->vm_planes); + kvm_state->vm_planes =NULL ; + kvm_state->vm_plane_count =0 ; + }close (kvm_state->fd); kvm_state->fd =-1 ; }
include/standard-headers/linux/kvm_para.h +2 -0
@@ -30,6 +30,8 @@#define KVM_HC_SEND_IPI 10#define KVM_HC_SCHED_YIELD 11#define KVM_HC_MAP_GPA_RANGE 12 +#define KVM_HC_VM_PLANES_CONFIG 13 +#define KVM_HC_VM_PLANES_ACTIVATE 14/* * hypercalls use architecture specific
include/system/kvm_int.h +20 -0
@@ -109,6 +109,22 @@ struct KVMPlane {bool vcpu_dirty; }; +/* +* Per-plane VM state managed by the LVBS VM-planes hypercall handlers. +* The plane fd itself is owned by the accel layer (kvm_get_plane_fd); +* only the plane's vCPU fds and memory description live here. +*/ +struct kvm_vm_plane_state { +int *vcpu_fds; +unsigned int *vcpu_cpu_index; +unsigned int vcpu_count; +uint64_t load_offset; +uint64_t memory_size; +uint64_t entry_point; +void *host_addr;/* host pointer to plane RAM */ +char cmdline[512 ]; +}; +struct KVMState {AccelState parent_obj;
@@ -176,6 +192,10 @@ struct KVMStateuint16_t xen_evtchn_max_pirq;char *device;OnOffAuto honor_guest_pat; +/* VM planes state (populated by the LVBS hypercall handlers) */ +struct kvm_vm_plane_state *vm_planes; +unsigned int vm_plane_count; +unsigned int vm_planes_max; };static inline void kvm_set_plane_fd (KVMState *s,unsigned plane,int fd)
target/i386/kvm/kvm.c +517 -0
539 lines not on this page · raw message
Signature · 1 line
2.55.0