powerpc/mm: Update page table format for book3s 64
v2 cover powerpc/mm: Update page table format for book3s 64
Hi All,
This patch series attempt to update book3s 64 linux page table format to make it more flexible. Our current pte format is very restrictive and we overload multiple pte bits. This is due to the non-availability of free bits in pte_t. We use pte_t to track the validity of 4K subpages. This patch series free up pte_t of 11 bits by moving 4K subpage tracking to the lower half of PTE page. The pte format is updated such that we have a better method for identifying a pte entry at pmd level. This will also enable us to implement hugetlb migration(not yet done in this series).
Before making the changes to the pte format, I am splitting the pte header definition such that we now have the below layout for headers
book3s
32
hash.h pgtable.h
64
hash.h pgtable.h hash-4k.h hash-64k.h
booke
32
pgtable.h pte-40x.h pte-44x.h pte-8xx.h pte-fsl-booke.h
64
pgtable-4k.h pgtable-64k.h pgtable.h
I have done the header split such that booke headers and modified to the minimum so as to avoid causing breakage in booke.
The patch series can also be found at
https://github.com/kvaneesh/linux.git book3s-pte-format
https://github.com/kvaneesh/linux/commits/book3s-pte-format
Performance numbers with and without patch series.
Path length __hash_page_4k
with patch: 196
without patch: 142
Path length __hash_page_64k
with patch: 219
without patch: 154
But even if we have a path lengh increase of around 50 instructions. We don't see the impact when running workload. I tried the kernelbuild test.
With THP enabled (which is default) we see an improvement. I haven't fully looked at the reason. This could be due to reduced contention of ptl lock. __hash_thp_page is already a C code.
make -j64 vmlinux modules
With fix:
---------
real 1m35.509s user 56m8.565s sys 4m34.973s
real 1m32.174s user 57m2.336s sys 4m39.142s
Without fix:
---------------
real 1m37.703s user 58m50.783s sys 7m52.440s
real 1m37.890s user 57m55.445s sys 7m50.501s
THP disabled:
make -j64 vmlinux modules
With fix:
---------
real 1m37.197s user 58m28.672s sys 7m58.188s
real 1m44.638s user 58m37.551s sys 7m53.960s
Without fix:
------------
real 1m41.224s user 58m46.944s sys 7m49.714s
real 1m42.585s user 59m14.019s sys 7m52.714s
Changes from V1:
1) Build fix with STRICT_MM_TYPES enabled
2) pte_mkwrite fix for nohash
3) rebase to latest linus tree.
Aneesh Kumar K.V (31):
powerpc/mm: move pte headers to book3s directory powerpc/mm: move pte headers to book3s directory (part 2) powerpc/mm: make a separate copy for book3s
powerpc/mm: make a separate copy for book3s (part 2) powerpc/mm: Move hash specific pte width and other defines to book3s powerpc/mm: Delete booke bits from book3s
powerpc/mm: Don't have generic headers introduce functions touching
pte bits
powerpc/mm: Drop pte-common.h from BOOK3S 64
powerpc/mm: Don't use pte_val as lvalue
powerpc/mm: Don't use pmd_val,pud_val and pgd_val as lvalue powerpc/mm: Move hash64 PTE bits from book3s/64/pgtable.h to hash.h powerpc/mm: Move PTE bits from generic functions to hash64 functions. powerpc/booke: Move booke headers (part 1)
powerpc/booke: Move booke headers (part 2)
powerpc/booke: Move booke headers (part 3)
powerpc/booke: Move booke headers (part 4)
powerpc/booke: Move booke headers (part 5)
powerpc/mm: Increase the pte frag size.
powerpc/mm: Convert 4k hash insert to C
powerpc/mm: update __real_pte to take address as argument powerpc/mm: make pte page hash index slot 8 bits powerpc/mm: Don't track subpage valid bit in pte_t powerpc/mm: Increase the width of #define
powerpc/mm: Convert __hash_page_64K to C
powerpc/mm: Convert 4k insert from asm to C
powerpc/mm: Remove the dependency on pte bit position in asm code powerpc/mm: Add helper for converting pte bit to hpte bits powerpc/mm: Move WIMG update to helper.
powerpc/mm: Move hugetlb related headers
powerpc/mm: Move THP headers around
powerpc/mm: Add a _PAGE_PTE bit
.../include/asm/{pte-hash32.h => book3s/32/hash.h} | 6 +-
arch/powerpc/include/asm/book3s/32/pgtable.h | 476 ++++++++++
arch/powerpc/include/asm/book3s/64/hash-4k.h | 132 +++
arch/powerpc/include/asm/book3s/64/hash-64k.h | 285 ++++++
arch/powerpc/include/asm/book3s/64/hash.h | 513 ++++++++++
arch/powerpc/include/asm/book3s/64/pgtable.h | 266 ++++++
arch/powerpc/include/asm/book3s/pgtable.h | 29 +
arch/powerpc/include/asm/mmu-hash64.h | 2 +-
.../asm/{pgtable-ppc32.h => nohash/32/pgtable.h} | 25 +-
arch/powerpc/include/asm/{ => nohash/32}/pte-40x.h | 6 +-
arch/powerpc/include/asm/{ => nohash/32}/pte-44x.h | 6 +-
arch/powerpc/include/asm/{ => nohash/32}/pte-8xx.h | 6 +-
.../include/asm/{ => nohash/32}/pte-fsl-booke.h | 6 +-
.../{pgtable-ppc64-4k.h => nohash/64/pgtable-4k.h} | 12 +-
.../64/pgtable-64k.h} | 6 +-
.../asm/{pgtable-ppc64.h => nohash/64/pgtable.h} | 299 +-----
arch/powerpc/include/asm/nohash/pgtable.h | 252 +++++
arch/powerpc/include/asm/{ => nohash}/pte-book3e.h | 6 +-
arch/powerpc/include/asm/page.h | 75 +-
arch/powerpc/include/asm/pgalloc-32.h | 34 +-
arch/powerpc/include/asm/pgalloc-64.h | 29 +-
arch/powerpc/include/asm/pgtable.h | 200 +---
arch/powerpc/include/asm/pte-common.h | 5 +
arch/powerpc/include/asm/pte-hash64-4k.h | 17 -
arch/powerpc/include/asm/pte-hash64-64k.h | 102 --
arch/powerpc/include/asm/pte-hash64.h | 54 --
arch/powerpc/kernel/exceptions-64s.S | 16 +-
arch/powerpc/mm/Makefile | 9 +-
arch/powerpc/mm/hash64_4k.c | 123 +++
arch/powerpc/mm/hash64_64k.c | 313 ++++++
arch/powerpc/mm/hash_low_64.S | 1003 --------------------
arch/powerpc/mm/hash_native_64.c | 10 +
arch/powerpc/mm/hash_utils_64.c | 105 +-
arch/powerpc/mm/hugepage-hash64.c | 20 +-
arch/powerpc/mm/hugetlbpage-hash64.c | 15 +-
arch/powerpc/mm/hugetlbpage.c | 57 +-
arch/powerpc/mm/pgtable.c | 4 +
arch/powerpc/mm/pgtable_64.c | 28 +-
arch/powerpc/mm/tlb_hash64.c | 2 +-
arch/powerpc/platforms/pseries/lpar.c | 10 +
40 files changed, 2670 insertions(+), 1894 deletions(-)
rename arch/powerpc/include/asm/{pte-hash32.h => book3s/32/hash.h} (93%)
create mode 100644 arch/powerpc/include/asm/book3s/32/pgtable.h
create mode 100644 arch/powerpc/include/asm/book3s/64/hash-4k.h
create mode 100644 arch/powerpc/include/asm/book3s/64/hash-64k.h
create mode 100644 arch/powerpc/include/asm/book3s/64/hash.h
create mode 100644 arch/powerpc/include/asm/book3s/64/pgtable.h
create mode 100644 arch/powerpc/include/asm/book3s/pgtable.h
rename arch/powerpc/include/asm/{pgtable-ppc32.h => nohash/32/pgtable.h} (96%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-40x.h (95%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-44x.h (96%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-8xx.h (95%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-fsl-booke.h (88%)
rename arch/powerpc/include/asm/{pgtable-ppc64-4k.h => nohash/64/pgtable-4k.h} (92%)
rename arch/powerpc/include/asm/{pgtable-ppc64-64k.h => nohash/64/pgtable-64k.h} (90%)
rename arch/powerpc/include/asm/{pgtable-ppc64.h => nohash/64/pgtable.h} (56%)
create mode 100644 arch/powerpc/include/asm/nohash/pgtable.h
rename arch/powerpc/include/asm/{ => nohash}/pte-book3e.h (95%)
delete mode 100644 arch/powerpc/include/asm/pte-hash64-4k.h
delete mode 100644 arch/powerpc/include/asm/pte-hash64-64k.h
delete mode 100644 arch/powerpc/include/asm/pte-hash64.h
create mode 100644 arch/powerpc/mm/hash64_4k.c
create mode 100644 arch/powerpc/mm/hash64_64k.c
delete mode 100644 arch/powerpc/mm/hash_low_64.SSignature · 1 line
2.5.0
PATCH v2 1/31 powerpc/mm: move pte headers to book3s directory
---
arch/powerpc/include/asm/{pte-hash32.h => book3s/32/hash.h} | 0
arch/powerpc/include/asm/{pte-hash64.h => book3s/64/hash.h} | 0
arch/powerpc/include/asm/pgtable-ppc32.h | 2 +-
arch/powerpc/include/asm/pgtable-ppc64.h | 2 +-
4 files changed, 2 insertions(+), 2 deletions(-)
rename arch/powerpc/include/asm/{pte-hash32.h => book3s/32/hash.h} (100%)
rename arch/powerpc/include/asm/{pte-hash64.h => book3s/64/hash.h} (100%)arch/powerpc/include/asm/book3s/32/hash.h renamed from arch/powerpc/include/asm/pte-hash32.h +0 -0
arch/powerpc/include/asm/book3s/64/hash.h renamed from arch/powerpc/include/asm/pte-hash64.h +0 -0
arch/powerpc/include/asm/pgtable-ppc32.h +1 -1
@@ -116,7 +116,7 @@ extern int icache_44x_need_flush;#elif defined(CONFIG_8xx)#include <asm/pte-8xx.h> #else /* CONFIG_6xx */ -#include <asm/pte-hash32.h> +#include <asm/book3s/32/hash.h> #endif /* And here we include common definitions */
arch/powerpc/include/asm/pgtable-ppc64.h +1 -1
@@ -98,7 +98,7 @@* Include the PTE bits definitions */ #ifdef CONFIG_PPC_BOOK3S -#include <asm/pte-hash64.h> +#include <asm/book3s/64/hash.h> #else #include <asm/pte-book3e.h> #endif
Signature · 1 line
2.5.0
PATCH v2 2/31 powerpc/mm: move pte headers to book3s directory (part 2)
In reply to Aneesh Kumar K.VSplitting this so that rename can track changes to file. Before merging we will fold this
---
arch/powerpc/include/asm/book3s/32/hash.h | 6 +++---
.../include/asm/{pte-hash64-4k.h => book3s/64/hash-4k.h} | 1 -
.../include/asm/{pte-hash64-64k.h => book3s/64/hash-64k.h} | 0
arch/powerpc/include/asm/book3s/64/hash.h | 10 +++++-----
4 files changed, 8 insertions(+), 9 deletions(-)
rename arch/powerpc/include/asm/{pte-hash64-4k.h => book3s/64/hash-4k.h} (99%)
rename arch/powerpc/include/asm/{pte-hash64-64k.h => book3s/64/hash-64k.h} (100%)arch/powerpc/include/asm/book3s/32/hash.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_HASH32_H -#define _ASM_POWERPC_PTE_HASH32_H +#ifndef _ASM_POWERPC_BOOK3S_32_HASH_H +#define _ASM_POWERPC_BOOK3S_32_HASH_H#ifdef __KERNEL__/*
@@ -43,4 +43,4 @@#define PTE_ATOMIC_UPDATES 1#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_HASH32_H */ +#endif /* _ASM_POWERPC_BOOK3S_32_HASH_H */
arch/powerpc/include/asm/book3s/64/hash-4k.h renamed from arch/powerpc/include/asm/pte-hash64-4k.h +0 -1
@@ -14,4 +14,3 @@/* shift to put page number into pte */ #define PTE_RPN_SHIFT (17) -
arch/powerpc/include/asm/book3s/64/hash-64k.h renamed from arch/powerpc/include/asm/pte-hash64-64k.h +0 -0
arch/powerpc/include/asm/book3s/64/hash.h +5 -5
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_HASH64_H -#define _ASM_POWERPC_PTE_HASH64_H +#ifndef _ASM_POWERPC_BOOK3S_64_HASH_H +#define _ASM_POWERPC_BOOK3S_64_HASH_H#ifdef __KERNEL__/*
@@ -45,10 +45,10 @@#define PTE_ATOMIC_UPDATES 1#ifdef CONFIG_PPC_64K_PAGES -#include <asm/pte-hash64-64k.h> +#include <asm/book3s/64/hash-64k.h> #else -#include <asm/pte-hash64-4k.h> +#include <asm/book3s/64/hash-4k.h> #endif #endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_HASH64_H */ +#endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */
Signature · 1 line
2.5.0
PATCH v2 3/31 powerpc/mm: make a separate copy for book3s
In reply to Aneesh Kumar K.VIn this patch we do:
cp pgtable-ppc32.h book3s/32/pgtable.h
cp pgtable-ppc64.h book3s/64/pgtable.h
This enable us to do further changes to hash specific config. We will change the page table format for 64bit hash in later patches.
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 340 +++++++++++++++ arch/powerpc/include/asm/book3s/64/pgtable.h | 618 +++++++++++++++++++++++++++ arch/powerpc/include/asm/book3s/pgtable.h | 10 + arch/powerpc/include/asm/mmu-hash64.h | 2 +- arch/powerpc/include/asm/pgtable-ppc32.h | 2 - arch/powerpc/include/asm/pgtable-ppc64.h | 4 - arch/powerpc/include/asm/pgtable.h | 4 + 7 files changed, 973 insertions(+), 7 deletions(-) create mode 100644 arch/powerpc/include/asm/book3s/32/pgtable.h create mode 100644 arch/powerpc/include/asm/book3s/64/pgtable.h create mode 100644 arch/powerpc/include/asm/book3s/pgtable.h
arch/powerpc/include/asm/book3s/32/pgtable.h new file +340 -0
@@ -0,0 +1,340 @@ +#ifndef _ASM_POWERPC_PGTABLE_PPC32_H +#define _ASM_POWERPC_PGTABLE_PPC32_H + +#include <asm-generic/pgtable-nopmd.h> + +#ifndef __ASSEMBLY__ +#include <linux/sched.h> +#include <linux/threads.h> +#include <asm/io.h> /* For sub-arch specific PPC_PIN_SIZE */ + +extern unsigned long ioremap_bot; + +#ifdef CONFIG_44x +extern int icache_44x_need_flush; +#endif + +#endif /* __ASSEMBLY__ */ + +/* +* The normal case is that PTEs are 32-bits and we have a 1-page +* 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus +* +* For any >32-bit physical address platform, we can use the following +* two level page table layout where the pgdir is 8KB and the MS 13 bits +* are an index to the second level table. The combined pgdir/pmd first +* level has 2048 entries and the second level has 512 64-bit PTE entries. +* -Matt +*/ +/* PGDIR_SHIFT determines what a top-level page table entry can map */ +#define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT) +#define PGDIR_SIZE (1UL << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +/* +* entries per page directory level: our page-table tree is two-level, so +* we don't really have any PMD directory. +*/ +#ifndef __ASSEMBLY__ +#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_SHIFT) +#define PGD_TABLE_SIZE (sizeof(pgd_t) << (32 - PGDIR_SHIFT)) +#endif /* __ASSEMBLY__ */ + +#define PTRS_PER_PTE (1 << PTE_SHIFT) +#define PTRS_PER_PMD 1 +#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) + +#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) +#define FIRST_USER_ADDRESS 0UL + +#define pte_ERROR (e) \ + pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \ + (unsigned long long)pte_val(e)) +#define pgd_ERROR (e) \ + pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) + +/* +* This is the bottom of the PKMAP area with HIGHMEM or an arbitrary +* value (for now) on others, from where we can start layout kernel +* virtual space that goes below PKMAP and FIXMAP +*/ +#ifdef CONFIG_HIGHMEM +#define KVIRT_TOP PKMAP_BASE +#else +#define KVIRT_TOP (0xfe000000UL)/* for now, could be FIXMAP_BASE ? */ +#endif + +/* +* ioremap_bot starts at that address. Early ioremaps move down from there, +* until mem_init() at which point this becomes the top of the vmalloc +* and ioremap space +*/ +#ifdef CONFIG_NOT_COHERENT_CACHE +#define IOREMAP_TOP ((KVIRT_TOP - CONFIG_CONSISTENT_SIZE) & PAGE_MASK) +#else +#define IOREMAP_TOP KVIRT_TOP +#endif + +/* +* Just any arbitrary offset to the start of the vmalloc VM area: the +* current 16MB value just means that there will be a 64MB "hole" after the +* physical memory until the kernel virtual memory starts. That means that +* any out-of-bounds memory accesses will hopefully be caught. +* The vmalloc() routines leaves a hole of 4kB between each vmalloced +* area for the same reason. ;) +* +* We no longer map larger than phys RAM with the BATs so we don't have +* to worry about the VMALLOC_OFFSET causing problems. We do have to worry +* about clashes between our early calls to ioremap() that start growing down +* from ioremap_base being run into the VM area allocations (growing upwards +* from VMALLOC_START). For this reason we have ioremap_bot to check when +* we actually run into our mappings setup in the early boot with the VM +* system. This really does become a problem for machines with good amounts +* of RAM. -- Cort +*/ +#define VMALLOC_OFFSET (0x1000000)/* 16M */ +#ifdef PPC_PIN_SIZE +#define VMALLOC_START (((_ALIGN((long)high_memory, PPC_PIN_SIZE) + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))) +#else +#define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))) +#endif +#define VMALLOC_END ioremap_bot + +/* +* Bits in a linux-style PTE. These match the bits in the +* (hardware-defined) PowerPC PTE as closely as possible. +*/ + +#if defined(CONFIG_40x) +#include <asm/pte-40x.h> +#elif defined(CONFIG_44x) +#include <asm/pte-44x.h> +#elif defined(CONFIG_FSL_BOOKE ) && defined(CONFIG_PTE_64BIT ) +#include <asm/pte-book3e.h> +#elif defined(CONFIG_FSL_BOOKE ) +#include <asm/pte-fsl-booke.h> +#elif defined(CONFIG_8xx) +#include <asm/pte-8xx.h> +#else /* CONFIG_6xx */ +#include <asm/book3s/32/hash.h> +#endif + +/* And here we include common definitions */ +#include <asm/pte-common.h> + +#ifndef __ASSEMBLY__ + +#define pte_clear (mm, addr, ptep) \ + do { pte_update(ptep, ~_PAGE_HASHPTE, 0); } while (0) + +#define pmd_none (pmd) (!pmd_val(pmd)) +#define pmd_bad (pmd) (pmd_val(pmd) & _PMD_BAD) +#define pmd_present (pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK) +#define pmd_clear (pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) + +/* +* When flushing the tlb entry for a page, we also need to flush the hash +* table entry. flush_hash_pages is assembler (for speed) in hashtable.S. +*/ +extern int flush_hash_pages (unsigned context,unsigned long va, +unsigned long pmdval,int count); + +/* Add an HPTE to the hash table */ +extern void add_hash_page (unsigned context,unsigned long va, +unsigned long pmdval); + +/* Flush an entry from the TLB/hash table */ +extern void flush_hash_entry (struct mm_struct *mm,pte_t *ptep, +unsigned long address); + +/* +* PTE updates. This function is called whenever an existing +* valid PTE is updated. This does -not- include set_pte_at() +* which nowadays only sets a new PTE. +* +* Depending on the type of MMU, we may need to use atomic updates +* and the PTE may be either 32 or 64 bit wide. In the later case, +* when using atomic updates, only the low part of the PTE is +* accessed atomically. +* +* In addition, on 44x, we also maintain a global flag indicating +* that an executable user mapping was modified, which is needed +* to properly flush the virtually tagged instruction cache of +* those implementations. +*/ +#ifndef CONFIG_PTE_64BIT +static inline unsigned long pte_update (pte_t *p, +unsigned long clr, +unsigned long set) +{ +#ifdef PTE_ATOMIC_UPDATES +unsigned long old, tmp; + + __asm__ __volatile__("\ +1: lwarx %0,0,%3\n\ +andc %1,%0,%4\n\ +or %1,%1,%5\n" + PPC405_ERR77(0,%3) +" stwcx. %1,0,%3\n\ + bne- 1b" + : "=&r" (old), "=&r" (tmp), "=m" (*p) + : "r" (p), "r" (clr), "r" (set), "m" (*p) + : "cc" ); +#else /* PTE_ATOMIC_UPDATES */ +unsigned long old =pte_val (*p); + *p =__pte ((old & ~clr) | set); +#endif /* !PTE_ATOMIC_UPDATES */ + +#ifdef CONFIG_44x +if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) + icache_44x_need_flush =1 ; +#endif +return old; +} +#else /* CONFIG_PTE_64BIT */ +static inline unsigned long long pte_update (pte_t *p, +unsigned long clr, +unsigned long set) +{ +#ifdef PTE_ATOMIC_UPDATES +unsigned long long old; +unsigned long tmp; + + __asm__ __volatile__("\ +1: lwarx %L0,0,%4\n\ +lwzx %0,0,%3\n\ +andc %1,%L0,%5\n\ +or %1,%1,%6\n" + PPC405_ERR77(0,%3) +" stwcx. %1,0,%4\n\ + bne- 1b" + : "=&r" (old), "=&r" (tmp), "=m" (*p) + : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p) + : "cc" ); +#else /* PTE_ATOMIC_UPDATES */ +unsigned long long old =pte_val (*p); + *p =__pte ((old & ~(unsigned long long )clr) | set); +#endif /* !PTE_ATOMIC_UPDATES */ + +#ifdef CONFIG_44x +if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) + icache_44x_need_flush =1 ; +#endif +return old; +} +#endif /* CONFIG_PTE_64BIT */ + +/* +* 2.6 calls this without flushing the TLB entry; this is wrong +* for our hash-based implementation, we fix that up here. +*/ +#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG +static inline int __ptep_test_and_clear_young (unsigned int context,unsigned long addr,pte_t *ptep) +{ +unsigned long old; + old =pte_update (ptep, _PAGE_ACCESSED,0 ); +#if _PAGE_HASHPTE !=0 +if (old & _PAGE_HASHPTE) { +unsigned long ptephys =__pa (ptep) &PAGE_MASK ; +flush_hash_pages (context, addr, ptephys,1 ); + } +#endif +return (old & _PAGE_ACCESSED) !=0 ; +} +#define ptep_test_and_clear_young (__vma, __addr, __ptep) \ + __ptep_test_and_clear_young((__vma)->vm_mm->context.id, __addr, __ptep) + +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR +static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep) +{ +return __pte (pte_update (ptep, ~_PAGE_HASHPTE,0 )); +} + +#define __HAVE_ARCH_PTEP_SET_WRPROTECT +static inline void ptep_set_wrprotect (struct mm_struct *mm,unsigned long addr, +pte_t *ptep) +{ +pte_update (ptep, (_PAGE_RW | _PAGE_HWWRITE), _PAGE_RO); +} +static inline void huge_ptep_set_wrprotect (struct mm_struct *mm, +unsigned long addr,pte_t *ptep) +{ +ptep_set_wrprotect (mm, addr, ptep); +} + + +static inline void __ptep_set_access_flags (pte_t *ptep,pte_t entry) +{ +unsigned long set =pte_val (entry) & + (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC); +unsigned long clr = ~pte_val (entry) & _PAGE_RO; + +pte_update (ptep, clr, set); +} + +#define __HAVE_ARCH_PTE_SAME +#define pte_same (A ,B ) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0) + +/* +* Note that on Book E processors, the pmd contains the kernel virtual +* (lowmem) address of the pte page. The physical address is less useful +* because everything runs with translation enabled (even the TLB miss +* handler). On everything else the pmd contains the physical address +* of the pte page. -- paulus +*/ +#ifndef CONFIG_BOOKE +#define pmd_page_vaddr (pmd) \ + ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK)) +#define pmd_page (pmd) \ + pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT) +#else +#define pmd_page_vaddr (pmd) \ + ((unsigned long) (pmd_val(pmd) & PAGE_MASK)) +#define pmd_page (pmd) \ + pfn_to_page((__pa(pmd_val(pmd)) >> PAGE_SHIFT)) +#endif + +/* to find an entry in a kernel page-table-directory */ +#define pgd_offset_k (address) pgd_offset(&init_mm, address) + +/* to find an entry in a page-table-directory */ +#define pgd_index (address) ((address) >> PGDIR_SHIFT) +#define pgd_offset (mm, address) ((mm)->pgd + pgd_index(address)) + +/* Find an entry in the third-level page table.. */ +#define pte_index (address) \ + (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) +#define pte_offset_kernel (dir, addr) \ + ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr)) +#define pte_offset_map (dir, addr) \ + ((pte_t *) kmap_atomic(pmd_page(*(dir))) + pte_index(addr)) +#define pte_unmap (pte) kunmap_atomic(pte) + +/* +* Encode and decode a swap entry. +* Note that the bits we use in a PTE for representing a swap entry +* must not include the _PAGE_PRESENT bit or the _PAGE_HASHPTE bit (if used). +* -- paulus +*/ +#define __swp_type (entry) ((entry).val & 0x1f) +#define __swp_offset (entry) ((entry).val >> 5) +#define __swp_entry (type, offset) ((swp_entry_t) { (type) | ((offset) << 5) }) +#define __pte_to_swp_entry (pte) ((swp_entry_t) { pte_val(pte) >> 3 }) +#define __swp_entry_to_pte (x) ((pte_t) { (x).val << 3 }) + +#ifndef CONFIG_PPC_4K_PAGES +void pgtable_cache_init (void ); +#else +/* +* No page table caches to initialise +*/ +#define pgtable_cache_init () do { } while (0) +#endif + +extern int get_pteptr (struct mm_struct *mm,unsigned long addr,pte_t **ptep, +pmd_t **pmdp); + +#endif /* !__ASSEMBLY__ */ + +#endif /* _ASM_POWERPC_PGTABLE_PPC32_H */
arch/powerpc/include/asm/book3s/64/pgtable.h new file +618 -0
618 lines not on this page · raw message
arch/powerpc/include/asm/book3s/pgtable.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _ASM_POWERPC_BOOK3S_PGTABLE_H +#define _ASM_POWERPC_BOOK3S_PGTABLE_H + +#ifdef CONFIG_PPC64 +#include <asm/book3s/64/pgtable.h> +#else +#include <asm/book3s/32/pgtable.h> +#endif + +#endif
arch/powerpc/include/asm/mmu-hash64.h +1 -1
@@ -20,7 +20,7 @@* need for various slices related matters. Note that this isn't the * complete pgtable.h but only a portion of it. */ -#include <asm/pgtable-ppc64.h> +#include <asm/book3s/64/pgtable.h> #include <asm/bug.h> #include <asm/processor.h>
arch/powerpc/include/asm/pgtable-ppc32.h +0 -2
@@ -115,8 +115,6 @@ extern int icache_44x_need_flush;#include <asm/pte-fsl-booke.h> #elif defined(CONFIG_8xx)#include <asm/pte-8xx.h> -#else /* CONFIG_6xx */ -#include <asm/book3s/32/hash.h> #endif /* And here we include common definitions */
arch/powerpc/include/asm/pgtable-ppc64.h +0 -4
@@ -97,11 +97,7 @@/* * Include the PTE bits definitions */ -#ifdef CONFIG_PPC_BOOK3S -#include <asm/book3s/64/hash.h> -#else #include <asm/pte-book3e.h> -#endif #include <asm/pte-common.h> #ifdef CONFIG_PPC_MM_SLICES
arch/powerpc/include/asm/pgtable.h +4 -0
@@ -13,11 +13,15 @@ struct mm_struct;#endif /* !__ASSEMBLY__ */ +#ifdef CONFIG_PPC_BOOK3S +#include <asm/book3s/pgtable.h> +#else #if defined(CONFIG_PPC64 )# include <asm/pgtable-ppc64.h> #else # include <asm/pgtable-ppc32.h> #endif +#endif /* !CONFIG_PPC_BOOK3S */ /* * We save the slot number & secondary bit in the second half of the
Signature · 1 line
2.5.0
PATCH v2 4/31 powerpc/mm: make a separate copy for book3s (part 2)
In reply to Aneesh Kumar K.VKeep it seperate to make rebasing easier
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 4 ++-- arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +2 -2
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC32_H -#define _ASM_POWERPC_PGTABLE_PPC32_H +#ifndef _ASM_POWERPC_BOOK3S_32_PGTABLE_H +#define _ASM_POWERPC_BOOK3S_32_PGTABLE_H#include <asm-generic/pgtable-nopmd.h>
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC64_H_ -#define _ASM_POWERPC_PGTABLE_PPC64_H_ +#ifndef _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ +#define _ASM_POWERPC_BOOK3S_64_PGTABLE_H_/* * This file contains the functions and defines necessary to modify and use * the ppc64 hashed page table.
@@ -615,4 +615,4 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,return true; }#endif /* __ASSEMBLY__ */ -#endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */ +#endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
Signature · 1 line
2.5.0
PATCH v2 5/31 powerpc/mm: Move hash specific pte width and other defines to book3s
In reply to Aneesh Kumar K.VThis further make a copy of pte defines to book3s/64/hash*.h. This remove the dependency on ppc64-4k.h and ppc64-64k.h
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 87 ++++++++++++++++++++++++++- arch/powerpc/include/asm/book3s/64/hash-64k.h | 46 +++++++++++++- arch/powerpc/include/asm/book3s/64/pgtable.h | 6 +- 3 files changed, 130 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +86 -1
@@ -1,4 +1,51 @@ -/* To be include by pgtable-hash64.h only */ +#ifndef _ASM_POWERPC_BOOK3S_64_HASH_4K_H +#define _ASM_POWERPC_BOOK3S_64_HASH_4K_H +/* +* Entries per page directory level. The PTE level must use a 64b record +* for each page table entry. The PMD and PGD level use a 32b record for +* each entry by assuming that each entry is page aligned. +*/ +#define PTE_INDEX_SIZE 9 +#define PMD_INDEX_SIZE 7 +#define PUD_INDEX_SIZE 9 +#define PGD_INDEX_SIZE 9 + +#ifndef __ASSEMBLY__ +#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_INDEX_SIZE) +#define PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE) +#define PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE) +#define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE) +#endif /* __ASSEMBLY__ */ + +#define PTRS_PER_PTE (1 << PTE_INDEX_SIZE) +#define PTRS_PER_PMD (1 << PMD_INDEX_SIZE) +#define PTRS_PER_PUD (1 << PUD_INDEX_SIZE) +#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE) + +/* PMD_SHIFT determines what a second-level page table entry can map */ +#define PMD_SHIFT (PAGE_SHIFT + PTE_INDEX_SIZE) +#define PMD_SIZE (1UL << PMD_SHIFT) +#define PMD_MASK (~(PMD_SIZE-1)) + +/* With 4k base page size, hugepage PTEs go at the PMD level */ +#define MIN_HUGEPTE_SHIFT PMD_SHIFT + +/* PUD_SHIFT determines what a third-level page table entry can map */ +#define PUD_SHIFT (PMD_SHIFT + PMD_INDEX_SIZE) +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE-1)) + +/* PGDIR_SHIFT determines what a fourth-level page table entry can map */ +#define PGDIR_SHIFT (PUD_SHIFT + PUD_INDEX_SIZE) +#define PGDIR_SIZE (1UL << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +/* Bits to mask out from a PMD to get to the PTE page */ +#define PMD_MASKED_BITS 0 +/* Bits to mask out from a PUD to get to the PMD page */ +#define PUD_MASKED_BITS 0 +/* Bits to mask out from a PGD to get to the PUD page */ +#define PGD_MASKED_BITS 0/* PTE bits */ #define _PAGE_HASHPTE 0x0400/* software: pte has an associated HPTE */
@@ -14,3 +61,41 @@/* shift to put page number into pte */ #define PTE_RPN_SHIFT (17) + +#ifndef __ASSEMBLY__ +/* +* 4-level page tables related bits +*/ + +#define pgd_none (pgd) (!pgd_val(pgd)) +#define pgd_bad (pgd) (pgd_val(pgd) == 0) +#define pgd_present (pgd) (pgd_val(pgd) != 0) +#define pgd_clear (pgdp) (pgd_val(*(pgdp)) = 0) +#define pgd_page_vaddr (pgd) (pgd_val(pgd) & ~PGD_MASKED_BITS) + +static inline pte_t pgd_pte (pgd_t pgd) +{ +return __pte (pgd_val (pgd)); +} + +static inline pgd_t pte_pgd (pte_t pte) +{ +return __pgd (pte_val (pte)); +} +extern struct page *pgd_page (pgd_t pgd); + +#define pud_offset (pgdp, addr) \ + (((pud_t *) pgd_page_vaddr(*(pgdp))) + \ + (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))) + +#define pud_ERROR (e) \ + pr_err("%s:%d: bad pud %08lx.\n", __FILE__, __LINE__, pud_val(e)) + +/* +* On all 4K setups, remap_4k_pfn() equates to remap_pfn_range() */ +#define remap_4k_pfn (vma, addr, pfn, prot) \ + remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) + +#endif /* !__ASSEMBLY__ */ + +#endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
arch/powerpc/include/asm/book3s/64/hash-64k.h +43 -3
59 lines not on this page · raw message
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -5
@@ -5,11 +5,7 @@* the ppc64 hashed page table. */ -#ifdef CONFIG_PPC_64K_PAGES -#include <asm/pgtable-ppc64-64k.h> -#else -#include <asm/pgtable-ppc64-4k.h> -#endif +#include <asm/book3s/64/hash.h> #include <asm/barrier.h> #define FIRST_USER_ADDRESS 0UL
Signature · 1 line
2.5.0
PATCH v2 6/31 powerpc/mm: Delete booke bits from book3s
In reply to Aneesh Kumar K.VWe also move __ASSEMBLY__ towards the end of header. This avoid having #ifndef __ASSEMBLY___ all over the header
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 93 +++++++--------------------- arch/powerpc/include/asm/book3s/64/pgtable.h | 88 ++++++++------------------ arch/powerpc/include/asm/book3s/pgtable.h | 1 + 3 files changed, 51 insertions(+), 131 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +24 -69
@@ -3,18 +3,10 @@#include <asm-generic/pgtable-nopmd.h> -#ifndef __ASSEMBLY__ -#include <linux/sched.h> -#include <linux/threads.h> -#include <asm/io.h> /* For sub-arch specific PPC_PIN_SIZE */ - -extern unsigned long ioremap_bot; - -#ifdef CONFIG_44x -extern int icache_44x_need_flush; -#endif +#include <asm/book3s/32/hash.h> -#endif /* __ASSEMBLY__ */ +/* And here we include common definitions */ +#include <asm/pte-common.h> /* * The normal case is that PTEs are 32-bits and we have a 1-page
@@ -31,28 +23,11 @@ extern int icache_44x_need_flush;#define PGDIR_SIZE (1UL << PGDIR_SHIFT)#define PGDIR_MASK (~(PGDIR_SIZE-1)) -/* -* entries per page directory level: our page-table tree is two-level, so -* we don't really have any PMD directory. -*/ -#ifndef __ASSEMBLY__ -#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_SHIFT) -#define PGD_TABLE_SIZE (sizeof(pgd_t) << (32 - PGDIR_SHIFT)) -#endif /* __ASSEMBLY__ */ -#define PTRS_PER_PTE (1 << PTE_SHIFT)#define PTRS_PER_PMD 1#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) -#define FIRST_USER_ADDRESS 0UL - -#define pte_ERROR (e) \ - pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \ - (unsigned long long)pte_val(e)) -#define pgd_ERROR (e) \ - pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) -/* * This is the bottom of the PKMAP area with HIGHMEM or an arbitrary * value (for now) on others, from where we can start layout kernel
@@ -100,30 +75,30 @@ extern int icache_44x_need_flush;#endif #define VMALLOC_END ioremap_bot +#ifndef __ASSEMBLY__ +#include <linux/sched.h> +#include <linux/threads.h> +#include <asm/io.h> /* For sub-arch specific PPC_PIN_SIZE */ + +extern unsigned long ioremap_bot; + +/* +* entries per page directory level: our page-table tree is two-level, so +* we don't really have any PMD directory. +*/ +#define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_SHIFT) +#define PGD_TABLE_SIZE (sizeof(pgd_t) << (32 - PGDIR_SHIFT)) + +#define pte_ERROR (e) \ + pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \ + (unsigned long long)pte_val(e)) +#define pgd_ERROR (e) \ + pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))/* * Bits in a linux-style PTE. These match the bits in the * (hardware-defined) PowerPC PTE as closely as possible. */ -#if defined(CONFIG_40x) -#include <asm/pte-40x.h> -#elif defined(CONFIG_44x) -#include <asm/pte-44x.h> -#elif defined(CONFIG_FSL_BOOKE ) && defined(CONFIG_PTE_64BIT ) -#include <asm/pte-book3e.h> -#elif defined(CONFIG_FSL_BOOKE ) -#include <asm/pte-fsl-booke.h> -#elif defined(CONFIG_8xx) -#include <asm/pte-8xx.h> -#else /* CONFIG_6xx */ -#include <asm/book3s/32/hash.h> -#endif - -/* And here we include common definitions */ -#include <asm/pte-common.h> - -#ifndef __ASSEMBLY__ -#define pte_clear (mm, addr, ptep) \ do { pte_update(ptep, ~_PAGE_HASHPTE, 0); } while (0)
@@ -167,7 +142,6 @@ static inline unsigned long pte_update(pte_t *p, unsigned long clr, unsigned long set) { -#ifdef PTE_ATOMIC_UPDATES unsigned long old, tmp; __asm__ __volatile__("\
@@ -180,15 +154,7 @@ static inline unsigned long pte_update(pte_t *p, : "=&r" (old), "=&r" (tmp), "=m" (*p) : "r" (p), "r" (clr), "r" (set), "m" (*p) : "cc" ); -#else /* PTE_ATOMIC_UPDATES */ -unsigned long old =pte_val (*p); - *p =__pte ((old & ~clr) | set); -#endif /* !PTE_ATOMIC_UPDATES */ - -#ifdef CONFIG_44x -if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) - icache_44x_need_flush =1 ; -#endif + return old; }#else /* CONFIG_PTE_64BIT */
@@ -196,7 +162,6 @@ static inline unsigned long long pte_update(pte_t *p, unsigned long clr, unsigned long set) { -#ifdef PTE_ATOMIC_UPDATES unsigned long long old;unsigned long tmp;
@@ -211,15 +176,7 @@ static inline unsigned long long pte_update(pte_t *p, : "=&r" (old), "=&r" (tmp), "=m" (*p) : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p) : "cc" ); -#else /* PTE_ATOMIC_UPDATES */ -unsigned long long old =pte_val (*p); - *p =__pte ((old & ~(unsigned long long )clr) | set); -#endif /* !PTE_ATOMIC_UPDATES */ - -#ifdef CONFIG_44x -if ((old & _PAGE_USER) && (old & _PAGE_EXEC)) - icache_44x_need_flush =1 ; -#endif + return old; }#endif /* CONFIG_PTE_64BIT */
@@ -233,12 +190,10 @@ static inline int __ptep_test_and_clear_young(unsigned int context, unsigned lon {unsigned long old; old =pte_update (ptep, _PAGE_ACCESSED,0 ); -#if _PAGE_HASHPTE !=0 if (old & _PAGE_HASHPTE) {unsigned long ptephys =__pa (ptep) &PAGE_MASK ;flush_hash_pages (context, addr, ptephys,1 ); } -#endif return (old & _PAGE_ACCESSED) !=0 ; }#define ptep_test_and_clear_young (__vma, __addr, __ptep) \
arch/powerpc/include/asm/book3s/64/pgtable.h +26 -62
176 lines not on this page · raw message
arch/powerpc/include/asm/book3s/pgtable.h +1 -0
@@ -7,4 +7,5 @@#include <asm/book3s/32/pgtable.h> #endif +#define FIRST_USER_ADDRESS 0UL#endif
Signature · 1 line
2.5.0
PATCH v2 7/31 powerpc/mm: Don't have generic headers introduce functions touching pte bits
In reply to Aneesh Kumar K.VWe are going to drop pte_common.h in the later patch. The idea is to enable hash code not require to define all PTE bits. Having PTE bits defined in pte_common.h made the code unnecessarily complex.
--- arch/powerpc/include/asm/book3s/pgtable.h | 176 ++++++++++++++++++++++++++ arch/powerpc/include/asm/pgtable-book3e.h | 199 ++++++++++++++++++++++++++++++ arch/powerpc/include/asm/pgtable.h | 192 +--------------------------- 3 files changed, 376 insertions(+), 191 deletions(-) create mode 100644 arch/powerpc/include/asm/pgtable-book3e.h
arch/powerpc/include/asm/book3s/pgtable.h +176 -0
@@ -8,4 +8,180 @@#endif #define FIRST_USER_ADDRESS 0UL +#ifndef __ASSEMBLY__ + +/* Generic accessors to PTE bits */ +static inline int pte_write (pte_t pte) +{ +return (pte_val (pte) & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO; +} +static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; } +static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } +static inline int pte_special (pte_t pte) {return pte_val (pte) & _PAGE_SPECIAL; } +static inline int pte_none (pte_t pte) {return (pte_val (pte) & ~_PTE_NONE_MASK) ==0 ; } +static inline pgprot_t pte_pgprot (pte_t pte) {return __pgprot (pte_val (pte) &PAGE_PROT_BITS ); } + +#ifdef CONFIG_NUMA_BALANCING +/* +* These work without NUMA balancing but the kernel does not care. See the +* comment in include/asm-generic/pgtable.h . On powerpc, this will only +* work for user pages and always return true for kernel pages. +*/ +static inline int pte_protnone (pte_t pte) +{ +return (pte_val (pte) & + (_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT; +} + +static inline int pmd_protnone (pmd_t pmd) +{ +return pte_protnone (pmd_pte (pmd)); +} +#endif /* CONFIG_NUMA_BALANCING */ + +static inline int pte_present (pte_t pte) +{ +return pte_val (pte) & _PAGE_PRESENT; +} + +/* Conversion functions: convert a page and protection to a page entry, +* and a page entry and page directory to the page they refer to. +* +* Even if PTEs can be unsigned long long, a PFN is always an unsigned +* long for now. +*/ +static inline pte_t pfn_pte (unsigned long pfn,pgprot_t pgprot) { +return __pte (((pte_basic_t)(pfn) <<PTE_RPN_SHIFT ) | +pgprot_val (pgprot)); } +static inline unsigned long pte_pfn (pte_t pte) { +return pte_val (pte) >>PTE_RPN_SHIFT ; } + +/* Generic modifiers for PTE bits */ +static inline pte_t pte_wrprotect (pte_t pte) { +pte_val (pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); +pte_val (pte) |= _PAGE_RO;return pte; } +static inline pte_t pte_mkclean (pte_t pte) { +pte_val (pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE);return pte; } +static inline pte_t pte_mkold (pte_t pte) { +pte_val (pte) &= ~_PAGE_ACCESSED;return pte; } +static inline pte_t pte_mkwrite (pte_t pte) { +pte_val (pte) &= ~_PAGE_RO; +pte_val (pte) |= _PAGE_RW;return pte; } +static inline pte_t pte_mkdirty (pte_t pte) { +pte_val (pte) |= _PAGE_DIRTY;return pte; } +static inline pte_t pte_mkyoung (pte_t pte) { +pte_val (pte) |= _PAGE_ACCESSED;return pte; } +static inline pte_t pte_mkspecial (pte_t pte) { +pte_val (pte) |= _PAGE_SPECIAL;return pte; } +static inline pte_t pte_mkhuge (pte_t pte) { +return pte; } +static inline pte_t pte_modify (pte_t pte,pgprot_t newprot) +{ +pte_val (pte) = (pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot); +return pte; +} + + +/* Insert a PTE, top-level function is out of line. It uses an inline +* low level function in the respective pgtable-* files +*/ +extern void set_pte_at (struct mm_struct *mm,unsigned long addr,pte_t *ptep, +pte_t pte); + +/* This low level function performs the actual PTE insertion +* Setting the PTE depends on the MMU type and other factors. It's +* an horrible mess that I'm not going to try to clean up now but +* I'm keeping it in one place rather than spread around +*/ +static inline void __set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,int percpu) +{ +#if defined(CONFIG_PPC_STD_MMU_32 ) && defined(CONFIG_SMP ) && !defined(CONFIG_PTE_64BIT ) +/* First case is 32-bit Hash MMU in SMP mode with 32-bit PTEs. We use the +* helper pte_update() which does an atomic update. We need to do that +* because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a +* per-CPU PTE such as a kmap_atomic, we do a simple update preserving +* the hash bits instead (ie, same as the non-SMP case) +*/ +if (percpu) + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); +else +pte_update (ptep, ~_PAGE_HASHPTE,pte_val (pte)); + +#elif defined(CONFIG_PPC32 ) && defined(CONFIG_PTE_64BIT ) +/* Second case is 32-bit with 64-bit PTE. In this case, we +* can just store as long as we do the two halves in the right order +* with a barrier in between. This is possible because we take care, +* in the hash code, to pre-invalidate if the PTE was already hashed, +* which synchronizes us with any concurrent invalidation. +* In the percpu case, we also fallback to the simple update preserving +* the hash bits +*/ +if (percpu) { + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); +return ; + } +if (pte_val (*ptep) & _PAGE_HASHPTE) +flush_hash_entry (mm, ptep, addr); + __asm__ __volatile__("\ +stw%U0%X0 %2,%0\n\ +eieio\n\ +stw%U0%X0 %L2,%1" + :"=m" (*ptep),"=m" (*((unsigned char *)ptep+4 )) + :"r" (pte) :"memory" ); + +#elif defined(CONFIG_PPC_STD_MMU_32 ) +/* Third case is 32-bit hash table in UP mode, we need to preserve +* the _PAGE_HASHPTE bit since we may not have invalidated the previous +* translation in the hash yet (done in a subsequent flush_tlb_xxx()) +* and see we need to keep track that this PTE needs invalidating +*/ + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); + +#else +/* Anything else just stores the PTE normally. That covers all 64-bit +* cases, and 32-bit non-hash with 32-bit PTEs. +*/ + *ptep = pte; +#endif +} + + +#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS +extern int ptep_set_access_flags (struct vm_area_struct *vma,unsigned long address, +pte_t *ptep,pte_t entry,int dirty); + +/* +* Macro to mark a page protection value as "uncacheable". +*/ + +#define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \ + _PAGE_WRITETHRU) + +#define pgprot_noncached (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ + _PAGE_NO_CACHE | _PAGE_GUARDED)) + +#define pgprot_noncached_wc (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ + _PAGE_NO_CACHE)) + +#define pgprot_cached (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ + _PAGE_COHERENT)) + +#define pgprot_cached_wthru (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ + _PAGE_COHERENT | _PAGE_WRITETHRU)) + +#define pgprot_cached_noncoherent (prot) \ + (__pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL)) + +#define pgprot_writecombine pgprot_noncached_wc + +struct file ; +extern pgprot_t phys_mem_access_prot (struct file *file,unsigned long pfn, +unsigned long size,pgprot_t vma_prot); +#define __HAVE_PHYS_MEM_ACCESS_PROT + +#endif /* __ASSEMBLY__ */ #endif
arch/powerpc/include/asm/pgtable-book3e.h new file +199 -0
199 lines not on this page · raw message
arch/powerpc/include/asm/pgtable.h +1 -191
217 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 8/31 powerpc/mm: Drop pte-common.h from BOOK3S 64
In reply to Aneesh Kumar K.VWe copy only needed PTE bits define from pte-common.h to respective hash related header. This should greatly simply later patches in which we are going to change the pte format for hash config
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 1 + arch/powerpc/include/asm/book3s/64/hash.h | 2 + arch/powerpc/include/asm/book3s/64/pgtable.h | 106 ++++++++++++++++++++++++++- arch/powerpc/include/asm/book3s/pgtable.h | 16 ++-- 4 files changed, 113 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +1 -0
@@ -62,6 +62,7 @@/* shift to put page number into pte */ #define PTE_RPN_SHIFT (17) +#define _PAGE_4K_PFN 0#ifndef __ASSEMBLY__/* * 4-level page tables related bits
arch/powerpc/include/asm/book3s/64/hash.h +2 -0
@@ -20,6 +20,7 @@#define _PAGE_EXEC 0x0004/* No execute on POWER4 and newer (we invert) */ #define _PAGE_GUARDED 0x0008/* We can derive Memory coherence from _PAGE_NO_CACHE */ +#define _PAGE_COHERENT 0x0#define _PAGE_NO_CACHE 0x0020/* I: cache inhibit */ #define _PAGE_WRITETHRU 0x0040/* W: cache write-through */ #define _PAGE_DIRTY 0x0080/* C: page changed */
@@ -30,6 +31,7 @@/* No separate kernel read-only */ #define _PAGE_KERNEL_RW (_PAGE_RW | _PAGE_DIRTY)/* user access blocked by key */ #define _PAGE_KERNEL_RO _PAGE_KERNEL_RW +#define _PAGE_KERNEL_RWX (_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)/* Strong Access Ordering */ #define _PAGE_SAO (_PAGE_WRITETHRU | _PAGE_NO_CACHE | _PAGE_COHERENT)
arch/powerpc/include/asm/book3s/64/pgtable.h +103 -3
114 lines not on this page · raw message
arch/powerpc/include/asm/book3s/pgtable.h +7 -9
@@ -11,10 +11,7 @@#ifndef __ASSEMBLY__/* Generic accessors to PTE bits */ -static inline int pte_write (pte_t pte) -{ -return (pte_val (pte) & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO; -} +static inline int pte_write (pte_t pte) {return !!(pte_val (pte) & _PAGE_RW);}static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; }static inline int pte_special (pte_t pte) {return pte_val (pte) & _PAGE_SPECIAL; }
@@ -57,15 +54,16 @@ static inline unsigned long pte_pfn(pte_t pte) {return pte_val (pte) >>PTE_RPN_SHIFT ; }/* Generic modifiers for PTE bits */ -static inline pte_t pte_wrprotect (pte_t pte) { -pte_val (pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); -pte_val (pte) |= _PAGE_RO;return pte; } +static inline pte_t pte_wrprotect (pte_t pte) +{ +pte_val (pte) &= ~_PAGE_RW; +return pte; +}static inline pte_t pte_mkclean (pte_t pte) { -pte_val (pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE);return pte; } +pte_val (pte) &= ~_PAGE_DIRTY;return pte; }static inline pte_t pte_mkold (pte_t pte) {pte_val (pte) &= ~_PAGE_ACCESSED;return pte; }static inline pte_t pte_mkwrite (pte_t pte) { -pte_val (pte) &= ~_PAGE_RO;pte_val (pte) |= _PAGE_RW;return pte; }static inline pte_t pte_mkdirty (pte_t pte) {pte_val (pte) |= _PAGE_DIRTY;return pte; }
Signature · 1 line
2.5.0
PATCH v2 9/31 powerpc/mm: Don't use pte_val as lvalue
In reply to Aneesh Kumar K.VWe also convert few #define to static inline in this patch for better type checking
--- arch/powerpc/include/asm/book3s/pgtable.h | 112 ++++++++++++++++++++---------- arch/powerpc/include/asm/page.h | 10 ++- arch/powerpc/include/asm/pgtable-book3e.h | 68 ++++++++++++------ 3 files changed, 133 insertions(+), 57 deletions(-)
arch/powerpc/include/asm/book3s/pgtable.h +77 -35
@@ -12,9 +12,9 @@/* Generic accessors to PTE bits */ static inline int pte_write (pte_t pte) {return !!(pte_val (pte) & _PAGE_RW);} -static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; } -static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; } -static inline int pte_special (pte_t pte) {return pte_val (pte) & _PAGE_SPECIAL; } +static inline int pte_dirty (pte_t pte) {return !!(pte_val (pte) & _PAGE_DIRTY); } +static inline int pte_young (pte_t pte) {return !!(pte_val (pte) & _PAGE_ACCESSED); } +static inline int pte_special (pte_t pte) {return !!(pte_val (pte) & _PAGE_SPECIAL); }static inline int pte_none (pte_t pte) {return (pte_val (pte) & ~_PTE_NONE_MASK) ==0 ; }static inline pgprot_t pte_pgprot (pte_t pte) {return __pgprot (pte_val (pte) &PAGE_PROT_BITS ); }
@@ -47,36 +47,61 @@ static inline int pte_present(pte_t pte)* Even if PTEs can be unsigned long long, a PFN is always an unsigned * long for now. */ -static inline pte_t pfn_pte (unsigned long pfn,pgprot_t pgprot) { +static inline pte_t pfn_pte (unsigned long pfn,pgprot_t pgprot) +{return __pte (((pte_basic_t)(pfn) <<PTE_RPN_SHIFT ) | -pgprot_val (pgprot)); } -static inline unsigned long pte_pfn (pte_t pte) { -return pte_val (pte) >>PTE_RPN_SHIFT ; } +pgprot_val (pgprot)); +} + +static inline unsigned long pte_pfn (pte_t pte) +{ +return pte_val (pte) >>PTE_RPN_SHIFT ; +}/* Generic modifiers for PTE bits */ static inline pte_t pte_wrprotect (pte_t pte) { -pte_val (pte) &= ~_PAGE_RW; +return __pte (pte_val (pte) & ~_PAGE_RW); +} + +static inline pte_t pte_mkclean (pte_t pte) +{ +return __pte (pte_val (pte) & ~_PAGE_DIRTY); +} + +static inline pte_t pte_mkold (pte_t pte) +{ +return __pte (pte_val (pte) & ~_PAGE_ACCESSED); +} + +static inline pte_t pte_mkwrite (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_RW); +} + +static inline pte_t pte_mkdirty (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_DIRTY); +} + +static inline pte_t pte_mkyoung (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_ACCESSED); +} + +static inline pte_t pte_mkspecial (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_SPECIAL); +} + +static inline pte_t pte_mkhuge (pte_t pte) +{return pte; } -static inline pte_t pte_mkclean (pte_t pte) { -pte_val (pte) &= ~_PAGE_DIRTY;return pte; } -static inline pte_t pte_mkold (pte_t pte) { -pte_val (pte) &= ~_PAGE_ACCESSED;return pte; } -static inline pte_t pte_mkwrite (pte_t pte) { -pte_val (pte) |= _PAGE_RW;return pte; } -static inline pte_t pte_mkdirty (pte_t pte) { -pte_val (pte) |= _PAGE_DIRTY;return pte; } -static inline pte_t pte_mkyoung (pte_t pte) { -pte_val (pte) |= _PAGE_ACCESSED;return pte; } -static inline pte_t pte_mkspecial (pte_t pte) { -pte_val (pte) |= _PAGE_SPECIAL;return pte; } -static inline pte_t pte_mkhuge (pte_t pte) { -return pte; } +static inline pte_t pte_modify (pte_t pte,pgprot_t newprot) { -pte_val (pte) = (pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot); -return pte; +return __pte ((pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot)); }
@@ -159,22 +184,39 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addre#define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \ _PAGE_WRITETHRU) -#define pgprot_noncached (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ - _PAGE_NO_CACHE | _PAGE_GUARDED)) +static inline pgprot_t pgprot_noncached (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_NO_CACHE | _PAGE_GUARDED); +} -#define pgprot_noncached_wc (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ - _PAGE_NO_CACHE)) +static inline pgprot_t pgprot_noncached_wc (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_NO_CACHE); +} -#define pgprot_cached (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ - _PAGE_COHERENT)) +static inline pgprot_t pgprot_cached (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_COHERENT); +} -#define pgprot_cached_wthru (prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ - _PAGE_COHERENT | _PAGE_WRITETHRU)) +static inline pgprot_t pgprot_cached_wthru (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_COHERENT | _PAGE_WRITETHRU); +} -#define pgprot_cached_noncoherent (prot) \ - (__pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL)) +static inline pgprot_t pgprot_cached_noncoherent (pgprot_t prot) +{ +return __pgprot (pgprot_val (prot) & ~_PAGE_CACHE_CTL); +} -#define pgprot_writecombine pgprot_noncached_wc +static inline pgprot_t pgprot_writecombine (pgprot_t prot) +{ +return pgprot_noncached_wc (prot); +}struct file ; extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
arch/powerpc/include/asm/page.h +8 -2
@@ -283,8 +283,11 @@ extern long long virt_phys_offset;/* PTE level */ typedef struct {pte_basic_t pte; }pte_t ; -#define pte_val (x) ((x).pte)#define __pte (x) ((pte_t) { (x) }) +static inline pte_basic_t pte_val (pte_t x) +{ +return x.pte; +}/* 64k pages additionally define a bigger "real PTE" type that gathers * the "second half" part of the PTE for pseudo 64k pages
@@ -326,8 +329,11 @@ typedef struct { unsigned long pgprot; } pgprot_t;*/ typedef pte_basic_t pte_t ; -#define pte_val (x) (x)#define __pte (x) (x) +static inline pte_basic_t pte_val (pte_t pte) +{ +return pte; +}#if defined(CONFIG_PPC_64K_PAGES ) && defined(CONFIG_PPC_STD_MMU_64 )typedef struct {pte_t pte;unsigned long hidx; }real_pte_t ;
arch/powerpc/include/asm/pgtable-book3e.h +48 -20
78 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 10/31 powerpc/mm: Don't use pmd_val, pud_val and pgd_val as lvalue
In reply to Aneesh Kumar K.VWe convert them static inline function here as we did with pte_val in the previous patch
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 6 ++++- arch/powerpc/include/asm/book3s/64/hash-4k.h | 6 ++++- arch/powerpc/include/asm/book3s/64/pgtable.h | 36 +++++++++++++++++++++------- arch/powerpc/include/asm/page.h | 34 +++++++++++++++++++------- arch/powerpc/include/asm/pgalloc-32.h | 34 +++++++++++++++++++------- arch/powerpc/include/asm/pgalloc-64.h | 17 +++++++++---- arch/powerpc/include/asm/pgtable-ppc32.h | 7 +++++- arch/powerpc/include/asm/pgtable-ppc64-4k.h | 6 ++++- arch/powerpc/include/asm/pgtable-ppc64.h | 36 +++++++++++++++++++++------- arch/powerpc/mm/pgtable_64.c | 19 +++++++-------- 10 files changed, 149 insertions(+), 52 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +5 -1
@@ -105,7 +105,11 @@ extern unsigned long ioremap_bot;#define pmd_none (pmd) (!pmd_val(pmd))#define pmd_bad (pmd) (pmd_val(pmd) & _PMD_BAD)#define pmd_present (pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK) -#define pmd_clear (pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) +static inline void pmd_clear (pmd_t *pmdp) +{ + *pmdp =__pmd (0 ); +} +/* * When flushing the tlb entry for a page, we also need to flush the hash
arch/powerpc/include/asm/book3s/64/hash-4k.h +5 -1
@@ -71,9 +71,13 @@#define pgd_none (pgd) (!pgd_val(pgd))#define pgd_bad (pgd) (pgd_val(pgd) == 0)#define pgd_present (pgd) (pgd_val(pgd) != 0) -#define pgd_clear (pgdp) (pgd_val(*(pgdp)) = 0)#define pgd_page_vaddr (pgd) (pgd_val(pgd) & ~PGD_MASKED_BITS) +static inline void pgd_clear (pgd_t *pgdp) +{ + *pgdp =__pgd (0 ); +} +static inline pte_t pgd_pte (pgd_t pgd) {return __pte (pgd_val (pgd));
arch/powerpc/include/asm/book3s/64/pgtable.h +27 -9
@@ -240,21 +240,38 @@#define PMD_BAD_BITS (PTE_TABLE_SIZE-1)#define PUD_BAD_BITS (PMD_TABLE_SIZE-1) -#define pmd_set (pmdp, pmdval) (pmd_val(*(pmdp)) = (pmdval)) +static inline void pmd_set (pmd_t *pmdp,unsigned long val) +{ + *pmdp =__pmd (val); +} + +static inline void pmd_clear (pmd_t *pmdp) +{ + *pmdp =__pmd (0 ); +} + +#define pmd_none (pmd) (!pmd_val(pmd))#define pmd_bad (pmd) (!is_kernel_addr(pmd_val(pmd)) \ || (pmd_val(pmd) & PMD_BAD_BITS))#define pmd_present (pmd) (!pmd_none(pmd)) -#define pmd_clear (pmdp) (pmd_val(*(pmdp)) = 0)#define pmd_page_vaddr (pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS)extern struct page *pmd_page (pmd_t pmd); -#define pud_set (pudp, pudval) (pud_val(*(pudp)) = (pudval)) +static inline void pud_set (pud_t *pudp,unsigned long val) +{ + *pudp =__pud (val); +} + +static inline void pud_clear (pud_t *pudp) +{ + *pudp =__pud (0 ); +} +#define pud_none (pud) (!pud_val(pud))#define pud_bad (pud) (!is_kernel_addr(pud_val(pud)) \ || (pud_val(pud) & PUD_BAD_BITS))#define pud_present (pud) (pud_val(pud) != 0) -#define pud_clear (pudp) (pud_val(*(pudp)) = 0)#define pud_page_vaddr (pud) (pud_val(pud) & ~PUD_MASKED_BITS)extern struct page *pud_page (pud_t pud);
@@ -269,8 +286,11 @@ static inline pud_t pte_pud(pte_t pte)return __pud (pte_val (pte)); }#define pud_write (pud) pte_write(pud_pte(pud)) -#define pgd_set (pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})#define pgd_write (pgd) pte_write(pgd_pte(pgd)) +static inline void pgd_set (pgd_t *pgdp,unsigned long val) +{ + *pgdp =__pgd (val); +}/* * Find an entry in a page-table-directory. We combine the address region
@@ -584,14 +604,12 @@ static inline pmd_t pmd_mkhuge(pmd_t pmd)static inline pmd_t pmd_mknotpresent (pmd_t pmd) { -pmd_val (pmd) &= ~_PAGE_PRESENT; -return pmd; +return __pmd (pmd_val (pmd) & ~_PAGE_PRESENT); }static inline pmd_t pmd_mksplitting (pmd_t pmd) { -pmd_val (pmd) |= _PAGE_SPLITTING; -return pmd; +return __pmd (pmd_val (pmd) | _PAGE_SPLITTING); }#define __HAVE_ARCH_PMD_SAME
arch/powerpc/include/asm/page.h +26 -8
@@ -301,21 +301,30 @@ typedef struct { pte_t pte; } real_pte_t;/* PMD level */ #ifdef CONFIG_PPC64 typedef struct {unsigned long pmd; }pmd_t ; -#define pmd_val (x) ((x).pmd)#define __pmd (x) ((pmd_t) { (x) }) +static inline unsigned long pmd_val (pmd_t x) +{ +return x.pmd; +}/* PUD level exusts only on 4k pages */ #ifndef CONFIG_PPC_64K_PAGES typedef struct {unsigned long pud; }pud_t ; -#define pud_val (x) ((x).pud)#define __pud (x) ((pud_t) { (x) }) +static inline unsigned long pud_val (pud_t x) +{ +return x.pud; +}#endif /* !CONFIG_PPC_64K_PAGES */ #endif /* CONFIG_PPC64 */ /* PGD level */ typedef struct {unsigned long pgd; }pgd_t ; -#define pgd_val (x) ((x).pgd)#define __pgd (x) ((pgd_t) { (x) }) +static inline unsigned long pgd_val (pgd_t x) +{ +return x.pgd; +}/* Page protection bits */ typedef struct {unsigned long pgprot; }pgprot_t ;
@@ -344,22 +353,31 @@ typedef pte_t real_pte_t;#ifdef CONFIG_PPC64 typedef unsigned long pmd_t ; -#define pmd_val (x) (x)#define __pmd (x) (x) +static inline unsigned long pmd_val (pmd_t pmd) +{ +return pmd; +}#ifndef CONFIG_PPC_64K_PAGES typedef unsigned long pud_t ; -#define pud_val (x) (x)#define __pud (x) (x) +static inline unsigned long pud_val (pud_t pud) +{ +return pud; +}#endif /* !CONFIG_PPC_64K_PAGES */ #endif /* CONFIG_PPC64 */ typedef unsigned long pgd_t ; -#define pgd_val (x) (x) -#define pgprot_val (x) (x) +#define __pgd (x) (x) +static inline unsigned long pgd_val (pgd_t pgd) +{ +return pgd; +}typedef unsigned long pgprot_t ; -#define __pgd (x) (x) +#define pgprot_val (x) (x)#define __pgprot (x) (x)#endif
arch/powerpc/include/asm/pgalloc-32.h +26 -8
@@ -21,16 +21,34 @@ extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);/* #define pgd_populate(mm, pmd, pte) BUG() */ #ifndef CONFIG_BOOKE -#define pmd_populate_kernel (mm, pmd, pte) \ - (pmd_val(*(pmd)) = __pa(pte) | _PMD_PRESENT) -#define pmd_populate (mm, pmd, pte) \ - (pmd_val(*(pmd)) = (page_to_pfn(pte) << PAGE_SHIFT) | _PMD_PRESENT) + +static inline void pmd_populate_kernel (struct mm_struct *mm,pmd_t *pmdp, +pte_t *pte) +{ + *pmdp =__pmd (__pa (pte) | _PMD_PRESENT); +} + +static inline void pmd_populate (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pte_page) +{ + *pmdp =__pmd ((page_to_pfn (pte_page) <<PAGE_SHIFT ) | _PMD_PRESENT); +} +#define pmd_pgtable (pmd) pmd_page(pmd)#else -#define pmd_populate_kernel (mm, pmd, pte) \ - (pmd_val(*(pmd)) = (unsigned long)pte | _PMD_PRESENT) -#define pmd_populate (mm, pmd, pte) \ - (pmd_val(*(pmd)) = (unsigned long)lowmem_page_address(pte) | _PMD_PRESENT) + +static inline void pmd_populate_kernel (struct mm_struct *mm,pmd_t *pmdp, +pte_t *pte) +{ + *pmdp =__pmd ((unsigned long )pte | _PMD_PRESENT); +} + +static inline void pmd_populate (struct mm_struct *mm,pmd_t *pmdp, +pgtable_t pte_page) +{ + *pmdp =__pmd ((unsigned long )lowmem_page_address (pte_page) | _PMD_PRESENT); +} +#define pmd_pgtable (pmd) pmd_page(pmd)#endif
arch/powerpc/include/asm/pgalloc-64.h +13 -4
@@ -53,7 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)#ifndef CONFIG_PPC_64K_PAGES -#define pgd_populate (MM ,PGD ,PUD ) pgd_set(PGD, PUD) +#define pgd_populate (MM ,PGD ,PUD ) pgd_set(PGD, (unsigned long)PUD)static inline pud_t *pud_alloc_one (struct mm_struct *mm,unsigned long addr) {
@@ -71,9 +71,18 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)pud_set (pud, (unsigned long )pmd); } -#define pmd_populate (mm, pmd, pte_page) \ - pmd_populate_kernel(mm, pmd, page_address(pte_page)) -#define pmd_populate_kernel (mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte)) +static inline void pmd_populate_kernel (struct mm_struct *mm,pmd_t *pmd, +pte_t *pte) +{ +pmd_set (pmd, (unsigned long )pte); +} + +static inline void pmd_populate (struct mm_struct *mm,pmd_t *pmd, +pgtable_t pte_page) +{ +pmd_set (pmd, (unsigned long )page_address (pte_page)); +} +#define pmd_pgtable (pmd) pmd_page(pmd) static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
arch/powerpc/include/asm/pgtable-ppc32.h +6 -1
@@ -128,7 +128,12 @@ extern int icache_44x_need_flush;#define pmd_none (pmd) (!pmd_val(pmd))#define pmd_bad (pmd) (pmd_val(pmd) & _PMD_BAD)#define pmd_present (pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK) -#define pmd_clear (pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) +static inline void pmd_clear (pmd_t *pmdp) +{ + *pmdp =__pmd (0 ); +} + +/* * When flushing the tlb entry for a page, we also need to flush the hash
arch/powerpc/include/asm/pgtable-ppc64-4k.h +5 -1
@@ -55,11 +55,15 @@#define pgd_none (pgd) (!pgd_val(pgd))#define pgd_bad (pgd) (pgd_val(pgd) == 0)#define pgd_present (pgd) (pgd_val(pgd) != 0) -#define pgd_clear (pgdp) (pgd_val(*(pgdp)) = 0)#define pgd_page_vaddr (pgd) (pgd_val(pgd) & ~PGD_MASKED_BITS)#ifndef __ASSEMBLY__ +static inline void pgd_clear (pgd_t *pgdp) +{ + *pgdp =__pgd (0 ); +} +static inline pte_t pgd_pte (pgd_t pgd) {return __pte (pgd_val (pgd));
arch/powerpc/include/asm/pgtable-ppc64.h +27 -9
@@ -144,21 +144,37 @@#define PMD_BAD_BITS (PTE_TABLE_SIZE-1)#define PUD_BAD_BITS (PMD_TABLE_SIZE-1) -#define pmd_set (pmdp, pmdval) (pmd_val(*(pmdp)) = (pmdval)) +static inline void pmd_set (pmd_t *pmdp,unsigned long val) +{ + *pmdp =__pmd (val); +} + +static inline void pmd_clear (pmd_t *pmdp) +{ + *pmdp =__pmd (0 ); +} +#define pmd_none (pmd) (!pmd_val(pmd))#define pmd_bad (pmd) (!is_kernel_addr(pmd_val(pmd)) \ || (pmd_val(pmd) & PMD_BAD_BITS))#define pmd_present (pmd) (!pmd_none(pmd)) -#define pmd_clear (pmdp) (pmd_val(*(pmdp)) = 0)#define pmd_page_vaddr (pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS)extern struct page *pmd_page (pmd_t pmd); -#define pud_set (pudp, pudval) (pud_val(*(pudp)) = (pudval)) +static inline void pud_set (pud_t *pudp,unsigned long val) +{ + *pudp =__pud (val); +} + +static inline void pud_clear (pud_t *pudp) +{ + *pudp =__pud (0 ); +} +#define pud_none (pud) (!pud_val(pud))#define pud_bad (pud) (!is_kernel_addr(pud_val(pud)) \ || (pud_val(pud) & PUD_BAD_BITS))#define pud_present (pud) (pud_val(pud) != 0) -#define pud_clear (pudp) (pud_val(*(pudp)) = 0)#define pud_page_vaddr (pud) (pud_val(pud) & ~PUD_MASKED_BITS)extern struct page *pud_page (pud_t pud);
@@ -173,9 +189,13 @@ static inline pud_t pte_pud(pte_t pte)return __pud (pte_val (pte)); }#define pud_write (pud) pte_write(pud_pte(pud)) -#define pgd_set (pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})#define pgd_write (pgd) pte_write(pgd_pte(pgd)) +static inline void pgd_set (pgd_t *pgdp,unsigned long val) +{ + *pgdp =__pgd (val); +} +/* * Find an entry in a page-table-directory. We combine the address region * (the high order N bits) and the pgd portion of the address.
@@ -520,14 +540,12 @@ static inline pmd_t pmd_mkhuge(pmd_t pmd)static inline pmd_t pmd_mknotpresent (pmd_t pmd) { -pmd_val (pmd) &= ~_PAGE_PRESENT; -return pmd; +return __pmd (pmd_val (pmd) & ~_PAGE_PRESENT); }static inline pmd_t pmd_mksplitting (pmd_t pmd) { -pmd_val (pmd) |= _PAGE_SPLITTING; -return pmd; +return __pmd (pmd_val (pmd) | _PAGE_SPLITTING); }#define __HAVE_ARCH_PMD_SAME
arch/powerpc/mm/pgtable_64.c +9 -10
@@ -759,22 +759,20 @@ void hpte_do_hugepage_flush(struct mm_struct *mm, unsigned long addr,static pmd_t pmd_set_protbits (pmd_t pmd,pgprot_t pgprot) { -pmd_val (pmd) |=pgprot_val (pgprot); -return pmd; +return __pmd (pmd_val (pmd) |pgprot_val (pgprot)); }pmd_t pfn_pmd (unsigned long pfn,pgprot_t pgprot) { -pmd_t pmd; +unsigned long pmdv;/* * For a valid pte, we would have _PAGE_PRESENT always * set. We use this to check THP page at pmd level. * leaf pte for huge page, bottom two bits != 00 */ -pmd_val (pmd) = pfn <<PTE_RPN_SHIFT ; -pmd_val (pmd) |= _PAGE_THP_HUGE; - pmd =pmd_set_protbits (pmd, pgprot); -return pmd; + pmdv = pfn <<PTE_RPN_SHIFT ; + pmdv |= _PAGE_THP_HUGE; +return pmd_set_protbits (__pmd (pmdv), pgprot); }pmd_t mk_pmd (struct page *page,pgprot_t pgprot)
@@ -784,10 +782,11 @@ pmd_t mk_pmd(struct page *page, pgprot_t pgprot)pmd_t pmd_modify (pmd_t pmd,pgprot_t newprot) { +unsigned long pmdv; -pmd_val (pmd) &= _HPAGE_CHG_MASK; - pmd =pmd_set_protbits (pmd, newprot); -return pmd; + pmdv =pmd_val (pmd); + pmdv &= _HPAGE_CHG_MASK; +return pmd_set_protbits (__pmd (pmdv), newprot); }/*
Signature · 1 line
2.5.0
PATCH v2 11/31 powerpc/mm: Move hash64 PTE bits from book3s/64/pgtable.h to hash.h
In reply to Aneesh Kumar K.VThis enables us to keep hash64 related bits together, and makes it easy to follow.
--- arch/powerpc/include/asm/book3s/64/hash.h | 442 ++++++++++++++++++++++++++- arch/powerpc/include/asm/book3s/64/pgtable.h | 441 +------------------------- arch/powerpc/include/asm/pgtable.h | 6 - 3 files changed, 442 insertions(+), 447 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h +439 -3
@@ -2,6 +2,63 @@#define _ASM_POWERPC_BOOK3S_64_HASH_H#ifdef __KERNEL__ +#ifdef CONFIG_PPC_64K_PAGES +#include <asm/book3s/64/hash-64k.h> +#else +#include <asm/book3s/64/hash-4k.h> +#endif + +/* +* Size of EA range mapped by our pagetables. +*/ +#define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \ + PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT) +#define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE) + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define PMD_CACHE_INDEX (PMD_INDEX_SIZE + 1) +#else +#define PMD_CACHE_INDEX PMD_INDEX_SIZE +#endif +/* +* Define the address range of the kernel non-linear virtual area +*/ +#define KERN_VIRT_START ASM_CONST(0xD000000000000000) +#define KERN_VIRT_SIZE ASM_CONST(0x0000100000000000) + +/* +* The vmalloc space starts at the beginning of that region, and +* occupies half of it on hash CPUs and a quarter of it on Book3E +* (we keep a quarter for the virtual memmap) +*/ +#define VMALLOC_START KERN_VIRT_START +#define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1) +#define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE) + +/* +* Region IDs +*/ +#define REGION_SHIFT 60UL +#define REGION_MASK (0xfUL << REGION_SHIFT) +#define REGION_ID (ea) (((unsigned long)(ea)) >> REGION_SHIFT) + +#define VMALLOC_REGION_ID (REGION_ID(VMALLOC_START)) +#define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET)) +#define VMEMMAP_REGION_ID (0xfUL)/* Server only */ +#define USER_REGION_ID (0UL) + +/* +* Defines the address of the vmemap area, in its own region on +* hash table CPUs. +*/ +#define VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT) + +#ifdef CONFIG_PPC_MM_SLICES +#define HAVE_ARCH_UNMAPPED_AREA +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN +#else +#error "Hash Config needs mm slice enabled" +#endif /* CONFIG_PPC_MM_SLICES */ /* * Common bits between 4K and 64K pages in a linux-style PTE. * These match the bits in the (hardware-defined) PowerPC PTE as closely
@@ -46,11 +103,390 @@/* Hash table based platforms need atomic updates of the linux PTE */ #define PTE_ATOMIC_UPDATES 1 -#ifdef CONFIG_PPC_64K_PAGES -#include <asm/book3s/64/hash-64k.h> +/* +* THP pages can't be special. So use the _PAGE_SPECIAL +*/ +#define _PAGE_SPLITTING _PAGE_SPECIAL + +/* +* We need to differentiate between explicit huge page and THP huge +* page, since THP huge page also need to track real subpage details +*/ +#define _PAGE_THP_HUGE _PAGE_4K_PFN + +/* +* set of bits not changed in pmd_modify. +*/ +#define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | \ + _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SPLITTING | \ + _PAGE_THP_HUGE) +#define _PTE_NONE_MASK _PAGE_HPTEFLAGS +/* +* The mask convered by the RPN must be a ULL on 32-bit platforms with +* 64-bit PTEs +* FIXME!! double check the RPN_MAX May be not used +*/ +//#define PTE_RPN_MAX (1UL << (32 - PTE_RPN_SHIFT)) +#define PTE_RPN_MASK (~((1UL << PTE_RPN_SHIFT) - 1)) +/* +* _PAGE_CHG_MASK masks of bits that are to be preserved across +* pgprot changes +*/ +#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ + _PAGE_ACCESSED | _PAGE_SPECIAL) +/* +* Mask of bits returned by pte_pgprot() +*/ +#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \ + _PAGE_WRITETHRU | _PAGE_4K_PFN | \ + _PAGE_USER | _PAGE_ACCESSED | \ + _PAGE_RW | _PAGE_DIRTY | _PAGE_EXEC) +/* +* We define 2 sets of base prot bits, one for basic pages (ie, +* cacheable kernel and user pages) and one for non cacheable +* pages. We always set _PAGE_COHERENT when SMP is enabled or +* the processor might need it for DMA coherency. +*/ +#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE) +#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT) + +/* Permission masks used to generate the __P and __S table, +* +* Note:__pgprot is defined in arch/powerpc/include/asm/page.h +* +* Write permissions imply read permissions for now (we could make write-only +* pages on BookE but we don't bother for now). Execute permission control is +* possible on platforms that define _PAGE_EXEC +* +* Note due to the way vm flags are laid out, the bits are XWR +*/ +#define PAGE_NONE __pgprot(_PAGE_BASE) +#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) +#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | \ + _PAGE_EXEC) +#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER ) +#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) +#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER ) +#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) + +#define __P000 PAGE_NONE +#define __P001 PAGE_READONLY +#define __P010 PAGE_COPY +#define __P011 PAGE_COPY +#define __P100 PAGE_READONLY_X +#define __P101 PAGE_READONLY_X +#define __P110 PAGE_COPY_X +#define __P111 PAGE_COPY_X + +#define __S000 PAGE_NONE +#define __S001 PAGE_READONLY +#define __S010 PAGE_SHARED +#define __S011 PAGE_SHARED +#define __S100 PAGE_READONLY_X +#define __S101 PAGE_READONLY_X +#define __S110 PAGE_SHARED_X +#define __S111 PAGE_SHARED_X + +/* Permission masks used for kernel mappings */ +#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW) +#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ + _PAGE_NO_CACHE) +#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \ + _PAGE_NO_CACHE | _PAGE_GUARDED) +#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RWX) +#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO) +#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_ROX) + +/* Protection used for kernel text. We want the debuggers to be able to +* set breakpoints anywhere, so don't write protect the kernel text +* on platforms where such control is possible. +*/ +#if defined(CONFIG_KGDB ) || defined(CONFIG_XMON ) || defined(CONFIG_BDI_SWITCH ) ||\ + defined(CONFIG_KPROBES ) || defined(CONFIG_DYNAMIC_FTRACE ) +#define PAGE_KERNEL_TEXT PAGE_KERNEL_X#else -#include <asm/book3s/64/hash-4k.h> +#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX +#endif + +/* Make modules code happy. We don't set RO yet */ +#define PAGE_KERNEL_EXEC PAGE_KERNEL_X +#define PAGE_AGP (PAGE_KERNEL_NC) + +#define PMD_BAD_BITS (PTE_TABLE_SIZE-1) +#define PUD_BAD_BITS (PMD_TABLE_SIZE-1) +/* +* We save the slot number & secondary bit in the second half of the +* PTE page. We use the 8 bytes per each pte entry. +*/ +#define PTE_PAGE_HIDX_OFFSET (PTRS_PER_PTE * 8) + +#ifndef __ASSEMBLY__ +#define pmd_bad (pmd) (!is_kernel_addr(pmd_val(pmd)) \ + || (pmd_val(pmd) & PMD_BAD_BITS)) +#define pmd_page_vaddr (pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS) + +#define pud_bad (pud) (!is_kernel_addr(pud_val(pud)) \ + || (pud_val(pud) & PUD_BAD_BITS)) +#define pud_page_vaddr (pud) (pud_val(pud) & ~PUD_MASKED_BITS) + +#define pgd_index (address) (((address) >> (PGDIR_SHIFT)) & (PTRS_PER_PGD - 1)) +#define pmd_index (address) (((address) >> (PMD_SHIFT)) & (PTRS_PER_PMD - 1)) +#define pte_index (address) (((address) >> (PAGE_SHIFT)) & (PTRS_PER_PTE - 1)) + +extern void hpte_need_flush (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long pte,int huge); +extern void hpte_do_hugepage_flush (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp,unsigned long old_pmd); +extern unsigned long pmd_hugepage_update (struct mm_struct *mm, +unsigned long addr, +pmd_t *pmdp, +unsigned long clr, +unsigned long set); +/* Atomic PTE updates */ +static inline unsigned long pte_update (struct mm_struct *mm, +unsigned long addr, +pte_t *ptep,unsigned long clr, +unsigned long set, +int huge) +{ +unsigned long old, tmp; + + __asm__ __volatile__( +"1: ldarx %0,0,%3 # pte_update\n\ +andi. %1,%0,%6\n\ +bne- 1b \n\ +andc %1,%0,%4 \n\ +or %1,%1,%7\n\ +stdcx. %1,0,%3 \n\ +bne- 1b" + :"=&r" (old),"=&r" (tmp),"=m" (*ptep) + :"r" (ptep),"r" (clr),"m" (*ptep),"i" (_PAGE_BUSY),"r" (set) + :"cc" ); +/* huge pages use the old page table lock */ +if (!huge) +assert_pte_locked (mm, addr); + +if (old & _PAGE_HASHPTE) +hpte_need_flush (mm, addr, ptep, old, huge); + +return old; +} + +static inline int __ptep_test_and_clear_young (struct mm_struct *mm, +unsigned long addr,pte_t *ptep) +{ +unsigned long old; + +if ((pte_val (*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 ) +return 0 ; + old =pte_update (mm, addr, ptep, _PAGE_ACCESSED,0 ,0 ); +return (old & _PAGE_ACCESSED) !=0 ; +} +#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG +#define ptep_test_and_clear_young (__vma, __addr, __ptep) \ +({ \ + int __r; \ + __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \ + __r; \ +}) + +#define __HAVE_ARCH_PTEP_SET_WRPROTECT +static inline void ptep_set_wrprotect (struct mm_struct *mm,unsigned long addr, +pte_t *ptep) +{ + +if ((pte_val (*ptep) & _PAGE_RW) ==0 ) +return ; + +pte_update (mm, addr, ptep, _PAGE_RW,0 ,0 ); +} + +static inline void huge_ptep_set_wrprotect (struct mm_struct *mm, +unsigned long addr,pte_t *ptep) +{ +if ((pte_val (*ptep) & _PAGE_RW) ==0 ) +return ; + +pte_update (mm, addr, ptep, _PAGE_RW,0 ,1 ); +} + +/* +* We currently remove entries from the hashtable regardless of whether +* the entry was young or dirty. The generic routines only flush if the +* entry was young or dirty which is not good enough. +* +* We should be more intelligent about this but for the moment we override +* these functions and force a tlb flush unconditionally +*/ +#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH +#define ptep_clear_flush_young (__vma, __address, __ptep) \ +({ \ + int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \ + __ptep); \ + __young; \ +}) + +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR +static inline pte_t ptep_get_and_clear (struct mm_struct *mm, +unsigned long addr,pte_t *ptep) +{ +unsigned long old =pte_update (mm, addr, ptep, ~0UL ,0 ,0 ); +return __pte (old); +} + +static inline void pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t * ptep) +{ +pte_update (mm, addr, ptep, ~0UL ,0 ,0 ); +} + + +/* Set the dirty and/or accessed bits atomically in a linux PTE, this +* function doesn't need to flush the hash entry +*/ +static inline void __ptep_set_access_flags (pte_t *ptep,pte_t entry) +{ +unsigned long bits =pte_val (entry) & + (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC); + +unsigned long old, tmp; + + __asm__ __volatile__( +"1: ldarx %0,0,%4\n\ +andi. %1,%0,%6\n\ +bne- 1b \n\ +or %0,%3,%0\n\ +stdcx. %0,0,%4\n\ +bne- 1b" + :"=&r" (old),"=&r" (tmp),"=m" (*ptep) + :"r" (bits),"r" (ptep),"m" (*ptep),"i" (_PAGE_BUSY) + :"cc" ); +} + +#define __HAVE_ARCH_PTE_SAME +#define pte_same (A ,B ) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0) + +static inline char *get_hpte_slot_array (pmd_t *pmdp) +{ +/* +* The hpte hindex is stored in the pgtable whose address is in the +* second half of the PMD +* +* Order this load with the test for pmd_trans_huge in the caller +*/ +smp_rmb (); +return *(char **)(pmdp +PTRS_PER_PMD ); + + +} +/* +* The linux hugepage PMD now include the pmd entries followed by the address +* to the stashed pgtable_t. The stashed pgtable_t contains the hpte bits. +* [ 1 bit secondary | 3 bit hidx | 1 bit valid | 000]. We use one byte per +* each HPTE entry. With 16MB hugepage and 64K HPTE we need 256 entries and +* with 4K HPTE we need 4096 entries. Both will fit in a 4K pgtable_t. +* +* The last three bits are intentionally left to zero. This memory location +* are also used as normal page PTE pointers. So if we have any pointers +* left around while we collapse a hugepage, we need to make sure +* _PAGE_PRESENT bit of that is zero when we look at them +*/ +static inline unsigned int hpte_valid (unsigned char *hpte_slot_array,int index) +{ +return (hpte_slot_array[index] >>3 ) &0x1 ; +} + +static inline unsigned int hpte_hash_index (unsigned char *hpte_slot_array, +int index) +{ +return hpte_slot_array[index] >>4 ; +} + +static inline void mark_hpte_slot_valid (unsigned char *hpte_slot_array, +unsigned int index,unsigned int hidx) +{ + hpte_slot_array[index] = hidx <<4 |0x1 <<3 ; +} + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +/* +* +* For core kernel code by design pmd_trans_huge is never run on any hugetlbfs +* page. The hugetlbfs page table walking and mangling paths are totally +* separated form the core VM paths and they're differentiated by +* VM_HUGETLB being set on vm_flags well before any pmd_trans_huge could run. +* +* pmd_trans_huge() is defined as false at build time if +* CONFIG_TRANSPARENT_HUGEPAGE=n to optimize away code blocks at build +* time in such case. +* +* For ppc64 we need to differntiate from explicit hugepages from THP, because +* for THP we also track the subpage details at the pmd level. We don't do +* that for explicit huge pages. +* +*/ +static inline int pmd_trans_huge (pmd_t pmd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return (pmd_val (pmd) &0x3 ) && (pmd_val (pmd) & _PAGE_THP_HUGE); +} + +static inline int pmd_trans_splitting (pmd_t pmd) +{ +if (pmd_trans_huge (pmd)) +return pmd_val (pmd) & _PAGE_SPLITTING; +return 0 ; +} +#endif +static inline int pmd_large (pmd_t pmd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return ((pmd_val (pmd) &0x3 ) !=0x0 ); +} + +static inline pmd_t pmd_mknotpresent (pmd_t pmd) +{ +return __pmd (pmd_val (pmd) & ~_PAGE_PRESENT); +} + +static inline pmd_t pmd_mksplitting (pmd_t pmd) +{ +return __pmd (pmd_val (pmd) | _PAGE_SPLITTING); +} + +#define __HAVE_ARCH_PMD_SAME +static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b) +{ +return (((pmd_val (pmd_a) ^pmd_val (pmd_b)) & ~_PAGE_HPTEFLAGS) ==0 ); +} + +static inline int __pmdp_test_and_clear_young (struct mm_struct *mm, +unsigned long addr,pmd_t *pmdp) +{ +unsigned long old; + +if ((pmd_val (*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 ) +return 0 ; + old =pmd_hugepage_update (mm, addr, pmdp, _PAGE_ACCESSED,0 ); +return ((old & _PAGE_ACCESSED) !=0 ); +} + +#define __HAVE_ARCH_PMDP_SET_WRPROTECT +static inline void pmdp_set_wrprotect (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp) +{ + +if ((pmd_val (*pmdp) & _PAGE_RW) ==0 ) +return ; + +pmd_hugepage_update (mm, addr, pmdp, _PAGE_RW,0 ); +} +#endif /* !__ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_H */
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -438
531 lines not on this page · raw message
arch/powerpc/include/asm/pgtable.h +0 -6
@@ -18,12 +18,6 @@ struct mm_struct;#include <asm/pgtable-book3e.h> #endif /* !CONFIG_PPC_BOOK3S */ -/* -* We save the slot number & secondary bit in the second half of the -* PTE page. We use the 8 bytes per each pte entry. -*/ -#define PTE_PAGE_HIDX_OFFSET (PTRS_PER_PTE * 8) -#ifndef __ASSEMBLY__#include <asm/tlbflush.h>
Signature · 1 line
2.5.0
PATCH v2 12/31 powerpc/mm: Move PTE bits from generic functions to hash64 functions.
In reply to Aneesh Kumar K.Vfunctions which operate on pte bits are moved to hash*.h and other generic functions are moved to pgtable.h
--- arch/powerpc/include/asm/book3s/32/pgtable.h | 177 ++++++++++++++++++++++++ arch/powerpc/include/asm/book3s/64/hash.h | 144 +++++++++++++++++++ arch/powerpc/include/asm/book3s/64/pgtable.h | 6 + arch/powerpc/include/asm/book3s/pgtable.h | 198 --------------------------- 4 files changed, 327 insertions(+), 198 deletions(-)
arch/powerpc/include/asm/book3s/32/pgtable.h +177 -0
@@ -294,6 +294,183 @@ void pgtable_cache_init(void);extern int get_pteptr (struct mm_struct *mm,unsigned long addr,pte_t **ptep,pmd_t **pmdp); +/* Generic accessors to PTE bits */ +static inline int pte_write (pte_t pte) {return !!(pte_val (pte) & _PAGE_RW);} +static inline int pte_dirty (pte_t pte) {return !!(pte_val (pte) & _PAGE_DIRTY); } +static inline int pte_young (pte_t pte) {return !!(pte_val (pte) & _PAGE_ACCESSED); } +static inline int pte_special (pte_t pte) {return !!(pte_val (pte) & _PAGE_SPECIAL); } +static inline int pte_none (pte_t pte) {return (pte_val (pte) & ~_PTE_NONE_MASK) ==0 ; } +static inline pgprot_t pte_pgprot (pte_t pte) {return __pgprot (pte_val (pte) &PAGE_PROT_BITS ); } + +static inline int pte_present (pte_t pte) +{ +return pte_val (pte) & _PAGE_PRESENT; +} + +/* Conversion functions: convert a page and protection to a page entry, +* and a page entry and page directory to the page they refer to. +* +* Even if PTEs can be unsigned long long, a PFN is always an unsigned +* long for now. +*/ +static inline pte_t pfn_pte (unsigned long pfn,pgprot_t pgprot) +{ +return __pte (((pte_basic_t)(pfn) <<PTE_RPN_SHIFT ) | +pgprot_val (pgprot)); +} + +static inline unsigned long pte_pfn (pte_t pte) +{ +return pte_val (pte) >>PTE_RPN_SHIFT ; +} + +/* Generic modifiers for PTE bits */ +static inline pte_t pte_wrprotect (pte_t pte) +{ +return __pte (pte_val (pte) & ~_PAGE_RW); +} + +static inline pte_t pte_mkclean (pte_t pte) +{ +return __pte (pte_val (pte) & ~_PAGE_DIRTY); +} + +static inline pte_t pte_mkold (pte_t pte) +{ +return __pte (pte_val (pte) & ~_PAGE_ACCESSED); +} + +static inline pte_t pte_mkwrite (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_RW); +} + +static inline pte_t pte_mkdirty (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_DIRTY); +} + +static inline pte_t pte_mkyoung (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_ACCESSED); +} + +static inline pte_t pte_mkspecial (pte_t pte) +{ +return __pte (pte_val (pte) | _PAGE_SPECIAL); +} + +static inline pte_t pte_mkhuge (pte_t pte) +{ +return pte; +} + +static inline pte_t pte_modify (pte_t pte,pgprot_t newprot) +{ +return __pte ((pte_val (pte) & _PAGE_CHG_MASK) |pgprot_val (newprot)); +} + + + +/* This low level function performs the actual PTE insertion +* Setting the PTE depends on the MMU type and other factors. It's +* an horrible mess that I'm not going to try to clean up now but +* I'm keeping it in one place rather than spread around +*/ +static inline void __set_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,int percpu) +{ +#if defined(CONFIG_PPC_STD_MMU_32 ) && defined(CONFIG_SMP ) && !defined(CONFIG_PTE_64BIT ) +/* First case is 32-bit Hash MMU in SMP mode with 32-bit PTEs. We use the +* helper pte_update() which does an atomic update. We need to do that +* because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a +* per-CPU PTE such as a kmap_atomic, we do a simple update preserving +* the hash bits instead (ie, same as the non-SMP case) +*/ +if (percpu) + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); +else +pte_update (ptep, ~_PAGE_HASHPTE,pte_val (pte)); + +#elif defined(CONFIG_PPC32 ) && defined(CONFIG_PTE_64BIT ) +/* Second case is 32-bit with 64-bit PTE. In this case, we +* can just store as long as we do the two halves in the right order +* with a barrier in between. This is possible because we take care, +* in the hash code, to pre-invalidate if the PTE was already hashed, +* which synchronizes us with any concurrent invalidation. +* In the percpu case, we also fallback to the simple update preserving +* the hash bits +*/ +if (percpu) { + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); +return ; + } +if (pte_val (*ptep) & _PAGE_HASHPTE) +flush_hash_entry (mm, ptep, addr); + __asm__ __volatile__("\ +stw%U0%X0 %2,%0\n\ +eieio\n\ +stw%U0%X0 %L2,%1" + :"=m" (*ptep),"=m" (*((unsigned char *)ptep+4 )) + :"r" (pte) :"memory" ); + +#elif defined(CONFIG_PPC_STD_MMU_32 ) +/* Third case is 32-bit hash table in UP mode, we need to preserve +* the _PAGE_HASHPTE bit since we may not have invalidated the previous +* translation in the hash yet (done in a subsequent flush_tlb_xxx()) +* and see we need to keep track that this PTE needs invalidating +*/ + *ptep =__pte ((pte_val (*ptep) & _PAGE_HASHPTE) + | (pte_val (pte) & ~_PAGE_HASHPTE)); + +#else +#error "Not supported " +#endif +} + +/* +* Macro to mark a page protection value as "uncacheable". +*/ + +#define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \ + _PAGE_WRITETHRU) + +static inline pgprot_t pgprot_noncached (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_NO_CACHE | _PAGE_GUARDED); +} + +static inline pgprot_t pgprot_noncached_wc (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_NO_CACHE); +} + +static inline pgprot_t pgprot_cached (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_COHERENT); +} + +static inline pgprot_t pgprot_cached_wthru (pgprot_t prot) +{ +return __pgprot ((pgprot_val (prot) & ~_PAGE_CACHE_CTL) | + _PAGE_COHERENT | _PAGE_WRITETHRU); +} + +static inline pgprot_t pgprot_cached_noncoherent (pgprot_t prot) +{ +return __pgprot (pgprot_val (prot) & ~_PAGE_CACHE_CTL); +} + +static inline pgprot_t pgprot_writecombine (pgprot_t prot) +{ +return pgprot_noncached_wc (prot); +} +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_PGTABLE_PPC32_H */
arch/powerpc/include/asm/book3s/64/hash.h +144 -0
150 lines not on this page · raw message
arch/powerpc/include/asm/book3s/64/pgtable.h +6 -0
@@ -201,6 +201,12 @@ static inline pte_t *pmdp_ptep(pmd_t *pmd)#define pmd_mkdirty (pmd) pte_pmd(pte_mkdirty(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))) +#ifdef CONFIG_NUMA_BALANCING +static inline int pmd_protnone (pmd_t pmd) +{ +return pte_protnone (pmd_pte (pmd)); +} +#endif /* CONFIG_NUMA_BALANCING */ #define __HAVE_ARCH_PMD_WRITE#define pmd_write (pmd) pte_write(pmd_pte(pmd))
arch/powerpc/include/asm/book3s/pgtable.h +0 -198
215 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 13/31 powerpc/booke: Move booke headers (part 1)
In reply to Aneesh Kumar K.VMove the booke related headers below booke/32 or booke/64
We are splitting this change into multiple patch to make the rebasing easier. The following patches can be folded into this if needed. They are kept separate for easier review.
---
arch/powerpc/include/asm/{pgtable-book3e.h => nohash/pgtable.h} | 0
arch/powerpc/include/asm/pgtable.h | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename arch/powerpc/include/asm/{pgtable-book3e.h => nohash/pgtable.h} (100%)arch/powerpc/include/asm/nohash/pgtable.h renamed from arch/powerpc/include/asm/pgtable-book3e.h +0 -0
arch/powerpc/include/asm/pgtable.h +1 -1
@@ -15,7 +15,7 @@ struct mm_struct;#ifdef CONFIG_PPC_BOOK3S #include <asm/book3s/pgtable.h> #else -#include <asm/pgtable-book3e.h> +#include <asm/nohash/pgtable.h> #endif /* !CONFIG_PPC_BOOK3S */ #ifndef __ASSEMBLY__
Signature · 1 line
2.5.0
PATCH v2 14/31 powerpc/booke: Move booke headers (part 2)
In reply to Aneesh Kumar K.V---
arch/powerpc/include/asm/{pgtable-ppc32.h => nohash/32/pgtable.h} | 0
arch/powerpc/include/asm/{pgtable-ppc64.h => nohash/64/pgtable.h} | 2 +-
arch/powerpc/include/asm/nohash/pgtable.h | 8 ++++----
3 files changed, 5 insertions(+), 5 deletions(-)
rename arch/powerpc/include/asm/{pgtable-ppc32.h => nohash/32/pgtable.h} (100%)
rename arch/powerpc/include/asm/{pgtable-ppc64.h => nohash/64/pgtable.h} (99%)arch/powerpc/include/asm/nohash/32/pgtable.h renamed from arch/powerpc/include/asm/pgtable-ppc32.h +0 -0
arch/powerpc/include/asm/nohash/64/pgtable.h renamed from arch/powerpc/include/asm/pgtable-ppc64.h +1 -1
@@ -18,7 +18,7 @@* Size of EA range mapped by our pagetables. */ #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \ - PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT) + PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)#define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE)#ifdef CONFIG_TRANSPARENT_HUGEPAGE
arch/powerpc/include/asm/nohash/pgtable.h +4 -4
@@ -1,10 +1,10 @@ -#ifndef _ASM_POWERPC_PGTABLE_BOOK3E_H -#define _ASM_POWERPC_PGTABLE_BOOK3E_H +#ifndef _ASM_POWERPC_NOHASH_PGTABLE_H +#define _ASM_POWERPC_NOHASH_PGTABLE_H#if defined(CONFIG_PPC64 ) -#include <asm/pgtable-ppc64.h> +#include <asm/nohash/64/pgtable.h> #else -#include <asm/pgtable-ppc32.h> +#include <asm/nohash/32/pgtable.h> #endif #ifndef __ASSEMBLY__
Signature · 1 line
2.5.0
PATCH v2 15/31 powerpc/booke: Move booke headers (part 3)
In reply to Aneesh Kumar K.V---
.../include/asm/{pgtable-ppc64-4k.h => nohash/64/pgtable-4k.h} | 0
.../asm/{pgtable-ppc64-64k.h => nohash/64/pgtable-64k.h} | 0
arch/powerpc/include/asm/nohash/64/pgtable.h | 10 +++++-----
3 files changed, 5 insertions(+), 5 deletions(-)
rename arch/powerpc/include/asm/{pgtable-ppc64-4k.h => nohash/64/pgtable-4k.h} (100%)
rename arch/powerpc/include/asm/{pgtable-ppc64-64k.h => nohash/64/pgtable-64k.h} (100%)arch/powerpc/include/asm/nohash/64/pgtable-4k.h renamed from arch/powerpc/include/asm/pgtable-ppc64-4k.h +0 -0
arch/powerpc/include/asm/nohash/64/pgtable-64k.h renamed from arch/powerpc/include/asm/pgtable-ppc64-64k.h +0 -0
arch/powerpc/include/asm/nohash/64/pgtable.h +5 -5
@@ -1,14 +1,14 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC64_H_ -#define _ASM_POWERPC_PGTABLE_PPC64_H_ +#ifndef _ASM_POWERPC_NOHASH_64_PGTABLE_H +#define _ASM_POWERPC_NOHASH_64_PGTABLE_H/* * This file contains the functions and defines necessary to modify and use * the ppc64 hashed page table. */ #ifdef CONFIG_PPC_64K_PAGES -#include <asm/pgtable-ppc64-64k.h> +#include <asm/nohash/64/pgtable-64k.h> #else -#include <asm/pgtable-ppc64-4k.h> +#include <asm/nohash/64/pgtable-4k.h> #endif #include <asm/barrier.h>
@@ -629,4 +629,4 @@ static inline int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,return true; }#endif /* __ASSEMBLY__ */ -#endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */ +#endif /* _ASM_POWERPC_NOHASH_64_PGTABLE_H */
Signature · 1 line
2.5.0
PATCH v2 16/31 powerpc/booke: Move booke headers (part 4)
In reply to Aneesh Kumar K.V---
arch/powerpc/include/asm/nohash/32/pgtable.h | 16 ++++++++--------
arch/powerpc/include/asm/{ => nohash/32}/pte-40x.h | 0
arch/powerpc/include/asm/{ => nohash/32}/pte-44x.h | 0
arch/powerpc/include/asm/{ => nohash/32}/pte-8xx.h | 0
arch/powerpc/include/asm/{ => nohash/32}/pte-fsl-booke.h | 0
arch/powerpc/include/asm/nohash/64/pgtable.h | 2 +-
arch/powerpc/include/asm/{ => nohash}/pte-book3e.h | 0
7 files changed, 9 insertions(+), 9 deletions(-)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-40x.h (100%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-44x.h (100%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-8xx.h (100%)
rename arch/powerpc/include/asm/{ => nohash/32}/pte-fsl-booke.h (100%)
rename arch/powerpc/include/asm/{ => nohash}/pte-book3e.h (100%)arch/powerpc/include/asm/nohash/32/pgtable.h +8 -8
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC32_H -#define _ASM_POWERPC_PGTABLE_PPC32_H +#ifndef _ASM_POWERPC_NOHASH_32_PGTABLE_H +#define _ASM_POWERPC_NOHASH_32_PGTABLE_H#include <asm-generic/pgtable-nopmd.h>
@@ -106,15 +106,15 @@ extern int icache_44x_need_flush;*/ #if defined(CONFIG_40x) -#include <asm/pte-40x.h> +#include <asm/nohash/32/pte-40x.h> #elif defined(CONFIG_44x) -#include <asm/pte-44x.h> +#include <asm/nohash/32/pte-44x.h> #elif defined(CONFIG_FSL_BOOKE ) && defined(CONFIG_PTE_64BIT ) -#include <asm/pte-book3e.h> +#include <asm/nohash/pte-book3e.h> #elif defined(CONFIG_FSL_BOOKE ) -#include <asm/pte-fsl-booke.h> +#include <asm/nohash/32/pte-fsl-booke.h> #elif defined(CONFIG_8xx) -#include <asm/pte-8xx.h> +#include <asm/nohash/32/pte-8xx.h> #endif /* And here we include common definitions */
@@ -340,4 +340,4 @@ extern int get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep,#endif /* !__ASSEMBLY__ */ -#endif /* _ASM_POWERPC_PGTABLE_PPC32_H */ +#endif /* __ASM_POWERPC_NOHASH_32_PGTABLE_H */
arch/powerpc/include/asm/nohash/32/pte-40x.h renamed from arch/powerpc/include/asm/pte-40x.h +0 -0
arch/powerpc/include/asm/nohash/32/pte-44x.h renamed from arch/powerpc/include/asm/pte-44x.h +0 -0
arch/powerpc/include/asm/nohash/32/pte-8xx.h renamed from arch/powerpc/include/asm/pte-8xx.h +0 -0
arch/powerpc/include/asm/nohash/32/pte-fsl-booke.h renamed from arch/powerpc/include/asm/pte-fsl-booke.h +0 -0
arch/powerpc/include/asm/nohash/64/pgtable.h +1 -1
@@ -97,7 +97,7 @@/* * Include the PTE bits definitions */ -#include <asm/pte-book3e.h> +#include <asm/nohash/pte-book3e.h> #include <asm/pte-common.h> #ifdef CONFIG_PPC_MM_SLICES
arch/powerpc/include/asm/nohash/pte-book3e.h renamed from arch/powerpc/include/asm/pte-book3e.h +0 -0
Signature · 1 line
2.5.0
PATCH v2 17/31 powerpc/booke: Move booke headers (part 5)
In reply to Aneesh Kumar K.V--- arch/powerpc/include/asm/nohash/32/pte-40x.h | 6 +++--- arch/powerpc/include/asm/nohash/32/pte-44x.h | 6 +++--- arch/powerpc/include/asm/nohash/32/pte-8xx.h | 6 +++--- arch/powerpc/include/asm/nohash/32/pte-fsl-booke.h | 6 +++--- arch/powerpc/include/asm/nohash/64/pgtable-4k.h | 6 +++--- arch/powerpc/include/asm/nohash/64/pgtable-64k.h | 6 +++--- arch/powerpc/include/asm/nohash/pte-book3e.h | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/nohash/32/pte-40x.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_40x_H -#define _ASM_POWERPC_PTE_40x_H +#ifndef _ASM_POWERPC_NOHASH_32_PTE_40x_H +#define _ASM_POWERPC_NOHASH_32_PTE_40x_H#ifdef __KERNEL__/*
@@ -61,4 +61,4 @@#define PTE_ATOMIC_UPDATES 1#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_40x_H */ +#endif /* _ASM_POWERPC_NOHASH_32_PTE_40x_H */
arch/powerpc/include/asm/nohash/32/pte-44x.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_44x_H -#define _ASM_POWERPC_PTE_44x_H +#ifndef _ASM_POWERPC_NOHASH_32_PTE_44x_H +#define _ASM_POWERPC_NOHASH_32_PTE_44x_H#ifdef __KERNEL__/*
@@ -94,4 +94,4 @@#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_44x_H */ +#endif /* _ASM_POWERPC_NOHASH_32_PTE_44x_H */
arch/powerpc/include/asm/nohash/32/pte-8xx.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_8xx_H -#define _ASM_POWERPC_PTE_8xx_H +#ifndef _ASM_POWERPC_NOHASH_32_PTE_8xx_H +#define _ASM_POWERPC_NOHASH_32_PTE_8xx_H#ifdef __KERNEL__/*
@@ -62,4 +62,4 @@ _PAGE_HWWRITE | _PAGE_EXEC)#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_8xx_H */ +#endif /* _ASM_POWERPC_NOHASH_32_PTE_8xx_H */
arch/powerpc/include/asm/nohash/32/pte-fsl-booke.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_FSL_BOOKE_H -#define _ASM_POWERPC_PTE_FSL_BOOKE_H +#ifndef _ASM_POWERPC_NOHASH_32_PTE_FSL_BOOKE_H +#define _ASM_POWERPC_NOHASH_32_PTE_FSL_BOOKE_H#ifdef __KERNEL__/* PTE bit definitions for Freescale BookE SW loaded TLB MMU based
@@ -37,4 +37,4 @@#define PTE_WIMGE_SHIFT (6)#endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_FSL_BOOKE_H */ +#endif /* _ASM_POWERPC_NOHASH_32_PTE_FSL_BOOKE_H */
arch/powerpc/include/asm/nohash/64/pgtable-4k.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC64_4K_H -#define _ASM_POWERPC_PGTABLE_PPC64_4K_H +#ifndef _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H +#define _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H/* * Entries per page directory level. The PTE level must use a 64b record * for each page table entry. The PMD and PGD level use a 32b record for
@@ -89,4 +89,4 @@ extern struct page *pgd_page(pgd_t pgd);#define remap_4k_pfn (vma, addr, pfn, prot) \ remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) -#endif /* _ASM_POWERPC_PGTABLE_PPC64_4K_H */ +#endif /* _ _ASM_POWERPC_NOHASH_64_PGTABLE_4K_H */
arch/powerpc/include/asm/nohash/64/pgtable-64k.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PGTABLE_PPC64_64K_H -#define _ASM_POWERPC_PGTABLE_PPC64_64K_H +#ifndef _ASM_POWERPC_NOHASH_64_PGTABLE_64K_H +#define _ASM_POWERPC_NOHASH_64_PGTABLE_64K_H#include <asm-generic/pgtable-nopud.h>
@@ -41,4 +41,4 @@#define pgd_pte (pgd) (pud_pte(((pud_t){ pgd })))#define pte_pgd (pte) ((pgd_t)pte_pud(pte)) -#endif /* _ASM_POWERPC_PGTABLE_PPC64_64K_H */ +#endif /* _ASM_POWERPC_NOHASH_64_PGTABLE_64K_H */
arch/powerpc/include/asm/nohash/pte-book3e.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _ASM_POWERPC_PTE_BOOK3E_H -#define _ASM_POWERPC_PTE_BOOK3E_H +#ifndef _ASM_POWERPC_NOHASH_PTE_BOOK3E_H +#define _ASM_POWERPC_NOHASH_PTE_BOOK3E_H#ifdef __KERNEL__/* PTE bit definitions for processors compliant to the Book3E
@@ -84,4 +84,4 @@#endif #endif /* __KERNEL__ */ -#endif /* _ASM_POWERPC_PTE_FSL_BOOKE_H */ +#endif /* _ASM_POWERPC_NOHASH_PTE_BOOK3E_H */
Signature · 1 line
2.5.0
PATCH v2 18/31 powerpc/mm: Increase the pte frag size.
In reply to Aneesh Kumar K.VWe will use the increased size to store more information of 4K pte when using 64K page size. The idea is to free up bits in pte_t.
--- arch/powerpc/include/asm/pgalloc-64.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/pgalloc-64.h +6 -6
@@ -164,15 +164,15 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,#else /* if CONFIG_PPC_64K_PAGES */ /* -* we support 16 fragments per PTE page. +* we support 8 fragments per PTE page. */ -#define PTE_FRAG_NR 16 +#define PTE_FRAG_NR 8/* -* We use a 2K PTE page fragment and another 2K for storing -* real_pte_t hash index +* We use a 2K PTE page fragment and another 4K for storing +* real_pte_t hash index. Rounding the entire thing to 8K */ -#define PTE_FRAG_SIZE_SHIFT 12 -#define PTE_FRAG_SIZE (2 * PTRS_PER_PTE * sizeof(pte_t)) +#define PTE_FRAG_SIZE_SHIFT 13 +#define PTE_FRAG_SIZE (1UL << PTE_FRAG_SIZE_SHIFT)extern pte_t *page_table_alloc (struct mm_struct *,unsigned long ,int );extern void page_table_free (struct mm_struct *,unsigned long *,int );
Signature · 1 line
2.5.0
PATCH v2 19/31 powerpc/mm: Convert 4k hash insert to C
In reply to Aneesh Kumar K.V--- arch/powerpc/mm/Makefile | 3 + arch/powerpc/mm/hash64_64k.c | 202 +++++++++++++++++++++ arch/powerpc/mm/hash_low_64.S | 380 ---------------------------------------- arch/powerpc/mm/hash_utils_64.c | 4 +- 4 files changed, 208 insertions(+), 381 deletions(-) create mode 100644 arch/powerpc/mm/hash64_64k.c
arch/powerpc/mm/Makefile +3 -0
@@ -18,6 +18,9 @@ obj-$(CONFIG_PPC_STD_MMU_32) += ppc_mmu_32.o obj-$(CONFIG_PPC_STD_MMU) += hash_low_$(CONFIG_WORD_SIZE).o \ tlb_hash$(CONFIG_WORD_SIZE).o \ mmu_context_hash$(CONFIG_WORD_SIZE).o +ifeq ($(CONFIG_PPC_STD_MMU_64),y) +obj-$(CONFIG_PPC_64K_PAGES) += hash64_64k.o +endif obj-$(CONFIG_PPC_ICSWX) += icswx.o obj-$(CONFIG_PPC_ICSWX_PID) += icswx_pid.o obj-$(CONFIG_40x) += 40x_mmu.o
arch/powerpc/mm/hash64_64k.c new file +202 -0
202 lines not on this page · raw message
arch/powerpc/mm/hash_low_64.S +0 -380
391 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +3 -1
@@ -653,7 +653,7 @@ static void __init htab_finish_init(void)patch_branch (ht64_call_hpte_updatepp,ppc_function_entry (ppc_md.hpte_updatepp),BRANCH_SET_LINK ); -#endif /* CONFIG_PPC_64K_PAGES */ +#else /* !CONFIG_PPC_64K_PAGES */ patch_branch(htab_call_hpte_insert1, ppc_function_entry(ppc_md.hpte_insert),
@@ -667,6 +667,8 @@ static void __init htab_finish_init(void)patch_branch (htab_call_hpte_updatepp,ppc_function_entry (ppc_md.hpte_updatepp),BRANCH_SET_LINK ); +#endif + }static void __init htab_initialize (void )
Signature · 1 line
2.5.0
Re: [PATCH V2 19/31] powerpc/mm: Convert 4k hash insert to C
Quoted 58 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/mm/Makefile | 3 + arch/powerpc/mm/hash64_64k.c | 202 +++++++++++++++++++++ arch/powerpc/mm/hash_low_64.S | 380 ---------------------------------------- arch/powerpc/mm/hash_utils_64.c | 4 +- 4 files changed, 208 insertions(+), 381 deletions(-) create mode 100644 arch/powerpc/mm/hash64_64k.carch/powerpc/mm/Makefile +3
-0@@ -18,6 +18,9 @@ obj-$(CONFIG_PPC_STD_MMU_32) += ppc_mmu_32.o obj-$(CONFIG_PPC_STD_MMU) += hash_low_$(CONFIG_WORD_SIZE).o \ tlb_hash$(CONFIG_WORD_SIZE).o \ mmu_context_hash$(CONFIG_WORD_SIZE).o +ifeq ($(CONFIG_PPC_STD_MMU_64),y) +obj-$(CONFIG_PPC_64K_PAGES) += hash64_64k.o +endif obj-$(CONFIG_PPC_ICSWX) += icswx.o obj-$(CONFIG_PPC_ICSWX_PID) += icswx_pid.o obj-$(CONFIG_40x) += 40x_mmu.oarch/powerpc/mm/hash64_64k.c new file +29
-0@@ -0,0 +1,202 @@ +/* +* Copyright IBM Corporation, 2015 +* Author Aneesh Kumar K.V <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2.1 of the GNU Lesser General Public License +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +*/ + +#include <linux/mm.h> +#include <asm/machdep.h> +#include <asm/mmu.h> + +int __hash_page_4K (unsigned long ea,unsigned long access,unsigned long vsid, +pte_t *ptep,unsigned long trap,unsigned long flags, +int ssize,int subpg_prot) +{ +real_pte_t rpte; +unsigned long *hidxp; +unsigned long hpte_group; +unsigned int subpg_index; +unsigned long shift =12 ;/* 4K */ +unsigned long rflags, pa, hidx; +unsigned long old_pte, new_pte, subpg_pte;
arch/powerpc/mm/hash64_64k.c line 39
Quoted 10 lines
arch/powerpc/mm/hash64_64k.c new file +10
-0+unsigned long vpn, hash, slot; + +/* +* atomically mark the linux large page PTE busy and dirty +*/ + do { + pte_t pte = READ_ONCE(*ptep); + + old_pte = pte_val(pte); + /* If PTE busy, retry the access */
Small nit, need a gap between the above two lines ?
arch/powerpc/mm/hash64_64k.c line 42
Quoted 3 lines
arch/powerpc/mm/hash64_64k.c new file +3
-0+if (unlikely (old_pte & _PAGE_BUSY)) +return 0 ; +/* If PTE permissions don't match, take page fault */
We are already in page fault interrupt path, will it be better if we call it "take Linux page fault" instead as we will go back walking the page table.
Re: [PATCH V2 19/31] powerpc/mm: Convert 4k hash insert to C
Quoted 7 lines · Anshuman Khandual
arch/powerpc/mm/hash64_64k.c line 42
Quoted 3 lines
arch/powerpc/mm/hash64_64k.c new file +3
-0+if (unlikely (old_pte & _PAGE_BUSY)) +return 0 ; +/* If PTE permissions don't match, take page fault */ We are already in page fault interrupt path, will it be better if we call it "take Linux page fault" instead as we will go back walking the page table.
A better wording would be "escalate the page fault"
Cheers,
Ben.
Re: [PATCH V2 19/31] powerpc/mm: Convert 4k hash insert to C
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 7 lines · Anshuman Khandual
arch/powerpc/mm/hash64_64k.c line 42
Quoted 3 lines
arch/powerpc/mm/hash64_64k.c new file +3
-0+if (unlikely (old_pte & _PAGE_BUSY)) +return 0 ; +/* If PTE permissions don't match, take page fault */ We are already in page fault interrupt path, will it be better if we call it "take Linux page fault" instead as we will go back walking the page table.
A better wording would be "escalate the page fault"
Right. There is one more thing. hash_page_mm function can have these following return values after completion.
/* Result code is:
* 0 - handled
* 1 - normal page fault---> Escalate into linux page fault
* -1 - critical hash insertion error
* -2 - access not permitted by subpage protection mechanism */
-2 is returned after looking into the sub page protection bits.
0 is returned when hash page insert succeeds
- ppc_md.hpte_insert returns actual slot number
- Multiple retries after ppc_md.hpte_insert returns -1 indicating that HPTEG is full and try secondary hash
1 is returned when PTE in the page table does not contain PFN
-1 is returned when hash page did not succeed
- ppc_md.hpte_insert returns -2 when it cannot insert HPTE
The point is, there are multiple combinations of (0, 1, -1, -2) out there in various paths without much documentation which can be cleaned up. Not in this series but may be later.
PATCH v2 20/31 powerpc/mm: update __real_pte to take address as argument
In reply to Aneesh Kumar K.VWe will use this in the later patch to compute the right hash index
--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 2 +- arch/powerpc/include/asm/book3s/64/pgtable.h | 4 ++-- arch/powerpc/include/asm/nohash/64/pgtable.h | 4 ++-- arch/powerpc/mm/hash64_64k.c | 2 +- arch/powerpc/mm/tlb_hash64.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +1 -1
@@ -78,7 +78,7 @@* generic accessors and iterators here */ #define __real_pte __real_pte -static inline real_pte_t __real_pte (pte_t pte,pte_t *ptep) +static inline real_pte_t __real_pte (unsigned long addr,pte_t pte,pte_t *ptep) {real_pte_t rpte;
arch/powerpc/include/asm/book3s/64/pgtable.h +2 -2
@@ -44,10 +44,10 @@#ifndef __real_pte#ifdef CONFIG_STRICT_MM_TYPECHECKS -#define __real_pte (e,p) ((real_pte_t){(e)}) +#define __real_pte (a,e,p) ((real_pte_t){(e)})#define __rpte_to_pte (r) ((r).pte)#else -#define __real_pte (e,p) (e) +#define __real_pte (a,e,p) (e)#define __rpte_to_pte (r) (__pte(r))#endif #define __rpte_to_hidx (r,index) (pte_val(__rpte_to_pte(r)) >> 12)
arch/powerpc/include/asm/nohash/64/pgtable.h +2 -2
@@ -115,10 +115,10 @@#ifndef __real_pte#ifdef CONFIG_STRICT_MM_TYPECHECKS -#define __real_pte (e,p) ((real_pte_t){(e)}) +#define __real_pte (a,e,p) ((real_pte_t){(e)})#define __rpte_to_pte (r) ((r).pte)#else -#define __real_pte (e,p) (e) +#define __real_pte (a,e,p) (e)#define __rpte_to_pte (r) (__pte(r))#endif #define __rpte_to_hidx (r,index) (pte_val(__rpte_to_pte(r)) >> 12)
arch/powerpc/mm/hash64_64k.c +1 -1
@@ -90,7 +90,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid, subpg_index = (ea & (PAGE_SIZE -1 )) >> shift; vpn =hpt_vpn (ea, vsid, ssize); - rpte =__real_pte (__pte (old_pte), ptep); + rpte =__real_pte (ea,__pte (old_pte), ptep);/* *None of the sub 4k page is hashed */
arch/powerpc/mm/tlb_hash64.c +1 -1
@@ -89,7 +89,7 @@ void hpte_need_flush(struct mm_struct *mm, unsigned long addr, }WARN_ON (vsid ==0 ); vpn =hpt_vpn (addr, vsid, ssize); - rpte =__real_pte (__pte (pte), ptep); + rpte =__real_pte (addr,__pte (pte), ptep);/* * Check if we have an active batch on this CPU. If not, just
Signature · 1 line
2.5.0
PATCH v2 21/31 powerpc/mm: make pte page hash index slot 8 bits
In reply to Aneesh Kumar K.VCurrently we use 4 bits for each slot and pack all the 16 slot information related to a 64K linux page in a 64bit value. To do this we use 16 bits of pte_t. Move the hash slot valid bit out of pte_t and place them in the second half of pte page. We also use 8 bit per each slot.
--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 48 +++++++++++++++------------ arch/powerpc/include/asm/book3s/64/hash.h | 5 --- arch/powerpc/include/asm/page.h | 4 +-- arch/powerpc/mm/hash64_64k.c | 34 +++++++++++++++---- 4 files changed, 56 insertions(+), 35 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +27 -21
@@ -78,33 +78,39 @@* generic accessors and iterators here */ #define __real_pte __real_pte -static inline real_pte_t __real_pte (unsigned long addr,pte_t pte,pte_t *ptep) -{ -real_pte_t rpte; - - rpte.pte = pte; - rpte.hidx =0 ; -if (pte_val (pte) & _PAGE_COMBO) { -/* -* Make sure we order the hidx load against the _PAGE_COMBO -* check. The store side ordering is done in __hash_page_4K -*/ -smp_rmb (); - rpte.hidx =pte_val (*((ptep) +PTRS_PER_PTE )); - } -return rpte; -} - +extern real_pte_t __real_pte (unsigned long addr,pte_t pte,pte_t *ptep);static inline unsigned long __rpte_to_hidx (real_pte_t rpte,unsigned long index) {if ((pte_val (rpte.pte) & _PAGE_COMBO)) -return (rpte.hidx >> (index<<2 )) &0xf ; +return (unsigned long ) rpte.hidx[index] >>4 ;return (pte_val (rpte.pte) >>12 ) &0xf ; } -#define __rpte_to_pte (r) ((r).pte) -#define __rpte_sub_valid (rpte, index) \ - (pte_val(rpte.pte) & (_PAGE_HPTE_SUB0 >> (index))) +static inline pte_t __rpte_to_pte (real_pte_t rpte) +{ +return rpte.pte; +} +/* +* we look at the second half of the pte page to determine whether +* the sub 4k hpte is valid. We use 8 bits per each index, and we have +* 16 index mapping full 64K page. Hence for each +* 64K linux page we use 128 bit from the second half of pte page. +* The encoding in the second half of the page is as below: +* [ index 15 ] .........................[index 0] +* [bit 127 ..................................bit 0] +* fomat of each index +* bit 7 ........ bit0 +* [one bit secondary][ 3 bit hidx][1 bit valid][000] +*/ +static inline bool __rpte_sub_valid (real_pte_t rpte,unsigned long index) +{ +unsigned char index_val = rpte.hidx[index]; + +if ((index_val >>3 ) &0x1 ) +return true; +return false; +} +/* * Trick: we set __end to va + 64k, which happens works for * a 16M page as well as we want only one iteration
arch/powerpc/include/asm/book3s/64/hash.h +0 -5
@@ -214,11 +214,6 @@#define PMD_BAD_BITS (PTE_TABLE_SIZE-1)#define PUD_BAD_BITS (PMD_TABLE_SIZE-1) -/* -* We save the slot number & secondary bit in the second half of the -* PTE page. We use the 8 bytes per each pte entry. -*/ -#define PTE_PAGE_HIDX_OFFSET (PTRS_PER_PTE * 8)#ifndef __ASSEMBLY__#define pmd_bad (pmd) (!is_kernel_addr(pmd_val(pmd)) \
arch/powerpc/include/asm/page.h +2 -2
@@ -293,7 +293,7 @@ static inline pte_basic_t pte_val(pte_t x)* the "second half" part of the PTE for pseudo 64k pages */ #if defined(CONFIG_PPC_64K_PAGES ) && defined(CONFIG_PPC_STD_MMU_64 ) -typedef struct {pte_t pte;unsigned long hidx; }real_pte_t ; +typedef struct {pte_t pte;unsigned char *hidx; }real_pte_t ;#else typedef struct {pte_t pte; }real_pte_t ;#endif
@@ -345,7 +345,7 @@ static inline pte_basic_t pte_val(pte_t pte) }#if defined(CONFIG_PPC_64K_PAGES ) && defined(CONFIG_PPC_STD_MMU_64 ) -typedef struct {pte_t pte;unsigned long hidx; }real_pte_t ; +typedef struct {pte_t pte;unsigned char *hidx; }real_pte_t ;#else typedef pte_t real_pte_t ;#endif
arch/powerpc/mm/hash64_64k.c +27 -7
@@ -16,12 +16,32 @@#include <asm/machdep.h> #include <asm/mmu.h> +real_pte_t __real_pte (unsigned long addr,pte_t pte,pte_t *ptep) +{ +int indx; +real_pte_t rpte; +pte_t *pte_headp; + + rpte.pte = pte; + rpte.hidx =NULL ; +if (pte_val (pte) & _PAGE_COMBO) { + indx =pte_index (addr); + pte_headp = ptep - indx; +/* +* Make sure we order the hidx load against the _PAGE_COMBO +* check. The store side ordering is done in __hash_page_4K +*/ +smp_rmb (); + rpte.hidx = (unsigned char *)(pte_headp +PTRS_PER_PTE ) + (16 * indx); + } +return rpte; +} +int __hash_page_4K (unsigned long ea,unsigned long access,unsigned long vsid,pte_t *ptep,unsigned long trap,unsigned long flags,int ssize,int subpg_prot) {real_pte_t rpte; -unsigned long *hidxp;unsigned long hpte_group;unsigned int subpg_index;unsigned long shift =12 ;/* 4K */
@@ -90,7 +110,10 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid, subpg_index = (ea & (PAGE_SIZE -1 )) >> shift; vpn =hpt_vpn (ea, vsid, ssize); - rpte =__real_pte (ea,__pte (old_pte), ptep); +if (!(old_pte & _PAGE_COMBO)) + rpte =__real_pte (ea,__pte (old_pte | _PAGE_COMBO), ptep); +else + rpte =__real_pte (ea,__pte (old_pte), ptep);/* *None of the sub 4k page is hashed */
@@ -188,11 +211,8 @@ repeat:* Since we have _PAGE_BUSY set on ptep, we can be sure * nobody is undating hidx. */ - hidxp = (unsigned long *)(ptep +PTRS_PER_PTE ); -/* __real_pte use pte_val() any idea why ? FIXME!! */ - rpte.hidx &= ~(0xfUL << (subpg_index <<2 )); - *hidxp = rpte.hidx | (slot << (subpg_index <<2 )); - new_pte |= (_PAGE_HPTE_SUB0 >> subpg_index); + rpte.hidx[subpg_index] = (unsigned char )(slot <<4 |0x1 <<3 ); + new_pte |= _PAGE_HPTE_SUB0;/* * check __real_pte for details on matching smp_rmb() */
Signature · 1 line
2.5.0
PATCH v2 22/31 powerpc/mm: Don't track subpage valid bit in pte_t
In reply to Aneesh Kumar K.VThis free up 11 bits in pte_t. In the later patch we also change the pte_t format so that we can start supporting migration pte at pmd level.
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 10 +-------- arch/powerpc/include/asm/book3s/64/hash-64k.h | 29 ++------------------------- arch/powerpc/include/asm/book3s/64/hash.h | 4 ++++ arch/powerpc/mm/hash64_64k.c | 4 ++-- arch/powerpc/mm/hash_low_64.S | 6 +----- arch/powerpc/mm/hugetlbpage-hash64.c | 5 +---- arch/powerpc/mm/pgtable_64.c | 2 +- 7 files changed, 12 insertions(+), 48 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +1 -9
@@ -47,17 +47,9 @@/* Bits to mask out from a PGD to get to the PUD page */ #define PGD_MASKED_BITS 0 -/* PTE bits */ -#define _PAGE_HASHPTE 0x0400/* software: pte has an associated HPTE */ -#define _PAGE_SECONDARY 0x8000/* software: HPTE is in secondary group */ -#define _PAGE_GROUP_IX 0x7000/* software: HPTE index within group */ -#define _PAGE_F_SECOND _PAGE_SECONDARY -#define _PAGE_F_GIX _PAGE_GROUP_IX -#define _PAGE_SPECIAL 0x10000/* software: special page */ -/* PTE flags to conserve for HPTE identification */ #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | \ - _PAGE_SECONDARY | _PAGE_GROUP_IX) + _PAGE_F_SECOND | _PAGE_F_GIX)/* shift to put page number into pte */ #define PTE_RPN_SHIFT (17)
arch/powerpc/include/asm/book3s/64/hash-64k.h +2 -27
@@ -31,33 +31,8 @@/* Bits to mask out from a PGD/PUD to get to the PMD page */ #define PUD_MASKED_BITS 0x1ff -/* Additional PTE bits (don't change without checking asm in hash_low.S) */ -#define _PAGE_SPECIAL 0x00000400/* software: special page */ -#define _PAGE_HPTE_SUB 0x0ffff000/* combo only: sub pages HPTE bits */ -#define _PAGE_HPTE_SUB0 0x08000000/* combo only: first sub page */ -#define _PAGE_COMBO 0x10000000/* this is a combo 4k page */ -#define _PAGE_4K_PFN 0x20000000/* PFN is for a single 4k page */ - -/* For 64K page, we don't have a separate _PAGE_HASHPTE bit. Instead, -* we set that to be the whole sub-bits mask. The C code will only -* test this, so a multi-bit mask will work. For combo pages, this -* is equivalent as effectively, the old _PAGE_HASHPTE was an OR of -* all the sub bits. For real 64k pages, we now have the assembly set -* _PAGE_HPTE_SUB0 in addition to setting the HIDX bits which overlap -* that mask. This is fine as long as the HIDX bits are never set on -* a PTE that isn't hashed, which is the case today. -* -* A little nit is for the huge page C code, which does the hashing -* in C, we need to provide which bit to use. -*/ -#define _PAGE_HASHPTE _PAGE_HPTE_SUB - -/* Note the full page bits must be in the same location as for normal -* 4k pages as the same assembly will be used to insert 64K pages -* whether the kernel has CONFIG_PPC_64K_PAGES or not -*/ -#define _PAGE_F_SECOND 0x00008000/* full page: hidx bits */ -#define _PAGE_F_GIX 0x00007000/* full page: hidx bits */ +#define _PAGE_COMBO 0x00020000/* this is a combo 4k page */ +#define _PAGE_4K_PFN 0x00040000/* PFN is for a single 4k page */ /* PTE flags to conserve for HPTE identification */ #define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_COMBO)
arch/powerpc/include/asm/book3s/64/hash.h +4 -0
@@ -83,7 +83,11 @@#define _PAGE_DIRTY 0x0080/* C: page changed */ #define _PAGE_ACCESSED 0x0100/* R: page referenced */ #define _PAGE_RW 0x0200/* software: user write access allowed */ +#define _PAGE_HASHPTE 0x0400/* software: pte has an associated HPTE */ #define _PAGE_BUSY 0x0800/* software: PTE & hash are busy */ +#define _PAGE_F_GIX 0x7000/* full page: hidx bits */ +#define _PAGE_F_SECOND 0x8000/* Whether to use secondary hash or not */ +#define _PAGE_SPECIAL 0x10000/* software: special page */ /* No separate kernel read-only */ #define _PAGE_KERNEL_RW (_PAGE_RW | _PAGE_DIRTY)/* user access blocked by key */
arch/powerpc/mm/hash64_64k.c +2 -2
@@ -125,7 +125,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,*/ if (!(old_pte & _PAGE_COMBO)) {flush_hash_page (vpn, rpte,MMU_PAGE_64K , ssize, flags); - old_pte &= ~_PAGE_HPTE_SUB; + old_pte &= ~_PAGE_HASHPTE | _PAGE_F_GIX | _PAGE_F_SECOND; goto htab_insert_hpte; }/*
@@ -212,7 +212,7 @@ repeat:* nobody is undating hidx. */ rpte.hidx[subpg_index] = (unsigned char )(slot <<4 |0x1 <<3 ); - new_pte |= _PAGE_HPTE_SUB0; + new_pte |= _PAGE_HASHPTE;/* * check __real_pte for details on matching smp_rmb() */
arch/powerpc/mm/hash_low_64.S +1 -5
@@ -285,7 +285,7 @@ htab_modify_pte: /* Secondary group ? if yes, get a inverted hash value */ mr r5,r28 - andi. r0,r31,_PAGE_SECONDARY + andi. r0,r31,_PAGE_F_SECOND beq 1f not r5,r5 1:
@@ -473,11 +473,7 @@ ht64_insert_pte: lis r0,_PAGE_HPTEFLAGS@h ori r0,r0,_PAGE_HPTEFLAGS@l andc r30,r30,r0 -#ifdef CONFIG_PPC_64K_PAGES - oris r30,r30,_PAGE_HPTE_SUB0@h -#else ori r30,r30,_PAGE_HASHPTE -#endif /* Phyical address in r5 */ rldicl r5,r31,64-PTE_RPN_SHIFT,PTE_RPN_SHIFT sldi r5,r5,PAGE_SHIFT
arch/powerpc/mm/hugetlbpage-hash64.c +1 -4
@@ -91,11 +91,8 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, pa =pte_pfn (__pte (old_pte)) <<PAGE_SHIFT ;/* clear HPTE slot informations in new PTE */ -#ifdef CONFIG_PPC_64K_PAGES - new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | _PAGE_HPTE_SUB0; -#else new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | _PAGE_HASHPTE; -#endif +/* Add in WIMG bits */ rflags |= (new_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | _PAGE_COHERENT | _PAGE_GUARDED));
arch/powerpc/mm/pgtable_64.c +1 -1
@@ -625,7 +625,7 @@ void pmdp_splitting_flush(struct vm_area_struct *vma,"1: ldarx %0,0,%3\n\ andi. %1,%0,%6\n\ bne- 1b \n\ -ori %1,%0,%4 \n\ +oris %1,%0,%4@h \n\ stdcx. %1,0,%3 \n\ bne- 1b" : "=&r" (old), "=&r" (tmp), "=m" (*pmdp)
Signature · 1 line
2.5.0
PATCH v2 23/31 powerpc/mm: Increase the width of #define
In reply to Aneesh Kumar K.VNo real change, only style changes
--- arch/powerpc/include/asm/book3s/64/hash.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h +13 -13
@@ -71,22 +71,22 @@* We could create separate kernel read-only if we used the 3 PP bits * combinations that newer processors provide but we currently don't. */ -#define _PAGE_PRESENT 0x0001/* software: pte contains a translation */ -#define _PAGE_USER 0x0002/* matches one of the PP bits */ +#define _PAGE_PRESENT 0x00001/* software: pte contains a translation */ +#define _PAGE_USER 0x00002/* matches one of the PP bits */ #define _PAGE_BIT_SWAP_TYPE 2 -#define _PAGE_EXEC 0x0004/* No execute on POWER4 and newer (we invert) */ -#define _PAGE_GUARDED 0x0008 +#define _PAGE_EXEC 0x00004/* No execute on POWER4 and newer (we invert) */ +#define _PAGE_GUARDED 0x00008/* We can derive Memory coherence from _PAGE_NO_CACHE */ #define _PAGE_COHERENT 0x0 -#define _PAGE_NO_CACHE 0x0020/* I: cache inhibit */ -#define _PAGE_WRITETHRU 0x0040/* W: cache write-through */ -#define _PAGE_DIRTY 0x0080/* C: page changed */ -#define _PAGE_ACCESSED 0x0100/* R: page referenced */ -#define _PAGE_RW 0x0200/* software: user write access allowed */ -#define _PAGE_HASHPTE 0x0400/* software: pte has an associated HPTE */ -#define _PAGE_BUSY 0x0800/* software: PTE & hash are busy */ -#define _PAGE_F_GIX 0x7000/* full page: hidx bits */ -#define _PAGE_F_SECOND 0x8000/* Whether to use secondary hash or not */ +#define _PAGE_NO_CACHE 0x00020/* I: cache inhibit */ +#define _PAGE_WRITETHRU 0x00040/* W: cache write-through */ +#define _PAGE_DIRTY 0x00080/* C: page changed */ +#define _PAGE_ACCESSED 0x00100/* R: page referenced */ +#define _PAGE_RW 0x00200/* software: user write access allowed */ +#define _PAGE_HASHPTE 0x00400/* software: pte has an associated HPTE */ +#define _PAGE_BUSY 0x00800/* software: PTE & hash are busy */ +#define _PAGE_F_GIX 0x07000/* full page: hidx bits */ +#define _PAGE_F_SECOND 0x08000/* Whether to use secondary hash or not */ #define _PAGE_SPECIAL 0x10000/* software: special page */ /* No separate kernel read-only */
Signature · 1 line
2.5.0
PATCH v2 24/31 powerpc/mm: Convert __hash_page_64K to C
In reply to Aneesh Kumar K.VConvert from asm to C
--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 3 +- arch/powerpc/include/asm/book3s/64/hash.h | 1 + arch/powerpc/mm/hash64_64k.c | 134 +++++++++++- arch/powerpc/mm/hash_low_64.S | 290 +------------------------- arch/powerpc/mm/hash_utils_64.c | 19 +- 5 files changed, 137 insertions(+), 310 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +2 -1
@@ -35,7 +35,8 @@#define _PAGE_4K_PFN 0x00040000/* PFN is for a single 4k page */ /* PTE flags to conserve for HPTE identification */ -#define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | _PAGE_COMBO) +#define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_F_SECOND | \ + _PAGE_F_GIX | _PAGE_HASHPTE | _PAGE_COMBO)/* Shift to put page number into pte. *
arch/powerpc/include/asm/book3s/64/hash.h +1 -0
@@ -86,6 +86,7 @@#define _PAGE_HASHPTE 0x00400/* software: pte has an associated HPTE */ #define _PAGE_BUSY 0x00800/* software: PTE & hash are busy */ #define _PAGE_F_GIX 0x07000/* full page: hidx bits */ +#define _PAGE_F_GIX_SHIFT 12#define _PAGE_F_SECOND 0x08000/* Whether to use secondary hash or not */ #define _PAGE_SPECIAL 0x10000/* software: special page */
arch/powerpc/mm/hash64_64k.c +132 -2
152 lines not on this page · raw message
arch/powerpc/mm/hash_low_64.S +1 -289
293 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +1 -18
@@ -633,28 +633,11 @@ extern u32 htab_call_hpte_insert1[];extern u32 htab_call_hpte_insert2[];extern u32 htab_call_hpte_remove[];extern u32 htab_call_hpte_updatepp[]; -extern u32 ht64_call_hpte_insert1[]; -extern u32 ht64_call_hpte_insert2[]; -extern u32 ht64_call_hpte_remove[]; -extern u32 ht64_call_hpte_updatepp[];static void __init htab_finish_init (void ) { -#ifdef CONFIG_PPC_64K_PAGES -patch_branch (ht64_call_hpte_insert1, -ppc_function_entry (ppc_md.hpte_insert), -BRANCH_SET_LINK ); -patch_branch (ht64_call_hpte_insert2, -ppc_function_entry (ppc_md.hpte_insert), -BRANCH_SET_LINK ); -patch_branch (ht64_call_hpte_remove, -ppc_function_entry (ppc_md.hpte_remove), -BRANCH_SET_LINK ); -patch_branch (ht64_call_hpte_updatepp, -ppc_function_entry (ppc_md.hpte_updatepp), -BRANCH_SET_LINK ); -#else /* !CONFIG_PPC_64K_PAGES */ +#ifdef CONFIG_PPC_4K_PAGES patch_branch (htab_call_hpte_insert1,ppc_function_entry (ppc_md.hpte_insert),BRANCH_SET_LINK );
Signature · 1 line
2.5.0
PATCH v2 25/31 powerpc/mm: Convert 4k insert from asm to C
In reply to Aneesh Kumar K.VThis is similar to 64K insert. May be we want to consolidate
--- arch/powerpc/mm/Makefile | 6 +- arch/powerpc/mm/hash64_4k.c | 139 +++++++++++++++++ arch/powerpc/mm/hash_low_64.S | 331 ---------------------------------------- arch/powerpc/mm/hash_utils_64.c | 26 ---- 4 files changed, 142 insertions(+), 360 deletions(-) create mode 100644 arch/powerpc/mm/hash64_4k.c delete mode 100644 arch/powerpc/mm/hash_low_64.S
arch/powerpc/mm/Makefile +3 -3
@@ -14,11 +14,11 @@ obj-$(CONFIG_PPC_MMU_NOHASH) += mmu_context_nohash.o tlb_nohash.o \ obj-$(CONFIG_PPC_BOOK3E) += tlb_low_$(CONFIG_WORD_SIZE)e.o hash64-$(CONFIG_PPC_NATIVE) := hash_native_64.o obj-$(CONFIG_PPC_STD_MMU_64) += hash_utils_64.o slb_low.o slb.o $(hash64-y) -obj-$(CONFIG_PPC_STD_MMU_32) += ppc_mmu_32.o -obj-$(CONFIG_PPC_STD_MMU) += hash_low_$(CONFIG_WORD_SIZE).o \ - tlb_hash$(CONFIG_WORD_SIZE).o \ +obj-$(CONFIG_PPC_STD_MMU_32) += ppc_mmu_32.o hash_low_32.o +obj-$(CONFIG_PPC_STD_MMU) += tlb_hash$(CONFIG_WORD_SIZE).o \ mmu_context_hash$(CONFIG_WORD_SIZE).o ifeq ($(CONFIG_PPC_STD_MMU_64),y) +obj-$(CONFIG_PPC_4K_PAGES) += hash64_4k.o obj-$(CONFIG_PPC_64K_PAGES) += hash64_64k.o endif obj-$(CONFIG_PPC_ICSWX) += icswx.o
arch/powerpc/mm/hash64_4k.c new file +139 -0
139 lines not on this page · raw message
arch/powerpc/mm/hash_low_64.S deleted +0 -331
331 lines not on this page · raw message
arch/powerpc/mm/hash_utils_64.c +0 -26
@@ -629,31 +629,6 @@ int remove_section_mapping(unsigned long start, unsigned long end) }#endif /* CONFIG_MEMORY_HOTPLUG */ -extern u32 htab_call_hpte_insert1[]; -extern u32 htab_call_hpte_insert2[]; -extern u32 htab_call_hpte_remove[]; -extern u32 htab_call_hpte_updatepp[]; - -static void __init htab_finish_init (void ) -{ - -#ifdef CONFIG_PPC_4K_PAGES -patch_branch (htab_call_hpte_insert1, -ppc_function_entry (ppc_md.hpte_insert), -BRANCH_SET_LINK ); -patch_branch (htab_call_hpte_insert2, -ppc_function_entry (ppc_md.hpte_insert), -BRANCH_SET_LINK ); -patch_branch (htab_call_hpte_remove, -ppc_function_entry (ppc_md.hpte_remove), -BRANCH_SET_LINK ); -patch_branch (htab_call_hpte_updatepp, -ppc_function_entry (ppc_md.hpte_updatepp), -BRANCH_SET_LINK ); -#endif - -} -static void __init htab_initialize (void ) {unsigned long table;
@@ -800,7 +775,6 @@ static void __init htab_initialize(void) mmu_linear_psize, mmu_kernel_ssize)); } -htab_finish_init ();DBG (" <- htab_initialize()\n" ); }
Signature · 1 line
2.5.0
PATCH v2 26/31 powerpc/mm: Remove the dependency on pte bit position in asm code
In reply to Aneesh Kumar K.VWe should not expect pte bit position in asm code. Simply by moving part of that to C
--- arch/powerpc/kernel/exceptions-64s.S | 16 +++------------- arch/powerpc/mm/hash_utils_64.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +3 -13
@@ -1556,28 +1556,18 @@ do_hash_page: lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */ andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */ bne 77f /* then don't call hash_page now */ - /* - * We need to set the _PAGE_USER bit if MSR_PR is set or if we are - * accessing a userspace segment (even from the kernel). We assume - * kernel addresses always have the high bit set. - */ - rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */ - rotldi r0,r3,15 /* Move high bit into MSR_PR posn */ - orc r0,r12,r0 /* MSR_PR | ~high_bit */ - rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */ - ori r4,r4,1 /* add _PAGE_PRESENT */ - rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */ /* * r3 contains the faulting address - * r4 contains the required access permissions + * r4 msr * r5 contains the trap number * r6 contains dsisr * * at return r3 = 0 for success, 1 for page fault, negative for error */ + mr r4,r12 ld r6,_DSISR(r1) - bl hash_page /* build HPTE if possible */ + bl __hash_page /* build HPTE if possible */ cmpdi r3,0 /* see if hash_page succeeded */ /* Success */
arch/powerpc/mm/hash_utils_64.c +29 -0
@@ -1161,6 +1161,35 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap, }EXPORT_SYMBOL_GPL (hash_page); +int __hash_page (unsigned long ea,unsigned long msr,unsigned long trap, +unsigned long dsisr) +{ +unsigned long access = _PAGE_PRESENT; +unsigned long flags =0 ; +struct mm_struct *mm = current->mm; + +if (REGION_ID (ea) ==VMALLOC_REGION_ID ) + mm = &init_mm; + +if (dsisr &DSISR_NOHPTE ) + flags |=HPTE_NOHPTE_UPDATE ; + +if (dsisr &DSISR_ISSTORE ) + access |= _PAGE_RW; +/* +* We need to set the _PAGE_USER bit if MSR_PR is set or if we are +* accessing a userspace segment (even from the kernel). We assume +* kernel addresses always have the high bit set. +*/ +if ((msr &MSR_PR ) || (REGION_ID (ea) ==USER_REGION_ID )) + access |= _PAGE_USER; + +if (trap ==0x400 ) + access |= _PAGE_EXEC; + +return hash_page_mm (mm, ea, access, trap, flags); +} +void hash_preload (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {
Signature · 1 line
2.5.0
Re: [PATCH V2 26/31] powerpc/mm: Remove the dependency on pte bit position in asm code
Quoted 2 lines · Aneesh Kumar K.V
We should not expect pte bit position in asm code. Simply by moving part of that to C
I guess this does not depend on the new code changes and can simply be part of the preparatory patches at the beginning.
PATCH v2 27/31 powerpc/mm: Add helper for converting pte bit to hpte bits
In reply to Aneesh Kumar K.VInstead of open coding it in multiple code paths, export the helper and add more documentation. Also make sure we don't make assumption regarding pte bit position
--- arch/powerpc/include/asm/book3s/64/hash.h | 1 + arch/powerpc/mm/hash64_4k.c | 13 +----------- arch/powerpc/mm/hash64_64k.c | 35 +++---------------------------- arch/powerpc/mm/hash_utils_64.c | 22 ++++++++++++------- arch/powerpc/mm/hugepage-hash64.c | 13 +----------- arch/powerpc/mm/hugetlbpage-hash64.c | 4 +--- 6 files changed, 21 insertions(+), 67 deletions(-)
arch/powerpc/include/asm/book3s/64/hash.h +1 -0
@@ -242,6 +242,7 @@ extern unsigned long pmd_hugepage_update(struct mm_struct *mm,pmd_t *pmdp, unsigned long clr, unsigned long set); +extern unsigned long htab_convert_pte_flags (unsigned long pteflags);/* Atomic PTE updates */ static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
arch/powerpc/mm/hash64_4k.c +1 -12
@@ -53,18 +53,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,* PP bits. _PAGE_USER is already PP bit 0x2, so we only * need to add in 0x1 if it's a read-only user page */ - rflags = new_pte & _PAGE_USER; -if ((new_pte & _PAGE_USER) && !((new_pte & _PAGE_RW) && - (new_pte & _PAGE_DIRTY))) - rflags |=0x1 ; -/* -* _PAGE_EXEC -> HW_NO_EXEC since it's inverted -*/ - rflags |= ((new_pte & _PAGE_EXEC) ?0 :HPTE_R_N ); -/* -* Always add C and Memory coherence bit -*/ - rflags |=HPTE_R_C |HPTE_R_M ; + rflags =htab_convert_pte_flags (new_pte);/* * Add in WIMG bits */
arch/powerpc/mm/hash64_64k.c +3 -32
@@ -76,22 +76,7 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,* Handle the subpage protection bits */ subpg_pte = new_pte & ~subpg_prot; -/* -* PP bits. _PAGE_USER is already PP bit 0x2, so we only -* need to add in 0x1 if it's a read-only user page -*/ - rflags = subpg_pte & _PAGE_USER; -if ((subpg_pte & _PAGE_USER) && !((subpg_pte & _PAGE_RW) && - (subpg_pte & _PAGE_DIRTY))) - rflags |=0x1 ; -/* -* _PAGE_EXEC -> HW_NO_EXEC since it's inverted -*/ - rflags |= ((subpg_pte & _PAGE_EXEC) ?0 :HPTE_R_N ); -/* -* Always add C and Memory coherence bit -*/ - rflags |=HPTE_R_C |HPTE_R_M ; + rflags =htab_convert_pte_flags (subpg_pte);/* * Add in WIMG bits */
@@ -262,22 +247,8 @@ int __hash_page_64K(unsigned long ea, unsigned long access, new_pte |= _PAGE_DIRTY; }while (old_pte !=__cmpxchg_u64 ((unsigned long *)ptep, old_pte, new_pte)); -/* -* PP bits. _PAGE_USER is already PP bit 0x2, so we only -* need to add in 0x1 if it's a read-only user page -*/ - rflags = new_pte & _PAGE_USER; -if ((new_pte & _PAGE_USER) && !((new_pte & _PAGE_RW) && - (new_pte & _PAGE_DIRTY))) - rflags |=0x1 ; -/* -* _PAGE_EXEC -> HW_NO_EXEC since it's inverted -*/ - rflags |= ((new_pte & _PAGE_EXEC) ?0 :HPTE_R_N ); -/* -* Always add C and Memory coherence bit -*/ - rflags |=HPTE_R_C |HPTE_R_M ; + + rflags =htab_convert_pte_flags (new_pte);/* * Add in WIMG bits */
arch/powerpc/mm/hash_utils_64.c +14 -8
@@ -159,20 +159,26 @@ static struct mmu_psize_def mmu_psize_defaults_gp[] = { }, }; -static unsigned long htab_convert_pte_flags (unsigned long pteflags) +unsigned long htab_convert_pte_flags (unsigned long pteflags) { -unsigned long rflags = pteflags &0x1fa ; +unsigned long rflags =0 ;/* _PAGE_EXEC -> NOEXEC */ if ((pteflags & _PAGE_EXEC) ==0 ) rflags |=HPTE_R_N ; - -/* PP bits. PAGE_USER is already PP bit 0x2, so we only -* need to add in 0x1 if it's a read-only user page +/* +* PP bits: +* Linux use slb key 0 for kernel and 1 for user. +* kernel areas are mapped by PP bits 00 +* and and there is no kernel RO (_PAGE_KERNEL_RO). +* User area mapped by 0x2 and read only use by +* 0x3. */ -if ((pteflags & _PAGE_USER) && !((pteflags & _PAGE_RW) && - (pteflags & _PAGE_DIRTY))) - rflags |=1 ; +if (pteflags & _PAGE_USER) { + rflags |=0x2 ; +if (!((pteflags & _PAGE_RW) && (pteflags & _PAGE_DIRTY))) + rflags |=0x1 ; + }/* * Always add "C" bit for perf. Memory coherence is always enabled */
arch/powerpc/mm/hugepage-hash64.c +1 -12
@@ -54,18 +54,7 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, new_pmd |= _PAGE_DIRTY; }while (old_pmd !=__cmpxchg_u64 ((unsigned long *)pmdp, old_pmd, new_pmd)); -/* -* PP bits. _PAGE_USER is already PP bit 0x2, so we only -* need to add in 0x1 if it's a read-only user page -*/ - rflags = new_pmd & _PAGE_USER; -if ((new_pmd & _PAGE_USER) && !((new_pmd & _PAGE_RW) && - (new_pmd & _PAGE_DIRTY))) - rflags |=0x1 ; -/* -* _PAGE_EXEC -> HW_NO_EXEC since it's inverted -*/ - rflags |= ((new_pmd & _PAGE_EXEC) ?0 :HPTE_R_N ); + rflags =htab_convert_pte_flags (new_pmd);#if 0 if (!cpu_has_feature (CPU_FTR_COHERENT_ICACHE )) {
arch/powerpc/mm/hugetlbpage-hash64.c +1 -3
@@ -59,10 +59,8 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, new_pte |= _PAGE_DIRTY; }while (old_pte !=__cmpxchg_u64 ((unsigned long *)ptep, old_pte, new_pte)); + rflags =htab_convert_pte_flags (new_pte); - rflags =0x2 | (!(new_pte & _PAGE_RW)); -/* _PAGE_EXEC -> HW_NO_EXEC since it's inverted */ - rflags |= ((new_pte & _PAGE_EXEC) ?0 :HPTE_R_N ); sz = ((1UL ) << shift);if (!cpu_has_feature (CPU_FTR_COHERENT_ICACHE ))/* No CPU has hugepages but lacks no execute, so we
Signature · 1 line
2.5.0
PATCH v2 28/31 powerpc/mm: Move WIMG update to helper.
In reply to Aneesh Kumar K.VOnly difference here is, we apply the WIMG mapping early, so rflags passed to updatepp will also be changed.
--- arch/powerpc/mm/hash64_4k.c | 5 ----- arch/powerpc/mm/hash64_64k.c | 10 ---------- arch/powerpc/mm/hash_utils_64.c | 13 ++++++++++++- arch/powerpc/mm/hugepage-hash64.c | 7 ------- arch/powerpc/mm/hugetlbpage-hash64.c | 8 -------- 5 files changed, 12 insertions(+), 31 deletions(-)
arch/powerpc/mm/hash64_4k.c +0 -5
@@ -54,11 +54,6 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,* need to add in 0x1 if it's a read-only user page */ rflags =htab_convert_pte_flags (new_pte); -/* -* Add in WIMG bits -*/ - rflags |= (new_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | - _PAGE_COHERENT | _PAGE_GUARDED));if (!cpu_has_feature (CPU_FTR_NOEXECUTE ) && !cpu_has_feature (CPU_FTR_COHERENT_ICACHE ))
arch/powerpc/mm/hash64_64k.c +0 -10
@@ -77,11 +77,6 @@ int __hash_page_4K(unsigned long ea, unsigned long access, unsigned long vsid,*/ subpg_pte = new_pte & ~subpg_prot; rflags =htab_convert_pte_flags (subpg_pte); -/* -* Add in WIMG bits -*/ - rflags |= (subpg_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | - _PAGE_COHERENT | _PAGE_GUARDED));if (!cpu_has_feature (CPU_FTR_NOEXECUTE ) && !cpu_has_feature (CPU_FTR_COHERENT_ICACHE )) {
@@ -249,11 +244,6 @@ int __hash_page_64K(unsigned long ea, unsigned long access, old_pte, new_pte)); rflags =htab_convert_pte_flags (new_pte); -/* -* Add in WIMG bits -*/ - rflags |= (new_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | - _PAGE_COHERENT | _PAGE_GUARDED));if (!cpu_has_feature (CPU_FTR_NOEXECUTE ) && !cpu_has_feature (CPU_FTR_COHERENT_ICACHE ))
arch/powerpc/mm/hash_utils_64.c +12 -1
@@ -182,7 +182,18 @@ unsigned long htab_convert_pte_flags(unsigned long pteflags)/* * Always add "C" bit for perf. Memory coherence is always enabled */ -return rflags |HPTE_R_C |HPTE_R_M ; + rflags |=HPTE_R_C |HPTE_R_M ; +/* +* Add in WIG bits +*/ +if (pteflags & _PAGE_WRITETHRU) + rflags |=HPTE_R_W ; +if (pteflags & _PAGE_NO_CACHE) + rflags |=HPTE_R_I ; +if (pteflags & _PAGE_GUARDED) + rflags |=HPTE_R_G ; + +return rflags; } int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
arch/powerpc/mm/hugepage-hash64.c +0 -7
@@ -120,13 +120,6 @@ int __hash_page_thp(unsigned long ea, unsigned long access, unsigned long vsid, pa =pmd_pfn (__pmd (old_pmd)) <<PAGE_SHIFT ; new_pmd |= _PAGE_HASHPTE; -/* Add in WIMG bits */ - rflags |= (new_pmd & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | - _PAGE_GUARDED)); -/* -* enable the memory coherence always -*/ - rflags |=HPTE_R_M ; repeat: hpte_group = ((hash & htab_hash_mask) *HPTES_PER_GROUP ) & ~0x7UL ;
arch/powerpc/mm/hugetlbpage-hash64.c +0 -8
@@ -91,14 +91,6 @@ int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid,/* clear HPTE slot informations in new PTE */ new_pte = (new_pte & ~_PAGE_HPTEFLAGS) | _PAGE_HASHPTE; -/* Add in WIMG bits */ - rflags |= (new_pte & (_PAGE_WRITETHRU | _PAGE_NO_CACHE | - _PAGE_COHERENT | _PAGE_GUARDED)); -/* -* enable the memory coherence always -*/ - rflags |=HPTE_R_M ; - slot =hpte_insert_repeating (hash, vpn, pa, rflags,0 , mmu_psize, ssize);
Signature · 1 line
2.5.0
PATCH v2 29/31 powerpc/mm: Move hugetlb related headers
In reply to Aneesh Kumar K.VW.r.t hugetlb, we support two format for pmd. With book3s_64 and 64K linux page size, we can have pte at the pmd level. Hence we don't need to support hugepd there. For everything else hugepd is supported and pmd_huge is (0).
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 31 ++++++++++++++++ arch/powerpc/include/asm/book3s/64/hash-64k.h | 40 ++++++++++++++++++++ arch/powerpc/include/asm/nohash/pgtable.h | 25 +++++++++++++ arch/powerpc/include/asm/page.h | 27 ++------------ arch/powerpc/mm/hugetlbpage.c | 53 --------------------------- 5 files changed, 100 insertions(+), 76 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +31 -0
@@ -93,6 +93,37 @@ extern struct page *pgd_page(pgd_t pgd);#define remap_4k_pfn (vma, addr, pfn, prot) \ remap_pfn_range((vma), (addr), (pfn), PAGE_SIZE, (prot)) +#ifdef CONFIG_HUGETLB_PAGE +/* +* For 4k page size, we support explicit hugepage via hugepd +*/ +static inline int pmd_huge (pmd_t pmd) +{ +return 0 ; +} + +static inline int pud_huge (pud_t pud) +{ +return 0 ; +} + +static inline int pgd_huge (pgd_t pgd) +{ +return 0 ; +} +#define pgd_huge pgd_huge + +static inline int hugepd_ok (hugepd_t hpd) +{ +/* +* hugepd pointer, bottom two bits == 00 and next 4 bits +* indicate size of table +*/ +return (((hpd.pd &0x3 ) ==0x0 ) && ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )); +} +#define is_hugepd (hpd) (hugepd_ok(hpd)) +#endif +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_4K_H */
arch/powerpc/include/asm/book3s/64/hash-64k.h +40 -0
@@ -119,6 +119,46 @@ static inline bool __rpte_sub_valid(real_pte_t rpte, unsigned long index)#define pgd_pte (pgd) (pud_pte(((pud_t){ pgd })))#define pte_pgd (pte) ((pgd_t)pte_pud(pte)) +#ifdef CONFIG_HUGETLB_PAGE +/* +* We have PGD_INDEX_SIZ = 12 and PTE_INDEX_SIZE = 8, so that we can have +* 16GB hugepage pte in PGD and 16MB hugepage pte at PMD; +* +* Defined in such a way that we can optimize away code block at build time +* if CONFIG_HUGETLB_PAGE=n. +*/ +static inline int pmd_huge (pmd_t pmd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return ((pmd_val (pmd) &0x3 ) !=0x0 ); +} + +static inline int pud_huge (pud_t pud) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return ((pud_val (pud) &0x3 ) !=0x0 ); +} + +static inline int pgd_huge (pgd_t pgd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return ((pgd_val (pgd) &0x3 ) !=0x0 ); +} +#define pgd_huge pgd_huge + +static inline int hugepd_ok (hugepd_t hpd) +{ +return 0 ; +} +#define is_hugepd (pdep) 0 +#endif /* CONFIG_HUGETLB_PAGE */ +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */
arch/powerpc/include/asm/nohash/pgtable.h +25 -0
@@ -223,5 +223,30 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, unsigned long size, pgprot_t vma_prot);#define __HAVE_PHYS_MEM_ACCESS_PROT +#ifdef CONFIG_HUGETLB_PAGE +static inline int hugepd_ok (hugepd_t hpd) +{ +return (hpd.pd >0 ); +} + +static inline int pmd_huge (pmd_t pmd) +{ +return 0 ; +} + +static inline int pud_huge (pud_t pud) +{ +return 0 ; +} + +static inline int pgd_huge (pgd_t pgd) +{ +return 0 ; +} +#define pgd_huge pgd_huge + +#define is_hugepd (hpd) (hugepd_ok(hpd)) +#endif +#endif /* __ASSEMBLY__ */ #endif
arch/powerpc/include/asm/page.h +4 -23
@@ -384,30 +384,11 @@ typedef unsigned long pgprot_t;typedef struct {signed long pd; }hugepd_t ; -#ifdef CONFIG_HUGETLB_PAGE -#ifdef CONFIG_PPC_BOOK3S_64 -static inline int hugepd_ok (hugepd_t hpd) -{ -/* -* hugepd pointer, bottom two bits == 00 and next 4 bits -* indicate size of table -*/ -return (((hpd.pd &0x3 ) ==0x0 ) && ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )); -} -#else -static inline int hugepd_ok (hugepd_t hpd) -{ -return (hpd.pd >0 ); -} -#endif - -#define is_hugepd (hpd) (hugepd_ok(hpd)) -#define pgd_huge pgd_huge -int pgd_huge (pgd_t pgd); -#else /* CONFIG_HUGETLB_PAGE */ -#define is_hugepd (pdep) 0 -#define pgd_huge (pgd) 0 +#ifndef CONFIG_HUGETLB_PAGE +#define is_hugepd (pdep) (0) +#define pgd_huge (pgd) (0)#endif /* CONFIG_HUGETLB_PAGE */ +#define __hugepd (x) ((hugepd_t) { (x) })struct page ;
arch/powerpc/mm/hugetlbpage.c +0 -53
59 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 30/31 powerpc/mm: Move THP headers around
In reply to Aneesh Kumar K.VWe support THP only with book3s_64 and 64K page size. Move THP details to hash64-64k.h to clarify the same.
--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 126 +++++++++++++ arch/powerpc/include/asm/book3s/64/hash.h | 223 ++++++----------------- arch/powerpc/include/asm/nohash/64/pgtable.h | 245 +------------------------- arch/powerpc/mm/hash_native_64.c | 10 ++ arch/powerpc/mm/pgtable_64.c | 2 +- arch/powerpc/platforms/pseries/lpar.c | 10 ++ 6 files changed, 201 insertions(+), 415 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-64k.h +126 -0
@@ -159,6 +159,132 @@ static inline int hugepd_ok(hugepd_t hpd)#define is_hugepd (pdep) 0#endif /* CONFIG_HUGETLB_PAGE */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +extern unsigned long pmd_hugepage_update (struct mm_struct *mm, +unsigned long addr, +pmd_t *pmdp, +unsigned long clr, +unsigned long set); +static inline char *get_hpte_slot_array (pmd_t *pmdp) +{ +/* +* The hpte hindex is stored in the pgtable whose address is in the +* second half of the PMD +* +* Order this load with the test for pmd_trans_huge in the caller +*/ +smp_rmb (); +return *(char **)(pmdp +PTRS_PER_PMD ); + + +} +/* +* The linux hugepage PMD now include the pmd entries followed by the address +* to the stashed pgtable_t. The stashed pgtable_t contains the hpte bits. +* [ 1 bit secondary | 3 bit hidx | 1 bit valid | 000]. We use one byte per +* each HPTE entry. With 16MB hugepage and 64K HPTE we need 256 entries and +* with 4K HPTE we need 4096 entries. Both will fit in a 4K pgtable_t. +* +* The last three bits are intentionally left to zero. This memory location +* are also used as normal page PTE pointers. So if we have any pointers +* left around while we collapse a hugepage, we need to make sure +* _PAGE_PRESENT bit of that is zero when we look at them +*/ +static inline unsigned int hpte_valid (unsigned char *hpte_slot_array,int index) +{ +return (hpte_slot_array[index] >>3 ) &0x1 ; +} + +static inline unsigned int hpte_hash_index (unsigned char *hpte_slot_array, +int index) +{ +return hpte_slot_array[index] >>4 ; +} + +static inline void mark_hpte_slot_valid (unsigned char *hpte_slot_array, +unsigned int index,unsigned int hidx) +{ + hpte_slot_array[index] = hidx <<4 |0x1 <<3 ; +} + +/* +* +* For core kernel code by design pmd_trans_huge is never run on any hugetlbfs +* page. The hugetlbfs page table walking and mangling paths are totally +* separated form the core VM paths and they're differentiated by +* VM_HUGETLB being set on vm_flags well before any pmd_trans_huge could run. +* +* pmd_trans_huge() is defined as false at build time if +* CONFIG_TRANSPARENT_HUGEPAGE=n to optimize away code blocks at build +* time in such case. +* +* For ppc64 we need to differntiate from explicit hugepages from THP, because +* for THP we also track the subpage details at the pmd level. We don't do +* that for explicit huge pages. +* +*/ +static inline int pmd_trans_huge (pmd_t pmd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return (pmd_val (pmd) &0x3 ) && (pmd_val (pmd) & _PAGE_THP_HUGE); +} + +static inline int pmd_trans_splitting (pmd_t pmd) +{ +if (pmd_trans_huge (pmd)) +return pmd_val (pmd) & _PAGE_SPLITTING; +return 0 ; +} + +static inline int pmd_large (pmd_t pmd) +{ +/* +* leaf pte for huge page, bottom two bits != 00 +*/ +return ((pmd_val (pmd) &0x3 ) !=0x0 ); +} + +static inline pmd_t pmd_mknotpresent (pmd_t pmd) +{ +return __pmd (pmd_val (pmd) & ~_PAGE_PRESENT); +} + +static inline pmd_t pmd_mksplitting (pmd_t pmd) +{ +return __pmd (pmd_val (pmd) | _PAGE_SPLITTING); +} + +#define __HAVE_ARCH_PMD_SAME +static inline int pmd_same (pmd_t pmd_a,pmd_t pmd_b) +{ +return (((pmd_val (pmd_a) ^pmd_val (pmd_b)) & ~_PAGE_HPTEFLAGS) ==0 ); +} + +static inline int __pmdp_test_and_clear_young (struct mm_struct *mm, +unsigned long addr,pmd_t *pmdp) +{ +unsigned long old; + +if ((pmd_val (*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) ==0 ) +return 0 ; + old =pmd_hugepage_update (mm, addr, pmdp, _PAGE_ACCESSED,0 ); +return ((old & _PAGE_ACCESSED) !=0 ); +} + +#define __HAVE_ARCH_PMDP_SET_WRPROTECT +static inline void pmdp_set_wrprotect (struct mm_struct *mm,unsigned long addr, +pmd_t *pmdp) +{ + +if ((pmd_val (*pmdp) & _PAGE_RW) ==0 ) +return ; + +pmd_hugepage_update (mm, addr, pmdp, _PAGE_RW,0 ); +} + +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_BOOK3S_64_HASH_64K_H */
arch/powerpc/include/asm/book3s/64/hash.h +49 -174
253 lines not on this page · raw message
arch/powerpc/include/asm/nohash/64/pgtable.h +5 -240
255 lines not on this page · raw message
arch/powerpc/mm/hash_native_64.c +10 -0
@@ -429,6 +429,7 @@ static void native_hpte_invalidate(unsigned long slot, unsigned long vpn,local_irq_restore (flags); } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE static void native_hugepage_invalidate(unsigned long vsid, unsigned long addr, unsigned char *hpte_slot_array,
@@ -482,6 +483,15 @@ static void native_hugepage_invalidate(unsigned long vsid, }local_irq_restore (flags); } +#else +static void native_hugepage_invalidate (unsigned long vsid, +unsigned long addr, +unsigned char *hpte_slot_array, +int psize,int ssize,int local) +{ +WARN (1 ,"%s called without THP support\n" , __func__); +} +#endif static inline int __hpte_actual_psize (unsigned int lp,int psize) {
arch/powerpc/mm/pgtable_64.c +1 -1
@@ -359,7 +359,7 @@ struct page *pud_page(pud_t pud)struct page *pmd_page (pmd_t pmd) {if (pmd_trans_huge (pmd) ||pmd_huge (pmd)) -return pfn_to_page (pmd_pfn (pmd)); +return pte_page (pmd_pte (pmd));return virt_to_page (pmd_page_vaddr (pmd)); }
arch/powerpc/platforms/pseries/lpar.c +10 -0
@@ -396,6 +396,7 @@ static void pSeries_lpar_hpte_invalidate(unsigned long slot, unsigned long vpn,BUG_ON (lpar_rc !=H_SUCCESS ); } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * Limit iterations holding pSeries_lpar_tlbie_lock to 3. We also need * to make sure that we avoid bouncing the hypervisor tlbie lock.
@@ -494,6 +495,15 @@ static void pSeries_lpar_hugepage_invalidate(unsigned long vsid,__pSeries_lpar_hugepage_invalidate (slot_array, vpn_array, index, psize, ssize); } +#else +static void pSeries_lpar_hugepage_invalidate (unsigned long vsid, +unsigned long addr, +unsigned char *hpte_slot_array, +int psize,int ssize,int local) +{ +WARN (1 ,"%s called without THP support\n" , __func__); +} +#endif static void pSeries_lpar_hpte_removebolted (unsigned long ea,int psize,int ssize)
Signature · 1 line
2.5.0
PATCH v2 31/31 powerpc/mm: Add a _PAGE_PTE bit
In reply to Aneesh Kumar K.VFor a pte entry we will have _PAGE_PTE set. Our pte page address have a minimum alignment requirement of HUGEPD_SHIFT_MASK + 1. We use the lower 7 bits to indicate hugepd. ie.
For pmd and pgd we can find:
1) _PAGE_PTE set pte -> indicate PTE
2) bits [2..6] non zero -> indicate hugepd.
They also encode the size. We skip bit 1 (_PAGE_PRESENT).
3) othewise pointer to next table.
--- arch/powerpc/include/asm/book3s/64/hash-4k.h | 9 ++++++--- arch/powerpc/include/asm/book3s/64/hash-64k.h | 23 +++++++++-------------- arch/powerpc/include/asm/book3s/64/hash.h | 13 +++++++------ arch/powerpc/include/asm/book3s/64/pgtable.h | 3 +-- arch/powerpc/include/asm/pte-common.h | 5 +++++ arch/powerpc/mm/hugetlbpage.c | 4 ++-- arch/powerpc/mm/pgtable.c | 4 ++++ arch/powerpc/mm/pgtable_64.c | 7 +------ 8 files changed, 35 insertions(+), 33 deletions(-)
arch/powerpc/include/asm/book3s/64/hash-4k.h +6 -3
@@ -116,10 +116,13 @@ static inline int pgd_huge(pgd_t pgd)static inline int hugepd_ok (hugepd_t hpd) {/* -* hugepd pointer, bottom two bits == 00 and next 4 bits -* indicate size of table +* if it is not a pte and have hugepd shift mask +* set, then it is a hugepd directory pointer */ -return (((hpd.pd &0x3 ) ==0x0 ) && ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )); +if (!(hpd.pd & _PAGE_PTE) && + ((hpd.pd &HUGEPD_SHIFT_MASK ) !=0 )) +return true; +return false; }#define is_hugepd (hpd) (hugepd_ok(hpd))#endif
arch/powerpc/include/asm/book3s/64/hash-64k.h +9 -14
@@ -130,25 +130,25 @@ static inline bool __rpte_sub_valid(real_pte_t rpte, unsigned long index)static inline int pmd_huge (pmd_t pmd) {/* -* leaf pte for huge page, bottom two bits != 00 +* leaf pte for huge page */ -return ((pmd_val (pmd) &0x3 ) !=0x0 ); +return !!(pmd_val (pmd) & _PAGE_PTE); }static inline int pud_huge (pud_t pud) {/* -* leaf pte for huge page, bottom two bits != 00 +* leaf pte for huge page */ -return ((pud_val (pud) &0x3 ) !=0x0 ); +return !!(pud_val (pud) & _PAGE_PTE); }static inline int pgd_huge (pgd_t pgd) {/* -* leaf pte for huge page, bottom two bits != 00 +* leaf pte for huge page */ -return ((pgd_val (pgd) &0x3 ) !=0x0 ); +return !!(pgd_val (pgd) & _PAGE_PTE); }#define pgd_huge pgd_huge
@@ -225,10 +225,8 @@ static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,*/ static inline int pmd_trans_huge (pmd_t pmd) { -/* -* leaf pte for huge page, bottom two bits != 00 -*/ -return (pmd_val (pmd) &0x3 ) && (pmd_val (pmd) & _PAGE_THP_HUGE); +return !!((pmd_val (pmd) & (_PAGE_PTE | _PAGE_THP_HUGE)) == + (_PAGE_PTE | _PAGE_THP_HUGE)); }static inline int pmd_trans_splitting (pmd_t pmd)
@@ -240,10 +238,7 @@ static inline int pmd_trans_splitting(pmd_t pmd)static inline int pmd_large (pmd_t pmd) { -/* -* leaf pte for huge page, bottom two bits != 00 -*/ -return ((pmd_val (pmd) &0x3 ) !=0x0 ); +return !!(pmd_val (pmd) & _PAGE_PTE); }static inline pmd_t pmd_mknotpresent (pmd_t pmd)
arch/powerpc/include/asm/book3s/64/hash.h +7 -6
@@ -14,11 +14,12 @@* We could create separate kernel read-only if we used the 3 PP bits * combinations that newer processors provide but we currently don't. */ -#define _PAGE_PRESENT 0x00001/* software: pte contains a translation */ -#define _PAGE_USER 0x00002/* matches one of the PP bits */ +#define _PAGE_PTE 0x00001 +#define _PAGE_PRESENT 0x00002/* software: pte contains a translation */ +#define _PAGE_USER 0x00004/* matches one of the PP bits */ #define _PAGE_BIT_SWAP_TYPE 2 -#define _PAGE_EXEC 0x00004/* No execute on POWER4 and newer (we invert) */ -#define _PAGE_GUARDED 0x00008 +#define _PAGE_EXEC 0x00008/* No execute on POWER4 and newer (we invert) */ +#define _PAGE_GUARDED 0x00010/* We can derive Memory coherence from _PAGE_NO_CACHE */ #define _PAGE_COHERENT 0x0#define _PAGE_NO_CACHE 0x00020/* I: cache inhibit */
@@ -49,7 +50,7 @@*/ #define _HPAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | \ _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_SPLITTING | \ - _PAGE_THP_HUGE) + _PAGE_THP_HUGE | _PAGE_PTE)#ifdef CONFIG_PPC_64K_PAGES #include <asm/book3s/64/hash-64k.h>
@@ -139,7 +140,7 @@* pgprot changes */ #define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \ - _PAGE_ACCESSED | _PAGE_SPECIAL) + _PAGE_ACCESSED | _PAGE_SPECIAL | _PAGE_PTE)/* * Mask of bits returned by pte_pgprot() */
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -2
@@ -213,8 +213,7 @@ static inline int pmd_protnone(pmd_t pmd)static inline pmd_t pmd_mkhuge (pmd_t pmd) { -/* Do nothing, mk_pmd() does this part. */ -return pmd; +return __pmd (pmd_val (pmd) | (_PAGE_PTE | _PAGE_THP_HUGE)); }#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
arch/powerpc/include/asm/pte-common.h +5 -0
@@ -40,6 +40,11 @@#else #define _PAGE_RW 0#endif + +#ifndef _PAGE_PTE +#define _PAGE_PTE 0 +#endif +#ifndef _PMD_PRESENT_MASK#define _PMD_PRESENT_MASK _PMD_PRESENT#endif
arch/powerpc/mm/hugetlbpage.c +2 -2
@@ -893,8 +893,8 @@ void flush_dcache_icache_hugepage(struct page *page)* We have 4 cases for pgds and pmds: * (1) invalid (all zeroes) * (2) pointer to next table, as normal; bottom 6 bits == 0 -* (3) leaf pte for huge page, bottom two bits != 00 -* (4) hugepd pointer, bottom two bits == 00, next 4 bits indicate size of table +* (3) leaf pte for huge page _PAGE_PTE set +* (4) hugepd pointer, _PAGE_PTE = 0 and bits [2..6] indicate size of table * * So long as we atomically load page table pointers we are safe against teardown, * we can follow the address down to the the page and take a ref on it.
arch/powerpc/mm/pgtable.c +4 -0
@@ -179,6 +179,10 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,*/ VM_WARN_ON ((pte_val (*ptep) & (_PAGE_PRESENT | _PAGE_USER)) == (_PAGE_PRESENT | _PAGE_USER)); +/* +* Add the pte bit when tryint set a pte +*/ + pte =__pte (pte_val (pte) | _PAGE_PTE);/* Note: mm->context.id might not yet have been assigned as * this context might not have been activated yet when this
arch/powerpc/mm/pgtable_64.c +1 -6
@@ -765,13 +765,8 @@ static pmd_t pmd_set_protbits(pmd_t pmd, pgprot_t pgprot)pmd_t pfn_pmd (unsigned long pfn,pgprot_t pgprot) {unsigned long pmdv; -/* -* For a valid pte, we would have _PAGE_PRESENT always -* set. We use this to check THP page at pmd level. -* leaf pte for huge page, bottom two bits != 00 -*/ + pmdv = pfn <<PTE_RPN_SHIFT ; - pmdv |= _PAGE_THP_HUGE;return pmd_set_protbits (__pmd (pmdv), pgprot); }
Signature · 1 line
2.5.0