[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <058c0dedfc3464a62085f071f593796c6fb9f072.camel@intel.com>
Date: Thu, 30 Mar 2023 01:36:05 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "isaku.yamahata@...il.com" <isaku.yamahata@...il.com>
CC: "Christopherson,, Sean" <seanjc@...gle.com>,
"Shahar, Sagi" <sagis@...gle.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"Aktas, Erdem" <erdemaktas@...gle.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"zhi.wang.linux@...il.com" <zhi.wang.linux@...il.com>,
"dmatlack@...gle.com" <dmatlack@...gle.com>,
"Yamahata, Isaku" <isaku.yamahata@...el.com>
Subject: Re: [PATCH v13 057/113] KVM: TDX: MTRR: implement get_mt_mask() for
TDX
On Wed, 2023-03-29 at 18:15 -0700, Isaku Yamahata wrote:
> On Mon, Mar 27, 2023 at 09:54:40AM +0000,
> "Huang, Kai" <kai.huang@...el.com> 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;
> }
>
>
I think for private page, _theoretically_, you should include VMX_EPT_IPAT_BIT
(because the TDX module spec says the "access semantics for private is WB", but
not "private is _mapped_ as WB"). But in practice this doesn't matter because
the mirrored-EPT is never used by hardware.
While for shared page, when guest has non-coherent DMA, IIUC your intention is
you still want to horner guest's PAT, so you omitted the VMX_EPT_IPAT_BIT.
Powered by blists - more mailing lists