Re: [PATCH v15 15/23] KVM: selftests: Call KVM_TDX_INIT_VCPU when creating a new TDX vcpu
From: Xiaoyao Li
Date: Fri Oct 09 2026 - 04:03:06 EST
On 10/2/2026 3:37 AM, Lisa Wang wrote:
> +struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, u32 vcpu_id)
> +{
> + struct kvm_mp_state mp_state;
> + struct kvm_vcpu *vcpu;
> + struct kvm_regs regs;
> +
rebase mess up due to the previous patch.
> vcpu = __vm_vcpu_add(vm, vcpu_id);
> - vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid());
> - vcpu_init_sregs(vm, vcpu);
> - vcpu_init_xcrs(vm, vcpu);
>
> - /* Setup guest general purpose registers */
> - vcpu_regs_get(vcpu, ®s);
> - regs.rflags = regs.rflags | 0x2;
> - regs.rsp = kvm_allocate_vcpu_stack(vm);
> - vcpu_regs_set(vcpu, ®s);
> + /*
> + * Both kvm_get_supported_cpuid() (for legacy VMs) and KVM_TDX_GET_CPUID
> + * (for TDX VMs) return VM-scoped CPUID. e.g. the APIC ID isn't
> + * populated per vCPU. This is fine because KVM selftests don't
> + * currently test CPUID topology enumeration.
> + */
> + if (is_tdx_vm(vm)) {
> + tdx_vcpu_init(vm, vcpu);
> + } else {
> + vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid());
> +
> + vcpu_init_sregs(vm, vcpu);
> + vcpu_init_xcrs(vm, vcpu);
> +
> + /* Setup guest general purpose registers */
> + vcpu_regs_get(vcpu, ®s);
> + regs.rflags = regs.rflags | 0x2;
> + regs.rsp = kvm_allocate_vcpu_stack(vm);
> + vcpu_regs_set(vcpu, ®s);
> + }
>
> /* Setup the MP state */
> mp_state.mp_state = 0;