Re: [PATCH v2] x86/cpu: Skip reading MSR_IA32_PLATFORM_ID in virtualized environment

From: Binbin Wu

Date: Wed May 13 2026 - 08:20:39 EST




On 5/13/2026 7:08 PM, Borislav Petkov wrote:
> On Wed, May 13, 2026 at 07:02:53PM +0800, Binbin Wu wrote:
>> My version treated it as a bug fix, so I tried to minimize the code change.
>
> I didn't like
>
> BIT(X86_FEATURE_HYPERVISOR & 0x1f))
>
> in your patch. I'd use BIT(31) as it does.

It was suggested by Dave in the v1 comment.
https://lore.kernel.org/kvm/1a1b0f7c-aa3f-4758-8e17-bc2176c52952@xxxxxxxxx/

>
> But, more importantly, it added yet another place where we test whether we run
> on a HV. And it is high time we unified those because we run more and more on
> HVs nowadays.

Agree.

>
>> There is one case not covered by setting the global x86_hypervisor_present at this point.
>> Xen PV guest will not go this path, so Xen PV guest will not see the hypervisor bit.
>>
>> But maybe we can just ignore Xen PV guest case today?
>
> Nothing changes before or after this fix. So Xen PV can be handled
> completely separated from this.

intel_get_platform_id() can be called in Xen PV guest during normal boot.
Using x86_hypervisor_present just doesn't cover the case.

My fix was intended to skip reading MSR_IA32_PLATFORM_ID if hypervisor is
detected, I used cpuid_ecx() instead of cpuid_ecx_native() so that Xen PV
guest can also read the hypervisor bit using xen_cpuid() (Xen PV guest has
overwritten the pv ops) to make the coverage complete.


>
> Thx.
>