Re: [PATCH v5 2/2] kvm: Use huge pages for DAX-backed files

From: Sean Christopherson
Date: Fri Dec 13 2019 - 12:50:34 EST


On Fri, Dec 13, 2019 at 07:31:55PM +0200, Liran Alon wrote:
>
> > On 13 Dec 2019, at 19:19, Sean Christopherson <sean.j.christopherson@xxxxxxxxx> wrote:
> >
> > Then allowed_hugepage_adjust() would look something like:
> >
> > static void allowed_hugepage_adjust(struct kvm_vcpu *vcpu, gfn_t gfn,
> > kvm_pfn_t *pfnp, int *levelp, int max_level)
> > {
> > kvm_pfn_t pfn = *pfnp;
> > int level = *levelp;
> > unsigned long mask;
> >
> > if (is_error_noslot_pfn(pfn) || !kvm_is_reserved_pfn(pfn) ||
> > level == PT_PAGE_TABLE_LEVEL)
> > return;
> >
> > /*
> > * mmu_notifier_retry() was successful and mmu_lock is held, so
> > * the pmd/pud can't be split from under us.
> > */
> > level = host_pfn_mapping_level(vcpu->kvm, gfn, pfn);
> >
> > *levelp = level = min(level, max_level);
> > mask = KVM_PAGES_PER_HPAGE(level) - 1;
> > VM_BUG_ON((gfn & mask) != (pfn & mask));
> > *pfnp = pfn & ~mask;
>
> Why donât you still need to kvm_release_pfn_clean() for original pfn and
> kvm_get_pfn() for new huge-page start pfn?

That code is gone in kvm/queue. thp_adjust() is now called from
__direct_map() and FNAME(fetch), and so its pfn adjustment doesn't bleed
back to the page fault handlers. The only reason the put/get pfn code
existed was because the page fault handlers called kvm_release_pfn_clean()
on the pfn, i.e. they would have put the wrong pfn.