Re: [PATCH 2/2] arm64: dynamically enable st64bv0 for SVA

From: Arnd Bergmann

Date: Thu Nov 26 2026 - 10:52:44 EST


On Sun, Nov 22, 2026, at 20:51, Siddharth Chintamaneni wrote:
> On Tue, 17 Nov 2026 at 14:22, Arnd Bergmann <arnd@xxxxxxxxxx> wrote:

>
> 1. SCTLR_EL1_EnAS0 is missing from SCTLR_USER_MASK (and fork/exec reset):
>
> update_sctlr_el1() clears only (SCTLR_USER_MASK & ~SCTLR_ELx_ENIA). Because
> SCTLR_EL1_EnAS0 is not in SCTLR_USER_MASK, once a task enables st64bv0 on a
> CPU, __switch_to() -> update_sctlr_el1() never clears SCTLR_EL1.EnAS0 when
> switching to another task, and switch_iommu_mm() returns early because the
> next task does not have SCTLR_EL1_EnAS0 set in thread.sctlr_user. On Cobalt
> 200, an unprivileged process with no SVA binding scheduled onto that CPU
> executed st64bv0 without trapping while the previous task's PASID was still in
> ACCDATA_EL1.
>
> Similarly:
> - arch_dup_task_struct() copies thread.sctlr_user, so a fork() child inherits
> SCTLR_EL1_EnAS0 with a fresh mm whose PASID is IOMMU_PASID_INVALID (leaving
> the parent's PASID in ACCDATA_EL1 when switch_iommu_mm() skips the write).
> - flush_thread() does not clear SCTLR_EL1_EnAS0 across execve().
> - try_enable_st64bv0() can return false if SCTLR_EL1_EnAS0 is already set in
> current->thread.sctlr_user (matching current->pasid_activated on x86).
>
> Folding in the diff below fixed all three cases (context switch to an unbound
> task on the same CPU, fork(), and execve() all trap with SIGILL again on
> Cobalt 200):
>
>
> diff --git a/arch/arm64/include/asm/processor.h
> b/arch/arm64/include/asm/processor.h
> index 2f368889aa3a..c7243bd4849a 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -264,7 +264,7 @@ static inline void task_set_sve_vl_onexec(struct
> task_struct *task,
>
> #define SCTLR_USER_MASK
> \
> (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | \
> - SCTLR_EL1_TCF0_MASK | SCTLR_EL1_TCSO0_MASK)
> + SCTLR_EL1_TCF0_MASK | SCTLR_EL1_TCSO0_MASK | SCTLR_EL1_EnAS0)

Fixed

> static inline void arch_thread_struct_whitelist(unsigned long *offset,
> unsigned long *size)
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index b52d4f0cf5b4..6a1cfeb28bf2 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -350,6 +350,13 @@ void flush_thread(void)
> flush_tagged_addr_state();
> flush_poe();
> flush_gcs();
> +
> + if (current->thread.sctlr_user & SCTLR_EL1_EnAS0) {
> + preempt_disable();
> + current->thread.sctlr_user &= ~SCTLR_EL1_EnAS0;
> + update_sctlr_el1(current->thread.sctlr_user);
> + preempt_enable();

Right. For consistency I'll put this into a separate function.

> void exit_thread(struct task_struct *tsk)
> @@ -395,6 +402,7 @@ int arch_dup_task_struct(struct task_struct *dst,
> struct task_struct *src)
>
> /* clear any pending asynchronous tag fault raised by the parent */
> clear_tsk_thread_flag(dst, TIF_MTE_ASYNC_FAULT);
> + dst->thread.sctlr_user &= ~SCTLR_EL1_EnAS0;
>
> return 0;
> }

ok

> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index a02dbee8c06d..be84e84c5fa1 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -558,7 +558,8 @@ static bool try_enable_st64bv0(struct pt_regs
> *regs, unsigned long esr)
> u32 pasid;
> u64 sctlr;
>
> - if (!system_supports_ls64_accdata())
> + if (!system_supports_ls64_accdata() ||
> + (current->thread.sctlr_user & SCTLR_EL1_EnAS0))
> return false;

I don't understand how you hit this one.

I'd change it to report bus error in this case, which also helps
add a testcase for the hwcap.


> 2. Other corners (first three also highlighted by Sashiko [1]):
>
> - EL2 -> EL1 boot setup (arch/arm64/include/asm/el2_setup.h): our bare-metal
> host ran at EL2 with VHE, so HCRX_EL2 did not affect host EL2/EL0. For
> kernels booting at EL2 and dropping to EL1 (e.g. CONFIG_KVM=n, nVHE/pKVM, or
> guest VMs booting at EL2), __init_el2_hcrx and __init_el2_fgt do not yet set
> HCRX_EL2_EnAS0 or HFGRTR_EL2_nACCDATA_EL1 / HFGWTR_EL2_nACCDATA_EL1, so EL1
> ACCDATA_EL1 accesses and EL0 st64bv0 will trap to EL2.

I've added the bit to __init_el2_hcrx now, not sure what is actually
needed for __init_el2_fgt.

> - KVM host ACCDATA_EL1 save/restore: regarding the commit message note about a
> host process using both SVA and KVM, even with Fuad's series applied,
> ctxt_has_accdata() in arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h returns
> false when !ctxt_is_guest(ctxt), so KVM loads the guest's ACCDATA_EL1
> without saving or restoring the host's ACCDATA_EL1 across vCPU run.

I added a check for CONFIG_IOMMU_SVA now, so we always context switch
it in KVM when that is available. In theory, this could be optimized
further to not save it and only restore accdata if the current thread has
enabled it. Not sure if that's worth it, as reading accdata from the host
should be fast.

> - Assembler target: arch/arm64/Makefile caps -Wa,-march at armv8.5-a, which
> breaks Clang IAS (LLVM=1) on write_sysreg(..., accdata_el1); using
> write_sysreg_s(pasid, SYS_ACCDATA_EL1) avoids that (and the duplicate manual
> #define SYS_ACCDATA_EL1 in arch/arm64/include/asm/sysreg.h can be dropped now
> that tools/sysreg generates it).

ok, changed it now

> - CPU suspend: cpu_do_suspend / cpu_do_resume in arch/arm64/mm/proc.S
> saves/restores sctlr_el1 across CPU powerdown idle states without
> saving/restoring accdata_el1.

I've added a restore function now. My first guess was that the cpu_do_suspend
function would always be called from the idle task, but I see that this
is not the case. No need to do anything in suspend though because
the data is already stored in current->mm->iommu_mm.

Arnd