On Fri, Apr 19, 2024 at 06:04:10PM +0800, Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx> wrote: > > > On 2/26/2024 4:27 PM, isaku.yamahata@xxxxxxxxx wrote: > > From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx> > > > > TDX protects TDX guest state from VMM. Implement access methods for TDX > > guest state to ignore them or return zero. Because those methods can be > > called by kvm ioctls to set/get cpu registers, they don't have KVM_BUG_ON > > except one method. > > > > Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx> > > --- > > arch/x86/kvm/vmx/main.c | 289 +++++++++++++++++++++++++++++++++---- > > arch/x86/kvm/vmx/tdx.c | 48 +++++- > > arch/x86/kvm/vmx/x86_ops.h | 13 ++ > > 3 files changed, 321 insertions(+), 29 deletions(-) > > > > diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c > > index 84d2dc818cf7..9fb3f28d8259 100644 > > --- a/arch/x86/kvm/vmx/main.c > > +++ b/arch/x86/kvm/vmx/main.c > > @@ -375,6 +375,200 @@ static void vt_vcpu_deliver_init(struct kvm_vcpu *vcpu) > > kvm_vcpu_deliver_init(vcpu); > > } > > +static void vt_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > > +{ > > + if (is_td_vcpu(vcpu)) > > + return; > > + > > + vmx_vcpu_after_set_cpuid(vcpu); > > +} > > + > > +static void vt_update_exception_bitmap(struct kvm_vcpu *vcpu) > > +{ > > + if (is_td_vcpu(vcpu)) > > + return; > > + > > + vmx_update_exception_bitmap(vcpu); > > +} > > + > > +static u64 vt_get_segment_base(struct kvm_vcpu *vcpu, int seg) > > +{ > > + if (is_td_vcpu(vcpu)) > > + return tdx_get_segment_base(vcpu, seg); > Could just return 0? > Not need to add a function, since it's only called here and it's more > straight forward to read the code without jump to the definition of these > functions. > > Similarly, we can use open code for tdx_get_cpl(), tdx_get_rflags() and > tdx_get_segment(), which return 0 or memset with 0. Yes, we should drop them. They came from the TDX guest debug. But right now we drop the support and we have guard with vcpu->arch.guest_state_protected. guest debug is a future topic now. -- Isaku Yamahata <isaku.yamahata@xxxxxxxxx>