Re: [patch V3a 30/40] x86/cpu: Provide an AMD/HYGON specific topology parser

From: Pu Wen
Date: Sat Aug 12 2023 - 00:20:19 EST


On 2023/8/12 1:11, Thomas Gleixner wrote:
On Fri, Aug 11 2023 at 20:58, Pu Wen wrote:
On 2023/8/3 3:51, Thomas Gleixner wrote:
+ if (tscan->c->x86_vendor == X86_VENDOR_AMD) {
+ if (tscan->c->x86 == 0x15)
+ tscan->c->topo.cu_id = leaf.cuid;
+
+ cacheinfo_amd_init_llc_id(tscan->c, leaf.nodeid);
+ } else {
+ /*
+ * Package ID is ApicId[6..] on Hygon CPUs. See commit
+ * e0ceeae708ce for explanation. The topology info is
+ * screwed up: The package shift is always 6 and the node
+ * ID is bit [4:5]. Don't touch the latter without
+ * confirmation from the Hygon developers.
+ */
+ topology_set_dom(tscan, TOPO_CORE_DOMAIN, 6, tscan->dom_ncpus[TOPO_CORE_DOMAIN]);

Hygon updated CPUs will not always shift 6, and shift 6 is not good for
running guests.
So suggest to modify like this:
if (!boot_cpu_has(X86_FEATURE_HYPERVISOR) && tscan->c->x86_model <=
0x3)
topology_set_dom(tscan, TOPO_CORE_DOMAIN, 6,
tscan->dom_ncpus[TOPO_CORE_DOMAIN]);

This is exactly what the existing code does today. Can you please send a
delta patch on top of this with a proper explanation?

Will.

And I think it's better to send a prerequisite patch(is attached) after
patch 02 of this series. Since it can be individually back-ported to the
stable releases.

--
Regards,
Pu Wen


From 768af7009f6fa9f9c40251c5979f611479165dc4 Mon Sep 17 00:00:00 2001
From: Pu Wen <puwen@xxxxxxxx>
Date: Sat, 12 Aug 2023 11:41:06 +0800
Subject: [PATCH] x86/cpu: Refine the CPU topology deriving method for Hygon

Hygon updated processors will not always shift 6 and use the result
of CPUID leaf 0xB to derive the socket ID.

If running on guest, the ApicID is not the same as host's, so just
use the hypervisor's default.

Cc: <stable@xxxxxxxxxxxxxxx> # v5.2+
Fixes: e0ceeae708ce ("x86/CPU/hygon: Fix phys_proc_id calculation logic for multi-die processors")
Signed-off-by: Pu Wen <puwen@xxxxxxxx>
---
arch/x86/kernel/cpu/hygon.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index defdc594be14..a7b3ef4c4de9 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -87,8 +87,12 @@ static void hygon_get_topology(struct cpuinfo_x86 *c)
if (!err)
c->x86_coreid_bits = get_count_order(c->x86_max_cores);

- /* Socket ID is ApicId[6] for these processors. */
- c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT;
+ /*
+ * Socket ID is ApicId[6] for the processors with model <= 0x3
+ * when running on host.
+ */
+ if (!boot_cpu_has(X86_FEATURE_HYPERVISOR) && c->x86_model <= 0x3)
+ c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT;

cacheinfo_hygon_init_llc_id(c, cpu);
} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
--
2.23.0