* [PATCH 0/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
@ 2015-02-28 0:29 Denys Vlasenko
2015-02-28 0:29 ` [PATCH 1/3] x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users Denys Vlasenko
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Denys Vlasenko @ 2015-02-28 0:29 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
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; \ <======= HERE
The 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(-)
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
--
1.8.1.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users
2015-02-28 0:29 [PATCH 0/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
@ 2015-02-28 0:29 ` Denys Vlasenko
2015-02-28 0:29 ` [PATCH 2/3] x86: fold ARCH_LOCKDEP_SYS_EXIT defines into " Denys Vlasenko
2015-02-28 0:29 ` [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2 siblings, 0 replies; 7+ messages in thread
From: Denys Vlasenko @ 2015-02-28 0:29 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
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.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/irqflags.h | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 021bee9..55866c2 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -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
--
1.8.1.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] x86: fold ARCH_LOCKDEP_SYS_EXIT defines into their users
2015-02-28 0:29 [PATCH 0/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2015-02-28 0:29 ` [PATCH 1/3] x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users Denys Vlasenko
@ 2015-02-28 0:29 ` Denys Vlasenko
2015-02-28 0:29 ` [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2 siblings, 0 replies; 7+ messages in thread
From: Denys Vlasenko @ 2015-02-28 0:29 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
There is no need to have an extra level of macro indirection here.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/irqflags.h | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 55866c2..19355f3 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -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
--
1.8.1.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
2015-02-28 0:29 [PATCH 0/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2015-02-28 0:29 ` [PATCH 1/3] x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users Denys Vlasenko
2015-02-28 0:29 ` [PATCH 2/3] x86: fold ARCH_LOCKDEP_SYS_EXIT defines into " Denys Vlasenko
@ 2015-02-28 0:29 ` Denys Vlasenko
2015-03-01 16:16 ` Andy Lutomirski
2 siblings, 1 reply; 7+ messages in thread
From: Denys Vlasenko @ 2015-02-28 0:29 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
Internally, 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.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/irqflags.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 19355f3..9a63eae 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
2015-02-28 0:29 ` [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
@ 2015-03-01 16:16 ` Andy Lutomirski
2015-03-02 8:45 ` Peter Zijlstra
0 siblings, 1 reply; 7+ messages in thread
From: Andy Lutomirski @ 2015-03-01 16:16 UTC (permalink / raw)
To: Denys Vlasenko, Peter Zijlstra
Cc: Linus Torvalds, Steven Rostedt, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, Oleg Nesterov, Frederic Weisbecker,
Alexei Starovoitov, Will Drewry, Kees Cook, X86 ML, linux-kernel
On Fri, Feb 27, 2015 at 4:29 PM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
> Internally, 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.
Peterz, I think this was your code.
--Andy
>
> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
> CC: Linus Torvalds <torvalds@linux-foundation.org>
> CC: Steven Rostedt <rostedt@goodmis.org>
> CC: Ingo Molnar <mingo@kernel.org>
> CC: Borislav Petkov <bp@alien8.de>
> CC: "H. Peter Anvin" <hpa@zytor.com>
> CC: Andy Lutomirski <luto@amacapital.net>
> CC: Oleg Nesterov <oleg@redhat.com>
> CC: Frederic Weisbecker <fweisbec@gmail.com>
> CC: Alexei Starovoitov <ast@plumgrid.com>
> CC: Will Drewry <wad@chromium.org>
> CC: Kees Cook <keescook@chromium.org>
> CC: x86@kernel.org
> CC: linux-kernel@vger.kernel.org
> ---
> arch/x86/include/asm/irqflags.h | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
> index 19355f3..9a63eae 100644
> --- a/arch/x86/include/asm/irqflags.h
> +++ b/arch/x86/include/asm/irqflags.h
> @@ -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
>
--
Andy Lutomirski
AMA Capital Management, LLC
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
2015-03-01 16:16 ` Andy Lutomirski
@ 2015-03-02 8:45 ` Peter Zijlstra
0 siblings, 0 replies; 7+ messages in thread
From: Peter Zijlstra @ 2015-03-02 8:45 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
X86 ML, linux-kernel
On Sun, Mar 01, 2015 at 08:16:18AM -0800, Andy Lutomirski wrote:
> On Fri, Feb 27, 2015 at 4:29 PM, Denys Vlasenko <dvlasenk@redhat.com> wrote:
> > Internally, 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.
>
> Peterz, I think this was your code.
It was, I'm forever unsure on when what register are saved by which
macros/functions.
Thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk
2015-03-25 20:14 [PATCH 0/3] " Denys Vlasenko
@ 2015-03-25 20:14 ` Denys Vlasenko
0 siblings, 0 replies; 7+ messages in thread
From: Denys Vlasenko @ 2015-03-25 20:14 UTC (permalink / raw)
To: Ingo Molnar
Cc: Denys Vlasenko, Linus Torvalds, Steven Rostedt, Borislav Petkov,
H. Peter Anvin, Andy Lutomirski, Oleg Nesterov,
Frederic Weisbecker, Alexei Starovoitov, Will Drewry, Kees Cook,
x86, linux-kernel
Internally, lockdep_sys_exit_thunk saves callee-clobbered registers,
and calls a C function, lockdep_sys_exit. Thus, callee-preserved registers
won't be mangled, there is no need to save them.
Patch was run-tested.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: Linus Torvalds <torvalds@linux-foundation.org>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@kernel.org>
CC: Borislav Petkov <bp@alien8.de>
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Andy Lutomirski <luto@amacapital.net>
CC: Oleg Nesterov <oleg@redhat.com>
CC: Frederic Weisbecker <fweisbec@gmail.com>
CC: Alexei Starovoitov <ast@plumgrid.com>
CC: Will Drewry <wad@chromium.org>
CC: Kees Cook <keescook@chromium.org>
CC: x86@kernel.org
CC: linux-kernel@vger.kernel.org
---
arch/x86/include/asm/irqflags.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 19355f3..9a63eae 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-03-25 20:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 0:29 [PATCH 0/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2015-02-28 0:29 ` [PATCH 1/3] x86: move ARCH_LOCKDEP_SYS_EXIT[IRQ] defines closer to their users Denys Vlasenko
2015-02-28 0:29 ` [PATCH 2/3] x86: fold ARCH_LOCKDEP_SYS_EXIT defines into " Denys Vlasenko
2015-02-28 0:29 ` [PATCH 3/3] x86: do not save callee-preserved registers around lockdep_sys_exit_thunk Denys Vlasenko
2015-03-01 16:16 ` Andy Lutomirski
2015-03-02 8:45 ` Peter Zijlstra
2015-03-25 20:14 [PATCH 0/3] " Denys Vlasenko
2015-03-25 20:14 ` [PATCH 3/3] " Denys Vlasenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome