* [PATCH 00/11] support SCTLR2_ELx
@ 2025-08-04 12:17 Yeoreum Yun
2025-08-04 12:17 ` [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2 Yeoreum Yun
` (11 more replies)
0 siblings, 12 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
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.
This series is based on v6.16 and probably KVM-safe but
Not tested yet:
- nVHE boot.
Yeoreum Yun (11):
arm64/sysreg: add system registers SCTLR2_EL2
arm64: make SCTLR2_EL1 accessible
arm64: initialise SCTLR2_ELx register at boot time
arm64: cpufeature: add FEAT_SCTLR2 feature
arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume()
arm64: init SCTLR2_EL1 at cpu_soft_restart()
arm64: make the per-task SCTLR2_EL1
KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
KVM: arm64: support SCTLR2_EL1 for guest
KVM: arm64: nv: support SCTLR2_ELx on nv
KVM: arm64: expose FEAT_SCTLR2 feature to guest
arch/arm64/include/asm/el2_setup.h | 14 +++++++++++-
arch/arm64/include/asm/kvm_host.h | 7 ++++++
arch/arm64/include/asm/processor.h | 5 +++++
arch/arm64/include/asm/suspend.h | 2 +-
arch/arm64/include/asm/sysreg.h | 22 ++++++++++++++++++
arch/arm64/include/asm/vncr_mapping.h | 1 +
arch/arm64/kernel/cpu-reset.S | 6 +++++
arch/arm64/kernel/cpufeature.c | 8 +++++++
arch/arm64/kernel/head.S | 5 ++++-
arch/arm64/kernel/process.c | 9 ++++++++
arch/arm64/kvm/emulate-nested.c | 2 ++
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 16 +++++++++++++
arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++
arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 6 +++++
arch/arm64/kvm/nested.c | 13 +++++++++++
arch/arm64/kvm/sys_regs.c | 25 +++++++++++++++++++--
arch/arm64/mm/proc.S | 26 +++++++++++++++-------
arch/arm64/tools/cpucaps | 1 +
arch/arm64/tools/sysreg | 17 ++++++++++++++
19 files changed, 175 insertions(+), 13 deletions(-)
base-commit: 038d61fd642278bab63ee8ef722c50d10ab01e8f
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:24 ` Mark Brown
2025-08-04 12:17 ` [PATCH 02/11] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
` (10 subsequent siblings)
11 siblings, 1 reply; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Add definitions of SCTLR2_EL2.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/tools/sysreg | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index 8a8cf6874298..ae655672a944 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -2469,6 +2469,23 @@ Sysreg SCTLR2ALIAS_EL1 3 0 1 4 7
Mapping SCTLR2_EL1
EndSysreg
+Sysreg SCTLR2_EL2 3 4 1 0 3
+Res0 63:13
+Field 12 CPTM0
+Field 11 CPTM
+Field 10 CPTA0
+Field 9 CPTA
+Field 8 EnPACM0
+Field 7 EnPACM
+Field 6 EnIDCP128
+Field 5 EASE
+Field 4 EnANERR
+Field 3 EnADERR
+Field 2 NMEA
+Field 1 EMEC
+Res0 0
+EndSysreg
+
Sysreg SCTLR2MASK_EL1 3 0 1 4 3
Res0 63:13
Field 12 CPTM0
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 02/11] arm64: make SCTLR2_EL1 accessible
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
2025-08-04 12:17 ` [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2 Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 03/11] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
` (9 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
make SCTLR2_EL1 accssible to initilise it.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/el2_setup.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
index 9f38340d24c2..33b59601e8c2 100644
--- a/arch/arm64/include/asm/el2_setup.h
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -57,9 +57,15 @@
/* 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
+.Lskip_hcrx_GCSEn_\@:
+ mrs_s x1, SYS_ID_AA64MMFR3_EL1
+ ubfx x1, x1, #ID_AA64MMFR3_EL1_SCTLRX_SHIFT, #4
+ cbz x1, .Lset_hcrx_\@
+ orr x0, x0, HCRX_EL2_SCTLR2En
+
.Lset_hcrx_\@:
msr_s SYS_HCRX_EL2, x0
.Lskip_hcrx_\@:
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 03/11] arm64: initialise SCTLR2_ELx register at boot time
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
2025-08-04 12:17 ` [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2 Yeoreum Yun
2025-08-04 12:17 ` [PATCH 02/11] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 04/11] arm64: cpufeature: add FEAT_SCTLR2 feature Yeoreum Yun
` (8 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
add initialisation for SCTRL2_ELx register at boot time.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/el2_setup.h | 6 ++++++
arch/arm64/include/asm/sysreg.h | 22 ++++++++++++++++++++++
arch/arm64/kernel/head.S | 5 ++++-
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
index 33b59601e8c2..c519b6e923ad 100644
--- a/arch/arm64/include/asm/el2_setup.h
+++ b/arch/arm64/include/asm/el2_setup.h
@@ -48,6 +48,11 @@
isb
.endm
+.macro __init_el2_sctlr2
+ init_sctlr2_elx 2, x0
+ isb
+.endm
+
.macro __init_el2_hcrx
mrs x0, id_aa64mmfr1_el1
ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4
@@ -303,6 +308,7 @@
*/
.macro init_el2_state
__init_el2_sctlr
+ __init_el2_sctlr2
__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 f1bb0d10c39a..ee4c6033b0d2 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)
@@ -1103,6 +1107,24 @@
msr hcr_el2, \reg
#endif
.endm
+
+ .macro init_sctlr2_elx, el, tmp
+ mrs_s \tmp, SYS_ID_AA64MMFR3_EL1
+ ubfx \tmp, \tmp, #ID_AA64MMFR3_EL1_SCTLRX_SHIFT, #4
+ cbz \tmp, .Lskip_sctlr2_\@
+ .if \el == 2
+ mov_q \tmp, INIT_SCTLR2_EL2
+ msr_s SYS_SCTLR_EL2, \tmp
+ .else
+ mov_q \tmp, INIT_SCTLR2_EL1
+ .if \el == 12
+ msr_s SYS_SCTLR_EL12, \tmp
+ .else
+ msr_s SYS_SCTLR_EL1, \tmp
+ .endif
+ .endif
+.Lskip_sctlr2_\@:
+ .endm
#else
#include <linux/bitfield.h>
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index ca04b338cb0d..0dff7593e50b 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -276,6 +276,7 @@ SYM_INNER_LABEL(init_el1, SYM_L_LOCAL)
mov_q x0, INIT_SCTLR_EL1_MMU_OFF
pre_disable_mmu_workaround
msr sctlr_el1, x0
+ init_sctlr2_elx 1, x0
isb
mov_q x0, INIT_PSTATE_EL1
msr spsr_el1, x0
@@ -298,7 +299,6 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
msr sctlr_el2, x0
isb
0:
-
init_el2_hcr HCR_HOST_NVHE_FLAGS
init_el2_state
@@ -315,12 +315,15 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL)
/* Set a sane SCTLR_EL1, the VHE way */
msr_s SYS_SCTLR_EL12, x1
+ init_sctlr2_elx 12, x2
mov x2, #BOOT_CPU_FLAG_E2H
b 3f
2:
msr sctlr_el1, x1
+ init_sctlr2_elx 1, x2
mov x2, xzr
+
3:
mov x0, #INIT_PSTATE_EL1
msr spsr_el2, x0
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 04/11] arm64: cpufeature: add FEAT_SCTLR2 feature
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (2 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 03/11] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 05/11] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
` (7 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Since Armv8.8 architecture FEAT_SCTLR2 is supported to provide
extensions of top-level control system
(i.e) FEAT_PAuth_LR, FEAT_CPA/CPA2, FEAT_MEC and etc.
To use related system extensions in the future, add SCTLR2 feature.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/kernel/cpufeature.c | 8 ++++++++
arch/arm64/tools/cpucaps | 1 +
2 files changed, 9 insertions(+)
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index e151585c6cca..4aa83221a4a6 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -500,6 +500,7 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr3[] = {
ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_POE),
FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_S1POE_SHIFT, 4, 0),
ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_S1PIE_SHIFT, 4, 0),
+ ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_SCTLRX_SHIFT, 4, 0),
ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR3_EL1_TCRX_SHIFT, 4, 0),
ARM64_FTR_END,
};
@@ -3061,6 +3062,13 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
.matches = has_pmuv3,
},
#endif
+ {
+ .desc = "Secondary System Control Register (SCTLR2)",
+ .capability = ARM64_HAS_SCTLR2,
+ .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+ .matches = has_cpuid_feature,
+ ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, SCTLRX, IMP)
+ },
{},
};
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 10effd4cff6b..a0184295c5d9 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -52,6 +52,7 @@ HAS_S1POE
HAS_RAS_EXTN
HAS_RNG
HAS_SB
+HAS_SCTLR2
HAS_STAGE2_FWB
HAS_TCR2
HAS_TIDCP1
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 05/11] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume()
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (3 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 04/11] arm64: cpufeature: add FEAT_SCTLR2 feature Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 06/11] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
` (6 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
save/restore SCTLR2_EL1 when cpu_suspend()/resume().
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/suspend.h | 2 +-
arch/arm64/mm/proc.S | 26 ++++++++++++++++++--------
2 files changed, 19 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 54dccfd6aa11..155d930b6d99 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -87,8 +87,14 @@ 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_not ARM64_HAS_SCTLR2
+ mov x12, xzr
+alternative_else
+ mrs_s x12, SYS_SCTLR2_EL1
+alternative_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 +105,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 +126,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 +142,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 +161,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] 19+ messages in thread
* [PATCH 06/11] arm64: init SCTLR2_EL1 at cpu_soft_restart()
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (4 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 05/11] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 07/11] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
` (5 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Initailize SCTLR2_EL1 at cpu_soft_restart().
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/kernel/cpu-reset.S | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S
index c87445dde674..123564af345b 100644
--- a/arch/arm64/kernel/cpu-reset.S
+++ b/arch/arm64/kernel/cpu-reset.S
@@ -37,6 +37,12 @@ SYM_TYPED_FUNC_START(cpu_soft_restart)
* regime if HCR_EL2.E2H == 1
*/
msr sctlr_el1, x12
+
+alternative_if ARM64_HAS_SCTLR2
+ mov_q x12, INIT_SCTLR2_EL1
+ msr_s SYS_SCTLR2_EL1, x12
+alternative_else_nop_endif
+
isb
cbz x0, 1f // el2_switch?
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 07/11] arm64: make the per-task SCTLR2_EL1
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (5 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 06/11] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-05 9:01 ` kernel test robot
2025-08-04 12:17 ` [PATCH 08/11] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
` (4 subsequent siblings)
11 siblings, 1 reply; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Some of field of SCTLR2 registers should be configurable per task
not globally -- i.e) FEAT_CPA2 related field and etc.
For future usage of these fields, make the per-task SCTLR2_EL1.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/processor.h | 5 +++++
arch/arm64/kernel/process.c | 9 +++++++++
2 files changed, 14 insertions(+)
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 1bf1a3b16e88..7980161172f7 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -182,6 +182,7 @@ struct thread_struct {
u64 mte_ctrl;
#endif
u64 sctlr_user;
+ u64 sctlr2_user;
u64 svcr;
u64 tpidr2_el0;
u64 por_el0;
@@ -256,6 +257,9 @@ 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 \
+ (SCTLR2_EL1_EnPACM0 | SCTLR2_EL1_CPTA0 | SCTLR2_EL1_CPTM0)
+
static inline void arch_thread_struct_whitelist(unsigned long *offset,
unsigned long *size)
{
@@ -368,6 +372,7 @@ struct task_struct;
unsigned long __get_wchan(struct task_struct *p);
void update_sctlr_el1(u64 sctlr);
+void update_sctlr2_el1(u64 sctlr2);
/* Thread switching */
extern struct task_struct *cpu_switch_to(struct task_struct *prev,
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 08b7042a2e2d..e86325d07fa8 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -699,6 +699,11 @@ void update_sctlr_el1(u64 sctlr)
isb();
}
+void update_sctlr2_el1(u64 sctlr2)
+{
+ sysreg_clear_set(sctlr2_el1, SCTLR2_USER_MASK, sctlr2);
+}
+
/*
* Thread switching.
*/
@@ -738,6 +743,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] 19+ messages in thread
* [PATCH 08/11] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (6 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 07/11] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 09/11] KVM: arm64: support SCTLR2_EL1 for guest Yeoreum Yun
` (3 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry().
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/kvm/hyp/nvhe/psci-relay.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm64/kvm/hyp/nvhe/psci-relay.c b/arch/arm64/kvm/hyp/nvhe/psci-relay.c
index c3e196fb8b18..4ed4b7fa57c2 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/alternative.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 (alternative_has_cap_unlikely(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] 19+ messages in thread
* [PATCH 09/11] KVM: arm64: support SCTLR2_EL1 for guest
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (7 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 08/11] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv Yeoreum Yun
` (2 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
support SCTLR2_EL1 system register for guest.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/kvm_host.h | 4 ++++
arch/arm64/include/asm/vncr_mapping.h | 1 +
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 16 ++++++++++++++++
arch/arm64/kvm/sys_regs.c | 11 +++++++++++
4 files changed, 32 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 3e41a880b062..4ff0ebcc2f60 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -532,6 +532,7 @@ enum vcpu_sysreg {
VNCR(SCTLR_EL1),/* System Control Register */
VNCR(ACTLR_EL1),/* Auxiliary Control Register */
VNCR(CPACR_EL1),/* Coprocessor Access Control */
+ VNCR(SCTLR2_EL1),/* Extended System Control Register */
VNCR(ZCR_EL1), /* SVE Control */
VNCR(TTBR0_EL1),/* Translation Table Base Register 0 */
VNCR(TTBR1_EL1),/* Translation Table Base Register 1 */
@@ -1659,6 +1660,9 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val);
#define kvm_has_tcr2(k) \
(kvm_has_feat((k), ID_AA64MMFR3_EL1, TCRX, IMP))
+#define kvm_has_sctlr2(k) \
+ (kvm_has_feat((k), ID_AA64MMFR3_EL1, SCTLRX, IMP))
+
#define kvm_has_s1pie(k) \
(kvm_has_feat((k), ID_AA64MMFR3_EL1, S1PIE, IMP))
diff --git a/arch/arm64/include/asm/vncr_mapping.h b/arch/arm64/include/asm/vncr_mapping.h
index 6f556e993644..ce7a401cb1be 100644
--- a/arch/arm64/include/asm/vncr_mapping.h
+++ b/arch/arm64/include/asm/vncr_mapping.h
@@ -51,6 +51,7 @@
#define VNCR_SP_EL1 0x240
#define VNCR_VBAR_EL1 0x250
#define VNCR_TCR2_EL1 0x270
+#define VNCR_SCTLR2_EL1 0x278
#define VNCR_PIRE0_EL1 0x290
#define VNCR_PIR_EL1 0x2A0
#define VNCR_POR_EL1 0x2A8
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 4d0dbea4c56f..29ee9cd54a04 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -98,6 +98,17 @@ static inline bool ctxt_has_tcrx(struct kvm_cpu_context *ctxt)
return kvm_has_tcr2(kern_hyp_va(vcpu->kvm));
}
+static inline bool ctxt_has_sctlrx(struct kvm_cpu_context *ctxt)
+{
+ struct kvm_vcpu *vcpu;
+
+ if (!cpus_have_final_cap(ARM64_HAS_SCTLR2))
+ return false;
+
+ vcpu = ctxt_to_vcpu(ctxt);
+ return kvm_has_sctlr2(kern_hyp_va(vcpu->kvm));
+}
+
static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt)
{
struct kvm_vcpu *vcpu;
@@ -112,6 +123,8 @@ static inline bool ctxt_has_s1poe(struct kvm_cpu_context *ctxt)
static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
{
ctxt_sys_reg(ctxt, SCTLR_EL1) = read_sysreg_el1(SYS_SCTLR);
+ if (ctxt_has_sctlrx(ctxt))
+ ctxt_sys_reg(ctxt, SCTLR2_EL1) = read_sysreg_el1(SYS_SCTLR2);
ctxt_sys_reg(ctxt, CPACR_EL1) = read_sysreg_el1(SYS_CPACR);
ctxt_sys_reg(ctxt, TTBR0_EL1) = read_sysreg_el1(SYS_TTBR0);
ctxt_sys_reg(ctxt, TTBR1_EL1) = read_sysreg_el1(SYS_TTBR1);
@@ -200,6 +213,9 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt,
isb();
}
+ if (ctxt_has_sctlrx(ctxt))
+ write_sysreg_el1(ctxt_sys_reg(ctxt, SCTLR2_EL1), SYS_SCTLR2);
+
write_sysreg_el1(ctxt_sys_reg(ctxt, CPACR_EL1), SYS_CPACR);
write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR0_EL1), SYS_TTBR0);
write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR1_EL1), SYS_TTBR1);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index c20bd6f21e60..c960470b6d2b 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2588,6 +2588,15 @@ static unsigned int tcr2_el2_visibility(const struct kvm_vcpu *vcpu,
return __el2_visibility(vcpu, rd, tcr2_visibility);
}
+static unsigned int sctlr2_visibility(const struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *rd)
+{
+ if (kvm_has_sctlr2(vcpu->kvm))
+ return 0;
+
+ return REG_HIDDEN;
+}
+
static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu,
const struct sys_reg_desc *rd)
{
@@ -2955,6 +2964,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
{ SYS_DESC(SYS_SCTLR_EL1), access_vm_reg, reset_val, SCTLR_EL1, 0x00C50078 },
{ SYS_DESC(SYS_ACTLR_EL1), access_actlr, reset_actlr, ACTLR_EL1 },
{ SYS_DESC(SYS_CPACR_EL1), NULL, reset_val, CPACR_EL1, 0 },
+ { SYS_DESC(SYS_SCTLR2_EL1), access_vm_reg, reset_val, SCTLR2_EL1, 0,
+ .visibility = sctlr2_visibility },
MTE_REG(RGSR_EL1),
MTE_REG(GCR_EL1),
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (8 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 09/11] KVM: arm64: support SCTLR2_EL1 for guest Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 13:11 ` Marc Zyngier
2025-08-04 12:17 ` [PATCH 11/11] KVM: arm64: expose FEAT_SCTLR2 feature to guest Yeoreum Yun
2025-08-04 12:37 ` [PATCH 00/11] support SCTLR2_ELx Marc Zyngier
11 siblings, 1 reply; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
Support SCTLR2_ELx sysreg on nv.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/include/asm/kvm_host.h | 3 +++
arch/arm64/kvm/emulate-nested.c | 2 ++
arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 6 ++++++
arch/arm64/kvm/nested.c | 13 +++++++++++++
arch/arm64/kvm/sys_regs.c | 9 +++++++++
5 files changed, 33 insertions(+)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 4ff0ebcc2f60..95d0027a734e 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -525,6 +525,7 @@ enum vcpu_sysreg {
TCR2_EL2, /* Extended Translation Control Register (EL2) */
MDCR_EL2, /* Monitor Debug Configuration Register (EL2) */
CNTHCTL_EL2, /* Counter-timer Hypervisor Control register */
+ SCTLR2_EL2, /* Extend System Control Register (EL2) */
/* Any VNCR-capable reg goes after this point */
MARKER(__VNCR_START__),
@@ -1161,6 +1162,7 @@ static inline bool __vcpu_read_sys_reg_from_cpu(int reg, u64 *val)
switch (reg) {
case SCTLR_EL1: *val = read_sysreg_s(SYS_SCTLR_EL12); break;
case CPACR_EL1: *val = read_sysreg_s(SYS_CPACR_EL12); break;
+ case SCTLR2_EL1: *val = read_sysreg_s(SYS_SCTLR2_EL12); break;
case TTBR0_EL1: *val = read_sysreg_s(SYS_TTBR0_EL12); break;
case TTBR1_EL1: *val = read_sysreg_s(SYS_TTBR1_EL12); break;
case TCR_EL1: *val = read_sysreg_s(SYS_TCR_EL12); break;
@@ -1211,6 +1213,7 @@ static inline bool __vcpu_write_sys_reg_to_cpu(u64 val, int reg)
switch (reg) {
case SCTLR_EL1: write_sysreg_s(val, SYS_SCTLR_EL12); break;
case CPACR_EL1: write_sysreg_s(val, SYS_CPACR_EL12); break;
+ case SCTLR2_EL1: write_sysreg_s(val, SYS_SCTLR2_EL12); break;
case TTBR0_EL1: write_sysreg_s(val, SYS_TTBR0_EL12); break;
case TTBR1_EL1: write_sysreg_s(val, SYS_TTBR1_EL12); break;
case TCR_EL1: write_sysreg_s(val, SYS_TCR_EL12); break;
diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
index 3a384e9660b8..d7809682915c 100644
--- a/arch/arm64/kvm/emulate-nested.c
+++ b/arch/arm64/kvm/emulate-nested.c
@@ -782,6 +782,7 @@ static const struct encoding_to_trap_config encoding_to_cgt[] __initconst = {
SR_TRAP(OP_TLBI_RVALE1OSNXS, CGT_HCR_TTLB_TTLBOS),
SR_TRAP(OP_TLBI_RVAALE1OSNXS, CGT_HCR_TTLB_TTLBOS),
SR_TRAP(SYS_SCTLR_EL1, CGT_HCR_TVM_TRVM),
+ SR_TRAP(SYS_SCTLR2_EL1, CGT_HCR_TVM_TRVM),
SR_TRAP(SYS_TTBR0_EL1, CGT_HCR_TVM_TRVM),
SR_TRAP(SYS_TTBR1_EL1, CGT_HCR_TVM_TRVM),
SR_TRAP(SYS_TCR_EL1, CGT_HCR_TVM_TRVM),
@@ -1354,6 +1355,7 @@ static const struct encoding_to_trap_config encoding_to_fgt[] __initconst = {
SR_FGT(SYS_SCXTNUM_EL0, HFGRTR, SCXTNUM_EL0, 1),
SR_FGT(SYS_SCXTNUM_EL1, HFGRTR, SCXTNUM_EL1, 1),
SR_FGT(SYS_SCTLR_EL1, HFGRTR, SCTLR_EL1, 1),
+ SR_FGT(SYS_SCTLR2_EL1, HFGRTR, SCTLR_EL1, 1), /* not typo! */
SR_FGT(SYS_REVIDR_EL1, HFGRTR, REVIDR_EL1, 1),
SR_FGT(SYS_PAR_EL1, HFGRTR, PAR_EL1, 1),
SR_FGT(SYS_MPIDR_EL1, HFGRTR, MPIDR_EL1, 1),
diff --git a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
index 73e4bc7fde9e..689e3297d949 100644
--- a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
+++ b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c
@@ -51,6 +51,9 @@ static void __sysreg_save_vel2_state(struct kvm_vcpu *vcpu)
__vcpu_assign_sys_reg(vcpu, TTBR1_EL2, read_sysreg_el1(SYS_TTBR1));
__vcpu_assign_sys_reg(vcpu, TCR_EL2, read_sysreg_el1(SYS_TCR));
+ if (ctxt_has_sctlrx(&vcpu->arch.ctxt))
+ __vcpu_assign_sys_reg(vcpu, SCTLR2_EL2, read_sysreg_el1(SYS_SCTLR2));
+
if (ctxt_has_tcrx(&vcpu->arch.ctxt)) {
__vcpu_assign_sys_reg(vcpu, TCR2_EL2, read_sysreg_el1(SYS_TCR2));
@@ -120,6 +123,9 @@ static void __sysreg_restore_vel2_state(struct kvm_vcpu *vcpu)
write_sysreg_el1(val, SYS_TCR);
}
+ if (ctxt_has_sctlrx(&vcpu->arch.ctxt))
+ write_sysreg_el1(__vcpu_sys_reg(vcpu, SCTLR2_EL2), SYS_SCTLR2);
+
if (ctxt_has_tcrx(&vcpu->arch.ctxt)) {
write_sysreg_el1(__vcpu_sys_reg(vcpu, TCR2_EL2), SYS_TCR2);
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index dc1d26559bfa..a4d3b2d2fd80 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -1704,6 +1704,19 @@ int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
TCR2_EL2_AMEC1 | TCR2_EL2_DisCH0 | TCR2_EL2_DisCH1);
set_sysreg_masks(kvm, TCR2_EL2, res0, res1);
+ /*
+ * SCTLR2_EL2 - until explicit support for each feature, set all as RES0.
+ */
+ res0 = SCTLR2_EL2_RES0 | SCTLR2_EL2_EMEC;
+ res0 |= SCTLR2_EL2_EASE;
+ res0 |= SCTLR2_EL2_NMEA;
+ res0 |= (SCTLR2_EL2_EnADERR | SCTLR2_EL2_EnANERR);
+ res0 |= SCTLR2_EL2_EnIDCP128;
+ res0 |= (SCTLR2_EL2_CPTA | SCTLR2_EL2_CPTA0 |
+ SCTLR2_EL2_CPTM | SCTLR2_EL2_CPTM0);
+ res1 = SCTLR2_EL2_RES1;
+ set_sysreg_masks(kvm, SCTLR2_EL2, res0, res1);
+
/* SCTLR_EL1 */
res0 = SCTLR_EL1_RES0;
res1 = SCTLR_EL1_RES1;
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index c960470b6d2b..24881b7248b5 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -122,6 +122,7 @@ static bool get_el2_to_el1_mapping(unsigned int reg,
PURE_EL2_SYSREG( CNTHCTL_EL2 );
MAPPED_EL2_SYSREG(SCTLR_EL2, SCTLR_EL1,
translate_sctlr_el2_to_sctlr_el1 );
+ MAPPED_EL2_SYSREG(SCTLR2_EL2, SCTLR2_EL1, NULL );
MAPPED_EL2_SYSREG(CPTR_EL2, CPACR_EL1,
translate_cptr_el2_to_cpacr_el1 );
MAPPED_EL2_SYSREG(TTBR0_EL2, TTBR0_EL1,
@@ -2597,6 +2598,12 @@ static unsigned int sctlr2_visibility(const struct kvm_vcpu *vcpu,
return REG_HIDDEN;
}
+static unsigned int sctlr2_el2_visibility(const struct kvm_vcpu *vcpu,
+ const struct sys_reg_desc *rd)
+{
+ return __el2_visibility(vcpu, rd, sctlr2_visibility);
+}
+
static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu,
const struct sys_reg_desc *rd)
{
@@ -3313,6 +3320,8 @@ static const struct sys_reg_desc sys_reg_descs[] = {
EL2_REG_VNCR(VMPIDR_EL2, reset_unknown, 0),
EL2_REG(SCTLR_EL2, access_rw, reset_val, SCTLR_EL2_RES1),
EL2_REG(ACTLR_EL2, access_rw, reset_val, 0),
+ EL2_REG_FILTERED(SCTLR2_EL2, access_rw, reset_val, 0,
+ sctlr2_el2_visibility),
EL2_REG_VNCR(HCR_EL2, reset_hcr, 0),
EL2_REG(MDCR_EL2, access_mdcr, reset_mdcr, 0),
EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1),
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 11/11] KVM: arm64: expose FEAT_SCTLR2 feature to guest
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (9 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv Yeoreum Yun
@ 2025-08-04 12:17 ` Yeoreum Yun
2025-08-04 12:37 ` [PATCH 00/11] support SCTLR2_ELx Marc Zyngier
11 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 12:17 UTC (permalink / raw)
To: catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: linux-arm-kernel, linux-kernel, linux-pm, kvmarm, Yeoreum Yun
expose FEAT_SCTLR2 feature to guest.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
arch/arm64/kvm/sys_regs.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 24881b7248b5..3f82ef1a8eb0 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1644,8 +1644,8 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu,
val &= ~ID_AA64MMFR2_EL1_NV;
break;
case SYS_ID_AA64MMFR3_EL1:
- val &= ID_AA64MMFR3_EL1_TCRX | ID_AA64MMFR3_EL1_S1POE |
- ID_AA64MMFR3_EL1_S1PIE;
+ val &= ID_AA64MMFR3_EL1_TCRX | ID_AA64MMFR3_EL1_SCTLRX |
+ ID_AA64MMFR3_EL1_S1POE | ID_AA64MMFR3_EL1_S1PIE;
break;
case SYS_ID_MMFR4_EL1:
val &= ~ARM64_FEATURE_MASK(ID_MMFR4_EL1_CCIDX);
@@ -2961,6 +2961,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
ID_AA64MMFR2_EL1_NV |
ID_AA64MMFR2_EL1_CCIDX)),
ID_WRITABLE(ID_AA64MMFR3_EL1, (ID_AA64MMFR3_EL1_TCRX |
+ ID_AA64MMFR3_EL1_SCTLRX |
ID_AA64MMFR3_EL1_S1PIE |
ID_AA64MMFR3_EL1_S1POE)),
ID_WRITABLE(ID_AA64MMFR4_EL1, ID_AA64MMFR4_EL1_NV_frac),
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2
2025-08-04 12:17 ` [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2 Yeoreum Yun
@ 2025-08-04 12:24 ` Mark Brown
2025-08-04 13:05 ` Yeoreum Yun
0 siblings, 1 reply; 19+ messages in thread
From: Mark Brown @ 2025-08-04 12:24 UTC (permalink / raw)
To: Yeoreum Yun
Cc: catalin.marinas, will, maz, oliver.upton, anshuman.khandual, robh,
james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
[-- Attachment #1: Type: text/plain, Size: 318 bytes --]
On Mon, Aug 04, 2025 at 01:17:14PM +0100, Yeoreum Yun wrote:
> Add definitions of SCTLR2_EL2.
When adding registers it's useful to quote the revision of the spec
you're referencing, this helps people doing updates in future (eg,
DDI0601 2025-06). The update looks good:
Reviewed-by: Mark Brown <broonie@kernel.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 00/11] support SCTLR2_ELx
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
` (10 preceding siblings ...)
2025-08-04 12:17 ` [PATCH 11/11] KVM: arm64: expose FEAT_SCTLR2 feature to guest Yeoreum Yun
@ 2025-08-04 12:37 ` Marc Zyngier
2025-08-04 13:04 ` Yeoreum Yun
11 siblings, 1 reply; 19+ messages in thread
From: Marc Zyngier @ 2025-08-04 12:37 UTC (permalink / raw)
To: Yeoreum Yun
Cc: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
On Mon, 04 Aug 2025 13:17:13 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> 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.
>
> This series is based on v6.16 and probably KVM-safe but
> Not tested yet:
> - nVHE boot.
"Probably" and "Not tested yet" are not exactly what we are looking
for when looking at a series that adds support for a new architectural
feature.
Also, a lot of the KVM patches are redundant now that we do have
FEAT_SCTLR2 support in KVM (see what has been merged for 6.17). You
probably want to rebase on -rc1 once it is released, which should cut
the series by half.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 00/11] support SCTLR2_ELx
2025-08-04 12:37 ` [PATCH 00/11] support SCTLR2_ELx Marc Zyngier
@ 2025-08-04 13:04 ` Yeoreum Yun
0 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 13:04 UTC (permalink / raw)
To: Marc Zyngier
Cc: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
Hi
> Yeoreum Yun <yeoreum.yun@arm.com> 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.
> >
> > This series is based on v6.16 and probably KVM-safe but
> > Not tested yet:
> > - nVHE boot.
Okay.
>
> "Probably" and "Not tested yet" are not exactly what we are looking
> for when looking at a series that adds support for a new architectural
> feature.
>
> Also, a lot of the KVM patches are redundant now that we do have
> FEAT_SCTLR2 support in KVM (see what has been merged for 6.17). You
> probably want to rebase on -rc1 once it is released, which should cut
> the series by half.
>
I didn't know that and I'll rebase on 6.17-rc1.
Thanks.
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2
2025-08-04 12:24 ` Mark Brown
@ 2025-08-04 13:05 ` Yeoreum Yun
0 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 13:05 UTC (permalink / raw)
To: Mark Brown
Cc: catalin.marinas, will, maz, oliver.upton, anshuman.khandual, robh,
james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
Hi Mark,
> On Mon, Aug 04, 2025 at 01:17:14PM +0100, Yeoreum Yun wrote:
> > Add definitions of SCTLR2_EL2.
>
> When adding registers it's useful to quote the revision of the spec
> you're referencing, this helps people doing updates in future (eg,
> DDI0601 2025-06). The update looks good:
>
> Reviewed-by: Mark Brown <broonie@kernel.org>
Thanks. I'll add this.
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv
2025-08-04 12:17 ` [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv Yeoreum Yun
@ 2025-08-04 13:11 ` Marc Zyngier
2025-08-04 15:03 ` Yeoreum Yun
0 siblings, 1 reply; 19+ messages in thread
From: Marc Zyngier @ 2025-08-04 13:11 UTC (permalink / raw)
To: Yeoreum Yun
Cc: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
On Mon, 04 Aug 2025 13:17:23 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> wrote:
[...]
> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> index dc1d26559bfa..a4d3b2d2fd80 100644
> --- a/arch/arm64/kvm/nested.c
> +++ b/arch/arm64/kvm/nested.c
> @@ -1704,6 +1704,19 @@ int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
> TCR2_EL2_AMEC1 | TCR2_EL2_DisCH0 | TCR2_EL2_DisCH1);
> set_sysreg_masks(kvm, TCR2_EL2, res0, res1);
>
> + /*
> + * SCTLR2_EL2 - until explicit support for each feature, set all as RES0.
> + */
> + res0 = SCTLR2_EL2_RES0 | SCTLR2_EL2_EMEC;
> + res0 |= SCTLR2_EL2_EASE;
> + res0 |= SCTLR2_EL2_NMEA;
> + res0 |= (SCTLR2_EL2_EnADERR | SCTLR2_EL2_EnANERR);
> + res0 |= SCTLR2_EL2_EnIDCP128;
> + res0 |= (SCTLR2_EL2_CPTA | SCTLR2_EL2_CPTA0 |
> + SCTLR2_EL2_CPTM | SCTLR2_EL2_CPTM0);
> + res1 = SCTLR2_EL2_RES1;
> + set_sysreg_masks(kvm, SCTLR2_EL2, res0, res1);
This patch is obsolete, but I'd like to point out that this is not the
way we describe these things. Each bit of the register needs to be
tracked against the feature it is part of, and not blindly added to
the RES0 set. See
https://lore.kernel.org/all/20250708172532.1699409-15-oliver.upton@linux.dev/
for the equivalent change.
You should *NEVER* describe a functional bit as RESx without
considering whether the feature is exposed to the guest, irrespective
of what the kernel supports.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv
2025-08-04 13:11 ` Marc Zyngier
@ 2025-08-04 15:03 ` Yeoreum Yun
0 siblings, 0 replies; 19+ messages in thread
From: Yeoreum Yun @ 2025-08-04 15:03 UTC (permalink / raw)
To: Marc Zyngier
Cc: catalin.marinas, will, broonie, oliver.upton, anshuman.khandual,
robh, james.morse, mark.rutland, joey.gouly, ry111, Dave.Martin,
ahmed.genidi, kevin.brodsky, scott, mbenes, james.clark, frederic,
rafael, pavel, ryan.roberts, suzuki.poulose, linux-arm-kernel,
linux-kernel, linux-pm, kvmarm
Hi Marc,
> [...]
>
> > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> > index dc1d26559bfa..a4d3b2d2fd80 100644
> > --- a/arch/arm64/kvm/nested.c
> > +++ b/arch/arm64/kvm/nested.c
> > @@ -1704,6 +1704,19 @@ int kvm_init_nv_sysregs(struct kvm_vcpu *vcpu)
> > TCR2_EL2_AMEC1 | TCR2_EL2_DisCH0 | TCR2_EL2_DisCH1);
> > set_sysreg_masks(kvm, TCR2_EL2, res0, res1);
> >
> > + /*
> > + * SCTLR2_EL2 - until explicit support for each feature, set all as RES0.
> > + */
> > + res0 = SCTLR2_EL2_RES0 | SCTLR2_EL2_EMEC;
> > + res0 |= SCTLR2_EL2_EASE;
> > + res0 |= SCTLR2_EL2_NMEA;
> > + res0 |= (SCTLR2_EL2_EnADERR | SCTLR2_EL2_EnANERR);
> > + res0 |= SCTLR2_EL2_EnIDCP128;
> > + res0 |= (SCTLR2_EL2_CPTA | SCTLR2_EL2_CPTA0 |
> > + SCTLR2_EL2_CPTM | SCTLR2_EL2_CPTM0);
> > + res1 = SCTLR2_EL2_RES1;
> > + set_sysreg_masks(kvm, SCTLR2_EL2, res0, res1);
>
> This patch is obsolete, but I'd like to point out that this is not the
> way we describe these things. Each bit of the register needs to be
> tracked against the feature it is part of, and not blindly added to
> the RES0 set. See
>
> https://lore.kernel.org/all/20250708172532.1699409-15-oliver.upton@linux.dev/
>
> for the equivalent change.
>
> You should *NEVER* describe a functional bit as RESx without
> considering whether the feature is exposed to the guest, irrespective
> of what the kernel supports.
Thanks to let me know.
I'll keep in mind :)
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 07/11] arm64: make the per-task SCTLR2_EL1
2025-08-04 12:17 ` [PATCH 07/11] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
@ 2025-08-05 9:01 ` kernel test robot
0 siblings, 0 replies; 19+ messages in thread
From: kernel test robot @ 2025-08-05 9:01 UTC (permalink / raw)
To: Yeoreum Yun, catalin.marinas, will, maz, broonie, oliver.upton,
anshuman.khandual, robh, james.morse, mark.rutland, joey.gouly,
ry111, Dave.Martin, ahmed.genidi, kevin.brodsky, scott, mbenes,
james.clark, frederic, rafael, pavel, ryan.roberts,
suzuki.poulose
Cc: oe-kbuild-all, linux-arm-kernel, linux-kernel, linux-pm, kvmarm,
Yeoreum Yun
Hi Yeoreum,
kernel test robot noticed the following build errors:
[auto build test ERROR on 038d61fd642278bab63ee8ef722c50d10ab01e8f]
url: https://github.com/intel-lab-lkp/linux/commits/Yeoreum-Yun/arm64-sysreg-add-system-registers-SCTLR2_EL2/20250804-202225
base: 038d61fd642278bab63ee8ef722c50d10ab01e8f
patch link: https://lore.kernel.org/r/20250804121724.3681531-8-yeoreum.yun%40arm.com
patch subject: [PATCH 07/11] arm64: make the per-task SCTLR2_EL1
config: arm64-randconfig-001-20250805 (https://download.01.org/0day-ci/archive/20250805/202508051649.pyaqcE8d-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 12.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250805/202508051649.pyaqcE8d-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508051649.pyaqcE8d-lkp@intel.com/
All errors (new ones prefixed by >>):
/tmp/ccFwinHr.s: Assembler messages:
>> /tmp/ccFwinHr.s:1352: Error: selected processor does not support system register name 'sctlr2_el1'
/tmp/ccFwinHr.s:1362: Error: selected processor does not support system register name 'sctlr2_el1'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2025-08-05 9:01 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04 12:17 [PATCH 00/11] support SCTLR2_ELx Yeoreum Yun
2025-08-04 12:17 ` [PATCH 01/11] arm64/sysreg: add system registers SCTLR2_EL2 Yeoreum Yun
2025-08-04 12:24 ` Mark Brown
2025-08-04 13:05 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 02/11] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
2025-08-04 12:17 ` [PATCH 03/11] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
2025-08-04 12:17 ` [PATCH 04/11] arm64: cpufeature: add FEAT_SCTLR2 feature Yeoreum Yun
2025-08-04 12:17 ` [PATCH 05/11] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
2025-08-04 12:17 ` [PATCH 06/11] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
2025-08-04 12:17 ` [PATCH 07/11] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
2025-08-05 9:01 ` kernel test robot
2025-08-04 12:17 ` [PATCH 08/11] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
2025-08-04 12:17 ` [PATCH 09/11] KVM: arm64: support SCTLR2_EL1 for guest Yeoreum Yun
2025-08-04 12:17 ` [PATCH 10/11] KVM: arm64: nv: support SCTLR2_ELx on nv Yeoreum Yun
2025-08-04 13:11 ` Marc Zyngier
2025-08-04 15:03 ` Yeoreum Yun
2025-08-04 12:17 ` [PATCH 11/11] KVM: arm64: expose FEAT_SCTLR2 feature to guest Yeoreum Yun
2025-08-04 12:37 ` [PATCH 00/11] support SCTLR2_ELx Marc Zyngier
2025-08-04 13:04 ` Yeoreum Yun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).