Add and use a generic version of devmem_is_allowed()
authorPalmer Dabbelt <palmerdabbelt@google.com>
Fri, 11 Dec 2020 20:30:26 +0000 (12:30 -0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Fri, 11 Dec 2020 20:30:26 +0000 (12:30 -0800)
As part of adding STRICT_DEVMEM support to the RISC-V port, Zong provided an
implementation of devmem_is_allowed() that's exactly the same as the version in
a handful of other ports.  Rather than duplicate code, I've put a generic
version of this in lib/ and used it for the RISC-V port.

* palmer/generic-devmem:
  arm64: Use the generic devmem_is_allowed()
  arm: Use the generic devmem_is_allowed()
  RISC-V: Use the new generic devmem_is_allowed()
  lib: Add a generic version of devmem_is_allowed()

1  2 
arch/arm/Kconfig
arch/arm64/Kconfig
arch/arm64/include/asm/io.h
arch/riscv/Kconfig
include/asm-generic/io.h
lib/Kconfig
lib/Kconfig.debug
lib/Makefile

diff --combined arch/arm/Kconfig
index fe2f17eb2b505ace1720741f7cd550d6eeb6f356,16095d3ab453652eec415b2f0297ba39c78c3b66..ae7c7364871bb19ea31f2a0de202983b6a89c564
@@@ -5,7 -5,6 +5,6 @@@ config AR
        select ARCH_32BIT_OFF_T
        select ARCH_HAS_BINFMT_FLAT
        select ARCH_HAS_DEBUG_VIRTUAL if MMU
-       select ARCH_HAS_DEVMEM_IS_ALLOWED
        select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
        select ARCH_HAS_ELF_RANDOMIZE
        select ARCH_HAS_FORTIFY_SOURCE
        select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
        select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI
        select GENERIC_CLOCKEVENTS_BROADCAST if SMP
 +      select GENERIC_IRQ_IPI if SMP
        select GENERIC_CPU_AUTOPROBE
        select GENERIC_EARLY_IOREMAP
        select GENERIC_IDLE_POLL_SETUP
        select GENERIC_IRQ_PROBE
        select GENERIC_IRQ_SHOW
        select GENERIC_IRQ_SHOW_LEVEL
+       select GENERIC_LIB_DEVMEM_IS_ALLOWED
        select GENERIC_PCI_IOMAP
        select GENERIC_SCHED_CLOCK
        select GENERIC_SMP_IDLE_THREAD
@@@ -68,7 -67,6 +68,7 @@@
        select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU
        select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
        select HAVE_ARCH_MMAP_RND_BITS if MMU
 +      select HAVE_ARCH_SECCOMP
        select HAVE_ARCH_SECCOMP_FILTER if AEABI && !OABI_COMPAT
        select HAVE_ARCH_THREAD_STRUCT_WHITELIST
        select HAVE_ARCH_TRACEHOOK
@@@ -85,7 -83,7 +85,7 @@@
        select HAVE_FAST_GUP if ARM_LPAE
        select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
        select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG
 -      select HAVE_FUNCTION_TRACER if !XIP_KERNEL && (CC_IS_GCC || CLANG_VERSION >= 100000)
 +      select HAVE_FUNCTION_TRACER if !XIP_KERNEL
        select HAVE_GCC_PLUGINS
        select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)
        select HAVE_IDE if PCI || ISA || PCMCIA
        select PCI_SYSCALL if PCI
        select PERF_USE_VMALLOC
        select RTC_LIB
 +      select SET_FS
        select SYS_SUPPORTS_APM_EMULATION
        # Above selects are sorted alphabetically; please add new ones
        # according to that.  Thanks.
@@@ -268,7 -265,9 +268,7 @@@ config PHYS_OFFSE
        depends on !ARM_PATCH_PHYS_VIRT
        default DRAM_BASE if !MMU
        default 0x00000000 if ARCH_EBSA110 || \
 -                      ARCH_FOOTBRIDGE || \
 -                      ARCH_INTEGRATOR || \
 -                      ARCH_REALVIEW
 +                      ARCH_FOOTBRIDGE
        default 0x10000000 if ARCH_OMAP1 || ARCH_RPC
        default 0x20000000 if ARCH_S5PV210
        default 0xc0000000 if ARCH_SA1100
