Re: [PATCH v3 0/4] x86/cpu/topology: Work around the nuances of virtualization on AMD/Hygon

From: K Prateek Nayak
Date: Wed Aug 20 2025 - 05:27:54 EST


Hello Boris,

On 8/20/2025 2:29 PM, Borislav Petkov wrote:
> On Wed, Aug 20, 2025 at 01:41:28PM +0530, Naveen N Rao wrote:
>> That suggests use of leaf 0xb for the initial x2APIC ID especially
>> during early init. I'm not sure why leaf 0x8000001e was preferred over
>> leaf 0xb in commit c749ce393b8f ("x86/cpu: Use common topology code for
>> AMD") though.
>
> Well, I see parse_topology_amd() calling cpu_parse_topology_ext() if you have
> TOPOEXT - which all AMD hw does - which then does cpu_parse_topology_ext() and
> that one tries 0x80000026 and then falls back to 0xb and *only* *then* to
> 0x8000001e.
>
> So, it looks like it DTRT to me...

But parse_8000_001e() then unconditionally overwrites the
"initial_apicid" with the value in 0x8000001E EAX despite it being
populated from cpu_parse_topology_ext().

The flow is as follows:

parse_topology_amd()
if (X86_FEATURE_TOPOEXT) /* True */
has_topoext = cpu_parse_topology_ext(); /* Populates "initial_apicid", returns True */

/* parse_8000_0008() is never called since has_topoext is true */

parse_8000_001e()
if (!X86_FEATURE_TOPOEXT) /* False */
return;

/* Proceeds here */
cpuid_leaf(0x8000001e, &leaf);
tscan->c->topo.initial_apicid = leaf.ext_apic_id; /*** Overwritten here ***/

--
Thanks and Regards,
Prateek