]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/include/asm/mpx.h
x86/mpx: Use 32-bit-only cmpxchg() for 32-bit apps
[mirror_ubuntu-artful-kernel.git] / arch / x86 / include / asm / mpx.h
CommitLineData
57319d80
QR
1#ifndef _ASM_X86_MPX_H
2#define _ASM_X86_MPX_H
3
4#include <linux/types.h>
5#include <asm/ptrace.h>
fcc7ffd6 6#include <asm/insn.h>
57319d80 7
fe3d197f
DH
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
57319d80
QR
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
fe3d197f 29#define MPX_BD_ENTRY_TAIL 3
57319d80
QR
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
fe3d197f 38#define MPX_BD_ENTRY_TAIL 2
57319d80
QR
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
fe3d197f
DH
45#define MPX_BNDSTA_TAIL 2
46#define MPX_BNDCFG_TAIL 12
47#define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1))
fe3d197f
DH
48
49#define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1))
57319d80
QR
50#define MPX_BNDSTA_ERROR_CODE 0x3
51
1de4fa14
DH
52#define MPX_BD_ENTRY_MASK ((1<<MPX_BD_ENTRY_OFFSET)-1)
53#define MPX_BT_ENTRY_MASK ((1<<MPX_BT_ENTRY_OFFSET)-1)
54#define MPX_GET_BD_ENTRY_OFFSET(addr) ((((addr)>>(MPX_BT_ENTRY_OFFSET+ \
55 MPX_IGN_BITS)) & MPX_BD_ENTRY_MASK) << MPX_BD_ENTRY_SHIFT)
56#define MPX_GET_BT_ENTRY_OFFSET(addr) ((((addr)>>MPX_IGN_BITS) & \
57 MPX_BT_ENTRY_MASK) << MPX_BT_ENTRY_SHIFT)
58
fcc7ffd6 59#ifdef CONFIG_X86_INTEL_MPX
46a6e0cf
DH
60siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
61int mpx_handle_bd_fault(void);
fe3d197f
DH
62static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
63{
64 return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
65}
66static 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 */
72 mm->bd_addr = MPX_INVALID_BOUNDS_DIR;
73}
1de4fa14
DH
74void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
75 unsigned long start, unsigned long end);
fcc7ffd6 76#else
46a6e0cf 77static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
fcc7ffd6
DH
78{
79 return NULL;
80}
46a6e0cf 81static inline int mpx_handle_bd_fault(void)
fe3d197f
DH
82{
83 return -EINVAL;
84}
85static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
86{
87 return 0;
88}
89static inline void mpx_mm_init(struct mm_struct *mm)
90{
91}
1de4fa14
DH
92static inline void mpx_notify_unmap(struct mm_struct *mm,
93 struct vm_area_struct *vma,
94 unsigned long start, unsigned long end)
95{
96}
fcc7ffd6
DH
97#endif /* CONFIG_X86_INTEL_MPX */
98
57319d80 99#endif /* _ASM_X86_MPX_H */