Skip to content

Commit 9286773

Browse files
committed
Merge branch 'for-next/cpufeature' into for-next/core
* for-next/cpufeature: arm64/hwcap: Support FEAT_EBF16 arm64/cpufeature: Store elf_hwcaps as a bitmap rather than unsigned long arm64/hwcap: Document allocation of upper bits of AT_HWCAP arm64: trap implementation defined functionality in userspace
2 parents e8da08f + a6a468f commit 9286773

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

Documentation/arm64/elf_hwcaps.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ HWCAP2_WFXT
301301

302302
Functionality implied by ID_AA64ISAR2_EL1.WFXT == 0b0010.
303303

304+
HWCAP2_EBF16
305+
306+
Functionality implied by ID_AA64ISAR1_EL1.BF16 == 0b0010.
307+
304308
4. Unused AT_HWCAP bits
305309
-----------------------
306310

arch/arm64/include/asm/cpufeature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <asm/hwcap.h>
1212
#include <asm/sysreg.h>
1313

14-
#define MAX_CPU_FEATURES 64
14+
#define MAX_CPU_FEATURES 128
1515
#define cpu_feature(x) KERNEL_HWCAP_ ## x
1616

1717
#ifndef __ASSEMBLY__

arch/arm64/include/asm/hwcap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#define KERNEL_HWCAP_PACA __khwcap_feature(PACA)
8686
#define KERNEL_HWCAP_PACG __khwcap_feature(PACG)
8787

88-
#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 32)
88+
#define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 64)
8989
#define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP)
9090
#define KERNEL_HWCAP_SVE2 __khwcap2_feature(SVE2)
9191
#define KERNEL_HWCAP_SVEAES __khwcap2_feature(SVEAES)
@@ -118,6 +118,7 @@
118118
#define KERNEL_HWCAP_SME_F32F32 __khwcap2_feature(SME_F32F32)
119119
#define KERNEL_HWCAP_SME_FA64 __khwcap2_feature(SME_FA64)
120120
#define KERNEL_HWCAP_WFXT __khwcap2_feature(WFXT)
121+
#define KERNEL_HWCAP_EBF16 __khwcap2_feature(EBF16)
121122

122123
/*
123124
* This yields a mask that user programs can use to figure out what

arch/arm64/include/asm/sysreg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@
788788

789789
/* id_aa64mmfr1 */
790790
#define ID_AA64MMFR1_ECBHB_SHIFT 60
791+
#define ID_AA64MMFR1_TIDCP1_SHIFT 52
791792
#define ID_AA64MMFR1_HCX_SHIFT 40
792793
#define ID_AA64MMFR1_AFP_SHIFT 44
793794
#define ID_AA64MMFR1_ETS_SHIFT 36
@@ -804,6 +805,9 @@
804805
#define ID_AA64MMFR1_VMIDBITS_8 0
805806
#define ID_AA64MMFR1_VMIDBITS_16 2
806807

808+
#define ID_AA64MMFR1_TIDCP1_NI 0
809+
#define ID_AA64MMFR1_TIDCP1_IMP 1
810+
807811
/* id_aa64mmfr2 */
808812
#define ID_AA64MMFR2_E0PD_SHIFT 60
809813
#define ID_AA64MMFR2_EVT_SHIFT 56

arch/arm64/include/uapi/asm/hwcap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
/*
2121
* HWCAP flags - for AT_HWCAP
22+
*
23+
* Bits 62 and 63 are reserved for use by libc.
24+
* Bits 32-61 are unallocated for potential use by libc.
2225
*/
2326
#define HWCAP_FP (1 << 0)
2427
#define HWCAP_ASIMD (1 << 1)
@@ -88,5 +91,6 @@
8891
#define HWCAP2_SME_F32F32 (1 << 29)
8992
#define HWCAP2_SME_FA64 (1 << 30)
9093
#define HWCAP2_WFXT (1UL << 31)
94+
#define HWCAP2_EBF16 (1UL << 32)
9195

9296
#endif /* _UAPI__ASM_HWCAP_H */

arch/arm64/kernel/cpufeature.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
#include <asm/virt.h>
9393

9494
/* Kernel representation of AT_HWCAP and AT_HWCAP2 */
95-
static unsigned long elf_hwcap __read_mostly;
95+
static DECLARE_BITMAP(elf_hwcap, MAX_CPU_FEATURES) __read_mostly;
9696

9797
#ifdef CONFIG_COMPAT
9898
#define COMPAT_ELF_HWCAP_DEFAULT \
@@ -362,6 +362,7 @@ static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = {
362362
};
363363

364364
static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = {
365+
ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_TIDCP1_SHIFT, 4, 0),
365366
ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_AFP_SHIFT, 4, 0),
366367
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_ETS_SHIFT, 4, 0),
367368
ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_TWED_SHIFT, 4, 0),
@@ -2035,6 +2036,11 @@ static bool is_kvm_protected_mode(const struct arm64_cpu_capabilities *entry, in
20352036
}
20362037
#endif /* CONFIG_KVM */
20372038

2039+
static void cpu_trap_el0_impdef(const struct arm64_cpu_capabilities *__unused)
2040+
{
2041+
sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_TIDCP);
2042+
}
2043+
20382044
/* Internal helper functions to match cpu capability type */
20392045
static bool
20402046
cpucap_late_cpu_optional(const struct arm64_cpu_capabilities *cap)
@@ -2578,6 +2584,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
25782584
.matches = has_cpuid_feature,
25792585
.min_field_value = ID_AA64ISAR2_EL1_WFxT_IMP,
25802586
},
2587+
{
2588+
.desc = "Trap EL0 IMPLEMENTATION DEFINED functionality",
2589+
.capability = ARM64_HAS_TIDCP1,
2590+
.type = ARM64_CPUCAP_SYSTEM_FEATURE,
2591+
.sys_reg = SYS_ID_AA64MMFR1_EL1,
2592+
.sign = FTR_UNSIGNED,
2593+
.field_pos = ID_AA64MMFR1_TIDCP1_SHIFT,
2594+
.field_width = 4,
2595+
.min_field_value = ID_AA64MMFR1_TIDCP1_IMP,
2596+
.matches = has_cpuid_feature,
2597+
.cpu_enable = cpu_trap_el0_impdef,
2598+
},
25812599
{},
25822600
};
25832601

@@ -2680,6 +2698,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
26802698
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_FRINTTS_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FRINT),
26812699
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_SB_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SB),
26822700
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_BF16_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_BF16),
2701+
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_BF16_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_EBF16),
26832702
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_DGH_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DGH),
26842703
HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_I8MM_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_I8MM),
26852704
HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT),
@@ -3155,14 +3174,12 @@ static bool __maybe_unused __system_matches_cap(unsigned int n)
31553174

31563175
void cpu_set_feature(unsigned int num)
31573176
{
3158-
WARN_ON(num >= MAX_CPU_FEATURES);
3159-
elf_hwcap |= BIT(num);
3177+
set_bit(num, elf_hwcap);
31603178
}
31613179

31623180
bool cpu_have_feature(unsigned int num)
31633181
{
3164-
WARN_ON(num >= MAX_CPU_FEATURES);
3165-
return elf_hwcap & BIT(num);
3182+
return test_bit(num, elf_hwcap);
31663183
}
31673184
EXPORT_SYMBOL_GPL(cpu_have_feature);
31683185

@@ -3173,12 +3190,12 @@ unsigned long cpu_get_elf_hwcap(void)
31733190
* note that for userspace compatibility we guarantee that bits 62
31743191
* and 63 will always be returned as 0.
31753192
*/
3176-
return lower_32_bits(elf_hwcap);
3193+
return elf_hwcap[0];
31773194
}
31783195

31793196
unsigned long cpu_get_elf_hwcap2(void)
31803197
{
3181-
return upper_32_bits(elf_hwcap);
3198+
return elf_hwcap[1];
31823199
}
31833200

31843201
static void __init setup_system_capabilities(void)

arch/arm64/kernel/cpuinfo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static const char *const hwcap_str[] = {
114114
[KERNEL_HWCAP_SME_F32F32] = "smef32f32",
115115
[KERNEL_HWCAP_SME_FA64] = "smefa64",
116116
[KERNEL_HWCAP_WFXT] = "wfxt",
117+
[KERNEL_HWCAP_EBF16] = "ebf16",
117118
};
118119

119120
#ifdef CONFIG_COMPAT

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ HAS_RNG
3636
HAS_SB
3737
HAS_STAGE2_FWB
3838
HAS_SYSREG_GIC_CPUIF
39+
HAS_TIDCP1
3940
HAS_TLB_RANGE
4041
HAS_VIRT_HOST_EXTN
4142
HAS_WFXT

0 commit comments

Comments
 (0)