Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/unwind/orc: Change REG_SP_INDIRECT

Currently REG_SP_INDIRECT is unused but means (%rsp + offset),
change it to mean (%rsp) + offset.

The reason is that we're going to swizzle stack in the middle of a C
function with non-trivial stack footprint. This means that when the
unwinder finds the ToS, it needs to dereference it (%rsp) and then add
the offset to the next frame, resulting in: (%rsp) + offset

This is somewhat unfortunate, since REG_BP_INDIRECT is used (by DRAP)
and thus needs to retain the current (%rbp + offset).

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>

+5 -2
+4 -1
arch/x86/kernel/unwind_orc.c
··· 471 471 break; 472 472 473 473 case ORC_REG_SP_INDIRECT: 474 - sp = state->sp + orc->sp_offset; 474 + sp = state->sp; 475 475 indirect = true; 476 476 break; 477 477 ··· 521 521 if (indirect) { 522 522 if (!deref_stack_reg(state, sp, &sp)) 523 523 goto err; 524 + 525 + if (orc->sp_reg == ORC_REG_SP_INDIRECT) 526 + sp += orc->sp_offset; 524 527 } 525 528 526 529 /* Find IP, SP and possibly regs: */
+1 -1
tools/objtool/orc_dump.c
··· 55 55 if (reg == ORC_REG_BP_INDIRECT) 56 56 printf("(bp%+d)", offset); 57 57 else if (reg == ORC_REG_SP_INDIRECT) 58 - printf("(sp%+d)", offset); 58 + printf("(sp)%+d", offset); 59 59 else if (reg == ORC_REG_UNDEFINED) 60 60 printf("(und)"); 61 61 else