aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2008-02-08 07:22:04 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:42 -0500
commit2f569afd9ced9ebec9a6eb3dbf6f83429be0a7b4 (patch)
tree23a31763887d9505e62e9d7cc8ec2fa4b86bd380 /arch
parent13214adf738abc92b0a00c0763fd3be79eebaa7c (diff)
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>
Diffstat (limited to 'arch')
-rw-r--r--arch/frv/mm/pgalloc.c8
-rw-r--r--arch/powerpc/mm/pgtable_32.c14
-rw-r--r--arch/ppc/mm/pgtable.c9
-rw-r--r--arch/s390/mm/pgtable.c2
-rw-r--r--arch/sparc/mm/srmmu.c10
-rw-r--r--arch/sparc/mm/sun4c.c14
-rw-r--r--arch/um/kernel/mem.c4
-rw-r--r--arch/x86/mm/pgtable_32.c5
8 files changed, 45 insertions, 21 deletions
diff --git a/arch/frv/mm/pgalloc.c b/arch/frv/mm/pgalloc.c
index 1a2e5c8d03a9..66f616fb4860 100644
--- a/arch/frv/mm/pgalloc.c
+++ b/arch/frv/mm/pgalloc.c
@@ -28,7 +28,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
28 return pte; 28 return pte;
29} 29}
30 30
31struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 31pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
32{ 32{
33 struct page *page; 33 struct page *page;
34 34
@@ -37,9 +37,11 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
37#else 37#else
38 page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0); 38 page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
39#endif 39#endif
40 if (page) 40 if (page) {
41 clear_highpage(page); 41 clear_highpage(page);
42 flush_dcache_page(page); 42 pgtable_page_ctor(page);
43 flush_dcache_page(page);
44 }
43 return page; 45 return page;
44} 46}
45 47
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index f80f90c4d58b..ac3390f81900 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -107,19 +107,20 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
107 return pte; 107 return pte;
108} 108}
109 109
110struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 110pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
111{ 111{
112 struct page *ptepage; 112 struct page *ptepage;
113 113
114#ifdef CONFIG_HIGHPTE 114#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;
116#else 116#else
117 gfp_t flags = GFP_KERNEL | __GFP_REPEAT; 117 gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
118#endif 118#endif
119 119
120 ptepage = alloc_pages(flags, 0); 120 ptepage = alloc_pages(flags, 0);
121 if (ptepage) 121 if (!ptepage)
122 clear_highpage(ptepage); 122 return NULL;
123 pgtable_page_ctor(ptepage);
123 return ptepage; 124 return ptepage;
124} 125}
125 126
@@ -131,11 +132,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
131 free_page((unsigned long)pte); 132 free_page((unsigned long)pte);
132} 133}
133 134
134void pte_free(struct mm_struct *mm, struct page *ptepage) 135void pte_free(struct mm_struct *mm, pgtable_t ptepage)
135{ 136{
136#ifdef CONFIG_SMP 137#ifdef CONFIG_SMP
137 hash_page_sync(); 138 hash_page_sync();
138#endif 139#endif
140 pgtable_page_dtor(ptepage);
139 __free_page(ptepage); 141 __free_page(ptepage);
140} 142}
141 143
diff --git a/arch/ppc/mm/pgtable.c b/arch/ppc/mm/pgtable.c
index 409fcaa4994a..03a79bff1271 100644
--- a/arch/ppc/mm/pgtable.c
+++ b/arch/ppc/mm/pgtable.c
@@ -95,7 +95,7 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
95 return pte; 95 return pte;
96} 96}
97 97
98struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 98pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
99{ 99{
100 struct page *ptepage; 100 struct page *ptepage;
101 101
@@ -106,8 +106,10 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
106#endif 106#endif
107 107
108 ptepage = alloc_pages(flags, 0); 108 ptepage = alloc_pages(flags, 0);
109 if (ptepage) 109 if (ptepage) {
110 clear_highpage(ptepage); 110 clear_highpage(ptepage);
111 pgtable_page_ctor(ptepage);
112 }
111 return ptepage; 113 return ptepage;
112} 114}
113 115
@@ -119,11 +121,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
119 free_page((unsigned long)pte); 121 free_page((unsigned long)pte);
120} 122}
121 123
122void pte_free(struct mm_struct *mm, struct page *ptepage) 124void pte_free(struct mm_struct *mm, pgtable_t ptepage)
123{ 125{
124#ifdef CONFIG_SMP 126#ifdef CONFIG_SMP
125 hash_page_sync(); 127 hash_page_sync();
126#endif 128#endif
129 pgtable_page_dtor(ptepage);
127 __free_page(ptepage); 130 __free_page(ptepage);
128} 131}
129 132
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index e60e0ae13402..019f518cd5a0 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -78,6 +78,7 @@ unsigned long *page_table_alloc(int noexec)
78 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE); 78 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
79 page->index = (addr_t) table; 79 page->index = (addr_t) table;
80 } 80 }
81 pgtable_page_ctor(page);
81 table = (unsigned long *) page_to_phys(page); 82 table = (unsigned long *) page_to_phys(page);
82 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE); 83 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
83 return table; 84 return table;
@@ -87,6 +88,7 @@ void page_table_free(unsigned long *table)
87{ 88{
88 unsigned long *shadow = get_shadow_pte(table); 89 unsigned long *shadow = get_shadow_pte(table);
89 90
91 pgtable_page_dtor(virt_to_page(table));
90 if (shadow) 92 if (shadow)
91 free_page((unsigned long) shadow); 93 free_page((unsigned long) shadow);
92 free_page((unsigned long) table); 94 free_page((unsigned long) table);
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index dc98e3844a0a..23d3291a3e81 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -489,14 +489,17 @@ srmmu_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
489 return (pte_t *)srmmu_get_nocache(PTE_SIZE, PTE_SIZE); 489 return (pte_t *)srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
490} 490}
491 491
492static struct page * 492static pgtable_t
493srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address) 493srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address)
494{ 494{
495 unsigned long pte; 495 unsigned long pte;
496 struct page *page;
496 497
497 if ((pte = (unsigned long)srmmu_pte_alloc_one_kernel(mm, address)) == 0) 498 if ((pte = (unsigned long)srmmu_pte_alloc_one_kernel(mm, address)) == 0)
498 return NULL; 499 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;
500} 503}
501 504
502static void srmmu_free_pte_fast(pte_t *pte) 505static void srmmu_free_pte_fast(pte_t *pte)
@@ -504,10 +507,11 @@ static void srmmu_free_pte_fast(pte_t *pte)
504 srmmu_free_nocache((unsigned long)pte, PTE_SIZE); 507 srmmu_free_nocache((unsigned long)pte, PTE_SIZE);
505} 508}
506 509
507static void srmmu_pte_free(struct page *pte) 510static void srmmu_pte_free(pgtable_t pte)
508{ 511{
509 unsigned long p; 512 unsigned long p;
510 513
514 pgtable_page_dtor(pte);
511 p = (unsigned long)page_address(pte); /* Cached address (for test) */ 515 p = (unsigned long)page_address(pte); /* Cached address (for test) */
512 if (p == 0) 516 if (p == 0)
513 BUG(); 517 BUG();
diff --git a/arch/sparc/mm/sun4c.c b/arch/sparc/mm/sun4c.c
index 0729305f2f59..c0442e8c4b15 100644
--- a/arch/sparc/mm/sun4c.c
+++ b/arch/sparc/mm/sun4c.c
@@ -1947,12 +1947,17 @@ static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
1947 return pte; 1947 return pte;
1948} 1948}
1949 1949
1950static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address) 1950static pgtable_t sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
1951{ 1951{
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);
1953 if (pte == NULL) 1956 if (pte == NULL)
1954 return NULL; 1957 return NULL;
1955 return virt_to_page(pte); 1958 page = virt_to_page(pte);
1959 pgtable_page_ctor(page);
1960 return page;
1956} 1961}
1957 1962
1958static inline void sun4c_free_pte_fast(pte_t *pte) 1963static inline void sun4c_free_pte_fast(pte_t *pte)
@@ -1962,8 +1967,9 @@ static inline void sun4c_free_pte_fast(pte_t *pte)
1962 pgtable_cache_size++; 1967 pgtable_cache_size++;
1963} 1968}
1964 1969
1965static void sun4c_pte_free(struct page *pte) 1970static void sun4c_pte_free(pgtable_t pte)
1966{ 1971{
1972 pgtable_page_dtor(pte);
1967 sun4c_free_pte_fast(page_address(pte)); 1973 sun4c_free_pte_fast(page_address(pte));
1968} 1974}
1969 1975
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index d872fdce1d7e..2627ce82e918 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -354,11 +354,13 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
354 return pte; 354 return pte;
355} 355}
356 356
357struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 357pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
358{ 358{
359 struct page *pte; 359 struct page *pte;
360 360
361 pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO); 361 pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
362 if (pte)
363 pgtable_page_ctor(pte);
362 return pte; 364 return pte;
363} 365}
364 366
diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
index 6c1914622a88..73aba7125203 100644
--- a/arch/x86/mm/pgtable_32.c
+++ b/arch/x86/mm/pgtable_32.c
@@ -183,7 +183,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
183 return (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO); 183 return (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
184} 184}
185 185
186struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address) 186pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
187{ 187{
188 struct page *pte; 188 struct page *pte;
189 189
@@ -192,6 +192,8 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
192#else 192#else
193 pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0); 193 pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
194#endif 194#endif
195 if (pte)
196 pgtable_page_ctor(pte);
195 return pte; 197 return pte;
196} 198}
197 199
@@ -365,6 +367,7 @@ void check_pgt_cache(void)
365 367
366void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte) 368void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
367{ 369{
370 pgtable_page_dtor(pte);
368 paravirt_release_pt(page_to_pfn(pte)); 371 paravirt_release_pt(page_to_pfn(pte));
369 tlb_remove_page(tlb, pte); 372 tlb_remove_page(tlb, pte);
370} 373}