Skip to content

Commit

Permalink
CONFIG_HIGHPTE vs. sub-page page tables.
Browse files Browse the repository at this point in the history
Background: I've implemented 1K/2K page tables for s390.  These sub-page
page tables are required to properly support the s390 virtualization
instruction with KVM.  The SIE instruction requires that the page tables
have 256 page table entries (pte) followed by 256 page status table entries
(pgste).  The pgstes are only required if the process is using the SIE
instruction.  The pgstes are updated by the hardware and by the hypervisor
for a number of reasons, one of them is dirty and reference bit tracking.
To avoid wasting memory the standard pte table allocation should return
1K/2K (31/64 bit) and 2K/4K if the process is using SIE.

Problem: Page size on s390 is 4K, page table size is 1K or 2K.  That means
the s390 version for pte_alloc_one cannot return a pointer to a struct
page.  Trouble is that with the CONFIG_HIGHPTE feature on x86 pte_alloc_one
cannot return a pointer to a pte either, since that would require more than
32 bit for the return value of pte_alloc_one (and the pte * would not be
accessible since its not kmapped).

Solution: The only solution I found to this dilemma is a new typedef: a
pgtable_t.  For s390 pgtable_t will be a (pte *) - to be introduced with a
later patch.  For everybody else it will be a (struct page *).  The
additional problem with the initialization of the ptl lock and the
NR_PAGETABLE accounting is solved with a constructor pgtable_page_ctor and
a destructor pgtable_page_dtor.  The page table allocation and free
functions need to call these two whenever a page table page is allocated or
freed.  pmd_populate will get a pgtable_t instead of a struct page pointer.
 To get the pgtable_t back from a pmd entry that has been installed with
pmd_populate a new function pmd_pgtable is added.  It replaces the pmd_page
call in free_pte_range and apply_to_pte_range.

Signed-off-by: Martin Schwidefsky <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Martin Schwidefsky authored and Linus Torvalds committed Feb 8, 2008
1 parent 13214ad commit 2f569af
Show file tree
Hide file tree
Showing 53 changed files with 326 additions and 132 deletions.
8 changes: 5 additions & 3 deletions arch/frv/mm/pgalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
return pte;
}

struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
struct page *page;

Expand All @@ -37,9 +37,11 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
#else
page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
#endif
if (page)
if (page) {
clear_highpage(page);
flush_dcache_page(page);
pgtable_page_ctor(page);
flush_dcache_page(page);
}
return page;
}

Expand Down
14 changes: 8 additions & 6 deletions arch/powerpc/mm/pgtable_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,20 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
return pte;
}

struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
struct page *ptepage;

#ifdef CONFIG_HIGHPTE
gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT;
gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT | __GFP_ZERO;
#else
gfp_t flags = GFP_KERNEL | __GFP_REPEAT;
gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
#endif

ptepage = alloc_pages(flags, 0);
if (ptepage)
clear_highpage(ptepage);
if (!ptepage)
return NULL;
pgtable_page_ctor(ptepage);
return ptepage;
}

Expand All @@ -131,11 +132,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
free_page((unsigned long)pte);
}

void pte_free(struct mm_struct *mm, struct page *ptepage)
void pte_free(struct mm_struct *mm, pgtable_t ptepage)
{
#ifdef CONFIG_SMP
hash_page_sync();
#endif
pgtable_page_dtor(ptepage);
__free_page(ptepage);
}

Expand Down
9 changes: 6 additions & 3 deletions arch/ppc/mm/pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
return pte;
}

struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
struct page *ptepage;

Expand All @@ -106,8 +106,10 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
#endif

ptepage = alloc_pages(flags, 0);
if (ptepage)
if (ptepage) {
clear_highpage(ptepage);
pgtable_page_ctor(ptepage);
}
return ptepage;
}

Expand All @@ -119,11 +121,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
free_page((unsigned long)pte);
}

