st64bv0 support in iommu-sva
Subsystems (5)
v3 cover st64bv0 support in iommu-sva
From: Arnd Bergmann <[email protected]>
This is an updated set of patches to enable ls64_accdata with the st64bv0 instruction in Linux, based on additional review from Catalin and remaining sashiko-bot replies.
The only remaining issue I'm aware of is the error code reported by the signal handler. I used a hardcoded '0' here instead of reporting reporting the esr value, which is consistent with most other trap handlers. If we determine that reporting esr is both safe to do here and desired, a follow-up patch can change this for all the traps that have the same behavior.
Changes since v2:
- split out kvm context save/restore change
- turn off fine grained traps for ACCDATA_EL1
- fix thread switch by moving ACCDATA_EL1 access to __switch_to
- report invalid access consistently as SIGBUS when ls64_accdata is supported by CPU
Changes since v1:
- 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 (4):
arm64: kvm: save and restore ACCDATA_EL1 if used by host
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 | 11 ++++ arch/arm64/Kconfig | 13 +++++ arch/arm64/include/asm/cpufeature.h | 5 ++ arch/arm64/include/asm/el2_setup.h | 12 +++++ arch/arm64/include/asm/exception.h | 1 + arch/arm64/include/asm/processor.h | 2 +- arch/arm64/include/asm/sysreg.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 | 42 +++++++++++++++ arch/arm64/kernel/suspend.c | 19 +++++++ arch/arm64/kernel/traps.c | 63 ++++++++++++++++++++++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++- arch/arm64/tools/sysreg | 5 ++ tools/testing/selftests/arm64/abi/hwcap.c | 50 +++++++++++++++++ 17 files changed, 242 insertions(+), 5 deletions(-)
Signature · 25 lines
2.53.0 Cc: [email protected] Cc: Catalin Marinas <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Fuad Tabba <[email protected]> Cc: [email protected] Cc: Joey Gouly <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Navneet Singh <[email protected]> Cc: Oliver Upton <[email protected]> Cc: [email protected] Cc: Siddharth Chintamaneni <[email protected]> Cc: Steffen Eiden <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yicong Yang <[email protected]> Cc: Zenghui Yu <[email protected]> Cc: Zhou Wang <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
PATCH v3 1/4 arm64: kvm: save and restore ACCDATA_EL1 if used by host
From: Arnd Bergmann <[email protected]>
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.
Assume that the host context needs to be saved and restored whenever both the kernel and the hardware support the feature. This assumes it is cheaper to access the register unconditionally than to check for 'current->thread.sctlr_user & SCTLR_EL1_EnAS0'.
--- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +6 -2
@@ -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_ARM64_LS64_ACCDATA ); + vcpu =ctxt_to_vcpu (ctxt);return kvm_has_feat (kern_hyp_va (vcpu->kvm),ID_AA64ISAR1_EL1 ,LS64 ,LS64_ACCDATA ); }
Signature · 1 line
2.53.0
PATCH v3 2/4 arm64: dynamically enable st64bv0 for SVA
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
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.
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().
--- arch/arm64/Kconfig | 13 ++++++ arch/arm64/include/asm/cpufeature.h | 5 +++ arch/arm64/include/asm/el2_setup.h | 12 ++++++ arch/arm64/include/asm/exception.h | 1 + arch/arm64/include/asm/processor.h | 2 +- arch/arm64/include/asm/sysreg.h | 2 - arch/arm64/kernel/entry-common.c | 11 +++++ arch/arm64/kernel/process.c | 42 +++++++++++++++++++ arch/arm64/kernel/suspend.c | 19 +++++++++ arch/arm64/kernel/traps.c | 63 +++++++++++++++++++++++++++++ arch/arm64/tools/sysreg | 5 +++ 11 files changed, 172 insertions(+), 3 deletions(-)
arch/arm64/Kconfig +13 -0
@@ -2324,6 +2324,19 @@ config ARM64_EPAN The feature is detected at runtime, and will remain disabled if the cpu does not implement the feature. + +config ARM64_LS64_ACCDATA + bool "Enable support for 64-byte EL0 stores with status (LS64_ACCDATA)" + depends on IOMMU_SVA + default y + help + 64-byte EL0 stores with status use the st64bv0 instruction to + initiate a transaction on an I/O device with shared virtual + addressing. + + The feature is detected at runtime, and will remain disabled + if the cpu does not implement the feature. + endmenu # "ARMv8.7 architectural features" config AS_HAS_MOPS
arch/arm64/include/asm/cpufeature.h +5 -0
@@ -914,6 +914,11 @@ static inline bool system_supports_bbml3(void)return alternative_has_cap_unlikely (ARM64_HAS_BBML3 ); } +static inline bool system_supports_ls64_accdata (void ) +{ +return 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);
arch/arm64/include/asm/el2_setup.h +12 -0
@@ -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
@@ -394,6 +397,15 @@ orr x0, x0, #HFGRTR_EL2_nGCS_EL0_MASK .Lskip_gce_fgt_\@: + mrs_s x1, SYS_ID_AA64ISAR1_EL1 + ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_ACCDATA + b.lt .Lskip_ls64_accdata_\@ + +/* Disable traps of access to ACCDATA_EL1 register */ + orr x0, x0, #HFGRTR_EL2_nACCDATA_EL1 + +.Lskip_ls64_accdata_\@: .Lset_fgt_\@: msr_s SYS_HFGRTR_EL2, x0
arch/arm64/include/asm/exception.h +1 -0
@@ -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);
arch/arm64/include/asm/processor.h +1 -1
@@ -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)
arch/arm64/include/asm/sysreg.h +0 -2
@@ -392,8 +392,6 @@#define SYS_ICC_IGRPEN0_EL1 sys_reg(3, 0, 12, 12, 6)#define SYS_ICC_IGRPEN1_EL1 sys_reg(3, 0, 12, 12, 7) -#define SYS_ACCDATA_EL1 sys_reg(3, 0, 13, 0, 5) -#define SYS_CNTKCTL_EL1 sys_reg(3, 0, 14, 1, 0)#define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7)
arch/arm64/kernel/entry-common.c +11 -0
@@ -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); }
arch/arm64/kernel/process.c +42 -0
72 lines not on this page · raw message
arch/arm64/kernel/suspend.c +19 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/ftrace.h> +#include <linux/iommu.h> #include <linux/percpu.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -42,6 +43,21 @@ 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 (!IS_ENABLED (CONFIG_ARM64_LS64_ACCDATA ) || + !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 +102,9 @@ void notrace __cpu_suspend_exit(void)/* Restore additional feature-specific configuration */ ptrauth_suspend_exit (); + +/* Restore accdata for st64bv0 */ +ls64_accdata_suspend_exit (); }/*
arch/arm64/kernel/traps.c +63 -0
81 lines not on this page · raw message
arch/arm64/tools/sysreg +5 -0
@@ -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
Signature · 1 line
2.53.0
PATCH v3 3/4 arm64: add HWCAP3_LS64_ACCDATA
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
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. This will be reported regardless of whether CONFIG_ARM64_LS64_ACCDATA is enabled, and a device driver may still fail to enable SVA on a device depending on both kernel configuration and hardware capabilities of the system.
--- Documentation/arch/arm64/elf_hwcaps.rst | 11 +++++++++++ arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 1 + arch/arm64/kernel/cpuinfo.c | 1 + 4 files changed, 14 insertions(+)
Documentation/arch/arm64/elf_hwcaps.rst +11 -0
@@ -478,6 +478,17 @@ 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 a matching + device driver. 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 + supports this instruction. Any other I/O access raises SIGBUS with + si_code == BUS_OBJERR. 4. Unused AT_HWCAP bits -----------------------
arch/arm64/include/uapi/asm/hwcap.h +1 -0
@@ -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 */
arch/arm64/kernel/cpufeature.c +1 -0
@@ -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),
arch/arm64/kernel/cpuinfo.c +1 -0
@@ -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
Signature · 1 line
2.53.0
PATCH v3 4/4 kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
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.
--- tools/testing/selftests/arm64/abi/hwcap.c | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/selftests/arm64/abi/hwcap.c +50 -0
@@ -693,6 +693,48 @@ static void ls64_sigill(void)/* ST64B x0, [x8] */ asmvolatile (".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; + registeru64 st asm ("x9" ); + +/* ST64BV0 x9, x0, [x8] */ + asmvolatile (".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 = "ls64accdata", + .sigill_fn = ls64_accdata_sigill, + .sigill_reliable = true, + }, };typedef void (*sighandler_fn )(int ,siginfo_t *,void *);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 4/4] kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Critical] arm64: NULL dereference of next->mm in ls64_accdata_thread_switch() on exit - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Critical] arm64: NULL dereference of next->mm in ls64_accdata_thread_switch() on exit
- [Low] kselftest/arm64: ls64_accdata_sigill() never verifies SIGBUS or BUS_OBJERR
--
commit ac9920ac55cd362ba0b8ee0ff7743b42ef69f9c4
Author: Arnd Bergmann <[email protected]>
kselftest/arm64: Add HWCAP test for FEAT_LS64_ACCDATA
This commit adds a HWCAP3_LS64_ACCDATA selftest to the arm64 ABI hwcap test, issuing st64bv0 on a stack buffer to verify the instruction does not raise SIGILL when the feature is reported.
Quoted 5 lines
tools/testing/selftests/arm64/abi/hwcap.c +0
-0@@ -693,6 +693,48 @@ static void ls64_sigill(void)
[ ... ]
Quoted 12 lines
tools/testing/selftests/arm64/abi/hwcap.c +12
-0+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. +*
tools/testing/selftests/arm64/abi/hwcap.c static void ls64_sigill(void) · line 720
Quoted 10 lines
tools/testing/selftests/arm64/abi/hwcap.c +10
-0+* 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);
[Severity: Low]
Does ls64_accdata_sigill() actually verify that SIGBUS with BUS_OBJERR is delivered?
The comment states that the test checks for the expected SIGBUS error when st64bv0 is not enabled for the thread, matching the ABI in Documentation/arch/arm64/elf_hwcaps.rst. However, ignore_signal() only advances uc->uc_mcontext.pc without recording SIGBUS delivery or checking info->si_code == BUS_OBJERR, and the hwcaps[] entry leaves .sigbus_fn NULL.
If a kernel bug left SCTLR_EL1.EnAS0 enabled for threads without a PASID, st64bv0 would execute without raising SIGILL or SIGBUS and the test would silently pass. Either verify SIGBUS with BUS_OBJERR when HWCAP3_LS64_ACCDATA is set, or update the comment to state that only the absence of SIGILL is checked.
[ ... ]
tools/testing/selftests/arm64/abi/hwcap.c static const struct hwcap_data { · line 1353
Quoted 13 lines
tools/testing/selftests/arm64/abi/hwcap.c +8
-0@@ -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 = "ls64accdata", + .sigill_fn = ls64_accdata_sigill, + .sigill_reliable = true, + }, };
[Severity: Critical]
In earlier commit "arm64: dynamically enable st64bv0 for SVA" from this series, can ls64_accdata_thread_switch() dereference a NULL next->mm when an exiting task is scheduled back in?
Once a thread enables st64bv0 via do_el0_other() -> try_enable_st64bv0(), SCTLR_EL1_EnAS0 remains set in thread.sctlr_user across exit_mm(), which sets current->mm = NULL. If the exiting task sleeps or is preempted during teardown (for example in mmput() or exit_files()), __switch_to() calls ls64_accdata_thread_switch() with next->mm == NULL:
arch/arm64/kernel/process.c:ls64_accdata_thread_switch() {
...
if (!(next->thread.sctlr_user & SCTLR_EL1_EnAS0))
return;
pasid = mm_get_enqcmd_pasid(next->mm);
...
}mm_get_enqcmd_pasid() unconditionally reads mm->iommu_mm, causing a deterministic kernel NULL pointer dereference panic when any local process that used st64bv0 exits.
In the same commit, ls64_accdata_suspend_exit() in arch/arm64/kernel/suspend.c also calls mm_get_enqcmd_pasid(current->mm) without checking current->mm != NULL, and writes the returned pasid to SYS_ACCDATA_EL1 without checking pasid != IOMMU_PASID_INVALID (which can write IOMMU_PASID_INVALID if the SVA device was unbound before suspend).
Clearing SCTLR_EL1_EnAS0 on exit, or checking for a NULL mm and IOMMU_PASID_INVALID before programming SYS_ACCDATA_EL1, avoids both issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 1/4] arm64: kvm: save and restore ACCDATA_EL1 if used by host
In reply to Arnd BergmannThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] KVM: arm64: ctxt_has_accdata() skips guest feature check for host context - [Low] KVM: arm64: host…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] KVM: arm64: ctxt_has_accdata() skips guest feature check for host context
- [Low] KVM: arm64: host ACCDATA_EL1 exposure if LS64_ACCDATA exists without FGT/HCX
--
commit e99c2c724dcc1601daf22519f4aeb9ec876d3278
Author: Arnd Bergmann <[email protected]>
arm64: kvm: save and restore ACCDATA_EL1 if used by host
This commit updates ctxt_has_accdata() so KVM saves and restores the host's ACCDATA_EL1 register when the hardware supports ARM64_HAS_LS64_ACCDATA and CONFIG_ARM64_LS64_ACCDATA is enabled.
Quoted 7 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +0
-0@@ -143,10 +143,14 @@ static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt) {struct kvm_vcpu *vcpu;
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt) · line 152
Quoted 10 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +5
-2-/* 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_ARM64_LS64_ACCDATA );
[Severity: Low]
Should this fall through to the guest kvm_has_feat() check instead of returning early for the host context?
When running a guest without FEAT_LS64_ACCDATA (such as a pKVM protected VM), guest ACCDATA_EL1 accesses are trapped and HCRX_EL2_EnAS0 is clear. Returning early causes KVM to save and restore the unchanged host SYS_ACCDATA_EL1 on every nVHE/pKVM world switch and VHE vCPU load/put.
Returning false only when !ctxt_is_guest(ctxt) && !IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) and falling through to kvm_has_feat() would avoid those accesses and match the sibling ctxt_has_*() helpers in this header.
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt) · line 156
Quoted 4 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +1
-0+ vcpu =ctxt_to_vcpu (ctxt);return kvm_has_feat (kern_hyp_va (vcpu->kvm),ID_AA64ISAR1_EL1 ,LS64 ,LS64_ACCDATA ); }
[Severity: Low]
Can a CPU implement FEAT_LS64_ACCDATA without implementing FEAT_FGT or FEAT_HCX? This question rests on an ARM64 architecture detail that could not be confirmed from the kernel source.
If so, entering a guest without FEAT_LS64_ACCDATA leaves the host's live SVA PASID in SYS_ACCDATA_EL1, since __sysreg_restore_user_state() skips writing it when ctxt_has_accdata(guest_ctxt) is false.
Because ACCDATA_EL1 trapping in __activate_traps_hfgxtr() is gated on ARM64_HAS_FGT and HCRX_EL2.EnAS0 in __activate_traps_common() is gated on ARM64_HAS_HCX, the guest could read or use the host's ACCDATA_EL1 value without trapping to EL2.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 3/4] arm64: add HWCAP3_LS64_ACCDATA
In reply to Arnd BergmannThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Critical] arm64: NULL mm dereference in ls64_accdata_thread_switch() on task exit - [Medium] arm64…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Critical] arm64: NULL mm dereference in ls64_accdata_thread_switch() on task exit
- [Medium] arm64: HWCAP3_LS64_ACCDATA advertised without CONFIG_ARM64_LS64_ACCDATA
- [Low] arm64: elf_hwcaps.rst overstates SIGBUS scope and uses >= convention
- [Low] arm64: elf_hwcaps.rst unconfirmed st64bv0 bits 31:0 overwrite claim
--
commit f0a6f157224e6ac0c0f369c507739103758e5747
Author: Arnd Bergmann <[email protected]>
arm64: add HWCAP3_LS64_ACCDATA
This commit exposes FEAT_LS64_ACCDATA to userspace via HWCAP3_LS64_ACCDATA and /proc/cpuinfo, and documents its semantics in elf_hwcaps.rst.
Quoted 6 lines
Documentation/arch/arm64/elf_hwcaps.rst +0
-0@@ -478,6 +478,17 @@ HWCAP3_SVE_LUT6 Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001 and
Documentation/arch/arm64/elf_hwcaps.rst HWCAP3_SVE_LUT6 · line 488
Quoted 10 lines
Documentation/arch/arm64/elf_hwcaps.rst +8
-0ID_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 a matching + device driver. 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
[Severity: Low]
This rests on an arm64 architectural detail that could not be confirmed from the kernel source: does st64bv0 transmit ACCDATA_EL1[31:0] as separate transaction metadata alongside the 64-byte store payload rather than overwriting bits [31:0] of the 64-byte store data?
If so, this documentation would mislead userspace about how to lay out its 64-byte st64bv0 work descriptors.
Documentation/arch/arm64/elf_hwcaps.rst HWCAP3_SVE_LUT6 · line 491
Quoted 3 lines
Documentation/arch/arm64/elf_hwcaps.rst +3
-0+ a device driver has bound the process address space to a device that + supports this instruction. Any other I/O access raises SIGBUS with + si_code == BUS_OBJERR.
[Severity: Low]
Does this overstate when SIGBUS with si_code == BUS_OBJERR is raised?
Only trapped st64bv0 instructions inject SIGBUS/BUS_OBJERR in do_el0_other(), not general I/O accesses. Furthermore, once try_enable_st64bv0() sets SCTLR_EL1_EnAS0 for a thread, it is not cleared on iommu_sva_unbind_device(), so later st64bv0 accesses by that thread to unbound or unsupported mappings no longer trap to do_el0_other() and are not guaranteed to raise SIGBUS.
Also, ID_AA64ISAR1_EL1.LS64 >= 0b0011 is the only entry in this file using >= instead of the idreg.field == val convention described in Section 2.
[ ... ]
arch/arm64/kernel/cpufeature.c static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { · line 3226
Quoted 9 lines
arch/arm64/kernel/cpufeature.c +1
-0@@ -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),
[Severity: Medium]
As reported by Catalin Marinas on v2 [1], should this entry and system_supports_ls64_accdata() be gated on CONFIG_ARM64_LS64_ACCDATA?
With CONFIG_IOMMU_SVA=y and CONFIG_ARM64_LS64_ACCDATA=n, in-tree SVA drivers such as uacce still bind via iommu_sva_bind_device() without checking CONFIG_ARM64_LS64_ACCDATA, while userspace sees HWCAP3_LS64_ACCDATA set with no way to tell that kernel ACCDATA_EL1 support is compiled out. Issuing st64bv0 then unconditionally fails with SIGBUS (BUS_OBJERR) in try_enable_st64bv0().
Guarding both the arm64_elf_hwcaps[] entry with #ifdef CONFIG_ARM64_LS64_ACCDATA and system_supports_ls64_accdata() with IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) would match the other Kconfig-gated EL0 features in this table.
[Severity: Critical]
Once userspace discovers HWCAP3_LS64_ACCDATA and executes st64bv0, can ls64_accdata_thread_switch() dereference a NULL next->mm on task exit?
In commit "arm64: dynamically enable st64bv0 for SVA", try_enable_st64bv0() sets SCTLR_EL1_EnAS0 in current->thread.sctlr_user, which is never cleared on exit. During do_exit(), exit_mm() sets current->mm = NULL before sleepable teardown steps such as exit_files(). If the exiting task sleeps or is preempted and later scheduled back in, __switch_to() calls ls64_accdata_thread_switch():
arch/arm64/kernel/process.c:ls64_accdata_thread_switch() {
if (!(next->thread.sctlr_user & SCTLR_EL1_EnAS0))
return;
pasid = mm_get_enqcmd_pasid(next->mm);
if (pasid != IOMMU_PASID_INVALID)
write_sysreg_s(pasid, SYS_ACCDATA_EL1);
}mm_get_enqcmd_pasid() unconditionally dereferences mm->iommu_mm, causing a kernel NULL pointer dereference inside __switch_to() with interrupts disabled and the runqueue lock held. Any unprivileged user with access to an SVA device can panic the kernel by running st64bv0 and exiting.
Similarly, ls64_accdata_suspend_exit() in arch/arm64/kernel/suspend.c passes current->mm to mm_get_enqcmd_pasid() without checking for NULL, and writes the result to SYS_ACCDATA_EL1 without checking for IOMMU_PASID_INVALID.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v3 2/4] arm64: dynamically enable st64bv0 for SVA
In reply to Arnd BergmannThank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Critical] arm64: NULL pointer dereference in ls64_accdata_thread_switch() on task exit - [Medium] arm64…
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Critical] arm64: NULL pointer dereference in ls64_accdata_thread_switch() on task exit
- [Medium] arm64: do_el0_other() drops esr_context on SIGILL by passing 0 for esr
- [Low] KVM: arm64: unnecessary host ACCDATA_EL1 save/restore in ctxt_has_accdata()
- [Low] arm64: missing FEAT_LS64_ACCDATA EL2 boot requirements in booting.rst
- [Low] arm64: missing SIGBUS description in force_signal_inject() --
commit 0483e6ecd8d45bd772eb519deb0c8760bf621a7c
Author: Arnd Bergmann <[email protected]>
arm64: dynamically enable st64bv0 for SVA
This commit adds CONFIG_ARM64_LS64_ACCDATA to enable EL0 st64bv0 on demand via do_el0_other() when a process has an IOMMU SVA PASID, and manages SCTLR_EL1.EnAS0 and ACCDATA_EL1 across fork, exec, context switch, and suspend.
arch/arm64/Kconfig config ARM64_EPAN · line 2316
Quoted 13 lines
arch/arm64/Kconfig +5
-0@@ -2309,6 +2309,19 @@ config ARM64_EPAN The feature is detected at runtime, and will remain disabled if the cpu does not implement the feature. + +config ARM64_LS64_ACCDATA + bool "Enable support for 64-byte EL0 stores with status (LS64_ACCDATA)" + depends on IOMMU_SVA + default y
[Severity: Low]
Does enabling CONFIG_ARM64_LS64_ACCDATA cause unnecessary host ACCDATA_EL1 save/restore in KVM when a guest does not use the feature?
In commit "arm64: kvm: save and restore ACCDATA_EL1 if used by host", ctxt_has_accdata() returns IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) early for host contexts before checking the guest's feature set. As a result, KVM saves and restores SYS_ACCDATA_EL1 on every VHE vcpu_load/vcpu_put and nVHE VM-entry/exit even when the guest does not expose FEAT_LS64_ACCDATA and traps any access.
Returning false only when !ctxt_is_guest(ctxt) && !IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) and falling through to kvm_has_feat() would avoid those redundant host register accesses.
[ ... ]
Quoted 14 lines
arch/arm64/include/asm/el2_setup.h +3
-0@@ -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
[ ... ]
arch/arm64/include/asm/el2_setup.h line 408
Quoted 13 lines
arch/arm64/include/asm/el2_setup.h +9
-0@@ -394,6 +397,15 @@ orr x0, x0, #HFGRTR_EL2_nGCS_EL0_MASK .Lskip_gce_fgt_\@: + mrs_s x1, SYS_ID_AA64ISAR1_EL1 + ubfx x1, x1, #ID_AA64ISAR1_EL1_LS64_SHIFT, #4 + cmp x1, #ID_AA64ISAR1_EL1_LS64_LS64_ACCDATA + b.lt .Lskip_ls64_accdata_\@ + +/* Disable traps of access to ACCDATA_EL1 register */ + orr x0, x0, #HFGRTR_EL2_nACCDATA_EL1 + +.Lskip_ls64_accdata_\@:
[Severity: Low]
As reported by Catalin Marinas on v2 [1], should Documentation/arch/arm64/booting.rst also document the EL2 requirements for FEAT_LS64_ACCDATA when the kernel is entered at EL1?
booting.rst already documents HCRX_EL2.EnALS and HCRX_EL2.EnASR for FEAT_LS64 and FEAT_LS64_V, but omits HCRX_EL2.EnAS0 (bit 0) and HFGRTR_EL2.nACCDATA_EL1 / HFGWTR_EL2.nACCDATA_EL1 (bit 50). Without this, firmware or hypervisors entering Linux at EL1 may leave these traps enabled.
[ ... ]
Quoted 4 lines
arch/arm64/kernel/process.c +0
-0
[ ... ]
arch/arm64/kernel/process.c static int copy_thread_gcs(struct task_struct *p, · line 374
Quoted 12 lines
arch/arm64/kernel/process.c +12
-0+/* switch PASID if new task has enabled st64bv0 */ +static void ls64_accdata_thread_switch (struct task_struct *next) +{ +u32 pasid; + +if (!(next->thread.sctlr_user & SCTLR_EL1_EnAS0)) +return ; + + pasid =mm_get_enqcmd_pasid (next->mm); +if (pasid !=IOMMU_PASID_INVALID ) +write_sysreg_s (pasid,SYS_ACCDATA_EL1 ); +}
[Severity: Critical]
Can ls64_accdata_thread_switch() cause a NULL pointer dereference on next->mm when an exiting task is scheduled back in?
SCTLR_EL1_EnAS0 is not cleared on task exit, so it stays set after do_exit() -> exit_mm() clears current->mm during sleepable teardown like exit_files(). When the task is rescheduled, __switch_to() passes NULL to mm_get_enqcmd_pasid(), which dereferences mm->iommu_mm.
ls64_accdata_suspend_exit() in arch/arm64/kernel/suspend.c also passes current->mm without a NULL check and writes SYS_ACCDATA_EL1 without checking for IOMMU_PASID_INVALID.
Guarding next->mm (and clearing SCTLR_EL1_EnAS0 in deactivate_mm()), along with checking current->mm and IOMMU_PASID_INVALID in ls64_accdata_suspend_exit(), would prevent the crash.
[ ... ]
Quoted 4 lines
arch/arm64/kernel/traps.c +0
-0
[ ... ]
arch/arm64/kernel/traps.c void do_el1_mops(struct pt_regs *regs, unsigned long esr) · line 596
Quoted 12 lines
arch/arm64/kernel/traps.c +12
-0+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 ()) +return ; + +force_signal_inject (SIGBUS ,BUS_OBJERR , regs->pc,0 ); +return ;
[Severity: Low]
Does force_signal_inject() have a description for SIGBUS?
Its switch statement only handles SIGILL and SIGSEGV, so an unhandled SIGBUS from st64bv0 falls through to default and logs "unknown or unrecoverable error" when show_unhandled_signals is enabled. Adding a SIGBUS case to force_signal_inject() would fix the log message.
arch/arm64/kernel/traps.c void do_el1_mops(struct pt_regs *regs, unsigned long esr) · line 606
Quoted 10 lines
arch/arm64/kernel/traps.c +10
-0+ +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 ); +}
[Severity: Medium]
As reported by Catalin Marinas on v2 [1], does passing 0 instead of esr here drop struct esr_context from the SIGILL signal frame?
Previously, unhandled ESR_ELx_EC_OTHER traps fell through to bad_el0_sync(regs, 0, esr), which saved esr in current->thread.fault_code so setup_sigframe() included esr_context. Passing esr as the fourth argument or reusing bad_el0_sync() would preserve the existing userspace behavior.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v3 1/4] arm64: kvm: save and restore ACCDATA_EL1 if used by host
In reply to [email protected]Quoted 23 lines · On Thu, Dec 3, 2026, at 11:16, [email protected] wrote:
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt) · line 152
Quoted 13 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +5
-2@@ -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_ARM64_LS64_ACCDATA );[Severity: Low]
Should this fall through to the guestkvm_has_feat()check instead of returning early for the host context?When running a guest without
FEAT_LS64_ACCDATA(such as a pKVM protected VM), guestACCDATA_EL1accesses are trapped andHCRX_EL2_EnAS0is clear. Returning early causes KVM to save and restore the unchanged hostSYS_ACCDATA_EL1on every nVHE/pKVM world switch and VHE vCPU load/put.
Quoted 4 lines
Returning false only when !ctxt_is_guest(ctxt) && !IS_ENABLED(CONFIG_ARM64_LS64_ACCDATA) and falling through to
kvm_has_feat()would avoid those accesses and match the sibling ctxt_has_*() helpers in this header.
Right, makes sense. We already rely on the FGT for the reason below, so I've changed it the same way now here.
Quoted 8 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h static inline bool ctxt_has_accdata(struct kvm_cpu_context *ctxt) · line 156
Quoted 3 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +0
-0vcpu =ctxt_to_vcpu (ctxt);return kvm_has_feat (kern_hyp_va (vcpu->kvm),ID_AA64ISAR1_EL1 ,LS64 ,LS64_ACCDATA ); }[Severity: Low]
Can a CPU implementFEAT_LS64_ACCDATAwithout implementingFEAT_FGTorFEAT_HCX? This question rests on an ARM64 architecture detail that could not be confirmed from the kernel source.
FEAT_LS64_ACCDATA requires ARMv8.7 or higher, while FEAT_FGT is mandatory from ARMv8.6 if EL2 is implemented, so I think this is always safe.
Arnd