[PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()

Yeoreum Yun posted 6 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
Posted by Yeoreum Yun 1 month, 3 weeks ago
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}
Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
Posted by Marc Zyngier 1 month, 3 weeks ago
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.
Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
Posted by Yeoreum Yun 1 month, 3 weeks ago
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
Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
Posted by Marc Zyngier 1 month, 3 weeks ago
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.
Re: [PATCH v2 6/6] KVM: arm64: initialise SCTLR2_EL1 at __kvm_host_psci_cpu_entry()
Posted by Yeoreum Yun 1 month, 3 weeks ago
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