linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] x86/asm: Add ASM_CALL() macro for inline asms with call instructions
@ 2017-08-31 14:11 Josh Poimboeuf
  2017-08-31 14:11 ` [RFC PATCH 1/4] x86/paravirt: Fix output constraint macro names Josh Poimboeuf
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Josh Poimboeuf @ 2017-08-31 14:11 UTC (permalink / raw)
  To: x86
  Cc: linux-kernel, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	Andy Lutomirski, Linus Torvalds, Alexander Potapenko,
	Dmitriy Vyukov, Matthias Kaehlcke, Arnd Bergmann, Peter Zijlstra

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(-)

-- 
2.13.5

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2017-09-19 16:02 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-31 14:11 [RFC PATCH 0/4] x86/asm: Add ASM_CALL() macro for inline asms with call instructions Josh Poimboeuf
2017-08-31 14:11 ` [RFC PATCH 1/4] x86/paravirt: Fix output constraint macro names Josh Poimboeuf
2017-08-31 14:11 ` [RFC PATCH 2/4] x86/asm: Convert some inline asm positional operands to named operands Josh Poimboeuf
2017-08-31 14:11 ` [RFC PATCH 3/4] x86/asm: Make alternative macro interfaces more clear and consistent Josh Poimboeuf
2017-08-31 16:11   ` Linus Torvalds
2017-08-31 17:25     ` Josh Poimboeuf
2017-08-31 17:31       ` Josh Poimboeuf
2017-09-02 10:32         ` Ingo Molnar
2017-09-14 14:48           ` Josh Poimboeuf
2017-09-14 17:16             ` Linus Torvalds
2017-09-14 17:26               ` Josh Poimboeuf
2017-09-14 17:33                 ` Josh Poimboeuf
2017-09-14 18:28                   ` Linus Torvalds
2017-09-14 18:45                     ` Josh Poimboeuf
2017-09-15 16:10                       ` Josh Poimboeuf
2017-09-15 16:53       ` Andrey Ryabinin
2017-09-15 17:20         ` Josh Poimboeuf
2017-09-15 18:01         ` Linus Torvalds
2017-09-15 23:29           ` Josh Poimboeuf
2017-09-16 22:22             ` Andrey Ryabinin
2017-09-18 17:40               ` Josh Poimboeuf
2017-09-19 16:02           ` Josh Poimboeuf
2017-08-31 14:11 ` [RFC PATCH 4/4] x86/asm: Use ASM_CALL() macro for inline asm statements with call instructions Josh Poimboeuf
2017-08-31 14:50   ` Peter Zijlstra
2017-08-31 15:21     ` Josh Poimboeuf
2017-08-31 15:36       ` Dmitry Vyukov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).