From: Marc Zyngier <maz@kernel.org>
To: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: catalin.marinas@arm.com, will@kernel.org, broonie@kernel.org,
oliver.upton@linux.dev, anshuman.khandual@arm.com,
robh@kernel.org, james.morse@arm.com, mark.rutland@arm.com,
joey.gouly@arm.com, Dave.Martin@arm.com, ahmed.genidi@arm.com,
kevin.brodsky@arm.com, scott@os.amperecomputing.com,
mbenes@suse.cz, james.clark@linaro.org, frederic@kernel.org,
rafael@kernel.org, pavel@kernel.org, ryan.roberts@arm.com,
suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
kvmarm@lists.linux.dev
Subject: Re: [PATCH v2 2/6] arm64: initialise SCTLR2_ELx register at boot time
Date: Mon, 11 Aug 2025 19:26:17 +0100 [thread overview]
Message-ID: <86pld190l2.wl-maz@kernel.org> (raw)
In-Reply-To: <20250811163340.1561893-3-yeoreum.yun@arm.com>
[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.
next prev parent reply other threads:[~2025-08-11 18:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86pld190l2.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=Dave.Martin@arm.com \
--cc=ahmed.genidi@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=frederic@kernel.org \
--cc=james.clark@linaro.org \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kevin.brodsky@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mbenes@suse.cz \
--cc=oliver.upton@linux.dev \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=scott@os.amperecomputing.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yeoreum.yun@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.