blob: 7a35495275a9b7b1150bde2935757a212defde59 [file] [log] [blame]
Kyle Swenson8d8f6542021-03-15 11:02:55 -06001#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/*
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.
22 */
23#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.
30 */
31#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)
34
35/*
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)
42
43/*
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)
50
51#define MPX_BNDSTA_TAIL 2
52#define MPX_BNDCFG_TAIL 12
53#define MPX_BNDSTA_ADDR_MASK (~((1UL<<MPX_BNDSTA_TAIL)-1))
54#define MPX_BNDCFG_ADDR_MASK (~((1UL<<MPX_BNDCFG_TAIL)-1))
55#define MPX_BNDSTA_ERROR_CODE 0x3
56
57#ifdef CONFIG_X86_INTEL_MPX
58siginfo_t *mpx_generate_siginfo(struct pt_regs *regs);
59int mpx_handle_bd_fault(void);
60static 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}
72void mpx_notify_unmap(struct mm_struct *mm, struct vm_area_struct *vma,
73 unsigned long start, unsigned long end);
74#else
75static inline siginfo_t *mpx_generate_siginfo(struct pt_regs *regs)
76{
77 return NULL;
78}
79static inline int mpx_handle_bd_fault(void)
80{
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}
90static inline void mpx_notify_unmap(struct mm_struct *mm,
91 struct vm_area_struct *vma,
92 unsigned long start, unsigned long end)
93{
94}
95#endif /* CONFIG_X86_INTEL_MPX */
96
97#endif /* _ASM_X86_MPX_H */