From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Aneesh Kumar K.V" Date: Tue, 15 Oct 2013 05:17:23 +0000 Subject: Re: [PATCH 3/4] kvm: powerpc: define a linux pte lookup function Message-Id: <871u3n15v0.fsf@linux.vnet.ibm.com> List-Id: References: <1381212212-29641-1-git-send-email-Bharat.Bhushan@freescale.com> <1381212212-29641-4-git-send-email-Bharat.Bhushan@freescale.com> In-Reply-To: <1381212212-29641-4-git-send-email-Bharat.Bhushan@freescale.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Bharat Bhushan , agraf@suse.de, scottwood@freescale.com, stuart.yoder@freescale.com, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, paulus@samba.org Cc: Bharat Bhushan , Bharat Bhushan Bharat Bhushan writes: > We need to search linux "pte" to get "pte" attributes for > setting TLB in KVM. > This patch defines a linux_pte_lookup() function for same. > > Signed-off-by: Bharat Bhushan > --- > arch/powerpc/include/asm/pgtable.h | 35 +++++++++++++++++++++++++++++++++++ > 1 files changed, 35 insertions(+), 0 deletions(-) > > diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h > index 7d6eacf..fd26c04 100644 > --- a/arch/powerpc/include/asm/pgtable.h > +++ b/arch/powerpc/include/asm/pgtable.h > @@ -223,6 +223,41 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, > #endif > pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, > unsigned *shift); > + > +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva, > + unsigned long *pte_sizep) > +{ > + pte_t *ptep; > + pte_t pte; > + unsigned long ps = *pte_sizep; > + unsigned int shift; > + > + ptep = find_linux_pte_or_hugepte(pgdir, hva, &shift); > + if (!ptep) > + return __pte(0); > + if (shift) > + *pte_sizep = 1ul << shift; > + else > + *pte_sizep = PAGE_SIZE; > + > + if (ps > *pte_sizep) > + return __pte(0); > + > + /* wait until _PAGE_BUSY is clear */ > + while (1) { > + pte = pte_val(*ptep); > + if (unlikely(pte & _PAGE_BUSY)) { > + cpu_relax(); > + continue; > + } What if we find a THP page that is splitting ? Older function returned __pte(0) in that case. > + } > + > + /* If pte is not present return None */ > + if (unlikely(!(pte & _PAGE_PRESENT))) > + return __pte(0); > + > + return pte; > +} > #endif /* __ASSEMBLY__ */ > > #endif /* __KERNEL__ */ > -- -aneesh From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Aneesh Kumar K.V" Subject: Re: [PATCH 3/4] kvm: powerpc: define a linux pte lookup function Date: Tue, 15 Oct 2013 10:35:23 +0530 Message-ID: <871u3n15v0.fsf@linux.vnet.ibm.com> References: <1381212212-29641-1-git-send-email-Bharat.Bhushan@freescale.com> <1381212212-29641-4-git-send-email-Bharat.Bhushan@freescale.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Bharat Bhushan , Bharat Bhushan To: Bharat Bhushan , agraf@suse.de, scottwood@freescale.com, stuart.yoder@freescale.com, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, paulus@samba.org Return-path: In-Reply-To: <1381212212-29641-4-git-send-email-Bharat.Bhushan@freescale.com> Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Bharat Bhushan writes: > We need to search linux "pte" to get "pte" attributes for > setting TLB in KVM. > This patch defines a linux_pte_lookup() function for same. > > Signed-off-by: Bharat Bhushan > --- > arch/powerpc/include/asm/pgtable.h | 35 +++++++++++++++++++++++++++++++++++ > 1 files changed, 35 insertions(+), 0 deletions(-) > > diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h > index 7d6eacf..fd26c04 100644 > --- a/arch/powerpc/include/asm/pgtable.h > +++ b/arch/powerpc/include/asm/pgtable.h > @@ -223,6 +223,41 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr, > #endif > pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea, > unsigned *shift); > + > +static inline pte_t lookup_linux_pte(pgd_t *pgdir, unsigned long hva, > + unsigned long *pte_sizep) > +{ > + pte_t *ptep; > + pte_t pte; > + unsigned long ps = *pte_sizep; > + unsigned int shift; > + > + ptep = find_linux_pte_or_hugepte(pgdir, hva, &shift); > + if (!ptep) > + return __pte(0); > + if (shift) > + *pte_sizep = 1ul << shift; > + else > + *pte_sizep = PAGE_SIZE; > + > + if (ps > *pte_sizep) > + return __pte(0); > + > + /* wait until _PAGE_BUSY is clear */ > + while (1) { > + pte = pte_val(*ptep); > + if (unlikely(pte & _PAGE_BUSY)) { > + cpu_relax(); > + continue; > + } What if we find a THP page that is splitting ? Older function returned __pte(0) in that case. > + } > + > + /* If pte is not present return None */ > + if (unlikely(!(pte & _PAGE_PRESENT))) > + return __pte(0); > + > + return pte; > +} > #endif /* __ASSEMBLY__ */ > > #endif /* __KERNEL__ */ > -- -aneesh