From: Marcelo Tosatti <mtosatti-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Greg Edwards <gedwards-LfVdkaOWEx8@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] KVM: IOMMU: hva align mapping page size
Date: Fri, 1 Nov 2013 23:14:33 -0200 [thread overview]
Message-ID: <20131102011433.GA30381@amt.cnet> (raw)
In-Reply-To: <20131101160855.GB5052@psuche>
On Fri, Nov 01, 2013 at 10:08:55AM -0600, Greg Edwards wrote:
> When determining the page size we could use to map with the IOMMU, the
> page size should be aligned with the hva, not the gfn. The gfn may not
> reflect the real alignment within the hugetlbfs file.
>
> Most of the time, this works fine. However, if the hugetlbfs file is
> backed by non-contiguous huge pages, a multi-huge page memslot starts at
> an unaligned offset within the hugetlbfs file, and the gfn is aligned
> with respect to the huge page size, kvm_host_page_size() will return the
> huge page size and we will use that to map with the IOMMU.
>
> When we later unpin that same memslot, the IOMMU returns the unmap size
> as the huge page size, and we happily unpin that many pfns in
> monotonically increasing order, not realizing we are spanning
> non-contiguous huge pages and partially unpin the wrong huge page.
>
> Instead, ensure the IOMMU mapping page size is aligned with the hva
> corresponding to the gfn, which does reflect the alignment within the
> hugetlbfs file.
>
> Signed-off-by: Greg Edwards <gedwards-LfVdkaOWEx8@public.gmane.org>
> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> ---
> This resolves the bug previously reported (and misdiagnosed) here:
>
> http://www.spinics.net/lists/kvm/msg97599.html
>
> virt/kvm/iommu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
> index 72a130b..0e2ff32 100644
> --- a/virt/kvm/iommu.c
> +++ b/virt/kvm/iommu.c
> @@ -99,8 +99,8 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
> while ((gfn + (page_size >> PAGE_SHIFT)) > end_gfn)
> page_size >>= 1;
>
> - /* Make sure gfn is aligned to the page size we want to map */
> - while ((gfn << PAGE_SHIFT) & (page_size - 1))
> + /* Make sure hva is aligned to the page size we want to map */
> + while (__gfn_to_hva_memslot(slot, gfn) & (page_size - 1))
> page_size >>= 1;
gfn should be aligned to page size as well (IOMMU requirement), so don't
drop that check.
next prev parent reply other threads:[~2013-11-02 1:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-01 16:08 [PATCH] KVM: IOMMU: hva align mapping page size Greg Edwards
2013-11-02 1:14 ` Marcelo Tosatti [this message]
[not found] ` <20131102011433.GA30381-I4X2Mt4zSy4@public.gmane.org>
2013-11-04 16:08 ` [PATCH v2] " Greg Edwards
2013-11-04 20:14 ` Marcelo Tosatti
2013-11-05 7:56 ` Gleb Natapov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131102011433.GA30381@amt.cnet \
--to=mtosatti-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=gedwards-LfVdkaOWEx8@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).