* [PATCH v5 0/6] initialize SCTRL2_ELx
@ 2025-09-17 14:56 Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
This series introduces initial support for the SCTLR2_ELx registers in Linux.
The feature is optional starting from ARMv8.8/ARMv9.3,
and becomes mandatory from ARMv8.9/ARMv9.4.
Currently, Linux has no strict need to modify SCTLR2_ELx--
at least assuming that firmware initializes
these registers to reasonable defaults.
However, several upcoming architectural features will require configuring
control bits in these registers.
Notable examples include FEAT_PAuth_LR and FEAT_CPA2.
Patch History
==============
from v4 to v5:
- using .ifc in set_sctlr2_elx
- change (re)initialise position after SCTLR_ELx
- add docs for SCTRL2_ELx
- rebase to v6.17-rc6
- https://lore.kernel.org/all/20250821172408.2101870-1-yeoreum.yun@arm.com/
from v3 to v4:
- integrate set_sctlr2_elx() and __set_sctlr2_elx() to set_sctlr2_elx()
without isb()
- fix the wrong register setting in set_sctlr2_elx().
- add initialise SCTLR2_EL2 at HVC_SOFT_RESTART.
- https://lore.kernel.org/all/20250813120118.3953541-1-yeoreum.yun@arm.com/
from v2 to v3:
- rewrite commit messages.
- fix missing SCTLR2_EL2 synchonization at boot.
- merging the __kvm_host_psci_cpu_entry() changes into patch #1
- https://lore.kernel.org/all/20250811163340.1561893-1-yeoreum.yun@arm.com/
from v1 to v2:
- rebase to v6.17-rc1
- https://lore.kernel.org/all/20250804121724.3681531-1-yeoreum.yun@arm.com/
Dave Martin (1):
docs: arm64: Document booting requirements for FEAT_SCTLR2
Yeoreum Yun (5):
arm64: make SCTLR2_EL1 accessible
arm64: initialise SCTLR2_ELx register at boot time
arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume()
arm64: initialise SCTLR2_EL1 at cpu_soft_restart()
arm64: make the per-task SCTLR2_EL1
Documentation/arch/arm64/booting.rst | 10 ++++++++++
arch/arm64/include/asm/assembler.h | 15 +++++++++++++++
arch/arm64/include/asm/el2_setup.h | 17 +++++++++++++++--
arch/arm64/include/asm/processor.h | 3 +++
arch/arm64/include/asm/suspend.h | 2 +-
arch/arm64/include/asm/sysreg.h | 5 +++++
arch/arm64/kernel/cpu-reset.S | 3 +++
arch/arm64/kernel/head.S | 5 +++++
arch/arm64/kernel/hyp-stub.S | 13 +++++++++++++
arch/arm64/kernel/process.c | 9 +++++++++
arch/arm64/kvm/hyp/nvhe/hyp-init.S | 3 +++
arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++
arch/arm64/mm/proc.S | 24 ++++++++++++++++--------
13 files changed, 101 insertions(+), 11 deletions(-)
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v5 1/6] arm64: make SCTLR2_EL1 accessible
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
When the kernel runs at EL1, and yet is booted at EL2,
HCRX_EL2.SCTLR2En must be set to avoid trapping SCTLR2_EL1 accesses
from EL1 to EL2.
Ensure this bit is set at the point of initialising EL2.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/el2_setup.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
index 46033027510c..d9529dfc4783 100644
--- a/arch/arm64/include/asm/el2_setup.h
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -57,10 +57,16 @@
/* Enable GCS if supported */
mrs_s x1, SYS_ID_AA64PFR1_EL1
ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
- cbz x1, .Lset_hcrx_\@
+ cbz x1, .Lskip_hcrx_GCSEn_\@
orr x0, x0, #HCRX_EL2_GCSEn
-.Lset_hcrx_\@:
+.Lskip_hcrx_GCSEn_\@:
+ mrs_s x1, SYS_ID_AA64MMFR3_EL1
+ ubfx x1, x1, #ID_AA64MMFR3_EL1_SCTLRX_SHIFT, #4
+ cbz x1, .Lskip_hcrx_SCTLR2En\@
+ orr x0, x0, #HCRX_EL2_SCTLR2En
+
+.Lskip_hcrx_SCTLR2En\@:
msr_s SYS_HCRX_EL2, x0
.Lskip_hcrx_\@:
.endm
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 2/6] arm64: initialise SCTLR2_ELx register at boot time
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
The value of the SCTLR2_ELx register is UNKNOWN after reset.
If the firmware initializes these registers properly, no additional
initialization is required.
However, in cases where they are not initialized correctly,
initialize the SCTLR2_ELx registers during CPU/vCPU boot
to prevent unexpected system behavior caused by invalid values.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/assembler.h | 15 +++++++++++++++
arch/arm64/include/asm/el2_setup.h | 7 +++++++
arch/arm64/include/asm/sysreg.h | 5 +++++
arch/arm64/kernel/head.S | 5 +++++
arch/arm64/kernel/hyp-stub.S | 13 +++++++++++++
arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++
6 files changed, 48 insertions(+)
diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 23be85d93348..c25c2aed5125 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -738,6 +738,21 @@ alternative_endif
set_sctlr sctlr_el2, \reg
.endm
+/* Set SCTLR2_ELx to the @reg value. */
+.macro set_sctlr2_elx, el, reg, tmp
+ mrs_s \tmp, SYS_ID_AA64MMFR3_EL1
+ ubfx \tmp, \tmp, #ID_AA64MMFR3_EL1_SCTLRX_SHIFT, #4
+ cbz \tmp, .Lskip_sctlr2_\@
+ .if \el == 2
+ msr_s SYS_SCTLR2_EL2, \reg
+ .elseif \el == 12
+ msr_s SYS_SCTLR2_EL12, \reg
+ .else
+ msr_s SYS_SCTLR2_EL1, \reg
+ .endif
+.Lskip_sctlr2_\@:
+.endm
+
/*
* Check whether asm code should yield as soon as it is able. This is
* the case if we are currently running in task context, and the
diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
index d9529dfc4783..2addf7c096fc 100644
--- a/arch/arm64/include/asm/el2_setup.h
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -48,6 +48,12 @@
isb
.endm
+.macro __init_sctlr2_el2
+ mov_q x0, INIT_SCTLR2_EL2
+ set_sctlr2_elx 2, x0, x1
+ isb
+.endm
+
.macro __init_el2_hcrx
mrs x0, id_aa64mmfr1_el1
ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
@@ -411,6 +417,7 @@
*/
.macro init_el2_state
__init_el2_sctlr
+ __init_sctlr2_el2
__init_el2_hcrx
__init_el2_timers
__init_el2_debug
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 6604fd6f33f4..8cf489d38724 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -868,6 +868,8 @@
#define INIT_SCTLR_EL2_MMU_OFF \
(SCTLR_EL2_RES1 | ENDIAN_SET_EL2)
+#define INIT_SCTLR2_EL2 UL(0)
+
/* SCTLR_EL1 specific flags. */
#ifdef CONFIG_CPU_BIG_ENDIAN
#define ENDIAN_SET_EL1 (SCTLR_EL1_E0E | SCTLR_ELx_EE)
@@ -888,6 +890,8 @@
SCTLR_EL1_LSMAOE | SCTLR_EL1_nTLSMD | SCTLR_EL1_EIS | \
SCTLR_EL1_TSCXT | SCTLR_EL1_EOS)
+#define INIT_SCTLR2_EL1 UL(0)
+
/* MAIR_ELx memory attributes (used by Linux) */
#define MAIR_ATTR_DEVICE_nGnRnE UL(0x00)
#define MAIR_ATTR_DEVICE_nGnRE UL(0x04)
@@ -1161,6 +1165,7 @@
msr hcr_el2, \reg
#endif
.endm
+
#else
#include <linux/bitfield.h>
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index ca04b338cb0d..e42664246e15 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -276,6 +276,8 @@ SYM_INNER_LABEL(init_el1, SYM_L_LOCAL)
mov_q x0, INIT_SCTLR_EL1_MMU_OFF
pre_disable_mmu_workaround
msr sctlr_el1, x0
+ mov_q x0, INIT_SCTLR2_EL1
+ set_sctlr2_elx 1, x0, x1
isb
mov_q x0, INIT_PSTATE_EL1
msr spsr_el1, x0
@@ -308,6 +310,7 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
isb
mov_q x1, INIT_SCTLR_EL1_MMU_OFF
+ mov_q x2, INIT_SCTLR2_EL1
mrs x0, hcr_el2
and x0, x0, #HCR_E2H
@@ -315,11 +318,13 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
/* Set a sane SCTLR_EL1, the VHE way */
msr_s SYS_SCTLR_EL12, x1
+ set_sctlr2_elx 12, x2, x0
mov x2, #BOOT_CPU_FLAG_E2H
b 3f
2:
msr sctlr_el1, x1
+ set_sctlr2_elx 1, x2, x0
mov x2, xzr
3:
mov x0, #INIT_PSTATE_EL1
diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S
index 36e2d26b54f5..7a59725fdbb6 100644
--- a/arch/arm64/kernel/hyp-stub.S
+++ b/arch/arm64/kernel/hyp-stub.S
@@ -178,6 +178,19 @@ SYM_CODE_START_LOCAL(enter_vhe)
mov_q x0, INIT_SCTLR_EL1_MMU_OFF
msr_s SYS_SCTLR_EL12, x0
+ mrs_s x0, SYS_ID_AA64MMFR3_EL1
+ ubfx x0, x0, #ID_AA64MMFR3_EL1_SCTLRX_SHIFT, #4
+ cbz x0, .Lskip_sctlr2
+
+ // setup SCTLR2_EL2 from EL1
+ mrs_s x0, SYS_SCTLR2_EL12
+ msr_s SYS_SCTLR2_EL1, x0
+
+ // clean SCTLR2_EL1
+ mov_q x0, INIT_SCTLR2_EL1
+ msr_s SYS_SCTLR2_EL12, x0
+
+.Lskip_sctlr2:
mov x0, xzr
eret
diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index c3e196fb8b18..df1180cad7f8 100644
--- a/arch/arm64/kvm/hyp/nvhe/psci-relay.c
+++ b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
@@ -4,6 +4,7 @@
* Author: David Brazdil <dbrazdil@google.com>
*/
+#include <asm/cpufeature.h>
#include <asm/kvm_asm.h>
#include <asm/kvm_hyp.h>
#include <asm/kvm_mmu.h>
@@ -219,6 +220,8 @@ asmlinkage void __noreturn __kvm_host_psci_cpu_entry(bool is_cpu_on)
release_boot_args(boot_args);
write_sysreg_el1(INIT_SCTLR_EL1_MMU_OFF, SYS_SCTLR);
+ if (cpus_have_final_cap(ARM64_HAS_SCTLR2))
+ write_sysreg_el1(INIT_SCTLR2_EL1, SYS_SCTLR2);
write_sysreg(INIT_PSTATE_EL1, SPSR_EL2);
__host_enter(host_ctxt);
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume()
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 4/6] arm64: initialise SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Save and restore the SCTLR2_EL1 value during cpu_suspend()/resume(),
ensuring that the configured value remains
consistent across suspend and resume.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/suspend.h | 2 +-
arch/arm64/mm/proc.S | 24 ++++++++++++++++--------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/arch/arm64/include/asm/suspend.h b/arch/arm64/include/asm/suspend.h
index 0cde2f473971..eb60c9735553 100644
--- a/arch/arm64/include/asm/suspend.h
+++ b/arch/arm64/include/asm/suspend.h
@@ -2,7 +2,7 @@
#ifndef __ASM_SUSPEND_H
#define __ASM_SUSPEND_H
-#define NR_CTX_REGS 13
+#define NR_CTX_REGS 14
#define NR_CALLEE_SAVED_REGS 12
/*
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index 8c75965afc9e..a330d828270f 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -87,8 +87,12 @@ SYM_FUNC_START(cpu_do_suspend)
mrs x9, mdscr_el1
mrs x10, oslsr_el1
mrs x11, sctlr_el1
- get_this_cpu_offset x12
- mrs x13, sp_el0
+alternative_if ARM64_HAS_SCTLR2
+ mrs_s x12, SYS_SCTLR2_EL1
+alternative_else_nop_endif
+ get_this_cpu_offset x13
+ mrs x14, sp_el0
+
stp x2, x3, [x0]
stp x4, x5, [x0, #16]
stp x6, x7, [x0, #32]
@@ -99,7 +103,7 @@ SYM_FUNC_START(cpu_do_suspend)
* Save x18 as it may be used as a platform register, e.g. by shadow
* call stack.
*/
- str x18, [x0, #96]
+ stp x14, x18, [x0, #96]
ret
SYM_FUNC_END(cpu_do_suspend)
@@ -120,8 +124,8 @@ SYM_FUNC_START(cpu_do_resume)
* the buffer to minimize the risk of exposure when used for shadow
* call stack.
*/
- ldr x18, [x0, #96]
- str xzr, [x0, #96]
+ ldp x15, x18, [x0, #96]
+ str xzr, [x0, #104]
msr tpidr_el0, x2
msr tpidrro_el0, x3
msr contextidr_el1, x4
@@ -136,8 +140,12 @@ SYM_FUNC_START(cpu_do_resume)
msr mdscr_el1, x10
msr sctlr_el1, x12
- set_this_cpu_offset x13
- msr sp_el0, x14
+alternative_if ARM64_HAS_SCTLR2
+ msr_s SYS_SCTLR2_EL1, x13
+alternative_else_nop_endif
+
+ set_this_cpu_offset x14
+ msr sp_el0, x15
/*
* Restore oslsr_el1 by writing oslar_el1
*/
@@ -151,7 +159,7 @@ alternative_if ARM64_HAS_RAS_EXTN
msr_s SYS_DISR_EL1, xzr
alternative_else_nop_endif
- ptrauth_keys_install_kernel_nosync x14, x1, x2, x3
+ ptrauth_keys_install_kernel_nosync x15, x1, x2, x3
isb
ret
SYM_FUNC_END(cpu_do_resume)
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 4/6] arm64: initialise SCTLR2_EL1 at cpu_soft_restart()
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
` (2 preceding siblings ...)
2025-09-17 14:56 ` [PATCH v5 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Explicitly initialize the SCTLR2_ELx register before launching
a new kernel via kexec() to avoid leaving SCTLR2_ELx with an
arbitrary value when the new kernel runs.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/kernel/cpu-reset.S | 3 +++
arch/arm64/kvm/hyp/nvhe/hyp-init.S | 3 +++
2 files changed, 6 insertions(+)
diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S
index c87445dde674..e2abc8f8c067 100644
--- a/arch/arm64/kernel/cpu-reset.S
+++ b/arch/arm64/kernel/cpu-reset.S
@@ -30,6 +30,9 @@
* flat identity mapping.
*/
SYM_TYPED_FUNC_START(cpu_soft_restart)
+ mov_q x12, INIT_SCTLR2_EL1
+ set_sctlr2_elx 1, x12, x8
+
mov_q x12, INIT_SCTLR_EL1_MMU_OFF
pre_disable_mmu_workaround
/*
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index aada42522e7b..cc569656fe35 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -255,6 +255,9 @@ SYM_CODE_START(__kvm_handle_stub_hvc)
mov x0, xzr
reset:
/* Reset kvm back to the hyp stub. */
+ mov_q x5, INIT_SCTLR2_EL2
+ set_sctlr2_elx 2, x5, x4
+
mov_q x5, INIT_SCTLR_EL2_MMU_OFF
pre_disable_mmu_workaround
msr sctlr_el2, x5
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 5/6] arm64: make the per-task SCTLR2_EL1
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
` (3 preceding siblings ...)
2025-09-17 14:56 ` [PATCH v5 4/6] arm64: initialise SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 6/6] docs: arm64: Document booting requirements for FEAT_SCTLR2 Yeoreum Yun
2025-09-17 15:28 ` [PATCH v5 0/6] initialize SCTRL2_ELx Will Deacon
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Some bits in SCTLR2_EL1 that control system behavior can be
configured on a per-task basis (e.g., fields related to FEAT_CPA2).
To support future use of these fields, SCTLR2_EL1 is maintained
per task.
On platforms without FEAT_SCTLR2 support, there is no functional
change and only minimal performance overhead.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/processor.h | 3 +++
arch/arm64/kernel/process.c | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 61d62bfd5a7b..e066116735c6 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -184,6 +184,7 @@ struct thread_struct {
u64 mte_ctrl;
#endif
u64 sctlr_user;
+ u64 sctlr2_user;
u64 svcr;
u64 tpidr2_el0;
u64 por_el0;
@@ -258,6 +259,8 @@ static inline void task_set_sve_vl_onexec(struct task_struct *task,
(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | \
SCTLR_EL1_TCF0_MASK)
+#define SCTLR2_USER_MASK (0)
+
static inline void arch_thread_struct_whitelist(unsigned long *offset,
unsigned long *size)
{
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 96482a1412c6..e54f192c0629 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -698,6 +698,11 @@ void update_sctlr_el1(u64 sctlr)
isb();
}
+static void update_sctlr2_el1(u64 sctlr2)
+{
+ sysreg_clear_set_s(SYS_SCTLR2_EL1, SCTLR2_USER_MASK, sctlr2);
+}
+
/*
* Thread switching.
*/
@@ -737,6 +742,10 @@ struct task_struct *__switch_to(struct task_struct *prev,
if (prev->thread.sctlr_user != next->thread.sctlr_user)
update_sctlr_el1(next->thread.sctlr_user);
+ if (alternative_has_cap_unlikely(ARM64_HAS_SCTLR2) &&
+ prev->thread.sctlr2_user != next->thread.sctlr2_user)
+ update_sctlr2_el1(next->thread.sctlr2_user);
+
/* the actual thread switch */
last = cpu_switch_to(prev, next);
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v5 6/6] docs: arm64: Document booting requirements for FEAT_SCTLR2
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
` (4 preceding siblings ...)
2025-09-17 14:56 ` [PATCH v5 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
@ 2025-09-17 14:56 ` Yeoreum Yun
2025-09-17 15:28 ` [PATCH v5 0/6] initialize SCTRL2_ELx Will Deacon
6 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 14:56 UTC (permalink / raw)
To: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, maz
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
From: Dave Martin <Dave.Martin@arm.com>
Support for FEAT_SCTLR2 imposes some requirments on the configuration
of traps at exception levels above the level at which the kernel is
booted.
Document them.
For now, don't document requirements on the initial state of SCTLR2_ELx
at the kernel boot exception level. The general wording under "System
registers" appiles. (SCTLR_ELx is similarly undocumented.)
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
Documentation/arch/arm64/booting.rst | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Documentation/arch/arm64/booting.rst b/Documentation/arch/arm64/booting.rst
index 2f666a7c303c..e8fe1b2023a9 100644
--- a/Documentation/arch/arm64/booting.rst
+++ b/Documentation/arch/arm64/booting.rst
@@ -545,6 +545,16 @@ Before jumping into the kernel, the following conditions must be met:
- MDCR_EL3.TPM (bit 6) must be initialized to 0b0
+ For CPUs with the SCTLR2_ELx registers (FEAT_SCTLR2):
+
+ - If EL3 is present:
+
+ - SCR_EL3.SCTLR2En (bit 44) must be initialised to 0b1.
+
+ - If the kernel is entered at EL1 and EL2 is present:
+
+ - HCRX_EL2.SCTLR2En (bit 15) must be initialised to 0b1.
+
The requirements described above for CPU mode, caches, MMUs, architected
timers, coherency and system registers apply to all CPUs. All CPUs must
enter the kernel in the same exception level. Where the values documented
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v5 0/6] initialize SCTRL2_ELx
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
` (5 preceding siblings ...)
2025-09-17 14:56 ` [PATCH v5 6/6] docs: arm64: Document booting requirements for FEAT_SCTLR2 Yeoreum Yun
@ 2025-09-17 15:28 ` Will Deacon
2025-09-17 16:44 ` Yeoreum Yun
6 siblings, 1 reply; 9+ messages in thread
From: Will Deacon @ 2025-09-17 15:28 UTC (permalink / raw)
To: Yeoreum Yun
Cc: catalin.marinas, broonie, oliver.upton, anshuman.khandual, robh,
james.morse, mark.rutland, joey.gouly, Dave.Martin, ahmed.genidi,
kevin.brodsky, scott, mbenes, james.clark, frederic, rafael,
pavel, ryan.roberts, suzuki.poulose, maz, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
On Wed, Sep 17, 2025 at 03:56:12PM +0100, Yeoreum Yun wrote:
> This series introduces initial support for the SCTLR2_ELx registers in Linux.
> The feature is optional starting from ARMv8.8/ARMv9.3,
> and becomes mandatory from ARMv8.9/ARMv9.4.
>
> Currently, Linux has no strict need to modify SCTLR2_ELx--
> at least assuming that firmware initializes
> these registers to reasonable defaults.
>
> However, several upcoming architectural features will require configuring
> control bits in these registers.
> Notable examples include FEAT_PAuth_LR and FEAT_CPA2.
>
> Patch History
> ==============
> from v4 to v5:
> - using .ifc in set_sctlr2_elx
> - change (re)initialise position after SCTLR_ELx
> - add docs for SCTRL2_ELx
> - rebase to v6.17-rc6
> - https://lore.kernel.org/all/20250821172408.2101870-1-yeoreum.yun@arm.com/
Sorry, this is a really pedantic nit, but please can you fix the typo in
the subject if/when you next post this?
More importantly, as Dave says, I don't see the point in merging this
until we have a use for the register. At that point, your patches can
hopefully be a prefix of the series that uses it.
Will
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v5 0/6] initialize SCTRL2_ELx
2025-09-17 15:28 ` [PATCH v5 0/6] initialize SCTRL2_ELx Will Deacon
@ 2025-09-17 16:44 ` Yeoreum Yun
0 siblings, 0 replies; 9+ messages in thread
From: Yeoreum Yun @ 2025-09-17 16:44 UTC (permalink / raw)
To: Will Deacon
Cc: catalin.marinas, broonie, oliver.upton, anshuman.khandual, robh,
james.morse, mark.rutland, joey.gouly, Dave.Martin, ahmed.genidi,
kevin.brodsky, scott, mbenes, james.clark, frederic, rafael,
pavel, ryan.roberts, suzuki.poulose, maz, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
Hi,
> On Wed, Sep 17, 2025 at 03:56:12PM +0100, Yeoreum Yun wrote:
> > This series introduces initial support for the SCTLR2_ELx registers in Linux.
> > The feature is optional starting from ARMv8.8/ARMv9.3,
> > and becomes mandatory from ARMv8.9/ARMv9.4.
> >
> > Currently, Linux has no strict need to modify SCTLR2_ELx--
> > at least assuming that firmware initializes
> > these registers to reasonable defaults.
> >
> > However, several upcoming architectural features will require configuring
> > control bits in these registers.
> > Notable examples include FEAT_PAuth_LR and FEAT_CPA2.
> >
> > Patch History
> > ==============
> > from v4 to v5:
> > - using .ifc in set_sctlr2_elx
> > - change (re)initialise position after SCTLR_ELx
> > - add docs for SCTRL2_ELx
> > - rebase to v6.17-rc6
> > - https://lore.kernel.org/all/20250821172408.2101870-1-yeoreum.yun@arm.com/
>
> Sorry, this is a really pedantic nit, but please can you fix the typo in
> the subject if/when you next post this?
>
> More importantly, as Dave says, I don't see the point in merging this
> until we have a use for the register. At that point, your patches can
> hopefully be a prefix of the series that uses it.
Okay. Thanks.
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-09-17 16:45 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 14:56 [PATCH v5 0/6] initialize SCTRL2_ELx Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 4/6] arm64: initialise SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
2025-09-17 14:56 ` [PATCH v5 6/6] docs: arm64: Document booting requirements for FEAT_SCTLR2 Yeoreum Yun
2025-09-17 15:28 ` [PATCH v5 0/6] initialize SCTRL2_ELx Will Deacon
2025-09-17 16:44 ` Yeoreum Yun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox