Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 May 2022 04:06:11 +0000 (21:06 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 May 2022 04:06:11 +0000 (21:06 -0700)
Pull arm64 updates from Catalin Marinas:

 - Initial support for the ARMv9 Scalable Matrix Extension (SME).

   SME takes the approach used for vectors in SVE and extends this to
   provide architectural support for matrix operations. No KVM support
   yet, SME is disabled in guests.

 - Support for crashkernel reservations above ZONE_DMA via the
   'crashkernel=X,high' command line option.

 - btrfs search_ioctl() fix for live-lock with sub-page faults.

 - arm64 perf updates: support for the Hisilicon "CPA" PMU for
   monitoring coherent I/O traffic, support for Arm's CMN-650 and
   CMN-700 interconnect PMUs, minor driver fixes, kerneldoc cleanup.

 - Kselftest updates for SME, BTI, MTE.

 - Automatic generation of the system register macros from a 'sysreg'
   file describing the register bitfields.

 - Update the type of the function argument holding the ESR_ELx register
   value to unsigned long to match the architecture register size
   (originally 32-bit but extended since ARMv8.0).

 - stacktrace cleanups.

 - ftrace cleanups.

 - Miscellaneous updates, most notably: arm64-specific huge_ptep_get(),
   avoid executable mappings in kexec/hibernate code, drop TLB flushing
   from get_clear_flush() (and rename it to get_clear_contig()),
   ARCH_NR_GPIO bumped to 2048 for ARCH_APPLE.

* tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (145 commits)
  arm64/sysreg: Generate definitions for FAR_ELx
  arm64/sysreg: Generate definitions for DACR32_EL2
  arm64/sysreg: Generate definitions for CSSELR_EL1
  arm64/sysreg: Generate definitions for CPACR_ELx
  arm64/sysreg: Generate definitions for CONTEXTIDR_ELx
  arm64/sysreg: Generate definitions for CLIDR_EL1
  arm64/sve: Move sve_free() into SVE code section
  arm64: Kconfig.platforms: Add comments
  arm64: Kconfig: Fix indentation and add comments
  arm64: mm: avoid writable executable mappings in kexec/hibernate code
  arm64: lds: move special code sections out of kernel exec segment
  arm64/hugetlb: Implement arm64 specific huge_ptep_get()
  arm64/hugetlb: Use ptep_get() to get the pte value of a huge page
  arm64: kdump: Do not allocate crash low memory if not needed
  arm64/sve: Generate ZCR definitions
  arm64/sme: Generate defintions for SVCR
  arm64/sme: Generate SMPRI_EL1 definitions
  arm64/sme: Automatically generate SMPRIMAP_EL2 definitions
  arm64/sme: Automatically generate SMIDR_EL1 defines
  arm64/sme: Automatically generate defines for SMCR
  ...

16 files changed:
1  2 
Documentation/admin-guide/kernel-parameters.txt
Documentation/virt/kvm/api.rst
arch/Kconfig
arch/arm64/Kconfig
arch/arm64/Kconfig.platforms
arch/arm64/include/asm/kvm_emulate.h
arch/arm64/include/asm/pgtable.h
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/mte.c
arch/arm64/kvm/arm.c
arch/arm64/kvm/inject_fault.c
arch/arm64/kvm/sys_regs.c
fs/btrfs/ioctl.c
include/uapi/linux/elf.h
kernel/trace/fgraph.c

                        Defaults to zero when built as a module and to
                        10 seconds when built into the kernel.
  
 -      clearcpuid=BITNUM[,BITNUM...] [X86]
 +      clearcpuid=X[,X...] [X86]
                        Disable CPUID feature X for the kernel. See
                        arch/x86/include/asm/cpufeatures.h for the valid bit
 -                      numbers. Note the Linux specific bits are not necessarily
 -                      stable over kernel options, but the vendor specific
 +                      numbers X. Note the Linux-specific bits are not necessarily
 +                      stable over kernel options, but the vendor-specific
                        ones should be.
 +                      X can also be a string as appearing in the flags: line
 +                      in /proc/cpuinfo which does not have the above
 +                      instability issue. However, not all features have names
 +                      in /proc/cpuinfo.
 +                      Note that using this option will taint your kernel.
                        Also note that user programs calling CPUID directly
                        or using the feature without checking anything
                        will still see it. This just prevents it from
                        Documentation/admin-guide/kdump/kdump.rst for an example.
  
        crashkernel=size[KMG],high
-                       [KNL, X86-64] range could be above 4G. Allow kernel
+                       [KNL, X86-64, ARM64] range could be above 4G. Allow kernel
                        to allocate physical memory region from top, so could
                        be above 4G if system have more than 4G ram installed.
                        Otherwise memory region will be allocated below 4G, if
                        that require some amount of low memory, e.g. swiotlb
                        requires at least 64M+32K low memory, also enough extra
                        low memory is needed to make sure DMA buffers for 32-bit
-                       devices won't run out. Kernel would try to allocate at
+                       devices won't run out. Kernel would try to allocate
                        at least 256M below 4G automatically.
-                       This one let user to specify own low range under 4G
+                       This one lets the user specify own low range under 4G
                        for second kernel instead.
                        0: to disable low allocation.
                        It will be ignored when crashkernel=X,high is not used
                        or memory reserved is below 4G.
  
+                       [KNL, ARM64] range in low memory.
+                       This one lets the user specify a low range in the
+                       DMA zone for the crash dump kernel.
+                       It will be ignored when crashkernel=X,high is not used
+                       or memory reserved is located in the DMA zones.
        cryptomgr.notests
                        [KNL] Disable crypto self-tests
  
                        when set.
                        Format: <int>
  
 -      libata.force=   [LIBATA] Force configurations.  The format is comma-
 -                      separated list of "[ID:]VAL" where ID is
 -                      PORT[.DEVICE].  PORT and DEVICE are decimal numbers
 -                      matching port, link or device.  Basically, it matches
 -                      the ATA ID string printed on console by libata.  If
 -                      the whole ID part is omitted, the last PORT and DEVICE
 -                      values are used.  If ID hasn't been specified yet, the
 -                      configuration applies to all ports, links and devices.
 +      libata.force=   [LIBATA] Force configurations.  The format is comma-
 +                      separated list of "[ID:]VAL" where ID is PORT[.DEVICE].
 +                      PORT and DEVICE are decimal numbers matching port, link
 +                      or device.  Basically, it matches the ATA ID string
 +                      printed on console by libata.  If the whole ID part is
 +                      omitted, the last PORT and DEVICE values are used.  If
 +                      ID hasn't been specified yet, the configuration applies
 +                      to all ports, links and devices.
  
                        If only DEVICE is omitted, the parameter applies to
                        the port and all links and devices behind it.  DEVICE
                        host link and device attached to it.
  
                        The VAL specifies the configuration to force.  As long
 -                      as there's no ambiguity shortcut notation is allowed.
 +                      as there is no ambiguity, shortcut notation is allowed.
                        For example, both 1.5 and 1.5G would work for 1.5Gbps.
                        The following configurations can be forced.
  
                          udma[/][16,25,33,44,66,100,133] notation is also
                          allowed.
  
 +                      * nohrst, nosrst, norst: suppress hard, soft and both
 +                        resets.
 +
 +                      * rstonce: only attempt one reset during hot-unplug
 +                        link recovery.
 +
 +                      * [no]dbdelay: Enable or disable the extra 200ms delay
 +                        before debouncing a link PHY and device presence
 +                        detection.
 +
                        * [no]ncq: Turn on or off NCQ.
  
 -                      * [no]ncqtrim: Turn off queued DSM TRIM.
 +                      * [no]ncqtrim: Enable or disable queued DSM TRIM.
 +
 +                      * [no]ncqati: Enable or disable NCQ trim on ATI chipset.
 +
 +                      * [no]trim: Enable or disable (unqueued) TRIM.
 +
 +                      * trim_zero: Indicate that TRIM command zeroes data.
 +
 +                      * max_trim_128m: Set 128M maximum trim size limit.
 +
 +                      * [no]dma: Turn on or off DMA transfers.
 +
 +                      * atapi_dmadir: Enable ATAPI DMADIR bridge support.
 +
 +                      * atapi_mod16_dma: Enable the use of ATAPI DMA for
 +                        commands that are not a multiple of 16 bytes.
 +
 +                      * [no]dmalog: Enable or disable the use of the
 +                        READ LOG DMA EXT command to access logs.
 +
 +                      * [no]iddevlog: Enable or disable access to the
 +                        identify device data log.
  
 -                      * nohrst, nosrst, norst: suppress hard, soft
 -                        and both resets.
 +                      * [no]logdir: Enable or disable access to the general
 +                        purpose log directory.
  
 -                      * rstonce: only attempt one reset during
 -                        hot-unplug link recovery
 +                      * max_sec_128: Set transfer size limit to 128 sectors.
  
 -                      * dump_id: dump IDENTIFY data.
 +                      * max_sec_1024: Set or clear transfer size limit to
 +                        1024 sectors.
  
 -                      * atapi_dmadir: Enable ATAPI DMADIR bridge support
 +                      * max_sec_lba48: Set or clear transfer size limit to
 +                        65535 sectors.
 +
 +                      * [no]lpm: Enable or disable link power management.
 +
 +                      * [no]setxfer: Indicate if transfer speed mode setting
 +                        should be skipped.
 +
 +                      * dump_id: Dump IDENTIFY data.
  
                        * disable: Disable this device.
  
                                               mds=off [X86]
                                               tsx_async_abort=off [X86]
                                               kvm.nx_huge_pages=off [X86]
 +                                             srbds=off [X86,INTEL]
                                               no_entry_flush [PPC]
                                               no_uaccess_flush [PPC]
  
  
        nocache         [ARM]
  
 -      noclflush       [BUGS=X86] Don't use the CLFLUSH instruction
 -
        delayacct       [KNL] Enable per-task delay accounting
  
        nodsp           [SH] Disable hardware DSP at boot time.
  
        noexec          [IA-64]
  
 -      noexec          [X86]
 -                      On X86-32 available only on PAE configured kernels.
 -                      noexec=on: enable non-executable mappings (default)
 -                      noexec=off: disable non-executable mappings
 -
 -      nosmap          [X86,PPC]
 +      nosmap          [PPC]
                        Disable SMAP (Supervisor Mode Access Prevention)
                        even if it is supported by processor.
  
 -      nosmep          [X86,PPC64s]
 +      nosmep          [PPC64s]
                        Disable SMEP (Supervisor Mode Execution Prevention)
                        even if it is supported by processor.
  
  
        nosbagart       [IA-64]
  
 -      nosep           [BUGS=X86-32] Disables x86 SYSENTER/SYSEXIT support.
 -
        nosgx           [X86-64,SGX] Disables Intel SGX kernel support.
  
        nosmp           [SMP] Tells an SMP kernel to act as a UP kernel,
  
        rcupdate.rcu_cpu_stall_timeout= [KNL]
                        Set timeout for RCU CPU stall warning messages.
 +                      The value is in seconds and the maximum allowed
 +                      value is 300 seconds.
 +
 +      rcupdate.rcu_exp_cpu_stall_timeout= [KNL]
 +                      Set timeout for expedited RCU CPU stall warning
 +                      messages.  The value is in milliseconds
 +                      and the maximum allowed value is 21000
 +                      milliseconds. Please note that this value is
 +                      adjusted to an arch timer tick resolution.
 +                      Setting this to zero causes the value from
 +                      rcupdate.rcu_cpu_stall_timeout to be used (after
 +                      conversion from seconds to milliseconds).
  
        rcupdate.rcu_expedited= [KNL]
                        Use expedited grace-period primitives, for
                        number avoids disturbing real-time workloads,
                        but lengthens grace periods.
  
 +      rcupdate.rcu_task_stall_info= [KNL]
 +                      Set initial timeout in jiffies for RCU task stall
 +                      informational messages, which give some indication
 +                      of the problem for those not patient enough to
 +                      wait for ten minutes.  Informational messages are
 +                      only printed prior to the stall-warning message
 +                      for a given grace period. Disable with a value
 +                      less than or equal to zero.  Defaults to ten
 +                      seconds.  A change in value does not take effect
 +                      until the beginning of the next grace period.
 +
 +      rcupdate.rcu_task_stall_info_mult= [KNL]
 +                      Multiplier for time interval between successive
 +                      RCU task stall informational messages for a given
 +                      RCU tasks grace period.  This value is clamped
 +                      to one through ten, inclusive.  It defaults to
 +                      the value three, so that the first informational
 +                      message is printed 10 seconds into the grace
 +                      period, the second at 40 seconds, the third at
 +                      160 seconds, and then the stall warning at 600
 +                      seconds would prevent a fourth at 640 seconds.
 +
        rcupdate.rcu_task_stall_timeout= [KNL]
 -                      Set timeout in jiffies for RCU task stall warning
 -                      messages.  Disable with a value less than or equal
 -                      to zero.
 +                      Set timeout in jiffies for RCU task stall
 +                      warning messages.  Disable with a value less
 +                      than or equal to zero.  Defaults to ten minutes.
 +                      A change in value does not take effect until
 +                      the beginning of the next grace period.
  
        rcupdate.rcu_self_test= [KNL]
                        Run the RCU early boot self tests
  
        serialnumber    [BUGS=X86-32]
  
 +      sev=option[,option...] [X86-64] See Documentation/x86/x86_64/boot-options.rst
 +
        shapers=        [NET]
                        Maximal number of shapers.
  
        smart2=         [HW]
                        Format: <io1>[,<io2>[,...,<io8>]]
  
 +      smp.csd_lock_timeout= [KNL]
 +                      Specify the period of time in milliseconds
 +                      that smp_call_function() and friends will wait
 +                      for a CPU to release the CSD lock.  This is
 +                      useful when diagnosing bugs involving CPUs
 +                      disabling interrupts for extended periods
 +                      of time.  Defaults to 5,000 milliseconds, and
 +                      setting a value of zero disables this feature.
 +                      This feature may be more efficiently disabled
 +                      using the csdlock_debug- kernel parameter.
 +
        smsc-ircc2.nopnp        [HW] Don't use PNP to discover SMC devices
        smsc-ircc2.ircc_cfg=    [HW] Device configuration I/O port
        smsc-ircc2.ircc_sir=    [HW] SIR base I/O port
                        off:    Disable mitigation and remove
                                performance impact to RDRAND and RDSEED
  
 +      srcutree.big_cpu_lim [KNL]
 +                      Specifies the number of CPUs constituting a
 +                      large system, such that srcu_struct structures
 +                      should immediately allocate an srcu_node array.
 +                      This kernel-boot parameter defaults to 128,
 +                      but takes effect only when the low-order four
 +                      bits of srcutree.convert_to_big is equal to 3
 +                      (decide at boot).
 +
 +      srcutree.convert_to_big [KNL]
 +                      Specifies under what conditions an SRCU tree
 +                      srcu_struct structure will be converted to big
 +                      form, that is, with an rcu_node tree:
 +
 +                                 0:  Never.
 +                                 1:  At init_srcu_struct() time.
 +                                 2:  When rcutorture decides to.
 +                                 3:  Decide at boot time (default).
 +                              0x1X:  Above plus if high contention.
 +
 +                      Either way, the srcu_node tree will be sized based
 +                      on the actual runtime number of CPUs (nr_cpu_ids)
 +                      instead of the compile-time CONFIG_NR_CPUS.
 +
        srcutree.counter_wrap_check [KNL]
                        Specifies how frequently to check for
                        grace-period sequence counter wrap for the
                        expediting.  Set to zero to disable automatic
                        expediting.
  
 +      srcutree.small_contention_lim [KNL]
 +                      Specifies the number of update-side contention
 +                      events per jiffy will be tolerated before
 +                      initiating a conversion of an srcu_struct
 +                      structure to big form.  Note that the value of
 +                      srcutree.convert_to_big must have the 0x10 bit
 +                      set for contention-based conversions to occur.
 +
        ssbd=           [ARM64,HW]
                        Speculative Store Bypass Disable control
  
@@@ -5713,6 -5713,8 +5713,8 @@@ affect the device's behavior. Current d
    #define KVM_RUN_X86_SMM     (1 << 0)
    /* x86, set if bus lock detected in VM */
    #define KVM_RUN_BUS_LOCK    (1 << 1)
+   /* arm64, set for KVM_EXIT_DEBUG */
+   #define KVM_DEBUG_ARCH_HSR_HIGH_VALID  (1 << 0)
  
  ::
  
@@@ -5986,16 -5988,16 +5988,16 @@@ should put the acknowledged interrupt v
    #define KVM_SYSTEM_EVENT_RESET          2
    #define KVM_SYSTEM_EVENT_CRASH          3
                        __u32 type;
 -                      __u64 flags;
 +                        __u32 ndata;
 +                        __u64 data[16];
                } system_event;
  
  If exit_reason is KVM_EXIT_SYSTEM_EVENT then the vcpu has triggered
  a system-level event using some architecture specific mechanism (hypercall
  or some special instruction). In case of ARM64, this is triggered using
 -HVC instruction based PSCI call from the vcpu. The 'type' field describes
 -the system-level event type. The 'flags' field describes architecture
 -specific flags for the system-level event.
 +HVC instruction based PSCI call from the vcpu.
  
 +The 'type' field describes the system-level event type.
  Valid values for 'type' are:
  
   - KVM_SYSTEM_EVENT_SHUTDOWN -- the guest has requested a shutdown of the
     to ignore the request, or to gather VM memory core dump and/or
     reset/shutdown of the VM.
  
 -Valid flags are:
 +If KVM_CAP_SYSTEM_EVENT_DATA is present, the 'data' field can contain
 +architecture specific information for the system-level event.  Only
 +the first `ndata` items (possibly zero) of the data array are valid.
  
 - - KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 (arm64 only) -- the guest issued
 -   a SYSTEM_RESET2 call according to v1.1 of the PSCI specification.
 + - for arm64, data[0] is set to KVM_SYSTEM_EVENT_RESET_FLAG_PSCI_RESET2 if
 +   the guest issued a SYSTEM_RESET2 call according to v1.1 of the PSCI
 +   specification.
 +
 + - for RISC-V, data[0] is set to the value of the second argument of the
 +   ``sbi_system_reset`` call.
 +
 +Previous versions of Linux defined a `flags` member in this struct.  The
 +field is now aliased to `data[0]`.  Userspace can assume that it is only
 +written if ndata is greater than 0.
  
  ::
  
diff --combined arch/Kconfig
@@@ -24,6 -24,13 +24,13 @@@ config KEXEC_EL
  config HAVE_IMA_KEXEC
        bool
  
+ config ARCH_HAS_SUBPAGE_FAULTS
+       bool
+       help
+         Select if the architecture can check permissions at sub-page
+         granularity (e.g. arm64 MTE). The probe_user_*() functions
+         must be implemented.
  config HOTPLUG_SMT
        bool
  
@@@ -35,7 -42,6 +42,7 @@@ config KPROBE
        depends on MODULES
        depends on HAVE_KPROBES
        select KALLSYMS
 +      select TASKS_RCU if PREEMPTION
        help
          Kprobes allows you to trap at almost any kernel address and
          execute a callback function.  register_kprobe() establishes
@@@ -855,8 -861,10 +862,8 @@@ config HAVE_ARCH_HUGE_VMA
  
  #
  #  Archs that select this would be capable of PMD-sized vmaps (i.e.,
 -#  arch_vmap_pmd_supported() returns true), and they must make no assumptions
 -#  that vmalloc memory is mapped with PAGE_SIZE ptes. The VM_NO_HUGE_VMAP flag
 -#  can be used to prohibit arch-specific allocations from using hugepages to
 -#  help with this (e.g., modules may require it).
 +#  arch_vmap_pmd_supported() returns true). The VM_ALLOW_HUGE_VMAP flag
 +#  must be used to enable allocations to use hugepages.
  #
  config HAVE_ARCH_HUGE_VMALLOC
        depends on HAVE_ARCH_HUGE_VMAP
diff --combined arch/arm64/Kconfig
@@@ -175,6 -175,8 +175,6 @@@ config ARM6
        select HAVE_DEBUG_KMEMLEAK
        select HAVE_DMA_CONTIGUOUS
        select HAVE_DYNAMIC_FTRACE
 -      select HAVE_DYNAMIC_FTRACE_WITH_REGS \
 -              if $(cc-option,-fpatchable-function-entry=2)
        select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
                if DYNAMIC_FTRACE_WITH_REGS
        select HAVE_EFFICIENT_UNALIGNED_ACCESS
        help
          ARM 64-bit (AArch64) Linux support.
  
 +config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
 +      def_bool CC_IS_CLANG
 +      # https://github.com/ClangBuiltLinux/linux/issues/1507
 +      depends on AS_IS_GNU || (AS_IS_LLVM && (LD_IS_LLD || LD_VERSION >= 23600))
 +      select HAVE_DYNAMIC_FTRACE_WITH_REGS
 +
 +config GCC_SUPPORTS_DYNAMIC_FTRACE_WITH_REGS
 +      def_bool CC_IS_GCC
 +      depends on $(cc-option,-fpatchable-function-entry=2)
 +      select HAVE_DYNAMIC_FTRACE_WITH_REGS
 +
  config 64BIT
        def_bool y
  
@@@ -262,31 -253,31 +262,31 @@@ config ARM64_CONT_PMD_SHIF
        default 4
  
  config ARCH_MMAP_RND_BITS_MIN
-        default 14 if ARM64_64K_PAGES
-        default 16 if ARM64_16K_PAGES
-        default 18
+       default 14 if ARM64_64K_PAGES
+       default 16 if ARM64_16K_PAGES
+       default 18
  
  # max bits determined by the following formula:
  #  VA_BITS - PAGE_SHIFT - 3
  config ARCH_MMAP_RND_BITS_MAX
-        default 19 if ARM64_VA_BITS=36
-        default 24 if ARM64_VA_BITS=39
-        default 27 if ARM64_VA_BITS=42
-        default 30 if ARM64_VA_BITS=47
-        default 29 if ARM64_VA_BITS=48 && ARM64_64K_PAGES
-        default 31 if ARM64_VA_BITS=48 && ARM64_16K_PAGES
-        default 33 if ARM64_VA_BITS=48
-        default 14 if ARM64_64K_PAGES
-        default 16 if ARM64_16K_PAGES
-        default 18
+       default 19 if ARM64_VA_BITS=36
+       default 24 if ARM64_VA_BITS=39
+       default 27 if ARM64_VA_BITS=42
+       default 30 if ARM64_VA_BITS=47
+       default 29 if ARM64_VA_BITS=48 && ARM64_64K_PAGES
+       default 31 if ARM64_VA_BITS=48 && ARM64_16K_PAGES
+       default 33 if ARM64_VA_BITS=48
+       default 14 if ARM64_64K_PAGES
+       default 16 if ARM64_16K_PAGES
+       default 18
  
  config ARCH_MMAP_RND_COMPAT_BITS_MIN
-        default 7 if ARM64_64K_PAGES
-        default 9 if ARM64_16K_PAGES
-        default 11
+       default 7 if ARM64_64K_PAGES
+       default 9 if ARM64_16K_PAGES
+       default 11
  
  config ARCH_MMAP_RND_COMPAT_BITS_MAX
-        default 16
+       default 16
  
  config NO_IOPORT_MAP
        def_bool y if !PCI
@@@ -313,7 -304,7 +313,7 @@@ config GENERIC_HWEIGH
        def_bool y
  
  config GENERIC_CSUM
-         def_bool y
+       def_bool y
  
  config GENERIC_CALIBRATE_DELAY
        def_bool y
@@@ -687,7 -678,7 +687,7 @@@ config ARM64_ERRATUM_205167
        default y
        help
          This options adds the workaround for ARM Cortex-A510 erratum ARM64_ERRATUM_2051678.
 -        Affected Coretex-A510 might not respect the ordering rules for
 +        Affected Cortex-A510 might not respect the ordering rules for
          hardware update of the page table's dirty bit. The workaround
          is to not enable the feature on affected CPUs.
  
@@@ -1046,8 -1037,7 +1046,7 @@@ config SOCIONEXT_SYNQUACER_PREIT
  
          If unsure, say Y.
  
- endmenu
+ endmenu # "ARM errata workarounds via the alternatives framework"
  
  choice
        prompt "Page size"
@@@ -1575,9 -1565,9 +1574,9 @@@ config SETEND_EMULATIO
          be unexpected results in the applications.
  
          If unsure, say Y
- endif
+ endif # ARMV8_DEPRECATED
  
- endif
+ endif # COMPAT
  
  menu "ARMv8.1 architectural features"
  
@@@ -1602,15 -1592,15 +1601,15 @@@ config ARM64_PA
        bool "Enable support for Privileged Access Never (PAN)"
        default y
        help
-        Privileged Access Never (PAN; part of the ARMv8.1 Extensions)
-        prevents the kernel or hypervisor from accessing user-space (EL0)
-        memory directly.
+         Privileged Access Never (PAN; part of the ARMv8.1 Extensions)
+         prevents the kernel or hypervisor from accessing user-space (EL0)
+         memory directly.
  
-        Choosing this option will cause any unprotected (not using
-        copy_to_user et al) memory access to fail with a permission fault.
+         Choosing this option will cause any unprotected (not using
+         copy_to_user et al) memory access to fail with a permission fault.
  
-        The feature is detected at runtime, and will remain as a 'nop'
-        instruction if the cpu does not implement the feature.
+         The feature is detected at runtime, and will remain as a 'nop'
+         instruction if the cpu does not implement the feature.
  
  config AS_HAS_LDAPR
        def_bool $(as-instr,.arch_extension rcpc)
@@@ -1638,15 -1628,15 +1637,15 @@@ config ARM64_USE_LSE_ATOMIC
          built with binutils >= 2.25 in order for the new instructions
          to be used.
  
- endmenu
+ endmenu # "ARMv8.1 architectural features"
  
  menu "ARMv8.2 architectural features"
  
  config AS_HAS_ARMV8_2
-        def_bool $(cc-option,-Wa$(comma)-march=armv8.2-a)
+       def_bool $(cc-option,-Wa$(comma)-march=armv8.2-a)
  
  config AS_HAS_SHA3
-        def_bool $(as-instr,.arch armv8.2-a+sha3)
+       def_bool $(as-instr,.arch armv8.2-a+sha3)
  
  config ARM64_PMEM
        bool "Enable support for persistent memory"
@@@ -1690,7 -1680,7 +1689,7 @@@ config ARM64_CN
          at runtime, and does not affect PEs that do not implement
          this feature.
  
- endmenu
+ endmenu # "ARMv8.2 architectural features"
  
  menu "ARMv8.3 architectural features"
  
@@@ -1753,7 -1743,7 +1752,7 @@@ config AS_HAS_PA
  config AS_HAS_CFI_NEGATE_RA_STATE
        def_bool $(as-instr,.cfi_startproc\n.cfi_negate_ra_state\n.cfi_endproc\n)
  
- endmenu
+ endmenu # "ARMv8.3 architectural features"
  
  menu "ARMv8.4 architectural features"
  
@@@ -1794,7 -1784,7 +1793,7 @@@ config ARM64_TLB_RANG
          The feature introduces new assembly instructions, and they were
          support when binutils >= 2.30.
  
- endmenu
+ endmenu # "ARMv8.4 architectural features"
  
  menu "ARMv8.5 architectural features"
  
@@@ -1880,6 -1870,7 +1879,7 @@@ config ARM64_MT
        depends on AS_HAS_LSE_ATOMICS
        # Required for tag checking in the uaccess routines
        depends on ARM64_PAN
+       select ARCH_HAS_SUBPAGE_FAULTS
        select ARCH_USES_HIGH_VMA_FLAGS
        help
          Memory Tagging (part of the ARMv8.5 Extensions) provides
  
          Documentation/arm64/memory-tagging-extension.rst.
  
- endmenu
+ endmenu # "ARMv8.5 architectural features"
  
  menu "ARMv8.7 architectural features"
  
@@@ -1910,12 -1901,12 +1910,12 @@@ config ARM64_EPA
        default y
        depends on ARM64_PAN
        help
-        Enhanced Privileged Access Never (EPAN) allows Privileged
-        Access Never to be used with Execute-only mappings.
+         Enhanced Privileged Access Never (EPAN) allows Privileged
+         Access Never to be used with Execute-only mappings.
  
-        The feature is detected at runtime, and will remain disabled
-        if the cpu does not implement the feature.
- endmenu
+         The feature is detected at runtime, and will remain disabled
+         if the cpu does not implement the feature.
+ endmenu # "ARMv8.7 architectural features"
  
  config ARM64_SVE
        bool "ARM Scalable Vector Extension support"
          booting the kernel.  If unsure and you are not observing these
          symptoms, you should assume that it is safe to say Y.
  
+ config ARM64_SME
+       bool "ARM Scalable Matrix Extension support"
+       default y
+       depends on ARM64_SVE
+       help
+         The Scalable Matrix Extension (SME) is an extension to the AArch64
+         execution state which utilises a substantial subset of the SVE
+         instruction set, together with the addition of new architectural
+         register state capable of holding two dimensional matrix tiles to
+         enable various matrix operations.
  config ARM64_MODULE_PLTS
        bool "Use PLTs to allow module memory to spill over into vmalloc area"
        depends on MODULES
@@@ -1991,7 -1993,7 +2002,7 @@@ config ARM64_DEBUG_PRIORITY_MASKIN
          the validity of ICC_PMR_EL1 when calling concerned functions.
  
          If unsure, say N
- endif
+ endif # ARM64_PSEUDO_NMI
  
  config RELOCATABLE
        bool "Build a relocatable kernel image" if EXPERT
@@@ -2050,7 -2052,19 +2061,19 @@@ config STACKPROTECTOR_PER_TAS
        def_bool y
        depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_SYSREG
  
- endmenu
+ # The GPIO number here must be sorted by descending number. In case of
+ # a multiplatform kernel, we just want the highest value required by the
+ # selected platforms.
+ config ARCH_NR_GPIO
+         int
+         default 2048 if ARCH_APPLE
+         default 0
+         help
+           Maximum number of GPIOs in the system.
+           If unsure, leave the default value.
+ endmenu # "Kernel Features"
  
  menu "Boot options"
  
@@@ -2114,7 -2128,7 +2137,7 @@@ config EF
        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
+         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.
  
@@@ -2129,7 -2143,7 +2152,7 @@@ config DM
          However, even with this option, the resultant kernel should
          continue to boot on existing non-UEFI platforms.
  
- endmenu
+ endmenu # "Boot options"
  
  config SYSVIPC_COMPAT
        def_bool y
@@@ -2150,7 -2164,7 +2173,7 @@@ config ARCH_HIBERNATION_HEADE
  config ARCH_SUSPEND_POSSIBLE
        def_bool y
  
- endmenu
+ endmenu # "Power management options"
  
  menu "CPU Power Management"
  
@@@ -2158,7 -2172,7 +2181,7 @@@ source "drivers/cpuidle/Kconfig
  
  source "drivers/cpufreq/Kconfig"
  
- endmenu
+ endmenu # "CPU Power Management"
  
  source "drivers/acpi/Kconfig"
  
@@@ -2166,4 -2180,4 +2189,4 @@@ source "arch/arm64/kvm/Kconfig
  
  if CRYPTO
  source "arch/arm64/crypto/Kconfig"
- endif
+ endif # CRYPTO
@@@ -11,11 -11,12 +11,11 @@@ config ARCH_ACTION
  config ARCH_SUNXI
        bool "Allwinner sunxi 64-bit SoC Family"
        select ARCH_HAS_RESET_CONTROLLER
 -      select GENERIC_IRQ_CHIP
 -      select IRQ_DOMAIN_HIERARCHY
 -      select IRQ_FASTEOI_HIERARCHY_HANDLERS
        select PINCTRL
        select RESET_CONTROLLER
        select SUN4I_TIMER
 +      select SUN6I_R_INTC
 +      select SUNXI_NMI_INTC
        help
          This enables support for Allwinner sunxi based SoCs like the A64.
  
@@@ -252,7 -253,6 +252,7 @@@ config ARCH_INTEL_SOCFPG
  
  config ARCH_SYNQUACER
        bool "Socionext SynQuacer SoC Family"
 +      select IRQ_FASTEOI_HIERARCHY_HANDLERS
  
  config ARCH_TEGRA
        bool "NVIDIA Tegra SoC Family"
@@@ -325,4 -325,4 +325,4 @@@ config ARCH_ZYNQM
        help
          This enables support for Xilinx ZynqMP Family
  
- endmenu
+ endmenu # "Platform selection"
@@@ -40,7 -40,6 +40,7 @@@ void kvm_inject_undefined(struct kvm_vc
  void kvm_inject_vabt(struct kvm_vcpu *vcpu);
  void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
  void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
 +void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
  
  void kvm_vcpu_wfi(struct kvm_vcpu *vcpu);
  
@@@ -236,14 -235,14 +236,14 @@@ static inline bool vcpu_mode_priv(cons
        return mode != PSR_MODE_EL0t;
  }
  
- static __always_inline u32 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
+ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
  {
        return vcpu->arch.fault.esr_el2;
  }
  
  static __always_inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu)
  {
-       u32 esr = kvm_vcpu_get_esr(vcpu);
+       u64 esr = kvm_vcpu_get_esr(vcpu);
  
        if (esr & ESR_ELx_CV)
                return (esr & ESR_ELx_COND_MASK) >> ESR_ELx_COND_SHIFT;
@@@ -374,7 -373,7 +374,7 @@@ static __always_inline bool kvm_vcpu_ab
  
  static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
  {
-       u32 esr = kvm_vcpu_get_esr(vcpu);
+       u64 esr = kvm_vcpu_get_esr(vcpu);
        return ESR_ELx_SYS64_ISS_RT(esr);
  }
  
@@@ -535,7 -535,7 +535,7 @@@ extern pgprot_t phys_mem_access_prot(st
                                 PMD_TYPE_TABLE)
  #define pmd_sect(pmd)         ((pmd_val(pmd) & PMD_TYPE_MASK) == \
                                 PMD_TYPE_SECT)
 -#define pmd_leaf(pmd)         pmd_sect(pmd)
 +#define pmd_leaf(pmd)         (pmd_present(pmd) && !pmd_table(pmd))
  #define pmd_bad(pmd)          (!pmd_table(pmd))
  
  #define pmd_leaf_size(pmd)    (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE)
@@@ -625,7 -625,7 +625,7 @@@ static inline unsigned long pmd_page_va
  #define pud_none(pud)         (!pud_val(pud))
  #define pud_bad(pud)          (!pud_table(pud))
  #define pud_present(pud)      pte_present(pud_pte(pud))
 -#define pud_leaf(pud)         pud_sect(pud)
 +#define pud_leaf(pud)         (pud_present(pud) && !pud_table(pud))
  #define pud_valid(pud)                pte_valid(pud_pte(pud))
  
  static inline void set_pud(pud_t *pudp, pud_t pud)
@@@ -1001,7 -1001,8 +1001,8 @@@ static inline void update_mmu_cache(str
   */
  static inline bool arch_faults_on_old_pte(void)
  {
-       WARN_ON(preemptible());
+       /* The register read below requires a stable CPU to make any sense */
+       cant_migrate();
  
        return !cpu_has_hw_af();
  }
@@@ -208,8 -208,6 +208,8 @@@ static const struct arm64_cpu_capabilit
  #ifdef CONFIG_ARM64_ERRATUM_1286807
        {
                ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0),
 +              /* Kryo4xx Gold (rcpe to rfpe) => (r0p0 to r3p0) */
 +              ERRATA_MIDR_RANGE(MIDR_QCOM_KRYO_4XX_GOLD, 0xc, 0xe, 0xf, 0xe),
        },
  #endif
        {},
  #endif
  
  #ifdef CONFIG_CAVIUM_ERRATUM_23154
- const struct midr_range cavium_erratum_23154_cpus[] = {
static const struct midr_range cavium_erratum_23154_cpus[] = {
        MIDR_ALL_VERSIONS(MIDR_THUNDERX),
        MIDR_ALL_VERSIONS(MIDR_THUNDERX_81XX),
        MIDR_ALL_VERSIONS(MIDR_THUNDERX_83XX),
@@@ -191,20 -191,20 +191,20 @@@ static bool __system_matches_cap(unsign
   * sync with the documentation of the CPU feature register ABI.
   */
  static const struct arm64_ftr_bits ftr_id_aa64isar0[] = {
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_RNDR_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_TLB_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_TS_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_FHM_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_DP_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SM4_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SM3_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA3_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_RDM_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_ATOMICS_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_CRC32_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA2_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA1_SHIFT, 4, 0),
-       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_AES_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_RNDR_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_TLB_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_TS_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_FHM_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_DP_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_SM4_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_SM3_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_SHA3_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_RDM_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_ATOMIC_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_CRC32_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_SHA2_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_SHA1_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_EL1_AES_SHIFT, 4, 0),
        ARM64_FTR_END,
  };
  
@@@ -261,6 -261,8 +261,8 @@@ static const struct arm64_ftr_bits ftr_
  };
  
  static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SME_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_MPAMFRAC_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_RASFRAC_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_MTE),
@@@ -293,6 -295,24 +295,24 @@@ static const struct arm64_ftr_bits ftr_
        ARM64_FTR_END,
  };
  
+ static const struct arm64_ftr_bits ftr_id_aa64smfr0[] = {
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_FA64_SHIFT, 1, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_I16I64_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_F64F64_SHIFT, 1, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_I8I32_SHIFT, 4, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_F16F32_SHIFT, 1, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_B16F32_SHIFT, 1, 0),
+       ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SME),
+                      FTR_STRICT, FTR_EXACT, ID_AA64SMFR0_F32F32_SHIFT, 1, 0),
+       ARM64_FTR_END,
+ };
  static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = {
        ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_ECV_SHIFT, 4, 0),
        ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_FGT_SHIFT, 4, 0),
@@@ -557,7 -577,13 +577,13 @@@ static const struct arm64_ftr_bits ftr_
  
  static const struct arm64_ftr_bits ftr_zcr[] = {
        ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE,
-               ZCR_ELx_LEN_SHIFT, ZCR_ELx_LEN_SIZE, 0),        /* LEN */
+               ZCR_ELx_LEN_SHIFT, ZCR_ELx_LEN_WIDTH, 0),       /* LEN */
+       ARM64_FTR_END,
+ };
+ static const struct arm64_ftr_bits ftr_smcr[] = {
+       ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE,
+               SMCR_ELx_LEN_SHIFT, SMCR_ELx_LEN_WIDTH, 0),     /* LEN */
        ARM64_FTR_END,
  };
  
@@@ -645,6 -671,7 +671,7 @@@ static const struct __ftr_reg_entry 
        ARM64_FTR_REG_OVERRIDE(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1,
                               &id_aa64pfr1_override),
        ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0),
+       ARM64_FTR_REG(SYS_ID_AA64SMFR0_EL1, ftr_id_aa64smfr0),
  
        /* Op1 = 0, CRn = 0, CRm = 5 */
        ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0),
        ARM64_FTR_REG(SYS_ID_AA64ISAR0_EL1, ftr_id_aa64isar0),
        ARM64_FTR_REG_OVERRIDE(SYS_ID_AA64ISAR1_EL1, ftr_id_aa64isar1,
                               &id_aa64isar1_override),
 -      ARM64_FTR_REG(SYS_ID_AA64ISAR2_EL1, ftr_id_aa64isar2),
        ARM64_FTR_REG_OVERRIDE(SYS_ID_AA64ISAR2_EL1, ftr_id_aa64isar2,
                               &id_aa64isar2_override),
  
  
        /* Op1 = 0, CRn = 1, CRm = 2 */
        ARM64_FTR_REG(SYS_ZCR_EL1, ftr_zcr),
+       ARM64_FTR_REG(SYS_SMCR_EL1, ftr_smcr),
  
        /* Op1 = 1, CRn = 0, CRm = 0 */
        ARM64_FTR_REG(SYS_GMID_EL1, ftr_gmid),
@@@ -809,7 -838,7 +837,7 @@@ static void __init sort_ftr_regs(void
                 * to sys_id for subsequent binary search in get_arm64_ftr_reg()
                 * to work correctly.
                 */
 -              BUG_ON(arm64_ftr_regs[i].sys_id < arm64_ftr_regs[i - 1].sys_id);
 +              BUG_ON(arm64_ftr_regs[i].sys_id <= arm64_ftr_regs[i - 1].sys_id);
        }
  }
  
@@@ -959,6 -988,7 +987,7 @@@ void __init init_cpu_features(struct cp
        init_cpu_ftr_reg(SYS_ID_AA64PFR0_EL1, info->reg_id_aa64pfr0);
        init_cpu_ftr_reg(SYS_ID_AA64PFR1_EL1, info->reg_id_aa64pfr1);
        init_cpu_ftr_reg(SYS_ID_AA64ZFR0_EL1, info->reg_id_aa64zfr0);
+       init_cpu_ftr_reg(SYS_ID_AA64SMFR0_EL1, info->reg_id_aa64smfr0);
  
        if (id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0))
                init_32bit_cpu_features(&info->aarch32);
                vec_init_vq_map(ARM64_VEC_SVE);
        }
  
