asm-uaccess.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __ASM_ASM_UACCESS_H
  2. #define __ASM_ASM_UACCESS_H
  3. #include <asm/alternative.h>
  4. #include <asm/kernel-pgtable.h>
  5. #include <asm/sysreg.h>
  6. #include <asm/assembler.h>
  7. /*
  8. * User access enabling/disabling macros.
  9. */
  10. #ifdef CONFIG_ARM64_SW_TTBR0_PAN
  11. .macro __uaccess_ttbr0_disable, tmp1
  12. mrs \tmp1, ttbr1_el1 // swapper_pg_dir
  13. add \tmp1, \tmp1, #SWAPPER_DIR_SIZE // reserved_ttbr0 at the end of swapper_pg_dir
  14. msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
  15. isb
  16. .endm
  17. .macro __uaccess_ttbr0_enable, tmp1
  18. get_thread_info \tmp1
  19. ldr \tmp1, [\tmp1, #TSK_TI_TTBR0] // load saved TTBR0_EL1
  20. msr ttbr0_el1, \tmp1 // set the non-PAN TTBR0_EL1
  21. isb
  22. .endm
  23. .macro uaccess_ttbr0_disable, tmp1
  24. alternative_if_not ARM64_HAS_PAN
  25. __uaccess_ttbr0_disable \tmp1
  26. alternative_else_nop_endif
  27. .endm
  28. .macro uaccess_ttbr0_enable, tmp1, tmp2
  29. alternative_if_not ARM64_HAS_PAN
  30. save_and_disable_irq \tmp2 // avoid preemption
  31. __uaccess_ttbr0_enable \tmp1
  32. restore_irq \tmp2
  33. alternative_else_nop_endif
  34. .endm
  35. #else
  36. .macro uaccess_ttbr0_disable, tmp1
  37. .endm
  38. .macro uaccess_ttbr0_enable, tmp1, tmp2
  39. .endm
  40. #endif
  41. /*
  42. * These macros are no-ops when UAO is present.
  43. */
  44. .macro uaccess_disable_not_uao, tmp1
  45. uaccess_ttbr0_disable \tmp1
  46. alternative_if ARM64_ALT_PAN_NOT_UAO
  47. SET_PSTATE_PAN(1)
  48. alternative_else_nop_endif
  49. .endm
  50. .macro uaccess_enable_not_uao, tmp1, tmp2
  51. uaccess_ttbr0_enable \tmp1, \tmp2
  52. alternative_if ARM64_ALT_PAN_NOT_UAO
  53. SET_PSTATE_PAN(0)
  54. alternative_else_nop_endif
  55. .endm
  56. #endif