@@@ -504,12 -503,11 +504,12 @@@ config ARCH_S3C24X
        select GPIOLIB
        select GENERIC_IRQ_MULTI_HANDLER
        select HAVE_S3C2410_I2C if I2C
 -      select HAVE_S3C2410_WATCHDOG if WATCHDOG
        select HAVE_S3C_RTC if RTC_CLASS
        select NEED_MACH_IO_H
 +      select S3C2410_WATCHDOG
        select SAMSUNG_ATAGS
        select USE_OF
 +      select WATCHDOG
        help
          Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443
          and S3C2450 SoCs based systems, such as the Simtec Electronics BAST
@@@ -638,6 -636,7 +638,6 @@@ source "arch/arm/mach-dove/Kconfig
  source "arch/arm/mach-ep93xx/Kconfig"
  
  source "arch/arm/mach-exynos/Kconfig"
 -source "arch/arm/plat-samsung/Kconfig"
  
  source "arch/arm/mach-footbridge/Kconfig"
  
@@@ -710,7 -709,9 +710,7 @@@ source "arch/arm/mach-realview/Kconfig
  
  source "arch/arm/mach-rockchip/Kconfig"
  
 -source "arch/arm/mach-s3c24xx/Kconfig"
 -
 -source "arch/arm/mach-s3c64xx/Kconfig"
 +source "arch/arm/mach-s3c/Kconfig"
  
  source "arch/arm/mach-s5pv210/Kconfig"
  
@@@ -1616,6 -1617,20 +1616,6 @@@ config UACCESS_WITH_MEMCP
          However, if the CPU data cache is using a write-allocate mode,
          this option is unlikely to provide any performance gain.
  
 -config SECCOMP
 -      bool
 -      prompt "Enable seccomp to safely compute untrusted bytecode"
 -      help
 -        This kernel feature is useful for number crunching applications
 -        that may need to compute untrusted bytecode during their
 -        execution. By using pipes or other transports made available to
 -        the process as file descriptors supporting the read/write
 -        syscalls, it's possible to isolate those applications in
 -        their own address space using seccomp. Once seccomp is
 -        enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
 -        and the task is only allowed to execute a few safe syscalls
 -        defined by each seccomp mode.
 -
  config PARAVIRT
        bool "Enable paravirtualization code"
        help
diff --combined arch/arm64/Kconfig
index f858c352f72a47cdef887a9a6d291b4f0a65dadd,93d041ffe583fad7cadac45f76ec9edcd7460ef2..dd3c81d84e28c009124f47f4b811e9632f6f956f
@@@ -13,7 -13,6 +13,6 @@@ config ARM6
        select ARCH_BINFMT_ELF_STATE
        select ARCH_HAS_DEBUG_VIRTUAL
        select ARCH_HAS_DEBUG_VM_PGTABLE
-       select ARCH_HAS_DEVMEM_IS_ALLOWED
        select ARCH_HAS_DMA_PREP_COHERENT
        select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
        select ARCH_HAS_FAST_MULTIPLIER
@@@ -29,7 -28,6 +28,7 @@@
        select ARCH_HAS_SETUP_DMA_OPS
        select ARCH_HAS_SET_DIRECT_MAP
        select ARCH_HAS_SET_MEMORY
 +      select ARCH_STACKWALK
        select ARCH_HAS_STRICT_KERNEL_RWX
        select ARCH_HAS_STRICT_MODULE_RWX
        select ARCH_HAS_SYNC_DMA_FOR_DEVICE
        select GENERIC_CPU_VULNERABILITIES
        select GENERIC_EARLY_IOREMAP
        select GENERIC_IDLE_POLL_SETUP
 +      select GENERIC_IRQ_IPI
        select GENERIC_IRQ_MULTI_HANDLER
        select GENERIC_IRQ_PROBE
        select GENERIC_IRQ_SHOW
        select GENERIC_IRQ_SHOW_LEVEL
+       select GENERIC_LIB_DEVMEM_IS_ALLOWED
        select GENERIC_PCI_IOMAP
        select GENERIC_PTDUMP
        select GENERIC_SCHED_CLOCK
        select GENERIC_VDSO_TIME_NS
        select HANDLE_DOMAIN_IRQ
        select HARDIRQS_SW_RESEND
 +      select HAVE_MOVE_PMD
        select HAVE_PCI
        select HAVE_ACPI_APEI if (ACPI && EFI)
        select HAVE_ALIGNED_STRUCT_PAGE if SLUB
        select PCI_SYSCALL if PCI
        select POWER_RESET
        select POWER_SUPPLY
 +      select SET_FS
        select SPARSE_IRQ
        select SWIOTLB
        select SYSCTL_EXCEPTION_TRACE
@@@ -215,18 -211,12 +215,18 @@@ config ARM64_PAGE_SHIF
        default 14 if ARM64_16K_PAGES
        default 12
  
 -config ARM64_CONT_SHIFT
 +config ARM64_CONT_PTE_SHIFT
        int
        default 5 if ARM64_64K_PAGES
        default 7 if ARM64_16K_PAGES
        default 4
  
 +config ARM64_CONT_PMD_SHIFT
 +      int
 +      default 5 if ARM64_64K_PAGES
 +      default 5 if ARM64_16K_PAGES
 +      default 4
 +
  config ARCH_MMAP_RND_BITS_MIN
         default 14 if ARM64_64K_PAGES
         default 16 if ARM64_16K_PAGES
@@@ -1043,6 -1033,19 +1043,6 @@@ config ARCH_ENABLE_SPLIT_PMD_PTLOC
  config CC_HAVE_SHADOW_CALL_STACK
        def_bool $(cc-option, -fsanitize=shadow-call-stack -ffixed-x18)
  
 -config SECCOMP
 -      bool "Enable seccomp to safely compute untrusted bytecode"
 -      help
 -        This kernel feature is useful for number crunching applications
 -        that may need to compute untrusted bytecode during their
 -        execution. By using pipes or other transports made available to
 -        the process as file descriptors supporting the read/write
 -        syscalls, it's possible to isolate those applications in
 -        their own address space using seccomp. Once seccomp is
 -        enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
 -        and the task is only allowed to execute a few safe syscalls
 -        defined by each seccomp mode.
 -
  config PARAVIRT
        bool "Enable paravirtualization code"
        help
@@@ -1162,6 -1165,32 +1162,6 @@@ config UNMAP_KERNEL_AT_EL
  
          If unsure, say Y.
  
 -config HARDEN_BRANCH_PREDICTOR
 -      bool "Harden the branch predictor against aliasing attacks" if EXPERT
 -      default y
 -      help
 -        Speculation attacks against some high-performance processors rely on
 -        being able to manipulate the branch predictor for a victim context by
 -        executing aliasing branches in the attacker context.  Such attacks
 -        can be partially mitigated against by clearing internal branch
 -        predictor state and limiting the prediction logic in some situations.
 -
 -        This config option will take CPU-specific actions to harden the
 -        branch predictor against aliasing attacks and may rely on specific
 -        instruction sequences or control bits being set by the system
 -        firmware.
 -
 -        If unsure, say Y.
 -
 -config ARM64_SSBD
 -      bool "Speculative Store Bypass Disable" if EXPERT
 -      default y
 -      help
 -        This enables mitigation of the bypassing of previous stores
 -        by speculative loads.
 -
 -        If unsure, say Y.
 -
  config RODATA_FULL_DEFAULT_ENABLED
        bool "Apply r/o permissions of VM areas also to their linear aliases"
        default y
