[kvm-unit-tests PATCH v3 01/17] x86/run_in_user: Add an "end branch" marker on the user_mode destination

Sean Christopherson
2025-11-14T00:13:03Z

Add an endbr64 at the user_mode "entry point" so that run_in_user() can be
used when CET's Indirect Branch Tracking is enabled.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
lib/x86/usermode.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c
index c3ec0ad7..f4ba0af4 100644
--- a/lib/x86/usermode.c
+++ b/lib/x86/usermode.c
@@ -68,6 +68,9 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector,
"iretq\n"

"user_mode:\n\t"
+#ifdef __x86_64__
+ "endbr64\n\t"
+#endif
/* Back up volatile registers before invoking func */
"push %%rcx\n\t"
"push %%rdx\n\t"
--
2.52.0.rc1.455.g30608eb744-goog