From patchwork Thu Apr 13 09:14:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 82876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp899153vqo; Thu, 13 Apr 2023 02:21:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ZDFlWl/FtZuv+gHqlrJ9nTY615EYS9YIGFYOidZaIf+H4q64ezqCWfFpKBCHcrsyS9UKL9 X-Received: by 2002:aa7:d987:0:b0:4fe:1b62:4741 with SMTP id u7-20020aa7d987000000b004fe1b624741mr1965925eds.28.1681377709204; Thu, 13 Apr 2023 02:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681377709; cv=none; d=google.com; s=arc-20160816; b=cOLnRwuJTqXoDerJ2SQ+N0QBxN2ijJs+FLHy4+w0Sq4JBZFkZ8gI4LMPXoMlEhma7f YI6lkX7bd+rh6maJG4XHj17c24bXWFiQDK8LniDms2mvG8DIWD7DYZ5r753IKupb3dTW aDlwcC5z/fGoZwGVxt+NsXn5amcF0ZBHIKQais5UvRLYelZuiD8Go9uNzvzgxPqR/4H/ fX/EZ0y+kq7hW7+lbduxCQ7JsZ5lR96lyEk2R5fteaxJgDMMyWcac08tBG1Yb8xtylEj oaBvwYa5zhwTfUfFIQsXUr8qYMQnmXo0qDaLirUGmuaPhJh3egfbzTG5qwo9+iPkD1iN 1D0Q== 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=TiI5qWV66DyQ6Y1AihYu0pa5BGXncmCb2peUQxVcwyU=; b=y2Gpmo/mOUr1RnKd+aZEG5G66yWM/RXKUPegq0AlTxPkTFNlDpKbW7WCJV93rOxsbt Qm52tqXMTm8Cwr7+FIZ4wCsDQwxuk6muJbcwKLQE7BXb4d/18CF7lN/XKhFkRK7XQps0 ynRZ5HlV67kBX4uprbFkT3V0GbIKDAqnGuF0SzJRo6kflqxdDGkf7hCRDf8xj9Q4xxQ/ 5x8AyGJjwihnps3iKp/Jezb1EXtcXgf7UKAg95lBTrAi7qKtkEIqqjTDFhahbCbtgPeG l9zokhhUX8tMMKTDU4UnJW8p01889xtsh3YK7elIJFu+jRZUh5Uo3UPz5fjHJBBfFcGK bxdw== 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 m20-20020a056402051400b00504b24593ffsi1440276edv.479.2023.04.13.02.21.25; Thu, 13 Apr 2023 02:21:49 -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 S230207AbjDMJPM (ORCPT + 99 others); Thu, 13 Apr 2023 05:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbjDMJPF (ORCPT ); Thu, 13 Apr 2023 05:15:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 890477DA5 for ; Thu, 13 Apr 2023 02:15: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 B02AF13D5; Thu, 13 Apr 2023 02:15:47 -0700 (PDT) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 938C03F6C4; Thu, 13 Apr 2023 02:15:01 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Radu Rendec , Alexandre Ghiti , Conor Dooley , Will Deacon , Pierre Gondois , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Palmer Dabbelt , Gavin Shan Subject: [PATCH v3 1/4] cacheinfo: Check sib_leaf in cache_leaves_are_shared() Date: Thu, 13 Apr 2023 11:14:31 +0200 Message-Id: <20230413091436.230134-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230413091436.230134-1-pierre.gondois@arm.com> References: <20230413091436.230134-1-pierre.gondois@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763052312688205975?= X-GMAIL-MSGID: =?utf-8?q?1763052312688205975?= If there is no ACPI/DT information, it is assumed that L1 caches are private and L2 (and higher) caches are shared. A cache is 'shared' between two CPUs if it is accessible from these two CPUs. Each CPU owns a representation (i.e. has a dedicated cacheinfo struct) of the caches it has access to. cache_leaves_are_shared() tries to identify whether two representations are designating the same actual cache. In cache_leaves_are_shared(), if 'this_leaf' is a L2 cache (or higher) and 'sib_leaf' is a L1 cache, the caches are detected as shared as only this_leaf's cache level is checked. This is leads to setting sib_leaf as being shared with another CPU, which is incorrect as this is a L1 cache. Check 'sib_leaf->level'. Also update the comment as the function is called when populating 'shared_cpu_map'. Fixes: f16d1becf96f ("cacheinfo: Use cache identifiers to check if the caches are shared if available") Signed-off-by: Pierre Gondois Reviewed-by: Conor Dooley --- drivers/base/cacheinfo.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index f3903d002819..c5d2293ac2a6 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -38,11 +38,10 @@ static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf, { /* * For non DT/ACPI systems, assume unique level 1 caches, - * system-wide shared caches for all other levels. This will be used - * only if arch specific code has not populated shared_cpu_map + * system-wide shared caches for all other levels. */ if (!(IS_ENABLED(CONFIG_OF) || IS_ENABLED(CONFIG_ACPI))) - return !(this_leaf->level == 1); + return (this_leaf->level != 1) && (sib_leaf->level != 1); if ((sib_leaf->attributes & CACHE_ID) && (this_leaf->attributes & CACHE_ID)) From patchwork Thu Apr 13 09:14:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 82880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp902374vqo; Thu, 13 Apr 2023 02:29:39 -0700 (PDT) X-Google-Smtp-Source: AKy350Z4o9e7HxMgsZATgnku5fhsCKAvde/BXQj3U92x1BEAN1dCtQoan0O6JoUkXsFXfiSsGfbl X-Received: by 2002:a05:6a00:1787:b0:635:cfa6:ee61 with SMTP id s7-20020a056a00178700b00635cfa6ee61mr2782329pfg.15.1681378178929; Thu, 13 Apr 2023 02:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681378178; cv=none; d=google.com; s=arc-20160816; b=igxGaxNuLC6gbb/dGEP2mwFBWW8U0fnnn5df8mkMsq8nGcWqXYSGyFYFblfzTneto6 st+sGxMoxBx3VeoifSO5XCqfTR2uSIvjI9QwdnLSdRHO5mBCsCEl+xvW5RJAS7ISOBUm Z5fOyn3QgIA7q2DO0fh6qYcDD4o7WoVVpaV48RhlJGZEv+eCWZkyU1fDyOk724Du7MnV uUfoHXr37GSz0RZ4hui4FKIA3M2BmXefrcwaUN+1qBU9w4sljqrSx+NvMWwLtMav4SjW f9D2eB1kV2l+uxnuH0YQOIaXQfmN+NHdR9R0aY4YqMmLyQDoxhWu55JCjGu3EFaEyYS8 bJyg== 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=Z8zPpumt5O4NM0t7Fqyztud8RHCmk3s6Ym5WFUdUmOU=; b=UIJrYDvC3lXTfLjbcuAgZaQPGL/SiTHa+1Tz3wgJcMnmA/YIX1TYuB09VarTVIoCHy RrMARvkj3SRplyTibmDLjZ3RLHzOI21oCECmlDSpR+BZpIGpCDj7XEeUbvvtE6+j7hFR KMO9jV+UAxXDSEtosBWx4uqTDF+mu5ErxuXJ9PqIsCEL0IIImDkDKZPQ7MqRMhlIxxiS 6tHKoOQ89xjQFCu0+b/ZF0r6N+qQBe0PcmMp3S8oB6JSrQVrh8CWzKbTYJ2zw+Ukc47e Aq1IYTl7gflWwAMyJqj1wTFpq1NfTgM1Ngpl0/DHChNnqbxDQGcafKbAIdzBTh8/XHTM bJ4w== 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 j1-20020a632301000000b0050fae6024fcsi1703968pgj.564.2023.04.13.02.29.26; Thu, 13 Apr 2023 02:29:38 -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 S229790AbjDMJPT (ORCPT + 99 others); Thu, 13 Apr 2023 05:15:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbjDMJPL (ORCPT ); Thu, 13 Apr 2023 05:15:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D149E93F4 for ; Thu, 13 Apr 2023 02:15:06 -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 0CEF2D75; Thu, 13 Apr 2023 02:15:51 -0700 (PDT) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E46F13F6C4; Thu, 13 Apr 2023 02:15:04 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Radu Rendec , Alexandre Ghiti , Conor Dooley , Will Deacon , Pierre Gondois , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Palmer Dabbelt , Gavin Shan Subject: [PATCH v3 2/4] cacheinfo: Check cache properties are present in DT Date: Thu, 13 Apr 2023 11:14:32 +0200 Message-Id: <20230413091436.230134-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230413091436.230134-1-pierre.gondois@arm.com> References: <20230413091436.230134-1-pierre.gondois@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763052805109011945?= X-GMAIL-MSGID: =?utf-8?q?1763052805109011945?= 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. Fixes: de0df442ee49 ("cacheinfo: Check 'cache-unified' property to count cache leaves") Reported-by: Alexandre Ghiti Link: https://lore.kernel.org/all/20230404-hatred-swimmer-6fecdf33b57a@spud/ Signed-off-by: Pierre Gondois Reviewed-by: Conor Dooley Tested-by: Florian Fainelli --- drivers/base/cacheinfo.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index c5d2293ac2a6..06de9a468958 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_present(np, "cache-size") || + of_property_present(np, "i-cache-size") || + of_property_present(np, "d-cache-size") || + of_property_present(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; From patchwork Thu Apr 13 09:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 82877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp901083vqo; Thu, 13 Apr 2023 02:26:21 -0700 (PDT) X-Google-Smtp-Source: AKy350YE2FSKBETYW0RjdpKHPlSWnos9mx51xNoBnLgfIMkSk2uVKRWLwpTv/fZLBMK1IylH4Gth X-Received: by 2002:aa7:d3d6:0:b0:505:879:b54f with SMTP id o22-20020aa7d3d6000000b005050879b54fmr1787282edr.37.1681377981573; Thu, 13 Apr 2023 02:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681377981; cv=none; d=google.com; s=arc-20160816; b=o8dL1oRWRr5C5qkAoQRDmn6sIoNi9/9wunvdmlWJvqTZr/CHTL3oOKOg6rexkEBBbq 2P7wOgYlpjkdeoIsKM3Zl1fPZdt8bLT0iFhLUtGjnGgLMApQFU4K6mnaYcYCBYOd5H/T nzYXHJaJrDKtEphSmS7i5HuQAf41zUz3ET0ha+SlYa1HyCL2CzcgFLqxFnybuz9iCIVU Z9buRpElHgJ4ScaozJiEDUl88/d6y+GMrPeslUNyxuIm+6pDKb7/PEAWHRTZQMToYJHF 2kgG7oL49tjbTMk0oFWeoCE22ol7iPhr6Sk88IHsKuemTUOvEd46xWQZBv0x7qalIQ8g aoaQ== 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=vyh+Z3p5FH+60z2QrHUnhOLI+BilfGmS0e7cNQdqmks=; b=AXuiKXeuI3HnNRg87zMaeRniKrZBLbCTW6FbzaDu6NOrtO54M8c81sbaj3YdVXOuhL 75h1p18tkC7Bd7a4jSvCWy2Wwe0THjso6i1At3eBcmtPBaGDiPS1LYZcJMTjAKLOlEU8 UMx5gnq0qOLtKG310FYMmcoTuqMFPNSpMv1f82l6TgZ2yPUQPXVe57Odmp6AGrsHwSat wMMfJDKIu5UnGpkoyynKHB0wzh+I5sYUd6kR6kEC0gCOFs1CNtrTXkppTl90B9GYwlZ4 rzs2K2xdIAm7YDhwt0YEB5EmqA34/o2Rz1eOHgA/Y/hUzi2Pi5SNrsJFwe/zSbKREUj4 tDbA== 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 o11-20020a056402038b00b00504c246e84csi1441501edv.601.2023.04.13.02.25.57; Thu, 13 Apr 2023 02:26:21 -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 S229913AbjDMJP0 (ORCPT + 99 others); Thu, 13 Apr 2023 05:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjDMJPS (ORCPT ); Thu, 13 Apr 2023 05:15:18 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CC0C6199 for ; Thu, 13 Apr 2023 02:15:10 -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 8708C13D5; Thu, 13 Apr 2023 02:15:54 -0700 (PDT) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 427923F6C4; Thu, 13 Apr 2023 02:15:08 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Radu Rendec , Alexandre Ghiti , Conor Dooley , Will Deacon , Pierre Gondois , Conor Dooley , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Palmer Dabbelt , Gavin Shan Subject: [PATCH v3 3/4] arch_topology: Remove early cacheinfo error message Date: Thu, 13 Apr 2023 11:14:33 +0200 Message-Id: <20230413091436.230134-4-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230413091436.230134-1-pierre.gondois@arm.com> References: <20230413091436.230134-1-pierre.gondois@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763052598677815711?= X-GMAIL-MSGID: =?utf-8?q?1763052598677815711?= fetch_cache_info() tries to get the number of cache leaves/levels for each CPU in order to pre-allocate memory for cacheinfo struct. Allocating this memory later triggers a: 'BUG: sleeping function called from invalid context' in PREEMPT_RT kernels. If there is no cache related information available in DT or ACPI, fetch_cache_info() fails and an error message is printed: 'Early cacheinfo failed, ret = ...' Not having cache information should be a valid configuration. Remove the error message if fetch_cache_info() fails. Suggested-by: Conor Dooley Link: https://lore.kernel.org/all/20230404-hatred-swimmer-6fecdf33b57a@spud/ Signed-off-by: Pierre Gondois Reviewed-by: Conor Dooley --- drivers/base/arch_topology.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index b1c1dd38ab01..1f071eaede5b 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -843,10 +843,8 @@ void __init init_cpu_topology(void) for_each_possible_cpu(cpu) { ret = fetch_cache_info(cpu); - if (ret) { - pr_err("Early cacheinfo failed, ret = %d\n", ret); + if (ret) break; - } } } From patchwork Thu Apr 13 09:14:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 82878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp902250vqo; Thu, 13 Apr 2023 02:29:18 -0700 (PDT) X-Google-Smtp-Source: AKy350b4HRe5G/vF6F205reiUpAI6oK+x/KIcgb5GSwNvzHZ1exUzl8umNs98RJcGTXgYK2P4r6T X-Received: by 2002:a17:902:d4c9:b0:19f:3797:d8de with SMTP id o9-20020a170902d4c900b0019f3797d8demr1685626plg.9.1681378157825; Thu, 13 Apr 2023 02:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681378157; cv=none; d=google.com; s=arc-20160816; b=VjsuQ6xvo10FYkIT1tG5BWVFGozqpUf0FADDmZt6i91P8G99foqDyiNApCt61UWclX PWFvAb/PZ2H1xE8H7ZOheXKK0hQ43JYYIJBHIRJZIWqZjZy0KvfntWxncaIUuCxsvqlT Le/KiAmLJskljdAFeSdXZ9O5rQ3ct73fd78AKvuo8u/wObzcV2QVGpFgqnbWeo6lkZ66 WabX99vx+ij5mNCfZtbRhp+97uUXWe99rr2ddskYdTgrct3xbsth/8C5Q4XbepnnwRWP HVyIAvmEEDDUVFphRJamzA8owWth0oSqRQ6y+YwGx47UYLy7HnOGMQi5OVeV1/j+vjf8 besQ== 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=yfP2893IzF+qFye4yUYKzcpknUPULAMP55atpYFXb3M=; b=MQ6U0eWrIT57HwCINQUygJGkThKOKD5A0aYB+q8K+0UfeSV+yyMV63uriwAhB53EnO PpL4bW11P+AFy5NgKotfAEluL8JXo0Hu/84eV09JF+q8fVx5KaBEwL4upZBrTZFeaosK SAFvGT6G/HBFBZA6B3/UJ2sZP8lB+j66l9bFj4zEV+08wI6732WCpnU0SPg5ZbtpPBjP 12cbO95w+1M46pGRuPMpYaPrtmrHHGYhN2oNSlZbaU3Gsx0r8J997Bhfsx0GR7V+gLZh wBHApzzecLfkPvv2mNHlHHJPrtaO496QA02/g62HWYkeGIuBYQC+HBAhI3hmuiXvzbKe wh/g== 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 k24-20020a63f018000000b0051b4a1f15e4si1313395pgh.113.2023.04.13.02.29.04; Thu, 13 Apr 2023 02:29:17 -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 S229598AbjDMJPf (ORCPT + 99 others); Thu, 13 Apr 2023 05:15:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230242AbjDMJP2 (ORCPT ); Thu, 13 Apr 2023 05:15:28 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2C2B6EB7 for ; Thu, 13 Apr 2023 02:15:13 -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 E3623D75; Thu, 13 Apr 2023 02:15:57 -0700 (PDT) Received: from pierre123.nice.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C75883F6C4; Thu, 13 Apr 2023 02:15:11 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Radu Rendec , Alexandre Ghiti , Conor Dooley , Will Deacon , Pierre Gondois , Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , Palmer Dabbelt , Gavin Shan Subject: [PATCH v3 4/4] cacheinfo: Add use_arch[|_cache]_info field/function Date: Thu, 13 Apr 2023 11:14:34 +0200 Message-Id: <20230413091436.230134-5-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230413091436.230134-1-pierre.gondois@arm.com> References: <20230413091436.230134-1-pierre.gondois@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763052783234634664?= X-GMAIL-MSGID: =?utf-8?q?1763052783234634664?= The cache information can be extracted from either a Device Tree (DT), the PPTT ACPI table, or arch registers (clidr_el1 for arm64). The clidr_el1 register is used only if DT/ACPI information is not available. It does not states how caches are shared among CPUs. Add a use_arch_cache_info field/function to identify when the DT/ACPI doesn't provide cache information. Use this information to assume L1 caches are privates and L2 and higher are shared among all CPUs. Signed-off-by: Pierre Gondois --- drivers/base/cacheinfo.c | 13 ++++++++++++- include/linux/cacheinfo.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 06de9a468958..49dbb4357911 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -40,7 +40,8 @@ static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf, * For non DT/ACPI systems, assume unique level 1 caches, * system-wide shared caches for all other levels. */ - if (!(IS_ENABLED(CONFIG_OF) || IS_ENABLED(CONFIG_ACPI))) + if (!(IS_ENABLED(CONFIG_OF) || IS_ENABLED(CONFIG_ACPI)) || + this_leaf->use_arch_info) return (this_leaf->level != 1) && (sib_leaf->level != 1); if ((sib_leaf->attributes & CACHE_ID) && @@ -349,6 +350,7 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); struct cacheinfo *this_leaf, *sib_leaf; unsigned int index, sib_index; + bool use_arch_info = false; int ret = 0; if (this_cpu_ci->cpu_map_populated) @@ -361,6 +363,12 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) */ if (!last_level_cache_is_valid(cpu)) { ret = cache_setup_properties(cpu); + if (ret && use_arch_cache_info()) { + // Possibility to rely on arch specific information. + use_arch_info = true; + ret = 0; + } + if (ret) return ret; } @@ -370,6 +378,9 @@ static int cache_shared_cpu_map_setup(unsigned int cpu) this_leaf = per_cpu_cacheinfo_idx(cpu, index); + if (use_arch_info) + this_leaf->use_arch_info = true; + cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); for_each_online_cpu(i) { struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i); diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index 908e19d17f49..fed675b251a2 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -66,6 +66,7 @@ struct cacheinfo { #define CACHE_ALLOCATE_POLICY_MASK \ (CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE) #define CACHE_ID BIT(4) + bool use_arch_info; void *fw_token; bool disable_sysfs; void *priv; @@ -129,4 +130,13 @@ static inline int get_cpu_cacheinfo_id(int cpu, int level) return -1; } +static inline bool use_arch_cache_info(void) +{ +#if defined(CONFIG_ARM64) + return true; +#else + return false; +#endif +} + #endif /* _LINUX_CACHEINFO_H */