aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/include/asm/book3s/64/hash.h1
-rw-r--r--arch/powerpc/include/asm/book3s/64/pgtable.h1
-rw-r--r--arch/powerpc/include/asm/book3s/64/radix.h1
-rw-r--r--arch/powerpc/include/asm/bug.h8
-rw-r--r--arch/powerpc/include/asm/pgtable.h7
-rw-r--r--arch/powerpc/kernel/exceptions-64s.S28
-rw-r--r--arch/powerpc/kernel/idle_book3s.S15
-rw-r--r--arch/powerpc/mm/mem.c1
-rw-r--r--arch/powerpc/mm/pgtable-hash64.c44
-rw-r--r--arch/powerpc/mm/pgtable-radix.c28
-rw-r--r--arch/powerpc/mm/pgtable_64.c8
-rw-r--r--arch/powerpc/platforms/powernv/opal.c2
12 files changed, 106 insertions, 38 deletions
diff --git a/arch/powerpc/include/asm/book3s/64/hash.h b/arch/powerpc/include/asm/book3s/64/hash.h
index 0ce513f2926f..36fc7bfe9e11 100644
--- a/arch/powerpc/include/asm/book3s/64/hash.h
+++ b/arch/powerpc/include/asm/book3s/64/hash.h
@@ -91,6 +91,7 @@ static inline int hash__pgd_bad(pgd_t pgd)
91} 91}
92#ifdef CONFIG_STRICT_KERNEL_RWX 92#ifdef CONFIG_STRICT_KERNEL_RWX
93extern void hash__mark_rodata_ro(void); 93extern void hash__mark_rodata_ro(void);
94extern void hash__mark_initmem_nx(void);
94#endif 95#endif
95 96
96extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr, 97extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index c0737c86a362..d1da415e283c 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1192,5 +1192,6 @@ static inline const int pud_pfn(pud_t pud)
1192 BUILD_BUG(); 1192 BUILD_BUG();
1193 return 0; 1193 return 0;
1194} 1194}
1195
1195#endif /* __ASSEMBLY__ */ 1196#endif /* __ASSEMBLY__ */
1196#endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */ 1197#endif /* _ASM_POWERPC_BOOK3S_64_PGTABLE_H_ */
diff --git a/arch/powerpc/include/asm/book3s/64/radix.h b/arch/powerpc/include/asm/book3s/64/radix.h
index 487709ff6875..544440b5aff3 100644
--- a/arch/powerpc/include/asm/book3s/64/radix.h
+++ b/arch/powerpc/include/asm/book3s/64/radix.h
@@ -118,6 +118,7 @@
118 118
119#ifdef CONFIG_STRICT_KERNEL_RWX 119#ifdef CONFIG_STRICT_KERNEL_RWX
120extern void radix__mark_rodata_ro(void); 120extern void radix__mark_rodata_ro(void);
121extern void radix__mark_initmem_nx(void);
121#endif 122#endif
122 123
123static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr, 124static inline unsigned long __radix_pte_update(pte_t *ptep, unsigned long clr,
diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 0151af6c2a50..87fcc1948817 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -18,7 +18,7 @@
18#include <asm/asm-offsets.h> 18#include <asm/asm-offsets.h>
19#ifdef CONFIG_DEBUG_BUGVERBOSE 19#ifdef CONFIG_DEBUG_BUGVERBOSE
20.macro EMIT_BUG_ENTRY addr,file,line,flags 20.macro EMIT_BUG_ENTRY addr,file,line,flags
21 .section __bug_table,"a" 21 .section __bug_table,"aw"
225001: PPC_LONG \addr, 5002f 225001: PPC_LONG \addr, 5002f
23 .short \line, \flags 23 .short \line, \flags
24 .org 5001b+BUG_ENTRY_SIZE 24 .org 5001b+BUG_ENTRY_SIZE
@@ -29,7 +29,7 @@
29.endm 29.endm
30#else 30#else
31.macro EMIT_BUG_ENTRY addr,file,line,flags 31.macro EMIT_BUG_ENTRY addr,file,line,flags
32 .section __bug_table,"a" 32 .section __bug_table,"aw"
335001: PPC_LONG \addr 335001: PPC_LONG \addr
34 .short \flags 34 .short \flags
35 .org 5001b+BUG_ENTRY_SIZE 35 .org 5001b+BUG_ENTRY_SIZE
@@ -42,14 +42,14 @@
42 sizeof(struct bug_entry), respectively */ 42 sizeof(struct bug_entry), respectively */
43#ifdef CONFIG_DEBUG_BUGVERBOSE 43#ifdef CONFIG_DEBUG_BUGVERBOSE
44#define _EMIT_BUG_ENTRY \ 44#define _EMIT_BUG_ENTRY \
45 ".section __bug_table,\"a\"\n" \ 45 ".section __bug_table,\"aw\"\n" \
46 "2:\t" PPC_LONG "1b, %0\n" \ 46 "2:\t" PPC_LONG "1b, %0\n" \
47 "\t.short %1, %2\n" \ 47 "\t.short %1, %2\n" \
48 ".org 2b+%3\n" \ 48 ".org 2b+%3\n" \
49 ".previous\n" 49 ".previous\n"
50#else 50#else
51#define _EMIT_BUG_ENTRY \ 51#define _EMIT_BUG_ENTRY \
52 ".section __bug_table,\"a\"\n" \ 52 ".section __bug_table,\"aw\"\n" \
53 "2:\t" PPC_LONG "1b\n" \ 53 "2:\t" PPC_LONG "1b\n" \
54 "\t.short %2\n" \ 54 "\t.short %2\n" \
55 ".org 2b+%3\n" \ 55 ".org 2b+%3\n" \
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index dd01212935ac..afae9a336136 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -80,6 +80,13 @@ unsigned long vmalloc_to_phys(void *vmalloc_addr);
80 80
81void pgtable_cache_add(unsigned shift, void (*ctor)(void *)); 81void pgtable_cache_add(unsigned shift, void (*ctor)(void *));
82void pgtable_cache_init(void); 82void pgtable_cache_init(void);
83
84#ifdef CONFIG_STRICT_KERNEL_RWX
85void mark_initmem_nx(void);
86#else
87static inline void mark_initmem_nx(void) { }
88#endif
89
83#endif /* __ASSEMBLY__ */ 90#endif /* __ASSEMBLY__ */
84 91
85#endif /* _ASM_POWERPC_PGTABLE_H */ 92#endif /* _ASM_POWERPC_PGTABLE_H */
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index e6d8354d79ef..9029afd1fa2a 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -824,7 +824,7 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
824 * r3 volatile parameter and return value for status 824 * r3 volatile parameter and return value for status
825 * r4-r10 volatile input and output value 825 * r4-r10 volatile input and output value
826 * r11 volatile hypercall number and output value 826 * r11 volatile hypercall number and output value
827 * r12 volatile 827 * r12 volatile input and output value
828 * r13-r31 nonvolatile 828 * r13-r31 nonvolatile
829 * LR nonvolatile 829 * LR nonvolatile
830 * CTR volatile 830 * CTR volatile
@@ -834,25 +834,26 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
834 * Other registers nonvolatile 834 * Other registers nonvolatile
835 * 835 *
836 * The intersection of volatile registers that don't contain possible 836 * The intersection of volatile registers that don't contain possible
837 * inputs is: r12, cr0, xer, ctr. We may use these as scratch regs 837 * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
838 * upon entry without saving. 838 * without saving, though xer is not a good idea to use, as hardware may
839 * interpret some bits so it may be costly to change them.
839 */ 840 */
840#ifdef CONFIG_KVM_BOOK3S_64_HANDLER 841#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
841 /* 842 /*
842 * There is a little bit of juggling to get syscall and hcall 843 * There is a little bit of juggling to get syscall and hcall
843 * working well. Save r10 in ctr to be restored in case it is a 844 * working well. Save r13 in ctr to avoid using SPRG scratch
844 * hcall. 845 * register.
845 * 846 *
846 * Userspace syscalls have already saved the PPR, hcalls must save 847 * Userspace syscalls have already saved the PPR, hcalls must save
847 * it before setting HMT_MEDIUM. 848 * it before setting HMT_MEDIUM.
848 */ 849 */
849#define SYSCALL_KVMTEST \ 850#define SYSCALL_KVMTEST \
850 mr r12,r13; \ 851 mtctr r13; \
851 GET_PACA(r13); \ 852 GET_PACA(r13); \
852 mtctr r10; \ 853 std r10,PACA_EXGEN+EX_R10(r13); \
853 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \ 854 KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
854 HMT_MEDIUM; \ 855 HMT_MEDIUM; \
855 mr r9,r12; \ 856 mfctr r9;
856 857
857#else 858#else
858#define SYSCALL_KVMTEST \ 859#define SYSCALL_KVMTEST \
@@ -935,8 +936,8 @@ EXC_VIRT_END(system_call, 0x4c00, 0x100)
935 * This is a hcall, so register convention is as above, with these 936 * This is a hcall, so register convention is as above, with these
936 * differences: 937 * differences:
937 * r13 = PACA 938 * r13 = PACA
938 * r12 = orig r13 939 * ctr = orig r13
939 * ctr = orig r10 940 * orig r10 saved in PACA
940 */ 941 */
941TRAMP_KVM_BEGIN(do_kvm_0xc00) 942TRAMP_KVM_BEGIN(do_kvm_0xc00)
942 /* 943 /*
@@ -944,14 +945,13 @@ TRAMP_KVM_BEGIN(do_kvm_0xc00)
944 * HMT_MEDIUM. That allows the KVM code to save that value into the 945 * HMT_MEDIUM. That allows the KVM code to save that value into the
945 * guest state (it is the guest's PPR value). 946 * guest state (it is the guest's PPR value).
946 */ 947 */
947 OPT_GET_SPR(r0, SPRN_PPR, CPU_FTR_HAS_PPR) 948 OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
948 HMT_MEDIUM 949 HMT_MEDIUM
949 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r0, CPU_FTR_HAS_PPR) 950 OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
950 mfctr r10 951 mfctr r10
951 SET_SCRATCH0(r12) 952 SET_SCRATCH0(r10)
952 std r9,PACA_EXGEN+EX_R9(r13) 953 std r9,PACA_EXGEN+EX_R9(r13)
953 mfcr r9 954 mfcr r9
954 std r10,PACA_EXGEN+EX_R10(r13)
955 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00) 955 KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
956#endif 956#endif
957 957
diff --git a/arch/powerpc/kernel/idle_book3s.S b/arch/powerpc/kernel/idle_book3s.S
index 5adb390e773b..516ebef905c0 100644
--- a/arch/powerpc/kernel/idle_book3s.S
+++ b/arch/powerpc/kernel/idle_book3s.S
@@ -30,6 +30,7 @@
30 * Use unused space in the interrupt stack to save and restore 30 * Use unused space in the interrupt stack to save and restore
31 * registers for winkle support. 31 * registers for winkle support.
32 */ 32 */
33#define _MMCR0 GPR0
33#define _SDR1 GPR3 34#define _SDR1 GPR3
34#define _PTCR GPR3 35#define _PTCR GPR3
35#define _RPR GPR4 36#define _RPR GPR4
@@ -272,6 +273,14 @@ power_enter_stop:
272 b pnv_wakeup_noloss 273 b pnv_wakeup_noloss
273 274
274.Lhandle_esl_ec_set: 275.Lhandle_esl_ec_set:
276 /*
277 * POWER9 DD2 can incorrectly set PMAO when waking up after a
278 * state-loss idle. Saving and restoring MMCR0 over idle is a
279 * workaround.
280 */
281 mfspr r4,SPRN_MMCR0
282 std r4,_MMCR0(r1)
283
275/* 284/*
276 * Check if the requested state is a deep idle state. 285 * Check if the requested state is a deep idle state.
277 */ 286 */
@@ -450,10 +459,14 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_300)
450pnv_restore_hyp_resource_arch300: 459pnv_restore_hyp_resource_arch300:
451 /* 460 /*
452 * Workaround for POWER9, if we lost resources, the ERAT 461 * Workaround for POWER9, if we lost resources, the ERAT
453 * might have been mixed up and needs flushing. 462 * might have been mixed up and needs flushing. We also need
463 * to reload MMCR0 (see comment above).
454 */ 464 */
455 blt cr3,1f 465 blt cr3,1f
456 PPC_INVALIDATE_ERAT 466 PPC_INVALIDATE_ERAT
467 ld r1,PACAR1(r13)
468 ld r4,_MMCR0(r1)
469 mtspr SPRN_MMCR0,r4
4571: 4701:
458 /* 471 /*
459 * POWER ISA 3. Use PSSCR to determine if we 472 * POWER ISA 3. Use PSSCR to determine if we
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8541f18694a4..46b4e67d2372 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -402,6 +402,7 @@ void __init mem_init(void)
402void free_initmem(void) 402void free_initmem(void)
403{ 403{
404 ppc_md.progress = ppc_printk_progress; 404 ppc_md.progress = ppc_printk_progress;
405 mark_initmem_nx();
405 free_initmem_default(POISON_FREE_INITMEM); 406 free_initmem_default(POISON_FREE_INITMEM);
406} 407}
407 408
diff --git a/arch/powerpc/mm/pgtable-hash64.c b/arch/powerpc/mm/pgtable-hash64.c
index 188b4107584d..443a2c66a304 100644
--- a/arch/powerpc/mm/pgtable-hash64.c
+++ b/arch/powerpc/mm/pgtable-hash64.c
@@ -425,33 +425,51 @@ int hash__has_transparent_hugepage(void)
425#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 425#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
426 426
427#ifdef CONFIG_STRICT_KERNEL_RWX 427#ifdef CONFIG_STRICT_KERNEL_RWX
428void hash__mark_rodata_ro(void) 428static bool hash__change_memory_range(unsigned long start, unsigned long end,
429 unsigned long newpp)
429{ 430{
430 unsigned long start = (unsigned long)_stext;
431 unsigned long end = (unsigned long)__init_begin;
432 unsigned long idx; 431 unsigned long idx;
433 unsigned int step, shift; 432 unsigned int step, shift;
434 unsigned long newpp = PP_RXXX;
435 433
436 shift = mmu_psize_defs[mmu_linear_psize].shift; 434 shift = mmu_psize_defs[mmu_linear_psize].shift;
437 step = 1 << shift; 435 step = 1 << shift;
438 436
439 start = ((start + step - 1) >> shift) << shift; 437 start = ALIGN_DOWN(start, step);
440 end = (end >> shift) << shift; 438 end = ALIGN(end, step); // aligns up
441 439
442 pr_devel("marking ro start %lx, end %lx, step %x\n", 440 if (start >= end)
443 start, end, step); 441 return false;
444 442
445 if (start == end) { 443 pr_debug("Changing page protection on range 0x%lx-0x%lx, to 0x%lx, step 0x%x\n",
446 pr_warn("could not set rodata ro, relocate the start" 444 start, end, newpp, step);
447 " of the kernel to a 0x%x boundary\n", step);
448 return;
449 }
450 445
451 for (idx = start; idx < end; idx += step) 446 for (idx = start; idx < end; idx += step)
452 /* Not sure if we can do much with the return value */ 447 /* Not sure if we can do much with the return value */
453 mmu_hash_ops.hpte_updateboltedpp(newpp, idx, mmu_linear_psize, 448 mmu_hash_ops.hpte_updateboltedpp(newpp, idx, mmu_linear_psize,
454 mmu_kernel_ssize); 449 mmu_kernel_ssize);
455 450
451 return true;
452}
453
454void hash__mark_rodata_ro(void)
455{
456 unsigned long start, end;
457
458 start = (unsigned long)_stext;
459 end = (unsigned long)__init_begin;
460
461 WARN_ON(!hash__change_memory_range(start, end, PP_RXXX));
462}
463
464void hash__mark_initmem_nx(void)
465{
466 unsigned long start, end, pp;
467
468 start = (unsigned long)__init_begin;
469 end = (unsigned long)__init_end;
470
471 pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL));
472
473 WARN_ON(!hash__change_memory_range(start, end, pp));
456} 474}
457#endif 475#endif
diff --git a/arch/powerpc/mm/pgtable-radix.c b/arch/powerpc/mm/pgtable-radix.c
index 8c13e4282308..5cc50d47ce3f 100644
--- a/arch/powerpc/mm/pgtable-radix.c
+++ b/arch/powerpc/mm/pgtable-radix.c
@@ -112,10 +112,9 @@ set_the_pte:
112} 112}
113 113
114#ifdef CONFIG_STRICT_KERNEL_RWX 114#ifdef CONFIG_STRICT_KERNEL_RWX
115void radix__mark_rodata_ro(void) 115void radix__change_memory_range(unsigned long start, unsigned long end,
116 unsigned long clear)
116{ 117{
117 unsigned long start = (unsigned long)_stext;
118 unsigned long end = (unsigned long)__init_begin;
119 unsigned long idx; 118 unsigned long idx;
120 pgd_t *pgdp; 119 pgd_t *pgdp;
121 pud_t *pudp; 120 pud_t *pudp;
@@ -125,7 +124,8 @@ void radix__mark_rodata_ro(void)
125 start = ALIGN_DOWN(start, PAGE_SIZE); 124 start = ALIGN_DOWN(start, PAGE_SIZE);
126 end = PAGE_ALIGN(end); // aligns up 125 end = PAGE_ALIGN(end); // aligns up
127 126
128 pr_devel("marking ro start %lx, end %lx\n", start, end); 127 pr_debug("Changing flags on range %lx-%lx removing 0x%lx\n",
128 start, end, clear);
129 129
130 for (idx = start; idx < end; idx += PAGE_SIZE) { 130 for (idx = start; idx < end; idx += PAGE_SIZE) {
131 pgdp = pgd_offset_k(idx); 131 pgdp = pgd_offset_k(idx);
@@ -147,11 +147,29 @@ void radix__mark_rodata_ro(void)
147 if (!ptep) 147 if (!ptep)
148 continue; 148 continue;
149update_the_pte: 149update_the_pte:
150 radix__pte_update(&init_mm, idx, ptep, _PAGE_WRITE, 0, 0); 150 radix__pte_update(&init_mm, idx, ptep, clear, 0, 0);
151 } 151 }
152 152
153 radix__flush_tlb_kernel_range(start, end); 153 radix__flush_tlb_kernel_range(start, end);
154} 154}
155
156void radix__mark_rodata_ro(void)
157{
158 unsigned long start, end;
159
160 start = (unsigned long)_stext;
161 end = (unsigned long)__init_begin;
162
163 radix__change_memory_range(start, end, _PAGE_WRITE);
164}
165
166void radix__mark_initmem_nx(void)
167{
168 unsigned long start = (unsigned long)__init_begin;
169 unsigned long end = (unsigned long)__init_end;
170
171 radix__change_memory_range(start, end, _PAGE_EXEC);
172}
155#endif /* CONFIG_STRICT_KERNEL_RWX */ 173#endif /* CONFIG_STRICT_KERNEL_RWX */
156 174
157static inline void __meminit print_mapping(unsigned long start, 175static inline void __meminit print_mapping(unsigned long start,
diff --git a/arch/powerpc/mm/pgtable_64.c b/arch/powerpc/mm/pgtable_64.c
index 5c0b795d656c..0736e94c7615 100644
--- a/arch/powerpc/mm/pgtable_64.c
+++ b/arch/powerpc/mm/pgtable_64.c
@@ -505,4 +505,12 @@ void mark_rodata_ro(void)
505 else 505 else
506 hash__mark_rodata_ro(); 506 hash__mark_rodata_ro();
507} 507}
508
509void mark_initmem_nx(void)
510{
511 if (radix_enabled())
512 radix__mark_initmem_nx();
513 else
514 hash__mark_initmem_nx();
515}
508#endif 516#endif
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 9b87abb178f0..cad6b57ce494 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -78,7 +78,7 @@ void opal_configure_cores(void)
78 * ie. Host hash supports hash guests 78 * ie. Host hash supports hash guests
79 * Host radix supports hash/radix guests 79 * Host radix supports hash/radix guests
80 */ 80 */
81 if (cpu_has_feature(CPU_FTR_ARCH_300)) { 81 if (early_cpu_has_feature(CPU_FTR_ARCH_300)) {
82 reinit_flags |= OPAL_REINIT_CPUS_MMU_HASH; 82 reinit_flags |= OPAL_REINIT_CPUS_MMU_HASH;
83 if (early_radix_enabled()) 83 if (early_radix_enabled())
84 reinit_flags |= OPAL_REINIT_CPUS_MMU_RADIX; 84 reinit_flags |= OPAL_REINIT_CPUS_MMU_RADIX;