[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/cpu-policy: Remove cpu_policy.x86_vendor




On 12/3/26 12:07, Jan Beulich wrote:
> On 03.12.2026 11:39, ODIN Thomas wrote:
>> On 12/2/26 16:07, Jan Beulich wrote:
>>> On 02.12.2026 10:42, ODIN Thomas wrote:
>>>> c520286a53 ("x86: Reject CPU policies with vendors other than the
>>>> host's") made x86_cpu_policies_are_compatible() reject any guest CPU
>>>> policy whose vendor doesn't match the host's, and that check runs
>>>> before a policy is ever installed.  Every cpu_policy visible to a
>>>> running domain, or to any other in-hypervisor consumer (the
>>>> raw/host/pv_max/hvm_max policies, all derived from the host's own
>>>> CPUID), therefore now necessarily has the same vendor as
>>>> boot_cpu_data.x86_vendor.
>>>>
>>>> The cached x86_vendor field is thus redundant, so we drop it, and
>>>> x86_cpu_policy_recalc_synth() along with it, since that function's
>>>> only job was to compute it.
>>>>
>>>> The lib/x86 code shared with the toolstack and the emulator's
>>>> standalone test suite has no boot_cpu_data to fall back on (and isn't
>>>> covered by the same guarantee), so those few spots compute the vendor
>>>> from basic.vendor_ebx/ecx/edx via x86_cpuid_lookup_vendor() instead of
>>>> caching it.
>>>
>>> I wonder whether this somewhat ugly aspect was taken into account when ...
>>>
>>>> No functional change.
>>>>
>>>> Suggested-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>>
>>> ... Andrew suggested this.
>>
>> To be fair, in our discussion Andrew only suggested removing
>> cpu_policy.x86_vendor as a small, isolated cleanup task (since c520286a53
>> made it redundant with the host vendor in Xen) to get familiar with the
>> patch workflow before tackling the larger x86_cpu_policies_are_compatible() 
>> work.
>>
>> The x86_cpuid_lookup_vendor() fallback in the shared lib/x86 paths was
>> something I ran into when implementing the removal, since those consumers
>> don't have boot_cpu_data. There are five call sites that each spell out
>> x86_cpuid_lookup_vendor(p->basic.vendor_ebx, p->basic.vendor_ecx,
>> p->basic.vendor_edx) instead of going through one accessor. Would a
>> small helper wrapping that call be better here, or would you rather I keep
>> the cached field around instead of working around its absence in lib/x86?
> 
> Well, first and foremost you will need Andrew's input.
> 
> Then: Yes, a helper would remove the fragility at call sites. It wouldn't
> remove the extra overhead. Take _amd_like() for example. That's a simple
> logical-and expression right now, and you switch it to a function call.
> That's okay-ish for the test/fuzzing harnesses, but less so for code Xen.
> (Yes, emulation is slow anyway, but we shouldn't make it yet slower when
> we can avoid doing so.) I'm therefore inclined to suggest that this gain
> __XEN__-dependent logic, e.g.:
> 
> static inline bool
> _amd_like(const struct cpu_policy *cp)
> {
> #ifdef __XEN__
>      return boot_cpu_data.vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON);
> #else
>      unsigned int vendor = x86_cpu_policy_lookup_vendor(cp);
> 
>      return vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON);
> #endif
> }
> 
> Of course the vendor retrieval itself may want further breaking out into
> a function, thus limiting the #ifdef-ary to just there.
> 
> Jan

I looked into how __XEN__ is used across the x86_emulate code - I
hadn't really understood that pattern well before writing this patch.

I'll wait for Andrew's input on this before I put together a v2.

--
ODIN Thomas


--
Thomas Odin | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.