[tip: x86/boot] x86/pvh: Really inline memcmp() and memset() to fix unbootable VMs

From: tip-bot2 for Mauricio Faria de Oliveira

Date: Wed Sep 23 2026 - 01:56:35 EST


The following commit has been merged into the x86/boot branch of tip:

Commit-ID: b24bc9dec9c89d01ccb675a55cda6831dc048ce9
Gitweb: https://git.kernel.org/tip/b24bc9dec9c89d01ccb675a55cda6831dc048ce9
Author: Mauricio Faria de Oliveira <mfo@xxxxxxxxxx>
AuthorDate: Mon, 21 Sep 2026 22:36:35 -03:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Tue, 22 Sep 2026 19:03:57 -07:00

x86/pvh: Really inline memcmp() and memset() to fix unbootable VMs

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.
The instrumented out of line function performs a memory access to a region not
yet initialized by KASAN, as it is still in the PVH kernel entry point.

For testing purposes, if the size argument in cpuid_base_hypervisor() is
reduced from 12 to 8 the compiler decides to use the inline implementation.
In xen_prepare_pvh(), it (still) decides to use the inline implementation
(at least in these compiler versions), but it is not guaranteed to remain.

Switch the builtin to the inline implementation to address this.

[ bp: Massage commit message. ]

Fixes: 416a33c9afce ("x86/cpu: fix unbootable VMs by inlining memcmp() in hypervisor_cpuid_base()")
Fixes: fbe5a6dfe492 ("xen, pvh: fix unbootable VMs by inlining memset() in xen_prepare_pvh()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@xxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
Link: https://patch.msgid.link/20260921-pvh-kasan-inline-v10-4-08da47943d8e@xxxxxxxxxx
---
arch/x86/include/asm/cpuid/api.h | 2 +-
arch/x86/platform/pvh/enlighten.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/api.h
index 82eddfa..2d9f3d4 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) &&
(leaves == 0 || ((eax - base) >= leaves)))
return base;
}
diff --git a/arch/x86/platform/pvh/enlighten.c b/arch/x86/platform/pvh/enlighten.c
index f2053cb..cb442cb 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);