From patchwork Mon Mar 4 10:32:03 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: 1907490 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 4TpFQ92dpkz23fC for ; Mon, 4 Mar 2024 21:32:49 +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 1rh5cd-0002EK-C8; Mon, 04 Mar 2024 10:32:39 +0000 Received: from mail-pf1-f175.google.com ([209.85.210.175]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rh5cV-00024W-F6 for kernel-team@lists.ubuntu.com; Mon, 04 Mar 2024 10:32:31 +0000 Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e56da425b5so3022583b3a.0 for ; Mon, 04 Mar 2024 02:32:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709548349; x=1710153149; 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=WfCq8xGc7cd14PEV7TFdWveXRZk2JaN9kacWDQXR62M=; b=XNtk5uEieY6HTIJ5T7omhABv/aMOVNwUEuwMV2gIcxEsMoeJcZ7P7Mmwx2tlgpiOAD rdLdijQm4FoE3QvyLYFNkVOkx72JSPlVrcZ5PE7y0M6CutC31ETXTz0NO8G0cxkb12vu E//43kCaBou+nDpIh7l01BmlLm6OS4qePBYA4xKpGfLhzOm4bVLUpJ1wWp+Nbgnmdf7Z A6MF+WvF01OxTd+p5KUiEy0u5M7XlOxsaSMIHeipRP0j7Ubor3tng51g5JzGqAlobDqR 3XBLt4rz7gOrP9v+5kW4eWryZQsJbchflZGxXgBh857fwVJraBY4B4KGRUGJc8AFF+Go GBmA== X-Gm-Message-State: AOJu0YzBDwdNq9R/18d4yexrKwjhWTNeGWNV3Yaj0jJeI0nv7+3hSbo2 NN+0VPAaAmgunp8s+R6Yx/YJYDsT9VIImjin3xCH8RIOjgDVP1jHNSbWQkY3 X-Google-Smtp-Source: AGHT+IEc1+WHpTSdjobFQxQEup04g+CCfh0lFE+oUAU201CmguQqQZeyalwqMBiuNpzEyDWo3habCQ== X-Received: by 2002:a05:6a20:7f8d:b0:1a1:fe8:b252 with SMTP id d13-20020a056a207f8d00b001a10fe8b252mr330907pzj.34.1709548348791; Mon, 04 Mar 2024 02:32:28 -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.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 02:32:28 -0800 (PST) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4][Noble] UBUNTU: SAUCE: cacheinfo: Check for null last-level cache info Date: Mon, 4 Mar 2024 18:32:03 +0800 Message-ID: <20240304103206.686842-2-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.210.175; envelope-from=vicamo@gmail.com; helo=mail-pf1-f175.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 Before determining the validity of the last-level cache info, ensure that it has been allocated. Simply checking for non-zero cache_leaves() is not sufficient, as some architectures (e.g., Intel processors) have non-zero cache_leaves() before allocation. Dereferencing NULL cacheinfo can occur in update_per_cpu_data_slice_size(). This function iterates over all online CPUs. However, a CPU may have come online recently, but its cacheinfo may not have been allocated yet. 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 Signed-off-by: Ricardo Neri (cherry-picked from https://lore.kernel.org/all/20231212222519.12834-2-ricardo.neri-calderon@linux.intel.com/raw) Signed-off-by: You-Sheng Yang --- drivers/base/cacheinfo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index f1e79263fe61e..967c5cf3fb1d6 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -61,6 +61,9 @@ bool last_level_cache_is_valid(unsigned int cpu) if (!cache_leaves(cpu)) return false; + if (!per_cpu_cacheinfo(cpu)) + return false; + llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); return (llc->attributes & CACHE_ID) || !!llc->fw_token; 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)); From patchwork Mon Mar 4 10:32:05 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: 1907492 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 4TpFQJ3H2Vz23fC for ; Mon, 4 Mar 2024 21:32:56 +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 1rh5cm-0002Iy-7E; Mon, 04 Mar 2024 10:32:48 +0000 Received: from mail-pf1-f174.google.com ([209.85.210.174]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rh5cY-00025u-6Z for kernel-team@lists.ubuntu.com; Mon, 04 Mar 2024 10:32:34 +0000 Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6da9c834646so3875494b3a.3 for ; Mon, 04 Mar 2024 02:32:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709548352; x=1710153152; 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=KDaREzLjsXDx6Pae2z961fu7Z/lKY0n+rF1ott7hicE=; b=itaP0wr1g0kj4ko7MovJeW5eIKwF7FYxC2/ptYBDfsGTJoUspqo85xXQ21LE3+ejqR SrHp8awl9sJc/LLEWznCY9EmaoOmrUgUP72ufNkaJe+kaAFjjHv3o/JE13x/02LsQucQ gcfYl4gLWhRJ5ShTfM99pBMdmKPxWga1QbkuMJyYEc1RCR9v97wgl1+aFLmaqLZqCcMH sHLXSSxsO8eiMF7lyPWX7joehtjMX24ln1yJkx046nwE1B4fQ4OSLkdlzk4SIdsAzOMh zOsTz5KRKNyCbacWlfIEfIJ0WpqL/kJ0Qz8RMoEhIokpyR1lRMRW8l8yGJjuoT0D3x2a cLsQ== X-Gm-Message-State: AOJu0YwRNa6o8+C/0Y2zYOuClPqk5d/jz8cHmsKyJ2os5xIRZFBwo3rL acgq8sgbSZhDdQ/qCGs/kjXvw2Rr7OdlkYzEqMjQ2w0Q6x2KCjWeUgpJLymO X-Google-Smtp-Source: AGHT+IG/z65V3rSy/InuVTRkeZz7qyohcQDsghVvirzYU97XGAZ+3EFT6fVlkOVGABi0ziaq7d8nWA== X-Received: by 2002:a05:6a20:729f:b0:1a1:4e34:2bcf with SMTP id o31-20020a056a20729f00b001a14e342bcfmr5043881pzk.25.1709548351731; Mon, 04 Mar 2024 02:32:31 -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.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 02:32:31 -0800 (PST) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4][Noble] UBUNTU: SAUCE: x86/cacheinfo: Delete global num_cache_leaves Date: Mon, 4 Mar 2024 18:32:05 +0800 Message-ID: <20240304103206.686842-4-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.210.174; envelope-from=vicamo@gmail.com; helo=mail-pf1-f174.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 Linux remembers cpu_cachinfo::num_leaves per CPU, but x86 initializes all CPUs from the same global "num_cache_leaves". This is erroneous on systems such as Meteor Lake, where each CPU has a distinct num_leaves value. Delete the global "num_cache_leaves" and initialize num_leaves on each CPU. 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: Len Brown Signed-off-by: Ricardo Neri (cherry-picked from https://lore.kernel.org/all/20231212222519.12834-4-ricardo.neri-calderon@linux.intel.com/raw) Signed-off-by: You-Sheng Yang --- arch/x86/kernel/cpu/cacheinfo.c | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index c131c412db89c..4125e53a5ef79 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -178,7 +178,16 @@ struct _cpuid4_info_regs { struct amd_northbridge *nb; }; -static unsigned short num_cache_leaves; +static inline unsigned int get_num_cache_leaves(unsigned int cpu) +{ + return get_cpu_cacheinfo(cpu)->num_leaves; +} + +static inline void +set_num_cache_leaves(unsigned int nr_leaves, unsigned int cpu) +{ + get_cpu_cacheinfo(cpu)->num_leaves = nr_leaves; +} /* AMD doesn't have CPUID4. Emulate it here to report the same information to the user. This makes some assumptions about the machine: @@ -718,19 +727,21 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) void init_amd_cacheinfo(struct cpuinfo_x86 *c) { + unsigned int cpu = c->cpu_index; + if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - num_cache_leaves = find_num_cache_leaves(c); + set_num_cache_leaves(find_num_cache_leaves(c), cpu); } else if (c->extended_cpuid_level >= 0x80000006) { if (cpuid_edx(0x80000006) & 0xf000) - num_cache_leaves = 4; + set_num_cache_leaves(4, cpu); else - num_cache_leaves = 3; + set_num_cache_leaves(3, cpu); } } void init_hygon_cacheinfo(struct cpuinfo_x86 *c) { - num_cache_leaves = find_num_cache_leaves(c); + set_num_cache_leaves(find_num_cache_leaves(c), c->cpu_index); } void init_intel_cacheinfo(struct cpuinfo_x86 *c) @@ -742,19 +753,19 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb; if (c->cpuid_level > 3) { - static int is_initialized; - - if (is_initialized == 0) { - /* Init num_cache_leaves from boot CPU */ - num_cache_leaves = find_num_cache_leaves(c); - is_initialized++; - } + /* + * There should be at least one leaf. A non-zero value means + * that the number of leaves has been initialized. + */ + if (!get_num_cache_leaves(c->cpu_index)) + set_num_cache_leaves(find_num_cache_leaves(c), + c->cpu_index); /* * Whenever possible use cpuid(4), deterministic cache * parameters cpuid leaf to find the cache details */ - for (i = 0; i < num_cache_leaves; i++) { + for (i = 0; i < get_num_cache_leaves(c->cpu_index); i++) { struct _cpuid4_info_regs this_leaf = {}; int retval; @@ -790,14 +801,14 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) * Don't use cpuid2 if cpuid4 is supported. For P4, we use cpuid2 for * trace cache */ - if ((num_cache_leaves == 0 || c->x86 == 15) && c->cpuid_level > 1) { + if ((!get_num_cache_leaves(c->cpu_index) || c->x86 == 15) && c->cpuid_level > 1) { /* supports eax=2 call */ int j, n; unsigned int regs[4]; unsigned char *dp = (unsigned char *)regs; int only_trace = 0; - if (num_cache_leaves != 0 && c->x86 == 15) + if (get_num_cache_leaves(c->cpu_index) && c->x86 == 15) only_trace = 1; /* Number of times to iterate */ @@ -993,12 +1004,9 @@ int init_cache_level(unsigned int cpu) { struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); - if (!num_cache_leaves) - return -ENOENT; if (!this_cpu_ci) return -EINVAL; this_cpu_ci->num_levels = 3; - this_cpu_ci->num_leaves = num_cache_leaves; return 0; } From patchwork Mon Mar 4 10:32:06 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: 1907493 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 4TpFQN6764z23fC for ; Mon, 4 Mar 2024 21:33:00 +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 1rh5cq-0002MT-O2; Mon, 04 Mar 2024 10:32:52 +0000 Received: from mail-pg1-f176.google.com ([209.85.215.176]) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rh5cZ-00028O-4b for kernel-team@lists.ubuntu.com; Mon, 04 Mar 2024 10:32:35 +0000 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5cf2d73a183so3838401a12.1 for ; Mon, 04 Mar 2024 02:32:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709548353; x=1710153153; 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=3kgmdCSeN5ZmQtvfL485XrTGeIATO05I5DoJL+xITdA=; b=aFdd8ng9oxeYu4sOPfOyH6t8sXtShBmYO4ss615gIrefs7l79VeJz9N27u7IGrTjMC tovk22eTfXU3PbrIzCXy6F0tHqFjQLCj9A10faicOyWRlFnEfVnMnuKi7asl8nIGma1S UIupteiEICaZTFZvVSZ7Myb8xd78eGJMofsh2jsWcxkFaVu522iKtvDp60C9wqb2QDno Z0et8JEAHfqfLSYFcoBjRy/rM6Do4M0beJHZUzQfJpsY+FhYfa23FyewYhpogU5J9pFc 8b9WOtQQ/BXQSyc+CYBcenBTVteKsW98F44CgdhMtkpNLMH5yNjpxnxFFClPOfF0vYf1 rMMQ== X-Gm-Message-State: AOJu0Ywk56jwMVEGLOE8EUlR5oXKat2+koxdFhjfDUnFrzlWWyqQgjtd +HhIV2inCxf8D7L6E4LfCOV2Y7Ug6tMz7pgG17CcAq2QD+3ylnIQo/kzX/Kd X-Google-Smtp-Source: AGHT+IFyPDRi9ktMpdYr3ih90SxLdmQTo/kV7KFyNFTg3R7mYSC4PY3rFq0qkKiT9LPoqgbg7m3L0g== X-Received: by 2002:a17:90b:4d91:b0:296:f2d5:6567 with SMTP id oj17-20020a17090b4d9100b00296f2d56567mr11595268pjb.4.1709548353066; Mon, 04 Mar 2024 02:32:33 -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.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 02:32:32 -0800 (PST) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/4][Noble] UBUNTU: SAUCE: x86/cacheinfo: Clean out init_cache_level() Date: Mon, 4 Mar 2024 18:32:06 +0800 Message-ID: <20240304103206.686842-5-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.215.176; envelope-from=vicamo@gmail.com; helo=mail-pg1-f176.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 init_cache_level() no longer has a purpose on x86. It no longer needs to set num_leaves, and it never had to set num_levels, which was unnecessary on x86. Replace it with "return 0" simply to override the weak function, which would return an error. 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: Len Brown Signed-off-by: Ricardo Neri (cherry-picked from https://lore.kernel.org/all/20231212222519.12834-5-ricardo.neri-calderon@linux.intel.com/raw) Signed-off-by: You-Sheng Yang --- arch/x86/kernel/cpu/cacheinfo.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 4125e53a5ef79..1cfe0921ac677 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -1002,11 +1002,6 @@ static void ci_leaf_init(struct cacheinfo *this_leaf, int init_cache_level(unsigned int cpu) { - struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); - - if (!this_cpu_ci) - return -EINVAL; - this_cpu_ci->num_levels = 3; return 0; }