From patchwork Mon Mar 4 10:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1907491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TpFQC5sLcz23fC for ; Mon, 4 Mar 2024 21:32:51 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rh5cg-0002Fi-Sa; Mon, 04 Mar 2024 10:32:42 +0000 Received: from mail-pj1-f41.google.com ([209.85.216.41]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rh5cW-00024f-P4 for kernel-team@lists.ubuntu.com; Mon, 04 Mar 2024 10:32:33 +0000 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-299b818d63aso3101209a91.0 for ; Mon, 04 Mar 2024 02:32:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709548350; x=1710153150; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yP4GHwXRwLtA8UwrRZbxa8QKfRwUKwQ0Y0+z88olEhY=; b=cQfkn/605xnOYxAz+SmOzY6UxMxN7zRvRU7lzKFoDhMaKYcvP76DYBE8AZ6qVkd87l eraWzRwSQ0J1qMlJmai6iOXc8UFRx9GChqeA8gE6VfltrB986SH3fy8+jnrqlfBh1g2T 5lNruTlG+ruhPcRb/EZ6R3Qqnuvo3sfwjGPjp/5bK0Bt7Vm6nc8ScXju26hOtnvcjjrI 4Gk+75kTjhN13bIGqBFlFu8lBgcojDq2g75OW7wRDjDAFVjnkeWxd7B8DQHrxFjlVdcp cSAlQP/jp1EatcYMO6DdoRFDxrihBfyjUDtb2jF3WP3kJmahaBxxdzXPSkp/jNYvkLVi 1XUg== X-Gm-Message-State: AOJu0YwL8VltwyoeI/KdOT6/ImflsE8LUVnLRH7zntT50LfszJJqtdie 6llM0R4QjYnS0AEMGRbVZ+ANgaRwhcX/xBVluT82Caiq1m1pzJOD4xeZkS/z X-Google-Smtp-Source: AGHT+IGS5SIpSMDrnm9wBdYGK4AcA0Wv2hxTNfpdVvT8ODhnEnIeMEhwH/2+QDh9WVJW2VB7Mpn8KQ== X-Received: by 2002:a17:90a:778b:b0:299:43fd:e967 with SMTP id v11-20020a17090a778b00b0029943fde967mr11848741pjk.18.1709548350289; Mon, 04 Mar 2024 02:32:30 -0800 (PST) Received: from localhost.localdomain (125-229-129-140.hinet-ip.hinet.net. [125.229.129.140]) by smtp.gmail.com with ESMTPSA id u13-20020a17090abb0d00b0029b2eccd158sm4396804pjr.48.2024.03.04.02.32.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 02:32:29 -0800 (PST) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4][Noble] UBUNTU: SAUCE: cacheinfo: Allocate memory for memory if not done from the primary CPU Date: Mon, 4 Mar 2024 18:32:04 +0800 Message-ID: <20240304103206.686842-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240304103206.686842-1-vicamo.yang@canonical.com> References: <20240304103206.686842-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.41; envelope-from=vicamo@gmail.com; helo=mail-pj1-f41.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Ricardo Neri BugLink: https://bugs.launchpad.net/bugs/2049793 Commit 5944ce092b97 ("arch_topology: Build cacheinfo from primary CPU") adds functionality that architectures can use to optionally allocate and build cacheinfo early during boot. Commit 6539cffa9495 ("cacheinfo: Add arch specific early level initializer") lets secondary CPUs correct (and reallocate memory) cacheinfo data if needed. If the early build functionality is not used and cacheinfo does not need correction, memory for cacheinfo is never allocated. x86 does not use the early build functionality. Consequently, during the cacheinfo CPU hotplug callback, last_level_cache_is_valid() attempts to dereference a NULL pointer: BUG: kernel NULL pointer dereference, address: 0000000000000100 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not present page PGD 0 P4D 0 Oops: 0000 [#1] PREEPMT SMP NOPTI CPU: 0 PID 19 Comm: cpuhp/0 Not tainted 6.4.0-rc2 #1 RIP: 0010: last_level_cache_is_valid+0x95/0xe0a Allocate memory for cacheinfo during the cacheinfo CPU hotplug callback if not done earlier. Cc: Andreas Herrmann Cc: Catalin Marinas Cc: Chen Yu Cc: Huang Ying Cc: Len Brown Cc: Radu Rendec Cc: Pierre Gondois Cc: Pu Wen Cc: "Rafael J. Wysocki" Cc: Sudeep Holla Cc: Srinivas Pandruvada Cc: Will Deacon Cc: Zhang Rui Cc: linux-arm-kernel@lists.infradead.org Cc: stable@vger.kernel.org Reviewed-by: Radu Rendec Reviewed-by: Sudeep Holla Fixes: 6539cffa9495 ("cacheinfo: Add arch specific early level initializer") Signed-off-by: Ricardo Neri (cherry-picked from https://lore.kernel.org/all/20231212222519.12834-3-ricardo.neri-calderon@linux.intel.com/raw) Signed-off-by: You-Sheng Yang --- drivers/base/cacheinfo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 967c5cf3fb1d6..735ccead190ec 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -557,7 +557,11 @@ static inline int init_level_allocate_ci(unsigned int cpu) */ ci_cacheinfo(cpu)->early_ci_levels = false; - if (cache_leaves(cpu) <= early_leaves) + /* + * Some architectures (e.g., x86) do not use early initialization. + * Allocate memory now in such case. + */ + if (cache_leaves(cpu) <= early_leaves && per_cpu_cacheinfo(cpu)) return 0; kfree(per_cpu_cacheinfo(cpu));