* [PATCH v10 1/4] x86/boot: comment out and document redundant "cc" clobber in memcmp()
2026-09-22 1:36 [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
@ 2026-09-22 1:36 ` Mauricio Faria de Oliveira
2026-09-23 5:52 ` [tip: x86/boot] x86/boot: Remove redundant "cc" clobber in memcmp() and document it tip-bot2 for Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 2/4] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-22 1:36 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
The "cc" clobber remains recognized for source compatibility, but it has
no meaning anymore; it is automatically generated without condition-code
constraints (explanation in [1]; related code in gcc [2] and clang [3]).
Comment out the redundant "cc" clobber for documentation purposes.
Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@zytor.com/
Link: https://lore.kernel.org/all/57b0d188-b256-bde4-43e6-99dae4f59d60@suse.de/ [1]
Link: https://github.com/gcc-mirror/gcc/blob/78d4ac73dd391005b895a6148cd9831e28e1208b/gcc/config/i386/i386.cc#L25355-L25363 [2]
Link: https://github.com/llvm/llvm-project/blob/6dfe1677ab8dffbc6ec13d53a1e0215d75147689/clang/lib/Basic/Targets/X86.h#L299-L301 [3]
Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
arch/x86/boot/string.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 1632d40e1f545ae0665597069b568ea6b6c263e5..e10260ed58b69fc734a4e63f15785a643f414441 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -36,11 +36,15 @@ int memcmp(const void *s1, const void *s2, size_t len)
/*
* Make sure ZF is properly set in the len==0 case because in it,
* RCX==0 and the REPE; CMPSB won't get executed.
+ *
+ * The "cc" clobber has no meaning anymore, just source compatibility.
+ * On x86 the flag status bits are automatically added to the clobber
+ * set when there are no =@ccXY constraints. Keep it as documentation.
*/
asm volatile("test %3, %3\n\t"
"repe cmpsb"
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
- : : "cc", "memory");
+ : : /* "cc", */ "memory");
return diff;
}
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [tip: x86/boot] x86/boot: Remove redundant "cc" clobber in memcmp() and document it
2026-09-22 1:36 ` [PATCH v10 1/4] x86/boot: comment out and document redundant "cc" clobber in memcmp() Mauricio Faria de Oliveira
@ 2026-09-23 5:52 ` tip-bot2 for Mauricio Faria de Oliveira
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for Mauricio Faria de Oliveira @ 2026-09-23 5:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: H. Peter Anvin, Mauricio Faria de Oliveira, Borislav Petkov (AMD),
x86, linux-kernel
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 94509668fccfa098e0a3d57e7093a9afd88aea9f
Gitweb: https://git.kernel.org/tip/94509668fccfa098e0a3d57e7093a9afd88aea9f
Author: Mauricio Faria de Oliveira <mfo@igalia.com>
AuthorDate: Mon, 21 Sep 2026 22:36:32 -03:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 22 Sep 2026 18:22:38 -07:00
x86/boot: Remove redundant "cc" clobber in memcmp() and document it
The "cc" clobber remains recognized for source compatibility, but it has
no meaning anymore; it is automatically generated without condition-code
constraints:
https://lore.kernel.org/all/57b0d188-b256-bde4-43e6-99dae4f59d60@suse.de
Comment out the redundant "cc" clobber for documentation purposes.
[ bp: Massage commit message. ]
Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260921-pvh-kasan-inline-v10-1-08da47943d8e@igalia.com
---
arch/x86/boot/string.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 1632d40..e10260e 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -36,11 +36,15 @@ int memcmp(const void *s1, const void *s2, size_t len)
/*
* Make sure ZF is properly set in the len==0 case because in it,
* RCX==0 and the REPE; CMPSB won't get executed.
+ *
+ * The "cc" clobber has no meaning anymore, just source compatibility.
+ * On x86 the flag status bits are automatically added to the clobber
+ * set when there are no =@ccXY constraints. Keep it as documentation.
*/
asm volatile("test %3, %3\n\t"
"repe cmpsb"
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
- : : "cc", "memory");
+ : : /* "cc", */ "memory");
return diff;
}
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v10 2/4] x86/asm, x86/boot: expose inline memcmp()
2026-09-22 1:36 [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 1/4] x86/boot: comment out and document redundant "cc" clobber in memcmp() Mauricio Faria de Oliveira
@ 2026-09-22 1:36 ` Mauricio Faria de Oliveira
2026-09-23 5:52 ` [tip: x86/boot] x86/asm, x86/boot: Carve out inline memcmp() into a separate header tip-bot2 for Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 3/4] x86/asm: group inline string functions Mauricio Faria de Oliveira
` (2 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-22 1:36 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Move the inline memcmp function currently only available in boot/string.c
into the shared string function header <asm/shared/string.h> to be reused.
This is not done through <asm/string.h> to avoid pulling unnecessary code
in boot/string.c that causes build errors in boot/compressed/string.c
and purgatory/purgatory.ro.
No functional changes.
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
Thanks to David Laight for noticing the return value difference between
inline and regular memcmp().
---
arch/x86/boot/string.c | 17 ++---------------
arch/x86/include/asm/shared/string.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index e10260ed58b69fc734a4e63f15785a643f414441..be454a6864225f3a972c3e81826b77ed4e8a57fe 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/shared/string.h>
#include "ctype.h"
#include "string.h"
@@ -31,21 +32,7 @@
int memcmp(const void *s1, const void *s2, size_t len)
{
- bool diff;
-
- /*
- * Make sure ZF is properly set in the len==0 case because in it,
- * RCX==0 and the REPE; CMPSB won't get executed.
- *
- * The "cc" clobber has no meaning anymore, just source compatibility.
- * On x86 the flag status bits are automatically added to the clobber
- * set when there are no =@ccXY constraints. Keep it as documentation.
- */
- asm volatile("test %3, %3\n\t"
- "repe cmpsb"
- : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
- : : /* "cc", */ "memory");
- return diff;
+ return __inline_memcmp(s1, s2, len);
}
/*
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
new file mode 100644
index 0000000000000000000000000000000000000000..6291653fe629babf15e29060b013d357d8eacf4c
--- /dev/null
+++ b/arch/x86/include/asm/shared/string.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SHARED_STRING_H
+#define _ASM_X86_SHARED_STRING_H
+
+/*
+ * Returns: 0 (equal)
+ * 1 (not equal)
+ *
+ * In contrast, the regular memcmp() follows glibc return value semantics.
+ */
+static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len)
+{
+ bool diff;
+
+ /*
+ * Make sure ZF is properly set in the len==0 case because in it,
+ * RCX==0 and the REPE; CMPSB won't get executed.
+ *
+ * The "cc" clobber has no meaning anymore, just source compatibility.
+ * On x86 the flag status bits are automatically added to the clobber
+ * set when there are no =@ccXY constraints. Keep it as documentation.
+ */
+ asm volatile("test %3, %3\n\t"
+ "repe cmpsb"
+ : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
+ : : /* "cc", */ "memory");
+
+ return diff;
+}
+
+#endif /* _ASM_X86_SHARED_STRING_H */
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [tip: x86/boot] x86/asm, x86/boot: Carve out inline memcmp() into a separate header
2026-09-22 1:36 ` [PATCH v10 2/4] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
@ 2026-09-23 5:52 ` tip-bot2 for Mauricio Faria de Oliveira
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for Mauricio Faria de Oliveira @ 2026-09-23 5:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Mauricio Faria de Oliveira, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 5b6fe00406ce967c556d544a7fc80233341c67c8
Gitweb: https://git.kernel.org/tip/5b6fe00406ce967c556d544a7fc80233341c67c8
Author: Mauricio Faria de Oliveira <mfo@igalia.com>
AuthorDate: Mon, 21 Sep 2026 22:36:33 -03:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 22 Sep 2026 18:41:56 -07:00
x86/asm, x86/boot: Carve out inline memcmp() into a separate header
Move the inline memcmp() function currently only available in boot/string.c
into the shared string function header <asm/shared/string.h> to be reused.
This is not done through <asm/string.h> to avoid pulling unnecessary code
in boot/string.c that causes build errors in boot/compressed/string.c
and purgatory/purgatory.ro.
No functional changes.
[ bp: Massage commit message. ]
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260921-pvh-kasan-inline-v10-2-08da47943d8e@igalia.com
---
arch/x86/boot/string.c | 17 +--------------
arch/x86/include/asm/shared/string.h | 31 +++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 15 deletions(-)
create mode 100644 arch/x86/include/asm/shared/string.h
diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index e10260e..be454a6 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/shared/string.h>
#include "ctype.h"
#include "string.h"
@@ -31,21 +32,7 @@
int memcmp(const void *s1, const void *s2, size_t len)
{
- bool diff;
-
- /*
- * Make sure ZF is properly set in the len==0 case because in it,
- * RCX==0 and the REPE; CMPSB won't get executed.
- *
- * The "cc" clobber has no meaning anymore, just source compatibility.
- * On x86 the flag status bits are automatically added to the clobber
- * set when there are no =@ccXY constraints. Keep it as documentation.
- */
- asm volatile("test %3, %3\n\t"
- "repe cmpsb"
- : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
- : : /* "cc", */ "memory");
- return diff;
+ return __inline_memcmp(s1, s2, len);
}
/*
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
new file mode 100644
index 0000000..6291653
--- /dev/null
+++ b/arch/x86/include/asm/shared/string.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SHARED_STRING_H
+#define _ASM_X86_SHARED_STRING_H
+
+/*
+ * Returns: 0 (equal)
+ * 1 (not equal)
+ *
+ * In contrast, the regular memcmp() follows glibc return value semantics.
+ */
+static __always_inline int __inline_memcmp(const void *s1, const void *s2, size_t len)
+{
+ bool diff;
+
+ /*
+ * Make sure ZF is properly set in the len==0 case because in it,
+ * RCX==0 and the REPE; CMPSB won't get executed.
+ *
+ * The "cc" clobber has no meaning anymore, just source compatibility.
+ * On x86 the flag status bits are automatically added to the clobber
+ * set when there are no =@ccXY constraints. Keep it as documentation.
+ */
+ asm volatile("test %3, %3\n\t"
+ "repe cmpsb"
+ : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
+ : : /* "cc", */ "memory");
+
+ return diff;
+}
+
+#endif /* _ASM_X86_SHARED_STRING_H */
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v10 3/4] x86/asm: group inline string functions
2026-09-22 1:36 [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 1/4] x86/boot: comment out and document redundant "cc" clobber in memcmp() Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 2/4] x86/asm, x86/boot: expose inline memcmp() Mauricio Faria de Oliveira
@ 2026-09-22 1:36 ` Mauricio Faria de Oliveira
2026-09-23 5:52 ` [tip: x86/boot] x86/asm: Group " tip-bot2 for Mauricio Faria de Oliveira
2026-09-22 1:36 ` [PATCH v10 4/4] x86/cpuid: fix unbootable VMs by really inlining memcmp() in cpuid_base_hypervisor() and xen_prepare_pvh() Mauricio Faria de Oliveira
2026-09-22 3:58 ` [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Borislav Petkov
4 siblings, 1 reply; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-22 1:36 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
Cc: kernel-dev, linux-kernel, xen-devel, Mauricio Faria de Oliveira
Group the __inline string functions in the same header.
Use <asm/shared/string.h> since __inline_memcmp() must remain there for use
by arch/x86/boot/string.c.
No functional changes.
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
arch/x86/include/asm/shared/string.h | 21 +++++++++++++++++++++
arch/x86/include/asm/string.h | 21 +--------------------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
index 6291653fe629babf15e29060b013d357d8eacf4c..6bef90d62a21138ec56c939ffc474732999bf465 100644
--- a/arch/x86/include/asm/shared/string.h
+++ b/arch/x86/include/asm/shared/string.h
@@ -2,6 +2,27 @@
#ifndef _ASM_X86_SHARED_STRING_H
#define _ASM_X86_SHARED_STRING_H
+static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
+{
+ void *ret = to;
+
+ asm volatile("rep movsb"
+ : "+D" (to), "+S" (from), "+c" (len)
+ : : "memory");
+ return ret;
+}
+
+static __always_inline void *__inline_memset(void *s, int v, size_t n)
+{
+ void *ret = s;
+
+ asm volatile("rep stosb"
+ : "+D" (s), "+c" (n)
+ : "a" ((uint8_t)v)
+ : "memory");
+ return ret;
+}
+
/*
* Returns: 0 (equal)
* 1 (not equal)
diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
index 9cb5aae7fba9ffcf0f5af8f939d30467750ccaa9..dbf59f0d4cca71e2ddce0d8764aeec8782236669 100644
--- a/arch/x86/include/asm/string.h
+++ b/arch/x86/include/asm/string.h
@@ -8,25 +8,6 @@
# include <asm/string_64.h>
#endif
-static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
-{
- void *ret = to;
-
- asm volatile("rep movsb"
- : "+D" (to), "+S" (from), "+c" (len)
- : : "memory");
- return ret;
-}
-
-static __always_inline void *__inline_memset(void *s, int v, size_t n)
-{
- void *ret = s;
-
- asm volatile("rep stosb"
- : "+D" (s), "+c" (n)
- : "a" ((uint8_t)v)
- : "memory");
- return ret;
-}
+#include <asm/shared/string.h>
#endif /* _ASM_X86_STRING_H */
--
2.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [tip: x86/boot] x86/asm: Group inline string functions
2026-09-22 1:36 ` [PATCH v10 3/4] x86/asm: group inline string functions Mauricio Faria de Oliveira
@ 2026-09-23 5:52 ` tip-bot2 for Mauricio Faria de Oliveira
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for Mauricio Faria de Oliveira @ 2026-09-23 5:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Mauricio Faria de Oliveira, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 85f11c17b261772cddc4606f98f6c604aded4607
Gitweb: https://git.kernel.org/tip/85f11c17b261772cddc4606f98f6c604aded4607
Author: Mauricio Faria de Oliveira <mfo@igalia.com>
AuthorDate: Mon, 21 Sep 2026 22:36:34 -03:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 22 Sep 2026 18:53:32 -07:00
x86/asm: Group inline string functions
Group the __inline string functions in the same header.
Use <asm/shared/string.h> since __inline_memcmp() must remain there for use
by arch/x86/boot/string.c.
No functional changes.
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260921-pvh-kasan-inline-v10-3-08da47943d8e@igalia.com
---
arch/x86/include/asm/shared/string.h | 21 +++++++++++++++++++++
arch/x86/include/asm/string.h | 21 +--------------------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/arch/x86/include/asm/shared/string.h b/arch/x86/include/asm/shared/string.h
index 6291653..6bef90d 100644
--- a/arch/x86/include/asm/shared/string.h
+++ b/arch/x86/include/asm/shared/string.h
@@ -2,6 +2,27 @@
#ifndef _ASM_X86_SHARED_STRING_H
#define _ASM_X86_SHARED_STRING_H
+static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
+{
+ void *ret = to;
+
+ asm volatile("rep movsb"
+ : "+D" (to), "+S" (from), "+c" (len)
+ : : "memory");
+ return ret;
+}
+
+static __always_inline void *__inline_memset(void *s, int v, size_t n)
+{
+ void *ret = s;
+
+ asm volatile("rep stosb"
+ : "+D" (s), "+c" (n)
+ : "a" ((uint8_t)v)
+ : "memory");
+ return ret;
+}
+
/*
* Returns: 0 (equal)
* 1 (not equal)
diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h
index 9cb5aae..dbf59f0 100644
--- a/arch/x86/include/asm/string.h
+++ b/arch/x86/include/asm/string.h
@@ -8,25 +8,6 @@
# include <asm/string_64.h>
#endif
-static __always_inline void *__inline_memcpy(void *to, const void *from, size_t len)
-{
- void *ret = to;
-
- asm volatile("rep movsb"
- : "+D" (to), "+S" (from), "+c" (len)
- : : "memory");
- return ret;
-}
-
-static __always_inline void *__inline_memset(void *s, int v, size_t n)
-{
- void *ret = s;
-
- asm volatile("rep stosb"
- : "+D" (s), "+c" (n)
- : "a" ((uint8_t)v)
- : "memory");
- return ret;
-}
+#include <asm/shared/string.h>
#endif /* _ASM_X86_STRING_H */
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v10 4/4] x86/cpuid: fix unbootable VMs by really inlining memcmp() in cpuid_base_hypervisor() and xen_prepare_pvh()
2026-09-22 1:36 [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
` (2 preceding siblings ...)
2026-09-22 1:36 ` [PATCH v10 3/4] x86/asm: group inline string functions Mauricio Faria de Oliveira
@ 2026-09-22 1:36 ` Mauricio Faria de Oliveira
2026-09-23 5:52 ` [tip: x86/boot] x86/pvh: Really inline memcmp() and memset() to fix unbootable VMs tip-bot2 for Mauricio Faria de Oliveira
2026-09-22 3:58 ` [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Borislav Petkov
4 siblings, 1 reply; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-22 1:36 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Juergen Gross, Alexey Dobriyan, Boris Ostrovsky,
Jan Beulich, Brian Gerst
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.
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.
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@igalia.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
---
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 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) &&
(leaves == 0 || ((eax - base) >= leaves)))
return base;
}
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.47.3
^ permalink raw reply [flat|nested] 13+ messages in thread* [tip: x86/boot] x86/pvh: Really inline memcmp() and memset() to fix unbootable VMs
2026-09-22 1:36 ` [PATCH v10 4/4] x86/cpuid: fix unbootable VMs by really inlining memcmp() in cpuid_base_hypervisor() and xen_prepare_pvh() Mauricio Faria de Oliveira
@ 2026-09-23 5:52 ` tip-bot2 for Mauricio Faria de Oliveira
0 siblings, 0 replies; 13+ messages in thread
From: tip-bot2 for Mauricio Faria de Oliveira @ 2026-09-23 5:52 UTC (permalink / raw)
To: linux-tip-commits
Cc: Mauricio Faria de Oliveira, Borislav Petkov (AMD),
Juergen Gross, x86, linux-kernel
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@igalia.com>
AuthorDate: Mon, 21 Sep 2026 22:36:35 -03:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
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@igalia.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://patch.msgid.link/20260921-pvh-kasan-inline-v10-4-08da47943d8e@igalia.com
---
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);
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN)
2026-09-22 1:36 [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Mauricio Faria de Oliveira
` (3 preceding siblings ...)
2026-09-22 1:36 ` [PATCH v10 4/4] x86/cpuid: fix unbootable VMs by really inlining memcmp() in cpuid_base_hypervisor() and xen_prepare_pvh() Mauricio Faria de Oliveira
@ 2026-09-22 3:58 ` Borislav Petkov
2026-09-22 22:13 ` Mauricio Faria de Oliveira
4 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2026-09-22 3:58 UTC (permalink / raw)
To: Mauricio Faria de Oliveira
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On Mon, Sep 21, 2026 at 10:36:31PM -0300, Mauricio Faria de Oliveira wrote:
> 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 use 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; see details below.
So, this whole deal doesn't sound to me like we need to backport it to stable
- it rather looks more like fixing some configs which want to enable KASAN on
PVH guests.
In that case, I'll queue this for 7.4.
If this needs to go to stable, then there better be a pretty good reason for
it.
Right?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN)
2026-09-22 3:58 ` [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN) Borislav Petkov
@ 2026-09-22 22:13 ` Mauricio Faria de Oliveira
2026-09-23 1:12 ` Borislav Petkov
0 siblings, 1 reply; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-22 22:13 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On 2026-09-22 00:58, Borislav Petkov wrote:
> On Mon, Sep 21, 2026 at 10:36:31PM -0300, Mauricio Faria de Oliveira wrote:
>> 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 use 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; see details below.
>
> So, this whole deal doesn't sound to me like we need to backport it to stable
> - it rather looks more like fixing some configs which want to enable KASAN on
> PVH guests.
>
> In that case, I'll queue this for 7.4.
>
> If this needs to go to stable, then there better be a pretty good reason for
> it.
>
> Right?
I think that is fine, yes. Even though it's a boot failure, actually
hitting it depends on all of: CONFIG_KASAN, CONFIG_PVH, booting from the
PVH entry point, _plus_ a compiler version that triggers it.
Nonetheless, this may be picked up for stable due to the Fixes: tags,
but I can provide backports as needed.
BTW, I just realized that the title of patch 4/4 is missing memset().
Would you mind adding it, please? Or I can send v11.
-x86/cpuid: fix unbootable VMs by really inlining memcmp() in
cpuid_base_hypervisor() and xen_prepare_pvh()
+x86/cpuid: fix unbootable VMs by really inlining memcmp() and memset()
in cpuid_base_hypervisor() and xen_prepare_pvh()
Thanks,
--
Mauricio
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN)
2026-09-22 22:13 ` Mauricio Faria de Oliveira
@ 2026-09-23 1:12 ` Borislav Petkov
2026-09-23 12:41 ` Mauricio Faria de Oliveira
0 siblings, 1 reply; 13+ messages in thread
From: Borislav Petkov @ 2026-09-23 1:12 UTC (permalink / raw)
To: Mauricio Faria de Oliveira
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On Tue, Sep 22, 2026 at 07:13:35PM -0300, Mauricio Faria de Oliveira wrote:
> I think that is fine, yes. Even though it's a boot failure, actually
> hitting it depends on all of: CONFIG_KASAN, CONFIG_PVH, booting from the
> PVH entry point, _plus_ a compiler version that triggers it.
>
> Nonetheless, this may be picked up for stable due to the Fixes: tags,
> but I can provide backports as needed.
Right, just consider all the bandwidth of the folks involved downstream:
stable team and all distros backporting stuff every day. This sounds like an
exotic thing so let's be conservative here pls.
> BTW, I just realized that the title of patch 4/4 is missing memset().
> Would you mind adding it, please? Or I can send v11.
> -x86/cpuid: fix unbootable VMs by really inlining memcmp() in
> cpuid_base_hypervisor() and xen_prepare_pvh()
> +x86/cpuid: fix unbootable VMs by really inlining memcmp() and memset()
> in cpuid_base_hypervisor() and xen_prepare_pvh()
Sure, np.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v10 0/4] x86/pvh: fix unbootable VMs again (PVH + KASAN)
2026-09-23 1:12 ` Borislav Petkov
@ 2026-09-23 12:41 ` Mauricio Faria de Oliveira
0 siblings, 0 replies; 13+ messages in thread
From: Mauricio Faria de Oliveira @ 2026-09-23 12:41 UTC (permalink / raw)
To: Borislav Petkov
Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
Juergen Gross, Alexey Dobriyan, Boris Ostrovsky, Jan Beulich,
Brian Gerst, kernel-dev, linux-kernel, xen-devel
On 2026-09-22 22:12, Borislav Petkov wrote:
> On Tue, Sep 22, 2026 at 07:13:35PM -0300, Mauricio Faria de Oliveira wrote:
>> I think that is fine, yes. Even though it's a boot failure, actually
>> hitting it depends on all of: CONFIG_KASAN, CONFIG_PVH, booting from the
>> PVH entry point, _plus_ a compiler version that triggers it.
>>
>> Nonetheless, this may be picked up for stable due to the Fixes: tags,
>> but I can provide backports as needed.
>
> Right, just consider all the bandwidth of the folks involved downstream:
> stable team and all distros backporting stuff every day. This sounds like an
> exotic thing so let's be conservative here pls.
Absolutely. I worked for a long time with distro kernels and
backporting. I just mentioned that it is possible for this to be picked
up, and that if it is, then I can help with it if needed; not pushing.
:)
>> BTW, I just realized that the title of patch 4/4 is missing memset().
>> Would you mind adding it, please? Or I can send v11.
>> -x86/cpuid: fix unbootable VMs by really inlining memcmp() in
>> cpuid_base_hypervisor() and xen_prepare_pvh()
>> +x86/cpuid: fix unbootable VMs by really inlining memcmp() and memset()
>> in cpuid_base_hypervisor() and xen_prepare_pvh()
>
> Sure, np.
Thanks!
>
> Thx.
--
Mauricio
^ permalink raw reply [flat|nested] 13+ messages in thread