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

Re: [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()



On 2026-09-11 01:38, Borislav Petkov wrote:
> On Sat, Aug 22, 2026 at 03:33:20PM -0300, Mauricio Faria de Oliveira wrote:
>> diff --git a/arch/x86/include/asm/cpuid/api.h 
>> b/arch/x86/include/asm/cpuid/api.h
>> index 
>> 82eddfa2347b32b76c2ea9b85f005ca5416ac71f..2d9f3d4d63de6e721f275d9e80d372edbdfedf30
>>  100644
>> --- a/arch/x86/include/asm/cpuid/api.h
>> +++ b/arch/x86/include/asm/cpuid/api.h
>> @@ -204,7 +204,7 @@ static inline u32 cpuid_base_hypervisor(const char *sig, 
>> u32 leaves)
>>               * from PVH early boot code before instrumentation is set up
>>               * and memcmp() itself may be instrumented.
>>               */
>> -            if (!__builtin_memcmp(sig, signature, 12) &&
>> +            if (!__inline_memcmp(sig, signature, 12) &&
> 
> Dunno, did you not think of simply doing it by foot and save yourself all
> those gymnastics in patches 1-3?

In the review of the original patchset (fixed by this series) it is
mentioned that a compiler might turn it into a memcmp() [1] -- and thus
revert back to the same issue.

[1] https://lore.kernel.org/all/877ccz12ab.ffs@tglx/

Thanks,

> 
> IOW, something like this totally untested thing below:
> 
> diff --git a/arch/x86/include/asm/cpuid/api.h 
> b/arch/x86/include/asm/cpuid/api.h
> index 2d9f3d4d63de..a2db83d17940 100644
> --- a/arch/x86/include/asm/cpuid/api.h
> +++ b/arch/x86/include/asm/cpuid/api.h
> @@ -192,9 +192,10 @@ static __always_inline bool 
> cpuid_function_is_indexed(u32 function)
>  #define for_each_possible_cpuid_base_hypervisor(function) \
>       for (function = 0x40000000; function < 0x40010000; function += 0x100)
>  
> -static inline u32 cpuid_base_hypervisor(const char *sig, u32 leaves)
> +static inline u32 cpuid_base_hypervisor(const char *__sig, u32 leaves)
>  {
>       u32 base, eax, signature[3];
> +     u32 *sig = (u32 *)__sig;
>  
>       for_each_possible_cpuid_base_hypervisor(base) {
>               cpuid(base, &eax, &signature[0], &signature[1], &signature[2]);
> @@ -204,9 +205,12 @@ static inline u32 cpuid_base_hypervisor(const char *sig, 
> u32 leaves)
>                * from PVH early boot code before instrumentation is set up
>                * and memcmp() itself may be instrumented.
>                */
> -             if (!__inline_memcmp(sig, signature, 12) &&
> -                 (leaves == 0 || ((eax - base) >= leaves)))
> -                     return base;
> +             if (sig[0] == signature[0] &&
> +                 sig[1] == signature[1] &&
> +                 sig[2] == signature[2]) {
> +                     if (leaves == 0 || ((eax - base) >= leaves))
> +                             return base;
> +             }
>       }
>  
>       return 0;

-- 
Mauricio



 


Rackspace

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