* [PATCH v2 0/3] st64bv0 support in iommu-sva
@ 2026-11-26 15:53 Arnd Bergmann
[not found] ` <20261126155339.1349218-2-arnd@kernel.org>
[not found] ` <20261126155339.1349218-3-arnd@kernel.org>
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2026-11-26 15:53 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Arnd Bergmann, apais, Catalin Marinas, Christian Borntraeger,
Fuad Tabba, hargar, Joey Gouly, Marc Zyngier, Mark Rutland,
Navneet Singh, Oliver Upton, rlmenge, Siddharth Chintamaneni,
Steffen Eiden, Suzuki K Poulose, Sven Schnelle, Will Deacon,
Yicong Yang, Zenghui Yu, Zhou Wang, kvmarm, kvm, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
This is an updated set of patches to enable ls64_accdata with the
st64bv0 instruction in Linux.
I have included feeback from Siddharth and Sven here, in
particular:
- fix SCTLR_USER_MASK and reset feature on fork/exec
- add a testcase for the HWCAP
- fix compilation with old assembler version
- enable HCRX_EL2_EnAS0 when booting in EL2
- restore ACCDATA_EL1 in cpu_resume
- context-switch host ACCDATA when entering KVM guest
Arnd
Arnd Bergmann (3):
arm64: dynamically enable st64bv0 for SVA
arm64: add HWCAP3_LS64_ACCDATA
kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
Documentation/arch/arm64/elf_hwcaps.rst | 7 +++
arch/arm64/include/asm/cpufeature.h | 6 +++
arch/arm64/include/asm/el2_setup.h | 3 ++
arch/arm64/include/asm/exception.h | 1 +
arch/arm64/include/asm/mmu_context.h | 17 +++++++
arch/arm64/include/asm/processor.h | 2 +-
arch/arm64/include/uapi/asm/hwcap.h | 1 +
arch/arm64/kernel/cpufeature.c | 1 +
arch/arm64/kernel/cpuinfo.c | 1 +
arch/arm64/kernel/entry-common.c | 11 ++++
arch/arm64/kernel/process.c | 25 +++++++++
arch/arm64/kernel/suspend.c | 17 +++++++
arch/arm64/kernel/traps.c | 59 ++++++++++++++++++++++
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++-
arch/arm64/tools/sysreg | 5 ++
tools/testing/selftests/arm64/abi/hwcap.c | 50 ++++++++++++++++++
16 files changed, 211 insertions(+), 3 deletions(-)
--
2.53.0
Cc: apais@microsoft.com
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Fuad Tabba <fuad.tabba@linux.dev>
Cc: hargar@linux.microsoft.com
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Navneet Singh <navneetsingh@microsoft.com>
Cc: Oliver Upton <oupton@kernel.org>
Cc: rlmenge@gmail.com
Cc: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Cc: Steffen Eiden <seiden@linux.ibm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Sven Schnelle <sven@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: kvmarm@lists.linux.dev
Cc: kvm@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA
[not found] ` <20261126155339.1349218-2-arnd@kernel.org>
@ 2026-11-30 17:24 ` Catalin Marinas
0 siblings, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2026-11-30 17:24 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-arm-kernel, Arnd Bergmann, apais, Christian Borntraeger,
Fuad Tabba, hargar, Joey Gouly, Marc Zyngier, Mark Rutland,
Navneet Singh, Oliver Upton, rlmenge, Siddharth Chintamaneni,
Steffen Eiden, Suzuki K Poulose, Sven Schnelle, Will Deacon,
Yicong Yang, Zenghui Yu, Zhou Wang, kvmarm, kvm, linux-kernel
Hi Arnd,
(BTW, you dropped all cc from the cover letter in subsequent patches,
re-adding them; forgot --cc-cover?)
On Thu, Nov 26, 2026 at 04:53:37PM +0100, Arnd Bergmann wrote:
> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h
> index 12a500181291..56b4b68407a9 100644
> --- a/arch/arm64/include/asm/el2_setup.h
> +++ b/arch/arm64/include/asm/el2_setup.h
> @@ -93,6 +93,9 @@
> cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_V
> b.lt .Lset_hcrx_\@
> orr x0, x0, #HCRX_EL2_EnASR
> + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_ACCDATA
> + b.lt .Lset_hcrx_\@
> + orr x0, x0, #HCRX_EL2_EnAS0
As reported by Siddharth (and Sashiko), we need to disable the
ACCDATA_EL1 fine-grained traps (HFG{R,W}TR_EL2.nACCDATA_EL1) in
__init_el2_fgt, similar to the existing PIE/POE/GCS blocks. Otherwise on
an nVHE/pKVM host the ACCDATA_EL1 write in try_enable_st64bv0() traps to
EL2 and hits the BUG() in handle_trap(). We should also add a note in
booting.rst for cases where the kernel is entered at EL1 (HCRX_EL2.EnAS0
and the nACCDATA_EL1 bits).
> diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
> index 803b68758152..1eb171cd546e 100644
> --- a/arch/arm64/include/asm/mmu_context.h
> +++ b/arch/arm64/include/asm/mmu_context.h
> @@ -16,6 +16,7 @@
> #include <linux/mm_types.h>
> #include <linux/pgtable.h>
> #include <linux/pkeys.h>
> +#include <linux/iommu.h>
>
> #include <asm/cacheflush.h>
> #include <asm/cpufeature.h>
> @@ -247,6 +248,20 @@ static inline void __switch_mm(struct mm_struct *next)
> check_and_switch_context(next);
> }
>
> +/* switch to PASID if new task has enabled st64bv0 */
> +static inline void switch_iommu_mm(struct mm_struct *mm, struct task_struct *tsk)
> +{
> + u32 pasid;
> +
> + if (!IS_ENABLED(CONFIG_IOMMU_SVA) ||
> + !(tsk->thread.sctlr_user & SCTLR_EL1_EnAS0))
> + return;
> +
> + pasid = mm_get_enqcmd_pasid(mm);
> + if (pasid != IOMMU_PASID_INVALID)
> + write_sysreg_s(pasid, SYS_ACCDATA_EL1);
> +}
> +
> static inline void
> switch_mm(struct mm_struct *prev, struct mm_struct *next,
> struct task_struct *tsk)
> @@ -254,6 +269,8 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,
> if (prev != next)
> __switch_mm(next);
>
> + switch_iommu_mm(next, tsk);
I don't think switch_mm() is the right place for this. Even if the PASID
is per-mm, this function is about per-thread state (EnAS0, ACCDATA_EL1).
I'd prefer something like ls64_accdata_thread_switch() called from
__switch_to().
> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
> index d6391ab20db3..b69943bfa297 100644
> --- a/arch/arm64/kernel/traps.c
> +++ b/arch/arm64/kernel/traps.c
> @@ -13,6 +13,7 @@
> #include <linux/kprobes.h>
> #include <linux/spinlock.h>
> #include <linux/uaccess.h>
> +#include <linux/iommu.h>
> #include <linux/hardirq.h>
> #include <linux/kdebug.h>
> #include <linux/module.h>
> @@ -543,6 +544,63 @@ void do_el1_mops(struct pt_regs *regs, unsigned long esr)
> kernel_fastforward_single_step(regs);
> }
>
> +/*
> + * PASID/ACCDATA is shared by the entire mm, while sctlr_el1
> + * is maintained per thread. Keep things simple and enable
> + * ACCDATA dynamically on first access if the feature is
> + * available and a valid pasid is set.
> + *
> + * After exiting back to userspace, the st64bv0 instruction
> + * should no longer trap.
> + */
> +static bool try_enable_st64bv0(struct pt_regs *regs, unsigned long esr)
> +{
> + u32 pasid;
> + u64 sctlr;
> +
> + /* unexpectedly already enabled, signal bus error */
> + if (current->thread.sctlr_user & SCTLR_EL1_EnAS0)
> + return false;
> +
> + /* no PASID set, disallow */
> + pasid = mm_get_enqcmd_pasid(current->mm);
> + if (pasid == IOMMU_PASID_INVALID)
> + return false;
> +
> + preempt_disable();
> + write_sysreg_s(pasid, SYS_ACCDATA_EL1);
> + sctlr = current->thread.sctlr_user;
> + sctlr |= SCTLR_EL1_EnAS0;
> + current->thread.sctlr_user = sctlr;
> + update_sctlr_el1(sctlr);
> + preempt_enable();
> +
> + return true;
> +}
Nit: are regs and esr used in later patches? They are unused here.
> +
> +void do_el0_other(struct pt_regs *regs, unsigned long esr)
> +{
> + switch (ESR_ELx_ISS(esr)) {
> + case ESR_ELx_ISS_OTHER_ST64BV0:
> + if (!system_supports_ls64_accdata())
> + break;
> +
> + if (try_enable_st64bv0(regs, esr))
> + return;
> +
> + force_signal_inject(SIGBUS, BUS_OBJERR, regs->pc, 0);
> + break;
As mentioned by Sashiko, with this 'break' we end up injecting two
signals. So better to just return here.
> +
> + case ESR_ELx_ISS_OTHER_ST64BV:
> + case ESR_ELx_ISS_OTHER_LDST64B:
> + default:
> + break;
> + }
> +
> + /* Treat all other "other" trapping instructions as illegal opcode */
> + force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0);
Prior to this patch, we passed the esr_context to the user signal
handler via bad_el0_sync(). You could pass esr as the last argument or
just reuse bad_el0_sync().
> diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
> index 28d319e63d8f..7612bacdb018 100644
> --- a/arch/arm64/tools/sysreg
> +++ b/arch/arm64/tools/sysreg
> @@ -3707,6 +3707,11 @@ Sysreg TPIDR_EL1 3 0 13 0 4
> Field 63:0 ThreadID
> EndSysreg
>
> +Sysreg ACCDATA_EL1 3 0 13 0 5
> +Res0 63:32
> +Field 31:0 ACCDATA
> +EndSysreg
It makes sense to define this but I think we should remove the
equivalent in asm/sysreg.h.
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA
[not found] ` <20261126155339.1349218-3-arnd@kernel.org>
@ 2026-11-30 18:02 ` Catalin Marinas
0 siblings, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2026-11-30 18:02 UTC (permalink / raw)
To: Arnd Bergmann
Cc: linux-arm-kernel, Arnd Bergmann, apais, Christian Borntraeger,
Fuad Tabba, hargar, Joey Gouly, Marc Zyngier, Mark Rutland,
Navneet Singh, Oliver Upton, rlmenge, Siddharth Chintamaneni,
Steffen Eiden, Suzuki K Poulose, Sven Schnelle, Will Deacon,
Zenghui Yu, Zhou Wang, kvmarm, kvm, linux-kernel
On Thu, Nov 26, 2026 at 04:53:38PM +0100, Arnd Bergmann wrote:
> diff --git a/Documentation/arch/arm64/elf_hwcaps.rst b/Documentation/arch/arm64/elf_hwcaps.rst
> index f60ca5612daa..f63035696654 100644
> --- a/Documentation/arch/arm64/elf_hwcaps.rst
> +++ b/Documentation/arch/arm64/elf_hwcaps.rst
> @@ -478,6 +478,13 @@ HWCAP3_SVE_LUT6
> Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001 and
> ID_AA64ISAR2_EL1.LUT == 0b0010.
>
> +HWCAP3_LS64_ACCDATA
> + Functionality implied by ID_AA64ISAR1_EL1.LS64 >= 0b0011. Note that
> + the function of instruction st64bv0 requires support by CPU, system
> + and target (device) memory location and HWCAP3_LS64_ACCDATA implies
> + the support of CPU. User should only use st64bv0 on supported target
> + (device) memory location, otherwise fallback to the non-atomic
> + alternatives.
Not sure where to document it but without a device and PASID the
instruction will trigger SIGBUS. I'm not even sure the fallback to
non-atomic alternatives is appropriate since user has no knowledge of
PASIDs. Something like (feel free to reword):
Functionality implied by ID_AA64ISAR1_EL1.LS64 >= 0b0011. Note that
the function of instruction st64bv0 requires support by CPU, system
and target (device) memory location and HWCAP3_LS64_ACCDATA implies
the support of CPU only.
The kernel uses ACCDATA_EL1 to supply the Process Address Space ID
(PASID) of the calling process. The CPU replaces bits [31:0] of the
64-byte store data with this value. st64bv0 can only be used after a
device driver has bound the process address space to a device that
takes the PASID from the store payload. Otherwise, the instruction
raises SIGBUS with si_code == BUS_OBJERR.
But a bit more below before deciding what this HWCAP means:
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index c88ea4b93138..dcbe024284e0 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -3223,6 +3223,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
> HWCAP_CAP(ID_AA64ISAR1_EL1, DGH, IMP, CAP_HWCAP, KERNEL_HWCAP_DGH),
> HWCAP_CAP(ID_AA64ISAR1_EL1, I8MM, IMP, CAP_HWCAP, KERNEL_HWCAP_I8MM),
> HWCAP_CAP(ID_AA64ISAR1_EL1, LS64, LS64, CAP_HWCAP, KERNEL_HWCAP_LS64),
> + HWCAP_CAP(ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA, CAP_HWCAP, KERNEL_HWCAP_LS64_ACCDATA),
This HWCAP is advertised even with CONFIG_IOMMU_SVA=n but in such
configuration we'll get a SIGILL rather than SIGBUS since
system_supports_ls64_accdata() is false. It feels a bit inconsistent:
HWCAP_CAP() above suggests it's a CPU only feature but the behaviour,
SIGBUS etc. depends on the kernel configuration.
We could make this a CPU feature only (irrespective of iommu) but then
we'd need to inform the user somehow that PASIDs get passed to the
device. The easiest is to add #ifdef around this with a dedicated
CONFIG_ARM64_LS64_ACCDATA option which depends on IOMMU_SVA (same with
system_supports_ls64_accdata()).
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 18:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:53 [PATCH v2 0/3] st64bv0 support in iommu-sva Arnd Bergmann
[not found] ` <20261126155339.1349218-2-arnd@kernel.org>
2026-11-30 17:24 ` [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Catalin Marinas
[not found] ` <20261126155339.1349218-3-arnd@kernel.org>
2026-11-30 18:02 ` [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox