linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] initialize SCTRL2_ELx
@ 2025-08-11 16:33 Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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.

Patch History
==============
from v1 to v2:
  - rebase to v6.17-rc1
  - https://lore.kernel.org/all/20250804121724.3681531-1-yeoreum.yun@arm.com/

Yeoreum Yun (6):
  arm64: make SCTLR2_EL1 accessible
  arm64: initialise SCTLR2_ELx register at boot time
  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()

 arch/arm64/include/asm/el2_setup.h   | 14 +++++++++++++-
 arch/arm64/include/asm/processor.h   |  5 +++++
 arch/arm64/include/asm/suspend.h     |  2 +-
 arch/arm64/include/asm/sysreg.h      | 22 ++++++++++++++++++++++
 arch/arm64/kernel/cpu-reset.S        |  6 ++++++
 arch/arm64/kernel/head.S             |  5 ++++-
 arch/arm64/kernel/process.c          |  9 +++++++++
 arch/arm64/kvm/hyp/nvhe/psci-relay.c |  3 +++
 arch/arm64/mm/proc.S                 | 26 ++++++++++++++++++--------
 9 files changed, 81 insertions(+), 11 deletions(-)


base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 17:46   ` Marc Zyngier
  2025-08-11 16:33 ` [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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 46033027510c..d755b4d46d77 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] 15+ messages in thread

* [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 18:26   ` Marc Zyngier
  2025-08-11 16:33 ` [PATCH v2 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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 d755b4d46d77..347ac4cc1283 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
@@ -411,6 +416,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 d5b5f2ae1afa..8b82af5be199 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)
@@ -1164,6 +1168,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] 15+ messages in thread

* [PATCH v2 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume()
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 4/6] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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 8c75965afc9e..f297bea7103b 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] 15+ messages in thread

* [PATCH v2 4/6] arm64: init SCTLR2_EL1 at cpu_soft_restart()
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
                   ` (2 preceding siblings ...)
  2025-08-11 16:33 ` [PATCH v2 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
  5 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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] 15+ messages in thread

