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