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