linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andy Lutomirski <luto@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Alexander Potapenko <glider@google.com>,
	Dmitriy Vyukov <dvyukov@google.com>,
	Matthias Kaehlcke <mka@chromium.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [RFC PATCH 0/4] x86/asm: Add ASM_CALL() macro for inline asms with call instructions
Date: Thu, 31 Aug 2017 09:11:16 -0500	[thread overview]
Message-ID: <cover.1504186968.git.jpoimboe@redhat.com> (raw)

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

             reply	other threads:[~2017-08-31 14:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 14:11 Josh Poimboeuf [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1504186968.git.jpoimboe@redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=arnd@arndb.de \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).