Skip to contentSkip to conversation

x86/kexec: Replace CALL+UD2 pattern with JMP

PATCH In review Andrew Cooper 2 participants 2 messages Dec 5, 2025 – Dec 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/kexec: Replace CALL+UD2 pattern with JMP

Linux jumps to the target image rather than calling it. Switch to using JMP, and drop the trailing UD2s.

Linux does have a mode, named CONFIG_KEXEC_JUMP, where the target image can be returned from, but that involves extra metadata and setting up a stack within the target image which Xen doesn't support at the moment.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/x86_64/kexec_reloc.S | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
xen/arch/x86/x86_64/kexec_reloc.S +4 -7
index 50ba454abd48..b52d31a654e0 100644
@@ -75,10 +75,8 @@ FUNC(kexec_reloc, PAGE_SIZE)
         testq   $KEXEC_RELOC_FLAG_COMPAT, %r8
         jnz     .L_call_32_bit
 
-.L_call_64_bit:
-        /* Call the image entry point.  This should never return. */
-        callq   *%rbp
-        ud2
+        /* Jump to the image entry point */
+        jmp     *%rbp
 
 .L_call_32_bit:
         /* Setup IDT. */
@@ -170,9 +168,8 @@ FUNC_LOCAL(compatibility_mode)
         xorl    %eax, %eax
         movl    %eax, %cr4
 
-        /* Call the image entry point.  This should never return. */
-        call    *%ebp
-        ud2
+        /* Jump to the image entry point. */
+        jmp     *%ebp
 END(compatibility_mode)
 
         /* Separate code and data into into different cache lines */

base-commit: 351d41e8aecc3f7566a0baa7b4066d06dedd7113

Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrew Cooper

Linux jumps to the target image rather than calling it. Switch to using JMP, and drop the trailing UD2s.

Linux does have a mode, named CONFIG_KEXEC_JUMP, where the target image can be returned from, but that involves extra metadata and setting up a stack within the target image which Xen doesn't support at the moment.

No functional change.

I wonder though why CALL was used in the first place. Usually this would be to e.g. have the callee have a call frame in order to e.g. unwind. For kexec that may not be overly relevant though.

Jan

Quoted 29 lines
xen/arch/x86/x86_64/kexec_reloc.S +4 -7
@@ -75,10 +75,8 @@ FUNC(kexec_reloc, PAGE_SIZE)
         testq   $KEXEC_RELOC_FLAG_COMPAT, %r8
         jnz     .L_call_32_bit
 
-.L_call_64_bit:
-        /* Call the image entry point.  This should never return. */
-        callq   *%rbp
-        ud2
+        /* Jump to the image entry point */
+        jmp     *%rbp
 
 .L_call_32_bit:
         /* Setup IDT. */
@@ -170,9 +168,8 @@ FUNC_LOCAL(compatibility_mode)
         xorl    %eax, %eax
         movl    %eax, %cr4
 
-        /* Call the image entry point.  This should never return. */
-        call    *%ebp
-        ud2
+        /* Jump to the image entry point. */
+        jmp     *%ebp
 END(compatibility_mode)
 
         /* Separate code and data into into different cache lines */

base-commit: 351d41e8aecc3f7566a0baa7b4066d06dedd7113