From patchwork Tue May 30 22:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13261195 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 7E655C77B7A for ; Tue, 30 May 2023 22:53:28 +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-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=a4fAcGcc9rxszuj8KoEFaMrtxLSueNMSXChjlhDq7hY=; b=vHocqYMht+q3Iyn3FkQnsK8G+m PDiB176+2VfXOT6E6AxQ2EPi88hp7n3NEDKLbQ9sc4MefS9GIgwSQHDUkymCo5nVRJCv952olVPDU BhszoY8CQfuVZBTFsl00uUtcshg+ge9WRPpM5xyksAc5tsMb/9gO93sl77yzLcKMoPo/0o1MQx5Qb hokrvj2kp4+kmDOt2fsPNZQ35C/63w4rrV3o8Y1JXyNQpfmh+XE03nBeYM4zMdqPBHRLh1K/aOjZx Y+W1swbJ+//KxtpLUTEJ1b6NAN2iCwqRPTXH25tsqPe9qZUqn41D5WZlxf9xSMtueWnZFx2J5PC3P 7gao4KrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q48D5-00FO3f-0y; Tue, 30 May 2023 22:52:59 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q48Co-00FNyH-2M for linux-arm-kernel@lists.infradead.org; Tue, 30 May 2023 22:52:44 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1b0424c5137so23805325ad.1 for ; Tue, 30 May 2023 15:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1685487160; x=1688079160; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=uXcF3cni6Xjkhuc++Zhz5mAkaCV4mmcTZJXW/M4AE6c=; b=bIhDw1HoW26jYGF66W87kLVJ0LQxQqHE84qO//SisW6e0hudkZKOklF1bKSeJKxFci BmVbImVIkPAtAkpnR2hgUaH3BuJk3y9nn/iWR1m+Y3414HQ9UzzoNge1ZfK/Ln033SQa oOo8CqQQztcJtc+WLSUCKIJD+y5rUWoabkhkw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685487160; x=1688079160; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uXcF3cni6Xjkhuc++Zhz5mAkaCV4mmcTZJXW/M4AE6c=; b=ke5dYcj6ClTk1qfDqhngRrO6naN2+DXYwcsyygabuTBKZwEdhIwuS+XV1pqCpwFfwL hLJnhhF1YuZe1OrZsulzPy8ztnQdeWZFA0bSG8cIBEf0cRpikOb0ErZChRMV9xZIXxMr lexePrg+ljva4ie0hCMY+UvHmYg4KYFgt2z8XvuiP/0DNuvhk3ct/D5oZAnWUQ9bvmKt GLLjKV1Z1t5iwqBKbvjrEJgIEElMhKCA+ug6a0tOWsTE/SBAHa1LlzmKGaPR9J3STui2 HoRBhyKQClSV9nzqdg6KkWzcrcbx/LTjYhndeAK2ltv93PFhGuUGGNdlnhaoWg8nk4xS 8upg== X-Gm-Message-State: AC+VfDxa4KAWW3ibXUcUL3ruvnNvpyEht31lqv7e6H2cTCWgac9ZU7ra WEvy8Hm0z1Nt8aOTnLfabXa0Zw== X-Google-Smtp-Source: ACHHUZ7yJRuL9xFFKSz/yN+4OYBaYez0aEkoWfkN6me4233VKKMjoRkyoStMmPoTORo0ffgK3lzitg== X-Received: by 2002:a17:902:e80b:b0:1b0:3cda:635b with SMTP id u11-20020a170902e80b00b001b03cda635bmr4407603plg.0.1685487159780; Tue, 30 May 2023 15:52:39 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id s3-20020a170902b18300b001a1b66af22fsm10805011plr.62.2023.05.30.15.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 15:52:39 -0700 (PDT) From: Florian Fainelli To: stable@vger.kernel.org Cc: Radu Rendec , Pierre Gondois , Sudeep Holla , Florian Fainelli , Catalin Marinas , Will Deacon , Greg Kroah-Hartman , "Rafael J. Wysocki" , Akihiko Odaki , Palmer Dabbelt , Gavin Shan , Jeremy Linton , linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH stable 6.3 3/4] cacheinfo: Add arm64 early level initializer implementation Date: Tue, 30 May 2023 15:49:13 -0700 Message-Id: <20230530224914.1251409-4-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530224914.1251409-1-florian.fainelli@broadcom.com> References: <20230530224914.1251409-1-florian.fainelli@broadcom.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230530_155242_771913_247A2FAB X-CRM114-Status: GOOD ( 22.29 ) 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 From: Radu Rendec commit c931680cfa958c8fe9ace31a1dbeefff75597d54 upstream This patch adds an architecture specific early cache level detection handler for arm64. This is basically the CLIDR_EL1 based detection that was previously done (only) in init_cache_level(). This is part of a patch series that attempts to further the work in commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU"). Previously, in the absence of any DT/ACPI cache info, architecture specific cache detection and info allocation for secondary CPUs would happen in non-preemptible context during early CPU initialization and trigger a "BUG: sleeping function called from invalid context" splat on an RT kernel. This patch does not solve the problem completely for RT kernels. It relies on the assumption that on most systems, the CPUs are symmetrical and therefore have the same number of cache leaves. The cacheinfo memory is allocated early (on the primary CPU), relying on the new handler. If later (when CLIDR_EL1 based detection runs again on the secondary CPU) the initial assumption proves to be wrong and the CPU has in fact more leaves, the cacheinfo memory is reallocated, and that still triggers a splat on an RT kernel. In other words, asymmetrical CPU systems *must* still provide cacheinfo data in DT/ACPI to avoid the splat on RT kernels (unless secondary CPUs happen to have less leaves than the primary CPU). But symmetrical CPU systems (the majority) can now get away without the additional DT/ACPI data and rely on CLIDR_EL1 based detection. Signed-off-by: Radu Rendec Reviewed-by: Pierre Gondois Link: https://lore.kernel.org/r/20230412185759.755408-3-rrendec@redhat.com Signed-off-by: Sudeep Holla Signed-off-by: Florian Fainelli --- arch/arm64/kernel/cacheinfo.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c index c307f69e9b55..d9c9218fa1fd 100644 --- a/arch/arm64/kernel/cacheinfo.c +++ b/arch/arm64/kernel/cacheinfo.c @@ -38,11 +38,9 @@ static void ci_leaf_init(struct cacheinfo *this_leaf, this_leaf->type = type; } -int init_cache_level(unsigned int cpu) +static void detect_cache_level(unsigned int *level_p, unsigned int *leaves_p) { unsigned int ctype, level, leaves; - int fw_level, ret; - struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); for (level = 1, leaves = 0; level <= MAX_CACHE_LEVEL; level++) { ctype = get_cache_type(level); @@ -54,6 +52,27 @@ int init_cache_level(unsigned int cpu) leaves += (ctype == CACHE_TYPE_SEPARATE) ? 2 : 1; } + *level_p = level; + *leaves_p = leaves; +} + +int early_cache_level(unsigned int cpu) +{ + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + + detect_cache_level(&this_cpu_ci->num_levels, &this_cpu_ci->num_leaves); + + return 0; +} + +int init_cache_level(unsigned int cpu) +{ + unsigned int level, leaves; + int fw_level, ret; + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); + + detect_cache_level(&level, &leaves); + if (acpi_disabled) { fw_level = of_find_last_cache_level(cpu); } else {