Skip to content

Commit d5d14ed

Browse files
arch/tile: Allow tilegx to build with either 16K or 64K page size
This change introduces new flags for the hv_install_context() API that passes a page table pointer to the hypervisor. Clients can explicitly request 4K, 16K, or 64K small pages when they install a new context. In practice, the page size is fixed at kernel compile time and the same size is always requested every time a new page table is installed. The <hv/hypervisor.h> header changes so that it provides more abstract macros for managing "page" things like PFNs and page tables. For example there is now a HV_DEFAULT_PAGE_SIZE_SMALL instead of the old HV_PAGE_SIZE_SMALL. The various PFN routines have been eliminated and only PA- or PTFN-based ones remain (since PTFNs are always expressed in fixed 2KB "page" size). The page-table management macros are renamed with a leading underscore and take page-size arguments with the presumption that clients will use those macros in some single place to provide the "real" macros they will use themselves. I happened to notice the old hv_set_caching() API was totally broken (it assumed 4KB pages) so I changed it so it would nominally work correctly with other page sizes. Tag modules with the page size so you can't load a module built with a conflicting page size. (And add a test for SMP while we're at it.) Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent 47d632f commit d5d14ed

20 files changed

Lines changed: 345 additions & 197 deletions

‎arch/tile/Kconfig‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ config NR_CPUS
139139
smaller kernel memory footprint results from using a smaller
140140
value on chips with fewer tiles.
141141

142+
if TILEGX
143+
144+
choice
145+
prompt "Kernel page size"
146+
default PAGE_SIZE_64KB
147+
help
148+
This lets you select the page size of the kernel. For best
149+
performance on memory-intensive applications, a page size of 64KB
150+
is recommended. For workloads involving many small files, many
151+
connections, etc., it may be better to select 16KB, which uses
152+
memory more efficiently at some cost in TLB performance.
153+
154+
Note that this option is TILE-Gx specific; currently
155+
TILEPro page size is set by rebuilding the hypervisor.
156+
157+
config PAGE_SIZE_16KB
158+
bool "16KB"
159+
160+
config PAGE_SIZE_64KB
161+
bool "64KB"
162+
163+
endchoice
164+
165+
endif
166+
142167
source "kernel/time/Kconfig"
143168

144169
source "kernel/Kconfig.hz"

‎arch/tile/include/asm/Kbuild‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ generic-y += ipcbuf.h
2121
generic-y += irq_regs.h
2222
generic-y += kdebug.h
2323
generic-y += local.h
24-
generic-y += module.h
2524
generic-y += msgbuf.h
2625
generic-y += mutex.h
2726
generic-y += param.h

‎arch/tile/include/asm/mmu.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct mm_context {
2121
* Written under the mmap_sem semaphore; read without the
2222
* semaphore but atomically, but it is conservatively set.
2323
*/
24-
unsigned int priority_cached;
24+
unsigned long priority_cached;
2525
};
2626

2727
typedef struct mm_context mm_context_t;

‎arch/tile/include/asm/mmu_context.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
3030
return 0;
3131
}
3232

33-
/* Note that arch/tile/kernel/head.S also calls hv_install_context() */
33+
/*
34+
* Note that arch/tile/kernel/head_NN.S and arch/tile/mm/migrate_NN.S
35+
* also call hv_install_context().
36+
*/
3437
static inline void __install_page_table(pgd_t *pgdir, int asid, pgprot_t prot)
3538
{
3639
/* FIXME: DIRECTIO should not always be set. FIXME. */
37-
int rc = hv_install_context(__pa(pgdir), prot, asid, HV_CTX_DIRECTIO);
40+
int rc = hv_install_context(__pa(pgdir), prot, asid,
41+
HV_CTX_DIRECTIO | CTX_PAGE_FLAG);
3842
if (rc < 0)
3943
panic("hv_install_context failed: %d", rc);
4044
}

