RFC x86/asm: Add ASM_CALL() macro for inline asms with call instructions
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest4 patches 21 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | x86/paravirt: Fix output constraint macro namesarch/ | +17 | 0 replies | |
| 2/4 | x86/asm: Convert some inline asm positional operands to named operandsarch/ arch/ arch/ +8 more | +99 | 0 replies | |
| 3/4 | x86/asm: Make alternative macro interfaces more clear and consistentarch/ arch/ arch/ +7 more | +155 | 18 replies | |
| 4/4 | x86/asm: Use ASM_CALL() macro for inline asm statements with call instructionsarch/ arch/ arch/ +14 more | +237 | 3 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC PATCH 0/4] x86/asm: Add ASM_CALL() macro for inline asms with call instructions
Making this RFC because I'm not sure if there's a better solution (like maybe trying to convince the clang folks to support the undocumented GCC syntax for this). Opinions and better ideas welcome.
For inline asm statements which have a "call" instruction, we have to set the stack pointer as a constraint to convince GCC to ensure the frame pointer is set up first:
register void *__sp asm(_ASM_SP);
asm("call foo" : "+r" (__sp))Clang doesn't have a known way to do the same thing. Doing the sp constraint thing causes it to corrupt the stack pointer.
Patch 4/4 adds a wrapper around such inline asm statements.
Before:
register void *__sp asm(_ASM_SP);
asm("call foo" : outputs, "+r" (__sp) : inputs : clobbers);
After:
ASM_CALL("call foo", outputs, inputs, clobbers);
A limitation of the wrapper is that it doesn't support positional operand names ("%0") and constraints ("0" (foo)).
The benefits of the wrapper are:
- Allows clang-built kernels to boot.
- Removes the stack pointer constraint with CONFIG_FRAME_POINTER=n (which may soon become the default).
- Will make it easy to handle if we ever get a documented way to do this.
NOTE: Patch 4/4 triggers a bug in the sparse preprocessor which causes
the kbuild robot to complain. I've reported the bug to the sparse mailing list.
Josh Poimboeuf (4):
x86/paravirt: Fix output constraint macro names
x86/asm: Convert some inline asm positional operands to named operands x86/asm: Make alternative macro interfaces more clear and consistent x86/asm: Use ASM_CALL() macro for inline asm statements with call
instructions
arch/x86/include/asm/alternative.h | 72 ++++------- arch/x86/include/asm/apic.h | 7 +- arch/x86/include/asm/arch_hweight.h | 14 +- arch/x86/include/asm/atomic64_32.h | 101 +++++++++------ arch/x86/include/asm/cmpxchg_32.h | 20 +-- arch/x86/include/asm/mshyperv.h | 51 ++++---- arch/x86/include/asm/page_64.h | 6 +- arch/x86/include/asm/paravirt_types.h | 86 ++++++------- arch/x86/include/asm/percpu.h | 13 +- arch/x86/include/asm/preempt.h | 15 +-- arch/x86/include/asm/processor.h | 41 +++--- arch/x86/include/asm/rwsem.h | 155 ++++++++++++----------- arch/x86/include/asm/special_insns.h | 7 +- arch/x86/include/asm/uaccess.h | 24 ++-- arch/x86/include/asm/uaccess_64.h | 16 +-- arch/x86/include/asm/xen/hypercall.h | 59 +++++---- arch/x86/kvm/emulate.c | 9 +- arch/x86/kvm/vmx.c | 17 +-- arch/x86/mm/fault.c | 13 +- include/linux/compiler-clang.h | 2 + include/linux/compiler-gcc.h | 19 +++ include/linux/compiler.h | 34 +++++ tools/objtool/Documentation/stack-validation.txt | 19 +-- 23 files changed, 427 insertions(+), 373 deletions(-)
Signature · 1 line
2.13.5