diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2e6fa8b49752e..c9c25a07be312 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -553,11 +553,12 @@ Kernel parameters See header of arch/x86/kernel/apm_32.c. apple_keep_idle_nop - [ARM64,EARLY] On T6050 and T8142, keep idle=nop. - These cores idle in WFI by default, and an idle=nop - that the boot loader appends is ignored, because the - kernel preserves the registers WFI loses there. With - this flag idle=nop spins the idle loop as elsewhere. + [ARM64,EARLY] On Apple M4 and later cores, keep + idle=nop. These cores idle in WFI by default, and an + idle=nop that an older boot loader appends is + ignored, because the kernel preserves the registers + WFI loses there. With this flag idle=nop spins the + idle loop as elsewhere. apparmor= [APPARMOR] Disable or enable AppArmor at boot time Format: { "0" | "1" } diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index 4c69fcbd33063..8755bd99695ce 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -47,11 +47,6 @@ #size-cells = <2>; ranges; stdout-path = "serial0"; - /* - * Temporary: the secondary cores lose state in WFIT and the - * kernel does not yet stop using WFxT on T8140 by itself. - */ - bootargs = "arm64.nowfxt"; framebuffer0: framebuffer@0 { compatible = "apple,simple-framebuffer", "simple-framebuffer"; diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index 8215a3b1dac4e..9fe3c491c9607 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -296,7 +296,31 @@ static inline u32 __attribute_const__ read_cpuid_id(void) return read_cpuid(MIDR_EL1); } -/* Apple part numbers from Donan onward identify the M4 and later generations. */ +/* + * Apple part numbers from Donan onward identify the M4 and later generations. + * + * These cores can come back from WFI and WFIT with their general-purpose and + * FP/SIMD registers cleared; SP and memory survive. On M1 to M3 the boot + * loader sets the cores up to keep that state in WFI (CYC_OVRD); from M4 on + * that register is locked before the kernel runs. The kernel keeps the state + * itself on every part matched here: cpu_do_idle() saves it around WFI, and + * WFxT is recorded as absent so that nothing executes WFIT. Neither idle=nop + * nor arm64.nowfxt is needed. + * + * Seen on: + * 0x054/0x055 T6040 (M4 Pro, J616s): the boot P core in WFI. + * 0x060/0x061 T8140 (A18 Pro, J700): the secondaries in WFI and WFIT. + * 0x062/0x063 T8142 (M5, J813): WFI in the idle loop, WFIT in a cpufreq + * __delay(). + * 0x064/0x065 T6050 (M5 Pro/Max, J714s/J716s): WFI. + * 0x072/0x073 T8152 (M6, J873): WFI at the first idle; WFIT under + * schedutil gave wrong SHA-256 results. + * Not measured separately, matched as the same core generations: 0x052/0x053 + * T8132 (M4), 0x058/0x059 T6041 (M4 Max), 0x068/0x069 and 0x06c/0x06d (M5 + * Pro/Max/Ultra variants). Later parts are matched as well: where the state + * would have survived, the save costs a few stores per idle entry; where it + * does not, a missing save corrupts the idle loop. + */ static inline bool midr_is_apple_m4_or_later(u32 midr) { return MIDR_IMPLEMENTOR(midr) == ARM_CPU_IMP_APPLE && diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 6648d300302f7..288c49dfc5fd3 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2627,40 +2627,6 @@ test_has_gicv5_legacy(const struct arm64_cpu_capabilities *entry, int scope) return !!(read_sysreg_s(SYS_ICC_IDR0_EL1) & ICC_IDR0_EL1_GCIE_LEGACY); } -/* - * Apple T8152 (M6) cores clear architectural state across WFIT, the FP/SIMD - * registers included. __delay() would execute it from any context, including - * the cpufreq transition polling that load-driven governors run on a CPU - * whose current task still has live FP/SIMD state: on J873 (M6) 25-56% of - * SHA-256 runs gave wrong results under schedutil. Treat WFxT as absent - * there, as arm64.nowfxt does, so __delay() uses WFE. T8142 (M5) was not - * measured; it is included because apple_m5_needs_wait_save() groups its - * cores with T8152 for this state loss. - * - * T6050 (M5 Pro and Max, parts 0x064 and 0x065) was not measured for the WFIT - * state loss either. On the K116s, at EL1 under the boot loader's monitor, - * ID_AA64ISAR2_EL1.WFxT reads 0, so the capability is not set there today - * with or without these entries, and __delay() already avoids WFIT on these - * cores by MIDR. The entries are a precaution for a kernel started at EL2, - * where the field may read as implemented. - */ -static bool has_wfxt(const struct arm64_cpu_capabilities *entry, int scope) -{ - static const struct midr_range apple_wfxt_loses_state[] = { - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T8142_E)), - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T8142_P)), - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T6050_064)), - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T6050_065)), - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T8152_E)), - MIDR_ALL_VERSIONS(MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_T8152_P)), - {} - }; - - if (is_midr_in_range_list(apple_wfxt_loses_state)) - return false; - return has_cpuid_feature(entry, scope); -} - static const struct arm64_cpu_capabilities arm64_features[] = { #ifdef CONFIG_ARM64_USER4K_EXPERIMENTAL { @@ -3165,7 +3131,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .desc = "WFx with timeout", .capability = ARM64_HAS_WFXT, .type = ARM64_CPUCAP_SYSTEM_FEATURE, - .matches = has_wfxt, + .matches = has_cpuid_feature, ARM64_CPUID_FIELDS(ID_AA64ISAR2_EL1, WFxT, IMP) }, { @@ -3529,8 +3495,7 @@ static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { HWCAP_CAP(ID_AA64ISAR2_EL1, CSSC, CMPBR, CAP_HWCAP, KERNEL_HWCAP_CMPBR), HWCAP_CAP(ID_AA64ISAR2_EL1, RPRFM, IMP, CAP_HWCAP, KERNEL_HWCAP_RPRFM), HWCAP_CAP(ID_AA64ISAR2_EL1, RPRES, IMP, CAP_HWCAP, KERNEL_HWCAP_RPRES), - /* WFxT loses state on apple_wfxt_loses_state parts; hide the hwcap there too. */ - HWCAP_CAP_MATCH_ID(has_wfxt, ID_AA64ISAR2_EL1, WFxT, IMP, CAP_HWCAP, KERNEL_HWCAP_WFXT), + HWCAP_CAP(ID_AA64ISAR2_EL1, WFxT, IMP, CAP_HWCAP, KERNEL_HWCAP_WFXT), HWCAP_CAP(ID_AA64ISAR2_EL1, MOPS, IMP, CAP_HWCAP, KERNEL_HWCAP_MOPS), HWCAP_CAP(ID_AA64ISAR2_EL1, BC, IMP, CAP_HWCAP, KERNEL_HWCAP_HBC), #ifdef CONFIG_ARM64_SME diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index 006cec695867d..f93f4e8782dc5 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -551,9 +551,10 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info) info->reg_id_aa64isar2 = read_cpuid(ID_AA64ISAR2_EL1); /* * Timed waits bypass the register-saving idle path on Apple M4 and - * later cores. Record WFxT as absent on every CPU, so the sanitised - * register hides it from the kernel, KVM guests and userspace - * (HWCAP2_WFXT) and a boot argument cannot bring it back. + * later cores, and lose the same state there (see + * midr_is_apple_m4_or_later()). Record WFxT as absent on every CPU, + * so the sanitised register hides it from the kernel, KVM guests and + * userspace (HWCAP2_WFXT) and a boot argument cannot bring it back. */ if (IS_ENABLED(CONFIG_ARCH_APPLE) && midr_is_apple_m4_or_later(info->reg_midr)) diff --git a/arch/arm64/kernel/idle.c b/arch/arm64/kernel/idle.c index 0d76030f78205..d197776f5db8b 100644 --- a/arch/arm64/kernel/idle.c +++ b/arch/arm64/kernel/idle.c @@ -53,8 +53,9 @@ static bool apple_wfi_loses_regs __ro_after_init; static bool apple_keep_idle_nop __initdata; /* - * The boot loader appends idle=nop after the user's arguments, so it cannot - * be overridden on the command line. This flag keeps it anyway. + * Older boot loaders append idle=nop after the user's arguments on these + * cores, so it cannot be overridden on the command line, and it is ignored + * below. This flag keeps it anyway, for comparisons. */ static int __init setup_apple_keep_idle_nop(char *arg) { @@ -65,22 +66,20 @@ early_param("apple_keep_idle_nop", setup_apple_keep_idle_nop); void __init apple_wfi_quirk_init(void) { - u32 model = read_cpuid_id() & MIDR_CPU_MODEL_MASK; + if (!midr_is_apple_m4_or_later(read_cpuid_id())) + return; + + apple_wfi_loses_regs = true; + pr_info("Apple: preserving registers across WFI\n"); - if (midr_is_apple_m4_or_later(read_cpuid_id())) { - apple_wfi_loses_regs = true; - pr_info("Apple: preserving registers across WFI\n"); - } /* - * aura (J813) and m1n1 (T6050) pass idle=nop on M4 and later for - * kernels without this quirk. Spinning idle keeps every core busy - * (cpuidle's WFI states spin too): on T8142 the SoC sits near 90 C - * and throttles, on T6050 the system draws about 10 W more at idle. - * WFI is safe here. + * aura and m1n1 used to pass idle=nop on M4 and later for kernels + * without this path. Spinning idle keeps every core busy (cpuidle's + * WFI states spin too): on T8142 the SoC sits near 90 C and + * throttles, on T6050 the system draws about 10 W more at idle, on + * T8140 the die idles at 85-92 C instead of 43 C. WFI is safe here. */ - if (idle == ARM64_IDLE_NOP && !apple_keep_idle_nop && - (model == MIDR_APPLE_T8142_E || model == MIDR_APPLE_T8142_P || - model == MIDR_APPLE_T6050_064 || model == MIDR_APPLE_T6050_065)) { + if (idle == ARM64_IDLE_NOP && !apple_keep_idle_nop) { idle = ARM64_IDLE_WFI; pr_info("Apple: idling in WFI, ignoring idle=nop\n"); } diff --git a/arch/arm64/lib/delay.c b/arch/arm64/lib/delay.c index 591c255214772..e278e060e78a9 100644 --- a/arch/arm64/lib/delay.c +++ b/arch/arm64/lib/delay.c @@ -14,7 +14,6 @@ #include #include -#include #define USECS_TO_CYCLES(time_usecs) \ xloops_to_cycles((time_usecs) * 0x10C7UL) @@ -43,19 +42,6 @@ void __delay(unsigned long cycles) { cycles_t start = __delay_cycles(); - /* - * T8142 and T6050 can clear registers on WFIT just as it does on WFI. A delay - * may run with live kernel SIMD state, so the idle task's save/flush - * path is not applicable here. Keep the core awake for short delays. - */ - if (IS_ENABLED(CONFIG_ARCH_APPLE)) { - u32 midr = read_cpuid_id() & MIDR_CPU_MODEL_MASK; - - if (midr == MIDR_APPLE_T8142_E || midr == MIDR_APPLE_T8142_P || - midr == MIDR_APPLE_T6050_064 || midr == MIDR_APPLE_T6050_065) - goto counter_delay; - } - if (alternative_has_cap_unlikely(ARM64_HAS_WFXT)) { u64 end = start + cycles; @@ -74,7 +60,6 @@ void __delay(unsigned long cycles) wfe(); } -counter_delay: while ((__delay_cycles() - start) < cycles) cpu_relax(); }