]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
arm64/gcs: Don't try to access GCS registers if arm64.nogcs is enabled
authorMark Brown <broonie@kernel.org>
Thu, 19 Jun 2025 21:15:41 +0000 (22:15 +0100)
committerWill Deacon <will@kernel.org>
Fri, 4 Jul 2025 15:29:12 +0000 (16:29 +0100)
During EL2 setup if GCS is advertised in the ID registers we will reset the
GCS control registers GCSCR_EL1 and GCSCRE0_EL1 to known values in order to
ensure it is disabled. This is done without taking into account overrides
supplied on the command line, meaning that if the user has configured
arm64.nogcs we will still access these GCS specific registers. If this was
done because EL3 does not enable GCS this results in traps to EL3 and a
failed boot which is not what users would expect from having set that
parameter.

Move the writes to these registers to finalise_el2_state where we can pay
attention to the command line overrides. For simplicity we leave the
updates to the traps in HCRX_EL2 and the FGT registers in place since these
should only be relevant for KVM guests and KVM will manage them itself for
guests. This follows the existing practice for other similar traps for
overridable features such as those for TPIDR2_EL0 and SMPRI_EL1.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250619-arm64-fix-nogcs-v1-1-febf2973672e@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/el2_setup.h

index ba5df0df02a467c800e262094b5c9e7f5911e760..9f38340d24c226df046dd62a4be5d416f9270533 100644 (file)
 .Lskip_fgt2_\@:
 .endm
 
-.macro __init_el2_gcs
-       mrs_s   x1, SYS_ID_AA64PFR1_EL1
-       ubfx    x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
-       cbz     x1, .Lskip_gcs_\@
-
-       /* Ensure GCS is not enabled when we start trying to do BLs */
-       msr_s   SYS_GCSCR_EL1, xzr
-       msr_s   SYS_GCSCRE0_EL1, xzr
-.Lskip_gcs_\@:
-.endm
-
 /**
  * Initialize EL2 registers to sane values. This should be called early on all
  * cores that were booted in EL2. Note that everything gets initialised as
        __init_el2_cptr
        __init_el2_fgt
        __init_el2_fgt2
-        __init_el2_gcs
 .endm
 
 #ifndef __KVM_NVHE_HYPERVISOR__
        msr_s   SYS_MPAMHCR_EL2, xzr            // clear TRAP_MPAMIDR_EL1 -> EL2
 
 .Lskip_mpam_\@:
+       check_override id_aa64pfr1, ID_AA64PFR1_EL1_GCS_SHIFT, .Linit_gcs_\@, .Lskip_gcs_\@, x1, x2
+
+.Linit_gcs_\@:
+       msr_s   SYS_GCSCR_EL1, xzr
+       msr_s   SYS_GCSCRE0_EL1, xzr
+
+.Lskip_gcs_\@:
        check_override id_aa64pfr0, ID_AA64PFR0_EL1_SVE_SHIFT, .Linit_sve_\@, .Lskip_sve_\@, x1, x2
 
 .Linit_sve_\@: /* SVE register access */