x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
cover x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
Recent change to struct pt_regs handling in entry.S, among other things, changed how callee-preserved registers are saved around call to lockdep_sys_exit_thunk:
# define LOCKDEP_SYS_EXIT_IRQ \
TRACE_IRQS_ON; \
sti; \
SAVE_EXTRA_REGS; \ <======= HERE
LOCKDEP_SYS_EXIT; \
RESTORE_EXTRA_REGS; \ <======= HEREThe change is in fact a bit fragile:
now we assume that LOCKDEP_SYS_EXIT_IRQ macro is used only when there is a struct pt_regs on the stack.
So far this assumption is true, but it is probably a coincidence.
We can revert back to pushing registers, but this callee-preserved registers saving appears bogus. It is not necessary: they _are_ callee-preserved, and lockdep_sys_exit() does not touch them on the stack either.
First two patches clean up #define maze so that we can see
that LOCKDEP_SYS_EXIT macro call above is merely "call lockdep_sys_exit_thunk".
Last patch removes SAVE/RESTORE.
I tested this patch series and everything seems to run fine on a lockdep-enabled kernel with these lines removed.
Denys Vlasenko (3):
x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users
x86: fold ARCH_LOCKDEP_SYS_EXIT defines into their users
x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
arch/x86/include/asm/irqflags.h | 45 +++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/3 x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users
This change simply moves defines around (even if it's not obvious in a patch form). Nothing is changed.
This is a preparation for folding ARCH_LOCKDEP_SYS_EXIT defines into their users.
--- arch/x86/include/asm/irqflags.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
arch/x86/include/asm/irqflags.h +17 -20
@@ -163,12 +163,20 @@ static inline int arch_irqs_disabled(void) return arch_irqs_disabled_flags(flags); } +#endif /* !__ASSEMBLY__ */ +#ifdef __ASSEMBLY__ +#ifdef CONFIG_TRACE_IRQFLAGS +# define TRACE_IRQS_ON call trace_hardirqs_on_thunk; +# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk;#else - -#ifdef CONFIG_X86_64 -#define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk -#define ARCH_LOCKDEP_SYS_EXIT_IRQ \ +# define TRACE_IRQS_ON +# define TRACE_IRQS_OFF +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC +# ifdef CONFIG_X86_64 +# define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk +# define ARCH_LOCKDEP_SYS_EXIT_IRQ \ TRACE_IRQS_ON; \ sti; \ SAVE_EXTRA_REGS; \
@@ -176,9 +184,8 @@ static inline int arch_irqs_disabled(void)RESTORE_EXTRA_REGS ; \ cli; \TRACE_IRQS_OFF ; - -#else -#define ARCH_LOCKDEP_SYS_EXIT \ +# else +# define ARCH_LOCKDEP_SYS_EXIT \ pushl %eax; \ pushl %ecx; \ pushl %edx; \
@@ -186,24 +193,14 @@ static inline int arch_irqs_disabled(void) popl %edx; \ popl %ecx; \ popl %eax; - -#define ARCH_LOCKDEP_SYS_EXIT_IRQ -#endif - -#ifdef CONFIG_TRACE_IRQFLAGS -# define TRACE_IRQS_ON call trace_hardirqs_on_thunk; -# define TRACE_IRQS_OFF call trace_hardirqs_off_thunk; -#else -# define TRACE_IRQS_ON -# define TRACE_IRQS_OFF -#endif -#ifdef CONFIG_DEBUG_LOCK_ALLOC +# define ARCH_LOCKDEP_SYS_EXIT_IRQ +# endif # define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT# define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ# else # define LOCKDEP_SYS_EXIT # define LOCKDEP_SYS_EXIT_IRQ # endif -#endif /* __ASSEMBLY__ */ +#endif
Signature · 1 line
1.8.1.4
PATCH 2/3 x86: fold ARCH_LOCKDEP_SYS_EXIT defines into their users
In reply to Denys VlasenkoThere is no need to have an extra level of macro indirection here.
--- arch/x86/include/asm/irqflags.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
arch/x86/include/asm/irqflags.h +7 -9
@@ -175,17 +175,17 @@ static inline int arch_irqs_disabled(void)#endif #ifdef CONFIG_DEBUG_LOCK_ALLOC # ifdef CONFIG_X86_64 -# define ARCH_LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk -# define ARCH_LOCKDEP_SYS_EXIT_IRQ \ +# define LOCKDEP_SYS_EXIT call lockdep_sys_exit_thunk +# define LOCKDEP_SYS_EXIT_IRQ \ TRACE_IRQS_ON; \ sti; \ SAVE_EXTRA_REGS; \ - LOCKDEP_SYS_EXIT; \ + call lockdep_sys_exit_thunk; \ RESTORE_EXTRA_REGS; \ cli; \ TRACE_IRQS_OFF;# else -# define ARCH_LOCKDEP_SYS_EXIT \ +# define LOCKDEP_SYS_EXIT \ pushl %eax; \ pushl %ecx; \ pushl %edx; \
@@ -193,14 +193,12 @@ static inline int arch_irqs_disabled(void) popl %edx; \ popl %ecx; \ popl %eax; -# define ARCH_LOCKDEP_SYS_EXIT_IRQ +# define LOCKDEP_SYS_EXIT_IRQ # endif -# define LOCKDEP_SYS_EXIT ARCH_LOCKDEP_SYS_EXIT -# define LOCKDEP_SYS_EXIT_IRQ ARCH_LOCKDEP_SYS_EXIT_IRQ -# else +#else # define LOCKDEP_SYS_EXIT # define LOCKDEP_SYS_EXIT_IRQ -# endif +#endif #endif /* __ASSEMBLY__ */ #endif
Signature · 1 line
1.8.1.4
PATCH 3/3 x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
In reply to Denys VlasenkoInternally, lockdep_sys_exit_thunk saves callee-clobbered registers, and calls a C function, lockdep_sys_exix. Thus, callee-preserved won't be mangled, there is no need to save them.
Patch was run-tested.
--- arch/x86/include/asm/irqflags.h | 2 -- 1 file changed, 2 deletions(-)
arch/x86/include/asm/irqflags.h +0 -2
@@ -179,9 +179,7 @@ static inline int arch_irqs_disabled(void)# define LOCKDEP_SYS_EXIT_IRQ \ TRACE_IRQS_ON; \ sti; \ - SAVE_EXTRA_REGS; \ call lockdep_sys_exit_thunk; \ - RESTORE_EXTRA_REGS; \ cli; \ TRACE_IRQS_OFF;# else
Signature · 1 line
1.8.1.4
Quoted 5 lines · Denys Vlasenko
Internally,
lockdep_sys_exit_thunksaves callee-clobbered registers, and calls a C function,lockdep_sys_exix. Thus, callee-preserved won't be mangled, there is no need to save them.Patch was run-tested.
Peterz, I think this was your code.
--Andy
Quoted 36 lines
Signed-off-by Denys Vlasenko <[email protected]>CC Linus Torvalds <[email protected]>CC Steven Rostedt <[email protected]>CC Ingo Molnar <[email protected]>CC Borislav Petkov <[email protected]>CC "H. Peter Anvin" <[email protected]>CC Andy Lutomirski <[email protected]>CC Oleg Nesterov <[email protected]>CC Frederic Weisbecker <[email protected]>CC Alexei Starovoitov <[email protected]>CC Will Drewry <[email protected]>CC Kees Cook <[email protected]>--- arch/x86/include/asm/irqflags.h | 2 -- 1 file changed, 2 deletions(-)arch/x86/include/asm/irqflags.h +0
-3@@ -179,9 +179,7 @@ static inline int arch_irqs_disabled(void)# define LOCKDEP_SYS_EXIT_IRQ \ TRACE_IRQS_ON; \ sti; \ - SAVE_EXTRA_REGS; \ call lockdep_sys_exit_thunk; \ - RESTORE_EXTRA_REGS; \ cli; \ TRACE_IRQS_OFF;# else --1.8.1.4
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Quoted 8 lines · Andy Lutomirski
Quoted 5 lines · Denys Vlasenko
Internally,
lockdep_sys_exit_thunksaves callee-clobbered registers, and calls a C function,lockdep_sys_exix. Thus, callee-preserved won't be mangled, there is no need to save them.Patch was run-tested.
Peterz, I think this was your code.
It was, I'm forever unsure on when what register are saved by which macros/functions.
Thanks!