Skip to content

Commit ff5181d

Browse files
brooniectmarinas
authored andcommitted
arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0 and EL1
There is a control HCRX_EL2.GCSEn which must be set to allow GCS features to take effect at lower ELs and also fine grained traps for GCS usage at EL0 and EL1. Configure all these to allow GCS usage by EL0 and EL1. We also initialise GCSCR_EL1 and GCSCRE0_EL1 to ensure that we can execute function call instructions without faulting regardless of the state when the kernel is started. Reviewed-by: Thiago Jung Bauermann <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent d0aa2b4 commit ff5181d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

arch/arm64/include/asm/el2_setup.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
2828
cbz x0, .Lskip_hcrx_\@
2929
mov_q x0, HCRX_HOST_FLAGS
30+
31+
/* Enable GCS if supported */
32+
mrs_s x1, SYS_ID_AA64PFR1_EL1
33+
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
34+
cbz x1, .Lset_hcrx_\@
35+
orr x0, x0, #HCRX_EL2_GCSEn
36+
37+
.Lset_hcrx_\@:
3038
msr_s SYS_HCRX_EL2, x0
3139
.Lskip_hcrx_\@:
3240
.endm
@@ -200,6 +208,16 @@
200208
orr x0, x0, #HFGxTR_EL2_nPOR_EL0
201209

202210
.Lskip_poe_fgt_\@:
211+
/* GCS depends on PIE so we don't check it if PIE is absent */
212+
mrs_s x1, SYS_ID_AA64PFR1_EL1
213+
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
214+
cbz x1, .Lset_fgt_\@
215+
216+
/* Disable traps of access to GCS registers at EL0 and EL1 */
217+
orr x0, x0, #HFGxTR_EL2_nGCS_EL1_MASK
218+
orr x0, x0, #HFGxTR_EL2_nGCS_EL0_MASK
219+
220+
.Lset_fgt_\@:
203221
msr_s SYS_HFGRTR_EL2, x0
204222
msr_s SYS_HFGWTR_EL2, x0
205223
msr_s SYS_HFGITR_EL2, xzr
@@ -215,6 +233,17 @@
215233
.Lskip_fgt_\@:
216234
.endm
217235

236+
.macro __init_el2_gcs
237+
mrs_s x1, SYS_ID_AA64PFR1_EL1
238+
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
239+
cbz x1, .Lskip_gcs_\@
240+
241+
/* Ensure GCS is not enabled when we start trying to do BLs */
242+
msr_s SYS_GCSCR_EL1, xzr
243+
msr_s SYS_GCSCRE0_EL1, xzr
244+
.Lskip_gcs_\@:
245+
.endm
246+
218247
.macro __init_el2_nvhe_prepare_eret
219248
mov x0, #INIT_PSTATE_EL1
220249
msr spsr_el2, x0
@@ -240,6 +269,7 @@
240269
__init_el2_nvhe_idregs
241270
__init_el2_cptr
242271
__init_el2_fgt
272+
__init_el2_gcs
243273
.endm
244274

245275
#ifndef __KVM_NVHE_HYPERVISOR__

0 commit comments

Comments
 (0)