arm64: Support FEAT_LSFE (Large System Float Extension)
Subsystems (4)
v3 cover arm64: Support FEAT_LSFE (Large System Float Extension)
FEAT_LSFE is optional from v9.5, it adds new instructions for atomic memory operations with floating point values. We have no immediate use for it in kernel, provide a hwcap so userspace can discover it and allow the ID register field to be exposed to KVM guests.
---
Changes in v3:
- Rebase onto v6.17-rc1.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Fix result of vi dropping in hwcap test.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Mark Brown (3):
arm64/hwcap: Add hwcap for FEAT_LSFE
KVM: arm64: Expose FEAT_LSFE to guests kselftest/arm64: Add lsfe to the hwcaps test
Documentation/arch/arm64/elf_hwcaps.rst | 4 ++++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 2 ++ arch/arm64/kernel/cpuinfo.c | 1 + arch/arm64/kvm/sys_regs.c | 4 +++- tools/testing/selftests/arm64/abi/hwcap.c | 21 +++++++++++++++++++++ 7 files changed, 33 insertions(+), 1 deletion(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250625-arm64-lsfe-0810cf98adc2
Best regards,
Signature · 1 line
Mark Brown <[email protected]>
PATCH v3 1/3 arm64/hwcap: Add hwcap for FEAT_LSFE
FEAT_LSFE (Large System Float Extension), providing atomic floating point memory operations, is optional from v9.5. This feature adds no new architectural stare and we have no immediate use for it in the kernel so simply provide a hwcap for it to support discovery by userspace.
--- Documentation/arch/arm64/elf_hwcaps.rst | 4 ++++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel/cpufeature.c | 2 ++ arch/arm64/kernel/cpuinfo.c | 1 + 5 files changed, 9 insertions(+)
Documentation/arch/arm64/elf_hwcaps.rst +4 -0
@@ -441,6 +441,10 @@ HWCAP3_MTE_FAR HWCAP3_MTE_STORE_ONLY Functionality implied by ID_AA64PFR2_EL1.MTESTOREONLY == 0b0001. +HWCAP3_LSFE + Functionality implied by ID_AA64ISAR3_EL1.LSFE == 0b0001 + + 4. Unused AT_HWCAP bits -----------------------
arch/arm64/include/asm/hwcap.h +1 -0
@@ -178,6 +178,7 @@#define __khwcap3_feature (x) (const_ilog2(HWCAP3_ ## x) + 128)#define KERNEL_HWCAP_MTE_FAR __khwcap3_feature(MTE_FAR)#define KERNEL_HWCAP_MTE_STORE_ONLY __khwcap3_feature(MTE_STORE_ONLY) +#define KERNEL_HWCAP_LSFE __khwcap3_feature(LSFE)/* * This yields a mask that user programs can use to figure out what
arch/arm64/include/uapi/asm/hwcap.h +1 -0
@@ -145,5 +145,6 @@*/ #define HWCAP3_MTE_FAR (1UL << 0)#define HWCAP3_MTE_STORE_ONLY (1UL << 1) +#define HWCAP3_LSFE (1UL << 2)#endif /* _UAPI__ASM_HWCAP_H */
arch/arm64/kernel/cpufeature.c +2 -0
@@ -278,6 +278,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar2[] = {static const struct arm64_ftr_bits ftr_id_aa64isar3[] = {ARM64_FTR_BITS (FTR_VISIBLE ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64ISAR3_EL1_FPRCVT_SHIFT ,4 ,0 ), +ARM64_FTR_BITS (FTR_VISIBLE ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64ISAR3_EL1_LSFE_SHIFT ,4 ,0 ),ARM64_FTR_BITS (FTR_VISIBLE ,FTR_NONSTRICT ,FTR_LOWER_SAFE ,ID_AA64ISAR3_EL1_FAMINMAX_SHIFT ,4 ,0 ),ARM64_FTR_END , };
@@ -3252,6 +3253,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {HWCAP_CAP (ID_AA64ISAR1_EL1 ,I8MM ,IMP ,CAP_HWCAP ,KERNEL_HWCAP_I8MM ),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 ),HWCAP_CAP (ID_AA64MMFR2_EL1 ,AT ,IMP ,CAP_HWCAP ,KERNEL_HWCAP_USCAT ), #ifdef CONFIG_ARM64_SVE HWCAP_CAP(ID_AA64PFR0_EL1, SVE, IMP, CAP_HWCAP, KERNEL_HWCAP_SVE),
arch/arm64/kernel/cpuinfo.c +1 -0
@@ -162,6 +162,7 @@ static const char *const hwcap_str[] = { [KERNEL_HWCAP_SME_SMOP4] = "smesmop4", [KERNEL_HWCAP_MTE_FAR] = "mtefar", [KERNEL_HWCAP_MTE_STORE_ONLY] = "mtestoreonly", + [KERNEL_HWCAP_LSFE] = "lsfe", };#ifdef CONFIG_COMPAT
Signature · 1 line
2.39.5
PATCH v3 2/3 KVM: arm64: Expose FEAT_LSFE to guests
In reply to Mark BrownFEAT_LSFE (Large System Float Extension), providing atomic floating point memory operations, is optional from v9.5. This feature adds no new architectural state, expose the relevant ID register field to guests so they can discover it.
--- arch/arm64/kvm/sys_regs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +3 -1
@@ -1642,7 +1642,8 @@ static u64 __kvm_read_sanitised_id_reg(const struct kvm_vcpu *vcpu, val &= ~ARM64_FEATURE_MASK (ID_AA64ISAR2_EL1_WFxT);break ;case SYS_ID_AA64ISAR3_EL1 : - val &=ID_AA64ISAR3_EL1_FPRCVT |ID_AA64ISAR3_EL1_FAMINMAX ; + val &=ID_AA64ISAR3_EL1_FPRCVT |ID_AA64ISAR3_EL1_LSFE | +ID_AA64ISAR3_EL1_FAMINMAX ;break ;case SYS_ID_AA64MMFR2_EL1 : val &= ~ID_AA64MMFR2_EL1_CCIDX_MASK ;
@@ -2991,6 +2992,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_AA64ISAR2_EL1_APA3 | ID_AA64ISAR2_EL1_GPA3)),ID_WRITABLE (ID_AA64ISAR3_EL1 , (ID_AA64ISAR3_EL1_FPRCVT | +ID_AA64ISAR3_EL1_LSFE |ID_AA64ISAR3_EL1_FAMINMAX )),ID_UNALLOCATED (6 ,4 ), ID_UNALLOCATED(6,5),
Signature · 1 line
2.39.5
PATCH v3 3/3 kselftest/arm64: Add lsfe to the hwcaps test
In reply to Mark BrownThis feature has no traps associated with it so the SIGILL is not reliable.
--- tools/testing/selftests/arm64/abi/hwcap.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/testing/selftests/arm64/abi/hwcap.c +21 -0
@@ -17,6 +17,8 @@#include <asm/sigcontext.h> #include <asm/unistd.h> +#include <linux/auxvec.h> +#include "../../kselftest.h" #define TESTS_PER_HWCAP 3
@@ -169,6 +171,18 @@ static void lse128_sigill(void) : "cc", "memory"); } +static void lsfe_sigill (void ) +{ +float __attribute__ ((aligned (16 ))) mem =0 ; + register float *memp asm ("x0") = &mem; + +/* LDFADD H0, H0, [X0] */ + asmvolatile (".inst 0x7c200000" + :"+r" (memp) + : + :"cc" ,"memory" ); +} +static void lut_sigill (void ) {/* LUTI2 V0.16B, { V0.16B }, V[0] */
@@ -762,6 +776,13 @@ static const struct hwcap_data { .cpuinfo = "lse128", .sigill_fn = lse128_sigill, }, + { + .name = "LSFE", + .at_hwcap = AT_HWCAP3, + .hwcap_bit = HWCAP3_LSFE, + .cpuinfo = "lsfe", + .sigill_fn = lsfe_sigill, + }, { .name = "LUT", .at_hwcap = AT_HWCAP2,
Signature · 1 line
2.39.5
Will Deacon
maintainerRe: [PATCH v3 3/3] kselftest/arm64: Add lsfe to the hwcaps test
Quoted 22 lines · Mark Brown
This feature has no traps associated with it so the SIGILL is not reliable.
Signed-off-by Mark Brown <[email protected]>--- tools/testing/selftests/arm64/abi/hwcap.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)tools/testing/selftests/arm64/abi/hwcap.c +2
-0@@ -17,6 +17,8 @@#include <asm/sigcontext.h> #include <asm/unistd.h> +#include <linux/auxvec.h> +#include "../../kselftest.h" #define TESTS_PER_HWCAP 3@@ -169,6 +171,18 @@ static void lse128_sigill(void) : "cc", "memory");
tools/testing/selftests/arm64/abi/hwcap.c static void lse128_sigill(void) · line 181
Quoted 10 lines
tools/testing/selftests/arm64/abi/hwcap.c +8
-0} +static void lsfe_sigill (void ) +{ +float __attribute__ ((aligned (16 ))) mem =0 ; + register float *memp asm ("x0") = &mem; + +/* LDFADD H0, H0, [X0] */ + asmvolatile (".inst 0x7c200000" + : "+r" (memp)
Doesn't this corrupt H0 without the compiler knowing? It's probably easier to use STFADD.
tools/testing/selftests/arm64/abi/hwcap.c static void lse128_sigill(void) · line 183
Quoted 2 lines
tools/testing/selftests/arm64/abi/hwcap.c +2
-0+ : + : "cc", "memory");
Why do you need the "cc" clobber?
Will
Re: [PATCH v3 3/3] kselftest/arm64: Add lsfe to the hwcaps test
Quoted 8 lines · Will Deacon
tools/testing/selftests/arm64/abi/hwcap.c static void lse128_sigill(void) · line 181
Quoted 3 lines · Mark Brown
tools/testing/selftests/arm64/abi/hwcap.c +3
-0+/* LDFADD H0, H0, [X0] */ + asmvolatile (".inst 0x7c200000" + : "+r" (memp)Doesn't this corrupt H0 without the compiler knowing? It's probably easier to use STFADD.
Yeah, that's more correct and easier than specifying constraints. In practice it should be safe as the compiler is unlikely to use FP in the instructions it generates and it's a caller saved register. The program is in general not careful with constraints.
Quoted 4 lines
tools/testing/selftests/arm64/abi/hwcap.c static void lse128_sigill(void) · line 183
Quoted 2 lines
tools/testing/selftests/arm64/abi/hwcap.c +2
-0+ : + : "cc", "memory");Why do you need the "cc" clobber?
It's overkill.
Will Deacon
maintainerQuoted 6 lines · Mark Brown
FEAT_LSFEis optional from v9.5, it adds new instructions for atomic memory operations with floating point values. We have no immediate use for it in kernel, provide a hwcap so userspace can discover it and allow the ID register field to be exposed to KVM guests.
Applied first patch to arm64 (for-next/cpufeature), thanks!
[1/3] arm64/hwcap: Add hwcap for FEAT_LSFE
https://git.kernel.org/arm64/c/220928e52cb0
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev