[RFC][PATCH 2/3] x86/entry: Provide ASM_INSTR_{BEGIN,END}

From: Peter Zijlstra
Date: Thu May 07 2020 - 12:19:09 EST


To reduce clutter.

Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
arch/x86/include/asm/irq_stack.h | 10 ++--------
arch/x86/include/asm/kvm_host.h | 10 ++--------
include/linux/compiler.h | 14 ++++++++++++++
3 files changed, 18 insertions(+), 16 deletions(-)

--- a/arch/x86/include/asm/irq_stack.h
+++ b/arch/x86/include/asm/irq_stack.h
@@ -24,15 +24,9 @@ do { \
asm volatile( \
"movq %%rsp, (%[ts]) \n" \
"movq %[ts], %%rsp \n" \
- "1: \n" \
- " .pushsection .discard.instr_begin \n" \
- " .long 1b - . \n" \
- " .popsection \n" \
+ ASM_INSTR_BEGIN \
_asm " \n" \
- "2: \n" \
- " .pushsection .discard.instr_end \n" \
- " .long 2b - . \n" \
- " .popsection \n" \
+ ASM_INSTR_END \
"popq %%rsp \n" \
: \
: [ts] "r" (tos), ##__VA_ARGS__ \
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1601,15 +1601,9 @@ asmlinkage void kvm_spurious_fault(void)
insn "\n\t" \
"jmp 668f \n\t" \
"667: \n\t" \
- "1: \n\t" \
- ".pushsection .discard.instr_begin \n\t" \
- ".long 1b - . \n\t" \
- ".popsection \n\t" \
+ ASM_INSTR_BEGIN \
"call kvm_spurious_fault \n\t" \
- "1: \n\t" \
- ".pushsection .discard.instr_end \n\t" \
- ".long 1b - . \n\t" \
- ".popsection \n\t" \
+ ASM_INSTR_END \
"668: \n\t" \
_ASM_EXTABLE(666b, 667b)

--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -135,12 +135,26 @@ void ftrace_likely_update(struct ftrace_
".popsection\n\t" : : "i" (__COUNTER__)); \
})

+#define ASM_INSTR_BEGIN \
+ "999:\n\t" \
+ ".pushsection .discard.instr_begin\n\t" \
+ ".long 999b - .\n\t" \
+ ".popsection\n\t"
+
+#define ASM_INSTR_END \
+ "999:\n\t" \
+ ".pushsection .discard.instr_end\n\t" \
+ ".long 999b - .\n\t" \
+ ".popsection\n\t"
+
#else
#define annotate_reachable()
#define annotate_unreachable()
#define __annotate_jump_table
#define instr_begin() do { } while(0)
#define instr_end() do { } while(0)
+#define ASM_INSTR_BEGIN
+#define ASM_INSTR_END
#endif

#ifndef ASM_UNREACHABLE