Re: [PATCH v16 16/20] KVM: selftests: Load private memory and finalize TDX VM in kvm_arch_vm_finalize_vcpus()

From: Ackerley Tng

Date: Mon Nov 09 2026 - 15:09:50 EST


Lisa Wang <wyihan@xxxxxxxxxx> writes:

> From: Sagi Shahar <sagis@xxxxxxxxxx>
>
> 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 <sagis@xxxxxxxxxx>
> Signed-off-by: Lisa Wang <wyihan@xxxxxxxxxx>
> Reviewed-by: Ira Weiny <ira.weiny@xxxxxxxxx>
> Reviewed-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
> Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>
> ---
> 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

Reviewed-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>