void pte_free(struct mm_struct *mm, struct page *ptepage)
void pte_free(struct mm_struct *mm, pgtable_t ptepage)
{
#ifdef CONFIG_SMP
hash_page_sync();
#endif
pgtable_page_dtor(ptepage);
__free_page(ptepage);
}

Expand Down
2 changes: 2 additions & 0 deletions arch/s390/mm/pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unsigned long *page_table_alloc(int noexec)
clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
page->index = (addr_t) table;
}
pgtable_page_ctor(page);
table = (unsigned long *) page_to_phys(page);
clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
return table;
Expand All @@ -87,6 +88,7 @@ void page_table_free(unsigned long *table)
{
unsigned long *shadow = get_shadow_pte(table);

pgtable_page_dtor(virt_to_page(table));
if (shadow)
free_page((unsigned long) shadow);
free_page((unsigned long) table);
Expand Down
10 changes: 7 additions & 3 deletions arch/sparc/mm/srmmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,25 +489,29 @@ srmmu_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
return (pte_t *)srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
}

static struct page *
static pgtable_t
srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
unsigned long pte;
struct page *page;

if ((pte = (unsigned long)srmmu_pte_alloc_one_kernel(mm, address)) == 0)
return NULL;
return pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
page = pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
pgtable_page_ctor(page);
return page;
}

static void srmmu_free_pte_fast(pte_t *pte)
{
srmmu_free_nocache((unsigned long)pte, PTE_SIZE);
}

static void srmmu_pte_free(struct page *pte)
static void srmmu_pte_free(pgtable_t pte)
{
unsigned long p;

pgtable_page_dtor(pte);
p = (unsigned long)page_address(pte); /* Cached address (for test) */
if (p == 0)
BUG();
Expand Down
14 changes: 10 additions & 4 deletions arch/sparc/mm/sun4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,12 +1947,17 @@ static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
return pte;
}

static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
static pgtable_t sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
pte_t *pte = sun4c_pte_alloc_one_kernel(mm, address);
pte_t *pte;
struct page *page;

pte = sun4c_pte_alloc_one_kernel(mm, address);
if (pte == NULL)
return NULL;
return virt_to_page(pte);
page = virt_to_page(pte);
pgtable_page_ctor(page);
return page;
}

static inline void sun4c_free_pte_fast(pte_t *pte)
Expand All @@ -1962,8 +1967,9 @@ static inline void sun4c_free_pte_fast(pte_t *pte)
pgtable_cache_size++;
}

static void sun4c_pte_free(struct page *pte)
static void sun4c_pte_free(pgtable_t pte)
{
pgtable_page_dtor(pte);
sun4c_free_pte_fast(page_address(pte));
}

Expand Down
4 changes: 3 additions & 1 deletion arch/um/kernel/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
return pte;
}

struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
struct page *pte;

pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
if (pte)
pgtable_page_ctor(pte);
return pte;
}

Expand Down
5 changes: 4 additions & 1 deletion arch/x86/mm/pgtable_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
return (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
}

struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
struct page *pte;

Expand All @@ -192,6 +192,8 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
#else
pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
#endif
if (pte)
pgtable_page_ctor(pte);
return pte;
}

Expand Down Expand Up @@ -365,6 +367,7 @@ void check_pgt_cache(void)

void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
{
pgtable_page_dtor(pte);
paravirt_release_pt(page_to_pfn(pte));
tlb_remove_page(tlb, pte);
}
Expand Down
2 changes: 2 additions & 0 deletions include/asm-alpha/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ typedef unsigned long pgprot_t;

#endif /* STRICT_MM_TYPECHECKS */

typedef struct page *pgtable_t;

#ifdef USE_48_BIT_KSEG
#define PAGE_OFFSET 0xffff800000000000UL
#else
Expand Down
22 changes: 14 additions & 8 deletions include/asm-alpha/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
*/