* [PATCH v2 5/6] arm64: make the per-task SCTLR2_EL1
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
                   ` (3 preceding siblings ...)
  2025-08-11 16:33 ` [PATCH v2 4/6] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 16:33 ` [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
  5 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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 61d62bfd5a7b..2c962816de70 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,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)
 {
@@ -370,6 +374,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 96482a1412c6..9191180c4875 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -698,6 +698,11 @@ void update_sctlr_el1(u64 sctlr)
 	isb();
 }
 
+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] 15+ messages in thread

* [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
  2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
                   ` (4 preceding siblings ...)
  2025-08-11 16:33 ` [PATCH v2 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
@ 2025-08-11 16:33 ` Yeoreum Yun
  2025-08-11 17:51   ` Marc Zyngier
  5 siblings, 1 reply; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 16:33 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] 15+ messages in thread

* Re: [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible
  2025-08-11 16:33 ` [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
@ 2025-08-11 17:46   ` Marc Zyngier
  2025-08-12  6:50     ` Yeoreum Yun
  0 siblings, 1 reply; 15+ messages in thread
From: Marc Zyngier @ 2025-08-11 17:46 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, 11 Aug 2025 17:33:35 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> wrote:
> 
> make SCTLR2_EL1 accssible to initilise it.

nit: "accessible", "initialise".

This could deserve a slightly less terse message, so that someone who
is not very much versed into the boring details of the architecture
can make sense of this patch. Because, frankly, if you can access
HCRX_EL2, why can't you access SCTLR2_EL1? You know why, I know why,
but hardly anyone else does.

I'd suggest something along the lines of:

"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."

which at least explains why we're doing this.

> 
> 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 46033027510c..d755b4d46d77 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_\@:

With that fixed,

Reviewed-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
  2025-08-11 16:33 ` [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
@ 2025-08-11 17:51   ` Marc Zyngier
  2025-08-11 19:43     ` Yeoreum Yun
  0 siblings, 1 reply; 15+ messages in thread
From: Marc Zyngier @ 2025-08-11 17:51 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, 11 Aug 2025 17:33:40 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> wrote:
> 
> initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry().

Same comment, I don't think this is an acceptable commit message.
Please ask for help if you don't feel confident writing it (I'm sure
some of your colleagues will be happy to help).

> 
> 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);

This needs to be folded into patch #1.

Otherwise, there is a window of patches where the kernel will not
survive CPU hotplug when booted in protected mode.

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time
  2025-08-11 16:33 ` [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
@ 2025-08-11 18:26   ` Marc Zyngier
  2025-08-11 19:23     ` Yeoreum Yun
  0 siblings, 1 reply; 15+ messages in thread
From: Marc Zyngier @ 2025-08-11 18:26 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: 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, linux-arm-kernel,
	linux-kernel, linux-pm, kvmarm

[dropping ry111@xry111.site, which bounces]

On Mon, 11 Aug 2025 17:33:36 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> wrote:
> 
> add initialisation for SCTRL2_ELx register at boot time.

Again, please expand.

> 
> 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 d755b4d46d77..347ac4cc1283 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

Writing this as __init_sctlr2_el2 would read vastly better (yes, I
know most macros in this file are similarly braindead).

> +	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
> @@ -411,6 +416,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 d5b5f2ae1afa..8b82af5be199 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)
> @@ -1164,6 +1168,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

I don't think this is the correct place for this macro.
asm/assembler.h seems more suitable, and already has that sort of
things.

> +	.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

This is missing something: you should resynchronise SCTLR2_EL2 from
SCTLR2_EL1 in __finalise_el2, rather than relying on whatever you've
set in __init_el2_sctlr2.

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time
  2025-08-11 18:26   ` Marc Zyngier
@ 2025-08-11 19:23     ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 19:23 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: 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, linux-arm-kernel,
	linux-kernel, linux-pm, kvmarm

Hi Marc,

> [dropping ry111@xry111.site, which bounces]
>
> On Mon, 11 Aug 2025 17:33:36 +0100,
> Yeoreum Yun <yeoreum.yun@arm.com> wrote:
> >
> > add initialisation for SCTRL2_ELx register at boot time.
>
> Again, please expand.

Okay.


[...]
> >
> > +.macro __init_el2_sctlr2
>
> Writing this as __init_sctlr2_el2 would read vastly better (yes, I
> know most macros in this file are similarly braindead).
>
> > +	.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
>
> I don't think this is the correct place for this macro.
> asm/assembler.h seems more suitable, and already has that sort of
> things.

Thanks for letting me know the proper place.
I'll rewrite it on there.

>
> > +	.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
>
> This is missing something: you should resynchronise SCTLR2_EL2 from
> SCTLR2_EL1 in __finalise_el2, rather than relying on whatever you've
> set in __init_el2_sctlr2.

Thanks. I'll add missing on enter_vhe().

--
Sincerely,
Yeoreum Yun

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
  2025-08-11 17:51   ` Marc Zyngier
@ 2025-08-11 19:43     ` Yeoreum Yun
  2025-08-12 10:06       ` Marc Zyngier
  0 siblings, 1 reply; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-11 19:43 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,

> > initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry().
>
> Same comment, I don't think this is an acceptable commit message.
> Please ask for help if you don't feel confident writing it (I'm sure
> some of your colleagues will be happy to help).

Okay. I'll rewrite the commit message

> > @@ -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);
>
> This needs to be folded into patch #1.
>
> Otherwise, there is a window of patches where the kernel will not
> survive CPU hotplug when booted in protected mode.

Do you mean fold this patch into patch #2 where initialise
SCTLR2_ELx?

Thanks.

> --
> Without deviation from the norm, progress is not possible.

