x86, mpx: On-demand kernel allocation of bounds tables
[deliverable/linux.git] / arch / x86 / include / asm / mpx.h
1 #ifndef _ASM_X86_MPX_H
2 #define _ASM_X86_MPX_H
3
4 #include <linux/types.h>
5 #include <asm/ptrace.h>
6 #include <asm/insn.h>
7
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
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
29 #define MPX_BD_ENTRY_TAIL 3
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
38 #define MPX_BD_ENTRY_TAIL 2
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
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))
52 #define MPX_BNDSTA_ERROR_CODE 0x3
53
54 #ifdef CONFIG_X86_INTEL_MPX
55 siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
56 struct xsave_struct *xsave_buf);
57 int mpx_handle_bd_fault(struct xsave_struct *xsave_buf);
58 static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
59 {
60 return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
61 }
62 static inline void mpx_mm_init(struct mm_struct *mm)
63 {
64 /*
65 * NULL is theoretically a valid place to put the bounds
66 * directory, so point this at an invalid address.
67 */
68 mm->bd_addr = MPX_INVALID_BOUNDS_DIR;
69 }
70 #else
71 static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs,
72 struct xsave_struct *xsave_buf)
73 {
74 return NULL;
75 }
76 static inline int mpx_handle_bd_fault(struct xsave_struct *xsave_buf)
77 {
78 return -EINVAL;
79 }
80 static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
81 {
82 return 0;
83 }
84 static inline void mpx_mm_init(struct mm_struct *mm)
85 {
86 }
87 #endif /* CONFIG_X86_INTEL_MPX */
88
89 #endif /* _ASM_X86_MPX_H */
This page took 0.035138 seconds and 5 git commands to generate.