Skip to content

static_call/x86: Handle clang's conditional tail calls

Peter Zijlstra lkml llvm 1 version Applied

Status from this message: The following commit has been merged into the x86/alternatives branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 6 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/3x86/alternative: Introduce int3_emulate_jcc()arch/x86/include/asm/text-patching.h arch/x86/kernel/kprobes/core.c+39 -300 replies
2/3x86/alternative: Teach text_poke_bp() to patch Jcc.d32 instructionsarch/x86/kernel/alternative.c+47 -150 replies
3/3x86/static_call: Add support for Jcc tail-callsarch/x86/kernel/static_call.c+47 -33 replies
3/3x86/static_call: Add support for Jcc tail-callsarch/x86/kernel/static_call.c+47 -32 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchMasami Hiramatsu (Google)
1/3R-b
2/3R-b
3/3R-b R-b
3/3R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] static_call/x86: Handle clang's conditional tail calls

Erhard reported boot fails on this AMD machine when using clang and bisected it to a commit introducing a few static_call()s. Turns out that when using clang with -Os it it very likely to generate conditional tail calls like:

0000000000000350 <amd_pmu_add_event>:

  350:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1) 351: R_X86_64_NONE      __fentry__-0x4
  355:       48 83 bf 20 01 00 00 00         cmpq   $0x0,0x120(%rdi)
  35d:       0f 85 00 00 00 00       jne    363 <amd_pmu_add_event+0x13>     35f: R_X86_64_PLT32     __SCT__amd_pmu_branch_add-0x4
  363:       e9 00 00 00 00          jmp    368 <amd_pmu_add_event+0x18>     364: R_X86_64_PLT32     __x86_return_thunk-0x4

And our inline static_call() patching code can't deal with those and BUG happens -- really early.

These patches borrow the kprobe Jcc emulation to implement text_poke_bp() Jcc support, which is then used to teach inline static_call() about this form.

---
 arch/x86/include/asm/text-patching.h | 31 ++++++++++++++++++
 arch/x86/kernel/alternative.c        | 62 +++++++++++++++++++++++++++---------
 arch/x86/kernel/kprobes/core.c       | 38 +++++-----------------
 arch/x86/kernel/static_call.c        | 50 +++++++++++++++++++++++++++--
 4 files changed, 133 insertions(+), 48 deletions(-)