From: Michael Ellerman Date: Fri, 06 Jul 2018 06:00:30 +0000 Subject: Re: [PATCH kernel v4 2/2] KVM: PPC: Check if IOMMU page is contained in the pinned physical page Message-Id: <874lhclx8h.fsf@concordia.ellerman.id.au> List-Id: References: <20180705080133.18690-1-aik@ozlabs.ru> <20180705080133.18690-3-aik@ozlabs.ru> In-Reply-To: <20180705080133.18690-3-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Alexey Kardashevskiy , linuxppc-dev@lists.ozlabs.org Cc: Alexey Kardashevskiy , David Gibson , kvm-ppc@vger.kernel.org, Alex Williamson , Paul Mackerras Alexey Kardashevskiy writes: > diff --git a/arch/powerpc/mm/mmu_context_iommu.c b/arch/powerpc/mm/mmu_context_iommu.c > index abb4364..11e1029 100644 > --- a/arch/powerpc/mm/mmu_context_iommu.c > +++ b/arch/powerpc/mm/mmu_context_iommu.c > @@ -159,6 +161,7 @@ long mm_iommu_get(struct mm_struct *mm, unsigned long ua, unsigned long entries, > goto unlock_exit; > } > > + mem->pageshift = __builtin_ctzl(ua | (entries << PAGE_SHIFT)); __builtin_ctzl(0) is undefined, so are we guaranteed that (ua | (entries << PAGE_SHIFT)) is never zero? I couldn't convince myself. > @@ -199,9 +202,17 @@ long mm_iommu_get(struct mm_struct *mm, unsigned long ua, unsigned long entries, > } > } > populate: > + pageshift = PAGE_SHIFT; > + if (PageCompound(page)) > + pageshift += compound_order(compound_head(page)); > + mem->pageshift = min(mem->pageshift, pageshift); > mem->hpas[i] = page_to_pfn(page) << PAGE_SHIFT; > } > > + /* We have an incomplete huge page, default to PAGE_SHIFT */ > + if (head) > + mem->pageshift = PAGE_SHIFT; > + You never set head AFIACS? (other than in the initialiser) cheers