Message ID | 20230327115953.788244-3-pierre.gondois@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1463864vqo; Mon, 27 Mar 2023 05:16:00 -0700 (PDT) X-Google-Smtp-Source: AKy350ZHAe1gp310jfQWXzjpLdObLhPltZTpj4lBH1fMwe2jfIFKnVI/qyfNIEG5jjen7yK3fQ3O X-Received: by 2002:a17:906:6dd7:b0:931:c99c:480 with SMTP id j23-20020a1709066dd700b00931c99c0480mr12430065ejt.69.1679919359906; Mon, 27 Mar 2023 05:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679919359; cv=none; d=google.com; s=arc-20160816; b=Zl/qIpZTQuCjbGcAPGJR9cawqjgrQQw6z1hs93GUShxNrMzLcgXlsU/Pz7K9YSxcHJ HlMU6b1b2rxb5qZLqSLwcUrD5G2dCHf/c5pI4yVoCdldStWiCQd5e5LL7OPlOJGhpnRp ja2w9oo0z5neHw2TtHqR7Q5m5DubOW9NYvVC2IIQik75tdBsxWmoKIfj8WURNgMW88Ka xL6ZTW9hdfVNNLnBOTsh0KWKbNNDInvYySvUsNiZU/wsb3n2+7X2+rU4/bJaaI0znxda O73MZslq4C30EBPJI1np9xGnWB2ObHbm4wfV0mnkLcCZds+qz6RG9fIdskxHqEAXWCed HT+g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1gOjYydFhv6TldVDIkUCs8YEsAJFlzQd972KH4PdqKs=; b=nVnjxTp30baQJ+/Qzo4ayM5liVEm08Kg1f5UiT7tSjidbBF6y0FQ9N69x8I1mNhdpI hXfgVHtJAu+wjEmarSIkNMBbHX1nyYf/ypd3Hk+wS5KlprOocmT6q38Ujn5C65rcAPTY XPNBAWb1idI/Ss4csmF9IfZvHxkx73YXYCwVoqRVrshS4i+9ujz7sQIKPLYE2CG1z51o L7Aok0bRwKgXs1jPobEojh5vmUalCoLrUfH66WA0HXbqa4yGWA76+aLInJgDVGgcrZ/V kSZTE1d6/LOc8A0TkZs9CN9wqaI7Ezfn1ZPk3GQsdtc9vC2EaX9QUYwQEl5YYdde9fiB 01PQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id me16-20020a170906aed000b0093100c0022bsi26709957ejb.674.2023.03.27.05.15.35; Mon, 27 Mar 2023 05:15:59 -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 S232602AbjC0MAf (ORCPT <rfc822;makky5685@gmail.com> + 99 others); Mon, 27 Mar 2023 08:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232593AbjC0MAa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 27 Mar 2023 08:00:30 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 64E9B1BE2 for <linux-kernel@vger.kernel.org>; Mon, 27 Mar 2023 05:00:29 -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 559A1FEC; Mon, 27 Mar 2023 05:01:13 -0700 (PDT) Received: from pierre123.arm.com (unknown [10.57.19.133]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 72C6C3F663; Mon, 27 Mar 2023 05:00:26 -0700 (PDT) From: Pierre Gondois <pierre.gondois@arm.com> To: linux-kernel@vger.kernel.org Cc: Radu Rendec <rrendec@redhat.com>, Pierre Gondois <pierre.gondois@arm.com>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Sudeep Holla <sudeep.holla@arm.com>, Akihiko Odaki <akihiko.odaki@daynix.com>, Palmer Dabbelt <palmer@rivosinc.com>, Gavin Shan <gshan@redhat.com>, Jeremy Linton <jeremy.linton@arm.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] cacheinfo: Check cache properties are present in DT Date: Mon, 27 Mar 2023 13:59:50 +0200 Message-Id: <20230327115953.788244-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230327115953.788244-1-pierre.gondois@arm.com> References: <20230327115953.788244-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761523122454310695?= X-GMAIL-MSGID: =?utf-8?q?1761523122454310695?= |
Series |
cacheinfo: Correctly fallback to using clidr_el1's information
|
|
Commit Message
Pierre Gondois
March 27, 2023, 11:59 a.m. UTC
If a Device Tree (DT) is used, the presence of cache properties is
assumed. Not finding any is not considered. For arm64 platforms,
cache information can be fetched from the clidr_el1 register.
Checking whether cache information is available in the DT
allows to switch to using clidr_el1.
init_of_cache_level()
\-of_count_cache_leaves()
will assume there a 2 cache leaves (L1 data/instruction caches), which
can be different from clidr_el1 information.
cache_setup_of_node() tries to read cache properties in the DT.
If there are none, this is considered a success. Knowing no
information was available would allow to switch to using clidr_el1.
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
drivers/base/cacheinfo.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
Comments
On Mon, Mar 27, 2023 at 01:59:50PM +0200, Pierre Gondois wrote: > If a Device Tree (DT) is used, the presence of cache properties is > assumed. Not finding any is not considered. For arm64 platforms, > cache information can be fetched from the clidr_el1 register. > Checking whether cache information is available in the DT > allows to switch to using clidr_el1. > > init_of_cache_level() > \-of_count_cache_leaves() > will assume there a 2 cache leaves (L1 data/instruction caches), which > can be different from clidr_el1 information. > > cache_setup_of_node() tries to read cache properties in the DT. > If there are none, this is considered a success. Knowing no > information was available would allow to switch to using clidr_el1. > > Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> > +static bool of_check_cache_nodes(struct device_node *np) > +{ > + struct device_node *next; > + > + if (of_property_read_bool(np, "cache-size") || > + of_property_read_bool(np, "i-cache-size") || > + of_property_read_bool(np, "d-cache-size") || > + of_property_read_bool(np, "cache-unified")) > + return true; > + Rob's been purging use of the of_property_read family of functions recently [1], should this use of_property_present() instead? Cheers, Conor. 1 - https://lore.kernel.org/all/?q=Use+of_property_present%28%29+for+testing+DT+property+presence+f%3Arob
Hey Pierre, On Mon, Mar 27, 2023 at 01:59:50PM +0200, Pierre Gondois wrote: > If a Device Tree (DT) is used, the presence of cache properties is > assumed. Not finding any is not considered. For arm64 platforms, > cache information can be fetched from the clidr_el1 register. > Checking whether cache information is available in the DT > allows to switch to using clidr_el1. > > init_of_cache_level() > \-of_count_cache_leaves() > will assume there a 2 cache leaves (L1 data/instruction caches), which > can be different from clidr_el1 information. > > cache_setup_of_node() tries to read cache properties in the DT. > If there are none, this is considered a success. Knowing no > information was available would allow to switch to using clidr_el1. > Alex reported seeing a bunch of messages in his boot log in QEMU since -rc1 which appears to be the fault of, as far as I can tell, e0df442ee49 ("cacheinfo: Check 'cache-unified' property to count cache leaves") like: cacheinfo: Unable to detect cache hierarchy for CPU N The RISC-V QEMU virt machine doesn't define any cache properties of any sort in the dtb, and unlike the arm64 virt machine I tried (a72) doesn't have some registers that cache info is discoverable from. When we call of_count_cache_leaves() from init_of_cache_level() and there are of course no reasons to increment leaves, we hit the return 2 case you mention above, setting num_leaves to 2. As you mention, when we hit cache_setup_of_node(), levels is not going to be set to one, so we trigger the condition (this_leaf->level != 1) and, as there are no cache nodes, break out of the loop without incrementing index. Index is therefore less than 2, and thus we return -ENOENT. This is of course propagated back out to detect_cache_attributes() and triggers the "Unable to detect..." printout :( With this patch(set), the spurious error prints go away, but we are left with a "Early cacheinfo failed, ret = -22" which will need to be fixed. So I think this also needs to be: Fixes: de0df442ee49 ("cacheinfo: Check 'cache-unified' property to count cache leaves") Probably also needs a: Reported-by: Alexandre Ghiti <alexghiti@rivosinc.com> since he's found an actual, rather than theoretical, problem! Cheers, Conor. > Signed-off-by: Pierre Gondois <pierre.gondois@arm.com> > --- > drivers/base/cacheinfo.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c > index 4ca117574af1..5b0edf2d5da8 100644 > --- a/drivers/base/cacheinfo.c > +++ b/drivers/base/cacheinfo.c > @@ -78,6 +78,9 @@ bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y) > } > > #ifdef CONFIG_OF > + > +static bool of_check_cache_nodes(struct device_node *np); > + > /* OF properties to query for a given cache type */ > struct cache_type_info { > const char *size_prop; > @@ -205,6 +208,11 @@ static int cache_setup_of_node(unsigned int cpu) > return -ENOENT; > } > > + if (!of_check_cache_nodes(np)) { > + of_node_put(np); > + return -ENOENT; > + } > + > prev = np; > > while (index < cache_leaves(cpu)) { > @@ -229,6 +237,25 @@ static int cache_setup_of_node(unsigned int cpu) > return 0; > } > > +static bool of_check_cache_nodes(struct device_node *np) > +{ > + struct device_node *next; > + > + if (of_property_read_bool(np, "cache-size") || > + of_property_read_bool(np, "i-cache-size") || > + of_property_read_bool(np, "d-cache-size") || > + of_property_read_bool(np, "cache-unified")) > + return true; > + > + next = of_find_next_cache_node(np); > + if (next) { > + of_node_put(next); > + return true; > + } > + > + return false; > +} > + > static int of_count_cache_leaves(struct device_node *np) > { > unsigned int leaves = 0; > @@ -260,6 +287,9 @@ int init_of_cache_level(unsigned int cpu) > struct device_node *prev = NULL; > unsigned int levels = 0, leaves, level; > > + if (!of_check_cache_nodes(np)) > + goto err_out; > + > leaves = of_count_cache_leaves(np); > if (leaves > 0) > levels = 1; > -- > 2.25.1 >
Hello Conor, On 4/4/23 21:29, Conor Dooley wrote: > Hey Pierre, > > On Mon, Mar 27, 2023 at 01:59:50PM +0200, Pierre Gondois wrote: >> If a Device Tree (DT) is used, the presence of cache properties is >> assumed. Not finding any is not considered. For arm64 platforms, >> cache information can be fetched from the clidr_el1 register. >> Checking whether cache information is available in the DT >> allows to switch to using clidr_el1. >> >> init_of_cache_level() >> \-of_count_cache_leaves() >> will assume there a 2 cache leaves (L1 data/instruction caches), which >> can be different from clidr_el1 information. >> >> cache_setup_of_node() tries to read cache properties in the DT. >> If there are none, this is considered a success. Knowing no >> information was available would allow to switch to using clidr_el1. >> > > Alex reported seeing a bunch of messages in his boot log in QEMU since > -rc1 which appears to be the fault of, as far as I can tell, e0df442ee49 > ("cacheinfo: Check 'cache-unified' property to count cache leaves") > like: > cacheinfo: Unable to detect cache hierarchy for CPU N > > The RISC-V QEMU virt machine doesn't define any cache properties of any > sort in the dtb, and unlike the arm64 virt machine I tried (a72) doesn't > have some registers that cache info is discoverable from. > When we call of_count_cache_leaves() from init_of_cache_level() and > there are of course no reasons to increment leaves, we hit the return 2 > case you mention above, setting num_leaves to 2. > > As you mention, when we hit cache_setup_of_node(), levels is not going > to be set to one, so we trigger the condition (this_leaf->level != 1) > and, as there are no cache nodes, break out of the loop without > incrementing index. Index is therefore less than 2, and thus we return > -ENOENT. > This is of course propagated back out to detect_cache_attributes() and > triggers the "Unable to detect..." printout :( > > With this patch(set), the spurious error prints go away, but we are left > with a "Early cacheinfo failed, ret = -22" which will need to be fixed. > > So I think this also needs to be: > Fixes: de0df442ee49 ("cacheinfo: Check 'cache-unified' property to count cache leaves") > > Probably also needs a: > Reported-by: Alexandre Ghiti <alexghiti@rivosinc.com> > since he's found an actual, rather than theoretical, problem! Ok yes indeed, I will do this and the other comments you made, Regards, Pierre > > Cheers, > Conor. >
diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 4ca117574af1..5b0edf2d5da8 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -78,6 +78,9 @@ bool last_level_cache_is_shared(unsigned int cpu_x, unsigned int cpu_y) } #ifdef CONFIG_OF + +static bool of_check_cache_nodes(struct device_node *np); + /* OF properties to query for a given cache type */ struct cache_type_info { const char *size_prop; @@ -205,6 +208,11 @@ static int cache_setup_of_node(unsigned int cpu) return -ENOENT; } + if (!of_check_cache_nodes(np)) { + of_node_put(np); + return -ENOENT; + } + prev = np; while (index < cache_leaves(cpu)) { @@ -229,6 +237,25 @@ static int cache_setup_of_node(unsigned int cpu) return 0; } +static bool of_check_cache_nodes(struct device_node *np) +{ + struct device_node *next; + + if (of_property_read_bool(np, "cache-size") || + of_property_read_bool(np, "i-cache-size") || + of_property_read_bool(np, "d-cache-size") || + of_property_read_bool(np, "cache-unified")) + return true; + + next = of_find_next_cache_node(np); + if (next) { + of_node_put(next); + return true; + } + + return false; +} + static int of_count_cache_leaves(struct device_node *np) { unsigned int leaves = 0; @@ -260,6 +287,9 @@ int init_of_cache_level(unsigned int cpu) struct device_node *prev = NULL; unsigned int levels = 0, leaves, level; + if (!of_check_cache_nodes(np)) + goto err_out; + leaves = of_count_cache_leaves(np); if (leaves > 0) levels = 1;