Re: [PATCH 2/7] KVM: TDX: Implement TDX vcpu enter/exit path
From: Yan Zhao
Date: Thu Nov 28 2024 - 00:59:32 EST
On Fri, Nov 22, 2024 at 04:33:27PM +0200, Adrian Hunter wrote:
> On 22/11/24 07:56, Binbin Wu wrote:
> >
> >
> >
> > On 11/22/2024 1:23 PM, Xiaoyao Li wrote:
> > [...]
> >>> +
> >>> +fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
> >>> +{
> >>> + struct vcpu_tdx *tdx = to_tdx(vcpu);
> >>> +
> >>> + /* TDX exit handle takes care of this error case. */
> >>> + if (unlikely(tdx->state != VCPU_TD_STATE_INITIALIZED)) {
> >>> + /* Set to avoid collision with EXIT_REASON_EXCEPTION_NMI. */
> >>
> >> It seems the check fits better in tdx_vcpu_pre_run().
> >
> > Indeed, it's cleaner to move the check to vcpu_pre_run.
> > Then no need to set the value to vp_enter_ret, and the comments are not
> > needed.
>
> And we can take out the same check in tdx_handle_exit()
> because it won't get there if ->vcpu_pre_run() fails.
And also check for TD_STATE_RUNNABLE in tdx_vcpu_pre_run()?
> >
> >>
> >> And without the patch of how TDX handles Exit (i.e., how deal with vp_enter_ret), it's hard to review this comment.
> >>
> >>> + tdx->vp_enter_ret = TDX_SW_ERROR;
> >>> + return EXIT_FASTPATH_NONE;
> >>> + }
> >>> +
> >>> + trace_kvm_entry(vcpu, force_immediate_exit);
> >>> +
> >>> + tdx_vcpu_enter_exit(vcpu);
> >>> +
> >>> + vcpu->arch.regs_avail &= ~VMX_REGS_LAZY_LOAD_SET;
> >>> + trace_kvm_exit(vcpu, KVM_ISA_VMX);
> >>> +
> >>> + return EXIT_FASTPATH_NONE;
> >>> +}
> >>> +
> > [...]
>