public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] x86/pvh: fix unbootable VMs again (PVH + KASAN)
@ 2026-04-22 20:07 Mauricio Faria de Oliveira
  2026-04-22 20:07 ` [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp Mauricio Faria de Oliveira
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-04-22 20:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira

The issue of unbootable VMs with CONFIG_PVH due to CONFIG_KASAN is back.

Booting directly from vmlinux (instead of bzImage) now fails with gcc-14/15
(but works with gcc-12/13) if CONFIG_KASAN_GENERIC is set, on Ubuntu 25.10.

The PVH code is required/supposed not to hit the KASAN memory access check
in the kernel entry point as KASAN has not yet been setup, or an exception
is hit and the boot fails.

This was previously described and addressed with __builtin_mem{cmp,set}():
- commit 661362e3dcab ("xen, pvh: fix unbootable VMs (PVH + KASAN - AMD_MEM_ENCRYPT)")
- commit 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()")
- commit fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()")

However, even with __builtin the compiler may decide to use the out of line
function instead of the inline implementation. So, that does not really fix
the issue unconditionally, as it's being seen (details below).

In order to address this, it's required to switch to inline implementations
that do not depend on the compiler.

There's such a memset in <asm/string.h> and memcmp in 'boot/string.c', now
exposed in <asm/string.h> too. Use them instead of builtins in PVH entry.

Testing:

- Booting from vmlinux (fixed) and bzImage (still works) using
  allnoconfig + CONFIG_PVH + CONFIG_KASAN with gcc-12/13/14/15.

- Building allyesconfig (check for issues with <asm/string.h>).

Details/Debugging:

- Only CONFIG_PVH (works):

  make allnoconfig
  ./scripts/config \
    -e 64BIT -e HYPERVISOR_GUEST -e PVH \
    -e SERIAL_8250 -e SERIAL_8250_CONSOLE
  make olddefconfig
  make -j$(nproc) vmlinux

  qemu-system-x86_64 \
    -accel kvm -nodefaults -nographic -serial stdio \
    -kernel vmlinux -append 'console=ttyS0'
  ...
  SeaBIOS (version ...)
  Booting from ROM...
  Linux version ...
  ...
  <Ctrl-C>

- With CONFIG_KASAN (fails)
  
  ./scripts/config -e KASAN
  make olddefconfig
  make -j$(nproc) vmlinux

  qemu-system-x86_64 \
    -accel kvm -nodefaults -nographic -serial stdio \
    -kernel vmlinux -append 'console=ttyS0'
  ...
  SeaBIOS (version ...)
  Booting from ROM...
  <QEMU reboot loop, flashing the text above>

- Debugging:

  Enable debug info and rebuild.

  QEMU: enable and wait for GDB, stop rebooting, remain running.

  qemu-system-x86_64 \
    -s -S -no-reboot -no-shutdown \
    <other options>

  gdb vmlinux
  (gdb) target remote localhost:1234
  ...
  (gdb) c
  ...
  Thread 2 received signal SIGQUIT, Quit.
  ...
  (gdb) info threads
    Id   Target Id                    Frame
    1    Thread 1.1 (CPU#0 [running]) bytes_is_nonzero (
      start=0xfffffbfff031eebe <error: Cannot access memory at address 0xfffffbfff031eebe>, size=1)
      at .../linux/mm/kasan/generic.c:98
  * 2    Thread 1.2 (CPU#1 [halted ]) 0x00000000000fd0a9 in ?? ()
  ...
  (gdb) thr 1
  ...
  (gdb) bt
  #0  bytes_is_nonzero (start=0xfffffbfff031eebe <error: Cannot access memory at address 0xfffffbfff031eebe>, size=1)
      at .../linux/mm/kasan/generic.c:98
  #1  memory_is_nonzero (start=0xfffffbfff031eebe, end=0xfffffbfff031eebf) at .../linux/mm/kasan/generic.c:115
  #2  memory_is_poisoned_n (addr=0xffffffff818f75f0, size=8) at .../linux/mm/kasan/generic.c:140
  #3  memory_is_poisoned (addr=0xffffffff818f75f0, size=8) at .../linux/mm/kasan/generic.c:172
  #4  check_region_inline (addr=0xffffffff818f75f0, size=8, write=false, ret_ip=18446744071585002062)
      at .../linux/mm/kasan/generic.c:191
  #5  kasan_check_range (addr=addr@entry=0xffffffff818f75f0, size=size@entry=8, write=write@entry=false,
      ret_ip=18446744071585002062) at .../linux/mm/kasan/generic.c:200
  #6  0xffffffff813eb283 in __asan_loadN (addr=addr@entry=0xffffffff818f75f0, size=size@entry=8)
      at .../linux/mm/kasan/generic.c:278
  #7  0xffffffff815df24e in memcmp (cs=cs@entry=0xffffffff818f75f0, ct=ct@entry=0x1be2fe4, count=<optimized out>,
      count@entry=12) at .../linux/lib/string.c:683
  #8  0xffffffff81ba2323 in cpuid_base_hypervisor (sig=0xffffffff818f75f0 "XenVMMXenVMM", leaves=2)
      at .../linux/arch/x86/include/asm/cpuid/api.h:206
  #9  xen_cpuid_base () at .../linux/arch/x86/include/asm/xen/hypervisor.h:46
  #10 xen_prepare_pvh () at .../linux/arch/x86/platform/pvh/enlighten.c:119
  #11 0x0000000001ba2588 in ?? ()
  #12 0x0000000000000000 in ?? ()
  (gdb)

  Frames #7-#8 show the non-builtin memcmp() (lib/string.c) was called
  even with __builtin_memcmp() being used in cpuid_base_hypervisor().

Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
Mauricio Faria de Oliveira (3):
      x86/asm, x86/boot: Expose inline memcmp
      x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()
      x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh()

 arch/x86/boot/string.c            |  6 ++----
 arch/x86/include/asm/cpuid/api.h  |  2 +-
 arch/x86/include/asm/string.h     | 11 +++++++++++
 arch/x86/platform/pvh/enlighten.c |  3 ++-
 4 files changed, 16 insertions(+), 6 deletions(-)
---
base-commit: 6596a02b207886e9e00bb0161c7fd59fea53c081
change-id: 20260422-pvh-kasan-inline-6efac77f1b27

Best regards,
-- 
Mauricio Faria de Oliveira <mfo@igalia.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp
  2026-04-22 20:07 [PATCH 0/3] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
@ 2026-04-22 20:07 ` Mauricio Faria de Oliveira
  2026-04-22 20:54   ` David Laight
  2026-04-22 20:07 ` [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
  2026-04-22 20:07 ` [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
  2 siblings, 1 reply; 8+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-04-22 20:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira

Move the inline memcmp function, currently only available to boot code
(boot/string.c), into the header with similar inline string functions
(include/asm/string.h) so it may be reused.

Add a _SETUP guard in string.h so not to include the 32/64-bit specific
string headers in boot/ code (16-bit, real mode) and avoid build errors.

Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
 arch/x86/boot/string.c        |  6 ++----
 arch/x86/include/asm/string.h | 11 +++++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index b25c6a9303b7314d5caf5c9306239811705294fe..bbee78637b349e42e9281d8df50d89d48f4490b9 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -15,6 +15,7 @@
 #include <linux/errno.h>
 #include <linux/limits.h>
 #include <asm/asm.h>
+#include <asm/string.h>
 #include "ctype.h"
 #include "string.h"
 
@@ -31,10 +32,7 @@
 
 int memcmp(const void *s1, const void *s2, size_t len)
 {
-	bool diff;
-	asm("repe cmpsb"
-	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
-	return diff;
+	return __inline_memcmp(s1, s2, len);
 }
 
 /*
diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..736a6f6a31f0a68281b4f17415aba0fcd95dc228 100644
--- a/arch/x86/include/asm/string.h
+++ b/arch/x86/include/asm/string.h
@@ -2,11 +2,13 @@
 #ifndef _ASM_X86_STRING_H
 #define _ASM_X86_STRING_H
 
+#ifndef _SETUP
 #ifdef CONFIG_X86_32
 # include <asm/string_32.h>
 #else
 # include <asm/string_64.h>
 #endif
+#endif
 
 static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
 {
@@ -29,4 +31,13 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n)
 	return ret;
 }
 
+static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len)
+{
+	bool diff;
+
+	asm("repe cmpsb"
+	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
+	return diff;
+}
+
 #endif /* _ASM_X86_STRING_H */

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()
  2026-04-22 20:07 [PATCH 0/3] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
  2026-04-22 20:07 ` [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp Mauricio Faria de Oliveira
@ 2026-04-22 20:07 ` Mauricio Faria de Oliveira
  2026-04-23 16:01   ` Jürgen Groß
  2026-04-22 20:07 ` [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
  2 siblings, 1 reply; 8+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-04-22 20:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira

Even with __builtin the compiler may decide to use the out of line function
instead of the inline implementation.

The existing code is broken with gcc-14/15 but not gcc-12/13 (Ubuntu 25.10)
and vmlinux no longer boots with CONFIG_PVH if CONFIG_KASAN_GENERIC is set.

For testing purposes, if the size argument is reduced from 12 to 8 then the
compiler decides to use the inline implementation; that shows results vary.

Switch the builtin to the inline implementation to address it.

Fixes: 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
 arch/x86/include/asm/cpuid/api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/api.h
index 44fa82e1267ce98c7f5f92f69b58f79e235f7261..c3bd1e51067346e817240b484dc0d0e5f02dcc4f 100644
--- a/arch/x86/include/asm/cpuid/api.h
+++ b/arch/x86/include/asm/cpuid/api.h
@@ -203,7 +203,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) &&
 		    (leaves == 0 || ((eax - base) >= leaves)))
 			return base;
 	}

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh()
  2026-04-22 20:07 [PATCH 0/3] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
  2026-04-22 20:07 ` [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp Mauricio Faria de Oliveira
  2026-04-22 20:07 ` [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
@ 2026-04-22 20:07 ` Mauricio Faria de Oliveira
  2026-04-23 16:01   ` Jürgen Groß
  2 siblings, 1 reply; 8+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-04-22 20:07 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira

Even with __builtin the compiler may decide to use the out of line function
instead of the inline implementation.

This particular one (still) generated the inline implementation as expected
(at least in these compiler versions), but this is not guaranteed to remain
the case, as seen with the previous commit.

Switch the builtin to the inline implementation to prevent a similar issue.

Fixes: fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
 arch/x86/platform/pvh/enlighten.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c
index f2053cbe9b0ce3d2178938269607c652ae8f528e..cb442cbd9d828619421babb281bfe9759edbca8a 100644
--- a/arch/x86/platform/pvh/enlighten.c
+++ b/arch/x86/platform/pvh/enlighten.c
@@ -8,6 +8,7 @@
 #include <asm/hypervisor.h>
 #include <asm/e820/api.h>
 #include <asm/x86_init.h>
+#include <asm/string.h>
 
 #include <asm/xen/interface.h>
 
@@ -129,7 +130,7 @@ void __init xen_prepare_pvh(void)
 	 * This must not compile to "call memset" because memset() may be
 	 * instrumented.
 	 */
-	__builtin_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
+	__inline_memset(&pvh_bootparams, 0, sizeof(pvh_bootparams));
 
 	hypervisor_specific_init(xen_guest);
 

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp
  2026-04-22 20:07 ` [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp Mauricio Faria de Oliveira
@ 2026-04-22 20:54   ` David Laight
  2026-04-23 15:58     ` Mauricio Faria de Oliveira
  0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2026-04-22 20:54 UTC (permalink / raw)
  To: Mauricio Faria de Oliveira
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
	kernel-dev, linux-kernel, xen-devel

On Wed, 22 Apr 2026 17:07:45 -0300
Mauricio Faria de Oliveira <mfo@igalia.com> wrote:

> Move the inline memcmp function, currently only available to boot code
> (boot/string.c), into the header with similar inline string functions
> (include/asm/string.h) so it may be reused.

This needs a comment/warning that it is incompatible with normal memcmp()
because it only returns 0/1 not -1/0/1.
Most callers don't care.

	David


> 
> Add a _SETUP guard in string.h so not to include the 32/64-bit specific
> string headers in boot/ code (16-bit, real mode) and avoid build errors.
> 
> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
> ---
>  arch/x86/boot/string.c        |  6 ++----
>  arch/x86/include/asm/string.h | 11 +++++++++++
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
> index b25c6a9303b7314d5caf5c9306239811705294fe..bbee78637b349e42e9281d8df50d89d48f4490b9 100644
> --- a/arch/x86/boot/string.c
> +++ b/arch/x86/boot/string.c
> @@ -15,6 +15,7 @@
>  #include <linux/errno.h>
>  #include <linux/limits.h>
>  #include <asm/asm.h>
> +#include <asm/string.h>
>  #include "ctype.h"
>  #include "string.h"
>  
> @@ -31,10 +32,7 @@
>  
>  int memcmp(const void *s1, const void *s2, size_t len)
>  {
> -	bool diff;
> -	asm("repe cmpsb"
> -	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
> -	return diff;
> +	return __inline_memcmp(s1, s2, len);
>  }
>  
>  /*
> diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
> index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..736a6f6a31f0a68281b4f17415aba0fcd95dc228 100644
> --- a/arch/x86/include/asm/string.h
> +++ b/arch/x86/include/asm/string.h
> @@ -2,11 +2,13 @@
>  #ifndef _ASM_X86_STRING_H
>  #define _ASM_X86_STRING_H
>  
> +#ifndef _SETUP
>  #ifdef CONFIG_X86_32
>  # include <asm/string_32.h>
>  #else
>  # include <asm/string_64.h>
>  #endif
> +#endif
>  
>  static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
>  {
> @@ -29,4 +31,13 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n)
>  	return ret;
>  }
>  
> +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len)
> +{
> +	bool diff;
> +
> +	asm("repe cmpsb"
> +	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
> +	return diff;
> +}
> +
>  #endif /* _ASM_X86_STRING_H */
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp
  2026-04-22 20:54   ` David Laight
@ 2026-04-23 15:58     ` Mauricio Faria de Oliveira
  0 siblings, 0 replies; 8+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-04-23 15:58 UTC (permalink / raw)
  To: David Laight
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
	kernel-dev, linux-kernel, xen-devel

On 2026-04-22 17:54, David Laight wrote:
> On Wed, 22 Apr 2026 17:07:45 -0300
> Mauricio Faria de Oliveira <mfo@igalia.com> wrote:
> 
>> Move the inline memcmp function, currently only available to boot code
>> (boot/string.c), into the header with similar inline string functions
>> (include/asm/string.h) so it may be reused.
> 
> This needs a comment/warning that it is incompatible with normal memcmp()
> because it only returns 0/1 not -1/0/1.
> Most callers don't care.

Thanks for catching and suggesting this.

I can also change it to -1/0/1 in a later patch, to keep v2 only a fix
and split a behavior change, with something like this (lightly tested):

static __always_inline int __inline_memcmp(const void *s1, const void
*s2, size_t len)
{
        bool above, below;

        asm("repe cmpsb"
            : "+S" (s1), "+D" (s2), "+c" (len),
              "=@cca" (above),
              "=@ccb" (below));

        return above - below;
}

cheers,

> 
> 	David
> 
> 
>> 
>> Add a _SETUP guard in string.h so not to include the 32/64-bit specific
>> string headers in boot/ code (16-bit, real mode) and avoid build errors.
>> 
>> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
>> ---
>>  arch/x86/boot/string.c        |  6 ++----
>>  arch/x86/include/asm/string.h | 11 +++++++++++
>>  2 files changed, 13 insertions(+), 4 deletions(-)
>> 
>> diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
>> index b25c6a9303b7314d5caf5c9306239811705294fe..bbee78637b349e42e9281d8df50d89d48f4490b9 100644
>> --- a/arch/x86/boot/string.c
>> +++ b/arch/x86/boot/string.c
>> @@ -15,6 +15,7 @@
>>  #include <linux/errno.h>
>>  #include <linux/limits.h>
>>  #include <asm/asm.h>
>> +#include <asm/string.h>
>>  #include "ctype.h"
>>  #include "string.h"
>>  
>> @@ -31,10 +32,7 @@
>>  
>>  int memcmp(const void *s1, const void *s2, size_t len)
>>  {
>> -	bool diff;
>> -	asm("repe cmpsb"
>> -	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
>> -	return diff;
>> +	return __inline_memcmp(s1, s2, len);
>>  }
>>  
>>  /*
>> diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
>> index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..736a6f6a31f0a68281b4f17415aba0fcd95dc228 100644
>> --- a/arch/x86/include/asm/string.h
>> +++ b/arch/x86/include/asm/string.h
>> @@ -2,11 +2,13 @@
>>  #ifndef _ASM_X86_STRING_H
>>  #define _ASM_X86_STRING_H
>>  
>> +#ifndef _SETUP
>>  #ifdef CONFIG_X86_32
>>  # include <asm/string_32.h>
>>  #else
>>  # include <asm/string_64.h>
>>  #endif
>> +#endif
>>  
>>  static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
>>  {
>> @@ -29,4 +31,13 @@ static __always_inline void *__inline_memset(void *s, int v, size_t n)
>>  	return ret;
>>  }
>>  
>> +static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len)
>> +{
>> +	bool diff;
>> +
>> +	asm("repe cmpsb"
>> +	    : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
>> +	return diff;
>> +}
>> +
>>  #endif /* _ASM_X86_STRING_H */
>>

-- 
Mauricio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base()
  2026-04-22 20:07 ` [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
@ 2026-04-23 16:01   ` Jürgen Groß
  0 siblings, 0 replies; 8+ messages in thread
From: Jürgen Groß @ 2026-04-23 16:01 UTC (permalink / raw)
  To: Mauricio Faria de Oliveira, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 798 bytes --]

On 22.04.26 22:07, Mauricio Faria de Oliveira wrote:
> Even with __builtin the compiler may decide to use the out of line function
> instead of the inline implementation.
> 
> The existing code is broken with gcc-14/15 but not gcc-12/13 (Ubuntu 25.10)
> and vmlinux no longer boots with CONFIG_PVH if CONFIG_KASAN_GENERIC is set.
> 
> For testing purposes, if the size argument is reduced from 12 to 8 then the
> compiler decides to use the inline implementation; that shows results vary.
> 
> Switch the builtin to the inline implementation to address it.
> 
> Fixes: 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()")
> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh()
  2026-04-22 20:07 ` [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
@ 2026-04-23 16:01   ` Jürgen Groß
  0 siblings, 0 replies; 8+ messages in thread
From: Jürgen Groß @ 2026-04-23 16:01 UTC (permalink / raw)
  To: Mauricio Faria de Oliveira, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Alexey Dobriyan, Boris Ostrovsky
  Cc: kernel-dev, linux-kernel, xen-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 691 bytes --]

On 22.04.26 22:07, Mauricio Faria de Oliveira wrote:
> Even with __builtin the compiler may decide to use the out of line function
> instead of the inline implementation.
> 
> This particular one (still) generated the inline implementation as expected
> (at least in these compiler versions), but this is not guaranteed to remain
> the case, as seen with the previous commit.
> 
> Switch the builtin to the inline implementation to prevent a similar issue.
> 
> Fixes: fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()")
> Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-23 16:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 20:07 [PATCH 0/3] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-04-22 20:07 ` [PATCH 1/3] x86/asm, x86/boot: Expose inline memcmp Mauricio Faria de Oliveira
2026-04-22 20:54   ` David Laight
2026-04-23 15:58     ` Mauricio Faria de Oliveira
2026-04-22 20:07 ` [PATCH 2/3] x86/cpuid: fix unbootable VMs by really inlining memcmp() in hypervisor_cpuid_base() Mauricio Faria de Oliveira
2026-04-23 16:01   ` Jürgen Groß
2026-04-22 20:07 ` [PATCH 3/3] x86/pvh: fix unbootable VMs by really inlining memset() in xen_prepare_pvh() Mauricio Faria de Oliveira
2026-04-23 16:01   ` Jürgen Groß

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox