[patch V2 04/17] x86/entry: Make DEBUG_ENTRY_ASSERT_IRQS_OFF available for 32bit

From: Thomas Gleixner
Date: Wed Oct 23 2019 - 08:33:28 EST


Move the interrupt state verification debug macro to common code and fixup
the irqflags and paravirt components so it can be used in 32bit code later.

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
arch/x86/entry/calling.h | 12 ++++++++++++
arch/x86/entry/entry_64.S | 12 ------------
arch/x86/include/asm/irqflags.h | 8 ++++++--
arch/x86/include/asm/paravirt.h | 9 +++++----
4 files changed, 23 insertions(+), 18 deletions(-)

--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -366,3 +366,15 @@ For 32-bit we have the following convent
#else
#define GET_CR2_INTO(reg) _ASM_MOV %cr2, reg
#endif
+
+.macro DEBUG_ENTRY_ASSERT_IRQS_OFF
+#ifdef CONFIG_DEBUG_ENTRY
+ push %_ASM_AX
+ SAVE_FLAGS(CLBR_EAX)
+ test $X86_EFLAGS_IF, %_ASM_AX
+ jz .Lokay_\@
+ ud2
+.Lokay_\@:
+ pop %_ASM_AX
+#endif
+.endm
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -387,18 +387,6 @@ ENTRY(spurious_entries_start)
.endr
END(spurious_entries_start)

-.macro DEBUG_ENTRY_ASSERT_IRQS_OFF
-#ifdef CONFIG_DEBUG_ENTRY
- pushq %rax
- SAVE_FLAGS(CLBR_RAX)
- testl $X86_EFLAGS_IF, %eax
- jz .Lokay_\@
- ud2
-.Lokay_\@:
- popq %rax
-#endif
-.endm
-
/*
* Enters the IRQ stack if we're not already using it. NMI-safe. Clobbers
* flags and puts old RSP into old_rsp, and leaves all other GPRs alone.
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -126,11 +126,15 @@ static inline notrace unsigned long arch
#define ENABLE_INTERRUPTS(x) sti
#define DISABLE_INTERRUPTS(x) cli

-#ifdef CONFIG_X86_64
#ifdef CONFIG_DEBUG_ENTRY
-#define SAVE_FLAGS(x) pushfq; popq %rax
+# ifdef CONFIG_X86_64
+# define SAVE_FLAGS(x) pushfq; popq %rax
+# else
+# define SAVE_FLAGS(x) pushfl; popl %eax
+# endif
#endif

+#ifdef CONFIG_X86_64
#define SWAPGS swapgs
/*
* Currently paravirt can't handle swapgs nicely when we
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -904,6 +904,11 @@ extern void default_banner(void);
ANNOTATE_RETPOLINE_SAFE; \
jmp PARA_INDIRECT(pv_ops+PV_CPU_usergs_sysret64);)

+#endif /* CONFIG_PARAVIRT_XXL */
+#endif /* CONFIG_X86_64 */
+
+#ifdef CONFIG_PARAVIRT_XXL
+
#ifdef CONFIG_DEBUG_ENTRY
#define SAVE_FLAGS(clobbers) \
PARA_SITE(PARA_PATCH(PV_IRQ_save_fl), \
@@ -912,10 +917,6 @@ extern void default_banner(void);
call PARA_INDIRECT(pv_ops+PV_IRQ_save_fl); \
PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);)
#endif
-#endif /* CONFIG_PARAVIRT_XXL */
-#endif /* CONFIG_X86_64 */
-
-#ifdef CONFIG_PARAVIRT_XXL

#define GET_CR2_INTO_AX \
PARA_SITE(PARA_PATCH(PV_MMU_read_cr2), \