1. 26 Apr, 2022 1 commit
  2. 01 Jul, 2021 1 commit
  3. 28 Jun, 2021 1 commit
    • Tanner Love's avatar
      once: implement DO_ONCE_LITE for non-fast-path "do once" functionality · a358f406
      Tanner Love authored
      
      Certain uses of "do once" functionality reside outside of fast path,
      and so do not require jump label patching via static keys, making
      existing DO_ONCE undesirable in such cases.
      
      Replace uses of __section(".data.once") with DO_ONCE_LITE(_IF)?
      
      This patch changes the return values of xfs_printk_once, printk_once,
      and printk_deferred_once. Before, they returned whether the print was
      performed, but now, they always return true. This is okay because the
      return values of the following macros are entirely ignored throughout
      the kernel:
      - xfs_printk_once
      - xfs_warn_once
      - xfs_notice_once
      - xfs_info_once
      - printk_once
      - pr_emerg_once
      - pr_alert_once
      - pr_crit_once
      - pr_err_once
      - pr_warn_once
      - pr_notice_once
      - pr_info_once
      - pr_devel_once
      - pr_debug_once
      - printk_deferred_once
      - orc_warn
      
      Changes
      v3:
        - Expand commit message to explain why changing return values of
          xfs_printk_once, printk_once, printk_deferred_once is benign
      v2:
        - Fix i386 build warnings
      Signed-off-by: default avatarTanner Love <tannerlove@google.com>
      Acked-by: default avatarEric Dumazet <edumazet@google.com>
      Acked-by: default avatarMahesh Bandewar <maheshb@google.com>
      Acked-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      a358f406
  4. 08 Apr, 2021 1 commit
    • Sami Tolvanen's avatar
      add support for Clang CFI · cf68fffb
      Sami Tolvanen authored
      This change adds support for Clang’s forward-edge Control Flow
      Integrity (CFI) checking. With CONFIG_CFI_CLANG, the compiler
      injects a runtime check before each indirect function call to ensure
      the target is a valid function with the correct static type. This
      restricts possible call targets and makes it more difficult for
      an attacker to exploit bugs that allow the modification of stored
      function pointers. For more details, see:
      
        https://clang.llvm.org/docs/ControlFlowIntegrity.html
      
      
      
      Clang requires CONFIG_LTO_CLANG to be enabled with CFI to gain
      visibility to possible call targets. Kernel modules are supported
      with Clang’s cross-DSO CFI mode, which allows checking between
      independently compiled components.
      
      With CFI enabled, the compiler injects a __cfi_check() function into
      the kernel and each module for validating local call targets. For
      cross-module calls that cannot be validated locally, the compiler
      calls the global __cfi_slowpath_diag() function, which determines
      the target module and calls the correct __cfi_check() function. This
      patch includes a slowpath implementation that uses __module_address()
      to resolve call targets, and with CONFIG_CFI_CLANG_SHADOW enabled, a
      shadow map that speeds up module look-ups by ~3x.
      
      Clang implements indirect call checking using jump tables and
      offers two methods of generating them. With canonical jump tables,
      the compiler renames each address-taken function to <function>.cfi
      and points the original symbol to a jump table entry, which passes
      __cfi_check() validation. This isn’t compatible with stand-alone
      assembly code, which the compiler doesn’t instrument, and would
      result in indirect calls to assembly code to fail. Therefore, we
      default to using non-canonical jump tables instead, where the compiler
      generates a local jump table entry <function>.cfi_jt for each
      address-taken function, and replaces all references to the function
      with the address of the jump table entry.
      
      Note that because non-canonical jump table addresses are local
      to each component, they break cross-module function address
      equality. Specifically, the address of a global function will be
      different in each module, as it's replaced with the address of a local
      jump table entry. If this address is passed to a different module,
      it won’t match the address of the same function taken there. This
      may break code that relies on comparing addresses passed from other
      components.
      
      CFI checking can be disabled in a function with the __nocfi attribute.
      Additionally, CFI can be disabled for an entire compilation unit by
      filtering out CC_FLAGS_CFI.
      
      By default, CFI failures result in a kernel panic to stop a potential
      exploit. CONFIG_CFI_PERMISSIVE enables a permissive mode, where the
      kernel prints out a rate-limited warning instead, and allows execution
      to continue. This option is helpful for locating type mismatches, but
      should only be enabled during development.
      Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20210408182843.1754385-2-samitolvanen@google.com
      cf68fffb
  5. 25 Oct, 2020 1 commit
  6. 24 Jul, 2020 1 commit
    • Ingo Molnar's avatar
      compiler.h: Move instrumentation_begin()/end() to new <linux/instrumentation.h> header · d19e789f
      Ingo Molnar authored
      Linus pointed out that compiler.h - which is a key header that gets included in every
      single one of the 28,000+ kernel files during a kernel build - was bloated in:
      
        65538966
      
      : ("vmlinux.lds.h: Create section for protection against instrumentation")
      
      Linus noted:
      
       > I have pulled this, but do we really want to add this to a header file
       > that is _so_ core that it gets included for basically every single
       > file built?
       >
       > I don't even see those instrumentation_begin/end() things used
       > anywhere right now.
       >
       > It seems excessive. That 53 lines is maybe not a lot, but it pushed
       > that header file to over 12kB, and while it's mostly comments, it's
       > extra IO and parsing basically for _every_ single file compiled in the
       > kernel.
       >
       > For what appears to be absolutely zero upside right now, and I really
       > don't see why this should be in such a core header file!
      
      Move these primitives into a new header: <linux/instrumentation.h>, and include that
      header in the headers that make use of it.
      
      Unfortunately one of these headers is asm-generic/bug.h, which does get included
      in a lot of places, similarly to compiler.h. So the de-bloating effect isn't as
      good as we'd like it to be - but at least the interfaces are defined separately.
      
      No change to functionality intended.
      Reported-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/20200604071921.GA1361070@gmail.com
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      d19e789f
  7. 11 Jun, 2020 1 commit
  8. 26 Sep, 2019 6 commits
    • Kees Cook's avatar
      bug: move WARN_ON() "cut here" into exception handler · a44f71a9
      Kees Cook authored
      The original clean up of "cut here" missed the WARN_ON() case (that does
      not have a printk message), which was fixed recently by adding an explicit
      printk of "cut here".  This had the downside of adding a printk() to every
      WARN_ON() caller, which reduces the utility of using an instruction
      exception to streamline the resulting code.  By making this a new BUGFLAG,
      all of these can be removed and "cut here" can be handled by the exception
      handler.
      
      This was very pronounced on PowerPC, but the effect can be seen on x86 as
      well.  The resulting text size of a defconfig build shows some small
      savings from this patch:
      
         text    data     bss     dec     hex filename
      19691167        5134320 1646664 26472151        193eed7 vmlinux.before
      19676362        5134260 1663048 26473670        193f4c6 vmlinux.after
      
      This change also opens the door for creating something like BUG_MSG(),
      where a custom printk() before issuing BUG(), without confusing the "cut
      here" line.
      
      Link: http://lkml.kernel.org/r/201908200943.601DD59DCE@keescook
      Fixes: 6b15f678
      
       ("include/asm-generic/bug.h: fix "cut here" for WARN_ON for __WARN_TAINT architectures")
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Reported-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      a44f71a9
    • Kees Cook's avatar
      bug: consolidate __WARN_FLAGS usage · 2da1ead4
      Kees Cook authored
      Instead of having separate tests for __WARN_FLAGS, merge the two #ifdef
      blocks and replace the synonym WANT_WARN_ON_SLOWPATH macro.
      
      Link: http://lkml.kernel.org/r/20190819234111.9019-7-keescook@chromium.org
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2da1ead4
    • Kees Cook's avatar
      bug: clean up helper macros to remove __WARN_TAINT() · d4bce140
      Kees Cook authored
      In preparation for cleaning up "cut here" even more, this removes the
      __WARN_*TAINT() helpers, as they limit the ability to add new BUGFLAG_*
      flags to call sites.  They are removed by expanding them into full
      __WARN_FLAGS() calls.
      
      Link: http://lkml.kernel.org/r/20190819234111.9019-6-keescook@chromium.org
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d4bce140
    • Kees Cook's avatar
      bug: consolidate warn_slowpath_fmt() usage · f2f84b05
      Kees Cook authored
      Instead of having a separate helper for no printk output, just consolidate
      the logic into warn_slowpath_fmt().
      
      Link: http://lkml.kernel.org/r/20190819234111.9019-4-keescook@chromium.org
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      f2f84b05
    • Kees Cook's avatar
      bug: rename __WARN_printf_taint() to __WARN_printf() · 89348fc3
      Kees Cook authored
      This just renames the helper to improve readability.
      
      Link: http://lkml.kernel.org/r/20190819234111.9019-3-keescook@chromium.org
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      89348fc3
    • Kees Cook's avatar
      bug: refactor away warn_slowpath_fmt_taint() · ee871133
      Kees Cook authored
      Patch series "Clean up WARN() "cut here" handling", v2.
      
      Christophe Leroy noticed that the fix for missing "cut here" in the WARN()
      case was adding explicit printk() calls instead of teaching the exception
      handler to add it.  This refactors the bug/warn infrastructure to pass
      this information as a new BUGFLAG.
      
      Longer details repeated from the last patch in the series:
      
      bug: move WARN_ON() "cut here" into exception handler
      
      The original cleanup of "cut here" missed the WARN_ON() case (that does
      not have a printk message), which was fixed recently by adding an explicit
      printk of "cut here".  This had the downside of adding a printk() to every
      WARN_ON() caller, which reduces the utility of using an instruction
      exception to streamline the resulting code.  By making this a new BUGFLAG,
      all of these can be removed and "cut here" can be handled by the exception
      handler.
      
      This was very pronounced on PowerPC, but the effect can be seen on x86 as
      well.  The resulting text size of a defconfig build shows some small
      savings from this patch:
      
         text    data     bss     dec     hex filename
      19691167        5134320 1646664 26472151        193eed7 vmlinux.before
      19676362        5134260 1663048 26473670        193f4c6 vmlinux.after
      
      This change also opens the door for creating something like BUG_MSG(),
      where a custom printk() before issuing BUG(), without confusing the "cut
      here" line.
      
      This patch (of 7):
      
      There's no reason to have specialized helpers for passing the warn taint
      down to __warn().  Consolidate and refactor helper macros, removing
      __WARN_printf() and warn_slowpath_fmt_taint().
      
      Link: http://lkml.kernel.org/r/20190819234111.9019-2-keescook@chromium.org
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Drew Davenport <ddavenport@chromium.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: Feng Tang <feng.tang@intel.com>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
      Cc: Borislav Petkov <bp@suse.de>
      Cc: YueHaibing <yuehaibing@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ee871133
  9. 01 Sep, 2019 1 commit
  10. 17 Jul, 2019 1 commit
  11. 25 Jan, 2019 1 commit
  12. 19 Dec, 2018 1 commit
  13. 04 Oct, 2018 1 commit
    • Nadav Amit's avatar
      x86/bug: Macrofy the BUG table section handling, to work around GCC inlining bugs · f81f8ad5
      Nadav Amit authored
      As described in:
      
        77b0bf55
      
      : ("kbuild/Makefile: Prepare for using macros in inline assembly code to work around asm() related GCC inlining bugs")
      
      GCC's inlining heuristics are broken with common asm() patterns used in
      kernel code, resulting in the effective disabling of inlining.
      
      The workaround is to set an assembly macro and call it from the inline
      assembly block. As a result GCC considers the inline assembly block as
      a single instruction. (Which it isn't, but that's the best we can get.)
      
      This patch increases the kernel size:
      
            text     data     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 better branch decisions).
      
      The number of static text symbols in vmlinux is much lower:
      
       Before: 40218
       After:  40053 (-165)
      
      The assembly code gets harder to read due to the extra macro layer.
      
      [ mingo: Rewrote the changelog. ]
      Tested-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarNadav Amit <namit@vmware.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/20181003213100.189959-7-namit@vmware.com
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      f81f8ad5
  14. 22 Aug, 2018 1 commit
    • Dmitry Vyukov's avatar
      include/asm-generic/bug.h: clarify valid uses of WARN() · 96c6a32c
      Dmitry Vyukov authored
      Explicitly state that WARN*() should be used only for recoverable kernel
      issues/bugs and that it should not be used for any kind of invalid
      external inputs or transient conditions.
      
      Motivation: it's a very useful capability to be able to understand if a
      particular kernel splat means a kernel bug or simply an invalid user-space
      program.  For the former one wants to notify kernel developers, while
      notifying kernel developers for the latter is annoying.  Even a kernel
      developer may not know what to do with a WARNING in an unfamiliar
      subsystem.  This is especially critical for any automated testing systems
      that may use panic_on_warn and mail kernel developers.
      
      The clear separation also serves as an additional documentation: is it a
      condition that must never occur because of additional checks/logic
      elsewhere?  or is it simply a check for invalid inputs or unfortunate
      conditions?
      
      Use of pr_err() for user messages also leads to better error messages.
      "Something is wrong in file foo on line X" is not particularly useful
      message for end user.  pr_err() forces developers to write more meaningful
      error messages for user.
      
      As of now we are almost there.  We are doing systematic kernel testing
      with panic_on_warn and are not seeing massive amounts of false positives.
      But every now and then another WARN on ENOMEM or invalid inputs pops up
      and leads to a lengthy argument each time.  The goal of this change is to
      officially document the rules.
      
      Link: http://lkml.kernel.org/r/20180620103716.61636-1-dvyukov@gmail.com
      
      Signed-off-by: default avatarDmitry Vyukov <dvyukov@google.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      96c6a32c
  15. 21 Feb, 2018 1 commit
    • Arnd Bergmann's avatar
      bug.h: work around GCC PR82365 in BUG() · 173a3efd
      Arnd Bergmann authored
      Looking at functions with large stack frames across all architectures
      led me discovering that BUG() suffers from the same problem as
      fortify_panic(), which I've added a workaround for already.
      
      In short, variables that go out of scope by calling a noreturn function
      or __builtin_unreachable() keep using stack space in functions
      afterwards.
      
      A workaround that was identified is to insert an empty assembler
      statement just before calling the function that doesn't return.  I'm
      adding a macro "barrier_before_unreachable()" to document this, and
      insert calls to that in all instances of BUG() that currently suffer
      from this problem.
      
      The files that saw the largest change from this had these frame sizes
      before, and much less with my patch:
      
        fs/ext4/inode.c:82:1: warning: the frame size of 1672 bytes is larger than 800 bytes [-Wframe-larger-than=]
        fs/ext4/namei.c:434:1: warning: the frame size of 904 bytes is larger than 800 bytes [-Wframe-larger-than=]
        fs/ext4/super.c:2279:1: warning: the frame size of 1160 bytes is larger than 800 bytes [-Wframe-larger-than=]
        fs/ext4/xattr.c:146:1: warning: the frame size of 1168 bytes is larger than 800 bytes [-Wframe-larger-than=]
        fs/f2fs/inode.c:152:1: warning: the frame size of 1424 bytes is larger than 800 bytes [-Wframe-larger-than=]
        net/netfilter/ipvs/ip_vs_core.c:1195:1: warning: the frame size of 1068 bytes is larger than 800 bytes [-Wframe-larger-than=]
        net/netfilter/ipvs/ip_vs_core.c:395:1: warning: the frame size of 1084 bytes is larger than 800 bytes [-Wframe-larger-than=]
        net/netfilter/ipvs/ip_vs_ftp.c:298:1: warning: the frame size of 928 bytes is larger than 800 bytes [-Wframe-larger-than=]
        net/netfilter/ipvs/ip_vs_ftp.c:418:1: warning: the frame size of 908 bytes is larger than 800 bytes [-Wframe-larger-than=]
        net/netfilter/ipvs/ip_vs_lblcr.c:718:1: warning: the frame size of 960 bytes is larger than 800 bytes [-Wframe-larger-than=]
        drivers/net/xen-netback/netback.c:1500:1: warning: the frame size of 1088 bytes is larger than 800 bytes [-Wframe-larger-than=]
      
      In case of ARC and CRIS, it turns out that the BUG() implementation
      actually does return (or at least the compiler thinks it does),
      resulting in lots of warnings about uninitialized variable use and
      leaving noreturn functions, such as:
      
        block/cfq-iosched.c: In function 'cfq_async_queue_prio':
        block/cfq-iosched.c:3804:1: error: control reaches end of non-void function [-Werror=return-type]
        include/linux/dmaengine.h: In function 'dma_maxpq':
        include/linux/dmaengine.h:1123:1: error: control reaches end of non-void function [-Werror=return-type]
      
      This makes them call __builtin_trap() instead, which should normally
      dump the stack and kill the current process, like some of the other
      architectures already do.
      
      I tried adding barrier_before_unreachable() to panic() and
      fortify_panic() as well, but that had very little effect, so I'm not
      submitting that patch.
      
      Vineet said:
      
      : For ARC, it is double win.
      :
      : 1. Fixes 3 -Wreturn-type warnings
      :
      : | ../net/core/ethtool.c:311:1: warning: control reaches end of non-void function
      : [-Wreturn-type]
      : | ../kernel/sched/core.c:3246:1: warning: control reaches end of non-void function
      : [-Wreturn-type]
      : | ../include/linux/sunrpc/svc_xprt.h:180:1: warning: control reaches end of
      : non-void function [-Wreturn-type]
      :
      : 2.  bloat-o-meter reports code size improvements as gcc elides the
      :    generated code for stack return.
      
      Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
      Link: http://lkml.kernel.org/r/20171219114112.939391-1-arnd@arndb.de
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: Vineet Gupta <vgupta@synopsys.com>	[arch/arc]
      Tested-by: Vineet Gupta <vgupta@synopsys.com>	[arch/arc]
      Cc: Mikael Starvik <starvik@axis.com>
      Cc: Jesper Nilsson <jesper.nilsson@axis.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Christopher Li <sparse@chrisli.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      173a3efd
  16. 18 Nov, 2017 3 commits
  17. 02 Nov, 2017 1 commit
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard...
      b2441318
  18. 10 Jul, 2017 1 commit
    • Ian Abbott's avatar
      asm-generic/bug.h: declare struct pt_regs; before function prototype · 0b396923
      Ian Abbott authored
      This series of patches splits BUILD_BUG related macros out of
      "include/linux/bug.h" into new file "include/linux/build_bug.h" (patch
      5), and changes the pointer type checking in the `container_of()` macro
      to deal with pointers of array type better (patch 6).  Patches 1 to 4
      are prerequisites.
      
      Patches 2, 3, 4, and 5 have been inserted since the previous version of
      this patch series.  Patch 6 here corresponds to v3 and v4's patch 2.
      
      Patch 1 was a prerequisite in v3 of this series to avoid a lot of
      warnings when <linux/bug.h> was included by <linux/kernel.h>.  That is
      no longer relevant for v5 of the series, but I left it in because it was
      acked by a Arnd Bergmann and Michal Nazarewicz.
      
      Patches 2, 3, and 4 are some checkpatch clean-ups on
      "include/linux/bug.h" before splitting out the BUILD_BUG stuff in patch
      5.
      
      Patch 5 splits the BUILD_BUG related macros out of "include/linux/bug.h"
      into new file "include/linux/build_bug.h" because including
      <linux/bug.h> in "include/linux/kernel.h" would result in build failures
      due to circular dependencies.
      
      Patch 6 changes the pointer type checking by `container_of()` to avoid
      some incompatible pointer warnings when the dereferenced pointer has
      array type.
      
      1) asm-generic/bug.h: declare struct pt_regs; before function prototype
      2) linux/bug.h: correct formatting of block comment
      3) linux/bug.h: correct "(foo*)" should be "(foo *)"
      4) linux/bug.h: correct "space required before that '-'"
      5) bug: split BUILD_BUG stuff out into <linux/build_bug.h>
      6) kernel.h: handle pointers to arrays better in container_of()
      
      This patch (of 6):
      
      The declaration of `__warn()` has `struct pt_regs *regs` as one of its
      parameters.  This can result in compiler warnings if `struct regs` is not
      already declared.  Add an empty declaration of `struct pt_regs` to avoid
      the warnings.
      
      Link: http://lkml.kernel.org/r/20170525120316.24473-2-abbotti@mev.co.uk
      
      Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
      Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: default avatarMichal Nazarewicz <mina86@mina86.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Kees Cook <keescook@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      0b396923
  19. 14 Apr, 2017 1 commit
  20. 30 Mar, 2017 1 commit
    • Peter Zijlstra's avatar
      debug: Add _ONCE() logic to report_bug() · 19d43626
      Peter Zijlstra authored
      
      Josh suggested moving the _ONCE logic inside the trap handler, using a
      bit in the bug_entry::flags field, avoiding the need for the extra
      variable.
      
      Sadly this only works for WARN_ON_ONCE(), since the others have
      printk() statements prior to triggering the trap.
      
      Still, this saves a fair amount of text and some data:
      
        text         data       filename
        10682460     4530992    defconfig-build/vmlinux.orig
        10665111     4530096    defconfig-build/vmlinux.patched
      Suggested-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      19d43626
  21. 17 Mar, 2016 2 commits
    • Josh Poimboeuf's avatar
      lib/bug.c: use common WARN helper · 2553b67a
      Josh Poimboeuf authored
      
      The traceoff_on_warning option doesn't have any effect on s390, powerpc,
      arm64, parisc, and sh because there are two different types of WARN
      implementations:
      
      1) The above mentioned architectures treat WARN() as a special case of a
         BUG() exception.  They handle warnings in report_bug() in lib/bug.c.
      
      2) All other architectures just call warn_slowpath_*() directly.  Their
         warnings are handled in warn_slowpath_common() in kernel/panic.c.
      
      Support traceoff_on_warning on all architectures and prevent any future
      divergence by using a single common function to emit the warning.
      
      Also remove the '()' from '%pS()', because the parentheses look funky:
      
        [   45.607629] WARNING: at /root/warn_mod/warn_mod.c:17 .init_dummy+0x20/0x40 [warn_mod]()
      Reported-by: default avatarChunyu Hu <chuhu@redhat.com>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Acked-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
      Tested-by: default avatarPrarit Bhargava <prarit@redhat.com>
      Acked-by: Prarit Bhargava <prarit@redhat...
      2553b67a
    • Steven Rostedt's avatar
      bug: set warn variable before calling WARN() · dfbf2897
      Steven Rostedt authored
      
      This has hit me a couple of times already.  I would be debugging code
      and the system would simply hang and then reboot.  Finally, I found that
      the problem was caused by WARN_ON_ONCE() and friends.
      
      The macro WARN_ON_ONCE(condition) is defined as:
      
      	static bool __section(.data.unlikely) __warned;
      	int __ret_warn_once = !!(condition);
      
      	if (unlikely(__ret_warn_once))
      		if (WARN_ON(!__warned))
      			__warned = true;
      
      	unlikely(__ret_warn_once);
      
      Which looks great and all.  But what I have hit, is an issue when
      WARN_ON() itself hits the same WARN_ON_ONCE() code.  Because, the
      variable __warned is not yet set.  Then it too calls WARN_ON() and that
      triggers the warning again.  It keeps doing this until the stack is
      overflowed and the system crashes.
      
      By setting __warned first before calling WARN_ON() makes the original
      WARN_ON_ONCE() really only warn once, and not an infinite amount of
      times if the WARN_ON() also triggers the warning.
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      dfbf2897
  22. 01 Mar, 2016 1 commit
    • Arnd Bergmann's avatar
      asm-generic: default BUG_ON(x) to if(x)BUG() · 3c047057
      Arnd Bergmann authored
      When CONFIG_BUG is disabled, BUG_ON() will only evaluate the condition,
      but will not actually stop the current thread. GCC warns about a couple
      of BUG_ON() users where this actually leads to further undefined
      behavior:
      
      include/linux/ceph/osdmap.h: In function 'ceph_can_shift_osds':
      include/linux/ceph/osdmap.h:54:1: warning: control reaches end of non-void function
      fs/ext4/inode.c: In function 'ext4_map_blocks':
      fs/ext4/inode.c:548:5: warning: 'retval' may be used uninitialized in this function
      drivers/mfd/db8500-prcmu.c: In function 'prcmu_config_clkout':
      drivers/mfd/db8500-prcmu.c:762:10: warning: 'div_mask' may be used uninitialized in this function
      drivers/mfd/db8500-prcmu.c:769:13: warning: 'mask' may be used uninitialized in this function
      drivers/mfd/db8500-prcmu.c:757:7: warning: 'bits' may be used uninitialized in this function
      drivers/tty/serial/8250/8250_core.c: In function 'univ8250_release_irq':
      drivers/tty/serial/8250/8250_core.c:252:18: warning: 'i' may be used uninitialized in this function
      drivers/tty/serial/8250/8250_core.c:235:19: note: 'i' was declared here
      
      There is an obvious conflict of interest here: on the one hand, someone
      who disables CONFIG_BUG() will want the kernel to be as small as possible
      and doesn't care about printing error messages to a console that nobody
      looks at. On the other hand, running into a BUG_ON() condition means that
      something has gone wrong, and we probably want to also stop doing things
      that might cause data corruption.
      
      This patch picks the second choice, and changes the NOP to BUG(), which
      normally stops the execution of the current thread in some form (endless
      loop or a trap). This follows the logic we applied in a4b5d580
      
       ("bug:
      Make BUG() always stop the machine").
      
      For ARM multi_v7_defconfig, the size slightly increases:
      
      section		CONFIG_BUG=y	CONFIG_BUG=n	CONFIG_BUG=n+patch
      
        .text            8320248   |     8180944   |     8207688
        .rodata          3633720   |     3567144   |     3570648
        __bug_table        32508   |         ---   |         ---
        __modver             692   |        1584   |        2176
        .init.text        558132   |      548300   |      550088
        .exit.text         12380   |       12256   |       12380
        .data            1016672   |     1016064   |     1016128
        Total           14622556   |    14374510   |    14407326
      
      So instead of saving 1.70% of the total image size, we only save 1.48%
      by turning off CONFIG_BUG, but in return we can ensure that we don't run
      into cases of uninitialized variable or return code uses when something
      bad happens. Aside from that, we significantly reduce the number of
      warnings in randconfig builds, which makes it easier to fix the warnings
      about other problems.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      3c047057
  23. 07 Apr, 2014 4 commits
  24. 25 Jun, 2012 1 commit
    • Paul Mundt's avatar
      bug.h: Fix up CONFIG_BUG=n implicit function declarations. · 09682c1d
      Paul Mundt authored
      Commit 2603efa3
      
       ("bug.h: Fix up powerpc build regression") corrected
      the powerpc build case and extended the __ASSEMBLY__ guards, but it also
      got caught in pre-processor hell accidentally matching the else case of
      CONFIG_BUG resulting in the BUG disabled case tripping up on
      -Werror=implicit-function-declaration.
      
      It's not possible to __ASSEMBLY__ guard the entire file as architecture
      code needs to get at the BUGFLAG_WARNING definition in the GENERIC_BUG
      case, but the rest of the CONFIG_BUG=y/n case needs to be guarded.
      
      Rather than littering endless __ASSEMBLY__ checks in each of the if/else
      cases we just move the BUGFLAG definitions up under their own
      GENERIC_BUG test and then shove everything else under one big
      __ASSEMBLY__ guard.
      
      Build tested on all of x86 CONFIG_BUG=y, CONFIG_BUG=n, powerpc (due to
      it's dependence on BUGFLAG definitions in assembly code), and sh (due to
      not bringing in linux/kernel.h to satisfy the taint flag definitions used
      by the generic bug code).
      
      Hopefully that's the end of the corner cases and I can abstain from ever
      having to touch this infernal header ever again.
      Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
      Tested-by: default avatarFengguang Wu <wfg@linux.intel.com>
      Acked-by: default avatarRandy Dunlap <rdunlap@xenotime.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      09682c1d
  25. 18 Jun, 2012 1 commit
    • Paul Mundt's avatar
      bug.h: Fix up powerpc build regression. · 2603efa3
      Paul Mundt authored
      
      The asm-generic/bug.h __ASSEMBLY__ guarding is completely bogus, which
      tripped up the powerpc build when the kernel.h include was added:
      
      	In file included from include/asm-generic/bug.h:5:0,
      			 from arch/powerpc/include/asm/bug.h:127,
      			 from arch/powerpc/kernel/head_64.S:31:
      	include/linux/kernel.h:44:0: warning: "ALIGN" redefined [enabled by default]
      	include/linux/linkage.h:57:0: note: this is the location of the previous definition
      	include/linux/sysinfo.h: Assembler messages:
      	include/linux/sysinfo.h:7: Error: Unrecognized opcode: `struct'
      	include/linux/sysinfo.h:8: Error: Unrecognized opcode: `__kernel_long_t'
      
      Moving the __ASSEMBLY__ guard up and stashing the kernel.h include under
      it fixes this up, as well as covering the case the original fix was
      attempting to handle.
      Tested-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2603efa3
  26. 11 Jun, 2012 1 commit
  27. 23 Mar, 2012 1 commit
  28. 01 Nov, 2011 1 commit
  29. 26 May, 2011 1 commit