[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YEwEjQZZJXvNWYna@google.com>
Date: Fri, 12 Mar 2021 16:17:17 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: "wangyanan (Y)" <wangyanan55@...wei.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, Ben Gardon <bgardon@...gle.com>,
Andrew Jones <drjones@...hat.com>,
Peter Xu <peterx@...hat.com>,
Aaron Lewis <aaronlewis@...gle.com>
Subject: Re: [PATCH 03/15] KVM: selftests: Align HVA for HugeTLB-backed
memslots
On Thu, Feb 25, 2021, wangyanan (Y) wrote:
> Hi Sean,
>
> On 2021/2/11 7:06, Sean Christopherson wrote:
> > Align the HVA for HugeTLB memslots, not just THP memslots. Add an
> > assert so any future backing types are forced to assess whether or not
> > they need to be aligned.
> >
> > Cc: Ben Gardon <bgardon@...gle.com>
> > Cc: Yanan Wang <wangyanan55@...wei.com>
> > Cc: Andrew Jones <drjones@...hat.com>
> > Cc: Peter Xu <peterx@...hat.com>
> > Cc: Aaron Lewis <aaronlewis@...gle.com>
> > Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> > ---
> > tools/testing/selftests/kvm/lib/kvm_util.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> > index 584167c6dbc7..deaeb47b5a6d 100644
> > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > @@ -731,8 +731,11 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
> > alignment = 1;
> > #endif
> > - if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
> > + if (src_type == VM_MEM_SRC_ANONYMOUS_THP ||
> > + src_type == VM_MEM_SRC_ANONYMOUS_HUGETLB)
> Sorry for the late reply, I just returned from vacation.
At least you had an excuse :-)
> I am not sure HVA alignment is really necessary here for hugetlb pages.
> Different from hugetlb pages, the THP pages are dynamically allocated by
> later madvise(), so the value of HVA returned from mmap() is host page size
> aligned but not THP page size aligned, so we indeed have to perform
> alignment. But hugetlb pages are pre-allocated on systems. The following
> test results also indicate that, with MAP_HUGETLB flag, the HVA returned from
> mmap() is already aligned to the corresponding hugetlb page size. So maybe
> HVAs of each hugetlb pages are aligned during allocation of them or in mmap()?
Yep, I verified the generic and arch version of hugetlb_get_unmapped_area() that
KVM supports all align the address. PARISC64 is the only one that looks suspect,
but it doesn't support KVM.
> If so, I think we better not do this again here, because the later
> *region->mmap_size += alignment* will cause one more hugetlb page mapped but
> will not be used.
Agreed. I think I'll still add the assert, along with a comment calling out
that HugetlB automatically handles alignment.
Nice catch, thanks!
Powered by blists - more mailing lists