+       if (id_aa64pfr1_sme(info->reg_id_aa64pfr1)) {
+               init_cpu_ftr_reg(SYS_SMCR_EL1, info->reg_smcr);
+               if (IS_ENABLED(CONFIG_ARM64_SME))
+                       vec_init_vq_map(ARM64_VEC_SME);
+       }
        if (id_aa64pfr1_mte(info->reg_id_aa64pfr1))
                init_cpu_ftr_reg(SYS_GMID_EL1, info->reg_gmid);
  
@@@ -1194,6 -1230,9 +1229,9 @@@ void update_cpu_features(int cpu
        taint |= check_update_ftr_reg(SYS_ID_AA64ZFR0_EL1, cpu,
                                      info->reg_id_aa64zfr0, boot->reg_id_aa64zfr0);
  
+       taint |= check_update_ftr_reg(SYS_ID_AA64SMFR0_EL1, cpu,
+                                     info->reg_id_aa64smfr0, boot->reg_id_aa64smfr0);
        if (id_aa64pfr0_sve(info->reg_id_aa64pfr0)) {
                taint |= check_update_ftr_reg(SYS_ZCR_EL1, cpu,
                                        info->reg_zcr, boot->reg_zcr);
                        vec_update_vq_map(ARM64_VEC_SVE);
        }
  
+       if (id_aa64pfr1_sme(info->reg_id_aa64pfr1)) {
+               taint |= check_update_ftr_reg(SYS_SMCR_EL1, cpu,
+                                       info->reg_smcr, boot->reg_smcr);
+               /* Probe vector lengths, unless we already gave up on SME */
+               if (id_aa64pfr1_sme(read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1)) &&
+                   !system_capabilities_finalized())
+                       vec_update_vq_map(ARM64_VEC_SME);
+       }
        /*
         * The kernel uses the LDGM/STGM instructions and the number of tags
         * they read/write depends on the GMID_EL1.BS field. Check that the
@@@ -1287,6 -1336,7 +1335,7 @@@ u64 __read_sysreg_by_encoding(u32 sys_i
        read_sysreg_case(SYS_ID_AA64PFR0_EL1);
        read_sysreg_case(SYS_ID_AA64PFR1_EL1);
        read_sysreg_case(SYS_ID_AA64ZFR0_EL1);
+       read_sysreg_case(SYS_ID_AA64SMFR0_EL1);
        read_sysreg_case(SYS_ID_AA64DFR0_EL1);
        read_sysreg_case(SYS_ID_AA64DFR1_EL1);
        read_sysreg_case(SYS_ID_AA64MMFR0_EL1);
@@@ -2012,7 -2062,7 +2061,7 @@@ static const struct arm64_cpu_capabilit
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,
                .matches = has_cpuid_feature,
                .sys_reg = SYS_ID_AA64ISAR0_EL1,
-               .field_pos = ID_AA64ISAR0_ATOMICS_SHIFT,
+               .field_pos = ID_AA64ISAR0_EL1_ATOMIC_SHIFT,
                .field_width = 4,
                .sign = FTR_UNSIGNED,
                .min_field_value = 2,
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,
                .matches = has_cpuid_feature,
                .sys_reg = SYS_ID_AA64ISAR0_EL1,
-               .field_pos = ID_AA64ISAR0_TLB_SHIFT,
+               .field_pos = ID_AA64ISAR0_EL1_TLB_SHIFT,
                .field_width = 4,
                .sign = FTR_UNSIGNED,
-               .min_field_value = ID_AA64ISAR0_TLB_RANGE,
+               .min_field_value = ID_AA64ISAR0_EL1_TLB_RANGE,
        },
  #ifdef CONFIG_ARM64_HW_AFDBM
        {
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,
                .matches = has_cpuid_feature,
                .sys_reg = SYS_ID_AA64ISAR0_EL1,
-               .field_pos = ID_AA64ISAR0_CRC32_SHIFT,
+               .field_pos = ID_AA64ISAR0_EL1_CRC32_SHIFT,
                .field_width = 4,
                .min_field_value = 1,
        },
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,
                .matches = has_cpuid_feature,
                .sys_reg = SYS_ID_AA64ISAR0_EL1,
-               .field_pos = ID_AA64ISAR0_RNDR_SHIFT,
+               .field_pos = ID_AA64ISAR0_EL1_RNDR_SHIFT,
                .field_width = 4,
                .sign = FTR_UNSIGNED,
                .min_field_value = 1,
                .matches = has_cpuid_feature,
                .min_field_value = 1,
        },
+ #ifdef CONFIG_ARM64_SME
+       {
+               .desc = "Scalable Matrix Extension",
+               .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+               .capability = ARM64_SME,
+               .sys_reg = SYS_ID_AA64PFR1_EL1,
+               .sign = FTR_UNSIGNED,
+               .field_pos = ID_AA64PFR1_SME_SHIFT,
+               .field_width = 4,
+               .min_field_value = ID_AA64PFR1_SME,
+               .matches = has_cpuid_feature,
+               .cpu_enable = sme_kernel_enable,
+       },
+       /* FA64 should be sorted after the base SME capability */
+       {
+               .desc = "FA64",
+               .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+               .capability = ARM64_SME_FA64,
+               .sys_reg = SYS_ID_AA64SMFR0_EL1,
+               .sign = FTR_UNSIGNED,
+               .field_pos = ID_AA64SMFR0_FA64_SHIFT,
+               .field_width = 1,
+               .min_field_value = ID_AA64SMFR0_FA64,
+               .matches = has_cpuid_feature,
+               .cpu_enable = fa64_kernel_enable,
+       },
+ #endif /* CONFIG_ARM64_SME */
        {},
  };
  
@@@ -2513,22 -2590,22 +2589,22 @@@ static const struct arm64_cpu_capabilit
  #endif
  
  static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = {
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_PMULL),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_AES),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA1),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA2),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_SHA512),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_CRC32),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ATOMICS),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RDM_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDRDM),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA3_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA3),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM3_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM3),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM4_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM4),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_DP_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDDP),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_FHM_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDFHM),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FLAGM),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_FLAGM2),
-       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RNDR_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_RNG),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_AES_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_PMULL),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_AES_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_AES),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SHA1_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA1),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SHA2_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA2),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SHA2_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_SHA512),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_CRC32_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_CRC32),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_ATOMIC_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ATOMICS),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_RDM_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDRDM),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SHA3_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA3),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SM3_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM3),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_SM4_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM4),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_DP_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDDP),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_FHM_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDFHM),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_TS_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FLAGM),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_TS_SHIFT, 4, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_FLAGM2),
+       HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_RNDR_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_RNG),
        HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, 4, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_FP),
        HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, 4, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FPHP),
        HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, 4, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_ASIMD),
        HWCAP_CAP(SYS_ID_AA64MMFR0_EL1, ID_AA64MMFR0_ECV_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ECV),
        HWCAP_CAP(SYS_ID_AA64MMFR1_EL1, ID_AA64MMFR1_AFP_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_AFP),
        HWCAP_CAP(SYS_ID_AA64ISAR2_EL1, ID_AA64ISAR2_RPRES_SHIFT, 4, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_RPRES),
+ #ifdef CONFIG_ARM64_SME
+       HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SME_SHIFT, 4, FTR_UNSIGNED, ID_AA64PFR1_SME, CAP_HWCAP, KERNEL_HWCAP_SME),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_FA64_SHIFT, 1, FTR_UNSIGNED, ID_AA64SMFR0_FA64, CAP_HWCAP, KERNEL_HWCAP_SME_FA64),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_I16I64_SHIFT, 4, FTR_UNSIGNED, ID_AA64SMFR0_I16I64, CAP_HWCAP, KERNEL_HWCAP_SME_I16I64),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_F64F64_SHIFT, 1, FTR_UNSIGNED, ID_AA64SMFR0_F64F64, CAP_HWCAP, KERNEL_HWCAP_SME_F64F64),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_I8I32_SHIFT, 4, FTR_UNSIGNED, ID_AA64SMFR0_I8I32, CAP_HWCAP, KERNEL_HWCAP_SME_I8I32),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_F16F32_SHIFT, 1, FTR_UNSIGNED, ID_AA64SMFR0_F16F32, CAP_HWCAP, KERNEL_HWCAP_SME_F16F32),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_B16F32_SHIFT, 1, FTR_UNSIGNED, ID_AA64SMFR0_B16F32, CAP_HWCAP, KERNEL_HWCAP_SME_B16F32),
+       HWCAP_CAP(SYS_ID_AA64SMFR0_EL1, ID_AA64SMFR0_F32F32_SHIFT, 1, FTR_UNSIGNED, ID_AA64SMFR0_F32F32, CAP_HWCAP, KERNEL_HWCAP_SME_F32F32),
+ #endif /* CONFIG_ARM64_SME */
        {},
  };
  
