1111
1212#ifdef __ASSEMBLY__
1313
14- .macro kuap_restore_amr gpr
1514#ifdef CONFIG_PPC_KUAP
15+ .macro kuap_restore_amr gpr
1616 BEGIN_MMU_FTR_SECTION_NESTED (67 )
1717 ld \gpr , STACK_REGS_KUAP (r1 )
1818 mtspr SPRN_AMR , \gpr
1919 END_MMU_FTR_SECTION_NESTED_IFSET (MMU_FTR_RADIX_KUAP , 67 )
20- #endif
2120.endm
2221
2322.macro kuap_check_amr gpr1 , gpr2
3130 END_MMU_FTR_SECTION_NESTED_IFSET (MMU_FTR_RADIX_KUAP , 67 )
3231#endif
3332.endm
33+ #endif
3434
3535.macro kuap_save_amr_and_lock gpr1 , gpr2 , use_cr , msr_pr_cr
3636#ifdef CONFIG_PPC_KUAP
5454
5555#else /* !__ASSEMBLY__ */
5656
57+ DECLARE_STATIC_KEY_FALSE (uaccess_flush_key );
58+
5759#ifdef CONFIG_PPC_KUAP
5860
5961#include < asm/reg .h >
@@ -77,6 +79,18 @@ static inline void set_kuap(unsigned long value)
7779 isync ();
7880}
7981
82+ static inline bool
83+ bad_kuap_fault (struct pt_regs * regs , unsigned long address , bool is_write )
84+ {
85+ return WARN (mmu_has_feature (MMU_FTR_RADIX_KUAP ) &&
86+ (regs -> kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ )),
87+ "Bug: %s fault blocked by AMR!" , is_write ? "Write" : "Read" );
88+ }
89+ #else /* CONFIG_PPC_KUAP */
90+ static inline void kuap_restore_amr (struct pt_regs * regs , unsigned long amr ) { }
91+ static inline void set_kuap (unsigned long value ) { }
92+ #endif /* !CONFIG_PPC_KUAP */
93+
8094static __always_inline void allow_user_access (void __user * to , const void __user * from ,
8195 unsigned long size , unsigned long dir )
8296{
@@ -94,17 +108,10 @@ static inline void prevent_user_access(void __user *to, const void __user *from,
94108 unsigned long size , unsigned long dir )
95109{
96110 set_kuap (AMR_KUAP_BLOCKED );
111+ if (static_branch_unlikely (& uaccess_flush_key ))
112+ do_uaccess_flush ();
97113}
98114
99- static inline bool
100- bad_kuap_fault (struct pt_regs * regs , unsigned long address , bool is_write )
101- {
102- return WARN (mmu_has_feature (MMU_FTR_RADIX_KUAP ) &&
103- (regs -> kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ )),
104- "Bug: %s fault blocked by AMR!" , is_write ? "Write" : "Read" );
105- }
106- #endif /* CONFIG_PPC_KUAP */
107-
108115#endif /* __ASSEMBLY__ */
109116
110117#endif /* _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H */
0 commit comments