Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp173339rdh; Tue, 13 Feb 2024 13:05:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVNBEg91LrR+wHHwyQDoWx+U1I0I/iclCevaxcpJjnjSm3RDPcVk3sv+2zoePJRNHncvLYrkQaj0fVGZxhj/s04PBwtrT27lbfjb9xp8A== X-Google-Smtp-Source: AGHT+IGOq8i9/4K+ePcMNirELOE83unH4A0DwLswqW5pQgS/fzRyVTc21k0/kGnAEXL8CU0dH2bO X-Received: by 2002:a0c:cb90:0:b0:68c:74a7:9e21 with SMTP id p16-20020a0ccb90000000b0068c74a79e21mr653496qvk.3.1707858349444; Tue, 13 Feb 2024 13:05:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707858349; cv=pass; d=google.com; s=arc-20160816; b=0zIbOKHnn20nDwVeR6dBIg6HI2W7ojkfvXIGvhCS+Z8vpIakNg7g5OlPNkz4Sznq1h 03z0P37LmhtRHUO83y6cgSaZ1FpKDCpP0/Hi9tA0CL6BcS+NguoKoEArWlnu6h99eFPb aYk68YnMA/iQ4WNrpSOAcnMqTyysYT5nWkFfiRRu4kjE7eT1WIYo38kjvdXsFptRQdXP YYcowCh21tX6LSHOWF2wXpKpLGFU0CArdSKAmMLFMS3blZsg9iExfg3aCAK7s1WhoV5y e9kDCY8xaZSmTlq8t/mI1p3YR8luS6w4b9sqn1sBsTPPne5rLxGt9ZDyfq3wvpuwaChQ IyxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=C8p7kQoF9JK2J2fxFsgb+njhdNZ+zabVP2maWn9Gt2Q=; fh=bp5sG6RDsZ58jv5bC5LUXekF06t46dVreEfbNXHM2zg=; b=uCujUN78ARfSki4Yf9ArPbpcYbNKgw3PTN+QvIeDNLGL79zci1iZzGX3ctVupWBM/X E+x+h8QNkmjfFuO8aa7iOceNidflH2kgLEqOkJZVLLYeHdFimY1wHvSGEAnAfwq4Z8Cf +/vb9UTYnqq0LpcexJNMHv2cRrE5Ou1jR/OcSIZH0gL1lEpH3pu5U9zcGlkRJxYGpDxR t7j6PzTLgdZsBpM/uZHNcp4S30OYzJ4AOJ81kCdcGQjEj5HaAsLr2b+OK4xa5tHbjmr0 LmrTDJ93POVTPglpsjloKcxTxQKvWBDhvePrIz0Dj2X9AQQ2eCOn9VMiT2kKzSsX4dFO Of3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TDngnBCr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCXzzzehJ1RPUww5+REPvncxi84O+19zfYB8+OuGR/slIq4Vdf0+5NkCc0Vk/Tpqnx2NaZNKRn4aWXUdp89v56Sc9jtzWol0TFYIn323/A== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gh11-20020a05621429cb00b0068cfb00a2c9si3651555qvb.286.2024.02.13.13.05.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TDngnBCr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-64247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1399F1C22D30 for ; Tue, 13 Feb 2024 21:05:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E797629ED; Tue, 13 Feb 2024 21:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TDngnBCr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8Ab/ZKA/" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 454BF627FB for ; Tue, 13 Feb 2024 21:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858254; cv=none; b=ffyWafQN1itAUoR60X6wSFZg3jNNY1ZzYM9y6usuNQ6SnswoGRRl9BQL0ysMQdpaDHrlb+vEFdOX57mbi7dZpZ50LjvKasWzqqj4/7WPlm+xIjjhM+oo/KJntFQFAcaweKWYVh1i1os0GSeVbyNKHavflFBbm6SDOrZyxNxXHL0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858254; c=relaxed/simple; bh=1pOcWfaWJWDSFwex5CtexTSeN4+vfjEq1y2FYJo1vSk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=Ykx5ECNP93Mp4COSjbNoQCiGKnWqVivaBa6I+Ig3AsOxqKzYExWaO927/if78vvU87NYAkHe7+V0v/6zYDIH0u0jNrEGvjy70M5LI+U+kUd37S//VXNXJddmYVCTuvAWmEdhyVLzgLVDCWJ1ZpWPpUOZc7zFuifdgk1H5Ailf8Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TDngnBCr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8Ab/ZKA/; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240212153624.956116738@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858250; 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: references:references; bh=C8p7kQoF9JK2J2fxFsgb+njhdNZ+zabVP2maWn9Gt2Q=; b=TDngnBCr97/pmC2I6VMD9tWSB5iPul6/3cECdjtfsd3b6mV5V/9ysto7pALN0fVyCtco5i Mn928LpwcnjxV3CONPiuErv+cr4zr27v1mlci96Vn/8nUqxDHOV3f5dld45YJYo0zfQBIF x6TSKSJpNnwi8E0cilnxyjz7JEol0x2J/LI1LXV1sFuAa6U52owVP7sDxFUBhqIzDYMQHV ipYxChtLEUzrSjPDW1CgFKOaIIAkKoiSRQlZO9niyj7BG93OWKMgmbQkuyor7FE+IZXzVk PLEV7xmqO0j06Lt3+LGRaQRcwvvWq8ds5V+RCH5/KLsfv1PGJNgN9uWKHpcbKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858250; 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: references:references; bh=C8p7kQoF9JK2J2fxFsgb+njhdNZ+zabVP2maWn9Gt2Q=; b=8Ab/ZKA/qaha5Z3KchU7X6TH04ICKSzuCs1RdnKOx5vtZRnyFe2bWIAp0qkAfa2eiLFcjg r2In1P4OdMCZwCCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko , Michael Kelley , "Peter Zijlstra (Intel)" , Wang Wendy Subject: [patch V6 08/19] x86/cpu/amd: Provide a separate accessor for Node ID References: <20240212153109.330805450@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 13 Feb 2024 22:04:10 +0100 (CET) From: Thomas Gleixner AMD (ab)uses topology_die_id() to store the Node ID information and topology_max_dies_per_pkg to store the number of nodes per package. This collides with the proper processor die level enumeration which is coming on AMD with CPUID 8000_0026, unless there is a correlation between the two. There is zero documentation about that. So provide new storage and new accessors which for now still access die_id and topology_max_die_per_pkg(). Will be mopped up after AMD and HYGON are converted over. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Tested-by: Zhang Rui Tested-by: Wang Wendy --- V6: Fixup changelog - Borislav --- arch/x86/events/amd/core.c | 2 +- arch/x86/include/asm/processor.h | 3 +++ arch/x86/include/asm/topology.h | 8 ++++++++ arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/mce/amd.c | 4 ++-- arch/x86/kernel/cpu/mce/inject.c | 4 ++-- drivers/edac/amd64_edac.c | 4 ++-- drivers/edac/mce_amd.c | 4 ++-- 9 files changed, 23 insertions(+), 12 deletions(-) --- --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -579,7 +579,7 @@ static void amd_pmu_cpu_starting(int cpu if (!x86_pmu.amd_nb_constraints) return; - nb_id = topology_die_id(cpu); + nb_id = topology_amd_node_id(cpu); WARN_ON_ONCE(nb_id == BAD_APICID); for_each_online_cpu(i) { --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -100,6 +100,9 @@ struct cpuinfo_topology { u32 logical_pkg_id; u32 logical_die_id; + // AMD Node ID and Nodes per Package info + u32 amd_node_id; + // Cache level topology IDs u32 llc_id; u32 l2c_id; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -131,6 +131,8 @@ extern const struct cpumask *cpu_cluster #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) + extern unsigned int __max_die_per_package; #ifdef CONFIG_SMP @@ -161,6 +163,11 @@ int topology_update_package_map(unsigned int topology_update_die_map(unsigned int dieid, unsigned int cpu); int topology_phys_to_logical_pkg(unsigned int pkg); +static inline unsigned int topology_amd_nodes_per_pkg(void) +{ + return __max_die_per_package; +} + extern struct cpumask __cpu_primary_thread_mask; #define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask) @@ -182,6 +189,7 @@ static inline int topology_phys_to_logic static inline int topology_max_die_per_package(void) { return 1; } static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } +static inline unsigned int topology_amd_nodes_per_pkg(void) { return 0; }; #endif /* !CONFIG_SMP */ static inline void arch_fix_phys_package_id(int num, u32 slot) --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -386,7 +386,7 @@ struct resource *amd_get_mmconfig_range( int amd_get_subcaches(int cpu) { - struct pci_dev *link = node_to_amd_nb(topology_die_id(cpu))->link; + struct pci_dev *link = node_to_amd_nb(topology_amd_node_id(cpu))->link; unsigned int mask; if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) @@ -400,7 +400,7 @@ int amd_get_subcaches(int cpu) int amd_set_subcaches(int cpu, unsigned long mask) { static unsigned int reset, ban; - struct amd_northbridge *nb = node_to_amd_nb(topology_die_id(cpu)); + struct amd_northbridge *nb = node_to_amd_nb(topology_amd_node_id(cpu)); unsigned int reg; int cuid; --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cp if (index < 3) return; - node = topology_die_id(smp_processor_id()); + node = topology_amd_node_id(smp_processor_id()); this_leaf->nb = node_to_amd_nb(node); if (this_leaf->nb && !this_leaf->nb->l3_cache.indices) amd_calc_l3_indices(this_leaf->nb); --- a/arch/x86/kernel/cpu/mce/amd.c +++ b/arch/x86/kernel/cpu/mce/amd.c @@ -1231,7 +1231,7 @@ static int threshold_create_bank(struct return -ENODEV; if (is_shared_bank(bank)) { - nb = node_to_amd_nb(topology_die_id(cpu)); + nb = node_to_amd_nb(topology_amd_node_id(cpu)); /* threshold descriptor already initialized on this node? */ if (nb && nb->bank4) { @@ -1335,7 +1335,7 @@ static void threshold_remove_bank(struct * The last CPU on this node using the shared bank is going * away, remove that bank now. */ - nb = node_to_amd_nb(topology_die_id(smp_processor_id())); + nb = node_to_amd_nb(topology_amd_node_id(smp_processor_id())); nb->bank4 = NULL; } --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -543,8 +543,8 @@ static void do_inject(void) if (boot_cpu_has(X86_FEATURE_AMD_DCM) && b == 4 && boot_cpu_data.x86 < 0x17) { - toggle_nb_mca_mst_cpu(topology_die_id(cpu)); - cpu = get_nbc_for_node(topology_die_id(cpu)); + toggle_nb_mca_mst_cpu(topology_amd_node_id(cpu)); + cpu = get_nbc_for_node(topology_amd_node_id(cpu)); } cpus_read_lock(); --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -1915,7 +1915,7 @@ static void dct_determine_memory_type(st /* On F10h and later ErrAddr is MC4_ADDR[47:1] */ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m) { - u16 mce_nid = topology_die_id(m->extcpu); + u16 mce_nid = topology_amd_node_id(m->extcpu); struct mem_ctl_info *mci; u8 start_bit = 1; u8 end_bit = 47; @@ -3446,7 +3446,7 @@ static void get_cpus_on_this_dct_cpumask int cpu; for_each_online_cpu(cpu) - if (topology_die_id(cpu) == nid) + if (topology_amd_node_id(cpu) == nid) cpumask_set_cpu(cpu, mask); } --- a/drivers/edac/mce_amd.c +++ b/drivers/edac/mce_amd.c @@ -584,7 +584,7 @@ static void decode_mc3_mce(struct mce *m static void decode_mc4_mce(struct mce *m) { unsigned int fam = x86_family(m->cpuid); - int node_id = topology_die_id(m->extcpu); + int node_id = topology_amd_node_id(m->extcpu); u16 ec = EC(m->status); u8 xec = XEC(m->status, 0x1f); u8 offset = 0; @@ -746,7 +746,7 @@ static void decode_smca_error(struct mce if ((bank_type == SMCA_UMC || bank_type == SMCA_UMC_V2) && xec == 0 && decode_dram_ecc) - decode_dram_ecc(topology_die_id(m->extcpu), m); + decode_dram_ecc(topology_amd_node_id(m->extcpu), m); } static inline void amd_decode_err_code(u16 ec)