From patchwork Thu Apr 6 23:39:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Rendec X-Patchwork-Id: 13204335 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 6F308C761A6 for ; Thu, 6 Apr 2023 23:41:27 +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=uZskyiF3//qTfedUl1hSidAN2e1WvqmCrk8wG1dGAEY=; b=qytVhhtE4KNUz6 nVd92gz9JRyJKLKidHO72igRnKOy+gN6WOXBH39SElvy+StebcunG9uRcZgND62rvszRkDx6gDzeg g27C+06KA4miBKK1tKfpRER0oagRZxt4wBV1ZnHL3FvOOpmZXOhBEnIPzzClvZ53azx987zkLE8Qn akMOrHYWIx0g2RwtdRM9GNyMWmeGHFRN3fL5tu5bhLtdOPDLVLFdJshVjvRqf0UFvePtkJbUcZHSp 4Wf2Ff+z5djoiVNeoUupRUPFef6ojCK+4VBneQeVst/MOu5f6JUfGpBzI62mgYVUGaJCwTC4BXauM 23NbozpqcCk5qO9htozA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkZD5-008pDX-21; Thu, 06 Apr 2023 23:40:07 +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 1pkZD1-008pCc-3A for linux-arm-kernel@lists.infradead.org; Thu, 06 Apr 2023 23:40:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680824399; 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=FyyxmsR12PIJKtju28/DIjkSeXN5QuTWPlrU2BOeH0k=; b=Xim4p6Kdtj5Fa8BSDQaVwwNrzAFv6rawYVhwuuql+a3I/v0HkGmfJbtT+8iEX0uySJ9Yks X+OHDBd/SAHGoX5AJLOdXJPkjFAAejM4O30lRAEoPZETx/TF259//9Gi/Z5SjKFJK1El3q eFuWZCzR2v+JvEp9yP09tp95kFJV/q8= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-2WrqWJ3_MXmQ4UygvTEybA-1; Thu, 06 Apr 2023 19:39:58 -0400 X-MC-Unique: 2WrqWJ3_MXmQ4UygvTEybA-1 Received: by mail-qk1-f200.google.com with SMTP id s2-20020a37a902000000b0074a28a891baso7955390qke.18 for ; Thu, 06 Apr 2023 16:39:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680824397; 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=FyyxmsR12PIJKtju28/DIjkSeXN5QuTWPlrU2BOeH0k=; b=OgIOJSrdgFHcPr0sBB2rheHh9XXxovB2CVCgfED+sROMkxroMq/oaHmh4M2ChAp1N6 +OaJbCOdRGg4fG5KNe9GNV9oS2IOM+yQkDlTia5pAVdv/JRuAjVHA7Jqmj/eiGXtnLIK 2+wR/qLvLqP7HDTwq8nwVQk1Xlisv2SjJiEmYIXz/z0HpToXG14opNhcMya0IATYBml3 XFCRNQYZgzaD+cqWlLBNOprSJ5Qwolfs7qm5BAS3UezrQfWdvTbwVvwD6qtCup7hh21v Ny9IFRiFCt4dnOu7aZNPyonUPEW4AesDaB1iLduCFntR+XBe3+F53E8jfrXsooJmXeZX 7jzQ== X-Gm-Message-State: AAQBX9dla+tKErKF+IduJ5N7HTGxiBijkEYefkKXD25GJtL09+bwzLRa TJR+z0QFuuSG0z+Mdnu6/1SnnktYy8Ft5EBnmuwDLQJI38uh7IiwWPNa1a2ciQFubvWCzMdFVhh cAn5gJH/7qkda2IxUgKoS+P+uAN+51htszoJ+A9iSiJY= X-Received: by 2002:a05:6214:c63:b0:56f:8ef:693 with SMTP id t3-20020a0562140c6300b0056f08ef0693mr1240389qvj.0.1680824397570; Thu, 06 Apr 2023 16:39:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YPYHCW537G/8xb3AdG7CIgSTiR+bz0OfW7EXjmNk068VXWNrsvEu5F6SBBnFsLqDfB0TOJUQ== X-Received: by 2002:a05:6214:c63:b0:56f:8ef:693 with SMTP id t3-20020a0562140c6300b0056f08ef0693mr1240372qvj.0.1680824397298; Thu, 06 Apr 2023 16:39:57 -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 mk21-20020a056214581500b005dd8b9345f0sm865599qvb.136.2023.04.06.16.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 16:39:56 -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 v3 0/2] arch_topology: Pre-allocate cacheinfo from primary CPU Date: Thu, 6 Apr 2023 19:39:24 -0400 Message-Id: <20230406233926.1670094-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-20230406_164004_261513_E1414E47 X-CRM114-Status: GOOD ( 20.02 ) 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 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 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 (2): cacheinfo: Add arch specific early level initializer cacheinfo: Add arm64 early level initializer implementation arch/arm64/kernel/cacheinfo.c | 32 +++++++++++---- drivers/base/cacheinfo.c | 75 +++++++++++++++++++++++++---------- include/linux/cacheinfo.h | 2 + 3 files changed, 79 insertions(+), 30 deletions(-) Reviewed-by: Pierre Gondois