[tip: x86/boot] x86/tdx: Share tdx_panic() with the EFI stub
From: tip-bot2 for Ard Biesheuvel
Date: Mon Sep 28 2026 - 23:02:06 EST
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 0ffdb6c1ea44ddb40794b9c20a39b8fb30551875
Gitweb: https://git.kernel.org/tip/0ffdb6c1ea44ddb40794b9c20a39b8fb30551875
Author: Ard Biesheuvel <ardb@xxxxxxxxxx>
AuthorDate: Fri, 25 Sep 2026 09:51:39 +02:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Mon, 28 Sep 2026 15:07:42 -07:00
x86/tdx: Share tdx_panic() with the EFI stub
Move the implementation of tdx_panic() into the source file that is
shared with the decompressor and the EFI stub.
Use memcpy() and strnlen() instead of strtomem_pad(), as the latter does
not exist in the early boot code. Avoid fortify instrumentation in the
decompressor/EFI stub by defining __NO_FORTIFY before including
tdx-shared.c
Note that __tdx_hypercall() may call __tdx_hypercall_failed() if the
hypercall returns with an error (while it should never return to begin
with). __tdx_hypercall_failed() calls the decompressor's error()
routine, which prints a message and then loops forever.
When called from the EFI stub, this error() call may attempt to use port
I/O to the default serial port rather than the TDX hypercalls which the
decompressor uses normally to print diagnostics to the console, but this
is fine: given that this situation only occurs after a catastrophic
error, and a subsequent spurious return from tdx_panic(), whether
error() uses port I/O or not is rather moot at that point, as long as it
never returns.
Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
Link: https://patch.msgid.link/20260925075137.44298-6-ardb@xxxxxxxxxx
---
arch/x86/boot/compressed/tdx-shared.c | 2 +-
arch/x86/coco/tdx/tdx-shared.c | 31 +++++++++++++++++++++++-
arch/x86/coco/tdx/tdx.c | 35 +--------------------------
arch/x86/include/asm/shared/tdx.h | 1 +-
4 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/arch/x86/boot/compressed/tdx-shared.c b/arch/x86/boot/compressed/tdx-shared.c
index 5ac4376..dc38047 100644
--- a/arch/x86/boot/compressed/tdx-shared.c
+++ b/arch/x86/boot/compressed/tdx-shared.c
@@ -1,2 +1,4 @@
+#define __NO_FORTIFY
+
#include "error.h"
#include "../../coco/tdx/tdx-shared.c"
diff --git a/arch/x86/coco/tdx/tdx-shared.c b/arch/x86/coco/tdx/tdx-shared.c
index 1655aa5..29661d8 100644
--- a/arch/x86/coco/tdx/tdx-shared.c
+++ b/arch/x86/coco/tdx/tdx-shared.c
@@ -89,3 +89,34 @@ noinstr u64 __tdx_hypercall(struct tdx_module_args *args)
/* TDVMCALL leaf return code is in R10 */
return args->r10;
}
+
+void __noreturn tdx_panic(const char *msg)
+{
+ struct tdx_module_args args = {
+ .r10 = TDX_HYPERCALL_STANDARD,
+ .r11 = TDVMCALL_REPORT_FATAL_ERROR,
+ .r12 = 0, /* Error code: 0 is Panic */
+ };
+ /* Define register order according to the GHCI */
+ struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; } message = {};
+
+ /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
+ memcpy(&message, msg, strnlen(msg, sizeof(message)));
+
+ args.r8 = message.r8;
+ args.r9 = message.r9;
+ args.r14 = message.r14;
+ args.r15 = message.r15;
+ args.rdi = message.rdi;
+ args.rsi = message.rsi;
+ args.rbx = message.rbx;
+ args.rdx = message.rdx;
+
+ /*
+ * This hypercall should never return and it is not safe
+ * to keep the guest running. Call it forever if it
+ * happens to return.
+ */
+ while (1)
+ __tdx_hypercall(&args);
+}
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index f904a63..a9a16d0 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -198,41 +198,6 @@ u64 tdx_hcall_get_quote(u8 *buf, size_t size)
}
EXPORT_SYMBOL_GPL(tdx_hcall_get_quote);
-static void __noreturn tdx_panic(const char *msg)
-{
- struct tdx_module_args args = {
- .r10 = TDX_HYPERCALL_STANDARD,
- .r11 = TDVMCALL_REPORT_FATAL_ERROR,
- .r12 = 0, /* Error code: 0 is Panic */
- };
- union {
- /* Define register order according to the GHCI */
- struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; };
-
- char bytes[64] __nonstring;
- } message;
-
- /* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
- strtomem_pad(message.bytes, msg, '\0');
-
- args.r8 = message.r8;
- args.r9 = message.r9;
- args.r14 = message.r14;
- args.r15 = message.r15;
- args.rdi = message.rdi;
- args.rsi = message.rsi;
- args.rbx = message.rbx;
- args.rdx = message.rdx;
-
- /*
- * This hypercall should never return and it is not safe
- * to keep the guest running. Call it forever if it
- * happens to return.
- */
- while (1)
- __tdx_hypercall(&args);
-}
-
/*
* The kernel cannot handle #VEs when accessing normal kernel memory. Ensure
* that no #VE will be delivered for accesses to TD-private memory.
diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
index f20e91d..e578525 100644
--- a/arch/x86/include/asm/shared/tdx.h
+++ b/arch/x86/include/asm/shared/tdx.h
@@ -171,6 +171,7 @@ static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
return __tdx_hypercall(&args);
}
+void __noreturn tdx_panic(const char *msg);
/* Called from __tdx_hypercall() for unrecoverable failure */
void __noreturn __tdx_hypercall_failed(void);