Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1426148rwb; Fri, 19 Aug 2022 03:35:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Zi7IRYhFj1xzNH2xJu6aFnH09XhysqOVzTDs19Qo+EHpfGJl8/pkguvbIrSNwU6lE8Oos X-Received: by 2002:a17:90a:a406:b0:1fa:da13:549e with SMTP id y6-20020a17090aa40600b001fada13549emr4146162pjp.182.1660905350423; Fri, 19 Aug 2022 03:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660905350; cv=none; d=google.com; s=arc-20160816; b=ReOox7dDYCP41fvk5VIUUIyWNEeLXCN/PM7qduYiRLH+Lapsyuigxal2rra+L6v08r FRZ9a1P3hc3tp24+0SIkgmFLX7zFfym1phsJb8rQ0+b0n/ARX0mn1qYgJozZg0adhpTi hjuiRUsxTH6q3yCbdaLPf65wHnDBkIGq4LYGsHOP71V0JIwGHjDhz17MTy1asbTvUDeJ kuAjTHGd1ya2uACEM1yj0pWUA1pjfiAeaYRKXcUeFk0bPMtap1mo4qo62BPAT+XQ5Ck1 5k6KFwrchyJ9/uDL0tz0XBzij/X79w1VovKSt8u+JVz+ER5yD4Rn1Ux/ldzij6ew2b+z s5Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+zZe38tlyy8FcJIhvPEliOYawag+FMFWFgtIZ1ag5TQ=; b=OcsOpsW+EVF4KIHlzIAX5OSa15msa4ppXx1+hJlQgt5ykZApyJrRyoLu+yKVOtMm8k gD91C2PdnQOTsK8FEuxO6y+G29e8POmuIN6oP31XnOBo3CmjGKwtUXWr2tlVSBFSDRWY 4XVBeT18WPoIZwzpbL0a6F5Yz30smpjjlEThWTB92ZLt4dLKnhqb8in6xAPhOZTRRHgF JXeZB4nhLZVR8+Lw3zhi6nWte0hW8WDRvpPcb12QUTznv6q8zh+1YpWs/r3zBwTL86Vf 5UjsHdxKvptI+ImjAkX3XW2pLvnf1aD5Cz0qaT8rzU4fSwrxbDDvMSjvMzrTZV8mbo7x 754A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w11-20020a63160b000000b0042a3636816fsi1949595pgl.168.2022.08.19.03.35.38; Fri, 19 Aug 2022 03:35:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348249AbiHSKbG (ORCPT + 99 others); Fri, 19 Aug 2022 06:31:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346949AbiHSKbE (ORCPT ); Fri, 19 Aug 2022 06:31:04 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1687BEF9F3 for ; Fri, 19 Aug 2022 03:31:03 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7A12C1042; Fri, 19 Aug 2022 03:31:04 -0700 (PDT) Received: from e108754-lin.cambridge.arm.com (unknown [10.1.195.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DCA6F3F70D; Fri, 19 Aug 2022 03:31:01 -0700 (PDT) From: Ionela Voinescu To: Catalin Marinas , Will Deacon , James Morse Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ionela Voinescu Subject: [PATCH v3] arm64: errata: add detection for AMEVCNTR01 incrementing incorrectly Date: Fri, 19 Aug 2022 11:30:50 +0100 Message-Id: <20220819103050.24211-1-ionela.voinescu@arm.com> X-Mailer: git-send-email 2.29.2.dirty MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The AMU counter AMEVCNTR01 (constant counter) should increment at the same rate as the system counter. On affected Cortex-A510 cores, AMEVCNTR01 increments incorrectly giving a significantly higher output value. This results in inaccurate task scheduler utilization tracking and incorrect feedback on CPU frequency. Work around this problem by returning 0 when reading the affected counter in key locations that results in disabling all users of this counter from using it either for frequency invariance or as FFH reference counter. This effect is the same to firmware disabling affected counters. Details on how the two features are affected by this erratum: - AMU counters will not be used for frequency invariance for affected CPUs and CPUs in the same cpufreq policy. AMUs can still be used for frequency invariance for unaffected CPUs in the system. Although unlikely, if no alternative method can be found to support frequency invariance for affected CPUs (cpufreq based or solution based on platform counters) frequency invariance will be disabled. Please check the chapter on frequency invariance at Documentation/scheduler/sched-capacity.rst for details of its effect. - Given that FFH can be used to fetch either the core or constant counter values, restrictions are lifted regarding any of these counters returning a valid (!0) value. Therefore FFH is considered supported if there is a least one CPU that support AMUs, independent of any counters being disabled or affected by this erratum. Clarifying comments are now added to the cpc_ffh_supported(), cpu_read_constcnt() and cpu_read_corecnt() functions. The above is achieved through adding a new erratum: ARM64_ERRATUM_2457168. Signed-off-by: Ionela Voinescu Reviewed-by: Catalin Marinas Cc: Catalin Marinas Cc: Will Deacon Cc: James Morse --- Hi, This patch is based on the information in the A510 Errata Notice, version 13.0 at [1] and applies on v6.0-rc1. v2 -> v3: - v2 resent at [3] - Based on 6.0-rc1. - Added (hopefully clarifying) comments to cpc_ffh_supported(), cpu_read_constcnt() and and cpu_read_corecnt() regarding CPUs affected by errata, that have counters disabled or that don't support AMUs. I'm happy to change the wording or add more details if need be. v2 RESEND: v2 rebased on 6.0-rc1 v1 -> v2: - v1 at [2] - Move detection of erratum in cpu_errata.c - Limit checking for affected CPUs to the init phase for FIE (Frequency Invariance Engine). For FFH we'll still check for affected CPUs at each read of the constant counter, but reads happen less often (driven by sysfs reads) compared to FIE (on the tick). [1] https://developer.arm.com/documentation/SDEN2397589/1300/?lang=en [2] https://lore.kernel.org/lkml/20220607125340.13635-1-ionela.voinescu@arm.com/ [3] https://lore.kernel.org/lkml/20220817121551.21790-1-ionela.voinescu@arm.com/ Thanks, Ionela. Documentation/arm64/silicon-errata.rst | 2 ++ arch/arm64/Kconfig | 17 ++++++++++++++ arch/arm64/kernel/cpu_errata.c | 10 ++++++++ arch/arm64/kernel/cpufeature.c | 5 +++- arch/arm64/kernel/topology.c | 32 ++++++++++++++++++++++++-- arch/arm64/tools/cpucaps | 1 + 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/Documentation/arm64/silicon-errata.rst b/Documentation/arm64/silicon-errata.rst index 33b04db8408f..fda97b3fcf01 100644 --- a/Documentation/arm64/silicon-errata.rst +++ b/Documentation/arm64/silicon-errata.rst @@ -52,6 +52,8 @@ stable kernels. | Allwinner | A64/R18 | UNKNOWN1 | SUN50I_ERRATUM_UNKNOWN1 | +----------------+-----------------+-----------------+-----------------------------+ +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A510 | #2457168 | ARM64_ERRATUM_2457168 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A510 | #2064142 | ARM64_ERRATUM_2064142 | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A510 | #2038923 | ARM64_ERRATUM_2038923 | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 571cc234d0b3..9fb9fff08c94 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -917,6 +917,23 @@ config ARM64_ERRATUM_1902691 If unsure, say Y. +config ARM64_ERRATUM_2457168 + bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly" + depends on ARM64_AMU_EXTN + default y + help + This option adds the workaround for ARM Cortex-A510 erratum 2457168. + + The AMU counter AMEVCNTR01 (constant counter) should increment at the same rate + as the system counter. On affected Cortex-A510 cores AMEVCNTR01 increments + incorrectly giving a significantly higher output value. + + Work around this problem by returning 0 when reading the affected counter in + key locations that results in disabling all users of this counter. This effect + is the same to firmware disabling affected counters. + + If unsure, say Y. + config CAVIUM_ERRATUM_22375 bool "Cavium erratum 22375, 24313" default y diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 7e6289e709fc..810dd3c39882 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -654,6 +654,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = { ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A510, 0, 0, 2) }, #endif +#ifdef CONFIG_ARM64_ERRATUM_2457168 + { + .desc = "ARM erratum 2457168", + .capability = ARM64_WORKAROUND_2457168, + .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE, + + /* Cortex-A510 r0p0-r1p1 */ + CAP_MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1) + }, +#endif #ifdef CONFIG_ARM64_ERRATUM_2038923 { .desc = "ARM erratum 2038923", diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 907401e4fffb..af4de817d712 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1870,7 +1870,10 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap) pr_info("detected CPU%d: Activity Monitors Unit (AMU)\n", smp_processor_id()); cpumask_set_cpu(smp_processor_id(), &amu_cpus); - update_freq_counters_refs(); + + /* 0 reference values signal broken/disabled counters */ + if (!this_cpu_has_cap(ARM64_WORKAROUND_2457168)) + update_freq_counters_refs(); } } diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 869ffc4d4484..ad2bfc794257 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -296,12 +296,25 @@ core_initcall(init_amu_fie); static void cpu_read_corecnt(void *val) { + /* + * A value of 0 can be returned if the current CPU does not support AMUs + * or if the counter is disabled for this CPU. A return value of 0 at + * counter read is properly handled as an error case by the users of the + * counter. + */ *(u64 *)val = read_corecnt(); } static void cpu_read_constcnt(void *val) { - *(u64 *)val = read_constcnt(); + /* + * Return 0 if the current CPU is affected by erratum 2457168. A value + * of 0 is also returned if the current CPU does not support AMUs or if + * the counter is disabled. A return value of 0 at counter read is + * properly handled as an error case by the users of the counter. + */ + *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_2457168) ? + 0UL : read_constcnt(); } static inline @@ -328,7 +341,22 @@ int counters_read_on_cpu(int cpu, smp_call_func_t func, u64 *val) */ bool cpc_ffh_supported(void) { - return freq_counters_valid(get_cpu_with_amu_feat()); + int cpu = get_cpu_with_amu_feat(); + + /* + * FFH is considered supported if there is at least one present CPU that + * supports AMUs. Using FFH to read core and reference counters for CPUs + * that do not support AMUs, have counters disabled or that are affected + * by errata, will result in a return value of 0. + * + * This is done to allow any enabled and valid counters to be read + * through FFH, knowing that potentially returning 0 as counter value is + * properly handled by the users of these counters. + */ + if ((cpu >= nr_cpu_ids) || !cpumask_test_cpu(cpu, cpu_present_mask)) + return false; + + return true; } int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val) diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index 779653771507..63b2484ce6c3 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -67,6 +67,7 @@ WORKAROUND_1902691 WORKAROUND_2038923 WORKAROUND_2064142 WORKAROUND_2077057 +WORKAROUND_2457168 WORKAROUND_TRBE_OVERWRITE_FILL_MODE WORKAROUND_TSB_FLUSH_FAILURE WORKAROUND_TRBE_WRITE_OUT_OF_RANGE -- 2.25.1