static inline void
pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
{
pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET));
}
#define pmd_pgtable(pmd) pmd_page(pmd)

static inline void
pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
Expand Down Expand Up @@ -57,18 +58,23 @@ pte_free_kernel(struct mm_struct *mm, pte_t *pte)
free_page((unsigned long)pte);
}

static inline struct page *
pte_alloc_one(struct mm_struct *mm, unsigned long addr)
static inline pgtable_t
pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
pte_t *pte = pte_alloc_one_kernel(mm, addr);
if (pte)
return virt_to_page(pte);
return NULL;
pte_t *pte = pte_alloc_one_kernel(mm, address);
struct page *page;

if (!pte)
return NULL;
page = virt_to_page(pte);
pgtable_page_ctor(page);
return page;
}

static inline void
pte_free(struct mm_struct *mm, struct page *page)
pte_free(struct mm_struct *mm, pgtable_t page)
{
pgtable_page_dtor(page);
__free_page(page);
}

Expand Down
2 changes: 2 additions & 0 deletions include/asm-arm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ typedef unsigned long pgprot_t;

#endif /* STRICT_MM_TYPECHECKS */

typedef struct page *pgtable_t;

#endif /* CONFIG_MMU */

#include <asm/memory.h>
Expand Down
9 changes: 6 additions & 3 deletions include/asm-arm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
return pte;
}

static inline struct page *
static inline pgtable_t
pte_alloc_one(struct mm_struct *mm, unsigned long addr)
{
struct page *pte;
Expand All @@ -75,6 +75,7 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
if (pte) {
void *page = page_address(pte);
clean_dcache_area(page, sizeof(pte_t) * PTRS_PER_PTE);
pgtable_page_ctor(pte);
}

return pte;
Expand All @@ -91,8 +92,9 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
}
}

static inline void pte_free(struct mm_struct *mm, struct page *pte)
static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
{
pgtable_page_dtor(pte);
__free_page(pte);
}

Expand Down Expand Up @@ -123,10 +125,11 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
}

static inline void
pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
{
__pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE);
}
#define pmd_pgtable(pmd) pmd_page(pmd)

#endif /* CONFIG_MMU */

Expand Down
1 change: 1 addition & 0 deletions include/asm-avr32/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern void copy_page(void *to, void *from);
typedef struct { unsigned long pte; } pte_t;
typedef struct { unsigned long pgd; } pgd_t;
typedef struct { unsigned long pgprot; } pgprot_t;
typedef struct page *pgtable_t;

#define pte_val(x) ((x).pte)
#define pgd_val(x) ((x).pgd)
Expand Down
16 changes: 12 additions & 4 deletions include/asm-avr32/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))

static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
struct page *pte)
pgtable_t pte)
{
set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
}
#define pmd_pgtable(pmd) pmd_page(pmd)

/*
* Allocate and free page tables
Expand Down Expand Up @@ -51,7 +52,9 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
struct page *pte;

pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);

if (!pte)
return NULL;
pgtable_page_ctor(pte);
return pte;
}

Expand All @@ -60,12 +63,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
free_page((unsigned long)pte);
}

static inline void pte_free(struct mm_struct *mm, struct page *pte)
static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
{
pgtable_page_dtor(pte);
__free_page(pte);
}

#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
#define __pte_free_tlb(tlb,pte) \
do { \
pgtable_page_dtor(pte); \
tlb_remove_page((tlb), pte); \
} while (0)

#define check_pgt_cache() do { } while(0)

Expand Down
1 change: 1 addition & 0 deletions include/asm-cris/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
typedef struct { unsigned long pte; } pte_t;
typedef struct { unsigned long pgd; } pgd_t;
typedef struct { unsigned long pgprot; } pgprot_t;
typedef struct page *pgtable_t;
#endif

#define pte_val(x) ((x).pte)
Expand Down
Loading

0 comments on commit 2f569af

Please sign in to comment.