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