All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Correct PowerPC VDSO call frame info
@ 2018-09-13 23:27 Alan Modra
  2018-09-14  0:01 ` Michael Neuling
  2018-09-14  2:59 ` [PATCH] Correct PowerPC VDSO call frame info Reza Arbab
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Modra @ 2018-09-13 23:27 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Paul Mackerras, Michael Ellerman, Michael Neuling

There is control flow in __kernel_clock_gettime that reaches label 99
without saving lr in r12.  CFI info however is interpreted by the
unwinder without reference to control flow: It's a simple matter of
"Execute all the CFI opcodes up to the current address".  That means
the unwinder thinks r12 contains the return address at label 99.
Disabuse it of that notion by resetting CFI for the return address at
label 99.

Note that the ".cfi_restore lr" could have gone anywhere from the
"mtlr r12" a few instructions earlier to the instruction at label 99.
I put the CFI as late as possible, because in general that's best
practice (and if possible grouped with other CFI in order to reduce
the number of CFI opcodes executed when unwinding).  Using r12 as the
return address is perfectly fine after the "mtlr r12" since r12 on
that code path still contains the return address.

__get_datapage also has a CFI error.  That function temporarily saves
lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
use of r0 means the CFI at that point isn't correct, as r0 no longer
contains the return address.  Fix that too.

Signed-off-by: Alan Modra <amodra@gmail.com>

diff --git a/arch/powerpc/kernel/vdso32/datapage.S b/arch/powerpc/kernel/vdso32/datapage.S
index 3745113fcc65..2a7eb5452aba 100644
--- a/arch/powerpc/kernel/vdso32/datapage.S
+++ b/arch/powerpc/kernel/vdso32/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
 	mtlr	r0
 	addi	r3, r3, __kernel_datapage_offset-data_page_branch
 	lwz	r0,0(r3)
+  .cfi_restore lr
 	add	r3,r0,r3
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S
index 769c2624e0a6..1e0bc5955a40 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	 */
 99:
 	li	r0,__NR_clock_gettime
+  .cfi_restore lr
 	sc
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/datapage.S b/arch/powerpc/kernel/vdso64/datapage.S
index abf17feffe40..bf9668691511 100644
--- a/arch/powerpc/kernel/vdso64/datapage.S
+++ b/arch/powerpc/kernel/vdso64/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
 	mtlr	r0
 	addi	r3, r3, __kernel_datapage_offset-data_page_branch
 	lwz	r0,0(r3)
+  .cfi_restore lr
 	add	r3,r0,r3
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S
index c002adcc694c..a4ed9edfd5f0 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	 */
 99:
 	li	r0,__NR_clock_gettime
+  .cfi_restore lr
 	sc
 	blr
   .cfi_endproc

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Correct PowerPC VDSO call frame info
  2018-09-13 23:27 [PATCH] Correct PowerPC VDSO call frame info Alan Modra
