Skip to content

Commit ed61fbf

Browse files
committed
Merge branch 'bits/030-misc' into asahi-wip
2 parents 85dbf51 + ad6ef2e commit ed61fbf

37 files changed

Lines changed: 702 additions & 190 deletions

File tree

arch/arm64/Kconfig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,9 @@ endchoice
13491349

13501350
choice
13511351
prompt "Virtual address space size"
1352-
default ARM64_VA_BITS_52
1352+
default ARM64_VA_BITS_39 if ARM64_4K_PAGES
1353+
default ARM64_VA_BITS_47 if ARM64_16K_PAGES
1354+
default ARM64_VA_BITS_42 if ARM64_64K_PAGES
13531355
help
13541356
Allows choosing one of multiple possible virtual address
13551357
space sizes. The level of translation table is determined by
@@ -1376,7 +1378,7 @@ config ARM64_VA_BITS_48
13761378

13771379
config ARM64_VA_BITS_52
13781380
bool "52-bit"
1379-
depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN
1381+
depends on ARM64_64K_PAGES && (ARM64_PAN || !ARM64_SW_TTBR0_PAN)
13801382
help
13811383
Enable 52-bit virtual addressing for userspace when explicitly
13821384
requested via a hint to mmap(). The kernel will also use 52-bit
@@ -1423,11 +1425,10 @@ choice
14231425

14241426
config ARM64_PA_BITS_48
14251427
bool "48-bit"
1426-
depends on ARM64_64K_PAGES || !ARM64_VA_BITS_52
14271428

14281429
config ARM64_PA_BITS_52
1429-
bool "52-bit"
1430-
depends on ARM64_64K_PAGES || ARM64_VA_BITS_52
1430+
bool "52-bit (ARMv8.2)"
1431+
depends on ARM64_64K_PAGES
14311432
depends on ARM64_PAN || !ARM64_SW_TTBR0_PAN
14321433
help
14331434
Enable support for a 52-bit physical address space, introduced as

arch/arm64/configs/defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ CONFIG_ARCH_VEXPRESS=y
7777
CONFIG_ARCH_VISCONTI=y
7878
CONFIG_ARCH_XGENE=y
7979
CONFIG_ARCH_ZYNQMP=y
80+
CONFIG_ARM64_VA_BITS_48=y
8081
CONFIG_SCHED_MC=y
8182
CONFIG_SCHED_SMT=y
8283
CONFIG_NUMA=y

arch/arm64/include/asm/apple_m1_pmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define PMCR0_PMI_ENABLE_8_9 GENMASK(45, 44)
3838

3939
#define SYS_IMP_APL_PMCR1_EL1 sys_reg(3, 1, 15, 1, 0)
40+
#define SYS_IMP_APL_PMCR1_EL12 sys_reg(3, 1, 15, 7, 2)
4041
#define PMCR1_COUNT_A64_EL0_0_7 GENMASK(15, 8)
4142
#define PMCR1_COUNT_A64_EL1_0_7 GENMASK(23, 16)
4243
#define PMCR1_COUNT_A64_EL0_8_9 GENMASK(41, 40)

arch/arm64/include/asm/cpufeature.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -524,29 +524,6 @@ cpuid_feature_extract_unsigned_field(u64 features, int field)
524524
return cpuid_feature_extract_unsigned_field_width(features, field, 4);
525525
}
526526

527-
/*
528-
* Fields that identify the version of the Performance Monitors Extension do
529-
* not follow the standard ID scheme. See ARM DDI 0487E.a page D13-2825,
530-
* "Alternative ID scheme used for the Performance Monitors Extension version".
531-
*/
532-
static inline u64 __attribute_const__
533-
cpuid_feature_cap_perfmon_field(u64 features, int field, u64 cap)
534-
{
535-
u64 val = cpuid_feature_extract_unsigned_field(features, field);
536-
u64 mask = GENMASK_ULL(field + 3, field);
537-
538-
/* Treat IMPLEMENTATION DEFINED functionality as unimplemented */
539-
if (val == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
540-
val = 0;
541-
542-
if (val > cap) {
543-
features &= ~mask;
544-
features |= (cap << field) & mask;
545-
}
546-
547-
return features;
548-
}
549-
550527
static inline u64 arm64_ftr_mask(const struct arm64_ftr_bits *ftrp)
551528
{
552529
return (u64)GENMASK(ftrp->shift + ftrp->width - 1, ftrp->shift);
@@ -838,6 +815,11 @@ static inline bool system_supports_poe(void)
838815
alternative_has_cap_unlikely(ARM64_HAS_S1POE);
839816
}
840817

818+
static inline bool system_supports_pmuv3(void)
819+
{
820+
return cpus_have_final_cap(ARM64_HAS_PMUV3);
821+
}
822+
841823
int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt);
842824
bool try_emulate_mrs(struct pt_regs *regs, u32 isn);
843825

arch/arm64/include/asm/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113
#define PHYSMEM_END __pa(PAGE_END - 1)
114114

115-
#define MIN_THREAD_SHIFT (14 + KASAN_THREAD_SHIFT)
115+
#define MIN_THREAD_SHIFT (15 + KASAN_THREAD_SHIFT)
116116

