From patchwork Tue Jan 24 12:34:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Gondois X-Patchwork-Id: 13113998 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B512FC25B4E for ; Tue, 24 Jan 2023 12:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=sWWibOHAg2PSdEbVP1eSJPcuXRkWSQlNCZaKNhY95Ms=; b=HGqnjVME2bXRMN BJKjryruah54Pw1hmiFo5ZWQva6ZPmizarV2SMM24ssUH7kP+Sa453y9k6bZdgwxUgUFaRyeSbFkK el+qVcUv+hIP6w2ZtIz989vwU0LakjsukjkOzJUEsblwQ7bXul+ORKqa/AttsyApNX8ujpU6Mc1ys mAAB57DI69ZCfdwzMSSh8nO49YVBpUJi3J3UMIRwunfItOpC5eXZtdvVixIntxMrPC6iJy0lu7kUA AsxxFPai+GDZEyBgB1YKzbNc9s7DstN88GAx+LlvBj9QGWcu+pdHdryA6U99MEFl8IVQL0rDn4ydZ K/WceSjCmWAaDa9dD7YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKIWA-003lOy-9T; Tue, 24 Jan 2023 12:35:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKIW7-003lNe-1g for linux-arm-kernel@lists.infradead.org; Tue, 24 Jan 2023 12:35:12 +0000 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 865B91FB; Tue, 24 Jan 2023 04:35:47 -0800 (PST) Received: from cam-smtp0.cambridge.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D97283F64C; Tue, 24 Jan 2023 04:35:03 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Dan Carpenter , kernel test robot , Catalin Marinas , Will Deacon , Greg Kroah-Hartman , "Rafael J. Wysocki" , Sudeep Holla , Palmer Dabbelt , Gavin Shan , Conor Dooley , linux-arm-kernel@lists.infradead.org Subject: [PATCH -next] cacheinfo: Correctly handle new acpi_get_cache_info() prototype Date: Tue, 24 Jan 2023 13:34:46 +0100 Message-Id: <20230124123450.321852-1-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230124_043511_175388_FCBB121B X-CRM114-Status: GOOD ( 16.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org commit bd500361a937 ("ACPI: PPTT: Update acpi_find_last_cache_level() to acpi_get_cache_info()") updates the function acpi_get_cache_info(). If CONFIG_ACPI_PPTT is not defined, acpi_get_cache_info() doesn't update its *levels and *split_levels parameters and returns 0. This can lead to a faulty behaviour. Make acpi_get_cache_info() return an error code if CONFIG_ACPI_PPTT is not defined. Initialize levels and split_levels before passing their address to acpi_get_cache_info(). Also, in init_cache_level(): - commit e75d18cecbb3 ("arm64: cacheinfo: Fix incorrect assignment of signed error value to unsigned fw_level") checks the fw_level value in init_cache_level() in case the value is negative. Remove this check as the error code is not returned through fw_level anymore. - if no PPTT is present or CONFIG_ACPI_PPTT is not defined, it is still possible to use the cache information from clidr_el1. Instead of aborting if acpi_get_cache_info() returns an error code, just continue. Reported-by: Dan Carpenter Reported-by: kernel test robot Signed-off-by: Pierre Gondois --- arch/arm64/kernel/cacheinfo.c | 5 +---- drivers/base/cacheinfo.c | 2 +- include/linux/cacheinfo.h | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c index 36c3b07cdf2d..3ba70985e3a2 100644 --- a/arch/arm64/kernel/cacheinfo.c +++ b/arch/arm64/kernel/cacheinfo.c @@ -64,12 +64,9 @@ int init_cache_level(unsigned int cpu) } else { ret = acpi_get_cache_info(cpu, &fw_level, NULL); if (ret < 0) - return ret; + fw_level = 0; } - if (fw_level < 0) - return fw_level; - if (level < fw_level) { /* * some external caches not specified in CLIDR_EL1 diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index b57fbd0d7114..f184ef7dc1d2 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -414,7 +414,7 @@ int allocate_cache_info(int cpu) int fetch_cache_info(unsigned int cpu) { struct cpu_cacheinfo *this_cpu_ci; - unsigned int levels, split_levels; + unsigned int levels = 0, split_levels = 0; int ret; if (acpi_disabled) { diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index dfef57077cd0..908e19d17f49 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -100,7 +100,7 @@ static inline int acpi_get_cache_info(unsigned int cpu, unsigned int *levels, unsigned int *split_levels) { - return 0; + return -ENOENT; } #else int acpi_get_cache_info(unsigned int cpu,