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 | |
Qiaowei Ren | 57319d8 | 2014-11-14 07:18:27 -0800 | [diff] [blame] | 16 | #ifdef CONFIG_X86_64 |
| 17 | |
| 18 | /* upper 28 bits [47:20] of the virtual address in 64-bit used to |
| 19 | * index into bounds directory (BD). |
| 20 | */ |
| 21 | #define MPX_BD_ENTRY_OFFSET 28 |
| 22 | #define MPX_BD_ENTRY_SHIFT 3 |
| 23 | /* bits [19:3] of the virtual address in 64-bit used to index into |
| 24 | * bounds table (BT). |
| 25 | */ |
| 26 | #define MPX_BT_ENTRY_OFFSET 17 |
| 27 | #define MPX_BT_ENTRY_SHIFT 5 |
| 28 | #define MPX_IGN_BITS 3 |
Dave Hansen | fe3d197 | 2014-11-14 07:18:29 -0800 | [diff] [blame] | 29 | #define MPX_BD_ENTRY_TAIL 3 |
Qiaowei Ren | 57319d8 | 2014-11-14 07:18:27 -0800 | [diff] [blame] | 30 | |
| 31 | #else |
| 32 | |
| 33 | #define MPX_BD_ENTRY_OFFSET 20 |
| 34 | #define MPX_BD_ENTRY_SHIFT 2 |
| 35 | #define MPX_BT_ENTRY_OFFSET 10 |
| 36 | #define MPX_BT_ENTRY_SHIFT 4 |
| 37 | #define MPX_IGN_BITS 2 |
Dave Hansen | fe3d197 | 2014-11-14 07:18:29 -0800 | [diff] [blame] | 38 | #define MPX_BD_ENTRY_TAIL 2 |
Qiaowei Ren | 57319d8 | 2014-11-14 07:18:27 -0800 | [diff] [blame] | 39 | |
| 40 | #endif |
| 41 | |
| 42 | #define MPX_BD_SIZE_BYTES (1UL<<(MPX_BD_ENTRY_OFFSET+MPX_BD_ENTRY_SHIFT)) |
| 43 | #define MPX_BT_SIZE_BYTES (1UL<<(MPX_BT_ENTRY_OFFSET+MPX_BT_ENTRY_SHIFT)) |
| 44 | |
Dave Hansen | fe3d197 | 2014-11-14 07:18:29 -0800 | [diff] [blame] | 45 | #define MPX_BNDSTA_TAIL 2 |
| 46 | #define MPX_BNDCFG_TAIL 12 |
| 47 | #define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1)) |
| 48 | #define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1)) |
| 49 | #define MPX_BT_ADDR_MASK (~((1UL<<MPX_BD_ENTRY_TAIL)-1)) |
| 50 | |
| 51 | #define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1)) |
Qiaowei Ren | 57319d8 | 2014-11-14 07:18:27 -0800 | [diff] [blame] | 52 | #define MPX_BNDSTA_ERROR_CODE 0x3 |
| 53 | |
Dave Hansen | 1de4fa1 | 2014-11-14 07:18:31 -0800 | [diff] [blame] | 54 | #define MPX_BD_ENTRY_MASK ((1<<MPX_BD_ENTRY_OFFSET)-1) |
| 55 | #define MPX_BT_ENTRY_MASK ((1<<MPX_BT_ENTRY_OFFSET)-1) |
| 56 | #define MPX_GET_BD_ENTRY_OFFSET(addr) ((((addr)>>(MPX_BT_ENTRY_OFFSET+ \ |
| 57 | MPX_IGN_BITS)) & MPX_BD_ENTRY_MASK) << MPX_BD_ENTRY_SHIFT) |
| 58 | #define MPX_GET_BT_ENTRY_OFFSET(addr) ((((addr)>>MPX_IGN_BITS) & \ |
| 59 | MPX_BT_ENTRY_MASK) << MPX_BT_ENTRY_SHIFT) |
| 60 | |
Dave Hansen | fcc7ffd | 2014-11-14 07:18:28 -0800 | [diff] [blame] | 61 | #ifdef CONFIG_X86_INTEL_MPX |
| 62 | siginfo_t *mpx_generate_siginfo(struct pt_regs *regs, |
| 63 | struct xsave_struct *xsave_buf); |
Dave Hansen | fe3d197 | 2014-11-14 07:18:29 -0800 | [diff] [blame] | 64 | int mpx_handle_bd_fault(struct xsave_struct *xsave_buf); |
| 65 | static inline int kernel_managing_mpx_tables(struct mm_struct *mm) |
| 66 | { |
| 67 | return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR); |
| 68 | } |
| 69 | static inline void mpx_mm_init(struct mm_struct *mm) |
| 70 | { |
| 71 | /* |
| 72 | * NULL is theoretically a valid place to put the bounds |
| 73 | * directory, so point this at an invalid address. |
| 74 | */ |
| 75 | mm->bd_addr = MPX_INVALID_BOUNDS_DIR; |
| 76 | } |
Dave Hansen | 1de4fa1 | 2014-11-14 07:18:31 -0800 | [diff] [blame] | 77 | void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma, |
| 78 | unsigned long start, unsigned long end); |
Dave Hansen | fcc7ffd | 2014-11-14 07:18:28 -0800 | [diff] [blame] | 79 | #else |
| 80 | static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs, |
| 81 | struct xsave_struct *xsave_buf) |
| 82 | { |
| 83 | return NULL; |
| 84 | } |
Dave Hansen | fe3d197 | 2014-11-14 07:18:29 -0800 | [diff] [blame] | 85 | static inline int mpx_handle_bd_fault(struct xsave_struct *xsave_buf) |
| 86 | { |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | static inline int kernel_managing_mpx_tables(struct mm_struct *mm) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | static inline void mpx_mm_init(struct mm_struct *mm) |
| 94 | { |
| 95 | } |
Dave Hansen | 1de4fa1 | 2014-11-14 07:18:31 -0800 | [diff] [blame] | 96 | static inline void mpx_notify_unmap(struct mm_struct *mm, |
| 97 | struct vm_area_struct *vma, |
| 98 | unsigned long start, unsigned long end) |
| 99 | { |
| 100 | } |
Dave Hansen | fcc7ffd | 2014-11-14 07:18:28 -0800 | [diff] [blame] | 101 | #endif /* CONFIG_X86_INTEL_MPX */ |
| 102 | |
Qiaowei Ren | 57319d8 | 2014-11-14 07:18:27 -0800 | [diff] [blame] | 103 | #endif /* _ASM_X86_MPX_H */ |