mpx.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _ASM_X86_MPX_H
  2. #define _ASM_X86_MPX_H
  3. #include <linux/types.h>
  4. #include <asm/ptrace.h>
  5. #include <asm/insn.h>
  6. /*
  7. * NULL is theoretically a valid place to put the bounds
  8. * directory, so point this at an invalid address.
  9. */
  10. #define MPX_INVALID_BOUNDS_DIR ((void __user *)-1)
  11. #define MPX_BNDCFG_ENABLE_FLAG 0x1
  12. #define MPX_BD_ENTRY_VALID_FLAG 0x1
  13. /*
  14. * The upper 28 bits [47:20] of the virtual address in 64-bit
  15. * are used to index into bounds directory (BD).
  16. *
  17. * The directory is 2G (2^31) in size, and with 8-byte entries
  18. * it has 2^28 entries.
  19. */
  20. #define MPX_BD_SIZE_BYTES_64 (1UL<<31)
  21. #define MPX_BD_ENTRY_BYTES_64 8
  22. #define MPX_BD_NR_ENTRIES_64 (MPX_BD_SIZE_BYTES_64/MPX_BD_ENTRY_BYTES_64)
  23. /*
  24. * The 32-bit directory is 4MB (2^22) in size, and with 4-byte
  25. * entries it has 2^20 entries.
  26. */
  27. #define MPX_BD_SIZE_BYTES_32 (1UL<<22)
  28. #define MPX_BD_ENTRY_BYTES_32 4
  29. #define MPX_BD_NR_ENTRIES_32 (MPX_BD_SIZE_BYTES_32/MPX_BD_ENTRY_BYTES_32)
  30. /*
  31. * A 64-bit table is 4MB total in size, and an entry is
  32. * 4 64-bit pointers in size.
  33. */
  34. #define MPX_BT_SIZE_BYTES_64 (1UL<<22)
  35. #define MPX_BT_ENTRY_BYTES_64 32
  36. #define MPX_BT_NR_ENTRIES_64 (MPX_BT_SIZE_BYTES_64/MPX_BT_ENTRY_BYTES_64)
  37. /*
  38. * A 32-bit table is 16kB total in size, and an entry is
  39. * 4 32-bit pointers in size.
  40. */
  41. #define MPX_BT_SIZE_BYTES_32 (1UL<<14)
  42. #define MPX_BT_ENTRY_BYTES_32 16
  43. #define MPX_BT_NR_ENTRIES_32 (MPX_BT_SIZE_BYTES_32/MPX_BT_ENTRY_BYTES_32)
  44. #define MPX_BNDSTA_TAIL 2
  45. #define MPX_BNDCFG_TAIL 12
  46. #define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1))
  47. #define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1))
  48. #define MPX_BNDSTA_ERROR_CODE 0x3
  49. #ifdef CONFIG_X86_INTEL_MPX
  50. siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
  51. int mpx_handle_bd_fault(void);
  52. static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
  53. {
  54. return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
  55. }
  56. static inline void mpx_mm_init(struct mm_struct *mm)
  57. {
  58. /*
  59. * NULL is theoretically a valid place to put the bounds
  60. * directory, so point this at an invalid address.
  61. */
  62. mm->bd_addr = MPX_INVALID_BOUNDS_DIR;
  63. }
  64. void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
  65. unsigned long start, unsigned long end);
  66. #else
  67. static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
  68. {
  69. return NULL;
  70. }
  71. static inline int mpx_handle_bd_fault(void)
  72. {
  73. return -EINVAL;
  74. }
  75. static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
  76. {
  77. return 0;
  78. }
  79. static inline void mpx_mm_init(struct mm_struct *mm)
  80. {
  81. }
  82. static inline void mpx_notify_unmap(struct mm_struct *mm,
  83. struct vm_area_struct *vma,
  84. unsigned long start, unsigned long end)
  85. {
  86. }
  87. #endif /* CONFIG_X86_INTEL_MPX */
  88. #endif /* _ASM_X86_MPX_H */