All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Juergen Gross <jgross@suse.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Jan Beulich <jbeulich@suse.com>, Brian Gerst <brgerst@gmail.com>,
	kernel-dev@igalia.com, linux-kernel@vger.kernel.org,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()
Date: Mon, 14 Sep 2026 08:22:08 -0300	[thread overview]
Message-ID: <6113f06c790cfe1141d2dc09b68937b6@igalia.com> (raw)
In-Reply-To: <20260911043822.GHaqOFvnw5mQ0s89QQ@fat_crate.local>

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


  reply	other threads:[~2026-09-14 11:22 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-22 18:33 [PATCH v9 0/5] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp() Mauricio Faria de Oliveira
2026-09-01 13:16   ` Jan Beulich
2026-09-02  8:33     ` David Laight
2026-09-02 14:18       ` H. Peter Anvin
2026-09-02  2:31   ` Borislav Petkov
2026-09-02 13:29     ` Michael Matz
2026-09-02 13:48       ` Mauricio Faria de Oliveira
2026-09-03  0:01         ` Borislav Petkov
2026-09-03  0:07           ` Mauricio Faria de Oliveira
2026-09-03  0:39             ` Borislav Petkov
2026-09-03  8:40           ` David Laight
2026-09-02 23:58       ` Borislav Petkov
2026-08-22 18:33 ` [PATCH v9 2/5] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
2026-09-06 17:01   ` Borislav Petkov
2026-09-06 18:15     ` H. Peter Anvin
2026-09-08 18:04       ` Mauricio Faria de Oliveira
2026-09-08 19:32         ` Borislav Petkov
2026-09-08 21:06           ` Mauricio Faria de Oliveira
2026-09-10  3:38             ` Borislav Petkov
2026-09-10 13:07               ` Mauricio Faria de Oliveira
2026-09-10 14:03               ` H. Peter Anvin
2026-09-08 23:16           ` H. Peter Anvin
2026-09-09  8:38             ` David Laight
2026-09-09 13:43               ` H. Peter Anvin
2026-09-09 19:28                 ` David Laight
2026-09-09 19:33                   ` H. Peter Anvin
2026-09-09 21:39                     ` David Laight
2026-09-09 23:12                       ` H. Peter Anvin
2026-09-08 17:57     ` Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 3/5] x86/asm: group inline string functions Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 4/5] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
2026-09-11  4:38   ` Borislav Petkov
2026-09-14 11:22     ` Mauricio Faria de Oliveira [this message]
2026-09-15  5:11       ` Borislav Petkov
2026-09-15  8:43         ` David Laight
2026-09-15 15:48         ` Borislav Petkov
2026-09-15 23:49           ` Mauricio Faria de Oliveira
2026-09-16  0:04             ` Borislav Petkov
2026-09-16  0:52               ` Mauricio Faria de Oliveira
2026-08-22 18:33 ` [PATCH v9 5/5] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
2026-09-11  4:39   ` Borislav Petkov
2026-09-14 11:40     ` Mauricio Faria de Oliveira
2026-09-15  5:26       ` Borislav Petkov
2026-09-15 23:55         ` Mauricio Faria de Oliveira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6113f06c790cfe1141d2dc09b68937b6@igalia.com \
    --to=mfo@igalia.com \
    --cc=adobriyan@gmail.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=kernel-dev@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.