Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1593226iol; Fri, 10 Jun 2022 10:31:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3flGp67Q0aR97EDlFpjDDniP11dASybXt+3NQqNsATvIc4xu60xI8ESKlxPZohdgXnEVC X-Received: by 2002:a17:90b:4cca:b0:1e8:70ed:1a4a with SMTP id nd10-20020a17090b4cca00b001e870ed1a4amr746805pjb.243.1654882283350; Fri, 10 Jun 2022 10:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654882283; cv=none; d=google.com; s=arc-20160816; b=S08OoGUQWfc1R+iSZIjHZVd3rKiU/iSStpIObS+niLmrNO5QkfJIUI/DVu1+Q/B8vD siOjr+je5m+3cD8GA3pixvuLN3du8YzMSUtr9tjAh/5hgm7MHFvBTtIhS5kDfHrgCiXh zpI3hcT3QMvSrvDOAysvAJxVmdTrhy1SxiptlEAD9SsNQWabs4ny9h7yNOu/nWxRPZRh u5VDSU2jFaQnwF6ia94cA1yBdJTWRy6fulxO5V9j3JMIT2VvDroqme4w3UJt6NiCFSpL MGI7qjqBw4fWwSTEcJqipmvADYoH8a5QNLp79UQsPc3aybUc1seyKPJbMvTCnEKXWJNZ DuOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=l6Le6Z8Oc2OqaO1XHVrMRruQmwZwkXVvQ2LuiDlRodk=; b=gaicKJf8MUP2C5gIY+Wqa21CkAkVleTzAgPCAPL/bObb676DeGVUyOni+wPnfhmfJz GB/P598/SPlgHiSS61U08D2ihxxUegL84cajAUIM1mayutW1koI/f7ttXGqvx7npZ3e1 T/APFH+nlJs9ywTdqn3GN705QL8NtQK4P9hhyWHjVmpKpB+iiD5LeMaj6LKVOKS7SUXU OvQuZDO4YT/X/SWnKITL/IRgs6LuYTT4QJQcSCCu9k80StBmD01tkL0vUro71sPBjtXR b2eFwoKUExKLRt7HLwv1Tc5bljMg//bt0vyyoYbGPueVshKg7eCbTX9/PjrSx+qZix59 SRVg== 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 b22-20020a63cf56000000b003fe0466ea39si14443503pgj.868.2022.06.10.10.31.10; Fri, 10 Jun 2022 10:31:23 -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 S1349654AbiFJQrY (ORCPT + 99 others); Fri, 10 Jun 2022 12:47:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235042AbiFJQrV (ORCPT ); Fri, 10 Jun 2022 12:47:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE2B6B7C8 for ; Fri, 10 Jun 2022 09:47:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1BCCFB83652 for ; Fri, 10 Jun 2022 16:47:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AAC1C34114; Fri, 10 Jun 2022 16:47:16 +0000 (UTC) Date: Fri, 10 Jun 2022 17:47:12 +0100 From: Catalin Marinas To: Ionela Voinescu Cc: Will Deacon , James Morse , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: errata: add detection for AMEVCNTR01 incrementing incorrectly Message-ID: References: <20220607125340.13635-1-ionela.voinescu@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220607125340.13635-1-ionela.voinescu@arm.com> X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, 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 On Tue, Jun 07, 2022 at 01:53:40PM +0100, Ionela Voinescu wrote: > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 14a8f3d93add..80e0c700cecf 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -881,11 +881,16 @@ static inline bool cpu_has_pan(void) > #ifdef CONFIG_ARM64_AMU_EXTN > /* Check whether the cpu supports the Activity Monitors Unit (AMU) */ > extern bool cpu_has_amu_feat(int cpu); > +extern bool cpu_has_broken_amu_constcnt(void); > #else > static inline bool cpu_has_amu_feat(int cpu) > { > return false; > } > +static inline bool cpu_has_broken_amu_constcnt(void) > +{ > + return false; > +} > #endif > > /* Get a cpu that supports the Activity Monitors Unit (AMU) */ > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > index 42ea2bd856c6..b9e4b2bd2c63 100644 > --- a/arch/arm64/kernel/cpufeature.c > +++ b/arch/arm64/kernel/cpufeature.c > @@ -1791,6 +1791,19 @@ int get_cpu_with_amu_feat(void) > return cpumask_any(&amu_cpus); > } > > +bool cpu_has_broken_amu_constcnt(void) > +{ > + /* List of CPUs which have broken AMEVCNTR01 (constant counter) */ > + static const struct midr_range cpus[] = { > +#ifdef CONFIG_ARM64_ERRATUM_2457168 > + MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1), > +#endif > + {}, > + }; > + > + return is_midr_in_range(read_cpuid_id(), cpus); > +} I'd rather not have this in cpufeature.c as it's not really a feature. We have some precedent with checking errata in cpufeature.c but IIRC we did that only to check whether to enable a feature or not in that file (DBM). > + > static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap) > { > if (has_cpuid_feature(cap, SCOPE_LOCAL_CPU)) { > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c > index 9ab78ad826e2..d4b0b0a40515 100644 > --- a/arch/arm64/kernel/topology.c > +++ b/arch/arm64/kernel/topology.c > @@ -127,7 +127,8 @@ int __init parse_acpi_topology(void) > > #ifdef CONFIG_ARM64_AMU_EXTN > #define read_corecnt() read_sysreg_s(SYS_AMEVCNTR0_CORE_EL0) > -#define read_constcnt() read_sysreg_s(SYS_AMEVCNTR0_CONST_EL0) > +#define read_constcnt() (cpu_has_broken_amu_constcnt() ? 0UL : \ > + read_sysreg_s(SYS_AMEVCNTR0_CONST_EL0)) How often is this called? You end up reading the cpuid, comparing the range on each call. I guess you can't use a cpucap in the arm64_errata[] array as you want a check per-CPU? Does it matter if we return 0UL on for all CPUs if one is affected? -- Catalin