Re: [PATCH v2 5/9] x86: bug: prevent gcc distortions

2018-06-05 Thread kbuild test robot
Hi Nadav,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.17 next-20180604]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nadav-Amit/x86-macrofying-inline-asm-for-better-compilation/20180605-124313
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/bug.h:5:0,
from include/linux/crypto.h:23,
from arch/x86/kernel/asm-offsets.c:9:
   include/linux/ktime.h: In function 'ktime_divns':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/ktime.h:150:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(div < 0);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_insert_fast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/rhashtable.h:936:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(ht->p.obj_hashfn);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_get_insert_fast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:962:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(ht->p.obj_hashfn);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_insert_key':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:996:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(!ht->p.obj_hashfn || !key);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_get_insert_key':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:1020:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(!ht->p.obj_hashfn || !key);
 ^~
   include/linux/crypto.h: In function 'crypto_blkcipher_cast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/crypto.h:1118:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
 ^~
  

Re: [PATCH v2 5/9] x86: bug: prevent gcc distortions

2018-06-05 Thread kbuild test robot
Hi Nadav,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.17 next-20180604]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nadav-Amit/x86-macrofying-inline-asm-for-better-compilation/20180605-124313
config: i386-tinyconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/bug.h:5:0,
from include/linux/crypto.h:23,
from arch/x86/kernel/asm-offsets.c:9:
   include/linux/ktime.h: In function 'ktime_divns':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/ktime.h:150:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(div < 0);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_insert_fast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/rhashtable.h:936:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(ht->p.obj_hashfn);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_get_insert_fast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:962:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(ht->p.obj_hashfn);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_insert_key':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:996:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(!ht->p.obj_hashfn || !key);
 ^~
   include/linux/rhashtable.h: In function 'rhashtable_lookup_get_insert_key':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
   include/linux/rhashtable.h:1020:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(!ht->p.obj_hashfn || !key);
 ^~
   include/linux/crypto.h: In function 'crypto_blkcipher_cast':
>> arch/x86/include/asm/bug.h:31:17: error: invalid application of 'sizeof' to 
>> incomplete type 'struct bug_entry'
"i" (sizeof(struct bug_entry)));  \
^
   arch/x86/include/asm/bug.h:37:2: note: in expansion of macro '_BUG_FLAGS'
 _BUG_FLAGS(ASM_UD2, 0); \
 ^~
   include/asm-generic/bug.h:176:47: note: in expansion of macro 'BUG'
#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  ^~~
>> include/linux/crypto.h:1118:2: note: in expansion of macro 'BUG_ON'
 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_BLKCIPHER);
 ^~
  

[PATCH v2 5/9] x86: bug: prevent gcc distortions

2018-06-04 Thread Nadav Amit
GCC considers the number of statements in inlined assembly blocks,
according to new-lines and semicolons, as an indication to the cost of
the block in time and space. This data is distorted by the kernel code,
which puts information in alternative sections. As a result, the
compiler may perform incorrect inlining and branch optimizations.

The solution is to set an assembly macro and call it from the inlinedv
assembly block. As a result GCC considers the inline assembly block as
a single instruction.

This patch increases the kernel size:

   textdata bss dec hex filename
18146889 10225380 2957312 31329581 1de0d2d ./vmlinux before
18147336 10226688 2957312 31331336 1de1408 ./vmlinux after (+1755)

But enables more aggressive inlining (and probably branch decisions).
The number of static text symbols in vmlinux is lower.

Static text symbols:
Before: 40218
After:  40053   (-165)

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: x...@kernel.org
Cc: Peter Zijlstra 
Cc: Josh Poimboeuf 

Signed-off-by: Nadav Amit 
---
 arch/x86/include/asm/bug.h | 98 ++
 arch/x86/kernel/macros.S   |  1 +
 2 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index 6804d6642767..5090035e6d16 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -4,6 +4,8 @@
 
 #include 
 
+#ifndef __ASSEMBLY__
+
 /*
  * Despite that some emulators terminate on UD2, we use it for WARN().
  *
@@ -20,53 +22,15 @@
 
 #define LEN_UD22
 
-#ifdef CONFIG_GENERIC_BUG
-
-#ifdef CONFIG_X86_32
-# define __BUG_REL(val)".long " __stringify(val)
-#else
-# define __BUG_REL(val)".long " __stringify(val) " - 2b"
-#endif
-
-#ifdef CONFIG_DEBUG_BUGVERBOSE
-
-#define _BUG_FLAGS(ins, flags) \
-do {   \
-   asm 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"   \
-"\t.word %c1""\t# bug_entry::line\n"   \
-"\t.word %c2""\t# bug_entry::flags\n"  \
-"\t.org 2b+%c3\n"  \
-".popsection"  \
-: : "i" (__FILE__), "i" (__LINE__),\
-"i" (flags),   \
-"i" (sizeof(struct bug_entry)));   \
-} while (0)
-
-#else /* !CONFIG_DEBUG_BUGVERBOSE */
-
 #define _BUG_FLAGS(ins, flags) \
 do {   \
-   asm volatile("1:\t" ins "\n"\
-".pushsection __bug_table,\"aw\"\n"\
-"2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
-"\t.word %c0""\t# bug_entry::flags\n"  \
-"\t.org 2b+%c1\n"  \
-".popsection"  \
-: : "i" (flags),   \
+   asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 "   \
+"flags=%c2 size=%c3"   \
+: : "i" (__FILE__), "i" (__LINE__),\
+"i" (flags),   \
 "i" (sizeof(struct bug_entry)));   \
 } while (0)
 
-#endif /* CONFIG_DEBUG_BUGVERBOSE */
-
-#else
-
-#define _BUG_FLAGS(ins, flags)  asm volatile(ins)
-
-#endif /* CONFIG_GENERIC_BUG */
-
 #define HAVE_ARCH_BUG
 #define BUG()  \
 do {   \
@@ -82,4 +46,54 @@ do { 
\
 
 #include 
 
+#else /* __ASSEMBLY__ */
+
+#ifdef CONFIG_GENERIC_BUG
+
+#ifdef CONFIG_X86_32
+.macro __BUG_REL val:req
+   .long \val
+.endm
+#else
+.macro __BUG_REL val:req
+   .long \val - 2b
+.endm
+#endif
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+
+.macro ASM_BUG ins:req file:req line:req flags:req size:req
+1: \ins
+   .pushsection __bug_table,"aw"
+2: __BUG_REL val=1b# bug_entry::bug_addr
+   __BUG_REL val=\file # bug_entry::file
+   .word \line # bug_entry::line
+   .word \flags# bug_entry::flags
+   .org 2b+\size
+   .popsection
+.endm
+
+#else /* !CONFIG_DEBUG_BUGVERBOSE */
+
+.macro ASM_BUG ins:req file:req line:req flags:req size:req
+1: \ins
+ 

[PATCH v2 5/9] x86: bug: prevent gcc distortions

2018-06-04 Thread Nadav Amit
GCC considers the number of statements in inlined assembly blocks,
according to new-lines and semicolons, as an indication to the cost of
the block in time and space. This data is distorted by the kernel code,
which puts information in alternative sections. As a result, the
compiler may perform incorrect inlining and branch optimizations.

The solution is to set an assembly macro and call it from the inlinedv
assembly block. As a result GCC considers the inline assembly block as
a single instruction.

This patch increases the kernel size:

   textdata bss dec hex filename
18146889 10225380 2957312 31329581 1de0d2d ./vmlinux before
18147336 10226688 2957312 31331336 1de1408 ./vmlinux after (+1755)

But enables more aggressive inlining (and probably branch decisions).
The number of static text symbols in vmlinux is lower.

Static text symbols:
Before: 40218
After:  40053   (-165)

Cc: Thomas Gleixner 
Cc: Ingo Molnar 
Cc: "H. Peter Anvin" 
Cc: x...@kernel.org
Cc: Peter Zijlstra 
Cc: Josh Poimboeuf 

Signed-off-by: Nadav Amit 
---
 arch/x86/include/asm/bug.h | 98 ++
 arch/x86/kernel/macros.S   |  1 +
 2 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h
index 6804d6642767..5090035e6d16 100644
--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -4,6 +4,8 @@
 
 #include 
 
+#ifndef __ASSEMBLY__
+
 /*
  * Despite that some emulators terminate on UD2, we use it for WARN().
  *
@@ -20,53 +22,15 @@
 
 #define LEN_UD22
 
-#ifdef CONFIG_GENERIC_BUG
-
-#ifdef CONFIG_X86_32
-# define __BUG_REL(val)".long " __stringify(val)
-#else
-# define __BUG_REL(val)".long " __stringify(val) " - 2b"
-#endif
-
-#ifdef CONFIG_DEBUG_BUGVERBOSE
-
-#define _BUG_FLAGS(ins, flags) \
-do {   \
-   asm 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"   \
-"\t.word %c1""\t# bug_entry::line\n"   \
-"\t.word %c2""\t# bug_entry::flags\n"  \
-"\t.org 2b+%c3\n"  \
-".popsection"  \
-: : "i" (__FILE__), "i" (__LINE__),\
-"i" (flags),   \
-"i" (sizeof(struct bug_entry)));   \
-} while (0)
-
-#else /* !CONFIG_DEBUG_BUGVERBOSE */
-
 #define _BUG_FLAGS(ins, flags) \
 do {   \
-   asm volatile("1:\t" ins "\n"\
-".pushsection __bug_table,\"aw\"\n"\
-"2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n"   \
-"\t.word %c0""\t# bug_entry::flags\n"  \
-"\t.org 2b+%c1\n"  \
-".popsection"  \
-: : "i" (flags),   \
+   asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 "   \
+"flags=%c2 size=%c3"   \
+: : "i" (__FILE__), "i" (__LINE__),\
+"i" (flags),   \
 "i" (sizeof(struct bug_entry)));   \
 } while (0)
 
-#endif /* CONFIG_DEBUG_BUGVERBOSE */
-
-#else
-
-#define _BUG_FLAGS(ins, flags)  asm volatile(ins)
-
-#endif /* CONFIG_GENERIC_BUG */
-
 #define HAVE_ARCH_BUG
 #define BUG()  \
 do {   \
@@ -82,4 +46,54 @@ do { 
\
 
 #include 
 
+#else /* __ASSEMBLY__ */
+
+#ifdef CONFIG_GENERIC_BUG
+
+#ifdef CONFIG_X86_32
+.macro __BUG_REL val:req
+   .long \val
+.endm
+#else
+.macro __BUG_REL val:req
+   .long \val - 2b
+.endm
+#endif
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+
+.macro ASM_BUG ins:req file:req line:req flags:req size:req
+1: \ins
+   .pushsection __bug_table,"aw"
+2: __BUG_REL val=1b# bug_entry::bug_addr
+   __BUG_REL val=\file # bug_entry::file
+   .word \line # bug_entry::line
+   .word \flags# bug_entry::flags
+   .org 2b+\size
+   .popsection
+.endm
+
+#else /* !CONFIG_DEBUG_BUGVERBOSE */
+
+.macro ASM_BUG ins:req file:req line:req flags:req size:req
+1: \ins
+