117117
/*
118118
* VMAP'd stacks are allocated at page granularity, so we must ensure that such

arch/arm64/kernel/cpu_errata.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,43 @@ has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry,
194194
return is_midr_in_range(midr, &range) && has_dic;
195195
}
196196

197+
static const struct midr_range impdef_pmuv3_cpus[] = {
198+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_ICESTORM),
199+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_FIRESTORM),
200+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_ICESTORM_PRO),
201+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_FIRESTORM_PRO),
202+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_ICESTORM_MAX),
203+
MIDR_ALL_VERSIONS(MIDR_APPLE_M1_FIRESTORM_MAX),
204+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD),
205+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE),
206+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_PRO),
207+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_PRO),
208+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_BLIZZARD_MAX),
209+
MIDR_ALL_VERSIONS(MIDR_APPLE_M2_AVALANCHE_MAX),
210+
{},
211+
};
212+
213+
static bool has_impdef_pmuv3(const struct arm64_cpu_capabilities *entry, int scope)
214+
{
215+
u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
216+
unsigned int pmuver;
217+
218+
if (!is_kernel_in_hyp_mode())
219+
return false;
220+
221+
pmuver = cpuid_feature_extract_unsigned_field(dfr0,
222+
ID_AA64DFR0_EL1_PMUVer_SHIFT);
223+
if (pmuver != ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
224+
return false;
225+
226+
return is_midr_in_range_list(read_cpuid_id(), impdef_pmuv3_cpus);
227+
}
228+
229+
static void cpu_enable_impdef_pmuv3_traps(const struct arm64_cpu_capabilities *__unused)
230+
{
231+
sysreg_clear_set_s(SYS_HACR_EL2, 0, BIT(56));
232+
}
233+
197234
#ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
198235
static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = {
199236
#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
@@ -786,6 +823,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
786823
ERRATA_MIDR_RANGE_LIST(erratum_ac03_cpu_38_list),
787824
},
788825
#endif
826+
{
827+
.desc = "Apple IMPDEF PMUv3 Traps",
828+
.capability = ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS,
829+
.type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
830+
.matches = has_impdef_pmuv3,
831+
.cpu_enable = cpu_enable_impdef_pmuv3_traps,
832+
},
789833
{
790834
}
791835
};

arch/arm64/kernel/cpufeature.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,19 @@ static bool has_lpa2(const struct arm64_cpu_capabilities *entry, int scope)
18671867
}
18681868
#endif
18691869

1870+
static bool has_pmuv3(const struct arm64_cpu_capabilities *entry, int scope)
1871+
{
1872+
u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
1873+
unsigned int pmuver;
1874+
1875+
pmuver = cpuid_feature_extract_unsigned_field(dfr0,
1876+
ID_AA64DFR0_EL1_PMUVer_SHIFT);
1877+
if (pmuver == ID_AA64DFR0_EL1_PMUVer_IMP_DEF)
1878+
return false;
1879+
1880+
return pmuver >= ID_AA64DFR0_EL1_PMUVer_IMP;
1881+
}
1882+
18701883
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
18711884
#define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT))
18721885

@@ -2891,6 +2904,12 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
28912904
ARM64_CPUID_FIELDS(ID_AA64MMFR3_EL1, S1POE, IMP)
28922905
},
28932906
#endif
2907+
{
2908+
.desc = "PMUv3",
2909+
.capability = ARM64_HAS_PMUV3,
2910+
.type = ARM64_CPUCAP_SYSTEM_FEATURE,
2911+
.matches = has_pmuv3,
2912+
},
28942913
{},
28952914
};
28962915

arch/arm64/kernel/image-vars.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ KVM_NVHE_ALIAS(vgic_v3_cpuif_trap);
109109
KVM_NVHE_ALIAS(__start___kvm_ex_table);
110110
KVM_NVHE_ALIAS(__stop___kvm_ex_table);
111111

112-
/* PMU available static key */
113-
#ifdef CONFIG_HW_PERF_EVENTS
114-
KVM_NVHE_ALIAS(kvm_arm_pmu_available);
115-
#endif
116-
117112
/* Position-independent library routines */
118113
KVM_NVHE_ALIAS_HYP(clear_page, __pi_clear_page);
119114
KVM_NVHE_ALIAS_HYP(copy_page, __pi_copy_page);

arch/arm64/kvm/arm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
391391
r = get_num_wrps();
392392
break;
393393
case KVM_CAP_ARM_PMU_V3:
394-
r = kvm_arm_support_pmu_v3();
394+
r = kvm_supports_guest_pmuv3();
395395
break;
396396
case KVM_CAP_ARM_INJECT_SERROR_ESR:
397397
r = cpus_have_final_cap(ARM64_HAS_RAS_EXTN);
@@ -1405,7 +1405,7 @@ static unsigned long system_supported_vcpu_features(void)
14051405
if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
14061406
clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
14071407

1408-
if (!kvm_arm_support_pmu_v3())
1408+
if (!kvm_supports_guest_pmuv3())
14091409
clear_bit(KVM_ARM_VCPU_PMU_V3, &features);
14101410

14111411
if (!system_supports_sve())

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
215215
* counter, which could make a PMXEVCNTR_EL0 access UNDEF at
216216
* EL1 instead of being trapped to EL2.
217217
*/
218-
if (kvm_arm_support_pmu_v3()) {
218+
if (system_supports_pmuv3()) {
219219
struct kvm_cpu_context *hctxt;
220220

221221
write_sysreg(0, pmselr_el0);
@@ -251,7 +251,7 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
251251
write_sysreg(*host_data_ptr(host_debug_state.mdcr_el2), mdcr_el2);
252252

253253
write_sysreg(0, hstr_el2);
254-
if (kvm_arm_support_pmu_v3()) {
254+
if (system_supports_pmuv3()) {
255255
struct kvm_cpu_context *hctxt;
256256

257257
hctxt = host_data_ptr(host_ctxt);

0 commit comments

Comments
 (0)