Re: [PATCH v15 19/23] KVM: selftests: Finalize TDX VM in kvm_arch_vm_finalize_vcpus()
From: Xiaoyao Li
Date: Fri Oct 09 2026 - 04:20:11 EST
On 10/2/2026 3:37 AM, Lisa Wang wrote:
> From: Sagi Shahar <sagis@xxxxxxxxxx>
>
> Finalize TDX VM after VM and VCPU creation and memory initialization.
>
> To integrate TDX VM finalization seamlessly, the finalization is hooked
> into kvm_arch_vm_finalize_vcpus(). This approach avoids the need for
> every TDX selftest to manually finalize the VM. While it does prevent
> TDX selftests 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>
> ---
> tools/testing/selftests/kvm/lib/x86/processor.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c
> index b4b76dc505ae..e1d0fd5ed1f6 100644
> --- a/tools/testing/selftests/kvm/lib/x86/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86/processor.c
> @@ -1536,6 +1536,12 @@ 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_vm_finalize(vm);
> +}
> +
> void setup_smram(struct kvm_vm *vm, struct kvm_vcpu *vcpu, u64 smram_gpa,
> const void *smi_handler, size_t handler_size)
> {
>