1. 27 2月, 2021 1 次提交
    • A
      mm: add Kernel Electric-Fence infrastructure · 0ce20dd8
      Alexander Potapenko 提交于
      Patch series "KFENCE: A low-overhead sampling-based memory safety error detector", v7.
      
      This adds the Kernel Electric-Fence (KFENCE) infrastructure. KFENCE is a
      low-overhead sampling-based memory safety error detector of heap
      use-after-free, invalid-free, and out-of-bounds access errors.  This
      series enables KFENCE for the x86 and arm64 architectures, and adds
      KFENCE hooks to the SLAB and SLUB allocators.
      
      KFENCE is designed to be enabled in production kernels, and has near
      zero performance overhead. Compared to KASAN, KFENCE trades performance
      for precision. The main motivation behind KFENCE's design, is that with
      enough total uptime KFENCE will detect bugs in code paths not typically
      exercised by non-production test workloads. One way to quickly achieve a
      large enough total uptime is when the tool is deployed across a large
      fleet of machines.
      
      KFENCE objects each reside on a dedicated page, at either the left or
      right page boundaries. The pages to the left and right of the object
      page are "guard pages", whose attributes are changed to a protected
      state, and cause page faults on any attempted access to them. Such page
      faults are then intercepted by KFENCE, which handles the fault
      gracefully by reporting a memory access error.
      
      Guarded allocations are set up based on a sample interval (can be set
      via kfence.sample_interval). After expiration of the sample interval,
      the next allocation through the main allocator (SLAB or SLUB) returns a
      guarded allocation from the KFENCE object pool. At this point, the timer
      is reset, and the next allocation is set up after the expiration of the
      interval.
      
      To enable/disable a KFENCE allocation through the main allocator's
      fast-path without overhead, KFENCE relies on static branches via the
      static keys infrastructure. The static branch is toggled to redirect the
      allocation to KFENCE.
      
      The KFENCE memory pool is of fixed size, and if the pool is exhausted no
      further KFENCE allocations occur. The default config is conservative
      with only 255 objects, resulting in a pool size of 2 MiB (with 4 KiB
      pages).
      
      We have verified by running synthetic benchmarks (sysbench I/O,
      hackbench) and production server-workload benchmarks that a kernel with
      KFENCE (using sample intervals 100-500ms) is performance-neutral
      compared to a non-KFENCE baseline kernel.
      
      KFENCE is inspired by GWP-ASan [1], a userspace tool with similar
      properties. The name "KFENCE" is a homage to the Electric Fence Malloc
      Debugger [2].
      
      For more details, see Documentation/dev-tools/kfence.rst added in the
      series -- also viewable here:
      
      	https://raw.githubusercontent.com/google/kasan/kfence/Documentation/dev-tools/kfence.rst
      
      [1] http://llvm.org/docs/GwpAsan.html
      [2] https://linux.die.net/man/3/efence
      
      This patch (of 9):
      
      This adds the Kernel Electric-Fence (KFENCE) infrastructure. KFENCE is a
      low-overhead sampling-based memory safety error detector of heap
      use-after-free, invalid-free, and out-of-bounds access errors.
      
      KFENCE is designed to be enabled in production kernels, and has near
      zero performance overhead. Compared to KASAN, KFENCE trades performance
      for precision. The main motivation behind KFENCE's design, is that with
      enough total uptime KFENCE will detect bugs in code paths not typically
      exercised by non-production test workloads. One way to quickly achieve a
      large enough total uptime is when the tool is deployed across a large
      fleet of machines.
      
      KFENCE objects each reside on a dedicated page, at either the left or
      right page boundaries. The pages to the left and right of the object
      page are "guard pages", whose attributes are changed to a protected
      state, and cause page faults on any attempted access to them. Such page
      faults are then intercepted by KFENCE, which handles the fault
      gracefully by reporting a memory access error. To detect out-of-bounds
      writes to memory within the object's page itself, KFENCE also uses
      pattern-based redzones. The following figure illustrates the page
      layout:
      
        ---+-----------+-----------+-----------+-----------+-----------+---
           | xxxxxxxxx | O :       | xxxxxxxxx |       : O | xxxxxxxxx |
           | xxxxxxxxx | B :       | xxxxxxxxx |       : B | xxxxxxxxx |
           | x GUARD x | J : RED-  | x GUARD x | RED-  : J | x GUARD x |
           | xxxxxxxxx | E :  ZONE | xxxxxxxxx |  ZONE : E | xxxxxxxxx |
           | xxxxxxxxx | C :       | xxxxxxxxx |       : C | xxxxxxxxx |
           | xxxxxxxxx | T :       | xxxxxxxxx |       : T | xxxxxxxxx |
        ---+-----------+-----------+-----------+-----------+-----------+---
      
      Guarded allocations are set up based on a sample interval (can be set
      via kfence.sample_interval). After expiration of the sample interval, a
      guarded allocation from the KFENCE object pool is returned to the main
      allocator (SLAB or SLUB). At this point, the timer is reset, and the
      next allocation is set up after the expiration of the interval.
      
      To enable/disable a KFENCE allocation through the main allocator's
      fast-path without overhead, KFENCE relies on static branches via the
      static keys infrastructure. The static branch is toggled to redirect the
      allocation to KFENCE. To date, we have verified by running synthetic
      benchmarks (sysbench I/O, hackbench) that a kernel compiled with KFENCE
      is performance-neutral compared to the non-KFENCE baseline.
      
      For more details, see Documentation/dev-tools/kfence.rst (added later in
      the series).
      
      [elver@google.com: fix parameter description for kfence_object_start()]
        Link: https://lkml.kernel.org/r/20201106092149.GA2851373@elver.google.com
      [elver@google.com: avoid stalling work queue task without allocations]
        Link: https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com
        Link: https://lkml.kernel.org/r/20201110135320.3309507-1-elver@google.com
      [elver@google.com: fix potential deadlock due to wake_up()]
        Link: https://lkml.kernel.org/r/000000000000c0645805b7f982e4@google.com
        Link: https://lkml.kernel.org/r/20210104130749.1768991-1-elver@google.com
      [elver@google.com: add option to use KFENCE without static keys]
        Link: https://lkml.kernel.org/r/20210111091544.3287013-1-elver@google.com
      [elver@google.com: add missing copyright and description headers]
        Link: https://lkml.kernel.org/r/20210118092159.145934-1-elver@google.com
      
      Link: https://lkml.kernel.org/r/20201103175841.3495947-2-elver@google.comSigned-off-by: NMarco Elver <elver@google.com>
      Signed-off-by: NAlexander Potapenko <glider@google.com>
      Reviewed-by: NDmitry Vyukov <dvyukov@google.com>
      Reviewed-by: NSeongJae Park <sjpark@amazon.de>
      Co-developed-by: NMarco Elver <elver@google.com>
      Reviewed-by: NJann Horn <jannh@google.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Paul E. McKenney <paulmck@kernel.org>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christopher Lameter <cl@linux.com>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Joern Engel <joern@purestorage.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0ce20dd8
  2. 16 2月, 2021 2 次提交
    • N
      Kconfig: allow explicit opt in to DWARF v5 · 98cd6f52
      Nick Desaulniers 提交于
      DWARF v5 is the latest standard of the DWARF debug info format. GCC 11
      will change the implicit default DWARF version, if left unspecified, to
      DWARF v5.
      
      Allow users of Clang and older versions of GCC that have not changed the
      implicit default DWARF version to DWARF v5 to opt in. This can help
      testing consumers of DWARF debug info in preparation of v5 becoming more
      widespread, as well as result in significant binary size savings of the
      pre-stripped vmlinux image.
      
      DWARF5 wins significantly in terms of size when mixed with compression
      (CONFIG_DEBUG_INFO_COMPRESSED).
      
      363M    vmlinux.clang12.dwarf5.compressed
      434M    vmlinux.clang12.dwarf4.compressed
      439M    vmlinux.clang12.dwarf2.compressed
      457M    vmlinux.clang12.dwarf5
      536M    vmlinux.clang12.dwarf4
      548M    vmlinux.clang12.dwarf2
      
      515M    vmlinux.gcc10.2.dwarf5.compressed
      599M    vmlinux.gcc10.2.dwarf4.compressed
      624M    vmlinux.gcc10.2.dwarf2.compressed
      630M    vmlinux.gcc10.2.dwarf5
      765M    vmlinux.gcc10.2.dwarf4
      809M    vmlinux.gcc10.2.dwarf2
      
      Though the quality of debug info is harder to quantify; size is not a
      proxy for quality.
      
      Jakub notes:
        One thing is GCC DWARF-5 support, that is whether the compiler will
        support -gdwarf-5 flag, and that support should be there from GCC 7
        onwards.
      
        All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental
        option that enabled some small DWARF subset (initially only a few
        DW_LANG_* codes newly added to DWARF5 drafts).  Only GCC 7 (released
        after DWARF 5 has been finalized) started emitting DWARF5 section
        headers and got most of the DWARF5 changes in...
      
        Another separate thing is whether the assembler does support
        the -gdwarf-5 option (i.e. if you can compile assembler files
        with -Wa,-gdwarf-5) ... That option is about whether the assembler
        will emit DWARF5 or DWARF2 .debug_line.  It is fine to compile C sources
        with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as
        doesn't support it.
      
      Version check GCC so that we don't need to worry about the difference in
      command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to
      validate the DWARF Version in the assembler feature detection script.
      
      Most issues with clang produced assembler were fixed in binutils 2.35.1,
      but 2.35.2 fixed issues related to requiring the flag -Wa,-gdwarf-5
      explicitly. The added shell script test checks for the latter, and is
      only required when using clang without its integrated assembler, though
      we use for clang regardless as we do not yet have a way to query the
      assembler from Kconfig.
      
      Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet
      recognize the new additions to the DWARF debug info.
      
      This only modifies the DWARF version emitted by the compiler, not the
      assembler.
      
      The DWARF version of a binary can be validated with:
      $ llvm-dwarfdump <object file> | head -n 4 | grep version
      or
      $ readelf --debug-dump=info <object file> 2>/dev/null | grep Version
      
      Parts of the tree don't reuse DEBUG_CFLAGS as they should; such cleanup
      is left as a follow up.
      
      Link: http://www.dwarfstd.org/doc/DWARF5.pdf
      Link: https://bugzilla.redhat.com/show_bug.cgi?id=1922707Reported-by: NSedat Dilek <sedat.dilek@gmail.com>
      Suggested-by: NArvind Sankar <nivedita@alum.mit.edu>
      Suggested-by: NCaroline Tice <cmtice@google.com>
      Suggested-by: NFangrui Song <maskray@google.com>
      Suggested-by: NJakub Jelinek <jakub@redhat.com>
      Suggested-by: NMasahiro Yamada <masahiroy@kernel.org>
      Suggested-by: NNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v12.0.0-rc1 x86-64
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      98cd6f52
    • N
      Kbuild: make DWARF version a choice · a66049e2
      Nick Desaulniers 提交于
      Adds a default CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT which allows
      the implicit default version of DWARF emitted by the toolchain to
      progress over time.
      
      Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice, making it
      mutually exclusive with CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT. Users
      may want to select this if they are using a newer toolchain, but have
      consumers of the DWARF debug info that aren't yet ready for newer DWARF
      versions' debug info.
      
      Does so in a way that's forward compatible with existing
      configs, and makes adding future versions more straightforward. This
      patch does not change the current behavior or selection of DWARF
      version for users upgrading to kernels with this patch.
      
      GCC since ~4.8 has defaulted to DWARF v4 implicitly, and GCC 11 has
      bumped this to v5.
      
      Remove the Kconfig help text  about DWARF v4 being larger.  It's
      empirically false for the latest toolchains for x86_64 defconfig, has no
      point of reference (I suspect it was DWARF v2 but that's stil
      empirically false), and debug info size is not a qualatative measure.
      Suggested-by: NArvind Sankar <nivedita@alum.mit.edu>
      Suggested-by: NFangrui Song <maskray@google.com>
      Suggested-by: NJakub Jelinek <jakub@redhat.com>
      Suggested-by: NMark Wielaard <mark@klomp.org>
      Suggested-by: NMasahiro Yamada <masahiroy@kernel.org>
      Suggested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: NSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a66049e2
  3. 12 2月, 2021 1 次提交
  4. 22 1月, 2021 1 次提交
    • M
      lockdep: report broken irq restoration · 997acaf6
      Mark Rutland 提交于
      We generally expect local_irq_save() and local_irq_restore() to be
      paired and sanely nested, and so local_irq_restore() expects to be
      called with irqs disabled. Thus, within local_irq_restore() we only
      trace irq flag changes when unmasking irqs.
      
      This means that a sequence such as:
      
      | local_irq_disable();
      | local_irq_save(flags);
      | local_irq_enable();
      | local_irq_restore(flags);
      
      ... is liable to break things, as the local_irq_restore() would mask
      irqs without tracing this change. Similar problems may exist for
      architectures whose arch_irq_restore() function depends on being called
      with irqs disabled.
      
      We don't consider such sequences to be a good idea, so let's define
      those as forbidden, and add tooling to detect such broken cases.
      
      This patch adds debug code to WARN() when raw_local_irq_restore() is
      called with irqs enabled. As raw_local_irq_restore() is expected to pair
      with raw_local_irq_save(), it should never be called with irqs enabled.
      
      To avoid the possibility of circular header dependencies between
      irqflags.h and bug.h, the warning is handled in a separate C file.
      
      The new code is all conditional on a new CONFIG_DEBUG_IRQFLAGS symbol
      which is independent of CONFIG_TRACE_IRQFLAGS. As noted above such cases
      will confuse lockdep, so CONFIG_DEBUG_LOCKDEP now selects
      CONFIG_DEBUG_IRQFLAGS.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/20210111153707.10071-1-mark.rutland@arm.com
      997acaf6
  5. 16 12月, 2020 1 次提交
  6. 12 12月, 2020 1 次提交
  7. 02 12月, 2020 2 次提交
  8. 24 11月, 2020 2 次提交
  9. 18 11月, 2020 1 次提交
  10. 13 11月, 2020 1 次提交
  11. 11 11月, 2020 1 次提交
    • A
      kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it · 5f9ae91f
      Andrii Nakryiko 提交于
      Detect if pahole supports split BTF generation, and generate BTF for each
      selected kernel module, if it does. This is exposed to Makefiles and C code as
      CONFIG_DEBUG_INFO_BTF_MODULES flag.
      
      Kernel module BTF has to be re-generated if either vmlinux's BTF changes or
      module's .ko changes. To achieve that, I needed a helper similar to
      if_changed, but that would allow to filter out vmlinux from the list of
      updated dependencies for .ko building. I've put it next to the only place that
      uses and needs it, but it might be a better idea to just add it along the
      other if_changed variants into scripts/Kbuild.include.
      
      Each kernel module's BTF deduplication is pretty fast, as it does only
      incremental BTF deduplication on top of already deduplicated vmlinux BTF. To
      show the added build time, I've first ran make only just built kernel (to
      establish the baseline) and then forced only BTF re-generation, without
      regenerating .ko files. The build was performed with -j60 parallelization on
      56-core machine. The final time also includes bzImage building, so it's not
      a pure BTF overhead.
      
      $ time make -j60
      ...
      make -j60  27.65s user 10.96s system 782% cpu 4.933 total
      $ touch ~/linux-build/default/vmlinux && time make -j60
      ...
      make -j60  123.69s user 27.85s system 1566% cpu 9.675 total
      
      So 4.6 seconds real time, with noticeable part spent in compressed vmlinux and
      bzImage building.
      
      To show size savings, I've built my kernel configuration with about 700 kernel
      modules with full BTF per each kernel module (without deduplicating against
      vmlinux) and with split BTF against deduplicated vmlinux (approach in this
      patch). Below are top 10 modules with biggest BTF sizes. And total size of BTF
      data across all kernel modules.
      
      It shows that split BTF "compresses" 115MB down to 5MB total. And the biggest
      kernel modules get a downsize from 500-570KB down to 200-300KB.
      
      FULL BTF
      ========
      
      $ for f in $(find . -name '*.ko'); do size -A -d $f | grep BTF | awk '{print $2}'; done | awk '{ s += $1 } END { print s }'
      115710691
      
      $ for f in $(find . -name '*.ko'); do printf "%s %d\n" $f $(size -A -d $f | grep BTF | awk '{print $2}'); done | sort -nr -k2 | head -n10
      ./drivers/gpu/drm/i915/i915.ko 570570
      ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 520240
      ./drivers/gpu/drm/radeon/radeon.ko 503849
      ./drivers/infiniband/hw/mlx5/mlx5_ib.ko 491777
      ./fs/xfs/xfs.ko 411544
      ./drivers/net/ethernet/intel/i40e/i40e.ko 403904
      ./drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko 398754
      ./drivers/infiniband/core/ib_core.ko 397224
      ./fs/cifs/cifs.ko 386249
      ./fs/nfsd/nfsd.ko 379738
      
      SPLIT BTF
      =========
      
      $ for f in $(find . -name '*.ko'); do size -A -d $f | grep BTF | awk '{print $2}'; done | awk '{ s += $1 } END { print s }'
      5194047
      
      $ for f in $(find . -name '*.ko'); do printf "%s %d\n" $f $(size -A -d $f | grep BTF | awk '{print $2}'); done | sort -nr -k2 | head -n10
      ./drivers/gpu/drm/i915/i915.ko 293206
      ./drivers/gpu/drm/radeon/radeon.ko 282103
      ./fs/xfs/xfs.ko 222150
      ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 198503
      ./drivers/infiniband/hw/mlx5/mlx5_ib.ko 198356
      ./drivers/net/ethernet/broadcom/bnx2x/bnx2x.ko 113444
      ./fs/cifs/cifs.ko 109379
      ./arch/x86/kvm/kvm.ko 100225
      ./drivers/gpu/drm/drm.ko 94827
      ./drivers/infiniband/core/ib_core.ko 91188
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20201110011932.3201430-4-andrii@kernel.org
      5f9ae91f
  12. 03 11月, 2020 1 次提交
    • A
      net: add kcov handle to skb extensions · 6370cc3b
      Aleksandr Nogikh 提交于
      Remote KCOV coverage collection enables coverage-guided fuzzing of the
      code that is not reachable during normal system call execution. It is
      especially helpful for fuzzing networking subsystems, where it is
      common to perform packet handling in separate work queues even for the
      packets that originated directly from the user space.
      
      Enable coverage-guided frame injection by adding kcov remote handle to
      skb extensions. Default initialization in __alloc_skb and
      __build_skb_around ensures that no socket buffer that was generated
      during a system call will be missed.
      
      Code that is of interest and that performs packet processing should be
      annotated with kcov_remote_start()/kcov_remote_stop().
      
      An alternative approach is to determine kcov_handle solely on the
      basis of the device/interface that received the specific socket
      buffer. However, in this case it would be impossible to distinguish
      between packets that originated during normal background network
      processes or were intentionally injected from the user space.
      Signed-off-by: NAleksandr Nogikh <nogikh@google.com>
      Acked-by: NWillem de Bruijn <willemb@google.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      6370cc3b
  13. 30 10月, 2020 1 次提交
  14. 17 10月, 2020 1 次提交
  15. 14 10月, 2020 2 次提交
  16. 20 9月, 2020 1 次提交
  17. 05 9月, 2020 1 次提交
  18. 26 8月, 2020 1 次提交
  19. 25 8月, 2020 1 次提交
  20. 13 8月, 2020 5 次提交
  21. 29 7月, 2020 1 次提交
  22. 27 7月, 2020 1 次提交
    • P
      locking/lockdep: Fix TRACE_IRQFLAGS vs. NMIs · ed004953
      peterz@infradead.org 提交于
      Prior to commit:
      
        859d069e ("lockdep: Prepare for NMI IRQ state tracking")
      
      IRQ state tracking was disabled in NMIs due to nmi_enter()
      doing lockdep_off() -- with the obvious requirement that NMI entry
      call nmi_enter() before trace_hardirqs_off().
      
      [ AFAICT, PowerPC and SH violate this order on their NMI entry ]
      
      However, that commit explicitly changed lockdep_hardirqs_*() to ignore
      lockdep_off() and breaks every architecture that has irq-tracing in
      it's NMI entry that hasn't been fixed up (x86 being the only fixed one
      at this point).
      
      The reason for this change is that by ignoring lockdep_off() we can:
      
        - get rid of 'current->lockdep_recursion' in lockdep_assert_irqs*()
          which was going to to give header-recursion issues with the
          seqlock rework.
      
        - allow these lockdep_assert_*() macros to function in NMI context.
      
      Restore the previous state of things and allow an architecture to
      opt-in to the NMI IRQ tracking support, however instead of relying on
      lockdep_off(), rely on in_nmi(), both are part of nmi_enter() and so
      over-all entry ordering doesn't need to change.
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      Link: https://lore.kernel.org/r/20200727124852.GK119549@hirez.programming.kicks-ass.net
      ed004953
  23. 23 7月, 2020 1 次提交
    • P
      debugfs: Add access restriction option · a24c6f7b
      Peter Enderborg 提交于
      Since debugfs include sensitive information it need to be treated
      carefully. But it also has many very useful debug functions for userspace.
      With this option we can have same configuration for system with
      need of debugfs and a way to turn it off. This gives a extra protection
      for exposure on systems where user-space services with system
      access are attacked.
      
      It is controlled by a configurable default value that can be override
      with a kernel command line parameter. (debugfs=)
      
      It can be on or off, but also internally on but not seen from user-space.
      This no-mount mode do not register a debugfs as filesystem, but client can
      register their parts in the internal structures. This data can be readed
      with a debugger or saved with a crashkernel. When it is off clients
      get EPERM error when accessing the functions for registering their
      components.
      Signed-off-by: NPeter Enderborg <peter.enderborg@sony.com>
      Link: https://lore.kernel.org/r/20200716071511.26864-3-peter.enderborg@sony.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a24c6f7b
  24. 03 7月, 2020 1 次提交
  25. 29 6月, 2020 1 次提交
    • P
      selftests/fpu: Add an FPU selftest · 4185b3b9
      Petteri Aimonen 提交于
      Add a selftest for the usage of FPU code in kernel mode.
      
      Currently only implemented for x86. In the future, kernel FPU testing
      could be unified between the different architectures supporting it.
      
       [ bp:
      
        - Split out from a conglomerate patch, put comments over statements.
        - run the test only on debugfs write.
        - Add bare-minimum run_test_fpu.sh, run 1000 iterations on all CPUs
          by default.
        - Add conditionally -msse2 so that clang doesn't generate library
          calls.
        - Use cc-option to detect gcc 7.1 not supporting -mpreferred-stack-boundary=3 (amluto).
        - Document stuff so that we don't forget.
        - Fix:
           ld: lib/test_fpu.o: in function `test_fpu_get':
           >> test_fpu.c:(.text+0x16e): undefined reference to `__sanitizer_cov_trace_cmpd'
           >> ld: test_fpu.c:(.text+0x1a7): undefined reference to `__sanitizer_cov_trace_cmpd'
           ld: test_fpu.c:(.text+0x1e0): undefined reference to `__sanitizer_cov_trace_cmpd'
        ]
      Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NPetteri Aimonen <jpa@git.mail.kapsi.fi>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Link: https://lkml.kernel.org/r/20200624114646.28953-3-bp@alien8.de
      4185b3b9
  26. 17 6月, 2020 1 次提交
    • M
      kconfig: unify cc-option and as-option · 4d0831e8
      Masahiro Yamada 提交于
      cc-option and as-option are almost the same; both pass the flag to
      $(CC). The main difference is the cc-option stops before the assemble
      stage (-S option) whereas as-option stops after (-c option).
      
      I chose -S because it is slightly faster, but $(cc-option,-gz=zlib)
      returns a wrong result (https://lkml.org/lkml/2020/6/9/1529).
      It has been fixed by commit 7b169944 ("Makefile: Improve compressed
      debug info support detection"), but the assembler should always be
      invoked for more reliable compiler option tests.
      
      However, you cannot simply replace -S with -c because the following
      code in lib/Kconfig.debug would break:
      
          depends on $(cc-option,-gsplit-dwarf)
      
      The combination of -c and -gsplit-dwarf does not accept /dev/null as
      output.
      
        $ cat /dev/null | gcc -gsplit-dwarf -S -x c - -o /dev/null
        $ echo $?
        0
      
        $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o /dev/null
        objcopy: Warning: '/dev/null' is not an ordinary file
        $ echo $?
        1
      
        $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o tmp.o
        $ echo $?
        0
      
      There is another flag that creates an separate file based on the
      object file path:
      
        $ cat /dev/null | gcc -ftest-coverage -c -x c - -o /dev/null
        <stdin>:1: error: cannot open /dev/null.gcno
      
      So, we cannot use /dev/null to sink the output.
      
      Align the cc-option implementation with scripts/Kbuild.include.
      
      With -c option used in cc-option, as-option is unneeded.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: NWill Deacon <will@kernel.org>
      4d0831e8
  27. 15 6月, 2020 1 次提交
    • A
      Makefile: Improve compressed debug info support detection · 7b169944
      Arvind Sankar 提交于
      Commit
        10e68b02 ("Makefile: support compressed debug info")
      added support for compressed debug sections.
      
      Support is detected by checking
      - does the compiler support -gz=zlib
      - does the assembler support --compressed-debug-sections=zlib
      - does the linker support --compressed-debug-sections=zlib
      
      However, the gcc driver's support for this option is somewhat
      convoluted. The driver's builtin specs are set based on the version of
      binutils that it was configured with. It reports an error if the
      configure-time linker/assembler (i.e., not necessarily the actual
      assembler that will be run) do not support the option, but only if the
      assembler (or linker) is actually invoked when -gz=zlib is passed.
      
      The cc-option check in scripts/Kconfig.include does not invoke the
      assembler, so the gcc driver reports success even if it does not support
      the option being passed to the assembler.
      
      Because the as-option check passes the option directly to the assembler
      via -Wa,--compressed-debug-sections=zlib, the gcc driver does not see
      this option and will never report an error.
      
      Combined with an installed version of binutils that is more recent than
      the one the compiler was built with, it is possible for all three tests
      to succeed, yet an actual compilation with -gz=zlib to fail.
      
      Moreover, it is unnecessary to explicitly pass
      --compressed-debug-sections=zlib to the assembler via -Wa, since the
      driver will do that automatically when it supports -gz=zlib.
      
      Convert the as-option to just -gz=zlib, simplifying it as well as
      performing a better test of the gcc driver's capabilities.
      Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NArvind Sankar <nivedita@alum.mit.edu>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7b169944
  28. 14 6月, 2020 1 次提交
    • M
      treewide: replace '---help---' in Kconfig files with 'help' · a7f7f624
      Masahiro Yamada 提交于
      Since commit 84af7a61 ("checkpatch: kconfig: prefer 'help' over
      '---help---'"), the number of '---help---' has been gradually
      decreasing, but there are still more than 2400 instances.
      
      This commit finishes the conversion. While I touched the lines,
      I also fixed the indentation.
      
      There are a variety of indentation styles found.
      
        a) 4 spaces + '---help---'
        b) 7 spaces + '---help---'
        c) 8 spaces + '---help---'
        d) 1 space + 1 tab + '---help---'
        e) 1 tab + '---help---'    (correct indentation)
        f) 1 tab + 1 space + '---help---'
        g) 1 tab + 2 spaces + '---help---'
      
      In order to convert all of them to 1 tab + 'help', I ran the
      following commend:
      
        $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a7f7f624
  29. 11 6月, 2020 1 次提交
  30. 09 6月, 2020 1 次提交
  31. 05 6月, 2020 2 次提交
    • J
      lib: make a test module with set/clear bit · c348c163
      Jesse Brandeburg 提交于
      Test some bit clears/sets to make sure assembly doesn't change, and that
      the set_bit and clear_bit functions work and don't cause sparse warnings.
      
      Instruct Kbuild to build this file with extra warning level -Wextra, to
      catch new issues, and also doesn't hurt to build with C=1.
      
      This was used to test changes to arch/x86/include/asm/bitops.h.
      
      In particular, sparse (C=1) was very concerned when the last bit before a
      natural boundary, like 7, or 31, was being tested, as this causes sign
      extension (0xffffff7f) for instance when clearing bit 7.
      
      Recommended usage:
      
        make defconfig
        scripts/config -m CONFIG_TEST_BITOPS
        make modules_prepare
        make C=1 W=1 lib/test_bitops.ko
        objdump -S -d lib/test_bitops.ko
        insmod lib/test_bitops.ko
        rmmod lib/test_bitops.ko
      
      <check dmesg>, there should be no compiler/sparse warnings and no
      error messages in log.
      
      Link: http://lkml.kernel.org/r/20200310221747.2848474-2-jesse.brandeburg@intel.comSigned-off-by: NJesse Brandeburg <jesse.brandeburg@intel.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      CcL Ingo Molnar <mingo@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Dan Williams <dan.j.williams@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Wei Yang <richard.weiyang@gmail.com>
      Cc: Christian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c348c163
    • A
      mm/debug: add tests validating architecture page table helpers · 399145f9
      Anshuman Khandual 提交于
      This adds tests which will validate architecture page table helpers and
      other accessors in their compliance with expected generic MM semantics.
      This will help various architectures in validating changes to existing
      page table helpers or addition of new ones.
      
      This test covers basic page table entry transformations including but not
      limited to old, young, dirty, clean, write, write protect etc at various
      level along with populating intermediate entries with next page table page
      and validating them.
      
      Test page table pages are allocated from system memory with required size
      and alignments.  The mapped pfns at page table levels are derived from a
      real pfn representing a valid kernel text symbol.  This test gets called
      via late_initcall().
      
      This test gets built and run when CONFIG_DEBUG_VM_PGTABLE is selected.
      Any architecture, which is willing to subscribe this test will need to
      select ARCH_HAS_DEBUG_VM_PGTABLE.  For now this is limited to arc, arm64,
      x86, s390 and powerpc platforms where the test is known to build and run
      successfully Going forward, other architectures too can subscribe the test
      after fixing any build or runtime problems with their page table helpers.
      
      Folks interested in making sure that a given platform's page table helpers
      conform to expected generic MM semantics should enable the above config
      which will just trigger this test during boot.  Any non conformity here
      will be reported as an warning which would need to be fixed.  This test
      will help catch any changes to the agreed upon semantics expected from
      generic MM and enable platforms to accommodate it thereafter.
      
      [anshuman.khandual@arm.com: v17]
        Link: http://lkml.kernel.org/r/1587436495-22033-3-git-send-email-anshuman.khandual@arm.com
      [anshuman.khandual@arm.com: v18]
        Link: http://lkml.kernel.org/r/1588564865-31160-3-git-send-email-anshuman.khandual@arm.comSuggested-by: NCatalin Marinas <catalin.marinas@arm.com>
      Signed-off-by: NAnshuman Khandual <anshuman.khandual@arm.com>
      Signed-off-by: NChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: NQian Cai <cai@lca.pw>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Tested-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>	[s390]
      Tested-by: Christophe Leroy <christophe.leroy@c-s.fr>	[ppc32]
      Reviewed-by: NIngo Molnar <mingo@kernel.org>
      Cc: Mike Rapoport <rppt@linux.ibm.com>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Kirill A. Shutemov <kirill@shutemov.name>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Link: http://lkml.kernel.org/r/1583919272-24178-1-git-send-email-anshuman.khandual@arm.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      399145f9