[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220901012034.GD2711697@ls.amr.corp.intel.com>
Date: Wed, 31 Aug 2022 18:20:34 -0700
From: Isaku Yamahata <isaku.yamahata@...il.com>
To: Sagi Shahar <sagis@...gle.com>
Cc: linux-kselftest@...r.kernel.org,
Paolo Bonzini <pbonzini@...hat.com>,
Sean Christopherson <seanjc@...gle.com>,
Isaku Yamahata <isaku.yamahata@...el.com>,
Erdem Aktas <erdemaktas@...gle.com>,
Ryan Afranji <afranji@...gle.com>,
Roger Wang <runanwang@...gle.com>,
Shuah Khan <shuah@...nel.org>,
Andrew Jones <drjones@...hat.com>,
Marc Zyngier <maz@...nel.org>, Ben Gardon <bgardon@...gle.com>,
Jim Mattson <jmattson@...gle.com>,
David Matlack <dmatlack@...gle.com>,
Peter Xu <peterx@...hat.com>, Oliver Upton <oupton@...gle.com>,
Ricardo Koller <ricarkol@...gle.com>,
Yang Zhong <yang.zhong@...el.com>,
Wei Wang <wei.w.wang@...el.com>,
Xiaoyao Li <xiaoyao.li@...el.com>,
Peter Gonda <pgonda@...gle.com>, Marc Orr <marcorr@...gle.com>,
Emanuele Giuseppe Esposito <eesposit@...hat.com>,
Christian Borntraeger <borntraeger@...ibm.com>,
Eric Auger <eric.auger@...hat.com>,
Yanan Wang <wangyanan55@...wei.com>,
Aaron Lewis <aaronlewis@...gle.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Peter Shier <pshier@...gle.com>,
Axel Rasmussen <axelrasmussen@...gle.com>,
Zhenzhong Duan <zhenzhong.duan@...el.com>,
"Maciej S . Szmigiero" <maciej.szmigiero@...cle.com>,
Like Xu <like.xu@...ux.intel.com>,
linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
isaku.yamahata@...il.com
Subject: Re: [RFC PATCH v2 02/17] KVM: selftest: Add helper functions to
create TDX VMs
On Tue, Aug 30, 2022 at 10:19:45PM +0000,
Sagi Shahar <sagis@...gle.com> wrote:
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> index f35626df1dea..2a6e28c769f2 100644
> --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
> @@ -8,6 +8,7 @@
> #include "test_util.h"
> #include "kvm_util.h"
> #include "processor.h"
> +#include "tdx.h"
>
> #ifndef NUM_INTERRUPTS
> #define NUM_INTERRUPTS 256
> @@ -641,6 +642,32 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id,
> return vcpu;
> }
>
> +/*
> + * Adds a vCPU to a TD (Trusted Domain) with minimum defaults. It will not set
> + * up any general purpose registers as they will be initialized by the TDX. In
> + * TDX, vCPUs RIP is set to 0xFFFFFFF0. See Intel TDX EAS Section "Initial State
> + * of Guest GPRs" for more information on vCPUs initial register values when
> + * entering the TD first time.
> + *
> + * Input Args:
> + * vm - Virtual Machine
> + * vcpuid - The id of the VCPU to add to the VM.
> + */
> +struct kvm_vcpu *vm_vcpu_add_tdx(struct kvm_vm *vm, uint32_t vcpu_id)
> +{
> + struct kvm_mp_state mp_state;
> + struct kvm_vcpu *vcpu;
> +
> + vcpu = __vm_vcpu_add(vm, vcpu_id);
> + initialize_td_vcpu(vcpu);
> +
> + /* Setup the MP state */
> + mp_state.mp_state = 0;
> + vcpu_mp_state_set(vcpu, &mp_state);
> +
> + return vcpu;
> +}
> +
It's better to use symbolic value. I know this is copied from vmx version, though.
diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c
index 3bb7dc5a55ea..4009bc926e33 100644
--- a/tools/testing/selftests/kvm/lib/x86_64/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c
@@ -636,7 +636,7 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id,
vcpu_regs_set(vcpu, ®s);
/* Setup the MP state */
- mp_state.mp_state = 0;
+ mp_state.mp_state = KVM_MP_STATE_RUNNABLE;
vcpu_mp_state_set(vcpu, &mp_state);
return vcpu;
@@ -662,7 +662,7 @@ struct kvm_vcpu *vm_vcpu_add_tdx(struct kvm_vm *vm, uint32_t vcpu_id)
initialize_td_vcpu(vcpu);
/* Setup the MP state */
- mp_state.mp_state = 0;
+ mp_state.mp_state = KVM_MP_STATE_RUNNABLE;
vcpu_mp_state_set(vcpu, &mp_state);
return vcpu;
--
Isaku Yamahata <isaku.yamahata@...il.com>
Powered by blists - more mailing lists