LKML Archive on
 help / color / Atom feed
From: Masahiro Yamada <>
To: Ingo Molnar <>,
	Thomas Gleixner <>,
	Borislav Petkov <>, "H . Peter Anvin" <>,
Cc: Richard Biener <>, Nadav Amit <>,
	Peter Zijlstra <>,
	Segher Boessenkool <>,
	Masahiro Yamada <>,
Subject: [RFC PATCH] compiler.h: support asm inline qualifier for better inlining
Date: Thu, 13 Dec 2018 18:59:14 +0900
Message-ID: <> (raw)

With the 'inline' qualifier supported for GCC's extended asm, we can
improve inlining where we know the actual code size of asm statement
is smaller than it looks.

You can mark such asm statements as 'asm_inline' instead of 'asm'.
'asm_volatile_goto' is always considered as the minimum code size.

Kconfig checks if the compiler supports 'asm inline'. In unsupported,
'asm_inline' falls back to 'asm'.

Signed-off-by: Masahiro Yamada <>

GCC 9 is not released yet, but I wanted to show how easy it is
to improve asm inlining thanks to the brand new 'asm inline' syntax.

The 'inline' qualifier is explained here:

To try this patch, the following two prerequisites are necessary.

 [1] Revert in-kernel workarounds

 [2] Replace the macros like follows:

     __inline    ->  inline
     __inline__  ->  inline

     Peter Zijlstra suggested to do this by scripting:

Then, replace 'asm' with 'asm_inline', for example, like follows:

 diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
 index 6804d66..5dbe012 100644
 --- a/arch/x86/include/asm/bug.h
 +++ b/arch/x86/include/asm/bug.h
 @@ -32,7 +32,7 @@

  #define _BUG_FLAGS(ins, flags)                                         \
  do {                                                                   \
 -       asm volatile("1:\t" ins "\n"                                    \
 +       asm_inline volatile("1:\t" ins "\n"                             \
                      ".pushsection __bug_table,\"aw\"\n"                \
                      "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
                      "\t"  __BUG_REL(%c0) "\t# bug_entry::file\n"       \

 include/linux/compiler-gcc.h   | 2 +-
 include/linux/compiler_types.h | 8 +++++++-
 init/Kconfig                   | 3 +++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 2010493..c04b350 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -121,7 +121,7 @@
  * (asm goto is automatically volatile - the naming reflects this.)
-#define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
+#define asm_volatile_goto(x...)	do { asm_inline goto(x); asm (""); } while (0)
  * sparse (__CHECKER__) pretends to be gcc, but can't do constant
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 5280aee..c989bcf 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -131,7 +131,13 @@ struct ftrace_likely_data {
 #ifndef asm_volatile_goto
-#define asm_volatile_goto(x...) asm goto(x)
+#define asm_volatile_goto(x...) asm_inline goto(x)
+# define asm_inline asm __inline__
+# define asm_inline asm
 /* Are two types/vars the same type (ignoring qualifiers)? */
diff --git a/init/Kconfig b/init/Kconfig
index cf5b5a0..52cf7f1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -23,6 +23,9 @@ config CLANG_VERSION
 	default $(shell,$(srctree)/scripts/ $(CC))
+	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 	depends on !UML

                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone