* [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint
@ 2020-02-10 14:05 Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 1/2] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h Dmitry Safonov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dmitry Safonov @ 2020-02-10 14:05 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-kernel, Dmitry Safonov, Dmitry Safonov, Linus Torvalds,
Peter Zijlstra, Thomas Gleixner, Josh Poimboeuf, Ingo Molnar
On 4.19.93 the following warning was observed with CONFIG_FRAME_POINTER:
> WARNING: kernel stack frame pointer at 00000000bceb5183 in Coronavirus:3282 has bad value (null)
> unwind stack type:0 next_sp: (null) mask:0x2 graph_idx:0
> 000000009630aa47: ffffc9000126fdb0 (0xffffc9000126fdb0)
> 0000000020360f53: ffffffff81038e33 (__save_stack_trace+0xcb/0xee)
> 00000000675081f2: 0000000000000000 ...
> 0000000043198fe7: ffffc9000126c000 (0xffffc9000126c000)
> 0000000008a46231: ffffc90001270000 (0xffffc90001270000)
[..]
It turns to be missing %rbp hint was making frame pointer unwinder
a bit tipsy.
The observed is WARN_ONCE(), so it one time per boot, but imho, worth to
have in stable too.
Peter Zijlstra (2):
x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h
x86/stackframe, x86/ftrace: Add pt_regs frame annotations
arch/x86/entry/calling.h | 15 -----------
arch/x86/entry/entry_32.S | 16 ------------
arch/x86/include/asm/frame.h | 49 ++++++++++++++++++++++++++++++++++++
arch/x86/kernel/ftrace_32.S | 3 +++
arch/x86/kernel/ftrace_64.S | 3 +++
5 files changed, 55 insertions(+), 31 deletions(-)
--
2.25.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH-4.19-stable 1/2] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h
2020-02-10 14:05 [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Dmitry Safonov
@ 2020-02-10 14:05 ` Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 2/2] x86/stackframe, x86/ftrace: Add pt_regs frame annotations Dmitry Safonov
2020-02-13 15:01 ` [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Safonov @ 2020-02-10 14:05 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-kernel, Dmitry Safonov, Peter Zijlstra, Dmitry Safonov,
Josh Poimboeuf, Ingo Molnar, Linus Torvalds, Thomas Gleixner
From: Peter Zijlstra <peterz@infradead.org>
[ Upstream commit a9b3c6998d4a7d53a787cf4d0fd4a4c11239e517 ]
In preparation for wider use, move the ENCODE_FRAME_POINTER macros to
a common header and provide inline asm versions.
These macros are used to encode a pt_regs frame for the unwinder; see
unwind_frame.c:decode_frame_pointer().
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
arch/x86/entry/calling.h | 15 -----------
arch/x86/entry/entry_32.S | 16 ------------
arch/x86/include/asm/frame.h | 49 ++++++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 578b5455334f..31fbb4a7d9f6 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -172,21 +172,6 @@ For 32-bit we have the following conventions - kernel is built with
.endif
.endm
-/*
- * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
- * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
- * is just setting the LSB, which makes it an invalid stack address and is also
- * a signal to the unwinder that it's a pt_regs pointer in disguise.
- *
- * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
- * the original rbp.
- */
-.macro ENCODE_FRAME_POINTER ptregs_offset=0
-#ifdef CONFIG_FRAME_POINTER
- leaq 1+\ptregs_offset(%rsp), %rbp
-#endif
-.endm
-
#ifdef CONFIG_PAGE_TABLE_ISOLATION
/*
diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
index 8059d4fd915c..d07432062ee6 100644
--- a/arch/x86/entry/entry_32.S
+++ b/arch/x86/entry/entry_32.S
@@ -245,22 +245,6 @@
.Lend_\@:
.endm
-/*
- * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
- * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
- * is just clearing the MSB, which makes it an invalid stack address and is also
- * a signal to the unwinder that it's a pt_regs pointer in disguise.
- *
- * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
- * original rbp.
- */
-.macro ENCODE_FRAME_POINTER
-#ifdef CONFIG_FRAME_POINTER
- mov %esp, %ebp
- andl $0x7fffffff, %ebp
-#endif
-.endm
-
.macro RESTORE_INT_REGS
popl %ebx
popl %ecx
diff --git a/arch/x86/include/asm/frame.h b/arch/x86/include/asm/frame.h
index 5cbce6fbb534..296b346184b2 100644
--- a/arch/x86/include/asm/frame.h
+++ b/arch/x86/include/asm/frame.h
@@ -22,6 +22,35 @@
pop %_ASM_BP
.endm
+#ifdef CONFIG_X86_64
+/*
+ * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
+ * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
+ * is just setting the LSB, which makes it an invalid stack address and is also
+ * a signal to the unwinder that it's a pt_regs pointer in disguise.
+ *
+ * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts
+ * the original rbp.
+ */
+.macro ENCODE_FRAME_POINTER ptregs_offset=0
+ leaq 1+\ptregs_offset(%rsp), %rbp
+.endm
+#else /* !CONFIG_X86_64 */
+/*
+ * This is a sneaky trick to help the unwinder find pt_regs on the stack. The
+ * frame pointer is replaced with an encoded pointer to pt_regs. The encoding
+ * is just clearing the MSB, which makes it an invalid stack address and is also
+ * a signal to the unwinder that it's a pt_regs pointer in disguise.
+ *
+ * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the
+ * original ebp.
+ */
+.macro ENCODE_FRAME_POINTER
+ mov %esp, %ebp
+ andl $0x7fffffff, %ebp
+.endm
+#endif /* CONFIG_X86_64 */
+
#else /* !__ASSEMBLY__ */
#define FRAME_BEGIN \
@@ -30,12 +59,32 @@
#define FRAME_END "pop %" _ASM_BP "\n"
+#ifdef CONFIG_X86_64
+#define ENCODE_FRAME_POINTER \
+ "lea 1(%rsp), %rbp\n\t"
+#else /* !CONFIG_X86_64 */
+#define ENCODE_FRAME_POINTER \
+ "movl %esp, %ebp\n\t" \
+ "andl $0x7fffffff, %ebp\n\t"
+#endif /* CONFIG_X86_64 */
+
#endif /* __ASSEMBLY__ */
#define FRAME_OFFSET __ASM_SEL(4, 8)
#else /* !CONFIG_FRAME_POINTER */
+#ifdef __ASSEMBLY__
+
+.macro ENCODE_FRAME_POINTER ptregs_offset=0
+.endm
+
+#else /* !__ASSEMBLY */
+
+#define ENCODE_FRAME_POINTER
+
+#endif
+
#define FRAME_BEGIN
#define FRAME_END
#define FRAME_OFFSET 0
--
2.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH-4.19-stable 2/2] x86/stackframe, x86/ftrace: Add pt_regs frame annotations
2020-02-10 14:05 [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 1/2] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h Dmitry Safonov
@ 2020-02-10 14:05 ` Dmitry Safonov
2020-02-13 15:01 ` [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Safonov @ 2020-02-10 14:05 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-kernel, Dmitry Safonov, Peter Zijlstra, Dmitry Safonov,
Josh Poimboeuf, Ingo Molnar, Linus Torvalds, Thomas Gleixner
From: Peter Zijlstra <peterz@infradead.org>
[ Upstream commit ea1ed38dba64b64a245ab8ca1406269d17b99485 ]
When CONFIG_FRAME_POINTER, we should mark pt_regs frames.
Fixes user-visible warning for unwinder (i.e, ftrace's stack tracer):
> WARNING: kernel stack frame pointer at 00000000bceb5183 in Coronavirus:3282 has bad value (null)
> unwind stack type:0 next_sp: (null) mask:0x2 graph_idx:0
> 000000009630aa47: ffffc9000126fdb0 (0xffffc9000126fdb0)
> 0000000020360f53: ffffffff81038e33 (__save_stack_trace+0xcb/0xee)
> 00000000675081f2: 0000000000000000 ...
> 0000000043198fe7: ffffc9000126c000 (0xffffc9000126c000)
> 0000000008a46231: ffffc90001270000 (0xffffc90001270000)
[..]
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
[4.19 backport; added user-visible changelog]
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
arch/x86/kernel/ftrace_32.S | 3 +++
arch/x86/kernel/ftrace_64.S | 3 +++
2 files changed, 6 insertions(+)
diff --git a/arch/x86/kernel/ftrace_32.S b/arch/x86/kernel/ftrace_32.S
index 4c8440de3355..83f18e829ac7 100644
--- a/arch/x86/kernel/ftrace_32.S
+++ b/arch/x86/kernel/ftrace_32.S
@@ -9,6 +9,7 @@
#include <asm/export.h>
#include <asm/ftrace.h>
#include <asm/nospec-branch.h>
+#include <asm/frame.h>
#ifdef CC_USING_FENTRY
# define function_hook __fentry__
@@ -131,6 +132,8 @@ ENTRY(ftrace_regs_caller)
pushl %ecx
pushl %ebx
+ ENCODE_FRAME_POINTER
+
movl 12*4(%esp), %eax /* Load ip (1st parameter) */
subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
#ifdef CC_USING_FENTRY
diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S
index 75f2b36b41a6..24b9abf718e8 100644
--- a/arch/x86/kernel/ftrace_64.S
+++ b/arch/x86/kernel/ftrace_64.S
@@ -9,6 +9,7 @@
#include <asm/export.h>
#include <asm/nospec-branch.h>
#include <asm/unwind_hints.h>
+#include <asm/frame.h>
.code64
.section .entry.text, "ax"
@@ -222,6 +223,8 @@ GLOBAL(ftrace_regs_caller_op_ptr)
leaq MCOUNT_REG_SIZE+8*2(%rsp), %rcx
movq %rcx, RSP(%rsp)
+ ENCODE_FRAME_POINTER
+
/* regs go into 4th parameter */
leaq (%rsp), %rcx
--
2.25.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint
2020-02-10 14:05 [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 1/2] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 2/2] x86/stackframe, x86/ftrace: Add pt_regs frame annotations Dmitry Safonov
@ 2020-02-13 15:01 ` Greg Kroah-Hartman
2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2020-02-13 15:01 UTC (permalink / raw)
To: Dmitry Safonov
Cc: linux-kernel, Dmitry Safonov, Linus Torvalds, Peter Zijlstra,
Thomas Gleixner, Josh Poimboeuf, Ingo Molnar
On Mon, Feb 10, 2020 at 02:05:41PM +0000, Dmitry Safonov wrote:
> On 4.19.93 the following warning was observed with CONFIG_FRAME_POINTER:
> > WARNING: kernel stack frame pointer at 00000000bceb5183 in Coronavirus:3282 has bad value (null)
> > unwind stack type:0 next_sp: (null) mask:0x2 graph_idx:0
> > 000000009630aa47: ffffc9000126fdb0 (0xffffc9000126fdb0)
> > 0000000020360f53: ffffffff81038e33 (__save_stack_trace+0xcb/0xee)
> > 00000000675081f2: 0000000000000000 ...
> > 0000000043198fe7: ffffc9000126c000 (0xffffc9000126c000)
> > 0000000008a46231: ffffc90001270000 (0xffffc90001270000)
> [..]
>
> It turns to be missing %rbp hint was making frame pointer unwinder
> a bit tipsy.
> The observed is WARN_ONCE(), so it one time per boot, but imho, worth to
> have in stable too.
All now queued up, thanks!
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-13 15:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 14:05 [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 1/2] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h Dmitry Safonov
2020-02-10 14:05 ` [PATCH-4.19-stable 2/2] x86/stackframe, x86/ftrace: Add pt_regs frame annotations Dmitry Safonov
2020-02-13 15:01 ` [PATCH-4.19-stable 0/2] Backport ENCODE_FRAME_POINTER hint Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).