Skip to content

Commit eeda243

Browse files
jgoulyctmarinas
authored andcommitted
arm64: add encodings of PIRx_ELx registers
The encodings used in the permission indirection registers means that the values that Linux puts in the PTEs do not need to be changed. The E0 values are replicated in E1, with the execute permissions removed. This is needed as the futex operations access user mappings with privileged loads/stores. Signed-off-by: Joey Gouly <[email protected]> Cc: Will Deacon <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 7df7170 commit eeda243

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

arch/arm64/include/asm/pgtable-hwdef.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@
170170
#define PTE_ATTRINDX(t) (_AT(pteval_t, (t)) << 2)
171171
#define PTE_ATTRINDX_MASK (_AT(pteval_t, 7) << 2)
172172

173+
/*
174+
* PIIndex[3:0] encoding (Permission Indirection Extension)
175+
*/
176+
#define PTE_PI_IDX_0 6 /* AP[1], USER */
177+
#define PTE_PI_IDX_1 51 /* DBM */
178+
#define PTE_PI_IDX_2 53 /* PXN */
179+
#define PTE_PI_IDX_3 54 /* UXN */
180+
173181
/*
174182
* Memory Attribute override for Stage-2 (MemAttr[3:0])
175183
*/

arch/arm64/include/asm/pgtable-prot.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,54 @@ extern bool arm64_use_ng_mappings;
107107

108108
#endif /* __ASSEMBLY__ */
109109

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+
110160
#endif /* __ASM_PGTABLE_PROT_H */

0 commit comments

Comments
 (0)