Patchwork [3/4,v2] kvm: powerpc: define a linux pte lookup function

login
register
mail settings
Submitter Bharat Bhushan
Date Oct. 28, 2013, 10:22 a.m.
Message ID <1382955750-32249-4-git-send-email-Bharat.Bhushan@freescale.com>
Download mbox | patch
Permalink /patch/286442/
State New
Headers show

Comments

Bharat Bhushan - Oct. 28, 2013, 10:22 a.m.
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 <bharat.bhushan@freescale.com>
---
v1->v2
 -- removed _PAGE_BUSY and _PAGE_PRESENT as suggested by PaulS
 -- Added _PAGE_SPLITTING 

 arch/powerpc/include/asm/pgtable.h |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
Scott Wood - Nov. 7, 2013, 1:54 a.m.
On Mon, 2013-10-28 at 15:52 +0530, Bharat Bhushan wrote:
> 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 <bharat.bhushan@freescale.com>
> ---
> v1->v2
>  -- removed _PAGE_BUSY and _PAGE_PRESENT as suggested by PaulS
>  -- Added _PAGE_SPLITTING 
> 
>  arch/powerpc/include/asm/pgtable.h |   27 +++++++++++++++++++++++++++
>  1 files changed, 27 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
> index 7d6eacf..a7151df 100644
> --- a/arch/powerpc/include/asm/pgtable.h
> +++ b/arch/powerpc/include/asm/pgtable.h
> @@ -223,6 +223,33 @@ 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;
> +	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);
> +
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> +	/* If hugepage and is trans splitting return None */
> +	if (unlikely(hugepage && pmd_trans_splitting(pte_pmd(*ptep))))
> +		return __pte(0);
> +#endif
> +
> +	return pte_val(*ptep);;
> +}

s/;;/;/

I'd still rather see lookup_linux_ptep and then the caller can decide
what to do with it.  Currently that CONFIG_TRANSPARENT_HUGEPAGE code
will be completely untested since we don't call this except on booke.  
In fact, it doesn't even look like it compiles -- where is "hugepage"
defined?

-Scott



--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index 7d6eacf..a7151df 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -223,6 +223,33 @@  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;
+	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);
+
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	/* If hugepage and is trans splitting return None */
+	if (unlikely(hugepage && pmd_trans_splitting(pte_pmd(*ptep))))
+		return __pte(0);
+#endif
+
+	return pte_val(*ptep);;
+}
 #endif /* __ASSEMBLY__ */
 
 #endif /* __KERNEL__ */