Skip to contentSkip to conversation

xen: drop the nop() macro

PATCH In review Andrew Cooper 4 participants 4 messages Mar 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: drop the nop() macro

There isn't a plausible reason to insert nops like this into code.

The sole use is in do_debug_key(), and exists to prevent the compiler optimising the tail of the function with 'jmp debugger_trap_fatal'

In practice, a compiler barrier suffices just as well to prevent the tailcall, and doesn't involve inserting unnecessary instructions.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

To preempt review questions, the (void) cast can't be dropped without breaking the ARM build. I tried cleaning up the debugger infrastructure a little (in particular to put this debugkey behind CONFIG_CRASH_DEBUG) but it is more than a 5 minute job to disentangle, and I don't have time.

---
 xen/common/keyhandler.c      | 6 +++---
 xen/include/asm-arm/system.h | 3 ---
 xen/include/asm-x86/system.h | 3 ---
 3 files changed, 3 insertions(+), 9 deletions(-)
xen/common/keyhandler.c +3 -3
index c25a30e..4f4a660 100644
@@ -480,9 +480,9 @@ static void do_debug_key(unsigned char key, struct cpu_user_regs *regs)
 {
     printk("'%c' pressed -> trapping into debugger\n", key);
     (void)debugger_trap_fatal(0xf001, regs);
-    nop(); /* Prevent the compiler doing tail call
-                             optimisation, as that confuses xendbg a
-                             bit. */
+
+    /* Prevent tail call optimisation, which confuses xendbg. */
+    barrier();
 }
 
 static void do_toggle_alt_key(unsigned char key, struct cpu_user_regs *regs)
xen/include/asm-arm/system.h +0 -3
index b94e56f..e5d0626 100644
@@ -5,9 +5,6 @@
 #include <xen/lib.h>
 #include <public/arch-arm.h>
 
-#define nop() \
-    asm volatile ( "nop" )
-
 #define sev()           asm volatile("sev" : : : "memory")
 #define wfe()           asm volatile("wfe" : : : "memory")
 #define wfi()           asm volatile("wfi" : : : "memory")
xen/include/asm-x86/system.h +0 -3
index 483cd20..c665499 100644
@@ -17,9 +17,6 @@
 #define clflush(a) \
     asm volatile ( "clflush (%0)" : : "r"(a) )
 
-#define nop() \
-    asm volatile ( "nop" )
-
 #define xchg(ptr,v) \
     ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

There isn't a plausible reason to insert nops like this into code.

The sole use is in do_debug_key(), and exists to prevent the compiler optimising the tail of the function with 'jmp debugger_trap_fatal'

In practice, a compiler barrier suffices just as well to prevent the tailcall, and doesn't involve inserting unnecessary instructions.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by
#2 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.19 at 14:41, <[email protected]> wrote:
Quoted 5 lines · Andrew Cooper

There isn't a plausible reason to insert nops like this into code.

The sole use is in do_debug_key(), and exists to prevent the compiler optimising the tail of the function with 'jmp debugger_trap_fatal'

Quoted 6 lines
Quoted 4 lines

In practice, a compiler barrier suffices just as well to prevent the tailcall, and doesn't involve inserting unnecessary instructions.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 9 lines · Andrew Cooper

There isn't a plausible reason to insert nops like this into code.

The sole use is in do_debug_key(), and exists to prevent the compiler optimising the tail of the function with 'jmp debugger_trap_fatal'

In practice, a compiler barrier suffices just as well to prevent the tailcall, and doesn't involve inserting unnecessary instructions.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel