blob: 7a35495275a9b7b1150bde2935757a212defde59 [file] [log] [blame]
Qiaowei Ren57319d82014-11-14 07:18:27 -08001#ifndef _ASM_X86_MPX_H
2#define _ASM_X86_MPX_H
3
4#include <linux/types.h>
5#include <asm/ptrace.h>
Dave Hansenfcc7ffd2014-11-14 07:18:28 -08006#include <asm/insn.h>
Qiaowei Ren57319d82014-11-14 07:18:27 -08007
Dave Hansenfe3d1972014-11-14 07:18:29 -08008/*
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
Dave Hansen613fcb72015-06-07 11:37:05 -070016/*
17 * The upper 28 bits [47:20] of the virtual address in 64-bit
18 * are used to index into bounds directory (BD).
19 *
20 * The directory is 2G (2^31) in size, and with 8-byte entries
21 * it has 2^28 entries.
Qiaowei Ren57319d82014-11-14 07:18:27 -080022 */
Dave Hansen613fcb72015-06-07 11:37:05 -070023#define MPX_BD_SIZE_BYTES_64 (1UL<<31)
24#define MPX_BD_ENTRY_BYTES_64 8
25#define MPX_BD_NR_ENTRIES_64 (MPX_BD_SIZE_BYTES_64/MPX_BD_ENTRY_BYTES_64)
26
27/*
28 * The 32-bit directory is 4MB (2^22) in size, and with 4-byte
29 * entries it has 2^20 entries.
Qiaowei Ren57319d82014-11-14 07:18:27 -080030 */
Dave Hansen613fcb72015-06-07 11:37:05 -070031#define MPX_BD_SIZE_BYTES_32 (1UL<<22)
32#define MPX_BD_ENTRY_BYTES_32 4
33#define MPX_BD_NR_ENTRIES_32 (MPX_BD_SIZE_BYTES_32/MPX_BD_ENTRY_BYTES_32)
Qiaowei Ren57319d82014-11-14 07:18:27 -080034
Dave Hansen613fcb72015-06-07 11:37:05 -070035/*
36 * A 64-bit table is 4MB total in size, and an entry is
37 * 4 64-bit pointers in size.
38 */
39#define MPX_BT_SIZE_BYTES_64 (1UL<<22)
40#define MPX_BT_ENTRY_BYTES_64 32
41#define MPX_BT_NR_ENTRIES_64 (MPX_BT_SIZE_BYTES_64/MPX_BT_ENTRY_BYTES_64)
Qiaowei Ren57319d82014-11-14 07:18:27 -080042
Dave Hansen613fcb72015-06-07 11:37:05 -070043/*
44 * A 32-bit table is 16kB total in size, and an entry is
45 * 4 32-bit pointers in size.
46 */
47#define MPX_BT_SIZE_BYTES_32 (1UL<<14)
48#define MPX_BT_ENTRY_BYTES_32 16
49#define MPX_BT_NR_ENTRIES_32 (MPX_BT_SIZE_BYTES_32/MPX_BT_ENTRY_BYTES_32)
Qiaowei Ren57319d82014-11-14 07:18:27 -080050
Dave Hansenfe3d1972014-11-14 07:18:29 -080051#define MPX_BNDSTA_TAIL 2
52#define MPX_BNDCFG_TAIL 12
53#define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1))
Dave Hansenfe3d1972014-11-14 07:18:29 -080054#define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1))
Qiaowei Ren57319d82014-11-14 07:18:27 -080055#define MPX_BNDSTA_ERROR_CODE 0x3
56
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080057#ifdef CONFIG_X86_INTEL_MPX
Dave Hansen46a6e0c2015-06-07 11:37:02 -070058siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
59int mpx_handle_bd_fault(void);
Dave Hansenfe3d1972014-11-14 07:18:29 -080060static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
61{
62 return (mm->bd_addr != MPX_INVALID_BOUNDS_DIR);
63}
64static inline void mpx_mm_init(struct mm_struct *mm)
65{
66 /*
67 * NULL is theoretically a valid place to put the bounds
68 * directory, so point this at an invalid address.
69 */
70 mm->bd_addr = MPX_INVALID_BOUNDS_DIR;
71}
Dave Hansen1de4fa12014-11-14 07:18:31 -080072void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
73 unsigned long start, unsigned long end);
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080074#else
Dave Hansen46a6e0c2015-06-07 11:37:02 -070075static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080076{
77 return NULL;
78}
Dave Hansen46a6e0c2015-06-07 11:37:02 -070079static inline int mpx_handle_bd_fault(void)
Dave Hansenfe3d1972014-11-14 07:18:29 -080080{
81 return -EINVAL;
82}
83static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
84{
85 return 0;
86}
87static inline void mpx_mm_init(struct mm_struct *mm)
88{
89}
Dave Hansen1de4fa12014-11-14 07:18:31 -080090static inline void mpx_notify_unmap(struct mm_struct *mm,
91 struct vm_area_struct *vma,
92 unsigned long start, unsigned long end)
93{
94}
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080095#endif /* CONFIG_X86_INTEL_MPX */
96
Qiaowei Ren57319d82014-11-14 07:18:27 -080097#endif /* _ASM_X86_MPX_H */