Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] st64bv0 support in iommu-sva
@ 2026-11-26 15:53 Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ 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] 4+ messages in thread

* [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA
  2026-11-26 15:53 [PATCH v2 0/3] st64bv0 support in iommu-sva Arnd Bergmann
@ 2026-11-26 15:53 ` Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 3/3] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-11-26 15:53 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Arnd Bergmann

From: Arnd Bergmann <arnd@arndb.de>

I/O devices that understand the st64bv0 instruction for doing shared
virtual access from userspace need to set the pasid value in the
accdata_el1 register, but in general we want this to be disabled unless
a driver actually hands an MMIO area to userspace that accepts these
commands and installs a pasid using iommu_sva_bind_device().

Rather than trying to find all threads that use an mm_struct by the
time the pasid created, iommu_sva_bind_device() only stores the pasid in
'struct iommu_mm_data' and sets up the iommu domain in the device. The
first attempt to use SVA from userspace traps into do_el0_other(),
which checks that this is indeed valid and then sets the configured
pasid before enabling SCTLR_EL1_EnAS0.

On machines running KVM guests, KVM already handles saving and restoring
ACCDATA now. If the same process uses SVA itself, the context is restored
upon guest access.  This only really makes sense if the host device using
SVA is attached to the same SMMU using a single stage translation, and
another device is assigned to the guest VMID for stage2 so it can use
the stage1 translation inside of the guest using ACCDATA as PASID.

During fork() and exec(), the mm->iommu_mm is cleaned up, so
SCTLR_EL1_EnAS0 has to get turned off as well. If a process with accdata
set enters suspend, restore the value when waking up in case the firmware
lost it.

The design is roughly based on what x86 does with try_fixup_enqcmd_gp().

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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/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 ++
 11 files changed, 151 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index 7d7b8eb7f72f..aba24d024e37 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -914,6 +914,12 @@ static inline bool system_supports_bbml3(void)
 	return alternative_has_cap_unlikely(ARM64_HAS_BBML3);
 }
 
+static inline bool system_supports_ls64_accdata(void)
+{
+	return IS_ENABLED(CONFIG_IOMMU_SVA) &&
+	       cpus_have_final_cap(ARM64_HAS_LS64_ACCDATA);
+}
+
 int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
 bool try_emulate_mrs(struct pt_regs *regs, u32 isn);
 
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
 
 .Lset_hcrx_\@:
 	msr_s	SYS_HCRX_EL2, x0
diff --git a/arch/arm64/include/asm/exception.h b/arch/arm64/include/asm/exception.h
index a2da3cb21c24..7c61b50718d6 100644
--- a/arch/arm64/include/asm/exception.h
+++ b/arch/arm64/include/asm/exception.h
@@ -81,6 +81,7 @@ void do_el0_sys(unsigned long esr, struct pt_regs *regs);
 void do_sp_pc_abort(unsigned long addr, unsigned long esr, struct pt_regs *regs);
 void bad_el0_sync(struct pt_regs *regs, int reason, unsigned long esr);
 void do_el0_cp15(unsigned long esr, struct pt_regs *regs);
+void do_el0_other(struct pt_regs *regs, unsigned long esr);
 int do_compat_alignment_fixup(unsigned long addr, struct pt_regs *regs);
 void do_el0_svc(struct pt_regs *regs);
 void do_el0_svc_compat(struct pt_regs *regs);
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);
+
 	/*
 	 * Update the saved TTBR0_EL1 of the scheduled-in task as the previous
 	 * value may have not been initialised yet (activate_mm caller) or the
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 481f1999f7c1..bf5ea7bc871a 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_MASK)
 
 static inline void arch_thread_struct_whitelist(unsigned long *offset,
 						unsigned long *size)
diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index beb56891fc4f..03ecc73c44a4 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -807,6 +807,14 @@ static void noinstr el0_fpac(struct pt_regs *regs, unsigned long esr)
 	arm64_exit_to_user_mode(regs);
 }
 
+static void noinstr el0_other(struct pt_regs *regs, unsigned long esr)
+{
+	arm64_enter_from_user_mode(regs);
+	local_daif_restore(DAIF_PROCCTX);
+	do_el0_other(regs, esr);
+	arm64_exit_to_user_mode(regs);
+}
+
 asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
 {
 	unsigned long esr = read_sysreg(esr_el1);
@@ -870,6 +878,9 @@ asmlinkage void noinstr el0t_64_sync_handler(struct pt_regs *regs)
 	case ESR_ELx_EC_FPAC:
 		el0_fpac(regs, esr);
 		break;
+	case ESR_ELx_EC_OTHER:
+		el0_other(regs, esr);
+		break;
 	default:
 		el0_inv(regs, esr);
 	}
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 42b15b0c069f..ae0af4d7cbc2 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -340,6 +340,29 @@ static int copy_thread_gcs(struct task_struct *p,
 
 #endif
 
+#ifdef CONFIG_IOMMU_SVA
+static void flush_ls64_accdata(void)
+{
+	if (!system_supports_ls64_accdata() ||
+	    !(current->thread.sctlr_user & SCTLR_EL1_EnAS0))
+		return;
+
+	preempt_disable();
+	current->thread.sctlr_user &= ~SCTLR_EL1_EnAS0;
+	update_sctlr_el1(current->thread.sctlr_user);
+	preempt_enable();
+}
+
+static void copy_thread_ls64_accdata(struct task_struct *p)
+{
+	/* Turn off ls64_accdata for new thread */
+	p->thread.sctlr_user &= ~SCTLR_EL1_EnAS0;
+}
+#else
+static void flush_ls64_accdata(void) { }
+static void copy_thread_ls64_accdata(struct task_struct *p) { }
+#endif
+
 void flush_thread(void)
 {
 	fpsimd_flush_thread();
@@ -348,6 +371,7 @@ void flush_thread(void)
 	flush_tagged_addr_state();
 	flush_poe();
 	flush_gcs();
+	flush_ls64_accdata();
 }
 
 void exit_thread(struct task_struct *tsk)
@@ -524,6 +548,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 		if (system_supports_poe())
 			p->thread.por_el0 = POR_EL0_INIT;
 	}
+	copy_thread_ls64_accdata(p);
 	p->thread.cpu_context.pc = (unsigned long)ret_from_fork;
 	p->thread.cpu_context.sp = (unsigned long)childregs;
 	/*
diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c
index 4c281ae6babe..b60c782d5e34 100644
--- a/arch/arm64/kernel/suspend.c
+++ b/arch/arm64/kernel/suspend.c
@@ -42,6 +42,20 @@ void __init cpu_suspend_set_dbg_restorer(int (*hw_bp_restore)(unsigned int))
 	hw_breakpoint_restore = hw_bp_restore;
 }
 
+static void ls64_accdata_suspend_exit(void)
+{
+	u32 pasid;
+
+	if (!system_supports_ls64_accdata())
+		return;
+
+	/* if current thread has accdata enabled, restore the pasid value */
+	if (current->thread.sctlr_user & SCTLR_EL1_EnAS0) {
+		pasid = mm_get_enqcmd_pasid(current->mm);
+		write_sysreg_s(pasid, SYS_ACCDATA_EL1);
+	}
+}
+
 void notrace __cpu_suspend_exit(void)
 {
 	unsigned int cpu = smp_processor_id();
@@ -86,6 +100,9 @@ void notrace __cpu_suspend_exit(void)
 
 	/* Restore additional feature-specific configuration */
 	ptrauth_suspend_exit();
+
+	/* Restore accdata for st64bv0 */
+	ls64_accdata_suspend_exit();
 }
 
 /*
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;
+}
+
+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;
+
+	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);
+}
+
 #define __user_cache_maint(insn, address, res)			\
 	if (address >= TASK_SIZE_MAX) {				\
 		res = -EFAULT;					\
@@ -842,6 +900,7 @@ static const char *esr_class_str[] = {
 	[ESR_ELx_EC_FP_ASIMD]		= "ASIMD",
 	[ESR_ELx_EC_CP10_ID]		= "CP10 MRC/VMRS",
 	[ESR_ELx_EC_PAC]		= "PAC",
+	[ESR_ELx_EC_OTHER]		= "OTHER",
 	[ESR_ELx_EC_CP14_64]		= "CP14 MCRR/MRRC",
 	[ESR_ELx_EC_BTI]		= "BTI",
 	[ESR_ELx_EC_ILL]		= "PSTATE.IL",
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index 4a008c8a696b..2d6f4dfd564f 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -143,10 +143,14 @@ static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt)
 {
 	struct kvm_vcpu *vcpu;
 
-	/* The host never uses ACCDATA_EL1 */
-	if (!cpus_have_final_cap(ARM64_HAS_LS64_ACCDATA) || !ctxt_is_guest(ctxt))
+	/* The hardware does not support ACCDATA_EL1 */
+	if (!cpus_have_final_cap(ARM64_HAS_LS64_ACCDATA))
 		return false;
 
+	/* host only cares if SVA is enabled */
+	if (!ctxt_is_guest(ctxt))
+		return IS_ENABLED(CONFIG_IOMMU_SVA);
+
 	vcpu = ctxt_to_vcpu(ctxt);
 	return kvm_has_feat(kern_hyp_va(vcpu->kvm), ID_AA64ISAR1_EL1, LS64, LS64_ACCDATA);
 }
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
+
 Sysreg	RCWMASK_EL1	3	0	13	0	6
 Field	63:0	RCWMASK
 EndSysreg
-- 
2.53.0



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

* [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA
  2026-11-26 15:53 [PATCH v2 0/3] st64bv0 support in iommu-sva Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
@ 2026-11-26 15:53 ` Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 3/3] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-11-26 15:53 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Arnd Bergmann

