[PATCH v3 08/11] arm64: drtm: Add drtm_entry point to head.S
Jason Gunthorpe
jgg at nvidia.com
Fri Nov 20 09:52:01 PST 2026
The DRTM launch defined by DEN0113 cannot use primary_entry because the
spec defines a different launch protocol. drtm_entry is a small trampoline
that validates the DRTM provided data matches the location expected from
the link layout, acquires the DTB through an EFI stub writable handoff
struct and then jumps to primary_entry.
Add drivers/firmware/drtm/arm64.c, as later patches and series will need more
kernel side functions.
Passing the fdt address like this will require security hardening in
future series.
Signed-off-by: Jason Gunthorpe <jgg at nvidia.com>
---
arch/arm64/include/asm/drtm.h | 20 ++++++
arch/arm64/kernel/head.S | 83 +++++++++++++++++++++++
arch/arm64/kernel/vmlinux.lds.S | 6 ++
drivers/firmware/Makefile | 1 +
drivers/firmware/drtm/Makefile | 2 +
drivers/firmware/drtm/arm64.c | 10 +++
drivers/firmware/efi/libstub/efistub.h | 14 ++++
drivers/firmware/efi/libstub/image_info.S | 2 +
8 files changed, 138 insertions(+)
create mode 100644 drivers/firmware/drtm/Makefile
create mode 100644 drivers/firmware/drtm/arm64.c
diff --git a/arch/arm64/include/asm/drtm.h b/arch/arm64/include/asm/drtm.h
index 34201bc092bcc6..e74328808466c0 100644
--- a/arch/arm64/include/asm/drtm.h
+++ b/arch/arm64/include/asm/drtm.h
@@ -176,6 +176,10 @@
#define ARM_DRTM_ALREADY_CLOSED -11
#define ARM_DRTM_TPM_ERROR -12
+/* Offsets in struct arm64_drtm_handoff */
+#define ARM64_DRTM_HANDOFF_FDT_ADDR_OFFSET 0
+#define ARM64_DRTM_HANDOFF_ENABLED_OFFSET 8
+
#ifndef __ASSEMBLY__
#include <linux/bitfield.h>
@@ -301,5 +305,21 @@ static inline s64 arm_drtm_enable_secure_interrupts(void)
return res.a0;
}
+/*
+ * Since we cannot pass a parameter through the launch to drtm_entry any
+ * additional data is written by the stub here.
+ */
+struct arm64_drtm_handoff {
+ __le64 fdt_addr;
+ u8 drtm_enabled;
+};
+
+static_assert(offsetof(struct arm64_drtm_handoff, fdt_addr) ==
+ ARM64_DRTM_HANDOFF_FDT_ADDR_OFFSET);
+static_assert(offsetof(struct arm64_drtm_handoff, drtm_enabled) ==
+ ARM64_DRTM_HANDOFF_ENABLED_OFFSET);
+
+extern struct arm64_drtm_handoff drtm_handoff;
+
#endif /* !__ASSEMBLY__ */
#endif /* __ASM_DRTM_H */
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index d6ba3c0af81190..dbc8a7cc0938f4 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -21,6 +21,7 @@
#include <asm/asm-offsets.h>
#include <asm/cache.h>
#include <asm/cputype.h>
+#include <asm/drtm.h>
#include <asm/el2_setup.h>
#include <asm/elf.h>
#include <asm/image.h>
@@ -35,6 +36,7 @@
#include <asm/stacktrace/frame.h>
#include <asm/thread_info.h>
#include <asm/virt.h>
+#include <uapi/linux/psci.h>
#include "efi-header.S"
@@ -131,6 +133,87 @@ SYM_CODE_START(primary_entry)
SYM_CODE_END(primary_entry)
__INIT
+#ifdef CONFIG_ARM64_DRTM
+/*
+ * Entry point used by a DRTM launch. Verify that information provided by the
+ * EFI stub matches expectations. We rely on an untrusted-write/trusted-verify
+ * approach so this doesn't have to deal with writing to cache-off memory. Per
+ * DEN0113 R45380, the launch supplies:
+ *
+ * x0 = physical base of the DLME region
+ * x1 = offset of thee DLME Data, which is several tables written by
+ * the launch to pass trusted information to the post launch kernel
+ *
+ * These values must match the link layout in vmlinux.lds.S or the launch is
+ * invalid. The EFI stub will get them from the efi_image_info and pass them
+ * into arm_drtm_parameters.
+ *
+ * DEN0113 R45450-R45470 specify the remaining entry state as the PSCI CPU_ON
+ * initial state: AArch64 at the highest Non-secure EL, little-endian, with the
+ * MMU and D-cache disabled and Non-secure asynchronous/debug exceptions
+ * masked.
+ *
+ * Per DEN0113 R45220 the launch cleans and invalidates the whole "DLME region"
+ * which is everything from _text till past __drtm_dlme_start before
+ * it measures the image. Thus the handoff data written into the region by the
+ * EFI stub is safely readable here with the MMU off.
+ */
+SYM_CODE_START(drtm_entry)
+ /* Verify that x0 is the runtime physical address of _text */
+ adr_l x2, _text
+ cmp x0, x2
+ b.ne .Ldrtm_bad_entry
+
+ /* x0 + x1 must be the runtime physical start of the DLME data */
+ add x3, x0, x1
+ adr_l x4, __drtm_dlme_start
+ cmp x3, x4
+ b.ne .Ldrtm_bad_entry
+
+ /* Stub must set drtm_enabled */
+ adr_l x4, drtm_handoff
+ ldrb w2, [x4, #ARM64_DRTM_HANDOFF_ENABLED_OFFSET]
+ cbz x2, .Ldrtm_bad_entry
+
+ /* primary_entry(handoff->fdt_addr, 0, 0, 0) */
+ ldr x0, [x4, #ARM64_DRTM_HANDOFF_FDT_ADDR_OFFSET]
+ mov x1, xzr
+ mov x2, xzr
+ mov x3, xzr
+ b primary_entry
+
+ /*
+ * Can't continue, launch is corrupted, spec says the DLME can call
+ * SET_ERROR which should forward the error to the next boot for
+ * display.
+ */
+.Ldrtm_bad_entry:
+ ldr w0, =ARM_DRTM_SMC_SET_ERROR
+ mov x1, #ARM_DRTM_MAKE_ERROR(ARM_DRTM_ERROR_PHASE_DLME,
+ ARM_DRTM_ERROR_ID_VENDOR, 0)
+ mov x2, xzr
+ mov x3, xzr
+ mov x4, xzr
+ mov x5, xzr
+ mov x6, xzr
+ mov x7, xzr
+ smc #0
+ /* Cold-reset the machine as required after reporting a DLME error */
+ ldr w0, =PSCI_0_2_FN_SYSTEM_RESET
+ mov x1, xzr
+ mov x2, xzr
+ mov x3, xzr
+ mov x4, xzr
+ mov x5, xzr
+ mov x6, xzr
+ mov x7, xzr
+ smc #0
+ /* FW is really broken, just hang. */
+1: wfe
+ b 1b
+SYM_CODE_END(drtm_entry)
+#endif
+
SYM_CODE_START_LOCAL(record_mmu_state)
mrs x19, CurrentEL
cmp x19, #CurrentEL_EL2
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index f4e9fd90cd1b12..a68881189f2313 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -380,6 +380,8 @@ SECTIONS
* DLME Region Address = _text's PA ie the start of Image
* DLME Region Size = DLME Data Offset + "Minimum Size of DLME data"
* DLME Image Start Offset = __drtm_measured_start - _text
+ * DLME Entry Point Offset = drtm_entry - __drtm_measured_start
+ * (in .init.text)
* DLME Image Size = __drtm_measured_end - __drtm_measured_start
* DLME Data Offset = __drtm_dlme_start - _text
* Normal World DCE region address = PA of __drtm_dlme_start +
@@ -466,6 +468,10 @@ ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
"HYP init code too big")
ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
"ID map text too big or misaligned")
+#ifdef CONFIG_ARM64_DRTM
+ASSERT(drtm_entry >= __drtm_measured_start && drtm_entry < __drtm_measured_end,
+ "DRTM entry is outside the measured image")
+#endif
#ifdef CONFIG_HIBERNATION
ASSERT(__hibernate_exit_text_end - __hibernate_exit_text_start <= SZ_4K,
"Hibernate exit text is bigger than 4 KiB")
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 50b3383131522d..7f74fd1bf75bda 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -30,6 +30,7 @@ obj-y += arm_rmm/
obj-y += arm_scmi/
obj-y += broadcom/
obj-y += cirrus/
+obj-y += drtm/
obj-y += meson/
obj-y += microchip/
obj-$(CONFIG_COREBOOT_FIRMWARE) += coreboot/
diff --git a/drivers/firmware/drtm/Makefile b/drivers/firmware/drtm/Makefile
new file mode 100644
index 00000000000000..658798bfd17801
--- /dev/null
+++ b/drivers/firmware/drtm/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_ARM64_DRTM) += arm64.o
diff --git a/drivers/firmware/drtm/arm64.c b/drivers/firmware/drtm/arm64.c
new file mode 100644
index 00000000000000..bf736ceb7f0368
--- /dev/null
+++ b/drivers/firmware/drtm/arm64.c
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES
+ *
+ * Support functions for ARM DEN 0113 "DRTM Architecture for Arm"
+ */
+#include <linux/efi.h>
+
+#include <asm/drtm.h>
+
+struct arm64_drtm_handoff drtm_handoff __efi_data_handoff;
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 154d2aefe6505f..386d65a3943af7 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1182,6 +1182,8 @@ struct efi_image_info {
#ifdef CONFIG_ARM64_DRTM
s32 __drtm_measured_start_offset;
s32 __drtm_measured_end_offset;
+ s32 drtm_entry_offset;
+ s32 drtm_handoff_offset;
#endif
};
@@ -1241,6 +1243,18 @@ efistub_drtm_measured_size(const struct efi_image_info *image_info)
return image_info->__drtm_measured_end_offset -
image_info->__drtm_measured_start_offset;
}
+
+static inline unsigned long
+efistub_drtm_entry_offset(const struct efi_image_info *image_info)
+{
+ return image_info->drtm_entry_offset - image_info->_text_offset;
+}
+
+static inline void *
+efistub_drtm_handoff(const struct efi_image_info *image_info)
+{
+ return offset_to_ptr(&image_info->drtm_handoff_offset);
+}
#endif
efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
diff --git a/drivers/firmware/efi/libstub/image_info.S b/drivers/firmware/efi/libstub/image_info.S
index 065bbfdf8fabad..adf82ad083b354 100644
--- a/drivers/firmware/efi/libstub/image_info.S
+++ b/drivers/firmware/efi/libstub/image_info.S
@@ -21,4 +21,6 @@ __efistub_efistub_image_info:
#ifdef CONFIG_EFI_STUB_DRTM
.long __drtm_measured_start - 0b
.long __drtm_measured_end - 0b
+ .long drtm_entry - 0b
+ .long drtm_handoff - .
#endif
--
2.43.0
More information about the linux-riscv
mailing list