root/arch/powerpc/include/asm/nohash/32/kup-8xx.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. STACK_REGS_KUAP
  2. prevent_user_access
  3. bad_kuap_fault

   1 /* SPDX-License-Identifier: GPL-2.0 */
   2 #ifndef _ASM_POWERPC_KUP_8XX_H_
   3 #define _ASM_POWERPC_KUP_8XX_H_
   4 
   5 #include <asm/bug.h>
   6 
   7 #ifdef CONFIG_PPC_KUAP
   8 
   9 #ifdef __ASSEMBLY__
  10 
  11 .macro kuap_save_and_lock       sp, thread, gpr1, gpr2, gpr3
  12         lis     \gpr2, MD_APG_KUAP@h    /* only APG0 and APG1 are used */
  13         mfspr   \gpr1, SPRN_MD_AP
  14         mtspr   SPRN_MD_AP, \gpr2
  15         stw     \gpr1, STACK_REGS_KUAP(\sp)
  16 .endm
  17 
  18 .macro kuap_restore     sp, current, gpr1, gpr2, gpr3
  19         lwz     \gpr1, STACK_REGS_KUAP(\sp)
  20         mtspr   SPRN_MD_AP, \gpr1
  21 .endm
  22 
  23 .macro kuap_check       current, gpr
  24 #ifdef CONFIG_PPC_KUAP_DEBUG
  25         mfspr   \gpr, SPRN_MD_AP
  26         rlwinm  \gpr, \gpr, 16, 0xffff
  27 999:    twnei   \gpr, MD_APG_KUAP@h
  28         EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE)
  29 #endif
  30 .endm
  31 
  32 #else /* !__ASSEMBLY__ */
  33 
  34 #include <asm/reg.h>
  35 
  36 static inline void allow_user_access(void __user *to, const void __user *from,
  37                                      unsigned long size, unsigned long dir)
  38 {
  39         mtspr(SPRN_MD_AP, MD_APG_INIT);
  40 }
  41 
  42 static inline void prevent_user_access(void __user *to, const void __user *from,
  43                                        unsigned long size, unsigned long dir)
  44 {
  45         mtspr(SPRN_MD_AP, MD_APG_KUAP);
  46 }
  47 
  48 static inline bool
  49 bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
  50 {
  51         return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xf0000000),
  52                     "Bug: fault blocked by AP register !");
  53 }
  54 
  55 #endif /* !__ASSEMBLY__ */
  56 
  57 #endif /* CONFIG_PPC_KUAP */
  58 
  59 #endif /* _ASM_POWERPC_KUP_8XX_H_ */

/* [<][>][^][v][top][bottom][index][help] */