From: Arnd Bergmann <arnd@arndb.de>

LS64_ACCDATA extends the LS64 feature with the user-space st64bv0 instruction
and the EL1 ACCDATA register. Like LS64, it was added with Armv8.7, and it
roughly corresponds to the 'enqcmd' feature for shared hardware workqueues
on x86 CPUs as described in the kernel's SVA documentation. [1]

Userspace can check availability of HWCAP3_LS64_ACCDATA to see if the shared
hardware workqueue feature is possible on a given driver.

Link: https://www.kernel.org/doc/html/v7.3/arch/x86/sva.html#enqcmd [1]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 Documentation/arch/arm64/elf_hwcaps.rst | 7 +++++++
 arch/arm64/include/uapi/asm/hwcap.h     | 1 +
 arch/arm64/kernel/cpufeature.c          | 1 +
 arch/arm64/kernel/cpuinfo.c             | 1 +
 4 files changed, 10 insertions(+)

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.
 
 4. Unused AT_HWCAP bits
 -----------------------
diff --git a/arch/arm64/include/uapi/asm/hwcap.h b/arch/arm64/include/uapi/asm/hwcap.h
index 10272ddb4d6f..c85c445275f6 100644
--- a/arch/arm64/include/uapi/asm/hwcap.h
+++ b/arch/arm64/include/uapi/asm/hwcap.h
@@ -155,5 +155,6 @@
 #define HWCAP3_F16F32DOT	(1UL << 9)
 #define HWCAP3_F16F32MM		(1UL << 10)
 #define HWCAP3_SVE_LUT6		(1UL << 11)
