From patchwork Wed Apr 12 18:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Rendec X-Patchwork-Id: 13209423 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 7550BC77B6F for ; Wed, 12 Apr 2023 18:59:53 +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=BzylOUM5G3cT3eEn+vVc5Dukrs/rI2yTV5F8Xk+hlmg=; b=QPJwT3mSrFZ2pP orp3bbuh1p8CSVmmXVYTTADDQwub9qD4AnB+OqqXt8TFch3QgsT3qdn7MqAEktcBx0UjV8c1rOhIL mkMGvGp53Eb08KKr8k0FbJYAuQnYstoZBa1aFqmEeaZFqaC9Vhz/XqCJON0gVD0Ohim0rlbu6mb9Z psMbZffa51woWweZtBPNwhoCBU5/Jq5y/Fp2OfSc8p5eseaEIgvSmlQQ6o7k1tmuKym+6xLTPjjjx 9CBLoW9LvQAQqKLCaNHQZ6g9dBgw05NthAbrla5ADTBKkVi/eurdndsU/0hx5d54uQKTyOff29SRh BZzQPe5/5gzLWcv4PGxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmfgK-0046q5-2g; Wed, 12 Apr 2023 18:59:00 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmfgH-0046pZ-2N for linux-arm-kernel@lists.infradead.org; Wed, 12 Apr 2023 18:58:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681325934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qwMo+EqT8g2dvdoPVGiHJ1L+SUDIHOHBg4VPzZsqxmQ=; b=VFY0GMd4A/HhYKjguxpgezQ4TLsbqXHu37KZH8I4d88zEHGEBMDlu7RnyK+JMJahrm418M eD8lveKl7GjoqqdUQ6V22DzEdqIQDFjAJcvI3wANKzko7QSzsr2rfe4fKYDs4MN79/DPYB sGb3zpR1YBKyVFzKNXIMbroSNhtJ6aI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-oNSZY7WJNUqg5R-sQM9yWw-1; Wed, 12 Apr 2023 14:58:53 -0400 X-MC-Unique: oNSZY7WJNUqg5R-sQM9yWw-1 Received: by mail-qv1-f72.google.com with SMTP id a9-20020a0ccdc9000000b005df3eac4c0bso2513372qvn.1 for ; Wed, 12 Apr 2023 11:58:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681325932; x=1683917932; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qwMo+EqT8g2dvdoPVGiHJ1L+SUDIHOHBg4VPzZsqxmQ=; b=GHT5JnxtpZKpgh/4Vut/LdT/ja7cX2izHMELvi6xpegcwlDe8AhOmy2iPMJVnwmtoI tpvuYS0b4lqCXfstrIQ+SXyWwvSnoD3CMY6Xi7K8BKSH6WY392dLQMFUAmqrWBrrU7EJ Xv1HEhLJeb0rlZ671n+UEeqCT0ejNMLrkH/WUj+91RARIT9v4moklaM679eL0jTuxgz+ 5v9YoxNCAxaoflVJqSXj/3YXN2RmycKQxaqjf+vss7p9l/XXk27OfYf2vfwnVyGfQiJV IhJorI2ci+XomlwkN76kSHokXNnrjeNAQV44gnjZMOU9j3Emi+p+FmRwx+lhE7o9gZbG Q4pw== X-Gm-Message-State: AAQBX9dvST7aKssEfvHl3LgVgUwzNoC8yGSKdPilkferggxbDFn0dDyR iTRAOW6RKjdYyQOiqvKhGNCeAByMgpsNqOjXMHMrvfuhXOHlqmDzUphwVdlBn/fpD8cDI7aPJWU CYuiaadUwdvJWjb6rx0X6t920Qu6B6JiL8NnB1Ed7xfE= X-Received: by 2002:a05:622a:1b8a:b0:3e6:71d6:5d5d with SMTP id bp10-20020a05622a1b8a00b003e671d65d5dmr3896733qtb.1.1681325932000; Wed, 12 Apr 2023 11:58:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Z3cv2wOUfSZ1yI11PC5cSu4o0dzjNOu9d3CB64tN0AWQDQpLV+D6zaZ5oJqshR1h2l3M45cw== X-Received: by 2002:a05:622a:1b8a:b0:3e6:71d6:5d5d with SMTP id bp10-20020a05622a1b8a00b003e671d65d5dmr3896719qtb.1.1681325931749; Wed, 12 Apr 2023 11:58:51 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id k21-20020ac86055000000b003d3a34d2eb2sm4417558qtm.41.2023.04.12.11.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 11:58:51 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Pierre Gondois , Sudeep Holla , linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 0/3] arch_topology: Pre-allocate cacheinfo from primary CPU Date: Wed, 12 Apr 2023 14:57:56 -0400 Message-Id: <20230412185759.755408-1-rrendec@redhat.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230412_115857_872610_54E63B62 X-CRM114-Status: GOOD ( 23.17 ) 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 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU") tries to build the cacheinfo from the primary CPU prior to secondary CPUs boot, if the DT/ACPI description contains cache information. However, if such information is not present, it still reverts to the old behavior, which allocates the cacheinfo memory on each secondary CPU. On RT kernels, this triggers a "BUG: sleeping function called from invalid context" because the allocation is done before preemption is first enabled on the secondary CPU. The solution is to add cache information to DT/ACPI, but at least on arm64 systems this can be avoided by leveraging automatic detection (through the CLIDR_EL1 register), which is already implemented but currently doesn't work on RT kernels for the reason described above. This patch series attempts to enable automatic detection for RT kernels when no DT/ACPI cache information is available, by pre-allocating cacheinfo memory on the primary CPU. The first patch adds an architecture independent infrastructure that allows architecture specific code to take an early guess at the number of cache leaves of the secodary CPUs, while it runs in preemptible context on the primary CPU. At the same time, it gives architecture specific code the opportunity to go back later, while it runs on the secondary CPU, and reallocate the cacheinfo memory if the initial guess proves to be wrong. The second patch leverages the infrastructure implemented in the first patch and enables early cache depth detection for arm64. The third patch addresses a specific issue on ACPI systems with no PPTT. This issue came up during review/testing of v3. The patch series is based on an RFC patch that was posted to the linux-arm-kernel mailing list and discussed with a smaller audience: https://lore.kernel.org/all/20230323224242.31142-1-rrendec@redhat.com/ Changes to v3: * Rebase on top of v6.3-rc6 to avoid a (trivial) merge conflict. * Add patch #3 (brief description included above). * Add "Reviewed-by: Pierre Gondois" tag to all patches. * Rename the new field that is added to struct cpu_cacheinfo from early_arch_info to early_ci_levels to better reflect what it does. * Use local variables in the new detect_cache_level() function. That way the code is easier to read and the original level/leaves algorithm is unchanged, which also makes the patch clearer. Changes to v2: * Address minor coding style issue (unbalanced braces). * Move cacheinfo reallocation logic from detect_cache_attributes() to a new function to improve code readability. * Minor fix to cacheinfo reallocation logic to avoid a new detection of the cache level if/when detect_cache_attributes() is called again. Radu Rendec (3): cacheinfo: Add arch specific early level initializer cacheinfo: Add arm64 early level initializer implementation cacheinfo: Allow early level detection when DT/ACPI info is missing/broken arch/arm64/kernel/cacheinfo.c | 25 ++++++++++-- drivers/base/arch_topology.c | 4 +- drivers/base/cacheinfo.c | 75 +++++++++++++++++++++++++---------- include/linux/cacheinfo.h | 2 + 4 files changed, 79 insertions(+), 27 deletions(-)