On Mon, Mar 27, 2023 at 09:54:40AM +0000, "Huang, Kai" <kai.huang@xxxxxxxxx> wrote: > > diff -u b/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > > --- b/arch/x86/kvm/vmx/tdx.c > > +++ b/arch/x86/kvm/vmx/tdx.c > > @@ -347,6 +347,25 @@ > > return 0; > > } > > > > +u8 tdx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) > > +{ > > + /* TDX private GPA is always WB. */ > > + if (!(gfn & kvm_gfn_shared_mask(vcpu->kvm))) { > > Are you still passing a "raw" GFN? Could you explain why you choose this way? > > > + /* MMIO is only for shared GPA. */ > > + WARN_ON_ONCE(is_mmio); > > + return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; > > I guess it's better to include VMX_EPT_IPAT_BIT bit. On second thought, there is no need to check it. We can simply drop this check. u8 tdx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) { if (is_mmio) return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; /* TDX enforces CR0.CD = 0 and KVM MTRR emulation enforces writeback. */ return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; } -- Isaku Yamahata <isaku.yamahata@xxxxxxxxx>