@@@ -2871,6 -2958,23 +2957,23 @@@ static void verify_sve_features(void
        /* Add checks on other ZCR bits here if necessary */
  }
  
+ static void verify_sme_features(void)
+ {
+       u64 safe_smcr = read_sanitised_ftr_reg(SYS_SMCR_EL1);
+       u64 smcr = read_smcr_features();
+       unsigned int safe_len = safe_smcr & SMCR_ELx_LEN_MASK;
+       unsigned int len = smcr & SMCR_ELx_LEN_MASK;
+       if (len < safe_len || vec_verify_vq_map(ARM64_VEC_SME)) {
+               pr_crit("CPU%d: SME: vector length support mismatch\n",
+                       smp_processor_id());
+               cpu_die_early();
+       }
+       /* Add checks on other SMCR bits here if necessary */
+ }
  static void verify_hyp_capabilities(void)
  {
        u64 safe_mmfr1, mmfr0, mmfr1;
@@@ -2923,6 -3027,9 +3026,9 @@@ static void verify_local_cpu_capabiliti
        if (system_supports_sve())
                verify_sve_features();
  
+       if (system_supports_sme())
+               verify_sme_features();
        if (is_hyp_mode_available())
                verify_hyp_capabilities();
  }
@@@ -3040,6 -3147,7 +3146,7 @@@ void __init setup_cpu_features(void
                pr_info("emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching\n");
  
        sve_setup();
+       sme_setup();
        minsigstksz_setup();
  
        /* Advertise that we have computed the system capabilities */
diff --combined arch/arm64/kernel/mte.c
@@@ -15,6 -15,7 +15,7 @@@
  #include <linux/swapops.h>
  #include <linux/thread_info.h>
  #include <linux/types.h>
+ #include <linux/uaccess.h>
  #include <linux/uio.h>
  
  #include <asm/barrier.h>
@@@ -76,9 -77,6 +77,9 @@@ void mte_sync_tags(pte_t old_pte, pte_
                        mte_sync_page_tags(page, old_pte, check_swap,
                                           pte_is_tagged);
        }
 +
 +      /* ensure the tags are visible before the PTE is set */
 +      smp_wmb();
  }
  
  int memcmp_pages(struct page *page1, struct page *page2)
  static inline void __mte_enable_kernel(const char *mode, unsigned long tcf)
  {
        /* Enable MTE Sync Mode for EL1. */
-       sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, tcf);
+       sysreg_clear_set(sctlr_el1, SCTLR_EL1_TCF_MASK,
+                        SYS_FIELD_PREP(SCTLR_EL1, TCF, tcf));
        isb();
  
        pr_info_once("MTE: enabled in %s mode at EL1\n", mode);
@@@ -125,12 -124,12 +127,12 @@@ void mte_enable_kernel_sync(void
        WARN_ONCE(system_uses_mte_async_or_asymm_mode(),
                        "MTE async mode enabled system wide!");
  
-       __mte_enable_kernel("synchronous", SCTLR_ELx_TCF_SYNC);
+       __mte_enable_kernel("synchronous", SCTLR_EL1_TCF_SYNC);
  }
  
  void mte_enable_kernel_async(void)
  {
-       __mte_enable_kernel("asynchronous", SCTLR_ELx_TCF_ASYNC);
+       __mte_enable_kernel("asynchronous", SCTLR_EL1_TCF_ASYNC);
  
        /*
         * MTE async mode is set system wide by the first PE that
  void mte_enable_kernel_asymm(void)
  {
        if (cpus_have_cap(ARM64_MTE_ASYMM)) {
-               __mte_enable_kernel("asymmetric", SCTLR_ELx_TCF_ASYMM);
+               __mte_enable_kernel("asymmetric", SCTLR_EL1_TCF_ASYMM);
  
                /*
                 * MTE asymm mode behaves as async mode for store
@@@ -219,11 -218,11 +221,11 @@@ static void mte_update_sctlr_user(struc
         * default order.
         */
        if (resolved_mte_tcf & MTE_CTRL_TCF_ASYMM)
-               sctlr |= SCTLR_EL1_TCF0_ASYMM;
+               sctlr |= SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF0, ASYMM);
        else if (resolved_mte_tcf & MTE_CTRL_TCF_ASYNC)
-               sctlr |= SCTLR_EL1_TCF0_ASYNC;
+               sctlr |= SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF0, ASYNC);
        else if (resolved_mte_tcf & MTE_CTRL_TCF_SYNC)
-               sctlr |= SCTLR_EL1_TCF0_SYNC;
+               sctlr |= SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF0, SYNC);
        task->thread.sctlr_user = sctlr;
  }
  
@@@ -546,3 -545,32 +548,32 @@@ static int register_mte_tcf_preferred_s
        return 0;
  }
  subsys_initcall(register_mte_tcf_preferred_sysctl);
