From: Sagi Shahar Initialize TDX private memory and finalize the TDX VM after VM and VCPU creation. Hook tdx_load_private_memory() and tdx_vm_finalize() into kvm_arch_vm_finalize_vcpus() to avoid the need for every TDX selftest to manually load initial private memory and finalize the VM. While this prevents TDX selftests that use vm_create() helpers from customizing memory before it is locked, no current selftests require this. In TDX, finalization is a mandatory step to make the TD runnable. It also finalizes the MRTD of the VM's initial memory and state, locking them in for future attestation and preventing any further modifications. Signed-off-by: Sagi Shahar Signed-off-by: Lisa Wang Reviewed-by: Ira Weiny Reviewed-by: Xiaoyao Li Reviewed-by: Binbin Wu --- tools/testing/selftests/kvm/lib/x86/processor.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c index 11db6a3b0366..ee8a1715d844 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -1503,6 +1503,14 @@ bool kvm_arch_has_default_irqchip(void) return true; } +void kvm_arch_vm_finalize_vcpus(struct kvm_vm *vm) +{ + if (is_tdx_vm(vm)) { + tdx_load_private_memory(vm); + tdx_vm_finalize(vm); + } +} + void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, gpa_t smram_gpa, const void *smi_handler, size_t handler_size) { -- 2.56.0.455.g6c5a503b38-goog