Skip to content

Commit 387e220

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Move hash MMU support code under CONFIG_PPC_64S_HASH_MMU
Compiling out hash support code when CONFIG_PPC_64S_HASH_MMU=n saves 128kB kernel image size (90kB text) on powernv_defconfig minus KVM, 350kB on pseries_defconfig minus KVM, 40kB on a tiny config. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> [mpe: Fixup defined(ARCH_HAS_MEMREMAP_COMPAT_ALIGN), which needs CONFIG. Fix radix_enabled() use in setup_initial_memory_limit(). Add some stubs to reduce number of ifdefs.] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20211201144153.2456614-18-npiggin@gmail.com
1 parent c285737 commit 387e220

File tree

35 files changed

+172
-57
lines changed

35 files changed

+172
-57
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ config PPC
129129
select ARCH_HAS_KCOV
130130
select ARCH_HAS_MEMBARRIER_CALLBACKS
131131
select ARCH_HAS_MEMBARRIER_SYNC_CORE
132-
select ARCH_HAS_MEMREMAP_COMPAT_ALIGN if PPC_BOOK3S_64
132+
select ARCH_HAS_MEMREMAP_COMPAT_ALIGN if PPC_64S_HASH_MMU
133133
select ARCH_HAS_MMIOWB if PPC64
134134
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
135135
select ARCH_HAS_PHYS_TO_DMA

arch/powerpc/include/asm/book3s/64/mmu-hash.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,14 @@ void slb_save_contents(struct slb_entry *slb_ptr);
523523
void slb_dump_contents(struct slb_entry *slb_ptr);
524524

525525
extern void slb_vmalloc_update(void);
526-
extern void slb_set_size(u16 size);
527526
void preload_new_slb_context(unsigned long start, unsigned long sp);
527+
528+
#ifdef CONFIG_PPC_64S_HASH_MMU
529+
void slb_set_size(u16 size);
530+
#else
531+
static inline void slb_set_size(u16 size) { }
532+
#endif
533+
528534
#endif /* __ASSEMBLY__ */
529535

530536
/*

arch/powerpc/include/asm/book3s/64/mmu.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ typedef struct {
105105
* from EA and new context ids to build the new VAs.
106106
*/
107107
mm_context_id_t id;
108+
#ifdef CONFIG_PPC_64S_HASH_MMU
108109
mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];
110+
#endif
109111
};
110112

111113
/* Number of bits in the mm_cpumask */
@@ -117,7 +119,9 @@ typedef struct {
117119
/* Number of user space windows opened in process mm_context */
118120
atomic_t vas_windows;
119121

122+
#ifdef CONFIG_PPC_64S_HASH_MMU
120123
struct hash_mm_context *hash_context;
124+
#endif
121125

122126
void __user *vdso;
123127
/*
@@ -140,6 +144,7 @@ typedef struct {
140144
#endif
141145
} mm_context_t;
142146

147+
#ifdef CONFIG_PPC_64S_HASH_MMU
143148
static inline u16 mm_ctx_user_psize(mm_context_t *ctx)
144149
{
145150
return ctx->hash_context->user_psize;
@@ -200,8 +205,15 @@ static inline struct subpage_prot_table *mm_ctx_subpage_prot(mm_context_t *ctx)
200205
extern int mmu_linear_psize;
201206
extern int mmu_virtual_psize;
202207
extern int mmu_vmalloc_psize;
203-
extern int mmu_vmemmap_psize;
204208
extern int mmu_io_psize;
209+
#else /* CONFIG_PPC_64S_HASH_MMU */
210+
#ifdef CONFIG_PPC_64K_PAGES
211+
#define mmu_virtual_psize MMU_PAGE_64K
212+
#else
213+
#define mmu_virtual_psize MMU_PAGE_4K
214+
#endif
215+
#endif
216+
extern int mmu_vmemmap_psize;
205217

206218
/* MMU initialization */
207219
void mmu_early_init_devtree(void);
@@ -240,8 +252,9 @@ static inline void setup_initial_memory_limit(phys_addr_t first_memblock_base,
240252
* know which translations we will pick. Hence go with hash
241253
* restrictions.
242254
*/
243-
return hash__setup_initial_memory_limit(first_memblock_base,
244-
first_memblock_size);
255+
if (!early_radix_enabled())
256+
hash__setup_initial_memory_limit(first_memblock_base,
257+
first_memblock_size);
245258
}
246259

247260
#ifdef CONFIG_PPC_PSERIES
@@ -262,6 +275,7 @@ static inline void radix_init_pseries(void) { }
262275
void cleanup_cpu_mmu_context(void);
263276
#endif
264277

278+
#ifdef CONFIG_PPC_64S_HASH_MMU
265279
static inline int get_user_context(mm_context_t *ctx, unsigned long ea)
266280
{
267281
int index = ea >> MAX_EA_BITS_PER_CONTEXT;
@@ -281,6 +295,7 @@ static inline unsigned long get_user_vsid(mm_context_t *ctx,
281295

282296
return get_vsid(context, ea, ssize);
283297
}
298+
#endif
284299

285300
#endif /* __ASSEMBLY__ */
286301
#endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */

arch/powerpc/include/asm/book3s/64/tlbflush-hash.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ static inline void hash__flush_tlb_kernel_range(unsigned long start,
112112

113113
struct mmu_gather;
114114
extern void hash__tlb_flush(struct mmu_gather *tlb);
115+
void flush_tlb_pmd_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr);
116+
117+
#ifdef CONFIG_PPC_64S_HASH_MMU
115118
/* Private function for use by PCI IO mapping code */
116119
extern void __flush_hash_table_range(unsigned long start, unsigned long end);
117120
extern void flush_tlb_pmd_range(struct mm_struct *mm, pmd_t *pmd,
118121
unsigned long addr);
122+
#else
123+
static inline void __flush_hash_table_range(unsigned long start, unsigned long end) { }
124+
#endif
119125
#endif /* _ASM_POWERPC_BOOK3S_64_TLBFLUSH_HASH_H */

arch/powerpc/include/asm/book3s/pgtable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
2525
unsigned long size, pgprot_t vma_prot);
2626
#define __HAVE_PHYS_MEM_ACCESS_PROT
2727

28+
#if defined(CONFIG_PPC32) || defined(CONFIG_PPC_64S_HASH_MMU)
2829
/*
2930
* This gets called at the end of handling a page fault, when
3031
* the kernel has put a new PTE into the page table for the process.
@@ -35,6 +36,9 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
3536
* waiting for the inevitable extra hash-table miss exception.
3637
*/
3738
void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep);
39+
#else
40+
static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) {}
41+
#endif
3842