+ /*
+  * Return 0 on success, the number of bytes not probed otherwise.
+  */
+ size_t mte_probe_user_range(const char __user *uaddr, size_t size)
+ {
+       const char __user *end = uaddr + size;
+       int err = 0;
+       char val;
+       __raw_get_user(val, uaddr, err);
+       if (err)
+               return size;
+       uaddr = PTR_ALIGN(uaddr, MTE_GRANULE_SIZE);
+       while (uaddr < end) {
+               /*
+                * A read is sufficient for mte, the caller should have probed
+                * for the pte write permission if required.
+                */
+               __raw_get_user(val, uaddr, err);
+               if (err)
+                       return end - uaddr;
+               uaddr += MTE_GRANULE_SIZE;
+       }
+       (void)val;
+       return 0;
+ }
diff --combined arch/arm64/kvm/arm.c
@@@ -783,6 -783,7 +783,7 @@@ int kvm_arch_vcpu_ioctl_run(struct kvm_
  
        ret = 1;
        run->exit_reason = KVM_EXIT_UNKNOWN;
+       run->flags = 0;
        while (ret > 0) {
                /*
                 * Check conditions before entering the guest
@@@ -1436,8 -1437,7 +1437,8 @@@ static int kvm_init_vector_slots(void
        base = kern_hyp_va(kvm_ksym_ref(__bp_harden_hyp_vecs));
        kvm_init_vector_slot(base, HYP_VECTOR_SPECTRE_DIRECT);
  
 -      if (kvm_system_needs_idmapped_vectors() && !has_vhe()) {
 +      if (kvm_system_needs_idmapped_vectors() &&
 +          !is_protected_kvm_enabled()) {
                err = create_hyp_exec_mappings(__pa_symbol(__bp_harden_hyp_vecs),
                                               __BP_HARDEN_HYP_VECS_SZ, &base);
                if (err)
@@@ -18,7 -18,7 +18,7 @@@ static void inject_abt64(struct kvm_vcp
  {
        unsigned long cpsr = *vcpu_cpsr(vcpu);
        bool is_aarch32 = vcpu_mode_is_32bit(vcpu);
-       u32 esr = 0;
+       u64 esr = 0;
  
        vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1          |
                             KVM_ARM64_EXCEPT_AA64_ELx_SYNC     |
@@@ -50,7 -50,7 +50,7 @@@
  
  static void inject_undef64(struct kvm_vcpu *vcpu)
  {
-       u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
+       u64 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
  
        vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1          |
                             KVM_ARM64_EXCEPT_AA64_ELx_SYNC     |
@@@ -145,34 -145,6 +145,34 @@@ void kvm_inject_pabt(struct kvm_vcpu *v
                inject_abt64(vcpu, true, addr);
  }
  
 +void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
 +{
 +      unsigned long addr, esr;
 +
 +      addr  = kvm_vcpu_get_fault_ipa(vcpu);
 +      addr |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
 +
 +      if (kvm_vcpu_trap_is_iabt(vcpu))
 +              kvm_inject_pabt(vcpu, addr);
 +      else
 +              kvm_inject_dabt(vcpu, addr);
 +
 +      /*
 +       * If AArch64 or LPAE, set FSC to 0 to indicate an Address
 +       * Size Fault at level 0, as if exceeding PARange.
 +       *
 +       * Non-LPAE guests will only get the external abort, as there
 +       * is no way to to describe the ASF.
 +       */
 +      if (vcpu_el1_is_32bit(vcpu) &&
 +          !(vcpu_read_sys_reg(vcpu, TCR_EL1) & TTBCR_EAE))
 +              return;
 +
 +      esr = vcpu_read_sys_reg(vcpu, ESR_EL1);
 +      esr &= ~GENMASK_ULL(5, 0);
 +      vcpu_write_sys_reg(vcpu, esr, ESR_EL1);
 +}
 +
  /**
   * kvm_inject_undefined - inject an undefined instruction into the guest
   * @vcpu: The vCPU in which to inject the exception
@@@ -1123,7 -1123,8 +1123,7 @@@ static u64 read_id_reg(const struct kvm
                val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_CSV2), (u64)vcpu->kvm->arch.pfr0_csv2);
                val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_CSV3);
                val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_CSV3), (u64)vcpu->kvm->arch.pfr0_csv3);
 -              if (irqchip_in_kernel(vcpu->kvm) &&
 -                  vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
 +              if (kvm_vgic_global_state.type == VGIC_V3) {
                        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_GIC);
                        val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_GIC), 1);
                }
        case SYS_ID_AA64PFR1_EL1:
                if (!kvm_has_mte(vcpu->kvm))
                        val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_MTE);
+               val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_SME);
                break;
        case SYS_ID_AA64ISAR1_EL1:
                if (!vcpu_has_ptrauth(vcpu))
@@@ -1552,7 -1555,7 +1554,7 @@@ static const struct sys_reg_desc sys_re
        ID_UNALLOCATED(4,2),
        ID_UNALLOCATED(4,3),
        ID_SANITISED(ID_AA64ZFR0_EL1),
-       ID_UNALLOCATED(4,5),
+       ID_HIDDEN(ID_AA64SMFR0_EL1),
        ID_UNALLOCATED(4,6),
        ID_UNALLOCATED(4,7),
  
  
        { SYS_DESC(SYS_ZCR_EL1), NULL, reset_val, ZCR_EL1, 0, .visibility = sve_visibility },
        { SYS_DESC(SYS_TRFCR_EL1), undef_access },
+       { SYS_DESC(SYS_SMPRI_EL1), undef_access },
+       { SYS_DESC(SYS_SMCR_EL1), undef_access },
        { SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
        { SYS_DESC(SYS_TTBR1_EL1), access_vm_reg, reset_unknown, TTBR1_EL1 },
        { SYS_DESC(SYS_TCR_EL1), access_vm_reg, reset_val, TCR_EL1, 0 },
  
        { SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr },
        { SYS_DESC(SYS_CLIDR_EL1), access_clidr },
+       { SYS_DESC(SYS_SMIDR_EL1), undef_access },
        { SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 },
        { SYS_DESC(SYS_CTR_EL0), access_ctr },
+       { SYS_DESC(SYS_SVCR), undef_access },
  
        { PMU_SYS_REG(SYS_PMCR_EL0), .access = access_pmcr,
          .reset = reset_pmcr, .reg = PMCR_EL0 },
  
        { SYS_DESC(SYS_TPIDR_EL0), NULL, reset_unknown, TPIDR_EL0 },
        { SYS_DESC(SYS_TPIDRRO_EL0), NULL, reset_unknown, TPIDRRO_EL0 },
+       { SYS_DESC(SYS_TPIDR2_EL0), undef_access },
  
        { SYS_DESC(SYS_SCXTNUM_EL0), undef_access },
  
@@@ -2303,7 -2311,7 +2310,7 @@@ static int kvm_handle_cp_64(struct kvm_
                            size_t nr_global)
  {
        struct sys_reg_params params;
-       u32 esr = kvm_vcpu_get_esr(vcpu);
+       u64 esr = kvm_vcpu_get_esr(vcpu);
        int Rt = kvm_vcpu_sys_get_rt(vcpu);
        int Rt2 = (esr >> 10) & 0x1f;
  
@@@ -2353,7 -2361,7 +2360,7 @@@ static int kvm_handle_cp_32(struct kvm_
                            size_t nr_global)
  {
        struct sys_reg_params params;
-       u32 esr = kvm_vcpu_get_esr(vcpu);
+       u64 esr = kvm_vcpu_get_esr(vcpu);
        int Rt  = kvm_vcpu_sys_get_rt(vcpu);
  
        params.CRm = (esr >> 1) & 0xf;
diff --combined fs/btrfs/ioctl.c
@@@ -468,6 -468,7 +468,6 @@@ static noinline int btrfs_ioctl_fitrim(
                                        void __user *arg)
  {
        struct btrfs_device *device;
 -      struct request_queue *q;
        struct fstrim_range range;
        u64 minlen = ULLONG_MAX;
        u64 num_devices = 0;
        rcu_read_lock();
        list_for_each_entry_rcu(device, &fs_info->fs_devices->devices,
                                dev_list) {
 -              if (!device->bdev)
 +              if (!device->bdev || !bdev_max_discard_sectors(device->bdev))
                        continue;
 -              q = bdev_get_queue(device->bdev);
 -              if (blk_queue_discard(q)) {
 -                      num_devices++;
 -                      minlen = min_t(u64, q->limits.discard_granularity,
 -                                   minlen);
 -              }
 +              num_devices++;
 +              minlen = min_t(u64, bdev_discard_granularity(device->bdev),
 +                                  minlen);
        }
        rcu_read_unlock();
  
@@@ -2561,7 -2565,12 +2561,12 @@@ static noinline int search_ioctl(struc
  
        while (1) {
                ret = -EFAULT;
-               if (fault_in_writeable(ubuf + sk_offset, *buf_size - sk_offset))
+               /*
+                * Ensure that the whole user buffer is faulted in at sub-page
+                * granularity, otherwise the loop may live-lock.
+                */
+               if (fault_in_subpage_writeable(ubuf + sk_offset,
+                                              *buf_size - sk_offset))
                        break;
  
                ret = btrfs_search_forward(root, &key, path, sk->min_transid);
diff --combined include/uapi/linux/elf.h
@@@ -42,7 -42,7 +42,7 @@@ typedef __s64 Elf64_Sxword
  
  
  /* ARM MTE memory tag segment type */
 -#define PT_ARM_MEMTAG_MTE     (PT_LOPROC + 0x1)
 +#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2)
  
  /*
   * Extended Numbering
@@@ -431,6 -431,8 +431,8 @@@ typedef struct elf64_shdr 
  #define NT_ARM_PACG_KEYS      0x408   /* ARM pointer authentication generic key */
  #define NT_ARM_TAGGED_ADDR_CTRL       0x409   /* arm64 tagged address control (prctl()) */
  #define NT_ARM_PAC_ENABLED_KEYS       0x40a   /* arm64 ptr auth enabled keys (prctl()) */
+ #define NT_ARM_SSVE   0x40b           /* ARM Streaming SVE registers */
+ #define NT_ARM_ZA     0x40c           /* ARM SME ZA registers */
  #define NT_ARC_V2     0x600           /* ARCv2 accumulator/extra registers */
  #define NT_VMCOREDD   0x700           /* Vmcore Device Dump Note */
  #define NT_MIPS_DSP   0x800           /* MIPS DSP ASE registers */
diff --combined kernel/trace/fgraph.c
@@@ -30,6 -30,24 +30,24 @@@ int ftrace_graph_active
  /* Both enabled by default (can be cleared by function_graph tracer flags */
  static bool fgraph_sleep_time = true;
  
+ /*
+  * archs can override this function if they must do something
+  * to enable hook for graph tracer.
+  */
+ int __weak ftrace_enable_ftrace_graph_caller(void)
+ {
+       return 0;
+ }
+ /*
+  * archs can override this function if they must do something
+  * to disable hook for graph tracer.
+  */
+ int __weak ftrace_disable_ftrace_graph_caller(void)
+ {
+       return 0;
+ }
  /**
   * ftrace_graph_stop - set to permanently disable function graph tracing
   *
@@@ -404,9 -422,9 +422,9 @@@ free
  
  static void
  ftrace_graph_probe_sched_switch(void *ignore, bool preempt,
 -                              unsigned int prev_state,
                                struct task_struct *prev,
 -                              struct task_struct *next)
 +                              struct task_struct *next,
 +                              unsigned int prev_state)
  {
        unsigned long long timestamp;
        int index;