27
27
*/
28
28
#define PMD_PRESENT_INVALID (_AT(pteval_t, 1) << 59) /* only when !PMD_SECT_VALID */
29
29
30
+ #define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
31
+ #define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
32
+
33
+ #define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG)
34
+ #define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG)
35
+
36
+ #define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))
37
+ #define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
38
+ #define PROT_NORMAL_NC (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
39
+ #define PROT_NORMAL (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
40
+ #define PROT_NORMAL_TAGGED (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
41
+
42
+ #define PROT_SECT_DEVICE_nGnRE (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
43
+ #define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PTE_WRITE | PMD_ATTRINDX(MT_NORMAL))
44
+ #define PROT_SECT_NORMAL_EXEC (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
45
+
46
+ #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
47
+
48
+ #define _PAGE_KERNEL (PROT_NORMAL)
49
+ #define _PAGE_KERNEL_RO ((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
50
+ #define _PAGE_KERNEL_ROX ((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
51
+ #define _PAGE_KERNEL_EXEC (PROT_NORMAL & ~PTE_PXN)
52
+ #define _PAGE_KERNEL_EXEC_CONT ((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
53
+
54
+ #define _PAGE_SHARED (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
55
+ #define _PAGE_SHARED_EXEC (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)
56
+ #define _PAGE_READONLY (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
57
+ #define _PAGE_READONLY_EXEC (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN)
58
+ #define _PAGE_EXECONLY (_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN)
59
+
60
+ #ifdef __ASSEMBLY__
61
+ #define PTE_MAYBE_NG 0
62
+ #endif
63
+
30
64
#ifndef __ASSEMBLY__
31
65
32
66
#include <asm/cpufeature.h>
33
67
#include <asm/pgtable-types.h>
34
68
35
69
extern bool arm64_use_ng_mappings ;
36
70
37
- #define _PROT_DEFAULT (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
38
- #define _PROT_SECT_DEFAULT (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
39
-
40
71
#define PTE_MAYBE_NG (arm64_use_ng_mappings ? PTE_NG : 0)
41
72
#define PMD_MAYBE_NG (arm64_use_ng_mappings ? PMD_SECT_NG : 0)
42
73
@@ -50,26 +81,11 @@ extern bool arm64_use_ng_mappings;
50
81
#define PTE_MAYBE_GP 0
51
82
#endif
52
83
53
- #define PROT_DEFAULT (_PROT_DEFAULT | PTE_MAYBE_NG)
54
- #define PROT_SECT_DEFAULT (_PROT_SECT_DEFAULT | PMD_MAYBE_NG)
55
-
56
- #define PROT_DEVICE_nGnRnE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))
57
- #define PROT_DEVICE_nGnRE (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
58
- #define PROT_NORMAL_NC (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
59
- #define PROT_NORMAL (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
60
- #define PROT_NORMAL_TAGGED (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
61
-
62
- #define PROT_SECT_DEVICE_nGnRE (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
63
- #define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
64
- #define PROT_SECT_NORMAL_EXEC (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
65
-
66
- #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
67
-
68
- #define PAGE_KERNEL __pgprot(PROT_NORMAL)
69
- #define PAGE_KERNEL_RO __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
70
- #define PAGE_KERNEL_ROX __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
71
- #define PAGE_KERNEL_EXEC __pgprot(PROT_NORMAL & ~PTE_PXN)
72
- #define PAGE_KERNEL_EXEC_CONT __pgprot((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
84
+ #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
85
+ #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL_RO)
86
+ #define PAGE_KERNEL_ROX __pgprot(_PAGE_KERNEL_ROX)
87
+ #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
88
+ #define PAGE_KERNEL_EXEC_CONT __pgprot(_PAGE_KERNEL_EXEC_CONT)
73
89
74
90
#define PAGE_S2_MEMATTR (attr , has_fwb ) \
75
91
({ \
@@ -83,12 +99,62 @@ extern bool arm64_use_ng_mappings;
83
99
84
100
#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
85
101
/* shared+writable pages are clean by default, hence PTE_RDONLY|PTE_WRITE */
86
- #define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE )
87
- #define PAGE_SHARED_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE )
88
- #define PAGE_READONLY __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN )
89
- #define PAGE_READONLY_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN )
90
- #define PAGE_EXECONLY __pgprot(_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN )
102
+ #define PAGE_SHARED __pgprot(_PAGE_SHARED )
103
+ #define PAGE_SHARED_EXEC __pgprot(_PAGE_SHARED_EXEC )
104
+ #define PAGE_READONLY __pgprot(_PAGE_READONLY )
105
+ #define PAGE_READONLY_EXEC __pgprot(_PAGE_READONLY_EXEC )
106
+ #define PAGE_EXECONLY __pgprot(_PAGE_EXECONLY )
91
107
92
108
#endif /* __ASSEMBLY__ */
93
109
110
+ #define pte_pi_index (pte ) ( \
111
+ ((pte & BIT(PTE_PI_IDX_3)) >> (PTE_PI_IDX_3 - 3)) | \
112
+ ((pte & BIT(PTE_PI_IDX_2)) >> (PTE_PI_IDX_2 - 2)) | \
113
+ ((pte & BIT(PTE_PI_IDX_1)) >> (PTE_PI_IDX_1 - 1)) | \
114
+ ((pte & BIT(PTE_PI_IDX_0)) >> (PTE_PI_IDX_0 - 0)))
115
+
116
+ /*
117
+ * Page types used via Permission Indirection Extension (PIE). PIE uses
118
+ * the USER, DBM, PXN and UXN bits to to generate an index which is used
119
+ * to look up the actual permission in PIR_ELx and PIRE0_EL1. We define
120
+ * combinations we use on non-PIE systems with the same encoding, for
121
+ * convenience these are listed here as comments as are the unallocated
122
+ * encodings.
123
+ */
124
+
125
+ /* 0: PAGE_DEFAULT */
126
+ /* 1: PTE_USER */
127
+ /* 2: PTE_WRITE */
128
+ /* 3: PTE_WRITE | PTE_USER */
129
+ /* 4: PAGE_EXECONLY PTE_PXN */
130
+ /* 5: PAGE_READONLY_EXEC PTE_PXN | PTE_USER */
131
+ /* 6: PTE_PXN | PTE_WRITE */
132
+ /* 7: PAGE_SHARED_EXEC PTE_PXN | PTE_WRITE | PTE_USER */
133
+ /* 8: PAGE_KERNEL_ROX PTE_UXN */
134
+ /* 9: PTE_UXN | PTE_USER */
135
+ /* a: PAGE_KERNEL_EXEC PTE_UXN | PTE_WRITE */
136
+ /* b: PTE_UXN | PTE_WRITE | PTE_USER */
137
+ /* c: PAGE_KERNEL_RO PTE_UXN | PTE_PXN */
138
+ /* d: PAGE_READONLY PTE_UXN | PTE_PXN | PTE_USER */
139
+ /* e: PAGE_KERNEL PTE_UXN | PTE_PXN | PTE_WRITE */
140
+ /* f: PAGE_SHARED PTE_UXN | PTE_PXN | PTE_WRITE | PTE_USER */
141
+
142
+ #define PIE_E0 ( \
143
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \
144
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX) | \
145
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX) | \
146
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R) | \
147
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW))
148
+
149
+ #define PIE_E1 ( \
150
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \
151
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \
152
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \
153
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R) | \
154
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW) | \
155
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_ROX), PIE_RX) | \
156
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_EXEC), PIE_RWX) | \
157
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_RO), PIE_R) | \
158
+ PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL), PIE_RW))
159
+
94
160
#endif /* __ASM_PGTABLE_PROT_H */
0 commit comments