[PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h

Fu Hao posted 8 patches 6 days, 8 hours ago
[PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h
Posted by Fu Hao 6 days, 8 hours ago
The die id should be get from the NodeId field of CPUID leaf 0x8000001e
ecx for Hygon model 4h~8h processors.

Signed-off-by: Fu Hao <fuhao@open-hieco.net>
---
 arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index 7f95a74e4..f39d32a68 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
 }
 
+/*
+ * Adjust the die_id and logical_die_id for Hygon model 4h~8h.
+ */
+static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
+{
+	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);
+	}
+}
+
 static void init_hygon(struct cpuinfo_x86 *c)
 {
 	u64 vm_cr;
@@ -191,6 +204,8 @@ static void init_hygon(struct cpuinfo_x86 *c)
 
 	init_hygon_cacheinfo(c);
 
+	cpu_topology_fixup_hygon(c);
+
 	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
Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h
Posted by Borislav Petkov 5 days, 3 hours ago
On Fri, Mar 27, 2026 at 04:07:31PM +0800, Fu Hao wrote:
> The die id should be get from the NodeId field of CPUID leaf 0x8000001e
	     ^^^^^^^^^^^^^

Pls run all your English text through an LLM so that corrects it for you.

Also "die ID".

> ecx for Hygon model 4h~8h processors.
> 
> Signed-off-by: Fu Hao <fuhao@open-hieco.net>
> ---
>  arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
> index 7f95a74e4..f39d32a68 100644
> --- a/arch/x86/kernel/cpu/hygon.c
> +++ b/arch/x86/kernel/cpu/hygon.c
> @@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
>  	set_cpu_cap(c, X86_FEATURE_VMMCALL);
>  }
>  
> +/*
> + * Adjust the die_id and logical_die_id for Hygon model 4h~8h.

What does "model 4h~8h" mean?

Models 0x4-0x8 ?

> + */
> +static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
> +{
> +	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);
> +	}
> +}

Does this really need to be a separate function or can you stick the
if-conditional along with the comment where it needs to be executed?

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Re: [PATCH 1/8] x86/cpu/hygon: Adjust the die_id and logical_die_id for Hygon model 4h~8h
Posted by Fu Hao 3 days, 14 hours ago
On 2026/3/28 21:34, Borislav Petkov wrote:
> On Fri, Mar 27, 2026 at 04:07:31PM +0800, Fu Hao wrote:
>> The die id should be get from the NodeId field of CPUID leaf 0x8000001e
> 	     ^^^^^^^^^^^^^
> 
> Pls run all your English text through an LLM so that corrects it for you.
> 
> Also "die ID".
> 
>> ecx for Hygon model 4h~8h processors.
>>
>> Signed-off-by: Fu Hao <fuhao@open-hieco.net>
>> ---
>>   arch/x86/kernel/cpu/hygon.c | 15 +++++++++++++++
>>   1 file changed, 15 insertions(+)
>>
>> diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
>> index 7f95a74e4..f39d32a68 100644
>> --- a/arch/x86/kernel/cpu/hygon.c
>> +++ b/arch/x86/kernel/cpu/hygon.c
>> @@ -168,6 +168,19 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
>>   	set_cpu_cap(c, X86_FEATURE_VMMCALL);
>>   }
>>   
>> +/*
>> + * Adjust the die_id and logical_die_id for Hygon model 4h~8h.
> 
> What does "model 4h~8h" mean?
> 
> Models 0x4-0x8 ?
> 
>> + */
>> +static void cpu_topology_fixup_hygon(struct cpuinfo_x86 *c)
>> +{
>> +	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);
>> +	}
>> +}
> 
> Does this really need to be a separate function or can you stick the
> if-conditional along with the comment where it needs to be executed?
> 
> Thx.
> 

Thank you very much for your suggestion.
The Hygon model 4h~8h, which is also the Hygon family 0x18
model 0x4~0x8 series of processors.

Using separate functions for encapsulation is primarily due to the
consideration for subsequent new processors, there may be different
ways to obtain the core ID, die ID and pkg ID. Of course, it can also
be temporarily placed in the "init_hygon" function at present.

What about your suggestion?

-- 
Regards,
Fu Hao