Re: [PATCH 2/2] powerpc/mm/autonuma: Switch ppc64 to its own implementeation of saved write

From: Michael Neuling
Date: Mon Feb 13 2017 - 22:59:29 EST


On Thu, 2017-02-09 at 08:30 +0530, Aneesh Kumar K.V wrote:
> With this our protnone becomes a present pte with READ/WRITE/EXEC bit cleared.
> By default we also set _PAGE_PRIVILEGED on such pte. This is now used to help
> us identify a protnone pte that as saved write bit. For such pte, we will
> clear
> the _PAGE_PRIVILEGED bit. The pte still remain non-accessible from both user
> and kernel.
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>


FWIW I've tested this, so:

Acked-By: Michael Neuling <mikey@xxxxxxxxxxx>

> ---
> Âarch/powerpc/include/asm/book3s/64/mmu-hash.h |ÂÂ3 +++
> Âarch/powerpc/include/asm/book3s/64/pgtable.hÂÂ| 32 +++++++++++++++++++++++++-
> -
> Â2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
> b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
> index 0735d5a8049f..8720a406bbbe 100644
> --- a/arch/powerpc/include/asm/book3s/64/mmu-hash.h
> +++ b/arch/powerpc/include/asm/book3s/64/mmu-hash.h
> @@ -16,6 +16,9 @@
> Â#include <asm/page.h>
> Â#include <asm/bug.h>
> Â
> +#ifndef __ASSEMBLY__
> +#include <linux/mmdebug.h>
> +#endif
> Â/*
> Â * This is necessary to get the definition of PGTABLE_RANGE which we
> Â * need for various slices related matters. Note that this isn't the
> diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h
> b/arch/powerpc/include/asm/book3s/64/pgtable.h
> index e91ada786d48..efff910a84b1 100644
> --- a/arch/powerpc/include/asm/book3s/64/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
> @@ -443,8 +443,8 @@ static inline pte_t pte_clear_soft_dirty(pte_t pte)
> Â */
> Âstatic inline int pte_protnone(pte_t pte)
> Â{
> - return (pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_PRIVILEGED))
> ==
> - cpu_to_be64(_PAGE_PRESENT | _PAGE_PRIVILEGED);
> + return (pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_RWX)) ==
> + cpu_to_be64(_PAGE_PRESENT);
> Â}
> Â#endif /* CONFIG_NUMA_BALANCING */
> Â
> @@ -514,6 +514,32 @@ static inline pte_t pte_mkhuge(pte_t pte)
> Â return pte;
> Â}
> Â
> +#define pte_mk_savedwrite pte_mk_savedwrite
> +static inline pte_t pte_mk_savedwrite(pte_t pte)
> +{
> + /*
> + Â* Used by Autonuma subsystem to preserve the write bit
> + Â* while marking the pte PROT_NONE. Only allow this
> + Â* on PROT_NONE pte
> + Â*/
> + VM_BUG_ON((pte_raw(pte) & cpu_to_be64(_PAGE_PRESENT | _PAGE_RWX |
> _PAGE_PRIVILEGED)) !=
> + ÂÂcpu_to_be64(_PAGE_PRESENT | _PAGE_PRIVILEGED));
> + return __pte(pte_val(pte) & ~_PAGE_PRIVILEGED);
> +}
> +
> +#define pte_savedwrite pte_savedwrite
> +static inline bool pte_savedwrite(pte_t pte)
> +{
> + /*
> + Â* Saved write ptes are prot none ptes that doesn't have
> + Â* privileged bit sit. We mark prot none as one which has
> + Â* present and pviliged bit set and RWX cleared. To mark
> + Â* protnone which used to have _PAGE_WRITE set we clear
> + Â* the privileged bit.
> + Â*/
> + return !(pte_raw(pte) & cpu_to_be64(_PAGE_RWX | _PAGE_PRIVILEGED));
> +}
> +
> Âstatic inline pte_t pte_mkdevmap(pte_t pte)
> Â{
> Â return __pte(pte_val(pte) | _PAGE_SPECIAL|_PAGE_DEVMAP);
> @@ -885,6 +911,7 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd)
> Â#define pmd_mkclean(pmd) pte_pmd(pte_mkclean(pmd_pte(pmd)))
> Â#define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
> Â#define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
> +#define pmd_mk_savedwrite(pmd) pte_pmd(pte_mk_savedwrite(pmd_pte(pmd))
> )
> Â
> Â#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
> Â#define pmd_soft_dirty(pmd)ÂÂÂÂpte_soft_dirty(pmd_pte(pmd))
> @@ -901,6 +928,7 @@ static inline int pmd_protnone(pmd_t pmd)
> Â
> Â#define __HAVE_ARCH_PMD_WRITE
> Â#define pmd_write(pmd) pte_write(pmd_pte(pmd))
> +#define pmd_savedwrite(pmd) pte_savedwrite(pmd_pte(pmd))
> Â
> Â#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> Âextern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot);