Re: [PATCH] powerpc/ftrace: restore r2 to caller's stack on livepatch sibling call
From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2024-07-29 14:18:08
Also in:
live-patching
From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2024-07-29 14:18:08
Also in:
live-patching
Hi Ryan, Thanks for the patch. Ryan Sullivan [off-list ref] writes:
Currently, on PowerPC machines, sibling calls in livepatched functions cause the stack to be corrupted and are thus not supported by tools such as kpatch. Below is an example stack frame showing one such currupted stacks:
...
diff --git a/arch/powerpc/kernel/trace/ftrace_entry.S b/arch/powerpc/kernel/trace/ftrace_entry.S index 76dbe9fd2c0f..4dfbe6076ad1 100644 --- a/arch/powerpc/kernel/trace/ftrace_entry.S +++ b/arch/powerpc/kernel/trace/ftrace_entry.S@@ -244,6 +244,9 @@ livepatch_handler: mtlr r12 ld r2, -24(r11) + /* Restore toc to caller's stack in case of sibling call */ + std r2, 24(r1) +
It would be good to have a comment here explaining why it's safe in all cases to store the current r2 value back to the caller's save slot. I haven't convinced myself that it is always safe, but I need to think about it a bit harder O_o cheers