+#define HWCAP3_LS64_ACCDATA	(1UL << 12)
 
 #endif /* _UAPI__ASM_HWCAP_H */
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),
 	HWCAP_CAP(ID_AA64ISAR2_EL1, LUT, IMP, CAP_HWCAP, KERNEL_HWCAP_LUT),
 	HWCAP_CAP(ID_AA64ISAR3_EL1, FAMINMAX, IMP, CAP_HWCAP, KERNEL_HWCAP_FAMINMAX),
 	HWCAP_CAP(ID_AA64ISAR3_EL1, LSFE, IMP, CAP_HWCAP, KERNEL_HWCAP_LSFE),
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 94e6cd211d70..beea36b282f1 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -158,6 +158,7 @@ static const char *const hwcap_str[] = {
 	[KERNEL_HWCAP_F16F32DOT]	= "f16f32dot",
 	[KERNEL_HWCAP_F16F32MM]		= "f16f32mm",
 	[KERNEL_HWCAP_SVE_LUT6]		= "svelut6",
+	[KERNEL_HWCAP_LS64_ACCDATA]	= "ls64accdata",
 };
 
 #ifdef CONFIG_COMPAT
-- 
2.53.0



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

* [PATCH v2 3/3] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
  2026-11-26 15:53 [PATCH v2 0/3] st64bv0 support in iommu-sva Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
  2026-11-26 15:53 ` [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA Arnd Bergmann
@ 2026-11-26 15:53 ` Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-11-26 15:53 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Arnd Bergmann, Yicong Yang

