Skip to content

Commit 2f569af

Browse files
Martin SchwidefskyLinus Torvalds
authored andcommitted
CONFIG_HIGHPTE vs. sub-page page tables.
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 <schwidefsky@de.ibm.com> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 13214ad commit 2f569af

53 files changed

Lines changed: 326 additions & 132 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/frv/mm/pgalloc.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
2828
return pte;
2929
}
3030

31-
struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
31+
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
3232
{
3333
struct page *page;
3434

@@ -37,9 +37,11 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
3737
#else
3838
page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
3939
#endif
40-
if (page)
40+
if (page) {
4141
clear_highpage(page);
42-
flush_dcache_page(page);
42+
pgtable_page_ctor(page);
43+
flush_dcache_page(page);
44+
}
4345
return page;
4446
}
4547

‎arch/powerpc/mm/pgtable_32.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,20 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
107107
return pte;
108108
}
109109

110-
struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
110+
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
111111
{
112112
struct page *ptepage;
113113

114114
#ifdef CONFIG_HIGHPTE
115-
gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT;
115+
gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT | __GFP_ZERO;
116116
#else
117-
gfp_t flags = GFP_KERNEL | __GFP_REPEAT;
117+
gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
118118
#endif
119119

120120
ptepage = alloc_pages(flags, 0);
121-
if (ptepage)
122-
clear_highpage(ptepage);
121+
if (!ptepage)
122+
return NULL;
123+
pgtable_page_ctor(ptepage);
123124
return ptepage;
124125
}
125126

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

134-
void pte_free(struct mm_struct *mm, struct page *ptepage)
135+
void pte_free(struct mm_struct *mm, pgtable_t ptepage)
135136
{
136137
#ifdef CONFIG_SMP
137138
hash_page_sync();
138139
#endif
140+
pgtable_page_dtor(ptepage);
139141
__free_page(ptepage);
140142
}
141143

‎arch/ppc/mm/pgtable.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
9595
return pte;
9696
}
9797

98-
struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
98+
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
9999
{
100100
struct page *ptepage;
101101

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

108108
ptepage = alloc_pages(flags, 0);
109-
if (ptepage)
109+
if (ptepage) {
110110
clear_highpage(ptepage);
111+
pgtable_page_ctor(ptepage);
112+
}
111113
return ptepage;
112114
}
113115

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

122-
void pte_free(struct mm_struct *mm, struct page *ptepage)
124+
void pte_free(struct mm_struct *mm, pgtable_t ptepage)
123125
{
124126
#ifdef CONFIG_SMP
125127
hash_page_sync();
126128
#endif
129+
pgtable_page_dtor(ptepage);
127130
__free_page(ptepage);
128131
}
129132

‎arch/s390/mm/pgtable.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ unsigned long *page_table_alloc(int noexec)
7878
clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
7979
page->index = (addr_t) table;
8080
}
81+
pgtable_page_ctor(page);
8182
table = (unsigned long *) page_to_phys(page);
8283
clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
8384
return table;
@@ -87,6 +88,7 @@ void page_table_free(unsigned long *table)
8788
{
8889
unsigned long *shadow = get_shadow_pte(table);
8990

91+
pgtable_page_dtor(virt_to_page(table));
9092
if (shadow)
9193
free_page((unsigned long) shadow);
9294
free_page((unsigned long) table);

‎arch/sparc/mm/srmmu.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,25 +489,29 @@ srmmu_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
489489
return (pte_t *)srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
490490
}
491491

492-
static struct page *
492+
static pgtable_t
493493
srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address)
494494
{
495495
unsigned long pte;
496+
struct page *page;
496497

497498
if ((pte = (unsigned long)srmmu_pte_alloc_one_kernel(mm, address)) == 0)
498499
return NULL;
499-
return pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
500+
page = pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
501+
pgtable_page_ctor(page);
502+
return page;
500503
}
501504

502505
static void srmmu_free_pte_fast(pte_t *pte)
503506
{
504507
srmmu_free_nocache((unsigned long)pte, PTE_SIZE);
505508
}
506509

507-
static void srmmu_pte_free(struct page *pte)
510+
static void srmmu_pte_free(pgtable_t pte)
508511
{
509512
unsigned long p;
510513

514+
pgtable_page_dtor(pte);
511515
p = (unsigned long)page_address(pte); /* Cached address (for test) */
512516
if (p == 0)
513517
BUG();

‎arch/sparc/mm/sun4c.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,12 +1947,17 @@ static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
19471947
return pte;
19481948
}
19491949

1950-
static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
1950+
static pgtable_t sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
19511951
{
1952-
pte_t *pte = sun4c_pte_alloc_one_kernel(mm, address);
1952+
pte_t *pte;
1953+
struct page *page;
1954+
1955+
pte = sun4c_pte_alloc_one_kernel(mm, address);
19531956
if (pte == NULL)
19541957
return NULL;
1955-
return virt_to_page(pte);
1958+
page = virt_to_page(pte);
1959+
pgtable_page_ctor(page);
1960+
return page;
19561961
}
19571962

19581963
static inline void sun4c_free_pte_fast(pte_t *pte)
@@ -1962,8 +1967,9 @@ static inline void sun4c_free_pte_fast(pte_t *pte)
19621967
pgtable_cache_size++;
19631968
}
19641969

1965-
static void sun4c_pte_free(struct page *pte)
1970+
static void sun4c_pte_free(pgtable_t pte)
19661971
{
1972+
pgtable_page_dtor(pte);
19671973
sun4c_free_pte_fast(page_address(pte));
19681974
}
19691975

‎arch/um/kernel/mem.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,13 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
354354
return pte;
355355
}
356356

357-
struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
357+
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
358358
{
359359
struct page *pte;
360360

361361
pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
362+
if (pte)
363+
pgtable_page_ctor(pte);
362364
return pte;
363365
}
364366

‎arch/x86/mm/pgtable_32.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
183183
return (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
184184
}
185185

186-
struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
186+
pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
187187
{
188188
struct page *pte;
189189

@@ -192,6 +192,8 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
192192
#else
193193
pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
194194
#endif
195+
if (pte)
196+
pgtable_page_ctor(pte);
195197
return pte;
196198
}
197199

@@ -365,6 +367,7 @@ void check_pgt_cache(void)
365367

366368
void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
367369
{
370+
pgtable_page_dtor(pte);
368371
paravirt_release_pt(page_to_pfn(pte));
369372
tlb_remove_page(tlb, pte);
370373
}

‎include/asm-alpha/page.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ typedef unsigned long pgprot_t;
6262

6363
#endif /* STRICT_MM_TYPECHECKS */
6464

65+
typedef struct page *pgtable_t;
66+
6567
#ifdef USE_48_BIT_KSEG
6668
#define PAGE_OFFSET 0xffff800000000000UL
6769
#else

‎include/asm-alpha/pgalloc.h‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
*/
1212

1313
static inline void
14-
pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
14+
pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
1515
{
1616
pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET));
1717
}
18+
#define pmd_pgtable(pmd) pmd_page(pmd)
1819

1920
static inline void
2021
pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
@@ -57,18 +58,23 @@ pte_free_kernel(struct mm_struct *mm, pte_t *pte)
5758
free_page((unsigned long)pte);
5859
}
5960

60-
static inline struct page *
61-
pte_alloc_one(struct mm_struct *mm, unsigned long addr)
61+
static inline pgtable_t
62+
pte_alloc_one(struct mm_struct *mm, unsigned long address)
6263
{
63-
pte_t *pte = pte_alloc_one_kernel(mm, addr);
64-
if (pte)
65-
return virt_to_page(pte);
66-
return NULL;
64+
pte_t *pte = pte_alloc_one_kernel(mm, address);
65+
struct page *page;
66+
67+
if (!pte)
68+
return NULL;
69+
page = virt_to_page(pte);
70+
pgtable_page_ctor(page);
71+
return page;
6772
}
6873

6974
static inline void
70-
pte_free(struct mm_struct *mm, struct page *page)
75+
pte_free(struct mm_struct *mm, pgtable_t page)
7176
{
77+
pgtable_page_dtor(page);
7278
__free_page(page);
7379
}
7480

0 commit comments

Comments
 (0)