]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
57319d80 QR |
2 | #ifndef _ASM_X86_MPX_H |
3 | #define _ASM_X86_MPX_H | |
4 | ||
5 | #include <linux/types.h> | |
589ee628 IM |
6 | #include <linux/mm_types.h> |
7 | ||
57319d80 | 8 | #include <asm/ptrace.h> |
fcc7ffd6 | 9 | #include <asm/insn.h> |
57319d80 | 10 | |
fe3d197f DH |
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 | ||
613fcb7d DH |
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. | |
57319d80 | 25 | */ |
613fcb7d DH |
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) | |
57319d80 | 29 | |
613fcb7d DH |
30 | /* |
31 | * The 32-bit directory is 4MB (2^22) in size, and with 4-byte | |
32 | * entries it has 2^20 entries. | |
33 | */ | |
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) | |
57319d80 | 37 | |
613fcb7d DH |
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) | |
57319d80 | 45 | |
613fcb7d DH |
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) | |
57319d80 | 53 | |
fe3d197f DH |
54 | #define MPX_BNDSTA_TAIL 2 |
55 | #define MPX_BNDCFG_TAIL 12 | |
56 | #define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1)) | |
fe3d197f | 57 | #define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1)) |
57319d80 QR |
58 | #define MPX_BNDSTA_ERROR_CODE 0x3 |
59 | ||
8d68fa0e EB |
60 | struct mpx_fault_info { |
61 | void __user *addr; | |
62 | void __user *lower; | |
63 | void __user *upper; | |
64 | }; | |
65 | ||
fcc7ffd6 | 66 | #ifdef CONFIG_X86_INTEL_MPX |
5a28fc94 DH |
67 | |
68 | extern int mpx_fault_info(struct mpx_fault_info *info, struct pt_regs *regs); | |
69 | extern int mpx_handle_bd_fault(void); | |
70 | ||
fe3d197f DH |
71 | static inline int kernel_managing_mpx_tables(struct mm_struct *mm) |
72 | { | |
cb02de96 | 73 | return (mm->context.bd_addr != MPX_INVALID_BOUNDS_DIR); |
fe3d197f | 74 | } |
5a28fc94 | 75 | |
fe3d197f DH |
76 | static inline void mpx_mm_init(struct mm_struct *mm) |
77 | { | |
78 | /* | |
79 | * NULL is theoretically a valid place to put the bounds | |
80 | * directory, so point this at an invalid address. | |
81 | */ | |
cb02de96 | 82 | mm->context.bd_addr = MPX_INVALID_BOUNDS_DIR; |
fe3d197f | 83 | } |
44b04912 | 84 | |
5a28fc94 DH |
85 | extern void mpx_notify_unmap(struct mm_struct *mm, unsigned long start, unsigned long end); |
86 | extern unsigned long mpx_unmapped_area_check(unsigned long addr, unsigned long len, unsigned long flags); | |
87 | ||
fcc7ffd6 | 88 | #else |
8d68fa0e | 89 | static inline int mpx_fault_info(struct mpx_fault_info *info, struct pt_regs *regs) |
fcc7ffd6 | 90 | { |
8d68fa0e | 91 | return -EINVAL; |
fcc7ffd6 | 92 | } |
46a6e0cf | 93 | static inline int mpx_handle_bd_fault(void) |
fe3d197f DH |
94 | { |
95 | return -EINVAL; | |
96 | } | |
97 | static inline int kernel_managing_mpx_tables(struct mm_struct *mm) | |
98 | { | |
99 | return 0; | |
100 | } | |
101 | static inline void mpx_mm_init(struct mm_struct *mm) | |
102 | { | |
103 | } | |
1de4fa14 | 104 | static inline void mpx_notify_unmap(struct mm_struct *mm, |
1de4fa14 DH |
105 | unsigned long start, unsigned long end) |
106 | { | |
107 | } | |
44b04912 KS |
108 | |
109 | static inline unsigned long mpx_unmapped_area_check(unsigned long addr, | |
110 | unsigned long len, unsigned long flags) | |
111 | { | |
112 | return addr; | |
113 | } | |
fcc7ffd6 DH |
114 | #endif /* CONFIG_X86_INTEL_MPX */ |
115 | ||
57319d80 | 116 | #endif /* _ASM_X86_MPX_H */ |