[patch V4 part 3 03/29] x86/entry: Disable interrupts for native_load_gs_index() in C code

Thomas Gleixner
2020-05-05T14:15:26Z

There is absolutely no point in doing this in ASM code. Move it to C.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/entry/entry_64.S | 19 +++++++------------
arch/x86/include/asm/special_insns.h | 14 ++++++++++++--
2 files changed, 19 insertions(+), 14 deletions(-)

--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1036,27 +1036,22 @@ idtentry alignment_check do_alignment_c
idtentry simd_coprocessor_error do_simd_coprocessor_error has_error_code=0

- /*
- * Reload gs selector with exception handling
- * edi: new selector
- */
+/*
+ * Reload gs selector with exception handling
+ * edi: new selector
+ */
.pushsection .text, "ax"
-SYM_FUNC_START(native_load_gs_index)
+SYM_FUNC_START(asm_native_load_gs_index)
FRAME_BEGIN
- pushfq
- DISABLE_INTERRUPTS(CLBR_ANY & ~CLBR_RDI)
- TRACE_IRQS_OFF
SWAPGS
.Lgs_change:
movl %edi, %gs
2: ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE
SWAPGS
- TRACE_IRQS_FLAGS (%rsp)
- popfq
FRAME_END
ret
-SYM_FUNC_END(native_load_gs_index)
-EXPORT_SYMBOL(native_load_gs_index)
+SYM_FUNC_END(asm_native_load_gs_index)
+EXPORT_SYMBOL(asm_native_load_gs_index)
.popsection

_ASM_EXTABLE(.Lgs_change, .Lbad_gs)
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -7,6 +7,7 @@

#include <asm/nops.h>
#include <asm/processor-flags.h>
+#include <linux/irqflags.h>
#include <linux/jump_label.h>

/*
@@ -129,7 +130,16 @@ static inline void native_wbinvd(void)
asm volatile("wbinvd": : :"memory");
}

-extern asmlinkage void native_load_gs_index(unsigned);
+extern asmlinkage void asm_native_load_gs_index(unsigned int selector);
+
+static inline void native_load_gs_index(unsigned int selector)
+{
+ unsigned long flags;
+
+ local_irq_save(flags);
+ asm_native_load_gs_index(selector);
+ local_irq_restore(flags);
+}

static inline unsigned long __read_cr4(void)
{
@@ -186,7 +196,7 @@ static inline void wbinvd(void)

#ifdef CONFIG_X86_64

-static inline void load_gs_index(unsigned selector)
+static inline void load_gs_index(unsigned int selector)
{
native_load_gs_index(selector);
}