‎arch/tile/include/asm/module.h‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2011 Tilera Corporation. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, version 2.
7+
*
8+
* This program is distributed in the hope that it will be useful, but
9+
* WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11+
* NON INFRINGEMENT. See the GNU General Public License for
12+
* more details.
13+
*/
14+
15+
#ifndef _ASM_TILE_MODULE_H
16+
#define _ASM_TILE_MODULE_H
17+
18+
#include <arch/chip.h>
19+
20+
#include <asm-generic/module.h>
21+
22+
/* We can't use modules built with different page sizes. */
23+
#if defined(CONFIG_PAGE_SIZE_16KB)
24+
# define MODULE_PGSZ " 16KB"
25+
#elif defined(CONFIG_PAGE_SIZE_64KB)
26+
# define MODULE_PGSZ " 64KB"
27+
#else
28+
# define MODULE_PGSZ ""
29+
#endif
30+
31+
/* We don't really support no-SMP so tag if someone tries. */
32+
#ifdef CONFIG_SMP
33+
#define MODULE_NOSMP ""
34+
#else
35+
#define MODULE_NOSMP " nosmp"
36+
#endif
37+
38+
#define MODULE_ARCH_VERMAGIC CHIP_ARCH_NAME MODULE_PGSZ MODULE_NOSMP
39+
40+
#endif /* _ASM_TILE_MODULE_H */

‎arch/tile/include/asm/page.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@
2020
#include <arch/chip.h>
2121

2222
/* PAGE_SHIFT and HPAGE_SHIFT determine the page sizes. */
23-
#define PAGE_SHIFT HV_LOG2_PAGE_SIZE_SMALL
24-
#define HPAGE_SHIFT HV_LOG2_PAGE_SIZE_LARGE
23+
#if defined(CONFIG_PAGE_SIZE_16KB)
24+
#define PAGE_SHIFT 14
25+
#define CTX_PAGE_FLAG HV_CTX_PG_SM_16K
26+
#elif defined(CONFIG_PAGE_SIZE_64KB)
27+
#define PAGE_SHIFT 16
28+
#define CTX_PAGE_FLAG HV_CTX_PG_SM_64K
29+
#else
30+
#define PAGE_SHIFT HV_LOG2_DEFAULT_PAGE_SIZE_SMALL
31+
#define CTX_PAGE_FLAG 0
32+
#endif
33+
#define HPAGE_SHIFT HV_LOG2_DEFAULT_PAGE_SIZE_LARGE
2534

2635
#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
2736
#define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT)

‎arch/tile/include/asm/pgalloc.h‎

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
#include <linux/mm.h>
2020
#include <linux/mmzone.h>
2121
#include <asm/fixmap.h>
22+
#include <asm/page.h>
2223
#include <hv/hypervisor.h>
2324

2425
/* Bits for the size of the second-level page table. */
25-
#define L2_KERNEL_PGTABLE_SHIFT \
26-
(HV_LOG2_PAGE_SIZE_LARGE - HV_LOG2_PAGE_SIZE_SMALL + HV_LOG2_PTE_SIZE)
26+
#define L2_KERNEL_PGTABLE_SHIFT _HV_LOG2_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
27+
28+
/* How big is a kernel L2 page table? */
29+
#define L2_KERNEL_PGTABLE_SIZE (1UL << L2_KERNEL_PGTABLE_SHIFT)
2730

2831
/* We currently allocate user L2 page tables by page (unlike kernel L2s). */
29-
#if L2_KERNEL_PGTABLE_SHIFT < HV_LOG2_PAGE_SIZE_SMALL
30-
#define L2_USER_PGTABLE_SHIFT HV_LOG2_PAGE_SIZE_SMALL
32+
#if L2_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
33+
#define L2_USER_PGTABLE_SHIFT PAGE_SHIFT
3134
#else
3235
#define L2_USER_PGTABLE_SHIFT L2_KERNEL_PGTABLE_SHIFT
3336
#endif
3437

3538
/* How many pages do we need, as an "order", for a user L2 page table? */
36-
#define L2_USER_PGTABLE_ORDER (L2_USER_PGTABLE_SHIFT - HV_LOG2_PAGE_SIZE_SMALL)
37-
38-
/* How big is a kernel L2 page table? */
39-
#define L2_KERNEL_PGTABLE_SIZE (1 << L2_KERNEL_PGTABLE_SHIFT)
39+
#define L2_USER_PGTABLE_ORDER (L2_USER_PGTABLE_SHIFT - PAGE_SHIFT)
4040

4141
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
4242
{
@@ -50,14 +50,14 @@ static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
5050
static inline void pmd_populate_kernel(struct mm_struct *mm,
5151
pmd_t *pmd, pte_t *ptep)
5252
{
53-
set_pmd(pmd, ptfn_pmd(__pa(ptep) >> HV_LOG2_PAGE_TABLE_ALIGN,
53+
set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(__pa(ptep)),
5454
__pgprot(_PAGE_PRESENT)));
5555
}
5656

5757
static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
5858
pgtable_t page)
5959
{
60-
set_pmd(pmd, ptfn_pmd(HV_PFN_TO_PTFN(page_to_pfn(page)),
60+
set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(PFN_PHYS(page_to_pfn(page))),
6161
__pgprot(_PAGE_PRESENT)));
6262
}
6363

@@ -68,8 +68,20 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
6868
extern pgd_t *pgd_alloc(struct mm_struct *mm);
6969
extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
7070

71-
extern pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address);
72-
extern void pte_free(struct mm_struct *mm, struct page *pte);
71+
extern pgtable_t pgtable_alloc_one(struct mm_struct *mm, unsigned long address,
72+
int order);
73+
extern void pgtable_free(struct mm_struct *mm, struct page *pte, int order);
74+
75+
static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
76+
unsigned long address)
77+
{
78+
return pgtable_alloc_one(mm, address, L2_USER_PGTABLE_ORDER);
79+
}
80+
81+
static inline void pte_free(struct mm_struct *mm, struct page *pte)
82+
{
83+
pgtable_free(mm, pte, L2_USER_PGTABLE_ORDER);
84+
}
7385

7486
#define pmd_pgtable(pmd) pmd_page(pmd)
7587

@@ -85,8 +97,13 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
8597
pte_free(mm, virt_to_page(pte));
8698
}
8799

88-
extern void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte,
89-
unsigned long address);
100+
extern void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte,
101+
unsigned long address, int order);
102+
static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte,
103+
unsigned long address)
104+
{
105+
__pgtable_free_tlb(tlb, pte, address, L2_USER_PGTABLE_ORDER);
106+
}
90107

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

@@ -104,19 +121,44 @@ void shatter_pmd(pmd_t *pmd);
104121
void shatter_huge_page(unsigned long addr);
105122

106123
#ifdef __tilegx__
107-
/* We share a single page allocator for both L1 and L2 page tables. */
108-
#if HV_L1_SIZE != HV_L2_SIZE
109-
# error Rework assumption that L1 and L2 page tables are same size.
110-
#endif
111-
#define L1_USER_PGTABLE_ORDER L2_USER_PGTABLE_ORDER
124+
112125
#define pud_populate(mm, pud, pmd) \
113126
pmd_populate_kernel((mm), (pmd_t *)(pud), (pte_t *)(pmd))
114-
#define pmd_alloc_one(mm, addr) \
115-
((pmd_t *)page_to_virt(pte_alloc_one((mm), (addr))))
116-
#define pmd_free(mm, pmdp) \
117-
pte_free((mm), virt_to_page(pmdp))
118-
#define __pmd_free_tlb(tlb, pmdp, address) \
119-
__pte_free_tlb((tlb), virt_to_page(pmdp), (address))
127+
128+
/* Bits for the size of the L1 (intermediate) page table. */
129+
#define L1_KERNEL_PGTABLE_SHIFT _HV_LOG2_L1_SIZE(HPAGE_SHIFT)
130+
131+
/* How big is a kernel L2 page table? */
132+
#define L1_KERNEL_PGTABLE_SIZE (1UL << L1_KERNEL_PGTABLE_SHIFT)
133+
134+
/* We currently allocate L1 page tables by page. */
135+
#if L1_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
136+
#define L1_USER_PGTABLE_SHIFT PAGE_SHIFT
137+
#else
138+
#define L1_USER_PGTABLE_SHIFT L1_KERNEL_PGTABLE_SHIFT
120139
#endif
121140

141+
/* How many pages do we need, as an "order", for an L1 page table? */
142+
#define L1_USER_PGTABLE_ORDER (L1_USER_PGTABLE_SHIFT - PAGE_SHIFT)
143+
144+
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
145+
{
146+
struct page *p = pgtable_alloc_one(mm, address, L1_USER_PGTABLE_ORDER);
147+
return (pmd_t *)page_to_virt(p);
148+
}
149+
150+
static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp)
151+
{
152+
pgtable_free(mm, virt_to_page(pmdp), L1_USER_PGTABLE_ORDER);
153+
}
154+
155+
static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
156+
unsigned long address)
157+
{
158+
__pgtable_free_tlb(tlb, virt_to_page(pmdp), address,
159+
L1_USER_PGTABLE_ORDER);
160+
}
161+
162+
#endif /* __tilegx__ */
163+
122164
#endif /* _ASM_TILE_PGALLOC_H */

‎arch/tile/include/asm/pgtable.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
#include <linux/slab.h>
2828
#include <linux/list.h>
2929
#include <linux/spinlock.h>
30+
#include <linux/pfn.h>
3031
#include <asm/processor.h>
3132
#include <asm/fixmap.h>
33+
#include <asm/page.h>
3234

3335
struct mm_struct;
3436
struct vm_area_struct;
@@ -162,7 +164,7 @@ extern void set_page_homes(void);
162164
(pgprot_t) { ((oldprot).val & ~_PAGE_ALL) | (newprot).val }
163165

164166
/* Just setting the PFN to zero suffices. */
165-
#define pte_pgprot(x) hv_pte_set_pfn((x), 0)
167+
#define pte_pgprot(x) hv_pte_set_pa((x), 0)
166168

167169
/*
168170
* For PTEs and PDEs, we must clear the Present bit first when
@@ -262,7 +264,7 @@ static inline int pte_none(pte_t pte)
262264

263265
static inline unsigned long pte_pfn(pte_t pte)
264266
{
265-
return hv_pte_get_pfn(pte);
267+
return PFN_DOWN(hv_pte_get_pa(pte));
266268
}
267269

268270
/* Set or get the remote cache cpu in a pgprot with remote caching. */
@@ -271,7 +273,7 @@ extern int get_remote_cache_cpu(pgprot_t prot);
271273

272274
static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
273275
{
274-
return hv_pte_set_pfn(prot, pfn);
276+
return hv_pte_set_pa(prot, PFN_PHYS(pfn));
275277
}
276278

277279
/* Support for priority mappings. */
@@ -471,7 +473,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
471473
* OK for pte_lockptr(), since we just end up with potentially one
472474
* lock being used for several pte_t arrays.
473475
*/
474-
#define pmd_page(pmd) pfn_to_page(HV_PTFN_TO_PFN(pmd_ptfn(pmd)))
476+
#define pmd_page(pmd) pfn_to_page(PFN_DOWN(HV_PTFN_TO_CPA(pmd_ptfn(pmd))))
475477

476478
static inline void pmd_clear(pmd_t *pmdp)
477479
{

‎arch/tile/include/asm/pgtable_32.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
* The level-1 index is defined by the huge page size. A PGD is composed
2121
* of PTRS_PER_PGD pgd_t's and is the top level of the page table.
2222
*/
23-
#define PGDIR_SHIFT HV_LOG2_PAGE_SIZE_LARGE
24-
#define PGDIR_SIZE HV_PAGE_SIZE_LARGE
23+
#define PGDIR_SHIFT HPAGE_SHIFT
24+
#define PGDIR_SIZE HPAGE_SIZE
2525
#define PGDIR_MASK (~(PGDIR_SIZE-1))
26-
#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))
27-
#define SIZEOF_PGD (PTRS_PER_PGD * sizeof(pgd_t))
26+
#define PTRS_PER_PGD _HV_L1_ENTRIES(HPAGE_SHIFT)
27+
#define PGD_INDEX(va) _HV_L1_INDEX(va, HPAGE_SHIFT)
28+
#define SIZEOF_PGD _HV_L1_SIZE(HPAGE_SHIFT)
2829

2930
/*
3031
* The level-2 index is defined by the difference between the huge
@@ -33,8 +34,9 @@
3334
* Note that the hypervisor docs use PTE for what we call pte_t, so
3435
* this nomenclature is somewhat confusing.
3536
*/
36-
#define PTRS_PER_PTE (1 << (HV_LOG2_PAGE_SIZE_LARGE - HV_LOG2_PAGE_SIZE_SMALL))
37-
#define SIZEOF_PTE (PTRS_PER_PTE * sizeof(pte_t))
37+
#define PTRS_PER_PTE _HV_L2_ENTRIES(HPAGE_SHIFT, PAGE_SHIFT)
38+
#define PTE_INDEX(va) _HV_L2_INDEX(va, HPAGE_SHIFT, PAGE_SHIFT)
39+
#define SIZEOF_PTE _HV_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
3840

3941
#ifndef __ASSEMBLY__
4042

0 commit comments

Comments
 (0)