From patchwork Mon Apr 3 23:15:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Rendec X-Patchwork-Id: 13198919 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 359EBC76196 for ; Mon, 3 Apr 2023 23:19:10 +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=+pzJ6H1J3QhEAQ2smipRWuX2e4FgX+PvaYkF1vFBdmI=; b=uqLpMuRC1JJu2V Mz+q8uns8LbZAVMWeGSNQNdEE8B/05iAmg+GsXsqaFMvakqIBwHuYlHNLJ0piNlh/jOh4/YkZV+OY eBH9jSJdc2tQTKOFxi2IbOvjmbY0oiYxtZZuF66ANjWrRoGh7w4b3CGczFOX13btM5VszvOk3ag0F +/svLHqHEaflIKstiifVqAXKcNj8ctf5wqZ3LDpVLcfyeJcGBs8ViHhI1AZqRZYvFBer46w2cQojN YLvhU2mv6jRG+gH+znV8kKM5v9SJ7QFdMllxbA1qGYUiTq6RenfOmdTid004A5QLNNvnSDE4mPHUL C0PGrWiNXSHyGz8COp4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pjTRI-00HA38-1C; Mon, 03 Apr 2023 23:18:16 +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 1pjTRE-00HA20-2G for linux-arm-kernel@lists.infradead.org; Mon, 03 Apr 2023 23:18:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680563888; 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=mKQAlhdwEv2W0Wg0Ync8Qe+weqVP4a18Rc/3M7do/+k=; b=IpMR6nXR1OLSdQW9oyVKPiqYLNk6CFMab5JhAle9hZIVxy/XMwwLhvNucsbuuex6EHna5b kLO6tNbjUNn5HwRUUbdaIXGtchogkg/DjMqNSREdigiJofXKs/MbnkgH1YNZQOLoQW0OIJ Gf8DaZ8F4BnXJ/BHpL5SKjuz+Wvz+DU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-425-JqpJNirMN-yMUWmq5CLKwA-1; Mon, 03 Apr 2023 19:18:07 -0400 X-MC-Unique: JqpJNirMN-yMUWmq5CLKwA-1 Received: by mail-qk1-f199.google.com with SMTP id 72-20020a37044b000000b0074694114c09so13785239qke.4 for ; Mon, 03 Apr 2023 16:18:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680563887; 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=mKQAlhdwEv2W0Wg0Ync8Qe+weqVP4a18Rc/3M7do/+k=; b=BDZXoAIdmr/l/6euKFwWYWcC3GYfr/xKWaYK1bsUieDHcmQeV5xuk4KpVW5GkcuSG+ jlllDP2iSNYyY1WRPH4w73qjWr1M8ZyMkQ2E8cxBadg1qpVOVHjUO9jFDbBXba41ggcY FS+8jBaFSn3cXg+uQ02ECPoDo/5McpytgsAtQ1/lHS51nWHc/xeYHySaoYfgxcA1GH8u dt08VAuvpOmcDWayWazyxFp6exPD26+eAJcukr9NBzJA6sT38UtbOna9cN4rMnB7uynu xIlI29n9gFaCk4fvA2qL4H0+8ViiUl9IZCeZAbW+QbrVl+1ix9Zu8c0HvSNeoU0FF//y 4ESg== X-Gm-Message-State: AAQBX9dOZtlAr4uVgdrpuAr3XBNmKKj0wLmzE0XV2B8pvsd5IA40pQU7 OT6YkVyIi8nF/InwohyL9MbvQoo/9esSUsBjVebFZ1HNiAbTdKUSms95PnelBX+icqLKbd8FoOO vwOuwUF6YfKLPVp3VnF7n3V8q74TGhrQPMcY= X-Received: by 2002:a05:6214:20c7:b0:5bd:74a7:e6f0 with SMTP id 7-20020a05621420c700b005bd74a7e6f0mr888122qve.20.1680563887170; Mon, 03 Apr 2023 16:18:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bqxjqhUc1/YgEorGYeLXst+f0hju0GvBMFx6hlrmR9Luls83e6h0eRMOfaFzBbtfvnjlckNQ== X-Received: by 2002:a05:6214:20c7:b0:5bd:74a7:e6f0 with SMTP id 7-20020a05621420c700b005bd74a7e6f0mr888095qve.20.1680563886918; Mon, 03 Apr 2023 16:18:06 -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 v6-20020ad45346000000b005e231177992sm2670207qvs.74.2023.04.03.16.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 16:18:06 -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 v2 0/2] arch_topology: Pre-allocate cacheinfo from primary CPU Date: Mon, 3 Apr 2023 19:15:49 -0400 Message-Id: <20230403231551.1090704-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-20230403_161813_096918_DBE41937 X-CRM114-Status: GOOD ( 18.33 ) 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/ 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 | 57 +++++++++++++++++++++++------------ include/linux/cacheinfo.h | 2 ++ 3 files changed, 64 insertions(+), 27 deletions(-)