Skip to content

Commit

Permalink
asm/head: balance branches to avoid link stack predictor mispredicts
Browse files Browse the repository at this point in the history
The Linux wrapper for OPAL call and return is arranged like this:

  __opal_call:
      mflr   r0
      std    r0,PPC_STK_LROFF(r1)
      LOAD_REG_ADDR(r11, opal_return)
      mtlr   r11
      hrfid  -> OPAL

  opal_return:
      ld     r0,PPC_STK_LROFF(r1)
      mtlr   r0
      blr

When skiboot returns to Linux, it branches to LR (i.e., opal_return)
with a blr. This unbalances the link stack predictor and will cause
mispredicts back up the return stack.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
npiggin authored and stewartsmith committed Apr 17, 2019
1 parent f244f3e commit 32a23ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion asm/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,12 @@ opal_entry:
lwz %r11,CPUTHREAD_IN_OPAL_CALL(%r12)
subi %r11,%r11,1
stw %r11,CPUTHREAD_IN_OPAL_CALL(%r12)
blr
/*
* blr with BH=01b means it's not a function return, OPAL was entered
* via (h)rfid not bl, so we don't have a corresponding link stack
* prediction to return to here.
*/
bclr 20,0,1

.global start_kernel
start_kernel:
Expand Down

0 comments on commit 32a23ae

Please sign in to comment.