1. 03 6月, 2021 1 次提交
    • N
      vmlinux.lds.h: Avoid orphan section with !SMP · d4c63999
      Nathan Chancellor 提交于
      With x86_64_defconfig and the following configs, there is an orphan
      section warning:
      
      CONFIG_SMP=n
      CONFIG_AMD_MEM_ENCRYPT=y
      CONFIG_HYPERVISOR_GUEST=y
      CONFIG_KVM=y
      CONFIG_PARAVIRT=y
      
      ld: warning: orphan section `.data..decrypted' from `arch/x86/kernel/cpu/vmware.o' being placed in section `.data..decrypted'
      ld: warning: orphan section `.data..decrypted' from `arch/x86/kernel/kvm.o' being placed in section `.data..decrypted'
      
      These sections are created with DEFINE_PER_CPU_DECRYPTED, which
      ultimately turns into __PCPU_ATTRS, which in turn has a section
      attribute with a value of PER_CPU_BASE_SECTION + the section name. When
      CONFIG_SMP is not set, the base section is .data and that is not
      currently handled in any linker script.
      
      Add .data..decrypted to PERCPU_DECRYPTED_SECTION, which is included in
      PERCPU_INPUT -> PERCPU_SECTION, which is include in the x86 linker
      script when either CONFIG_X86_64 or CONFIG_SMP is unset, taking care of
      the warning.
      
      Fixes: ac26963a ("percpu: Introduce DEFINE_PER_CPU_DECRYPTED")
      Link: https://github.com/ClangBuiltLinux/linux/issues/1360Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: Nick Desaulniers <ndesaulniers@google.com> # build
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20210506001410.1026691-1-nathan@kernel.org
      d4c63999
  2. 07 5月, 2021 5 次提交
    • D
      mm: remove xlate_dev_kmem_ptr() · f2e762ba
      David Hildenbrand 提交于
      Since /dev/kmem has been removed, let's remove the xlate_dev_kmem_ptr()
      leftovers.
      
      Link: https://lkml.kernel.org/r/20210324102351.6932-3-david@redhat.comSigned-off-by: NDavid Hildenbrand <david@redhat.com>
      Acked-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
      Cc: Matt Turner <mattst88@gmail.com>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Brian Cain <bcain@codeaurora.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Heiko Carstens <hca@linux.ibm.com>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
      Cc: Rich Felker <dalias@libc.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Hildenbrand <david@redhat.com>
      Cc: Krzysztof Kozlowski <krzk@kernel.org>
      Cc: Mikulas Patocka <mpatocka@redhat.com>
      Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Palmer Dabbelt <palmerdabbelt@google.com>
      Cc: Luis Chamberlain <mcgrof@kernel.org>
      Cc: Greentime Hu <green.hu@gmail.com>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
      Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
      Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
      Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
      Cc: Niklas Schnelle <schnelle@linux.ibm.com>
      Cc: Pierre Morel <pmorel@linux.ibm.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      f2e762ba
    • Y
      lib: add fast path for find_first_*_bit() and find_last_bit() · 2cc7b6a4
      Yury Norov 提交于
      Similarly to bitmap functions, users would benefit if we'll handle a case
      of small-size bitmaps that fit into a single word.
      
      While here, move the find_last_bit() declaration to bitops/find.h where
      other find_*_bit() functions sit.
      
      Link: https://lkml.kernel.org/r/20210401003153.97325-11-yury.norov@gmail.comSigned-off-by: NYury Norov <yury.norov@gmail.com>
      Acked-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Alexey Klimov <aklimov@redhat.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jianpeng Ma <jianpeng.ma@intel.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
      Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: Yoshinori Sato <ysato@users.osdn.me>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      2cc7b6a4
    • Y
      lib: add fast path for find_next_*_bit() · 277a20a4
      Yury Norov 提交于
      Similarly to bitmap functions, find_next_*_bit() users will benefit if
      we'll handle a case of bitmaps that fit into a single word inline.  In the
      very best case, the compiler may replace a function call with a few
      instructions.
      
      This is the quite typical find_next_bit() user:
      
      	unsigned int cpumask_next(int n, const struct cpumask *srcp)
      	{
      		/* -1 is a legal arg here. */
      		if (n != -1)
      			cpumask_check(n);
      		return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1);
      	}
      	EXPORT_SYMBOL(cpumask_next);
      
      Currently, on ARM64 the generated code looks like this:
      	0000000000000000 <cpumask_next>:
      	   0:   a9bf7bfd        stp     x29, x30, [sp, #-16]!
      	   4:   11000402        add     w2, w0, #0x1
      	   8:   aa0103e0        mov     x0, x1
      	   c:   d2800401        mov     x1, #0x40                       // #64
      	  10:   910003fd        mov     x29, sp
      	  14:   93407c42        sxtw    x2, w2
      	  18:   94000000        bl      0 <find_next_bit>
      	  1c:   a8c17bfd        ldp     x29, x30, [sp], #16
      	  20:   d65f03c0        ret
      	  24:   d503201f        nop
      
      After applying this patch:
      	0000000000000140 <cpumask_next>:
      	 140:   11000400        add     w0, w0, #0x1
      	 144:   93407c00        sxtw    x0, w0
      	 148:   f100fc1f        cmp     x0, #0x3f
      	 14c:   54000168        b.hi    178 <cpumask_next+0x38>  // b.pmore
      	 150:   f9400023        ldr     x3, [x1]
      	 154:   92800001        mov     x1, #0xffffffffffffffff         // #-1
      	 158:   9ac02020        lsl     x0, x1, x0
      	 15c:   52800802        mov     w2, #0x40                       // #64
      	 160:   8a030001        and     x1, x0, x3
      	 164:   dac00020        rbit    x0, x1
      	 168:   f100003f        cmp     x1, #0x0
      	 16c:   dac01000        clz     x0, x0
      	 170:   1a800040        csel    w0, w2, w0, eq  // eq = none
      	 174:   d65f03c0        ret
      	 178:   52800800        mov     w0, #0x40                       // #64
      	 17c:   d65f03c0        ret
      
      find_next_bit() call is replaced with 6 instructions.  find_next_bit()
      itself is 41 instructions plus function call overhead.
      
      Despite inlining, the scripts/bloat-o-meter report smaller .text size
      after applying the series:
      	add/remove: 11/9 grow/shrink: 233/176 up/down: 5780/-6768 (-988)
      
      Link: https://lkml.kernel.org/r/20210401003153.97325-10-yury.norov@gmail.comSigned-off-by: NYury Norov <yury.norov@gmail.com>
      Acked-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Alexey Klimov <aklimov@redhat.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jianpeng Ma <jianpeng.ma@intel.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
      Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: Yoshinori Sato <ysato@users.osdn.me>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      277a20a4
    • Y
      lib: inline _find_next_bit() wrappers · 5c88af59
      Yury Norov 提交于
      lib/find_bit.c declares five single-line wrappers for _find_next_bit().
      We may turn those wrappers to inline functions.  It eliminates unneeded
      function calls and opens room for compile-time optimizations.
      
      Link: https://lkml.kernel.org/r/20210401003153.97325-8-yury.norov@gmail.comSigned-off-by: NYury Norov <yury.norov@gmail.com>
      Acked-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Alexey Klimov <aklimov@redhat.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jianpeng Ma <jianpeng.ma@intel.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
      Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: Yoshinori Sato <ysato@users.osdn.me>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5c88af59
    • Y
      lib: extend the scope of small_const_nbits() macro · 586eaebe
      Yury Norov 提交于
      find_bit would also benefit from small_const_nbits() optimizations.  The
      detailed comment is provided by Rasmus Villemoes.
      
      Link: https://lkml.kernel.org/r/20210401003153.97325-6-yury.norov@gmail.comSuggested-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: NYury Norov <yury.norov@gmail.com>
      Acked-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
      Cc: Alexey Klimov <aklimov@redhat.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: David Sterba <dsterba@suse.com>
      Cc: Dennis Zhou <dennis@kernel.org>
      Cc: Geert Uytterhoeven <geert@linux-m68k.org>
      Cc: Jianpeng Ma <jianpeng.ma@intel.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Rich Felker <dalias@libc.org>
      Cc: Stefano Brivio <sbrivio@redhat.com>
      Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
      Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
      Cc: Yoshinori Sato <ysato@users.osdn.me>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      586eaebe
  3. 21 4月, 2021 3 次提交
  4. 09 4月, 2021 2 次提交
    • H
      asm-generic/io.h: Unbork ioremap_np() declaration · ea962928
      Hector Martin 提交于
      It accidentally slipped into the #ifdef for ioremap_uc().
      Signed-off-by: NHector Martin <marcan@marcan.st>
      Link: https://lore.kernel.org/r/20210409052038.58925-1-marcan@marcan.st'
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      ea962928
    • S
      add support for Clang CFI · cf68fffb
      Sami Tolvanen 提交于
      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: NSami Tolvanen <samitolvanen@google.com>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20210408182843.1754385-2-samitolvanen@google.com
      cf68fffb
  5. 08 4月, 2021 1 次提交
    • H
      asm-generic/io.h: Add a non-posted variant of ioremap() · 7c566bb5
      Hector Martin 提交于
      ARM64 currently defaults to posted MMIO (nGnRE), but some devices
      require the use of non-posted MMIO (nGnRnE). Introduce a new ioremap()
      variant to handle this case. ioremap_np() returns NULL on arches that
      do not implement this variant.
      
      sparc64 is the only architecture that needs to be touched directly,
      because it includes neither of the generic io.h or iomap.h headers.
      
      This adds the IORESOURCE_MEM_NONPOSTED flag, which maps to this
      variant and marks a given resource as requiring non-posted mappings.
      This is implemented in the resource system because it is a SoC-level
      requirement, so existing drivers do not need special-case code to pick
      this ioremap variant.
      
      Then this is implemented in devres by introducing devm_ioremap_np(),
      and making devm_ioremap_resource() automatically select this variant
      when the resource has the IORESOURCE_MEM_NONPOSTED flag set.
      Acked-by: NMarc Zyngier <maz@kernel.org>
      Signed-off-by: NHector Martin <marcan@marcan.st>
      7c566bb5
  6. 24 3月, 2021 1 次提交
  7. 11 3月, 2021 1 次提交
  8. 09 3月, 2021 6 次提交
  9. 26 2月, 2021 1 次提交
  10. 23 2月, 2021 1 次提交
    • A
      vmlinux.lds.h: catch even more instrumentation symbols into .data · 49387f62
      Alexander Lobakin 提交于
      LKP caught another bunch of orphaned instrumentation symbols [0]:
      
      mipsel-linux-ld: warning: orphan section `.data.$LPBX1' from
      `init/main.o' being placed in section `.data.$LPBX1'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX0' from
      `init/main.o' being placed in section `.data.$LPBX0'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX1' from
      `init/do_mounts.o' being placed in section `.data.$LPBX1'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX0' from
      `init/do_mounts.o' being placed in section `.data.$LPBX0'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX1' from
      `init/do_mounts_initrd.o' being placed in section `.data.$LPBX1'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX0' from
      `init/do_mounts_initrd.o' being placed in section `.data.$LPBX0'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX1' from
      `init/initramfs.o' being placed in section `.data.$LPBX1'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX0' from
      `init/initramfs.o' being placed in section `.data.$LPBX0'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX1' from
      `init/calibrate.o' being placed in section `.data.$LPBX1'
      mipsel-linux-ld: warning: orphan section `.data.$LPBX0' from
      `init/calibrate.o' being placed in section `.data.$LPBX0'
      
      [...]
      
      Soften the wildcard to .data.$L* to grab these ones into .data too.
      
      [0] https://lore.kernel.org/lkml/202102231519.lWPLPveV-lkp@intel.comReported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NAlexander Lobakin <alobakin@pm.me>
      Signed-off-by: NThomas Bogendoerfer <tsbogend@alpha.franken.de>
      49387f62
  11. 17 2月, 2021 2 次提交
  12. 16 2月, 2021 1 次提交
  13. 13 2月, 2021 1 次提交
  14. 11 2月, 2021 10 次提交
  15. 10 2月, 2021 1 次提交
  16. 08 2月, 2021 2 次提交
  17. 04 2月, 2021 1 次提交