1. 18 7月, 2022 1 次提交
    • U
      compiler-gcc.h: remove ancient workaround for gcc PR 58670 · 43c249ea
      Uros Bizjak 提交于
      The workaround for 'asm goto' miscompilation introduces a compiler barrier
      quirk that inhibits many useful compiler optimizations.  For example,
      __try_cmpxchg_user compiles to:
      
         11375:	41 8b 4d 00          	mov    0x0(%r13),%ecx
         11379:	41 8b 02             	mov    (%r10),%eax
         1137c:	f0 0f b1 0a          	lock cmpxchg %ecx,(%rdx)
         11380:	0f 94 c2             	sete   %dl
         11383:	84 d2                	test   %dl,%dl
         11385:	75 c4                	jne    1134b <...>
         11387:	41 89 02             	mov    %eax,(%r10)
      
      where the barrier inhibits flags propagation from asm when compiled with
      gcc-12.
      
      When the mentioned quirk is removed, the following code is generated:
      
         11553:	41 8b 4d 00          	mov    0x0(%r13),%ecx
         11557:	41 8b 02             	mov    (%r10),%eax
         1155a:	f0 0f b1 0a          	lock cmpxchg %ecx,(%rdx)
         1155e:	74 c9                	je     11529 <...>
         11560:	41 89 02             	mov    %eax,(%r10)
      
      The refered compiler bug:
      
      http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
      
      was fixed for gcc-4.8.2.
      
      Current minimum required version of GCC is version 5.1 which has the above
      'asm goto' miscompilation fixed, so remove the workaround.
      
      Link: https://lkml.kernel.org/r/20220624141412.72274-1-ubizjak@gmail.comSigned-off-by: NUros Bizjak <ubizjak@gmail.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      43c249ea
  2. 08 5月, 2022 1 次提交
  3. 11 3月, 2022 1 次提交
  4. 06 3月, 2022 1 次提交
  5. 07 11月, 2021 1 次提交
    • K
      Compiler Attributes: add __alloc_size() for better bounds checking · 86cffecd
      Kees Cook 提交于
      GCC and Clang can use the "alloc_size" attribute to better inform the
      results of __builtin_object_size() (for compile-time constant values).
      Clang can additionally use alloc_size to inform the results of
      __builtin_dynamic_object_size() (for run-time values).
      
      Because GCC sees the frequent use of struct_size() as an allocator size
      argument, and notices it can return SIZE_MAX (the overflow indication),
      it complains about these call sites overflowing (since SIZE_MAX is
      greater than the default -Walloc-size-larger-than=PTRDIFF_MAX).  This
      isn't helpful since we already know a SIZE_MAX will be caught at
      run-time (this was an intentional design).  To deal with this, we must
      disable this check as it is both a false positive and redundant.  (Clang
      does not have this warning option.)
      
      Unfortunately, just checking the -Wno-alloc-size-larger-than is not
      sufficient to make the __alloc_size attribute behave correctly under
      older GCC versions.  The attribute itself must be disabled in those
      situations too, as there appears to be no way to reliably silence the
      SIZE_MAX constant expression cases for GCC versions less than 9.1:
      
         In file included from ./include/linux/resource_ext.h:11,
                          from ./include/linux/pci.h:40,
                          from drivers/net/ethernet/intel/ixgbe/ixgbe.h:9,
                          from drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c:4:
         In function 'kmalloc_node',
             inlined from 'ixgbe_alloc_q_vector' at ./include/linux/slab.h:743:9:
         ./include/linux/slab.h:618:9: error: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
           return __kmalloc_node(size, flags, node);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ./include/linux/slab.h: In function 'ixgbe_alloc_q_vector':
         ./include/linux/slab.h:455:7: note: in a call to allocation function '__kmalloc_node' declared here
          void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_slab_alignment __malloc;
                ^~~~~~~~~~~~~~
      
      Specifically:
       '-Wno-alloc-size-larger-than' is not correctly handled by GCC < 9.1
          https://godbolt.org/z/hqsfG7q84 (doesn't disable)
          https://godbolt.org/z/P9jdrPTYh (doesn't admit to not knowing about option)
          https://godbolt.org/z/465TPMWKb (only warns when other warnings appear)
      
       '-Walloc-size-larger-than=18446744073709551615' is not handled by GCC < 8.2
          https://godbolt.org/z/73hh1EPxz (ignores numeric value)
      
      Since anything marked with __alloc_size would also qualify for marking
      with __malloc, just include __malloc along with it to avoid redundant
      markings.  (Suggested by Linus Torvalds.)
      
      Finally, make sure checkpatch.pl doesn't get confused about finding the
      __alloc_size attribute on functions.  (Thanks to Joe Perches.)
      
      Link: https://lkml.kernel.org/r/20210930222704.2631604-3-keescook@chromium.orgSigned-off-by: NKees Cook <keescook@chromium.org>
      Tested-by: NRandy Dunlap <rdunlap@infradead.org>
      Cc: Andy Whitcroft <apw@canonical.com>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Daniel Micay <danielmicay@gmail.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Alexandre Bounine <alex.bou9@gmail.com>
      Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
      Cc: Ira Weiny <ira.weiny@intel.com>
      Cc: Jing Xiangfeng <jingxiangfeng@huawei.com>
      Cc: John Hubbard <jhubbard@nvidia.com>
      Cc: kernel test robot <lkp@intel.com>
      Cc: Matt Porter <mporter@kernel.crashing.org>
      Cc: Miguel Ojeda <ojeda@kernel.org>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Souptick Joarder <jrdr.linux@gmail.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      86cffecd
  6. 21 10月, 2021 1 次提交
    • K
      compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer · 9a48e756
      Kees Cook 提交于
      When Clang is using the hwaddress sanitizer, it sets __SANITIZE_ADDRESS__
      explicitly:
      
       #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
       /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
       #define __SANITIZE_ADDRESS__
       #endif
      
      Once hwaddress sanitizer was added to GCC, however, a separate define
      was created, __SANITIZE_HWADDRESS__. The kernel is expecting to find
      __SANITIZE_ADDRESS__ in either case, though, and the existing string
      macros break on supported architectures:
      
       #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
                !defined(__SANITIZE_ADDRESS__)
      
      where as other architectures (like arm32) have no idea about hwaddress
      sanitizer and just check for __SANITIZE_ADDRESS__:
      
       #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
      
      This would lead to compiler foritfy self-test warnings when building
      with CONFIG_KASAN_SW_TAGS=y:
      
      warning: unsafe memmove() usage lacked '__read_overflow2' symbol in lib/test_fortify/read_overflow2-memmove.c
      warning: unsafe memcpy() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memcpy.c
      ...
      
      Sort this out by also defining __SANITIZE_ADDRESS__ in GCC under the
      hwaddress sanitizer.
      Suggested-by: NArnd Bergmann <arnd@arndb.de>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Will Deacon <will@kernel.org>
      Cc: Arvind Sankar <nivedita@alum.mit.edu>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: llvm@lists.linux.dev
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Reviewed-by: NNathan Chancellor <nathan@kernel.org>
      Acked-by: NMiguel Ojeda <ojeda@kernel.org>
      Reviewed-by: NMarco Elver <elver@google.com>
      Link: https://lore.kernel.org/r/20211020200039.170424-1-keescook@chromium.org
      9a48e756
  7. 25 9月, 2021 1 次提交
    • K
      compiler_types.h: Remove __compiletime_object_size() · c80d92fb
      Kees Cook 提交于
      Since all compilers support __builtin_object_size(), and there is only
      one user of __compiletime_object_size, remove it to avoid the needless
      indirection. This lets Clang reason about check_copy_size() correctly.
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/1179Suggested-by: NNick Desaulniers <ndesaulniers@google.com>
      Cc: Nathan Chancellor <nathan@kernel.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Sedat Dilek <sedat.dilek@gmail.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Marco Elver <elver@google.com>
      Cc: Arvind Sankar <nivedita@alum.mit.edu>
      Cc: Masahiro Yamada <masahiroy@kernel.org>
      Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Sami Tolvanen <samitolvanen@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Gabriel Krisman Bertazi <krisman@collabora.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Reviewed-by: NMiguel Ojeda <ojeda@kernel.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      c80d92fb
  8. 14 9月, 2021 2 次提交
  9. 09 9月, 2021 1 次提交
  10. 02 7月, 2021 1 次提交
  11. 01 5月, 2021 1 次提交
  12. 16 2月, 2021 1 次提交
  13. 15 1月, 2021 1 次提交
  14. 15 11月, 2020 1 次提交
  15. 30 10月, 2020 1 次提交
  16. 14 10月, 2020 1 次提交
  17. 17 7月, 2020 1 次提交
  18. 09 7月, 2020 1 次提交
    • L
      Raise gcc version requirement to 4.9 · 6ec4476a
      Linus Torvalds 提交于
      I realize that we fairly recently raised it to 4.8, but the fact is, 4.9
      is a much better minimum version to target.
      
      We have a number of workarounds for actual bugs in pre-4.9 gcc versions
      (including things like internal compiler errors on ARM), but we also
      have some syntactic workarounds for lacking features.
      
      In particular, raising the minimum to 4.9 means that we can now just
      assume _Generic() exists, which is likely the much better replacement
      for a lot of very convoluted built-time magic with conditionals on
      sizeof and/or __builtin_choose_expr() with same_type() etc.
      
      Using _Generic also means that you will need to have a very recent
      version of 'sparse', but thats easy to build yourself, and much less of
      a hassle than some old gcc version can be.
      
      The latest (in a long string) of reasons for minimum compiler version
      upgrades was commit 5435f73d ("efi/x86: Fix build with gcc 4").
      
      Ard points out that RHEL 7 uses gcc-4.8, but the people who stay back on
      old RHEL versions persumably also don't build their own kernels anyway.
      And maybe they should cross-built or just have a little side affair with
      a newer compiler?
      Acked-by: NArd Biesheuvel <ardb@kernel.org>
      Acked-by: NPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      6ec4476a
  19. 15 6月, 2020 1 次提交
  20. 16 4月, 2020 1 次提交
  21. 07 1月, 2020 1 次提交
    • M
      kcsan: Add __no_kcsan function attribute · e33f9a16
      Marco Elver 提交于
      Since the use of -fsanitize=thread is an implementation detail of KCSAN,
      the name __no_sanitize_thread could be misleading if used widely.
      Instead, we introduce the __no_kcsan attribute which is shorter and more
      accurate in the context of KCSAN.
      
      This matches the attribute name __no_kcsan_or_inline. The use of
      __kcsan_or_inline itself is still required for __always_inline functions
      to retain compatibility with older compilers.
      Signed-off-by: NMarco Elver <elver@google.com>
      Signed-off-by: NPaul E. McKenney <paulmck@kernel.org>
      e33f9a16
  22. 16 11月, 2019 1 次提交
  23. 19 7月, 2019 1 次提交
    • J
      bpf: Disable GCC -fgcse optimization for ___bpf_prog_run() · 3193c083
      Josh Poimboeuf 提交于
      On x86-64, with CONFIG_RETPOLINE=n, GCC's "global common subexpression
      elimination" optimization results in ___bpf_prog_run()'s jumptable code
      changing from this:
      
      	select_insn:
      		jmp *jumptable(, %rax, 8)
      		...
      	ALU64_ADD_X:
      		...
      		jmp *jumptable(, %rax, 8)
      	ALU_ADD_X:
      		...
      		jmp *jumptable(, %rax, 8)
      
      to this:
      
      	select_insn:
      		mov jumptable, %r12
      		jmp *(%r12, %rax, 8)
      		...
      	ALU64_ADD_X:
      		...
      		jmp *(%r12, %rax, 8)
      	ALU_ADD_X:
      		...
      		jmp *(%r12, %rax, 8)
      
      The jumptable address is placed in a register once, at the beginning of
      the function.  The function execution can then go through multiple
      indirect jumps which rely on that same register value.  This has a few
      issues:
      
      1) Objtool isn't smart enough to be able to track such a register value
         across multiple recursive indirect jumps through the jump table.
      
      2) With CONFIG_RETPOLINE enabled, this optimization actually results in
         a small slowdown.  I measured a ~4.7% slowdown in the test_bpf
         "tcpdump port 22" selftest.
      
         This slowdown is actually predicted by the GCC manual:
      
           Note: When compiling a program using computed gotos, a GCC
           extension, you may get better run-time performance if you
           disable the global common subexpression elimination pass by
           adding -fno-gcse to the command line.
      
      So just disable the optimization for this function.
      
      Fixes: e55a7325 ("bpf: Fix ORC unwinding in non-JIT BPF code")
      Reported-by: NRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Acked-by: NAlexei Starovoitov <ast@kernel.org>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/30c3ca29ba037afcbd860a8672eef0021addf9fe.1563413318.git.jpoimboe@redhat.com
      3193c083
  24. 09 1月, 2019 2 次提交
    • M
      include/linux/compiler*.h: fix OPTIMIZER_HIDE_VAR · 3e2ffd65
      Michael S. Tsirkin 提交于
      Since commit 815f0ddb ("include/linux/compiler*.h: make compiler-*.h
      mutually exclusive") clang no longer reuses the OPTIMIZER_HIDE_VAR macro
      from compiler-gcc - instead it gets the version in
      include/linux/compiler.h.  Unfortunately that version doesn't actually
      prevent compiler from optimizing out the variable.
      
      Fix up by moving the macro out from compiler-gcc.h to compiler.h.
      Compilers without incline asm support will keep working
      since it's protected by an ifdef.
      
      Also fix up comments to match reality since we are no longer overriding
      any macros.
      
      Build-tested with gcc and clang.
      
      Fixes: 815f0ddb ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")
      Cc: Eli Friedman <efriedma@codeaurora.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      3e2ffd65
    • W
      x86, modpost: Replace last remnants of RETPOLINE with CONFIG_RETPOLINE · e4f35891
      WANG Chao 提交于
      Commit
      
        4cd24de3 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
      
      replaced the RETPOLINE define with CONFIG_RETPOLINE checks. Remove the
      remaining pieces.
      
       [ bp: Massage commit message. ]
      
      Fixes: 4cd24de3 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
      Signed-off-by: NWANG Chao <chao.wang@ucloud.cn>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Reviewed-by: NZhenzhong Duan <zhenzhong.duan@oracle.com>
      Reviewed-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David Woodhouse <dwmw@amazon.co.uk>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Cc: Michal Marek <michal.lkml@markovi.net>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tim Chen <tim.c.chen@linux.intel.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: linux-kbuild@vger.kernel.org
      Cc: srinivas.eeda@oracle.com
      Cc: stable <stable@vger.kernel.org>
      Cc: x86-ml <x86@kernel.org>
      Link: https://lkml.kernel.org/r/20181210163725.95977-1-chao.wang@ucloud.cn
      e4f35891
  25. 29 12月, 2018 1 次提交
  26. 06 11月, 2018 1 次提交
  27. 19 10月, 2018 1 次提交
  28. 09 10月, 2018 1 次提交
  29. 01 10月, 2018 5 次提交
  30. 20 9月, 2018 2 次提交
  31. 23 8月, 2018 1 次提交
  32. 21 8月, 2018 1 次提交
  33. 19 8月, 2018 1 次提交
    • L
      deprecate the '__deprecated' attribute warnings entirely and for good · 771c0353
      Linus Torvalds 提交于
      We haven't had lots of deprecation warnings lately, but the rdma use of
      it made them flare up again.
      
      They are not useful.  They annoy everybody, and nobody ever does
      anything about them, because it's always "somebody elses problem".  And
      when people start thinking that warnings are normal, they stop looking
      at them, and the real warnings that mean something go unnoticed.
      
      If you want to get rid of a function, just get rid of it.  Convert every
      user to the new world order.
      
      And if you can't do that, then don't annoy everybody else with your
      marking that says "I couldn't be bothered to fix this, so I'll just spam
      everybody elses build logs with warnings about my laziness".
      
      Make a kernelnewbies wiki page about things that could be cleaned up,
      write a blog post about it, or talk to people on the mailing lists.  But
      don't add warnings to the kernel build about cleanup that you think
      should happen but you aren't doing yourself.
      
      Don't.  Just don't.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      771c0353