@@@ -1601,6 -1630,8 +1601,6 @@@ config ARM64_BTI_KERNE
        depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI
        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697
        depends on !CC_IS_GCC || GCC_VERSION >= 100100
 -      # https://reviews.llvm.org/rGb8ae3fdfa579dbf366b1bb1cbfdbf8c51db7fa55
 -      depends on !CC_IS_CLANG || CLANG_VERSION >= 100001
        depends on !(CC_IS_CLANG && GCOV_KERNEL)
        depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
        help
@@@ -1633,39 -1664,6 +1633,39 @@@ config ARCH_RANDO
          provides a high bandwidth, cryptographically secure
          hardware random number generator.
  
 +config ARM64_AS_HAS_MTE
 +      # Initial support for MTE went in binutils 2.32.0, checked with
 +      # ".arch armv8.5-a+memtag" below. However, this was incomplete
 +      # as a late addition to the final architecture spec (LDGM/STGM)
 +      # is only supported in the newer 2.32.x and 2.33 binutils
 +      # versions, hence the extra "stgm" instruction check below.
 +      def_bool $(as-instr,.arch armv8.5-a+memtag\nstgm xzr$(comma)[x0])
 +
 +config ARM64_MTE
 +      bool "Memory Tagging Extension support"
 +      default y
 +      depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI
 +      select ARCH_USES_HIGH_VMA_FLAGS
 +      help
 +        Memory Tagging (part of the ARMv8.5 Extensions) provides
 +        architectural support for run-time, always-on detection of
 +        various classes of memory error to aid with software debugging
 +        to eliminate vulnerabilities arising from memory-unsafe
 +        languages.
 +
 +        This option enables the support for the Memory Tagging
 +        Extension at EL0 (i.e. for userspace).
 +
 +        Selecting this option allows the feature to be detected at
 +        runtime. Any secondary CPU not implementing this feature will
 +        not be allowed a late bring-up.
 +
 +        Userspace binaries that want to use this feature must
 +        explicitly opt in. The mechanism for the userspace is
 +        described in:
 +
 +        Documentation/arm64/memory-tagging-extension.rst.
 +
  endmenu
  
  config ARM64_SVE
@@@ -1878,10 -1876,6 +1878,10 @@@ config ARCH_ENABLE_HUGEPAGE_MIGRATIO
        def_bool y
        depends on HUGETLB_PAGE && MIGRATION
  
 +config ARCH_ENABLE_THP_MIGRATION
 +      def_bool y
 +      depends on TRANSPARENT_HUGEPAGE
 +
  menu "Power management options"
  
  source "kernel/power/Kconfig"
index fd172c41df905120f157b90eecb93b3911e32e6a,c53eba1a7fd2d612b6061fc172fbe099d7abd036..5ea8656a2030bff30e447041029f13106b4c44c3
@@@ -110,7 -110,6 +110,7 @@@ static inline u64 __raw_readq(const vol
  
  #define __io_par(v)           __iormb(v)
  #define __iowmb()             dma_wmb()
 +#define __iomb()              dma_mb()
  
  /*
   * Relaxed I/O memory access primitives. These follow the Device memory
@@@ -201,6 -200,4 +201,4 @@@ extern void __iomem *ioremap_cache(phys
  extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
  extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
  
- extern int devmem_is_allowed(unsigned long pfn);
  #endif        /* __ASM_IO_H */
diff --combined arch/riscv/Kconfig
index d9da5d92e40da0f20325c54219c8e91bb9cb72f4,669a65d8f1d4714c4e9f6f4d7c678f290132d3d0..2b41f6d8e4583bd2106e8bd306bb702c52aa774d
@@@ -14,7 -14,6 +14,7 @@@ config RISC
        def_bool y
        select ARCH_CLOCKSOURCE_INIT
        select ARCH_SUPPORTS_ATOMIC_RMW
 +      select ARCH_STACKWALK
        select ARCH_HAS_BINFMT_FLAT
        select ARCH_HAS_DEBUG_VM_PGTABLE
        select ARCH_HAS_DEBUG_VIRTUAL if MMU
        select GENERIC_ARCH_TOPOLOGY if SMP
        select GENERIC_ATOMIC64 if !64BIT
        select GENERIC_CLOCKEVENTS
 +      select GENERIC_EARLY_IOREMAP
        select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
        select GENERIC_IOREMAP
        select GENERIC_IRQ_MULTI_HANDLER
        select GENERIC_IRQ_SHOW
+       select GENERIC_LIB_DEVMEM_IS_ALLOWED
        select GENERIC_PCI_IOMAP
        select GENERIC_PTDUMP if MMU
        select GENERIC_SCHED_CLOCK
@@@ -69,7 -68,6 +70,7 @@@
        select HAVE_FUTEX_CMPXCHG if FUTEX
        select HAVE_GCC_PLUGINS
        select HAVE_GENERIC_VDSO if MMU && 64BIT
 +      select HAVE_IRQ_TIME_ACCOUNTING
        select HAVE_PCI
        select HAVE_PERF_EVENTS
        select HAVE_PERF_REGS
@@@ -90,7 -88,6 +91,7 @@@
        select SPARSE_IRQ
        select SYSCTL_EXCEPTION_TRACE
        select THREAD_INFO_IN_TASK
 +      select UACCESS_MEMCPY if !MMU
  
  config ARCH_MMAP_RND_BITS_MIN
        default 18 if 64BIT
@@@ -338,6 -335,19 +339,6 @@@ menu "Kernel features
  
  source "kernel/Kconfig.hz"
  
 -config SECCOMP
 -      bool "Enable seccomp to safely compute untrusted bytecode"
 -      help
 -        This kernel feature is useful for number crunching applications
 -        that may need to compute untrusted bytecode during their
 -        execution. By using pipes or other transports made available to
 -        the process as file descriptors supporting the read/write
 -        syscalls, it's possible to isolate those applications in
 -        their own address space using seccomp. Once seccomp is
 -        enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
 -        and the task is only allowed to execute a few safe syscalls
 -        defined by each seccomp mode.
 -
  config RISCV_SBI_V01
        bool "SBI v0.1 support"
        default y
@@@ -392,28 -402,6 +393,28 @@@ config CMDLINE_FORC
  
  endchoice
  
 +config EFI_STUB
 +      bool
 +
 +config EFI
 +      bool "UEFI runtime support"
 +      depends on OF
 +      select LIBFDT
 +      select UCS2_STRING
 +      select EFI_PARAMS_FROM_FDT
 +      select EFI_STUB
 +      select EFI_GENERIC_STUB
 +      select EFI_RUNTIME_WRAPPERS
 +      select RISCV_ISA_C
 +      depends on MMU
 +      default y
 +      help
 +        This option provides support for runtime services provided
 +        by UEFI firmware (such as non-volatile variables, realtime
 +        clock, and platform reset). A UEFI stub is also provided to
 +        allow the kernel to be booted as an EFI application. This
 +        is only useful on systems that have UEFI firmware.
 +
  endmenu
  
  config BUILTIN_DTB
@@@ -426,5 -414,3 +427,5 @@@ menu "Power management options
  source "kernel/power/Kconfig"
  
  endmenu
 +
 +source "drivers/firmware/Kconfig"
diff --combined include/asm-generic/io.h
index 9ea83d80eb6f93f62fa98ba9875d03ed58871a69,da2e861dee1c3eb63cd31a5342561f869903acc5..c6af40ce03befec1740fd9ab705648e1eba2bf81
@@@ -911,6 -911,18 +911,6 @@@ static inline void iowrite64_rep(volati
  #include <linux/vmalloc.h>
  #define __io_virt(x) ((void __force *)(x))
  
 -#ifndef CONFIG_GENERIC_IOMAP
 -struct pci_dev;
 -extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
 -
 -#ifndef pci_iounmap
 -#define pci_iounmap pci_iounmap
 -static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
 -{
 -}
 -#endif
 -#endif /* CONFIG_GENERIC_IOMAP */
 -
  /*
   * Change virtual addresses to physical addresses and vv.
   * These are pretty trivial
@@@ -1004,16 -1016,6 +1004,16 @@@ static inline void __iomem *ioport_map(
        port &= IO_SPACE_LIMIT;
        return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
  }
 +#define __pci_ioport_unmap __pci_ioport_unmap
 +static inline void __pci_ioport_unmap(void __iomem *p)
 +{
 +      uintptr_t start = (uintptr_t) PCI_IOBASE;
 +      uintptr_t addr = (uintptr_t) p;
 +
 +      if (addr >= start && addr < start + IO_SPACE_LIMIT)
 +              return;
 +      iounmap(p);
 +}
  #endif
  
  #ifndef ioport_unmap
@@@ -1028,23 -1030,6 +1028,23 @@@ extern void ioport_unmap(void __iomem *
  #endif /* CONFIG_GENERIC_IOMAP */
  #endif /* CONFIG_HAS_IOPORT_MAP */
  
 +#ifndef CONFIG_GENERIC_IOMAP
 +struct pci_dev;
 +extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
 +
 +#ifndef __pci_ioport_unmap
 +static inline void __pci_ioport_unmap(void __iomem *p) {}
 +#endif
 +
 +#ifndef pci_iounmap
 +#define pci_iounmap pci_iounmap
 +static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
 +{
 +      __pci_ioport_unmap(p);
 +}
 +#endif
 +#endif /* CONFIG_GENERIC_IOMAP */
 +
  /*
   * Convert a virtual cached pointer to an uncached pointer
   */
@@@ -1137,6 -1122,10 +1137,10 @@@ static inline void memcpy_toio(volatil
  }
  #endif
  
+ #ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
+ extern int devmem_is_allowed(unsigned long pfn);
+ #endif
  #endif /* __KERNEL__ */
  
  #endif /* __ASM_GENERIC_IO_H */
diff --combined lib/Kconfig
index b46a9fd122c81acabd888e8b250e78be4f575ef6,b26721cf51bc977412df0801fe36128f3d71ac69..46806332a8cc2c3235a379b4300d113da959bbe0
@@@ -635,12 -635,7 +635,12 @@@ config UACCESS_MEMCP
  config ARCH_HAS_UACCESS_FLUSHCACHE
        bool
  
 -config ARCH_HAS_UACCESS_MCSAFE
 +# arch has a concept of a recoverable synchronous exception due to a
 +# memory-read error like x86 machine-check or ARM data-abort, and
 +# implements copy_mc_to_{user,kernel} to abort and report
 +# 'bytes-transferred' if that exception fires when accessing the source
 +# buffer.
 +config ARCH_HAS_COPY_MC
        bool
  
  # Temporary. Goes away when all archs are cleaned up
@@@ -686,6 -681,9 +686,9 @@@ config GENERIC_LIB_CMPDI
  config GENERIC_LIB_UCMPDI2
        bool
  
+ config GENERIC_LIB_DEVMEM_IS_ALLOWED
+       bool
  config PLDMFW
        bool
        default n
diff --combined lib/Kconfig.debug
index d7a7bc3b6098287dc7af87b2c94d5304675401f3,87410f62b50186a49bbf686f2cee1ff6ecc60c2b..c63fc68f9bf2e85bfc38a9192c70996b7f3f57e7
@@@ -212,10 -212,9 +212,10 @@@ config DEBUG_INF
  
          If unsure, say N.
  
 +if DEBUG_INFO
 +
  config DEBUG_INFO_REDUCED
        bool "Reduce debugging information"
 -      depends on DEBUG_INFO
        help
          If you say Y here gcc is instructed to generate less debugging
          information for structure types. This means that tools that
  
  config DEBUG_INFO_COMPRESSED
        bool "Compressed debugging information"
 -      depends on DEBUG_INFO
        depends on $(cc-option,-gz=zlib)
        depends on $(ld-option,--compress-debug-sections=zlib)
        help
  
  config DEBUG_INFO_SPLIT
        bool "Produce split debuginfo in .dwo files"
 -      depends on DEBUG_INFO
        depends on $(cc-option,-gsplit-dwarf)
        help
          Generate debug info into separate .dwo files. This significantly
  
  config DEBUG_INFO_DWARF4
        bool "Generate dwarf4 debuginfo"
 -      depends on DEBUG_INFO
        depends on $(cc-option,-gdwarf-4)
        help
          Generate dwarf4 debug info. This requires recent versions
  
  config DEBUG_INFO_BTF
        bool "Generate BTF typeinfo"
 -      depends on DEBUG_INFO
        depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
        depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
        help
  
  config GDB_SCRIPTS
        bool "Provide GDB scripts for kernel debugging"
 -      depends on DEBUG_INFO
        help
          This creates the required links to GDB helper scripts in the
          build directory. If you load vmlinux into gdb, the helper
          instance. See Documentation/dev-tools/gdb-kernel-debugging.rst
          for further details.
  
 +endif # DEBUG_INFO
 +
  config ENABLE_MUST_CHECK
        bool "Enable __must_check logic"
        default y
@@@ -1365,27 -1367,6 +1365,27 @@@ config WW_MUTEX_SELFTES
          Say M if you want these self tests to build as a module.
          Say N if you are unsure.
  
 +config SCF_TORTURE_TEST
 +      tristate "torture tests for smp_call_function*()"
 +      depends on DEBUG_KERNEL
 +      select TORTURE_TEST
 +      help
 +        This option provides a kernel module that runs torture tests
 +        on the smp_call_function() family of primitives.  The kernel
 +        module may be built after the fact on the running kernel to
 +        be tested, if desired.
 +
 +config CSD_LOCK_WAIT_DEBUG
 +      bool "Debugging for csd_lock_wait(), called from smp_call_function*()"
 +      depends on DEBUG_KERNEL
 +      depends on 64BIT
 +      default n
 +      help
 +        This option enables debug prints when CPUs are slow to respond
 +        to the smp_call_function*() IPI wrappers.  These debug prints
 +        include the IPI handler function currently executing (if any)
 +        and relevant stack traces.
 +
  endmenu # lock debugging
  
  config TRACE_IRQFLAGS
@@@ -1645,7 -1626,7 +1645,7 @@@ config ARCH_HAS_DEVMEM_IS_ALLOWE
  config STRICT_DEVMEM
        bool "Filter access to /dev/mem"
        depends on MMU && DEVMEM
-       depends on ARCH_HAS_DEVMEM_IS_ALLOWED
+       depends on ARCH_HAS_DEVMEM_IS_ALLOWED || GENERIC_LIB_DEVMEM_IS_ALLOWED
        default y if PPC || X86 || ARM64
        help
          If this option is disabled, you allow userspace (root) access to all
@@@ -1787,13 -1768,6 +1787,13 @@@ config FAIL_PAGE_ALLO
        help
          Provide fault-injection capability for alloc_pages().
  
 +config FAULT_INJECTION_USERCOPY
 +      bool "Fault injection capability for usercopy functions"
 +      depends on FAULT_INJECTION
 +      help
 +        Provides fault-injection capability to inject failures
 +        in usercopy functions (copy_from_user(), get_user(), ...).
 +
  config FAIL_MAKE_REQUEST
        bool "Fault-injection capability for disk IO"
        depends on FAULT_INJECTION && BLOCK
@@@ -2061,6 -2035,13 +2061,6 @@@ config TEST_BITMA
  
          If unsure, say N.
  
 -config TEST_BITFIELD
 -      tristate "Test bitfield functions at runtime"
 -      help
 -        Enable this option to test the bitfield functions at boot.
 -
 -        If unsure, say N.
 -
  config TEST_UUID
        tristate "Test functions located in the uuid module at runtime"
  
@@@ -2210,22 -2191,6 +2210,22 @@@ config TEST_SYSCT
  
          If unsure, say N.
  
 +config BITFIELD_KUNIT
 +      tristate "KUnit test bitfield functions at runtime"
 +      depends on KUNIT
 +      help
 +        Enable this option to test the bitfield functions at boot.
 +
 +        KUnit tests run during boot and output the results to the debug log
 +        in TAP format (http://testanything.org/). Only useful for kernel devs
 +        running the KUnit test harness, and not intended for inclusion into a
 +        production build.
 +
 +        For more information on KUnit and unit tests in general please refer
 +        to the KUnit documentation in Documentation/dev-tools/kunit/.
 +
 +        If unsure, say N.
 +
  config SYSCTL_KUNIT_TEST
        tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS
        depends on KUNIT
@@@ -2402,15 -2367,6 +2402,15 @@@ config TEST_HM
  
          If unsure, say N.
  
 +config TEST_FREE_PAGES
 +      tristate "Test freeing pages"
 +      help
 +        Test that a memory leak does not occur due to a race between
 +        freeing a block of pages and a speculative page reference.
 +        Loading this module is safe if your kernel has the bug fixed.
 +        If the bug is not fixed, it will leak gigabytes of memory and
 +        probably OOM your system.
 +
  config TEST_FPU
        tristate "Test floating point operations in kernel space"
        depends on X86 && !KCOV_INSTRUMENT_ALL
diff --combined lib/Makefile
index ce45af50983a2a5e35823dbd1e632aa425ab3560,34011a11fbb35c3cbefafe87a191c4b5c0fbc9ae..431d7d894bf797f5f05eff4ef87a964f8be7fdb5
@@@ -65,11 -65,9 +65,11 @@@ CFLAGS_test_bitops.o += -Werro
  obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
  obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o
  obj-$(CONFIG_TEST_IDA) += test_ida.o
 -obj-$(CONFIG_TEST_KASAN) += test_kasan.o
 +obj-$(CONFIG_KASAN_KUNIT_TEST) += test_kasan.o
  CFLAGS_test_kasan.o += -fno-builtin
  CFLAGS_test_kasan.o += $(call cc-disable-warning, vla)
 +obj-$(CONFIG_TEST_KASAN_MODULE) += test_kasan_module.o
 +CFLAGS_test_kasan_module.o += -fno-builtin
  obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
  CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
  UBSAN_SANITIZE_test_ubsan.o := y
@@@ -87,6 -85,7 +87,6 @@@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_
  obj-$(CONFIG_TEST_PRINTF) += test_printf.o
  obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
  obj-$(CONFIG_TEST_STRSCPY) += test_strscpy.o
 -obj-$(CONFIG_TEST_BITFIELD) += test_bitfield.o
  obj-$(CONFIG_TEST_UUID) += test_uuid.o
  obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
  obj-$(CONFIG_TEST_PARMAN) += test_parman.o
@@@ -100,7 -99,6 +100,7 @@@ obj-$(CONFIG_TEST_BLACKHOLE_DEV) += tes
  obj-$(CONFIG_TEST_MEMINIT) += test_meminit.o
  obj-$(CONFIG_TEST_LOCKUP) += test_lockup.o
  obj-$(CONFIG_TEST_HMM) += test_hmm.o
 +obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o
  
  #
  # CFLAGS for compiling floating point code inside the kernel. x86/Makefile turns
@@@ -209,7 -207,6 +209,7 @@@ obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += c
  
  obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
  obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
 +obj-$(CONFIG_FAULT_INJECTION_USERCOPY) += fault-inject-usercopy.o
  obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o
  obj-$(CONFIG_PM_NOTIFIER_ERROR_INJECT) += pm-notifier-error-inject.o
  obj-$(CONFIG_NETDEV_NOTIFIER_ERROR_INJECT) += netdev-notifier-error-inject.o
@@@ -348,7 -345,8 +348,9 @@@ obj-$(CONFIG_OBJAGG) += objagg.
  obj-$(CONFIG_PLDMFW) += pldmfw/
  
  # KUnit tests
 +obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
  obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
  obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
  obj-$(CONFIG_BITS_TEST) += test_bits.o
+ obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o