--
Sincerely,
Yeoreum Yun

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible
  2025-08-11 17:46   ` Marc Zyngier
@ 2025-08-12  6:50     ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-12  6:50 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,

> > make SCTLR2_EL1 accssible to initilise it.
>
> nit: "accessible", "initialise".
>
> This could deserve a slightly less terse message, so that someone who
> is not very much versed into the boring details of the architecture
> can make sense of this patch. Because, frankly, if you can access
> HCRX_EL2, why can't you access SCTLR2_EL1? You know why, I know why,
> but hardly anyone else does.
>
> I'd suggest something along the lines of:
>
> "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."
>
> which at least explains why we're doing this.
>
> >
> > 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 46033027510c..d755b4d46d77 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_\@:
>
> With that fixed,
>
> Reviewed-by: Marc Zyngier <maz@kernel.org>

Thanks for your suggetion.
I'll modify it.

>
> 	M.
>
> --
> Without deviation from the norm, progress is not possible.

--
Sincerely,
Yeoreum Yun

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
  2025-08-11 19:43     ` Yeoreum Yun
@ 2025-08-12 10:06       ` Marc Zyngier
  2025-08-12 10:29         ` Yeoreum Yun
  0 siblings, 1 reply; 15+ messages in thread
From: Marc Zyngier @ 2025-08-12 10:06 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, 11 Aug 2025 20:43:00 +0100,
Yeoreum Yun <yeoreum.yun@arm.com> wrote:
> 
> Hi Marc,
> 
> > > initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry().
> >
> > Same comment, I don't think this is an acceptable commit message.
> > Please ask for help if you don't feel confident writing it (I'm sure
> > some of your colleagues will be happy to help).
> 
> Okay. I'll rewrite the commit message
> 
> > > @@ -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);
> >
> > This needs to be folded into patch #1.
> >
> > Otherwise, there is a window of patches where the kernel will not
> > survive CPU hotplug when booted in protected mode.
> 
> Do you mean fold this patch into patch #2 where initialise
> SCTLR2_ELx?

Yes, sorry, I got it mixed with HCRX_EL2. Patch #2 is where it should
land indeed.

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
  2025-08-12 10:06       ` Marc Zyngier
@ 2025-08-12 10:29         ` Yeoreum Yun
  0 siblings, 0 replies; 15+ messages in thread
From: Yeoreum Yun @ 2025-08-12 10:29 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,

[...]
> > > > @@ -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);
> > >
> > > This needs to be folded into patch #1.
> > >
> > > Otherwise, there is a window of patches where the kernel will not
> > > survive CPU hotplug when booted in protected mode.
> >
> > Do you mean fold this patch into patch #2 where initialise
> > SCTLR2_ELx?
>
> Yes, sorry, I got it mixed with HCRX_EL2. Patch #2 is where it should
> land indeed.
>
> 	M.

Thanks for confirmation :D.
I'll fold it into patch #2 in next series.

--
Sincerely,
Yeoreum Yun

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-08-12 10:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 16:33 [PATCH v2 0/6] initialize SCTRL2_ELx Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 1/6] arm64: make SCTLR2_EL1 accessible Yeoreum Yun
2025-08-11 17:46   ` Marc Zyngier
2025-08-12  6:50     ` Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time Yeoreum Yun
2025-08-11 18:26   ` Marc Zyngier
2025-08-11 19:23     ` Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 3/6] arm64: save/restore SCTLR2_EL1 when cpu_suspend()/resume() Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 4/6] arm64: init SCTLR2_EL1 at cpu_soft_restart() Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 5/6] arm64: make the per-task SCTLR2_EL1 Yeoreum Yun
2025-08-11 16:33 ` [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry() Yeoreum Yun
2025-08-11 17:51   ` Marc Zyngier
2025-08-11 19:43     ` Yeoreum Yun
2025-08-12 10:06       ` Marc Zyngier
2025-08-12 10:29         ` 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).