3943
#endif /* __ASSEMBLY__ */
4044
#endif

arch/powerpc/include/asm/mmu_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ extern void hash__reserve_context_id(int id);
7575
extern void __destroy_context(int context_id);
7676
static inline void mmu_context_init(void) { }
7777

78+
#ifdef CONFIG_PPC_64S_HASH_MMU
7879
static inline int alloc_extended_context(struct mm_struct *mm,
7980
unsigned long ea)
8081
{
@@ -100,6 +101,7 @@ static inline bool need_extra_context(struct mm_struct *mm, unsigned long ea)
100101
return true;
101102
return false;
102103
}
104+
#endif
103105

104106
#else
105107
extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next,

arch/powerpc/include/asm/paca.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ struct paca_struct {
9797
/* this becomes non-zero. */
9898
u8 kexec_state; /* set when kexec down has irqs off */
9999
#ifdef CONFIG_PPC_BOOK3S_64
100+
#ifdef CONFIG_PPC_64S_HASH_MMU
100101
struct slb_shadow *slb_shadow_ptr;
102+
#endif
101103
struct dtl_entry *dispatch_log;
102104
struct dtl_entry *dispatch_log_end;
103105
#endif
@@ -110,6 +112,7 @@ struct paca_struct {
110112
/* used for most interrupts/exceptions */
111113
u64 exgen[EX_SIZE] __attribute__((aligned(0x80)));
112114

115+
#ifdef CONFIG_PPC_64S_HASH_MMU
113116
/* SLB related definitions */
114117
u16 vmalloc_sllp;
115118
u8 slb_cache_ptr;
@@ -120,6 +123,7 @@ struct paca_struct {
120123
u32 slb_used_bitmap; /* Bitmaps for first 32 SLB entries. */
121124
u32 slb_kern_bitmap;
122125
u32 slb_cache[SLB_CACHE_ENTRIES];
126+
#endif
123127
#endif /* CONFIG_PPC_BOOK3S_64 */
124128

125129
#ifdef CONFIG_PPC_BOOK3E
@@ -149,13 +153,15 @@ struct paca_struct {
149153
#endif /* CONFIG_PPC_BOOK3E */
150154

151155
#ifdef CONFIG_PPC_BOOK3S
156+
#ifdef CONFIG_PPC_64S_HASH_MMU
152157
#ifdef CONFIG_PPC_MM_SLICES
153158
unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE];
154159
unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE];
155160
#else
156161
u16 mm_ctx_user_psize;
157162
u16 mm_ctx_sllp;
158163
#endif
164+
#endif
159165
#endif
160166

161167
/*
@@ -268,9 +274,11 @@ struct paca_struct {
268274
#endif /* CONFIG_PPC_PSERIES */
269275

270276
#ifdef CONFIG_PPC_BOOK3S_64
277+
#ifdef CONFIG_PPC_64S_HASH_MMU
271278
/* Capture SLB related old contents in MCE handler. */
272279
struct slb_entry *mce_faulty_slbs;
273280
u16 slb_save_cache_ptr;
281+
#endif
274282
#endif /* CONFIG_PPC_BOOK3S_64 */
275283
#ifdef CONFIG_STACKPROTECTOR
276284
unsigned long canary;

arch/powerpc/kernel/asm-offsets.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ int main(void)
218218
OFFSET(PACA_EXGEN, paca_struct, exgen);
219219
OFFSET(PACA_EXMC, paca_struct, exmc);
220220
OFFSET(PACA_EXNMI, paca_struct, exnmi);
221+
#ifdef CONFIG_PPC_64S_HASH_MMU
221222
OFFSET(PACA_SLBSHADOWPTR, paca_struct, slb_shadow_ptr);
222223
OFFSET(SLBSHADOW_STACKVSID, slb_shadow, save_area[SLB_NUM_BOLTED - 1].vsid);
223224
OFFSET(SLBSHADOW_STACKESID, slb_shadow, save_area[SLB_NUM_BOLTED - 1].esid);
224225
OFFSET(SLBSHADOW_SAVEAREA, slb_shadow, save_area);
226+
#endif
225227
OFFSET(LPPACA_PMCINUSE, lppaca, pmcregs_in_use);
226228
#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
227229
OFFSET(PACA_PMCINUSE, paca_struct, pmcregs_in_use);

arch/powerpc/kernel/entry_64.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ _GLOBAL(_switch)
180180
#endif
181181

182182
ld r8,KSP(r4) /* new stack pointer */
183-
#ifdef CONFIG_PPC_BOOK3S_64
183+
#ifdef CONFIG_PPC_64S_HASH_MMU
184184
BEGIN_MMU_FTR_SECTION
185185
b 2f
186186
END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
@@ -232,7 +232,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
232232
slbmte r7,r0
233233
isync
234234
2:
235-
#endif /* CONFIG_PPC_BOOK3S_64 */
235+
#endif /* CONFIG_PPC_64S_HASH_MMU */
236236

237237
clrrdi r7, r8, THREAD_SHIFT /* base of new stack */
238238
/* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE

arch/powerpc/kernel/exceptions-64s.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,15 @@ EXC_COMMON_BEGIN(data_access_common)
13671367
addi r3,r1,STACK_FRAME_OVERHEAD
13681368
andis. r0,r4,DSISR_DABRMATCH@h
13691369
bne- 1f
1370+
#ifdef CONFIG_PPC_64S_HASH_MMU
13701371
BEGIN_MMU_FTR_SECTION
13711372
bl do_hash_fault
13721373
MMU_FTR_SECTION_ELSE
13731374
bl do_page_fault
13741375
ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1376+
#else
1377+
bl do_page_fault
1378+
#endif
13751379
b interrupt_return_srr
13761380

13771381
1: bl do_break
@@ -1414,6 +1418,7 @@ EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
14141418
EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
14151419
EXC_COMMON_BEGIN(data_access_slb_common)
14161420
GEN_COMMON data_access_slb
1421+
#ifdef CONFIG_PPC_64S_HASH_MMU
14171422
BEGIN_MMU_FTR_SECTION
14181423
/* HPT case, do SLB fault */
14191424
addi r3,r1,STACK_FRAME_OVERHEAD
@@ -1426,6 +1431,9 @@ MMU_FTR_SECTION_ELSE
14261431
/* Radix case, access is outside page table range */
14271432
li r3,-EFAULT
14281433
ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1434+
#else
1435+
li r3,-EFAULT
1436+
#endif
14291437
std r3,RESULT(r1)
14301438
addi r3,r1,STACK_FRAME_OVERHEAD
14311439
bl do_bad_segment_interrupt
@@ -1460,11 +1468,15 @@ EXC_VIRT_END(instruction_access, 0x4400, 0x80)
14601468
EXC_COMMON_BEGIN(instruction_access_common)
14611469
GEN_COMMON instruction_access
14621470
addi r3,r1,STACK_FRAME_OVERHEAD
1471+
#ifdef CONFIG_PPC_64S_HASH_MMU
14631472
BEGIN_MMU_FTR_SECTION
14641473
bl do_hash_fault
14651474
MMU_FTR_SECTION_ELSE
14661475
bl do_page_fault
14671476
ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1477+
#else
1478+
bl do_page_fault
1479+
#endif
14681480
b interrupt_return_srr
14691481

14701482

@@ -1494,6 +1506,7 @@ EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
14941506
EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
14951507
EXC_COMMON_BEGIN(instruction_access_slb_common)
14961508
GEN_COMMON instruction_access_slb
1509+
#ifdef CONFIG_PPC_64S_HASH_MMU
14971510
BEGIN_MMU_FTR_SECTION
14981511
/* HPT case, do SLB fault */
14991512
addi r3,r1,STACK_FRAME_OVERHEAD
@@ -1506,6 +1519,9 @@ MMU_FTR_SECTION_ELSE
15061519
/* Radix case, access is outside page table range */
15071520
li r3,-EFAULT
15081521
ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
1522+
#else
1523+
li r3,-EFAULT
1524+
#endif
15091525
std r3,RESULT(r1)
15101526
addi r3,r1,STACK_FRAME_OVERHEAD
15111527
bl do_bad_segment_interrupt

0 commit comments

Comments
 (0)