[PATCH v4 1/5] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon models 0x4 through 0x8
From: Fu Hao
Date: Fri Jul 10 2026 - 02:52:54 EST
For Hygon processor models 0x4–0x8, the die ID should be obtained
from the NodeId field in ECX of CPUID leaf 0x8000001e.
Starting with these models, Hygon CPUs support CPUID leaf 0xb but
do not support leaf 0x80000026. Consequently, the die ID and
logical die ID cannot be derived from the APIC ID space.
CPUID leaf 0xb only supports core and package levels, it cannot
enumerate die IDs within a socket.
However, we found that CPUID leaf 0x8000001e (ECX) provides the
necessary information. In Hygon CPU design, the NodeId field [7:0]
encodes both socket and die IDs in the format:
Bits [7:4]: socket ID
Bits [3:0]: die ID
We can calculate the correct IDs(die_id and logical_die_id) by parsing
this field.
Signed-off-by: Fu Hao <fuhao@xxxxxxxxxxxxxx>
Tested-by: Tingyin Duan <tingyin.duan@xxxxxxxxx>
---
arch/x86/kernel/cpu/hygon.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index 3e8891a9c..a0657c5ad 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -192,6 +192,19 @@ static void init_hygon(struct cpuinfo_x86 *c)
init_hygon_cacheinfo(c);
+ /*
+ * Adjust the die_id and logical_die_id for Hygon models 0x4-0x8.
+ * In Hygon CPU design, the NodeId field of CPUID leaf 0x8000001e (ECX)
+ * is now fixed to represent the socket ID and die ID, allocated as
+ * 4 bits each: socket ID = NodeId[7:4], die ID = NodeId[3:0].
+ */
+ if (c->x86_model >= 0x4 && c->x86_model <= 0x8) {
+ c->topo.die_id = cpuid_ecx(0x8000001e) & 0xff;
+ c->topo.logical_die_id = (c->topo.die_id >> 4) *
+ topology_amd_nodes_per_pkg() +
+ (c->topo.die_id & 0xf);
+ }
+
if (cpu_has(c, X86_FEATURE_SVM)) {
rdmsrq(MSR_VM_CR, vm_cr);
if (vm_cr & SVM_VM_CR_SVM_DIS_MASK) {
--
2.34.1