[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/asm: Introduce a tailcall pseduo-op


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 30 Jun 2023 16:20:57 +0100
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 30 Jun 2023 15:21:49 +0000
  • Ironport-data: A9a23:cVUsXaOcG9WpXJfvrR2gl8FynXyQoLVcMsEvi/4bfWQNrUor1mEHz msXXWCPbv3eZTakeY9xa4mwpkJT6sLWnNViQQto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/vrRC9H5qyo42tG5QRmP5ingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0uRsUHpl3 OwDEgEiZQGEv9/xkbyXFMA506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w2Nk+ojx5nYz/7DLoXmuuyi2a5WDpfsF+P/oI84nTJzRw327/oWDbQUoXTGJwKwRbD9 woq+Uz7Cz0/DM6R0QGGyXyltPP/wz39ZoMdQejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasnDQRRt5RGO0S8xyWx+zf5APxLncAZi5MbpohrsBeeNAx/ gbXxZWzX2Up6eDLDyvHrd94sA9eJwAXNj4ZTgYUVjE0zNLyp7kOyUPBYohKRfvdYsLOJd3g/ 9ybhHFg1+VK1JdTjfXTEUPv2Gz1+MWQJuIhzkCOBz/+sFskDGKwT9bwgWU3+8qsO2pworOpm HEf0/aT4+kVZX1mvHzcGb5ddF1FChvsDdE9vbKMN8N7n9hV0yT/Fb28GRknTKuTDu4KeCXyf GjYsh5L6ZlYMROCNPEnM9rvUJpxk/W6SrwJs8w4ifIUO/BMmPKvpnkyNSZ8IUiz+KTTrU3PE cjCKpv9ZZrrIa9m0CC3V48gPUwDn0gDKZfobcmjlXyPiOPODEN5vJ9ZaDNimMhltvLbyOgUm v4DX/a3J+J3CbyhPneNq9ZJdjjn7xETXPjLliCeTcbbSiIOJY3rI66IqV/9U+SJR5hoq9o=
  • Ironport-hdrordr: A9a23:0cE93a9ow9zRPdP3hFVuk+DUI+orL9Y04lQ7vn2YSXRuHPBw8P re+8jztCWE7Ar5N0tBpTntAsW9qBDnhPtICOsqTNSftWDd0QPCRuxfBOPZslvd8kbFl9K1u5 0OT0EHMqyTMWRH
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

It was previously noted that CALL/BUG is a weird combination, but there is
good reason to use this pattern.

Introduce an explicit tailcall macro make it clearer in context.

No functional change.

Reported-by: Jan Beulich <JBeulich@xxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>

It would be nicer if tailcall was shorter, but that loses clarity.  RISC-V has
'tail' as an alias for 'b', but that looses the call aspect, and tcall isn't
sufficiently recognisable as tailcall IMO.
---
 xen/arch/x86/boot/x86_64.S           |  6 ++----
 xen/arch/x86/include/asm/asm-defns.h |  9 +++++++++
 xen/arch/x86/x86_64/entry.S          | 12 ++++--------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S
index 5d12937a0e40..04bb62ae8680 100644
--- a/xen/arch/x86/boot/x86_64.S
+++ b/xen/arch/x86/boot/x86_64.S
@@ -74,14 +74,12 @@ ENTRY(__high_start)
 .L_ap_cet_done:
 #endif /* CONFIG_XEN_SHSTK || CONFIG_XEN_IBT */
 
-        call    start_secondary
-        BUG     /* start_secondary() shouldn't return. */
+        tailcall start_secondary
 
 .L_bsp:
         /* Pass off the Multiboot info structure to C land (if applicable). */
         mov     multiboot_ptr(%rip),%edi
-        call    __start_xen
-        BUG     /* __start_xen() shouldn't return. */
+        tailcall __start_xen
 
         .section .data.page_aligned, "aw", @progbits
         .align PAGE_SIZE, 0
diff --git a/xen/arch/x86/include/asm/asm-defns.h 
b/xen/arch/x86/include/asm/asm-defns.h
index 8bd9007731d5..9a7073ced5be 100644
--- a/xen/arch/x86/include/asm/asm-defns.h
+++ b/xen/arch/x86/include/asm/asm-defns.h
@@ -20,6 +20,15 @@
     .byte 0x0f, 0x01, 0xdd
 .endm
 
+/*
+ * Call a noreturn function.  This could be JMP, but CALL results in a more
+ * helpful backtrace.  BUG is to catch functions which do decide to return...
+ */
+.macro tailcall fn:req
+    call  \fn
+    BUG   /* Shouldn't return */
+.endm
+
 .macro INDIRECT_BRANCH insn:req arg:req
 /*
  * Create an indirect branch.  insn is one of call/jmp, arg is a single
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 8b77d7113bbf..bca1500e2b45 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -824,8 +824,7 @@ handle_exception_saved:
         DISPATCH(X86_EXC_CP, do_entry_CP)
 #undef DISPATCH
 
-        call  do_unhandled_trap
-        BUG   /* do_unhandled_trap() shouldn't return. */
+        tailcall do_unhandled_trap
 
 .L_exn_dispatch_done:
         mov   %r15, STACK_CPUINFO_FIELD(xen_cr3)(%r14)
@@ -880,8 +879,7 @@ exception_with_ints_disabled:
 FATAL_exception_with_ints_disabled:
         xorl  %esi,%esi
         movq  %rsp,%rdi
-        call  fatal_trap
-        BUG   /* fatal_trap() shouldn't return. */
+        tailcall fatal_trap
 
 ENTRY(divide_error)
         ENDBR64
@@ -989,8 +987,7 @@ ENTRY(double_fault)
 .Ldblf_cr3_okay:
 
         movq  %rsp,%rdi
-        call  do_double_fault
-        BUG   /* do_double_fault() shouldn't return. */
+        tailcall do_double_fault
 
 ENTRY(nmi)
         ENDBR64
@@ -1085,8 +1082,7 @@ handle_ist_exception:
         DISPATCH(X86_EXC_MC,  do_machine_check)
 #undef DISPATCH
 
-        call  do_unhandled_trap
-        BUG   /* do_unhandled_trap() shouldn't return. */
+        tailcall do_unhandled_trap
 
 .L_ist_dispatch_done:
         mov   %r15, STACK_CPUINFO_FIELD(xen_cr3)(%r14)

base-commit: f51e5d8eae8ece77a949571f39ee49904f3129aa
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.