lkml.org 
[lkml]   [2023]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [PATCH v13 057/113] KVM: TDX: MTRR: implement get_mt_mask() for TDX
    On Mon, Mar 27, 2023 at 09:54:40AM +0000,
    "Huang, Kai" <kai.huang@intel.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;
    }

    --
    Isaku Yamahata <isaku.yamahata@gmail.com>
    \
     
     \ /
      Last update: 2023-03-30 03:16    [W:4.045 / U:0.108 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site