Re: [PATCH v14 22/22] KVM: selftests: Add TDX lifecycle test

Xiaoyao Li <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,dev.linux.lists.linux-coco,org.kernel.vger.kvm,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
On 7/23/2026 7:13 AM, Lisa Wang wrote:
> From: Sagi Shahar <[email protected]>
> 
> Adding a test to verify TDX lifecycle by creating a simple TDX VM.
> 
> Signed-off-by: Sagi Shahar <[email protected]>
> Signed-off-by: Lisa Wang <[email protected]>

Reviewed-by: Xiaoyao Li <[email protected]>

> ---
>   tools/testing/selftests/kvm/Makefile.kvm           |  1 +
>   .../testing/selftests/kvm/include/x86/processor.h  |  1 +
>   .../selftests/kvm/include/x86/tdx/tdx_util.h       |  5 ++++
>   tools/testing/selftests/kvm/x86/tdx_vm_test.c      | 33 ++++++++++++++++++++++
>   4 files changed, 40 insertions(+)
> 
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index 28b33ed8c2e6..3561f9284e6f 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -167,6 +167,7 @@ TEST_GEN_PROGS_x86 += rseq_test
>   TEST_GEN_PROGS_x86 += steal_time
>   TEST_GEN_PROGS_x86 += system_counter_offset_test
>   TEST_GEN_PROGS_x86 += pre_fault_memory_test
> +TEST_GEN_PROGS_x86 += x86/tdx_vm_test
>   
>   # Compiled outputs used by test targets
>   TEST_GEN_PROGS_EXTENDED_x86 += x86/nx_huge_pages_test
> diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h
> index ff3219edab44..fa112a1c1c84 100644
> --- a/tools/testing/selftests/kvm/include/x86/processor.h
> +++ b/tools/testing/selftests/kvm/include/x86/processor.h
> @@ -372,6 +372,7 @@ static inline unsigned int x86_model(unsigned int eax)
>   #define VM_SHAPE_SEV		VM_TYPE(KVM_X86_SEV_VM)
>   #define VM_SHAPE_SEV_ES		VM_TYPE(KVM_X86_SEV_ES_VM)
>   #define VM_SHAPE_SNP		VM_TYPE(KVM_X86_SNP_VM)
> +#define VM_SHAPE_TDX		VM_TYPE(KVM_X86_TDX_VM)
>   
>   #define PHYSICAL_PAGE_MASK      GENMASK_ULL(51, 12)
>   
> diff --git a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> index 35f0b2b7ac40..9a882644a48d 100644
> --- a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> @@ -11,6 +11,11 @@ static inline bool is_tdx_vm(struct kvm_vm *vm)
>   	return vm->type == KVM_X86_TDX_VM;
>   }
>   
> +static inline bool is_tdx_supported(void)
> +{
> +	return !!(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_TDX_VM));
> +}
> +
>   /*
>    * TDX ioctls
>    * Use underscores to avoid collisions with struct member names.
> diff --git a/tools/testing/selftests/kvm/x86/tdx_vm_test.c b/tools/testing/selftests/kvm/x86/tdx_vm_test.c
> new file mode 100644
> index 000000000000..7cdcaf33b585
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/tdx_vm_test.c
> @@ -0,0 +1,33 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include "processor.h"
> +#include "kvm_util.h"
> +#include "tdx/tdx_util.h"
> +#include "ucall_common.h"
> +#include "kselftest_harness.h"
> +
> +static void guest_code_lifecycle(void)
> +{
> +	GUEST_DONE();
> +}
> +
> +TEST(verify_td_lifecycle)
> +{
> +	struct kvm_vcpu *vcpu;
> +	struct kvm_vm *vm;
> +	struct ucall uc;
> +
> +	vm = vm_create_shape_with_one_vcpu(VM_SHAPE_TDX, &vcpu,
> +					   guest_code_lifecycle);
> +
> +	vcpu_run(vcpu);
> +	TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_DONE);
> +
> +	kvm_vm_free(vm);
> +}
> +
> +int main(int argc, char **argv)
> +{
> +	TEST_REQUIRE(is_tdx_supported());
> +	return test_harness_run(argc, argv);
> +}
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.