[PATCH] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE2253d LANDED

Landed in mainline as 89bbe4c798bc on 2020-06-22.

4 messages, 3 authors, 2020-06-26 · open the first message on its own page

[PATCH] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2020-06-11 12:14:32

blrl is not recommended to use as an indirect function call, as it may
corrupt the link stack predictor.

This is not a performance critical path but this should be fixed for
consistency.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/entry_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 223c4f008e63..f59a17471d4d 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -400,12 +400,12 @@ _GLOBAL(ret_from_fork)
 _GLOBAL(ret_from_kernel_thread)
 	bl	schedule_tail
 	REST_NVGPRS(r1)
-	mtlr	r14
+	mtctr	r14
 	mr	r3,r15
 #ifdef PPC64_ELF_ABI_v2
 	mr	r12,r14
 #endif
-	blrl
+	bctrl
 	li	r3,0
 	b	.Lsyscall_exit
 
-- 
2.23.0

Re: [PATCH] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread

From: Christophe Leroy <hidden>
Date: 2020-06-11 12:29:26


Le 11/06/2020 à 14:11, Nicholas Piggin a écrit :
blrl is not recommended to use as an indirect function call, as it may
corrupt the link stack predictor.

This is not a performance critical path but this should be fixed for
consistency.
There's exactly the same in entry_32.S
Should it be changed there too ... for consistency :) ?

ppc32 also uses blrl for calling syscall handler, should it be changed 
as well ?

Christophe
quoted hunk
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
  arch/powerpc/kernel/entry_64.S | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 223c4f008e63..f59a17471d4d 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -400,12 +400,12 @@ _GLOBAL(ret_from_fork)
  _GLOBAL(ret_from_kernel_thread)
  	bl	schedule_tail
  	REST_NVGPRS(r1)
-	mtlr	r14
+	mtctr	r14
  	mr	r3,r15
  #ifdef PPC64_ELF_ABI_v2
  	mr	r12,r14
  #endif
-	blrl
+	bctrl
  	li	r3,0
  	b	.Lsyscall_exit
  

Re: [PATCH] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread

From: Nicholas Piggin <npiggin@gmail.com>
Date: 2020-06-14 09:26:14

Excerpts from Christophe Leroy's message of June 11, 2020 10:26 pm:

Le 11/06/2020 à 14:11, Nicholas Piggin a écrit :
quoted
blrl is not recommended to use as an indirect function call, as it may
corrupt the link stack predictor.

This is not a performance critical path but this should be fixed for
consistency.
There's exactly the same in entry_32.S
Should it be changed there too ... for consistency :) ?

ppc32 also uses blrl for calling syscall handler, should it be changed 
as well ?
Yes I would say so. I don't know much about 32-bit implementations but
MPC7450 at least has a link stack predictor.

Thanks,
Nick

Re: [PATCH] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread

From: Michael Ellerman <hidden>
Date: 2020-06-26 05:11:51

On Thu, 11 Jun 2020 22:11:19 +1000, Nicholas Piggin wrote:
blrl is not recommended to use as an indirect function call, as it may
corrupt the link stack predictor.

This is not a performance critical path but this should be fixed for
consistency.
Applied to powerpc/next.

[1/1] powerpc/64: indirect function call use bctrl rather than blrl in ret_from_kernel_thread
      https://git.kernel.org/powerpc/c/89bbe4c798bc3a43c882179adb5222c1a972ac70

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help