@ 2018-09-14  0:01 ` Michael Neuling
  2018-09-14  3:40   ` [PATCH] PowerPC/VDSO: Correct call frame information Alan Modra
  2018-09-14  2:59 ` [PATCH] Correct PowerPC VDSO call frame info Reza Arbab
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Neuling @ 2018-09-14  0:01 UTC (permalink / raw)
  To: Alan Modra, linuxppc-dev

Alan,

Thanks for the patch... A few minor comments...

> Re: [PATCH] Correct PowerPC VDSO call frame info

Our convention is to add powerpc: to the start. ie

  [PATCH] powerpc: Correct VDSO call frame info

or even:=20

  [PATCH] powerpc/vdso: Correct call frame info


On Fri, 2018-09-14 at 08:57 +0930, Alan Modra wrote:
> There is control flow in __kernel_clock_gettime that reaches label 99
> without saving lr in r12.  CFI info however is interpreted by the
> unwinder without reference to control flow: It's a simple matter of
> "Execute all the CFI opcodes up to the current address".  That means
> the unwinder thinks r12 contains the return address at label 99.
> Disabuse it of that notion by resetting CFI for the return address at
> label 99.

Can you expand on CFI =3D=3D Call Frame Information in the commit message. =
 Not a
common term for us mere kernel developers?

> Note that the ".cfi_restore lr" could have gone anywhere from the
> "mtlr r12" a few instructions earlier to the instruction at label 99.
> I put the CFI as late as possible, because in general that's best
> practice (and if possible grouped with other CFI in order to reduce
> the number of CFI opcodes executed when unwinding).  Using r12 as the
> return address is perfectly fine after the "mtlr r12" since r12 on
> that code path still contains the return address.
>=20
> __get_datapage also has a CFI error.  That function temporarily saves
> lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
> use of r0 means the CFI at that point isn't correct, as r0 no longer
> contains the return address.  Fix that too.

Can you describe the problem this fixes at a high level?  ie This fixes doi=
ng a
stack unwind with gdb when in __kernel_clock_gettime.

Mikey

> Signed-off-by: Alan Modra <amodra@gmail.com>
>=20
> diff --git a/arch/powerpc/kernel/vdso32/datapage.S
> b/arch/powerpc/kernel/vdso32/datapage.S
> index 3745113fcc65..2a7eb5452aba 100644
> --- a/arch/powerpc/kernel/vdso32/datapage.S
> +++ b/arch/powerpc/kernel/vdso32/datapage.S
> @@ -37,6 +37,7 @@ data_page_branch:
>  	mtlr	r0
>  	addi	r3, r3, __kernel_datapage_offset-data_page_branch
>  	lwz	r0,0(r3)
> +  .cfi_restore lr
>  	add	r3,r0,r3
>  	blr
>    .cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S
> b/arch/powerpc/kernel/vdso32/gettimeofday.S
> index 769c2624e0a6..1e0bc5955a40 100644
> --- a/arch/powerpc/kernel/vdso32/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
> @@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
>  	 */
>  99:
>  	li	r0,__NR_clock_gettime
> +  .cfi_restore lr
>  	sc
>  	blr
>    .cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso64/datapage.S
> b/arch/powerpc/kernel/vdso64/datapage.S
> index abf17feffe40..bf9668691511 100644
> --- a/arch/powerpc/kernel/vdso64/datapage.S
> +++ b/arch/powerpc/kernel/vdso64/datapage.S
> @@ -37,6 +37,7 @@ data_page_branch:
>  	mtlr	r0
>  	addi	r3, r3, __kernel_datapage_offset-data_page_branch
>  	lwz	r0,0(r3)
> +  .cfi_restore lr
>  	add	r3,r0,r3
>  	blr
>    .cfi_endproc
> diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S
> b/arch/powerpc/kernel/vdso64/gettimeofday.S
> index c002adcc694c..a4ed9edfd5f0 100644
> --- a/arch/powerpc/kernel/vdso64/gettimeofday.S
> +++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
> @@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
>  	 */
>  99:
>  	li	r0,__NR_clock_gettime
> +  .cfi_restore lr
>  	sc
>  	blr
>    .cfi_endproc
>=20

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Correct PowerPC VDSO call frame info
  2018-09-13 23:27 [PATCH] Correct PowerPC VDSO call frame info Alan Modra
  2018-09-14  0:01 ` Michael Neuling
@ 2018-09-14  2:59 ` Reza Arbab
  1 sibling, 0 replies; 5+ messages in thread
From: Reza Arbab @ 2018-09-14  2:59 UTC (permalink / raw)
  To: Alan Modra; +Cc: linuxppc-dev, Michael Neuling

On Fri, Sep 14, 2018 at 08:57:04AM +0930, Alan Modra wrote:
>There is control flow in __kernel_clock_gettime that reaches label 99
>without saving lr in r12.  CFI info however is interpreted by the
>unwinder without reference to control flow: It's a simple matter of
>"Execute all the CFI opcodes up to the current address".  That means
>the unwinder thinks r12 contains the return address at label 99.
>Disabuse it of that notion by resetting CFI for the return address at
>label 99.

Thanks for this! It looks like v2 will just be a commit log change, so 
feel free to carry over my

Tested-by: Reza Arbab <arbab@linux.ibm.com>

-- 
Reza Arbab

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] PowerPC/VDSO: Correct call frame information
  2018-09-14  0:01 ` Michael Neuling
@ 2018-09-14  3:40   ` Alan Modra
  2018-09-20  4:21     ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2018-09-14  3:40 UTC (permalink / raw)
  To: Michael Neuling; +Cc: linuxppc-dev, Paul Mackerras, Michael Ellerman

Call Frame Information is used by gdb for back-traces and inserting
breakpoints on function return for the "finish" command.  This failed
when inside __kernel_clock_gettime.  More concerning than difficulty
debugging is that CFI is also used by stack frame unwinding code to
implement exceptions.  If you have an app that needs to handle
asynchronous exceptions for some reason, and you are unlucky enough to
get one inside the VDSO time functions, your app will crash.

What's wrong:  There is control flow in __kernel_clock_gettime that
reaches label 99 without saving lr in r12.  CFI info however is
interpreted by the unwinder without reference to control flow: It's a
simple matter of "Execute all the CFI opcodes up to the current
address".  That means the unwinder thinks r12 contains the return
address at label 99.  Disabuse it of that notion by resetting CFI for
the return address at label 99.

Note that the ".cfi_restore lr" could have gone anywhere from the
"mtlr r12" a few instructions earlier to the instruction at label 99.
I put the CFI as late as possible, because in general that's best
practice (and if possible grouped with other CFI in order to reduce
the number of CFI opcodes executed when unwinding).  Using r12 as the
return address is perfectly fine after the "mtlr r12" since r12 on
that code path still contains the return address.

__get_datapage also has a CFI error.  That function temporarily saves
lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
use of r0 means the CFI at that point isn't correct, as r0 no longer
contains the return address.  Fix that too.

Signed-off-by: Alan Modra <amodra@gmail.com>
Tested-by: Reza Arbab <arbab@linux.ibm.com>

diff --git a/arch/powerpc/kernel/vdso32/datapage.S b/arch/powerpc/kernel/vdso32/datapage.S
index 3745113fcc65..2a7eb5452aba 100644
--- a/arch/powerpc/kernel/vdso32/datapage.S
+++ b/arch/powerpc/kernel/vdso32/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
 	mtlr	r0
 	addi	r3, r3, __kernel_datapage_offset-data_page_branch
 	lwz	r0,0(r3)
+  .cfi_restore lr
 	add	r3,r0,r3
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso32/gettimeofday.S b/arch/powerpc/kernel/vdso32/gettimeofday.S
index 769c2624e0a6..1e0bc5955a40 100644
--- a/arch/powerpc/kernel/vdso32/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso32/gettimeofday.S
@@ -139,6 +139,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	 */
 99:
 	li	r0,__NR_clock_gettime
+  .cfi_restore lr
 	sc
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/datapage.S b/arch/powerpc/kernel/vdso64/datapage.S
index abf17feffe40..bf9668691511 100644
--- a/arch/powerpc/kernel/vdso64/datapage.S
+++ b/arch/powerpc/kernel/vdso64/datapage.S
@@ -37,6 +37,7 @@ data_page_branch:
 	mtlr	r0
 	addi	r3, r3, __kernel_datapage_offset-data_page_branch
 	lwz	r0,0(r3)
+  .cfi_restore lr
 	add	r3,r0,r3
 	blr
   .cfi_endproc
diff --git a/arch/powerpc/kernel/vdso64/gettimeofday.S b/arch/powerpc/kernel/vdso64/gettimeofday.S
index c002adcc694c..a4ed9edfd5f0 100644
--- a/arch/powerpc/kernel/vdso64/gettimeofday.S
+++ b/arch/powerpc/kernel/vdso64/gettimeofday.S
@@ -169,6 +169,7 @@ V_FUNCTION_BEGIN(__kernel_clock_gettime)
 	 */
 99:
 	li	r0,__NR_clock_gettime
+  .cfi_restore lr
 	sc
 	blr
   .cfi_endproc

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: PowerPC/VDSO: Correct call frame information
  2018-09-14  3:40   ` [PATCH] PowerPC/VDSO: Correct call frame information Alan Modra
@ 2018-09-20  4:21     ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-09-20  4:21 UTC (permalink / raw)
  To: Alan Modra, Michael Neuling; +Cc: linuxppc-dev

On Fri, 2018-09-14 at 03:40:04 UTC, Alan Modra wrote:
> Call Frame Information is used by gdb for back-traces and inserting
> breakpoints on function return for the "finish" command.  This failed
> when inside __kernel_clock_gettime.  More concerning than difficulty
> debugging is that CFI is also used by stack frame unwinding code to
> implement exceptions.  If you have an app that needs to handle
> asynchronous exceptions for some reason, and you are unlucky enough to
> get one inside the VDSO time functions, your app will crash.
> 
> What's wrong:  There is control flow in __kernel_clock_gettime that
> reaches label 99 without saving lr in r12.  CFI info however is
> interpreted by the unwinder without reference to control flow: It's a
> simple matter of "Execute all the CFI opcodes up to the current
> address".  That means the unwinder thinks r12 contains the return
> address at label 99.  Disabuse it of that notion by resetting CFI for
> the return address at label 99.
> 
> Note that the ".cfi_restore lr" could have gone anywhere from the
> "mtlr r12" a few instructions earlier to the instruction at label 99.
> I put the CFI as late as possible, because in general that's best
> practice (and if possible grouped with other CFI in order to reduce
> the number of CFI opcodes executed when unwinding).  Using r12 as the
> return address is perfectly fine after the "mtlr r12" since r12 on
> that code path still contains the return address.
> 
> __get_datapage also has a CFI error.  That function temporarily saves
> lr in r0, and reflects that fact with ".cfi_register lr,r0".  A later
> use of r0 means the CFI at that point isn't correct, as r0 no longer
> contains the return address.  Fix that too.
> 
> Signed-off-by: Alan Modra <amodra@gmail.com>
> Tested-by: Reza Arbab <arbab@linux.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/56d20861c027498b5a1112b4f9f05b

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-20  4:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-13 23:27 [PATCH] Correct PowerPC VDSO call frame info Alan Modra
2018-09-14  0:01 ` Michael Neuling
2018-09-14  3:40   ` [PATCH] PowerPC/VDSO: Correct call frame information Alan Modra
2018-09-20  4:21     ` Michael Ellerman
2018-09-14  2:59 ` [PATCH] Correct PowerPC VDSO call frame info Reza Arbab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.