From: Lin Wang <wanglin@open-hieco.net>
To: Borislav Petkov <bp@alien8.de>,
Yazen Ghannam <yazen.ghannam@amd.com>,
Mario Limonciello <mario.limonciello@amd.com>
Cc: Pu Wen <puwen@hygon.cn>, Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>, Tony Luck <tony.luck@intel.com>,
x86@kernel.org, linux-edac@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v9 2/7] x86/hygon: Map CPU NodeIds to DF nodes
Date: Thu, 29 Oct 2026 13:33:08 +0800 [thread overview]
Message-ID: <20261029053313.46323-3-wanglin@open-hieco.net> (raw)
In-Reply-To: <20261029053313.46323-1-wanglin@open-hieco.net>
On bare-metal Hygon systems, CPUID 0x8000001E ECX[7:0] encodes a
CPU's socket and local CDD ordinal. The value is sparse across sockets
and cannot directly index the dense DF node cache.
Resolve the encoded socket and local ordinal against CDD entries in the
cache, which are ordered by socket and DFID. The NodeId reported by
CPUID in a guest may not describe the physical DF topology, so return
-ENODEV in guests or when it does not identify an enumerated CDD.
Hygon EDAC and ATL support will use this mapping. Keep it local until
that support is added.
Signed-off-by: Lin Wang <wanglin@open-hieco.net>
Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
arch/x86/kernel/hygon_node.c | 54 ++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/arch/x86/kernel/hygon_node.c b/arch/x86/kernel/hygon_node.c
index 6a5278f8e5ca..03c723aab97e 100644
--- a/arch/x86/kernel/hygon_node.c
+++ b/arch/x86/kernel/hygon_node.c
@@ -24,6 +24,7 @@
#include <linux/processor.h>
#include <linux/slab.h>
#include <linux/sort.h>
+#include <linux/topology.h>
#include <asm/cpu_device_id.h>
#include <asm/hygon/node.h>
@@ -481,6 +482,44 @@ static int __init sort_and_classify(struct df_node_cache *cache)
return 0;
}
+#define NODE_ID_SOCKET GENMASK(7, 4)
+#define NODE_ID_LOCAL GENMASK(3, 0)
+
+/*
+ * Translate a Hygon Fam18h phys_node_id (CPUID 8000001E ECX[7:0]) to a
+ * dense DF CDD index. On supported models, CPUID reports this
+ * encoding:
+ *
+ * phys_node_id = (socket_id << 4) | local_cdd_index_in_dfid_order
+ *
+ * The CDD region of df_cache.nodes[] is sorted by (socket_id, dfid), so
+ * return the index of the CDD whose socket_id matches and whose
+ * socket-local ordinal is @local.
+ *
+ * Return -ENODEV if the cache is unavailable or no CDD matches.
+ */
+static int phys_nid_to_df_node(unsigned int phys_nid)
+{
+ unsigned int socket, local, ordinal = 0;
+ u16 i;
+
+ socket = FIELD_GET(NODE_ID_SOCKET, phys_nid);
+ local = FIELD_GET(NODE_ID_LOCAL, phys_nid);
+
+ if (!df_cache.nodes)
+ return -ENODEV;
+
+ for (i = 0; i < df_cache.num_cdd; i++) {
+ if (df_cache.nodes[i].socket_id != socket)
+ continue;
+
+ if (ordinal++ == local)
+ return i;
+ }
+
+ return -ENODEV;
+}
+
static int __init build_cache(void)
{
struct df_node_cache cache = { };
@@ -533,6 +572,21 @@ static int __maybe_unused hygon_node_get_info(u16 node, struct hygon_node_info *
return 0;
}
+static int __maybe_unused cpu_to_df_node(unsigned int cpu)
+{
+ if (cpu >= nr_cpu_ids)
+ return -EINVAL;
+
+ /*
+ * The NodeId reported by CPUID in a guest may not describe the
+ * physical DF topology.
+ */
+ if (cpu_feature_enabled(X86_FEATURE_HYPERVISOR))
+ return -ENODEV;
+
+ return phys_nid_to_df_node(topology_amd_node_id(cpu));
+}
+
/* Return a referenced DF device; the caller must call pci_dev_put(). */
static __maybe_unused struct pci_dev *hygon_node_get_func(u16 node, u8 func)
{
--
2.43.0
next prev parent reply other threads:[~2026-10-29 5:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 5:33 [PATCH v9 0/7] x86/hygon: Add Family 0x18 DF node enumeration and SMN access Lin Wang
2026-10-29 5:33 ` [PATCH v9 1/7] x86/hygon: Add Family 0x18 DF node enumeration Lin Wang
2026-10-29 5:33 ` Lin Wang [this message]
2026-10-29 5:33 ` [PATCH v9 3/7] EDAC/amd64: Stop matching Hygon CPUs Lin Wang
2026-10-29 5:33 ` [PATCH v9 4/7] RAS/AMD/ATL: Match AMD CPUs only Lin Wang
2026-10-29 5:33 ` [PATCH v9 5/7] x86/amd_nb: Restrict the northbridge framework to AMD CPUs Lin Wang
2026-10-29 5:33 ` [PATCH v9 6/7] x86/amd_node: Restrict SMN setup " Lin Wang
2026-10-29 5:33 ` [PATCH v9 7/7] x86/hygon: Add Family 0x18 SMN access Lin Wang
2026-11-04 17:16 ` Yazen Ghannam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261029053313.46323-3-wanglin@open-hieco.net \
--to=wanglin@open-hieco.net \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=mingo@redhat.com \
--cc=puwen@hygon.cn \
--cc=tglx@kernel.org \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
--cc=yazen.ghannam@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®