From: Arnd Bergmann <arnd@arndb.de>

Add tests for FEAT_LS64_ACCDATA, similar to FEAT_LS64 test added in
57a96356bb69 ("kselftest/arm64: Add HWCAP test for FEAT_LS64").

st64bv0 only works on very specific devices and returns a bus error on
anything else, but an illegal instruction on machines without the feature.

Based on an earlier patch by Yicong Yang.

Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/all/20241202135504.14252-4-yangyicong@huawei.com/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 tools/testing/selftests/arm64/abi/hwcap.c | 50 +++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/tools/testing/selftests/arm64/abi/hwcap.c b/tools/testing/selftests/arm64/abi/hwcap.c
index 19fca95f7c22..8981a1eed2ca 100644
--- a/tools/testing/selftests/arm64/abi/hwcap.c
+++ b/tools/testing/selftests/arm64/abi/hwcap.c
@@ -693,6 +693,48 @@ static void ls64_sigill(void)
 	/* ST64B x0, [x8] */
 	asm volatile(".inst 0xf83f9100" : : "r" (xt_1), "r" (xn)
 		     : "x1", "x2", "x3", "x4", "x5", "x6", "x7");
+	sigaction(SIGBUS, &old, NULL);
+}
+
+static void ls64_accdata_sigill(void)
+{
+	struct sigaction ign, old;
+	char dst[64] __aligned(64);
+
+	/*
+	 * Like LS64, LS64_ACCDATA requires both the feature to be
+	 * available in hardware, and the address to be on a device
+	 * capable of the transaction.
+	 * In addition, the device driver that has mapped the device
+	 * must have created a PASID that can be used as ACCDATA.
+	 *
+	 * For testing the ABI, check only that st64bv0 on a user
+	 * address gives the expected SIGBUS error when the instruction
+	 * is not enabled for this thread. If it was enabled, the
+	 * error status would be reported in 'st' instead of a signal,
+	 * but that can only be tested if a PASID is set for this thread.
+	 */
+	ign.sa_sigaction = ignore_signal;
+	ign.sa_flags = SA_SIGINFO | SA_RESTART;
+	sigemptyset(&ign.sa_mask);
+	sigaction(SIGBUS, &ign, &old);
+
+	register void *xn asm ("x8") = dst;
+	register u64 xt_1 asm ("x0") = 1;
+	register u64 xt_2 asm ("x1") = 2;
+	register u64 xt_3 asm ("x2") = 3;
+	register u64 xt_4 asm ("x3") = 4;
+	register u64 xt_5 asm ("x4") = 5;
+	register u64 xt_6 asm ("x5") = 6;
+	register u64 xt_7 asm ("x6") = 7;
+	register u64 xt_8 asm ("x7") = 8;
+	register u64 st asm ("x9");
+
+	/* ST64BV0 x9, x0, [x8] */
+	asm volatile(".inst 0xf829a100" : "=r" (st) :
+			"r" (xt_1), "r" (xt_2), "r" (xt_3), "r" (xt_4),
+			"r" (xt_5), "r" (xt_6), "r" (xt_7), "r" (xt_8),
+			"r" (xn));
 
 	sigaction(SIGBUS, &old, NULL);
 }
@@ -1300,6 +1342,14 @@ static const struct hwcap_data {
 		.sigill_fn = ls64_sigill,
 		.sigill_reliable = true,
 	},
+	{
+		.name = "LS64_ACCDATA",
+		.at_hwcap = AT_HWCAP3,
+		.hwcap_bit = HWCAP3_LS64_ACCDATA,
+		.cpuinfo = "ls64_accdata",
+		.sigill_fn = ls64_accdata_sigill,
+		.sigill_reliable = true,
+	},
 };
 
 typedef void (*sighandler_fn)(int, siginfo_t *, void *);
-- 
2.53.0



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

end of thread, other threads:[~2026-11-26 15:54 UTC | newest]

Thread overview: 4+ 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
2026-11-26 15:53 ` [PATCH v2 1/3] arm64: dynamically enable st64bv0 for SVA Arnd Bergmann
2026-11-26 15:53 ` [PATCH v2 2/3] arm64: add HWCAP3_LS64_ACCDATA Arnd Bergmann
2026-11-26 15:53 ` [PATCH v2 3/3] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox