blob: a0d662be4c5b8545a7b0b8c5c846187ced8d0020 [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>
Ingo Molnar589ee622017-02-04 00:16:44 +01005#include <linux/mm_types.h>
6
Qiaowei Ren57319d82014-11-14 07:18:27 -08007#include <asm/ptrace.h>
Dave Hansenfcc7ffd2014-11-14 07:18:28 -08008#include <asm/insn.h>
Qiaowei Ren57319d82014-11-14 07:18:27 -08009
Dave Hansenfe3d1972014-11-14 07:18:29 -080010/*
11 * NULL is theoretically a valid place to put the bounds
12 * directory, so point this at an invalid address.
13 */
14#define MPX_INVALID_BOUNDS_DIR ((void __user *)-1)
15#define MPX_BNDCFG_ENABLE_FLAG 0x1
16#define MPX_BD_ENTRY_VALID_FLAG 0x1
17
Dave Hansen613fcb72015-06-07 11:37:05 -070018/*
19 * The upper 28 bits [47:20] of the virtual address in 64-bit
20 * are used to index into bounds directory (BD).
21 *
22 * The directory is 2G (2^31) in size, and with 8-byte entries
23 * it has 2^28 entries.
Qiaowei Ren57319d82014-11-14 07:18:27 -080024 */
Dave Hansen613fcb72015-06-07 11:37:05 -070025#define MPX_BD_SIZE_BYTES_64 (1UL<<31)
26#define MPX_BD_ENTRY_BYTES_64 8
27#define MPX_BD_NR_ENTRIES_64 (MPX_BD_SIZE_BYTES_64/MPX_BD_ENTRY_BYTES_64)
28
29/*
30 * The 32-bit directory is 4MB (2^22) in size, and with 4-byte
31 * entries it has 2^20 entries.
Qiaowei Ren57319d82014-11-14 07:18:27 -080032 */
Dave Hansen613fcb72015-06-07 11:37:05 -070033#define MPX_BD_SIZE_BYTES_32 (1UL<<22)
34#define MPX_BD_ENTRY_BYTES_32 4
35#define MPX_BD_NR_ENTRIES_32 (MPX_BD_SIZE_BYTES_32/MPX_BD_ENTRY_BYTES_32)
Qiaowei Ren57319d82014-11-14 07:18:27 -080036
Dave Hansen613fcb72015-06-07 11:37:05 -070037/*
38 * A 64-bit table is 4MB total in size, and an entry is
39 * 4 64-bit pointers in size.
40 */
41#define MPX_BT_SIZE_BYTES_64 (1UL<<22)
42#define MPX_BT_ENTRY_BYTES_64 32
43#define MPX_BT_NR_ENTRIES_64 (MPX_BT_SIZE_BYTES_64/MPX_BT_ENTRY_BYTES_64)
Qiaowei Ren57319d82014-11-14 07:18:27 -080044
Dave Hansen613fcb72015-06-07 11:37:05 -070045/*
46 * A 32-bit table is 16kB total in size, and an entry is
47 * 4 32-bit pointers in size.
48 */
49#define MPX_BT_SIZE_BYTES_32 (1UL<<14)
50#define MPX_BT_ENTRY_BYTES_32 16
51#define MPX_BT_NR_ENTRIES_32 (MPX_BT_SIZE_BYTES_32/MPX_BT_ENTRY_BYTES_32)
Qiaowei Ren57319d82014-11-14 07:18:27 -080052
Dave Hansenfe3d1972014-11-14 07:18:29 -080053#define MPX_BNDSTA_TAIL 2
54#define MPX_BNDCFG_TAIL 12
55#define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1))
Dave Hansenfe3d1972014-11-14 07:18:29 -080056#define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1))
Qiaowei Ren57319d82014-11-14 07:18:27 -080057#define MPX_BNDSTA_ERROR_CODE 0x3
58
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080059#ifdef CONFIG_X86_INTEL_MPX
Dave Hansen46a6e0c2015-06-07 11:37:02 -070060siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
61int mpx_handle_bd_fault(void);
Dave Hansenfe3d1972014-11-14 07:18:29 -080062static inline int kernel_managing_mpx_tables(struct mm_struct *mm)
63{
Mark Rutlandcb02de92016-12-16 12:40:55 +000064 return (mm->context.bd_addr != MPX_INVALID_BOUNDS_DIR);
Dave Hansenfe3d1972014-11-14 07:18:29 -080065}
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 */
Mark Rutlandcb02de92016-12-16 12:40:55 +000072 mm->context.bd_addr = MPX_INVALID_BOUNDS_DIR;
Dave Hansenfe3d1972014-11-14 07:18:29 -080073}
Dave Hansen1de4fa12014-11-14 07:18:31 -080074void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
75 unsigned long start, unsigned long end);
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080076#else
Dave Hansen46a6e0c2015-06-07 11:37:02 -070077static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080078{
79 return NULL;
80}
Dave Hansen46a6e0c2015-06-07 11:37:02 -070081static inline int mpx_handle_bd_fault(void)
Dave Hansenfe3d1972014-11-14 07:18:29 -080082{
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}
Dave Hansen1de4fa12014-11-14 07:18:31 -080092static inline void mpx_notify_unmap(struct mm_struct *mm,
93 struct vm_area_struct *vma,
94 unsigned long start, unsigned long end)
95{
96}
Dave Hansenfcc7ffd2014-11-14 07:18:28 -080097#endif /* CONFIG_X86_INTEL_MPX */
98
Qiaowei Ren57319d82014-11-14 07:18:27 -080099#endif /* _ASM_X86_MPX_H */