Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux

Pull arm64 updates from Will Deacon:
"Mostly just incremental improvements here:

- Introduce AT_HWCAP2 for advertising CPU features to userspace

- Expose SVE2 availability to userspace

- Support for "data cache clean to point of deep persistence" (DC PODP)

- Honour "mitigations=off" on the cmdline and advertise status via
sysfs

- CPU timer erratum workaround (Neoverse-N1 #1188873)

- Introduce perf PMU driver for the SMMUv3 performance counters

- Add config option to disable the kuser helpers page for AArch32 tasks

- Futex modifications to ensure liveness under contention

- Rework debug exception handling to seperate kernel and user
handlers

- Non-critical fixes and cleanup"

* tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (92 commits)
Documentation: Add ARM64 to kernel-parameters.rst
arm64/speculation: Support 'mitigations=' cmdline option
arm64: ssbs: Don't treat CPUs with SSBS as unaffected by SSB
arm64: enable generic CPU vulnerabilites support
arm64: add sysfs vulnerability show for speculative store bypass
arm64: Fix size of __early_cpu_boot_status
clocksource/arm_arch_timer: Use arch_timer_read_counter to access stable counters
clocksource/arm_arch_timer: Remove use of workaround static key
clocksource/arm_arch_timer: Drop use of static key in arch_timer_reg_read_stable
clocksource/arm_arch_timer: Direcly assign set_next_event workaround
arm64: Use arch_timer_read_counter instead of arch_counter_get_cntvct
watchdog/sbsa: Use arch_timer_read_counter instead of arch_counter_get_cntvct
ARM: vdso: Remove dependency with the arch_timer driver internals
arm64: Apply ARM64_ERRATUM_1188873 to Neoverse-N1
arm64: Add part number for Neoverse N1
arm64: Make ARM64_ERRATUM_1188873 depend on COMPAT
arm64: Restrict ARM64_ERRATUM_1188873 mitigation to AArch32
arm64: mm: Remove pte_unmap_nested()
arm64: Fix compiler warning from pte_unmap() with -Wunused-but-set-variable
arm64: compat: Reduce address limit for 64K pages
...

+2541 -837
+1
Documentation/admin-guide/kernel-parameters.rst
··· 88 88 APIC APIC support is enabled. 89 89 APM Advanced Power Management support is enabled. 90 90 ARM ARM architecture is enabled. 91 + ARM64 ARM64 architecture is enabled. 91 92 AX25 Appropriate AX.25 support is enabled. 92 93 CLK Common clock infrastructure is enabled. 93 94 CMA Contiguous Memory Area support is enabled.
+9 -7
Documentation/admin-guide/kernel-parameters.txt
··· 2548 2548 http://repo.or.cz/w/linux-2.6/mini2440.git 2549 2549 2550 2550 mitigations= 2551 - [X86,PPC,S390] Control optional mitigations for CPU 2552 - vulnerabilities. This is a set of curated, 2551 + [X86,PPC,S390,ARM64] Control optional mitigations for 2552 + CPU vulnerabilities. This is a set of curated, 2553 2553 arch-independent options, each of which is an 2554 2554 aggregation of existing arch-specific options. 2555 2555 ··· 2558 2558 improves system performance, but it may also 2559 2559 expose users to several CPU vulnerabilities. 2560 2560 Equivalent to: nopti [X86,PPC] 2561 + kpti=0 [ARM64] 2561 2562 nospectre_v1 [PPC] 2562 2563 nobp=0 [S390] 2563 - nospectre_v2 [X86,PPC,S390] 2564 + nospectre_v2 [X86,PPC,S390,ARM64] 2564 2565 spectre_v2_user=off [X86] 2565 2566 spec_store_bypass_disable=off [X86,PPC] 2567 + ssbd=force-off [ARM64] 2566 2568 l1tf=off [X86] 2567 2569 2568 2570 auto (default) ··· 2910 2908 check bypass). With this option data leaks are possible 2911 2909 in the system. 2912 2910 2913 - nospectre_v2 [X86,PPC_FSL_BOOK3E] Disable all mitigations for the Spectre variant 2 2914 - (indirect branch prediction) vulnerability. System may 2915 - allow data leaks with this option, which is equivalent 2916 - to spectre_v2=off. 2911 + nospectre_v2 [X86,PPC_FSL_BOOK3E,ARM64] Disable all mitigations for 2912 + the Spectre variant 2 (indirect branch prediction) 2913 + vulnerability. System may allow data leaks with this 2914 + option. 2917 2915 2918 2916 nospec_store_bypass_disable 2919 2917 [HW] Disable all mitigations for the Speculative Store Bypass vulnerability
+16
Documentation/arm64/cpu-feature-registers.txt
··· 209 209 | AT | [35-32] | y | 210 210 x--------------------------------------------------x 211 211 212 + 6) ID_AA64ZFR0_EL1 - SVE feature ID register 0 213 + 214 + x--------------------------------------------------x 215 + | Name | bits | visible | 216 + |--------------------------------------------------| 217 + | SM4 | [43-40] | y | 218 + |--------------------------------------------------| 219 + | SHA3 | [35-32] | y | 220 + |--------------------------------------------------| 221 + | BitPerm | [19-16] | y | 222 + |--------------------------------------------------| 223 + | AES | [7-4] | y | 224 + |--------------------------------------------------| 225 + | SVEVer | [3-0] | y | 226 + x--------------------------------------------------x 227 + 212 228 Appendix I: Example 213 229 --------------------------- 214 230
+38 -3
Documentation/arm64/elf_hwcaps.txt
··· 13 13 kernel exposes the presence of these features to userspace through a set 14 14 of flags called hwcaps, exposed in the auxilliary vector. 15 15 16 - Userspace software can test for features by acquiring the AT_HWCAP entry 17 - of the auxilliary vector, and testing whether the relevant flags are 18 - set, e.g. 16 + Userspace software can test for features by acquiring the AT_HWCAP or 17 + AT_HWCAP2 entry of the auxiliary vector, and testing whether the relevant 18 + flags are set, e.g. 19 19 20 20 bool floating_point_is_present(void) 21 21 { ··· 135 135 136 136 Functionality implied by ID_AA64ISAR1_EL1.DPB == 0b0001. 137 137 138 + HWCAP2_DCPODP 139 + 140 + Functionality implied by ID_AA64ISAR1_EL1.DPB == 0b0010. 141 + 138 142 HWCAP_SHA3 139 143 140 144 Functionality implied by ID_AA64ISAR0_EL1.SHA3 == 0b0001. ··· 162 158 HWCAP_SVE 163 159 164 160 Functionality implied by ID_AA64PFR0_EL1.SVE == 0b0001. 161 + 162 + HWCAP2_SVE2 163 + 164 + Functionality implied by ID_AA64ZFR0_EL1.SVEVer == 0b0001. 165 + 166 + HWCAP2_SVEAES 167 + 168 + Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0001. 169 + 170 + HWCAP2_SVEPMULL 171 + 172 + Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0010. 173 + 174 + HWCAP2_SVEBITPERM 175 + 176 + Functionality implied by ID_AA64ZFR0_EL1.BitPerm == 0b0001. 177 + 178 + HWCAP2_SVESHA3 179 + 180 + Functionality implied by ID_AA64ZFR0_EL1.SHA3 == 0b0001. 181 + 182 + HWCAP2_SVESM4 183 + 184 + Functionality implied by ID_AA64ZFR0_EL1.SM4 == 0b0001. 165 185 166 186 HWCAP_ASIMDFHM 167 187 ··· 222 194 Functionality implied by ID_AA64ISAR1_EL1.GPA == 0b0001 or 223 195 ID_AA64ISAR1_EL1.GPI == 0b0001, as described by 224 196 Documentation/arm64/pointer-authentication.txt. 197 + 198 + 199 + 4. Unused AT_HWCAP bits 200 + ----------------------- 201 + 202 + For interoperation with userspace, the kernel guarantees that bits 62 203 + and 63 of AT_HWCAP will always be returned as 0.
+2
Documentation/arm64/silicon-errata.txt
··· 61 61 | ARM | Cortex-A76 | #1188873 | ARM64_ERRATUM_1188873 | 62 62 | ARM | Cortex-A76 | #1165522 | ARM64_ERRATUM_1165522 | 63 63 | ARM | Cortex-A76 | #1286807 | ARM64_ERRATUM_1286807 | 64 + | ARM | Neoverse-N1 | #1188873 | ARM64_ERRATUM_1188873 | 64 65 | ARM | MMU-500 | #841119,#826419 | N/A | 65 66 | | | | | 66 67 | Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | ··· 78 77 | Hisilicon | Hip0{5,6,7} | #161010101 | HISILICON_ERRATUM_161010101 | 79 78 | Hisilicon | Hip0{6,7} | #161010701 | N/A | 80 79 | Hisilicon | Hip07 | #161600802 | HISILICON_ERRATUM_161600802 | 80 + | Hisilicon | Hip08 SMMU PMCG | #162001800 | N/A | 81 81 | | | | | 82 82 | Qualcomm Tech. | Kryo/Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003 | 83 83 | Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009 |
+17
Documentation/arm64/sve.txt
··· 34 34 following sections: software that needs to verify that those interfaces are 35 35 present must check for HWCAP_SVE instead. 36 36 37 + * On hardware that supports the SVE2 extensions, HWCAP2_SVE2 will also 38 + be reported in the AT_HWCAP2 aux vector entry. In addition to this, 39 + optional extensions to SVE2 may be reported by the presence of: 40 + 41 + HWCAP2_SVE2 42 + HWCAP2_SVEAES 43 + HWCAP2_SVEPMULL 44 + HWCAP2_SVEBITPERM 45 + HWCAP2_SVESHA3 46 + HWCAP2_SVESM4 47 + 48 + This list may be extended over time as the SVE architecture evolves. 49 + 50 + These extensions are also reported via the CPU ID register ID_AA64ZFR0_EL1, 51 + which userspace can read using an MRS instruction. See elf_hwcaps.txt and 52 + cpu-feature-registers.txt for details. 53 + 37 54 * Debuggers should restrict themselves to interacting with the target via the 38 55 NT_ARM_SVE regset. The recommended way of detecting support for this regset 39 56 is to connect to a target process first and then attempt a
+1 -2
Documentation/robust-futexes.txt
··· 218 218 the new syscalls yet. 219 219 220 220 Architectures need to implement the new futex_atomic_cmpxchg_inatomic() 221 - inline function before writing up the syscalls (that function returns 222 - -ENOSYS right now). 221 + inline function before writing up the syscalls.
+16 -2
arch/arm/include/asm/arch_timer.h
··· 11 11 #include <clocksource/arm_arch_timer.h> 12 12 13 13 #ifdef CONFIG_ARM_ARCH_TIMER 14 + /* 32bit ARM doesn't know anything about timer errata... */ 15 + #define has_erratum_handler(h) (false) 16 + #define erratum_handler(h) (arch_timer_##h) 17 + 14 18 int arch_timer_arch_init(void); 15 19 16 20 /* ··· 83 79 return val; 84 80 } 85 81 86 - static inline u64 arch_counter_get_cntpct(void) 82 + static inline u64 __arch_counter_get_cntpct(void) 87 83 { 88 84 u64 cval; 89 85 ··· 92 88 return cval; 93 89 } 94 90 95 - static inline u64 arch_counter_get_cntvct(void) 91 + static inline u64 __arch_counter_get_cntpct_stable(void) 92 + { 93 + return __arch_counter_get_cntpct(); 94 + } 95 + 96 + static inline u64 __arch_counter_get_cntvct(void) 96 97 { 97 98 u64 cval; 98 99 99 100 isb(); 100 101 asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (cval)); 101 102 return cval; 103 + } 104 + 105 + static inline u64 __arch_counter_get_cntvct_stable(void) 106 + { 107 + return __arch_counter_get_cntvct(); 102 108 } 103 109 104 110 static inline u32 arch_timer_get_cntkctl(void)
+2
arch/arm/include/asm/cp15.h
··· 68 68 #define BPIALL __ACCESS_CP15(c7, 0, c5, 6) 69 69 #define ICIALLU __ACCESS_CP15(c7, 0, c5, 0) 70 70 71 + #define CNTVCT __ACCESS_CP15_64(1, c14) 72 + 71 73 extern unsigned long cr_alignment; /* defined in entry-armv.S */ 72 74 73 75 static inline unsigned long get_cr(void)
+2 -2
arch/arm/include/asm/stage2_pgtable.h
··· 32 32 #define stage2_pgd_present(kvm, pgd) pgd_present(pgd) 33 33 #define stage2_pgd_populate(kvm, pgd, pud) pgd_populate(NULL, pgd, pud) 34 34 #define stage2_pud_offset(kvm, pgd, address) pud_offset(pgd, address) 35 - #define stage2_pud_free(kvm, pud) pud_free(NULL, pud) 35 + #define stage2_pud_free(kvm, pud) do { } while (0) 36 36 37 37 #define stage2_pud_none(kvm, pud) pud_none(pud) 38 38 #define stage2_pud_clear(kvm, pud) pud_clear(pud) 39 39 #define stage2_pud_present(kvm, pud) pud_present(pud) 40 40 #define stage2_pud_populate(kvm, pud, pmd) pud_populate(NULL, pud, pmd) 41 41 #define stage2_pmd_offset(kvm, pud, address) pmd_offset(pud, address) 42 - #define stage2_pmd_free(kvm, pmd) pmd_free(NULL, pmd) 42 + #define stage2_pmd_free(kvm, pmd) free_page((unsigned long)pmd) 43 43 44 44 #define stage2_pud_huge(kvm, pud) pud_huge(pud) 45 45
+3 -2
arch/arm/vdso/vgettimeofday.c
··· 18 18 #include <linux/compiler.h> 19 19 #include <linux/hrtimer.h> 20 20 #include <linux/time.h> 21 - #include <asm/arch_timer.h> 22 21 #include <asm/barrier.h> 23 22 #include <asm/bug.h> 23 + #include <asm/cp15.h> 24 24 #include <asm/page.h> 25 25 #include <asm/unistd.h> 26 26 #include <asm/vdso_datapage.h> ··· 123 123 u64 cycle_now; 124 124 u64 nsec; 125 125 126 - cycle_now = arch_counter_get_cntvct(); 126 + isb(); 127 + cycle_now = read_sysreg(CNTVCT); 127 128 128 129 cycle_delta = (cycle_now - vdata->cs_cycle_last) & vdata->cs_mask; 129 130
+85 -47
arch/arm64/Kconfig
··· 90 90 select GENERIC_CLOCKEVENTS 91 91 select GENERIC_CLOCKEVENTS_BROADCAST 92 92 select GENERIC_CPU_AUTOPROBE 93 + select GENERIC_CPU_VULNERABILITIES 93 94 select GENERIC_EARLY_IOREMAP 94 95 select GENERIC_IDLE_POLL_SETUP 95 96 select GENERIC_IRQ_MULTI_HANDLER ··· 149 148 select HAVE_PERF_REGS 150 149 select HAVE_PERF_USER_STACK_DUMP 151 150 select HAVE_REGS_AND_STACK_ACCESS_API 151 + select HAVE_FUNCTION_ARG_ACCESS_API 152 152 select HAVE_RCU_TABLE_FREE 153 153 select HAVE_RSEQ 154 154 select HAVE_STACKPROTECTOR ··· 295 293 menu "ARM errata workarounds via the alternatives framework" 296 294 297 295 config ARM64_WORKAROUND_CLEAN_CACHE 298 - def_bool n 296 + bool 299 297 300 298 config ARM64_ERRATUM_826319 301 299 bool "Cortex-A53: 826319: System might deadlock if a write cannot complete until read data is accepted" ··· 462 460 bool "Cortex-A55: 1024718: Update of DBM/AP bits without break before make might result in incorrect update" 463 461 default y 464 462 help 465 - This option adds work around for Arm Cortex-A55 Erratum 1024718. 463 + This option adds a workaround for ARM Cortex-A55 Erratum 1024718. 466 464 467 465 Affected Cortex-A55 cores (r0p0, r0p1, r1p0) could cause incorrect 468 466 update of the hardware dirty bit when the DBM/AP bits are updated 469 - without a break-before-make. The work around is to disable the usage 467 + without a break-before-make. The workaround is to disable the usage 470 468 of hardware DBM locally on the affected cores. CPUs not affected by 471 - erratum will continue to use the feature. 469 + this erratum will continue to use the feature. 472 470 473 471 If unsure, say Y. 474 472 475 473 config ARM64_ERRATUM_1188873 476 - bool "Cortex-A76: MRC read following MRRC read of specific Generic Timer in AArch32 might give incorrect result" 474 + bool "Cortex-A76/Neoverse-N1: MRC read following MRRC read of specific Generic Timer in AArch32 might give incorrect result" 477 475 default y 476 + depends on COMPAT 478 477 select ARM_ARCH_TIMER_OOL_WORKAROUND 479 478 help 480 - This option adds work arounds for ARM Cortex-A76 erratum 1188873 479 + This option adds a workaround for ARM Cortex-A76/Neoverse-N1 480 + erratum 1188873. 481 481 482 - Affected Cortex-A76 cores (r0p0, r1p0, r2p0) could cause 483 - register corruption when accessing the timer registers from 484 - AArch32 userspace. 482 + Affected Cortex-A76/Neoverse-N1 cores (r0p0, r1p0, r2p0) could 483 + cause register corruption when accessing the timer registers 484 + from AArch32 userspace. 485 485 486 486 If unsure, say Y. 487 487 ··· 491 487 bool "Cortex-A76: Speculative AT instruction using out-of-context translation regime could cause subsequent request to generate an incorrect translation" 492 488 default y 493 489 help 494 - This option adds work arounds for ARM Cortex-A76 erratum 1165522 490 + This option adds a workaround for ARM Cortex-A76 erratum 1165522. 495 491 496 492 Affected Cortex-A76 cores (r0p0, r1p0, r2p0) could end-up with 497 493 corrupted TLBs by speculating an AT instruction during a guest ··· 504 500 default y 505 501 select ARM64_WORKAROUND_REPEAT_TLBI 506 502 help 507 - This option adds workaround for ARM Cortex-A76 erratum 1286807 503 + This option adds a workaround for ARM Cortex-A76 erratum 1286807. 508 504 509 505 On the affected Cortex-A76 cores (r0p0 to r3p0), if a virtual 510 506 address for a cacheable mapping of a location is being ··· 521 517 bool "Cavium erratum 22375, 24313" 522 518 default y 523 519 help 524 - Enable workaround for erratum 22375, 24313. 520 + Enable workaround for errata 22375 and 24313. 525 521 526 522 This implements two gicv3-its errata workarounds for ThunderX. Both 527 - with small impact affecting only ITS table allocation. 523 + with a small impact affecting only ITS table allocation. 528 524 529 525 erratum 22375: only alloc 8MB table size 530 526 erratum 24313: ignore memory access type ··· 588 584 589 585 config ARM64_WORKAROUND_REPEAT_TLBI 590 586 bool 591 - help 592 - Enable the repeat TLBI workaround for Falkor erratum 1009 and 593 - Cortex-A76 erratum 1286807. 594 587 595 588 config QCOM_FALKOR_ERRATUM_1009 596 589 bool "Falkor E1009: Prematurely complete a DSB after a TLBI" ··· 623 622 bool "Hip07 161600802: Erroneous redistributor VLPI base" 624 623 default y 625 624 help 626 - The HiSilicon Hip07 SoC usees the wrong redistributor base 625 + The HiSilicon Hip07 SoC uses the wrong redistributor base 627 626 when issued ITS commands such as VMOVP and VMAPP, and requires 628 627 a 128kB offset to be applied to the target address in this commands. 629 628 ··· 643 642 bool "Fujitsu-A64FX erratum E#010001: Undefined fault may occur wrongly" 644 643 default y 645 644 help 646 - This option adds workaround for Fujitsu-A64FX erratum E#010001. 645 + This option adds a workaround for Fujitsu-A64FX erratum E#010001. 647 646 On some variants of the Fujitsu-A64FX cores ver(1.0, 1.1), memory 648 647 accesses may cause undefined fault (Data abort, DFSC=0b111111). 649 648 This fault occurs under a specific hardware condition when a ··· 654 653 case-4 TTBR1_EL2 with TCR_EL2.NFD1 == 1. 655 654 656 655 The workaround is to ensure these bits are clear in TCR_ELx. 657 - The workaround only affect the Fujitsu-A64FX. 656 + The workaround only affects the Fujitsu-A64FX. 658 657 659 658 If unsure, say Y. 660 659 ··· 886 885 config ARCH_HAS_CACHE_LINE_SIZE 887 886 def_bool y 888 887 888 + config ARCH_ENABLE_SPLIT_PMD_PTLOCK 889 + def_bool y if PGTABLE_LEVELS > 2 890 + 889 891 config SECCOMP 890 892 bool "Enable seccomp to safely compute untrusted bytecode" 891 893 ---help--- ··· 1078 1074 This requires the linear region to be mapped down to pages, 1079 1075 which may adversely affect performance in some cases. 1080 1076 1077 + config ARM64_SW_TTBR0_PAN 1078 + bool "Emulate Privileged Access Never using TTBR0_EL1 switching" 1079 + help 1080 + Enabling this option prevents the kernel from accessing 1081 + user-space memory directly by pointing TTBR0_EL1 to a reserved 1082 + zeroed area and reserved ASID. The user access routines 1083 + restore the valid TTBR0_EL1 temporarily. 1084 + 1085 + menuconfig COMPAT 1086 + bool "Kernel support for 32-bit EL0" 1087 + depends on ARM64_4K_PAGES || EXPERT 1088 + select COMPAT_BINFMT_ELF if BINFMT_ELF 1089 + select HAVE_UID16 1090 + select OLD_SIGSUSPEND3 1091 + select COMPAT_OLD_SIGACTION 1092 + help 1093 + This option enables support for a 32-bit EL0 running under a 64-bit 1094 + kernel at EL1. AArch32-specific components such as system calls, 1095 + the user helper functions, VFP support and the ptrace interface are 1096 + handled appropriately by the kernel. 1097 + 1098 + If you use a page size other than 4KB (i.e, 16KB or 64KB), please be aware 1099 + that you will only be able to execute AArch32 binaries that were compiled 1100 + with page size aligned segments. 1101 + 1102 + If you want to execute 32-bit userspace applications, say Y. 1103 + 1104 + if COMPAT 1105 + 1106 + config KUSER_HELPERS 1107 + bool "Enable kuser helpers page for 32 bit applications" 1108 + default y 1109 + help 1110 + Warning: disabling this option may break 32-bit user programs. 1111 + 1112 + Provide kuser helpers to compat tasks. The kernel provides 1113 + helper code to userspace in read only form at a fixed location 1114 + to allow userspace to be independent of the CPU type fitted to 1115 + the system. This permits binaries to be run on ARMv4 through 1116 + to ARMv8 without modification. 1117 + 1118 + See Documentation/arm/kernel_user_helpers.txt for details. 1119 + 1120 + However, the fixed address nature of these helpers can be used 1121 + by ROP (return orientated programming) authors when creating 1122 + exploits. 1123 + 1124 + If all of the binaries and libraries which run on your platform 1125 + are built specifically for your platform, and make no use of 1126 + these helpers, then you can turn this option off to hinder 1127 + such exploits. However, in that case, if a binary or library 1128 + relying on those helpers is run, it will not function correctly. 1129 + 1130 + Say N here only if you are absolutely certain that you do not 1131 + need these helpers; otherwise, the safe option is to say Y. 1132 + 1133 + 1081 1134 menuconfig ARMV8_DEPRECATED 1082 1135 bool "Emulate deprecated/obsolete ARMv8 instructions" 1083 - depends on COMPAT 1084 1136 depends on SYSCTL 1085 1137 help 1086 1138 Legacy software support may require certain instructions ··· 1202 1142 If unsure, say Y 1203 1143 endif 1204 1144 1205 - config ARM64_SW_TTBR0_PAN 1206 - bool "Emulate Privileged Access Never using TTBR0_EL1 switching" 1207 - help 1208 - Enabling this option prevents the kernel from accessing 1209 - user-space memory directly by pointing TTBR0_EL1 to a reserved 1210 - zeroed area and reserved ASID. The user access routines 1211 - restore the valid TTBR0_EL1 temporarily. 1145 + endif 1212 1146 1213 1147 menu "ARMv8.1 architectural features" 1214 1148 ··· 1368 1314 1369 1315 To enable use of this extension on CPUs that implement it, say Y. 1370 1316 1317 + On CPUs that support the SVE2 extensions, this option will enable 1318 + those too. 1319 + 1371 1320 Note that for architectural reasons, firmware _must_ implement SVE 1372 1321 support when running on SVE capable hardware. The required support 1373 1322 is present in: ··· 1404 1347 help 1405 1348 Adds support for mimicking Non-Maskable Interrupts through the use of 1406 1349 GIC interrupt priority. This support requires version 3 or later of 1407 - Arm GIC. 1350 + ARM GIC. 1408 1351 1409 1352 This high priority configuration for interrupts needs to be 1410 1353 explicitly enabled by setting the kernel parameter ··· 1527 1470 continue to boot on existing non-UEFI platforms. 1528 1471 1529 1472 endmenu 1530 - 1531 - config COMPAT 1532 - bool "Kernel support for 32-bit EL0" 1533 - depends on ARM64_4K_PAGES || EXPERT 1534 - select COMPAT_BINFMT_ELF if BINFMT_ELF 1535 - select HAVE_UID16 1536 - select OLD_SIGSUSPEND3 1537 - select COMPAT_OLD_SIGACTION 1538 - help 1539 - This option enables support for a 32-bit EL0 running under a 64-bit 1540 - kernel at EL1. AArch32-specific components such as system calls, 1541 - the user helper functions, VFP support and the ptrace interface are 1542 - handled appropriately by the kernel. 1543 - 1544 - If you use a page size other than 4KB (i.e, 16KB or 64KB), please be aware 1545 - that you will only be able to execute AArch32 binaries that were compiled 1546 - with page size aligned segments. 1547 - 1548 - If you want to execute 32-bit userspace applications, say Y. 1549 1473 1550 1474 config SYSVIPC_COMPAT 1551 1475 def_bool y
+1 -1
arch/arm64/boot/dts/mediatek/mt2712-pinfunc.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 3 * Copyright (C) 2018 MediaTek Inc. 4 4 * Author: Zhiyong Tao <zhiyong.tao@mediatek.com>
+1 -1
arch/arm64/crypto/aes-ce-ccm-glue.c
··· 372 372 373 373 static int __init aes_mod_init(void) 374 374 { 375 - if (!(elf_hwcap & HWCAP_AES)) 375 + if (!cpu_have_named_feature(AES)) 376 376 return -ENODEV; 377 377 return crypto_register_aead(&ccm_aes_alg); 378 378 }
+1 -1
arch/arm64/crypto/aes-neonbs-glue.c
··· 440 440 int err; 441 441 int i; 442 442 443 - if (!(elf_hwcap & HWCAP_ASIMD)) 443 + if (!cpu_have_named_feature(ASIMD)) 444 444 return -ENODEV; 445 445 446 446 err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
+1 -1
arch/arm64/crypto/chacha-neon-glue.c
··· 173 173 174 174 static int __init chacha_simd_mod_init(void) 175 175 { 176 - if (!(elf_hwcap & HWCAP_ASIMD)) 176 + if (!cpu_have_named_feature(ASIMD)) 177 177 return -ENODEV; 178 178 179 179 return crypto_register_skciphers(algs, ARRAY_SIZE(algs));
+2 -2
arch/arm64/crypto/crct10dif-ce-glue.c
··· 101 101 102 102 static int __init crc_t10dif_mod_init(void) 103 103 { 104 - if (elf_hwcap & HWCAP_PMULL) 104 + if (cpu_have_named_feature(PMULL)) 105 105 return crypto_register_shashes(crc_t10dif_alg, 106 106 ARRAY_SIZE(crc_t10dif_alg)); 107 107 else ··· 111 111 112 112 static void __exit crc_t10dif_mod_exit(void) 113 113 { 114 - if (elf_hwcap & HWCAP_PMULL) 114 + if (cpu_have_named_feature(PMULL)) 115 115 crypto_unregister_shashes(crc_t10dif_alg, 116 116 ARRAY_SIZE(crc_t10dif_alg)); 117 117 else
+4 -4
arch/arm64/crypto/ghash-ce-glue.c
··· 704 704 { 705 705 int ret; 706 706 707 - if (!(elf_hwcap & HWCAP_ASIMD)) 707 + if (!cpu_have_named_feature(ASIMD)) 708 708 return -ENODEV; 709 709 710 - if (elf_hwcap & HWCAP_PMULL) 710 + if (cpu_have_named_feature(PMULL)) 711 711 ret = crypto_register_shashes(ghash_alg, 712 712 ARRAY_SIZE(ghash_alg)); 713 713 else ··· 717 717 if (ret) 718 718 return ret; 719 719 720 - if (elf_hwcap & HWCAP_PMULL) { 720 + if (cpu_have_named_feature(PMULL)) { 721 721 ret = crypto_register_aead(&gcm_aes_alg); 722 722 if (ret) 723 723 crypto_unregister_shashes(ghash_alg, ··· 728 728 729 729 static void __exit ghash_ce_mod_exit(void) 730 730 { 731 - if (elf_hwcap & HWCAP_PMULL) 731 + if (cpu_have_named_feature(PMULL)) 732 732 crypto_unregister_shashes(ghash_alg, ARRAY_SIZE(ghash_alg)); 733 733 else 734 734 crypto_unregister_shash(ghash_alg);
+1 -1
arch/arm64/crypto/nhpoly1305-neon-glue.c
··· 56 56 57 57 static int __init nhpoly1305_mod_init(void) 58 58 { 59 - if (!(elf_hwcap & HWCAP_ASIMD)) 59 + if (!cpu_have_named_feature(ASIMD)) 60 60 return -ENODEV; 61 61 62 62 return crypto_register_shash(&nhpoly1305_alg);
+2 -2
arch/arm64/crypto/sha256-glue.c
··· 173 173 if (ret) 174 174 return ret; 175 175 176 - if (elf_hwcap & HWCAP_ASIMD) { 176 + if (cpu_have_named_feature(ASIMD)) { 177 177 ret = crypto_register_shashes(neon_algs, ARRAY_SIZE(neon_algs)); 178 178 if (ret) 179 179 crypto_unregister_shashes(algs, ARRAY_SIZE(algs)); ··· 183 183 184 184 static void __exit sha256_mod_fini(void) 185 185 { 186 - if (elf_hwcap & HWCAP_ASIMD) 186 + if (cpu_have_named_feature(ASIMD)) 187 187 crypto_unregister_shashes(neon_algs, ARRAY_SIZE(neon_algs)); 188 188 crypto_unregister_shashes(algs, ARRAY_SIZE(algs)); 189 189 }
+97 -22
arch/arm64/include/asm/arch_timer.h
··· 31 31 #include <clocksource/arm_arch_timer.h> 32 32 33 33 #if IS_ENABLED(CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND) 34 - extern struct static_key_false arch_timer_read_ool_enabled; 35 - #define needs_unstable_timer_counter_workaround() \ 36 - static_branch_unlikely(&arch_timer_read_ool_enabled) 34 + #define has_erratum_handler(h) \ 35 + ({ \ 36 + const struct arch_timer_erratum_workaround *__wa; \ 37 + __wa = __this_cpu_read(timer_unstable_counter_workaround); \ 38 + (__wa && __wa->h); \ 39 + }) 40 + 41 + #define erratum_handler(h) \ 42 + ({ \ 43 + const struct arch_timer_erratum_workaround *__wa; \ 44 + __wa = __this_cpu_read(timer_unstable_counter_workaround); \ 45 + (__wa && __wa->h) ? __wa->h : arch_timer_##h; \ 46 + }) 47 + 37 48 #else 38 - #define needs_unstable_timer_counter_workaround() false 49 + #define has_erratum_handler(h) false 50 + #define erratum_handler(h) (arch_timer_##h) 39 51 #endif 40 52 41 53 enum arch_timer_erratum_match_type { ··· 73 61 DECLARE_PER_CPU(const struct arch_timer_erratum_workaround *, 74 62 timer_unstable_counter_workaround); 75 63 64 + /* inline sysreg accessors that make erratum_handler() work */ 65 + static inline notrace u32 arch_timer_read_cntp_tval_el0(void) 66 + { 67 + return read_sysreg(cntp_tval_el0); 68 + } 69 + 70 + static inline notrace u32 arch_timer_read_cntv_tval_el0(void) 71 + { 72 + return read_sysreg(cntv_tval_el0); 73 + } 74 + 75 + static inline notrace u64 arch_timer_read_cntpct_el0(void) 76 + { 77 + return read_sysreg(cntpct_el0); 78 + } 79 + 80 + static inline notrace u64 arch_timer_read_cntvct_el0(void) 81 + { 82 + return read_sysreg(cntvct_el0); 83 + } 84 + 76 85 #define arch_timer_reg_read_stable(reg) \ 77 - ({ \ 78 - u64 _val; \ 79 - if (needs_unstable_timer_counter_workaround()) { \ 80 - const struct arch_timer_erratum_workaround *wa; \ 86 + ({ \ 87 + u64 _val; \ 88 + \ 81 89 preempt_disable_notrace(); \ 82 - wa = __this_cpu_read(timer_unstable_counter_workaround); \ 83 - if (wa && wa->read_##reg) \ 84 - _val = wa->read_##reg(); \ 85 - else \ 86 - _val = read_sysreg(reg); \ 90 + _val = erratum_handler(read_ ## reg)(); \ 87 91 preempt_enable_notrace(); \ 88 - } else { \ 89 - _val = read_sysreg(reg); \ 90 - } \ 91 - _val; \ 92 - }) 92 + \ 93 + _val; \ 94 + }) 93 95 94 96 /* 95 97 * These register accessors are marked inline so the compiler can ··· 174 148 isb(); 175 149 } 176 150 177 - static inline u64 arch_counter_get_cntpct(void) 151 + /* 152 + * Ensure that reads of the counter are treated the same as memory reads 153 + * for the purposes of ordering by subsequent memory barriers. 154 + * 155 + * This insanity brought to you by speculative system register reads, 156 + * out-of-order memory accesses, sequence locks and Thomas Gleixner. 157 + * 158 + * http://lists.infradead.org/pipermail/linux-arm-kernel/2019-February/631195.html 159 + */ 160 + #define arch_counter_enforce_ordering(val) do { \ 161 + u64 tmp, _val = (val); \ 162 + \ 163 + asm volatile( \ 164 + " eor %0, %1, %1\n" \ 165 + " add %0, sp, %0\n" \ 166 + " ldr xzr, [%0]" \ 167 + : "=r" (tmp) : "r" (_val)); \ 168 + } while (0) 169 + 170 + static inline u64 __arch_counter_get_cntpct_stable(void) 178 171 { 172 + u64 cnt; 173 + 179 174 isb(); 180 - return arch_timer_reg_read_stable(cntpct_el0); 175 + cnt = arch_timer_reg_read_stable(cntpct_el0); 176 + arch_counter_enforce_ordering(cnt); 177 + return cnt; 181 178 } 182 179 183 - static inline u64 arch_counter_get_cntvct(void) 180 + static inline u64 __arch_counter_get_cntpct(void) 184 181 { 182 + u64 cnt; 183 + 185 184 isb(); 186 - return arch_timer_reg_read_stable(cntvct_el0); 185 + cnt = read_sysreg(cntpct_el0); 186 + arch_counter_enforce_ordering(cnt); 187 + return cnt; 187 188 } 189 + 190 + static inline u64 __arch_counter_get_cntvct_stable(void) 191 + { 192 + u64 cnt; 193 + 194 + isb(); 195 + cnt = arch_timer_reg_read_stable(cntvct_el0); 196 + arch_counter_enforce_ordering(cnt); 197 + return cnt; 198 + } 199 + 200 + static inline u64 __arch_counter_get_cntvct(void) 201 + { 202 + u64 cnt; 203 + 204 + isb(); 205 + cnt = read_sysreg(cntvct_el0); 206 + arch_counter_enforce_ordering(cnt); 207 + return cnt; 208 + } 209 + 210 + #undef arch_counter_enforce_ordering 188 211 189 212 static inline int arch_timer_arch_init(void) 190 213 {
+6 -2
arch/arm64/include/asm/assembler.h
··· 407 407 .ifc \op, cvap 408 408 sys 3, c7, c12, 1, \kaddr // dc cvap 409 409 .else 410 + .ifc \op, cvadp 411 + sys 3, c7, c13, 1, \kaddr // dc cvadp 412 + .else 410 413 dc \op, \kaddr 414 + .endif 411 415 .endif 412 416 .endif 413 417 .endif ··· 446 442 * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present 447 443 */ 448 444 .macro reset_pmuserenr_el0, tmpreg 449 - mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer 450 - sbfx \tmpreg, \tmpreg, #8, #4 445 + mrs \tmpreg, id_aa64dfr0_el1 446 + sbfx \tmpreg, \tmpreg, #ID_AA64DFR0_PMUVER_SHIFT, #4 451 447 cmp \tmpreg, #1 // Skip if no PMU present 452 448 b.lt 9000f 453 449 msr pmuserenr_el0, xzr // Disable PMU access from EL0
+15 -9
arch/arm64/include/asm/barrier.h
··· 20 20 21 21 #ifndef __ASSEMBLY__ 22 22 23 + #include <linux/kasan-checks.h> 24 + 23 25 #define __nops(n) ".rept " #n "\nnop\n.endr\n" 24 26 #define nops(n) asm volatile(__nops(n)) 25 27 ··· 74 72 75 73 #define __smp_store_release(p, v) \ 76 74 do { \ 75 + typeof(p) __p = (p); \ 77 76 union { typeof(*p) __val; char __c[1]; } __u = \ 78 - { .__val = (__force typeof(*p)) (v) }; \ 77 + { .__val = (__force typeof(*p)) (v) }; \ 79 78 compiletime_assert_atomic_type(*p); \ 79 + kasan_check_write(__p, sizeof(*p)); \ 80 80 switch (sizeof(*p)) { \ 81 81 case 1: \ 82 82 asm volatile ("stlrb %w1, %0" \ 83 - : "=Q" (*p) \ 83 + : "=Q" (*__p) \ 84 84 : "r" (*(__u8 *)__u.__c) \ 85 85 : "memory"); \ 86 86 break; \ 87 87 case 2: \ 88 88 asm volatile ("stlrh %w1, %0" \ 89 - : "=Q" (*p) \ 89 + : "=Q" (*__p) \ 90 90 : "r" (*(__u16 *)__u.__c) \ 91 91 : "memory"); \ 92 92 break; \ 93 93 case 4: \ 94 94 asm volatile ("stlr %w1, %0" \ 95 - : "=Q" (*p) \ 95 + : "=Q" (*__p) \ 96 96 : "r" (*(__u32 *)__u.__c) \ 97 97 : "memory"); \ 98 98 break; \ 99 99 case 8: \ 100 100 asm volatile ("stlr %1, %0" \ 101 - : "=Q" (*p) \ 101 + : "=Q" (*__p) \ 102 102 : "r" (*(__u64 *)__u.__c) \ 103 103 : "memory"); \ 104 104 break; \ ··· 110 106 #define __smp_load_acquire(p) \ 111 107 ({ \ 112 108 union { typeof(*p) __val; char __c[1]; } __u; \ 109 + typeof(p) __p = (p); \ 113 110 compiletime_assert_atomic_type(*p); \ 111 + kasan_check_read(__p, sizeof(*p)); \ 114 112 switch (sizeof(*p)) { \ 115 113 case 1: \ 116 114 asm volatile ("ldarb %w0, %1" \ 117 115 : "=r" (*(__u8 *)__u.__c) \ 118 - : "Q" (*p) : "memory"); \ 116 + : "Q" (*__p) : "memory"); \ 119 117 break; \ 120 118 case 2: \ 121 119 asm volatile ("ldarh %w0, %1" \ 122 120 : "=r" (*(__u16 *)__u.__c) \ 123 - : "Q" (*p) : "memory"); \ 121 + : "Q" (*__p) : "memory"); \ 124 122 break; \ 125 123 case 4: \ 126 124 asm volatile ("ldar %w0, %1" \ 127 125 : "=r" (*(__u32 *)__u.__c) \ 128 - : "Q" (*p) : "memory"); \ 126 + : "Q" (*__p) : "memory"); \ 129 127 break; \ 130 128 case 8: \ 131 129 asm volatile ("ldar %0, %1" \ 132 130 : "=r" (*(__u64 *)__u.__c) \ 133 - : "Q" (*p) : "memory"); \ 131 + : "Q" (*__p) : "memory"); \ 134 132 break; \ 135 133 } \ 136 134 __u.__val; \
+5
arch/arm64/include/asm/brk-imm.h
··· 11 11 12 12 /* 13 13 * #imm16 values used for BRK instruction generation 14 + * 0x004: for installing kprobes 15 + * 0x005: for installing uprobes 14 16 * Allowed values for kgdb are 0x400 - 0x7ff 15 17 * 0x100: for triggering a fault on purpose (reserved) 16 18 * 0x400: for dynamic BRK instruction ··· 20 18 * 0x800: kernel-mode BUG() and WARN() traps 21 19 * 0x9xx: tag-based KASAN trap (allowed values 0x900 - 0x9ff) 22 20 */ 21 + #define KPROBES_BRK_IMM 0x004 22 + #define UPROBES_BRK_IMM 0x005 23 23 #define FAULT_BRK_IMM 0x100 24 24 #define KGDB_DYN_DBG_BRK_IMM 0x400 25 25 #define KGDB_COMPILED_DBG_BRK_IMM 0x401 26 26 #define BUG_BRK_IMM 0x800 27 27 #define KASAN_BRK_IMM 0x900 28 + #define KASAN_BRK_MASK 0x0ff 28 29 29 30 #endif
+2 -1
arch/arm64/include/asm/cpucaps.h
··· 61 61 #define ARM64_HAS_GENERIC_AUTH_ARCH 40 62 62 #define ARM64_HAS_GENERIC_AUTH_IMP_DEF 41 63 63 #define ARM64_HAS_IRQ_PRIO_MASKING 42 64 + #define ARM64_HAS_DCPODP 43 64 65 65 - #define ARM64_NCAPS 43 66 + #define ARM64_NCAPS 44 66 67 67 68 #endif /* __ASM_CPUCAPS_H */
+8 -17
arch/arm64/include/asm/cpufeature.h
··· 14 14 #include <asm/hwcap.h> 15 15 #include <asm/sysreg.h> 16 16 17 - /* 18 - * In the arm64 world (as in the ARM world), elf_hwcap is used both internally 19 - * in the kernel and for user space to keep track of which optional features 20 - * are supported by the current system. So let's map feature 'x' to HWCAP_x. 21 - * Note that HWCAP_x constants are bit fields so we need to take the log. 22 - */ 23 - 24 - #define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap)) 25 - #define cpu_feature(x) ilog2(HWCAP_ ## x) 17 + #define MAX_CPU_FEATURES 64 18 + #define cpu_feature(x) KERNEL_HWCAP_ ## x 26 19 27 20 #ifndef __ASSEMBLY__ 28 21 ··· 392 399 for_each_set_bit(cap, cpu_hwcaps, ARM64_NCAPS) 393 400 394 401 bool this_cpu_has_cap(unsigned int cap); 402 + void cpu_set_feature(unsigned int num); 403 + bool cpu_have_feature(unsigned int num); 404 + unsigned long cpu_get_elf_hwcap(void); 405 + unsigned long cpu_get_elf_hwcap2(void); 395 406 396 - static inline bool cpu_have_feature(unsigned int num) 397 - { 398 - return elf_hwcap & (1UL << num); 399 - } 407 + #define cpu_set_named_feature(name) cpu_set_feature(cpu_feature(name)) 408 + #define cpu_have_named_feature(name) cpu_have_feature(cpu_feature(name)) 400 409 401 410 /* System capability check for constant caps */ 402 411 static inline bool __cpus_have_const_cap(int num) ··· 633 638 #endif 634 639 } 635 640 636 - #ifdef CONFIG_ARM64_SSBD 637 641 void arm64_set_ssbd_mitigation(bool state); 638 - #else 639 - static inline void arm64_set_ssbd_mitigation(bool state) {} 640 - #endif 641 642 642 643 extern int do_emulate_mrs(struct pt_regs *regs, u32 sys_reg, u32 rt); 643 644
+2
arch/arm64/include/asm/cputype.h
··· 89 89 #define ARM_CPU_PART_CORTEX_A35 0xD04 90 90 #define ARM_CPU_PART_CORTEX_A55 0xD05 91 91 #define ARM_CPU_PART_CORTEX_A76 0xD0B 92 + #define ARM_CPU_PART_NEOVERSE_N1 0xD0C 92 93 93 94 #define APM_CPU_PART_POTENZA 0x000 94 95 ··· 119 118 #define MIDR_CORTEX_A35 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A35) 120 119 #define MIDR_CORTEX_A55 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A55) 121 120 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76) 121 + #define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1) 122 122 #define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX) 123 123 #define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX) 124 124 #define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)
+14 -11
arch/arm64/include/asm/debug-monitors.h
··· 65 65 #define CACHE_FLUSH_IS_SAFE 1 66 66 67 67 /* kprobes BRK opcodes with ESR encoding */ 68 - #define BRK64_ESR_MASK 0xFFFF 69 - #define BRK64_ESR_KPROBES 0x0004 70 - #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (BRK64_ESR_KPROBES << 5)) 68 + #define BRK64_OPCODE_KPROBES (AARCH64_BREAK_MON | (KPROBES_BRK_IMM << 5)) 71 69 /* uprobes BRK opcodes with ESR encoding */ 72 - #define BRK64_ESR_UPROBES 0x0005 73 - #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (BRK64_ESR_UPROBES << 5)) 70 + #define BRK64_OPCODE_UPROBES (AARCH64_BREAK_MON | (UPROBES_BRK_IMM << 5)) 74 71 75 72 /* AArch32 */ 76 73 #define DBG_ESR_EVT_BKPT 0x4 ··· 91 94 int (*fn)(struct pt_regs *regs, unsigned int esr); 92 95 }; 93 96 94 - void register_step_hook(struct step_hook *hook); 95 - void unregister_step_hook(struct step_hook *hook); 97 + void register_user_step_hook(struct step_hook *hook); 98 + void unregister_user_step_hook(struct step_hook *hook); 99 + 100 + void register_kernel_step_hook(struct step_hook *hook); 101 + void unregister_kernel_step_hook(struct step_hook *hook); 96 102 97 103 struct break_hook { 98 104 struct list_head node; 99 - u32 esr_val; 100 - u32 esr_mask; 101 105 int (*fn)(struct pt_regs *regs, unsigned int esr); 106 + u16 imm; 107 + u16 mask; /* These bits are ignored when comparing with imm */ 102 108 }; 103 109 104 - void register_break_hook(struct break_hook *hook); 105 - void unregister_break_hook(struct break_hook *hook); 110 + void register_user_break_hook(struct break_hook *hook); 111 + void unregister_user_break_hook(struct break_hook *hook); 112 + 113 + void register_kernel_break_hook(struct break_hook *hook); 114 + void unregister_kernel_break_hook(struct break_hook *hook); 106 115 107 116 u8 debug_monitors_arch(void); 108 117
+3 -3
arch/arm64/include/asm/elf.h
··· 214 214 set_thread_flag(TIF_32BIT); \ 215 215 }) 216 216 #define COMPAT_ARCH_DLINFO 217 - extern int aarch32_setup_vectors_page(struct linux_binprm *bprm, 218 - int uses_interp); 217 + extern int aarch32_setup_additional_pages(struct linux_binprm *bprm, 218 + int uses_interp); 219 219 #define compat_arch_setup_additional_pages \ 220 - aarch32_setup_vectors_page 220 + aarch32_setup_additional_pages 221 221 222 222 #endif /* CONFIG_COMPAT */ 223 223
+3 -4
arch/arm64/include/asm/esr.h
··· 156 156 ESR_ELx_WFx_ISS_WFI) 157 157 158 158 /* BRK instruction trap from AArch64 state */ 159 - #define ESR_ELx_VAL_BRK64(imm) \ 160 - ((ESR_ELx_EC_BRK64 << ESR_ELx_EC_SHIFT) | ESR_ELx_IL | \ 161 - ((imm) & 0xffff)) 159 + #define ESR_ELx_BRK64_ISS_COMMENT_MASK 0xffff 162 160 163 161 /* ISS field definitions for System instruction traps */ 164 162 #define ESR_ELx_SYS64_ISS_RES0_SHIFT 22 ··· 196 198 /* 197 199 * User space cache operations have the following sysreg encoding 198 200 * in System instructions. 199 - * op0=1, op1=3, op2=1, crn=7, crm={ 5, 10, 11, 12, 14 }, WRITE (L=0) 201 + * op0=1, op1=3, op2=1, crn=7, crm={ 5, 10, 11, 12, 13, 14 }, WRITE (L=0) 200 202 */ 201 203 #define ESR_ELx_SYS64_ISS_CRM_DC_CIVAC 14 204 + #define ESR_ELx_SYS64_ISS_CRM_DC_CVADP 13 202 205 #define ESR_ELx_SYS64_ISS_CRM_DC_CVAP 12 203 206 #define ESR_ELx_SYS64_ISS_CRM_DC_CVAU 11 204 207 #define ESR_ELx_SYS64_ISS_CRM_DC_CVAC 10
+37 -22
arch/arm64/include/asm/futex.h
··· 23 23 24 24 #include <asm/errno.h> 25 25 26 + #define FUTEX_MAX_LOOPS 128 /* What's the largest number you can think of? */ 27 + 26 28 #define __futex_atomic_op(insn, ret, oldval, uaddr, tmp, oparg) \ 27 29 do { \ 30 + unsigned int loops = FUTEX_MAX_LOOPS; \ 31 + \ 28 32 uaccess_enable(); \ 29 33 asm volatile( \ 30 34 " prfm pstl1strm, %2\n" \ 31 35 "1: ldxr %w1, %2\n" \ 32 36 insn "\n" \ 33 37 "2: stlxr %w0, %w3, %2\n" \ 34 - " cbnz %w0, 1b\n" \ 35 - " dmb ish\n" \ 38 + " cbz %w0, 3f\n" \ 39 + " sub %w4, %w4, %w0\n" \ 40 + " cbnz %w4, 1b\n" \ 41 + " mov %w0, %w7\n" \ 36 42 "3:\n" \ 43 + " dmb ish\n" \ 37 44 " .pushsection .fixup,\"ax\"\n" \ 38 45 " .align 2\n" \ 39 - "4: mov %w0, %w5\n" \ 46 + "4: mov %w0, %w6\n" \ 40 47 " b 3b\n" \ 41 48 " .popsection\n" \ 42 49 _ASM_EXTABLE(1b, 4b) \ 43 50 _ASM_EXTABLE(2b, 4b) \ 44 - : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp) \ 45 - : "r" (oparg), "Ir" (-EFAULT) \ 51 + : "=&r" (ret), "=&r" (oldval), "+Q" (*uaddr), "=&r" (tmp), \ 52 + "+r" (loops) \ 53 + : "r" (oparg), "Ir" (-EFAULT), "Ir" (-EAGAIN) \ 46 54 : "memory"); \ 47 55 uaccess_disable(); \ 48 56 } while (0) ··· 65 57 66 58 switch (op) { 67 59 case FUTEX_OP_SET: 68 - __futex_atomic_op("mov %w3, %w4", 60 + __futex_atomic_op("mov %w3, %w5", 69 61 ret, oldval, uaddr, tmp, oparg); 70 62 break; 71 63 case FUTEX_OP_ADD: 72 - __futex_atomic_op("add %w3, %w1, %w4", 64 + __futex_atomic_op("add %w3, %w1, %w5", 73 65 ret, oldval, uaddr, tmp, oparg); 74 66 break; 75 67 case FUTEX_OP_OR: 76 - __futex_atomic_op("orr %w3, %w1, %w4", 68 + __futex_atomic_op("orr %w3, %w1, %w5", 77 69 ret, oldval, uaddr, tmp, oparg); 78 70 break; 79 71 case FUTEX_OP_ANDN: 80 - __futex_atomic_op("and %w3, %w1, %w4", 72 + __futex_atomic_op("and %w3, %w1, %w5", 81 73 ret, oldval, uaddr, tmp, ~oparg); 82 74 break; 83 75 case FUTEX_OP_XOR: 84 - __futex_atomic_op("eor %w3, %w1, %w4", 76 + __futex_atomic_op("eor %w3, %w1, %w5", 85 77 ret, oldval, uaddr, tmp, oparg); 86 78 break; 87 79 default: ··· 101 93 u32 oldval, u32 newval) 102 94 { 103 95 int ret = 0; 96 + unsigned int loops = FUTEX_MAX_LOOPS; 104 97 u32 val, tmp; 105 98 u32 __user *uaddr; 106 99 ··· 113 104 asm volatile("// futex_atomic_cmpxchg_inatomic\n" 114 105 " prfm pstl1strm, %2\n" 115 106 "1: ldxr %w1, %2\n" 116 - " sub %w3, %w1, %w4\n" 117 - " cbnz %w3, 3f\n" 118 - "2: stlxr %w3, %w5, %2\n" 119 - " cbnz %w3, 1b\n" 120 - " dmb ish\n" 107 + " sub %w3, %w1, %w5\n" 108 + " cbnz %w3, 4f\n" 109 + "2: stlxr %w3, %w6, %2\n" 110 + " cbz %w3, 3f\n" 111 + " sub %w4, %w4, %w3\n" 112 + " cbnz %w4, 1b\n" 113 + " mov %w0, %w8\n" 121 114 "3:\n" 115 + " dmb ish\n" 116 + "4:\n" 122 117 " .pushsection .fixup,\"ax\"\n" 123 - "4: mov %w0, %w6\n" 124 - " b 3b\n" 118 + "5: mov %w0, %w7\n" 119 + " b 4b\n" 125 120 " .popsection\n" 126 - _ASM_EXTABLE(1b, 4b) 127 - _ASM_EXTABLE(2b, 4b) 128 - : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp) 129 - : "r" (oldval), "r" (newval), "Ir" (-EFAULT) 121 + _ASM_EXTABLE(1b, 5b) 122 + _ASM_EXTABLE(2b, 5b) 123 + : "+r" (ret), "=&r" (val), "+Q" (*uaddr), "=&r" (tmp), "+r" (loops) 124 + : "r" (oldval), "r" (newval), "Ir" (-EFAULT), "Ir" (-EAGAIN) 130 125 : "memory"); 131 126 uaccess_disable(); 132 127 133 - *uval = val; 128 + if (!ret) 129 + *uval = val; 130 + 134 131 return ret; 135 132 } 136 133
+58 -2
arch/arm64/include/asm/hwcap.h
··· 17 17 #define __ASM_HWCAP_H 18 18 19 19 #include <uapi/asm/hwcap.h> 20 + #include <asm/cpufeature.h> 20 21 21 22 #define COMPAT_HWCAP_HALF (1 << 1) 22 23 #define COMPAT_HWCAP_THUMB (1 << 2) ··· 41 40 #define COMPAT_HWCAP2_CRC32 (1 << 4) 42 41 43 42 #ifndef __ASSEMBLY__ 43 + #include <linux/log2.h> 44 + 45 + /* 46 + * For userspace we represent hwcaps as a collection of HWCAP{,2}_x bitfields 47 + * as described in uapi/asm/hwcap.h. For the kernel we represent hwcaps as 48 + * natural numbers (in a single range of size MAX_CPU_FEATURES) defined here 49 + * with prefix KERNEL_HWCAP_ mapped to their HWCAP{,2}_x counterpart. 50 + * 51 + * Hwcaps should be set and tested within the kernel via the 52 + * cpu_{set,have}_named_feature(feature) where feature is the unique suffix 53 + * of KERNEL_HWCAP_{feature}. 54 + */ 55 + #define __khwcap_feature(x) const_ilog2(HWCAP_ ## x) 56 + #define KERNEL_HWCAP_FP __khwcap_feature(FP) 57 + #define KERNEL_HWCAP_ASIMD __khwcap_feature(ASIMD) 58 + #define KERNEL_HWCAP_EVTSTRM __khwcap_feature(EVTSTRM) 59 + #define KERNEL_HWCAP_AES __khwcap_feature(AES) 60 + #define KERNEL_HWCAP_PMULL __khwcap_feature(PMULL) 61 + #define KERNEL_HWCAP_SHA1 __khwcap_feature(SHA1) 62 + #define KERNEL_HWCAP_SHA2 __khwcap_feature(SHA2) 63 + #define KERNEL_HWCAP_CRC32 __khwcap_feature(CRC32) 64 + #define KERNEL_HWCAP_ATOMICS __khwcap_feature(ATOMICS) 65 + #define KERNEL_HWCAP_FPHP __khwcap_feature(FPHP) 66 + #define KERNEL_HWCAP_ASIMDHP __khwcap_feature(ASIMDHP) 67 + #define KERNEL_HWCAP_CPUID __khwcap_feature(CPUID) 68 + #define KERNEL_HWCAP_ASIMDRDM __khwcap_feature(ASIMDRDM) 69 + #define KERNEL_HWCAP_JSCVT __khwcap_feature(JSCVT) 70 + #define KERNEL_HWCAP_FCMA __khwcap_feature(FCMA) 71 + #define KERNEL_HWCAP_LRCPC __khwcap_feature(LRCPC) 72 + #define KERNEL_HWCAP_DCPOP __khwcap_feature(DCPOP) 73 + #define KERNEL_HWCAP_SHA3 __khwcap_feature(SHA3) 74 + #define KERNEL_HWCAP_SM3 __khwcap_feature(SM3) 75 + #define KERNEL_HWCAP_SM4 __khwcap_feature(SM4) 76 + #define KERNEL_HWCAP_ASIMDDP __khwcap_feature(ASIMDDP) 77 + #define KERNEL_HWCAP_SHA512 __khwcap_feature(SHA512) 78 + #define KERNEL_HWCAP_SVE __khwcap_feature(SVE) 79 + #define KERNEL_HWCAP_ASIMDFHM __khwcap_feature(ASIMDFHM) 80 + #define KERNEL_HWCAP_DIT __khwcap_feature(DIT) 81 + #define KERNEL_HWCAP_USCAT __khwcap_feature(USCAT) 82 + #define KERNEL_HWCAP_ILRCPC __khwcap_feature(ILRCPC) 83 + #define KERNEL_HWCAP_FLAGM __khwcap_feature(FLAGM) 84 + #define KERNEL_HWCAP_SSBS __khwcap_feature(SSBS) 85 + #define KERNEL_HWCAP_SB __khwcap_feature(SB) 86 + #define KERNEL_HWCAP_PACA __khwcap_feature(PACA) 87 + #define KERNEL_HWCAP_PACG __khwcap_feature(PACG) 88 + 89 + #define __khwcap2_feature(x) (const_ilog2(HWCAP2_ ## x) + 32) 90 + #define KERNEL_HWCAP_DCPODP __khwcap2_feature(DCPODP) 91 + #define KERNEL_HWCAP_SVE2 __khwcap2_feature(SVE2) 92 + #define KERNEL_HWCAP_SVEAES __khwcap2_feature(SVEAES) 93 + #define KERNEL_HWCAP_SVEPMULL __khwcap2_feature(SVEPMULL) 94 + #define KERNEL_HWCAP_SVEBITPERM __khwcap2_feature(SVEBITPERM) 95 + #define KERNEL_HWCAP_SVESHA3 __khwcap2_feature(SVESHA3) 96 + #define KERNEL_HWCAP_SVESM4 __khwcap2_feature(SVESM4) 97 + 44 98 /* 45 99 * This yields a mask that user programs can use to figure out what 46 100 * instruction set this cpu supports. 47 101 */ 48 - #define ELF_HWCAP (elf_hwcap) 102 + #define ELF_HWCAP cpu_get_elf_hwcap() 103 + #define ELF_HWCAP2 cpu_get_elf_hwcap2() 49 104 50 105 #ifdef CONFIG_COMPAT 51 106 #define COMPAT_ELF_HWCAP (compat_elf_hwcap) ··· 117 60 #endif 118 61 }; 119 62 120 - extern unsigned long elf_hwcap; 121 63 #endif 122 64 #endif
+4 -4
arch/arm64/include/asm/irqflags.h
··· 43 43 asm volatile(ALTERNATIVE( 44 44 "msr daifclr, #2 // arch_local_irq_enable\n" 45 45 "nop", 46 - "msr_s " __stringify(SYS_ICC_PMR_EL1) ",%0\n" 46 + __msr_s(SYS_ICC_PMR_EL1, "%0") 47 47 "dsb sy", 48 48 ARM64_HAS_IRQ_PRIO_MASKING) 49 49 : ··· 55 55 { 56 56 asm volatile(ALTERNATIVE( 57 57 "msr daifset, #2 // arch_local_irq_disable", 58 - "msr_s " __stringify(SYS_ICC_PMR_EL1) ", %0", 58 + __msr_s(SYS_ICC_PMR_EL1, "%0"), 59 59 ARM64_HAS_IRQ_PRIO_MASKING) 60 60 : 61 61 : "r" ((unsigned long) GIC_PRIO_IRQOFF) ··· 86 86 "mov %0, %1\n" 87 87 "nop\n" 88 88 "nop", 89 - "mrs_s %0, " __stringify(SYS_ICC_PMR_EL1) "\n" 89 + __mrs_s("%0", SYS_ICC_PMR_EL1) 90 90 "ands %1, %1, " __stringify(PSR_I_BIT) "\n" 91 91 "csel %0, %0, %2, eq", 92 92 ARM64_HAS_IRQ_PRIO_MASKING) ··· 116 116 asm volatile(ALTERNATIVE( 117 117 "msr daif, %0\n" 118 118 "nop", 119 - "msr_s " __stringify(SYS_ICC_PMR_EL1) ", %0\n" 119 + __msr_s(SYS_ICC_PMR_EL1, "%0") 120 120 "dsb sy", 121 121 ARM64_HAS_IRQ_PRIO_MASKING) 122 122 : "+r" (flags)
-2
arch/arm64/include/asm/kprobes.h
··· 54 54 int kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr); 55 55 int kprobe_exceptions_notify(struct notifier_block *self, 56 56 unsigned long val, void *data); 57 - int kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr); 58 - int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr); 59 57 void kretprobe_trampoline(void); 60 58 void __kprobes *trampoline_probe_handler(struct pt_regs *regs); 61 59
+2 -2
arch/arm64/include/asm/kvm_hyp.h
··· 30 30 ({ \ 31 31 u64 reg; \ 32 32 asm volatile(ALTERNATIVE("mrs %0, " __stringify(r##nvh),\ 33 - "mrs_s %0, " __stringify(r##vh),\ 33 + __mrs_s("%0", r##vh), \ 34 34 ARM64_HAS_VIRT_HOST_EXTN) \ 35 35 : "=r" (reg)); \ 36 36 reg; \ ··· 40 40 do { \ 41 41 u64 __val = (u64)(v); \ 42 42 asm volatile(ALTERNATIVE("msr " __stringify(r##nvh) ", %x0",\ 43 - "msr_s " __stringify(r##vh) ", %x0",\ 43 + __msr_s(r##vh, "%x0"), \ 44 44 ARM64_HAS_VIRT_HOST_EXTN) \ 45 45 : : "rZ" (__val)); \ 46 46 } while (0)
+1 -1
arch/arm64/include/asm/memory.h
··· 302 302 */ 303 303 #define ARCH_PFN_OFFSET ((unsigned long)PHYS_PFN_OFFSET) 304 304 305 - #ifndef CONFIG_SPARSEMEM_VMEMMAP 305 + #if !defined(CONFIG_SPARSEMEM_VMEMMAP) || defined(CONFIG_DEBUG_VIRTUAL) 306 306 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 307 307 #define _virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 308 308 #else
+11 -1
arch/arm64/include/asm/pgalloc.h
··· 33 33 34 34 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) 35 35 { 36 - return (pmd_t *)__get_free_page(PGALLOC_GFP); 36 + struct page *page; 37 + 38 + page = alloc_page(PGALLOC_GFP); 39 + if (!page) 40 + return NULL; 41 + if (!pgtable_pmd_page_ctor(page)) { 42 + __free_page(page); 43 + return NULL; 44 + } 45 + return page_address(page); 37 46 } 38 47 39 48 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp) 40 49 { 41 50 BUG_ON((unsigned long)pmdp & (PAGE_SIZE-1)); 51 + pgtable_pmd_page_dtor(virt_to_page(pmdp)); 42 52 free_page((unsigned long)pmdp); 43 53 } 44 54
+2 -3
arch/arm64/include/asm/pgtable.h
··· 478 478 return __pmd_to_phys(pmd); 479 479 } 480 480 481 + static inline void pte_unmap(pte_t *pte) { } 482 + 481 483 /* Find an entry in the third-level page table. */ 482 484 #define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) 483 485 ··· 487 485 #define pte_offset_kernel(dir,addr) ((pte_t *)__va(pte_offset_phys((dir), (addr)))) 488 486 489 487 #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr)) 490 - #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr)) 491 - #define pte_unmap(pte) do { } while (0) 492 - #define pte_unmap_nested(pte) do { } while (0) 493 488 494 489 #define pte_set_fixmap(addr) ((pte_t *)set_fixmap_offset(FIX_PTE, addr)) 495 490 #define pte_set_fixmap_offset(pmd, addr) pte_set_fixmap(pte_offset_phys(pmd, addr))
+1 -1
arch/arm64/include/asm/pointer_auth.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 #ifndef __ASM_POINTER_AUTH_H 3 3 #define __ASM_POINTER_AUTH_H 4 4
+8
arch/arm64/include/asm/processor.h
··· 57 57 #define TASK_SIZE_64 (UL(1) << vabits_user) 58 58 59 59 #ifdef CONFIG_COMPAT 60 + #if defined(CONFIG_ARM64_64K_PAGES) && defined(CONFIG_KUSER_HELPERS) 61 + /* 62 + * With CONFIG_ARM64_64K_PAGES enabled, the last page is occupied 63 + * by the compat vectors page. 64 + */ 60 65 #define TASK_SIZE_32 UL(0x100000000) 66 + #else 67 + #define TASK_SIZE_32 (UL(0x100000000) - PAGE_SIZE) 68 + #endif /* CONFIG_ARM64_64K_PAGES */ 61 69 #define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ 62 70 TASK_SIZE_32 : TASK_SIZE_64) 63 71 #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
+22
arch/arm64/include/asm/ptrace.h
··· 305 305 return regs->regs[0]; 306 306 } 307 307 308 + /** 309 + * regs_get_kernel_argument() - get Nth function argument in kernel 310 + * @regs: pt_regs of that context 311 + * @n: function argument number (start from 0) 312 + * 313 + * regs_get_argument() returns @n th argument of the function call. 314 + * 315 + * Note that this chooses the most likely register mapping. In very rare 316 + * cases this may not return correct data, for example, if one of the 317 + * function parameters is 16 bytes or bigger. In such cases, we cannot 318 + * get access the parameter correctly and the register assignment of 319 + * subsequent parameters will be shifted. 320 + */ 321 + static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, 322 + unsigned int n) 323 + { 324 + #define NR_REG_ARGUMENTS 8 325 + if (n < NR_REG_ARGUMENTS) 326 + return pt_regs_read_reg(regs, n); 327 + return 0; 328 + } 329 + 308 330 /* We must avoid circular header include via sched.h */ 309 331 struct task_struct; 310 332 int valid_user_regs(struct user_pt_regs *regs, struct task_struct *task);
+1 -1
arch/arm64/include/asm/sdei.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 // Copyright (C) 2017 Arm Ltd. 3 3 #ifndef __ASM_SDEI_H 4 4 #define __ASM_SDEI_H
-2
arch/arm64/include/asm/signal32.h
··· 20 20 #ifdef CONFIG_COMPAT 21 21 #include <linux/compat.h> 22 22 23 - #define AARCH32_KERN_SIGRET_CODE_OFFSET 0x500 24 - 25 23 int compat_setup_frame(int usig, struct ksignal *ksig, sigset_t *set, 26 24 struct pt_regs *regs); 27 25 int compat_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
+2 -2
arch/arm64/include/asm/stage2_pgtable.h
··· 119 119 static inline void stage2_pud_free(struct kvm *kvm, pud_t *pud) 120 120 { 121 121 if (kvm_stage2_has_pud(kvm)) 122 - pud_free(NULL, pud); 122 + free_page((unsigned long)pud); 123 123 } 124 124 125 125 static inline bool stage2_pud_table_empty(struct kvm *kvm, pud_t *pudp) ··· 192 192 static inline void stage2_pmd_free(struct kvm *kvm, pmd_t *pmd) 193 193 { 194 194 if (kvm_stage2_has_pmd(kvm)) 195 - pmd_free(NULL, pmd); 195 + free_page((unsigned long)pmd); 196 196 } 197 197 198 198 static inline bool stage2_pud_huge(struct kvm *kvm, pud_t pud)
+46 -13
arch/arm64/include/asm/sysreg.h
··· 606 606 #define ID_AA64PFR1_SSBS_PSTATE_ONLY 1 607 607 #define ID_AA64PFR1_SSBS_PSTATE_INSNS 2 608 608 609 + /* id_aa64zfr0 */ 610 + #define ID_AA64ZFR0_SM4_SHIFT 40 611 + #define ID_AA64ZFR0_SHA3_SHIFT 32 612 + #define ID_AA64ZFR0_BITPERM_SHIFT 16 613 + #define ID_AA64ZFR0_AES_SHIFT 4 614 + #define ID_AA64ZFR0_SVEVER_SHIFT 0 615 + 616 + #define ID_AA64ZFR0_SM4 0x1 617 + #define ID_AA64ZFR0_SHA3 0x1 618 + #define ID_AA64ZFR0_BITPERM 0x1 619 + #define ID_AA64ZFR0_AES 0x1 620 + #define ID_AA64ZFR0_AES_PMULL 0x2 621 + #define ID_AA64ZFR0_SVEVER_SVE2 0x1 622 + 609 623 /* id_aa64mmfr0 */ 610 624 #define ID_AA64MMFR0_TGRAN4_SHIFT 28 611 625 #define ID_AA64MMFR0_TGRAN64_SHIFT 24 ··· 760 746 #include <linux/build_bug.h> 761 747 #include <linux/types.h> 762 748 763 - asm( 764 - " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" 765 - " .equ .L__reg_num_x\\num, \\num\n" 766 - " .endr\n" 749 + #define __DEFINE_MRS_MSR_S_REGNUM \ 750 + " .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n" \ 751 + " .equ .L__reg_num_x\\num, \\num\n" \ 752 + " .endr\n" \ 767 753 " .equ .L__reg_num_xzr, 31\n" 768 - "\n" 769 - " .macro mrs_s, rt, sreg\n" 770 - __emit_inst(0xd5200000|(\\sreg)|(.L__reg_num_\\rt)) 754 + 755 + #define DEFINE_MRS_S \ 756 + __DEFINE_MRS_MSR_S_REGNUM \ 757 + " .macro mrs_s, rt, sreg\n" \ 758 + __emit_inst(0xd5200000|(\\sreg)|(.L__reg_num_\\rt)) \ 771 759 " .endm\n" 772 - "\n" 773 - " .macro msr_s, sreg, rt\n" 774 - __emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt)) 760 + 761 + #define DEFINE_MSR_S \ 762 + __DEFINE_MRS_MSR_S_REGNUM \ 763 + " .macro msr_s, sreg, rt\n" \ 764 + __emit_inst(0xd5000000|(\\sreg)|(.L__reg_num_\\rt)) \ 775 765 " .endm\n" 776 - ); 766 + 767 + #define UNDEFINE_MRS_S \ 768 + " .purgem mrs_s\n" 769 + 770 + #define UNDEFINE_MSR_S \ 771 + " .purgem msr_s\n" 772 + 773 + #define __mrs_s(v, r) \ 774 + DEFINE_MRS_S \ 775 + " mrs_s " v ", " __stringify(r) "\n" \ 776 + UNDEFINE_MRS_S 777 + 778 + #define __msr_s(r, v) \ 779 + DEFINE_MSR_S \ 780 + " msr_s " __stringify(r) ", " v "\n" \ 781 + UNDEFINE_MSR_S 777 782 778 783 /* 779 784 * Unlike read_cpuid, calls to read_sysreg are never expected to be ··· 820 787 */ 821 788 #define read_sysreg_s(r) ({ \ 822 789 u64 __val; \ 823 - asm volatile("mrs_s %0, " __stringify(r) : "=r" (__val)); \ 790 + asm volatile(__mrs_s("%0", r) : "=r" (__val)); \ 824 791 __val; \ 825 792 }) 826 793 827 794 #define write_sysreg_s(v, r) do { \ 828 795 u64 __val = (u64)(v); \ 829 - asm volatile("msr_s " __stringify(r) ", %x0" : : "rZ" (__val)); \ 796 + asm volatile(__msr_s(r, "%x0") : : "rZ" (__val)); \ 830 797 } while (0) 831 798 832 799 /*
-1
arch/arm64/include/asm/system_misc.h
··· 41 41 int sig, int code, const char *name); 42 42 43 43 struct mm_struct; 44 - extern void show_pte(unsigned long addr); 45 44 extern void __show_regs(struct pt_regs *); 46 45 47 46 extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
+4 -1
arch/arm64/include/asm/tlb.h
··· 63 63 static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, 64 64 unsigned long addr) 65 65 { 66 - tlb_remove_table(tlb, virt_to_page(pmdp)); 66 + struct page *page = virt_to_page(pmdp); 67 + 68 + pgtable_pmd_page_dtor(page); 69 + tlb_remove_table(tlb, page); 67 70 } 68 71 #endif 69 72
+1
arch/arm64/include/asm/vdso_datapage.h
··· 38 38 __u32 tz_minuteswest; /* Whacky timezone stuff */ 39 39 __u32 tz_dsttime; 40 40 __u32 use_syscall; 41 + __u32 hrtimer_res; 41 42 }; 42 43 43 44 #endif /* !__ASSEMBLY__ */
+1 -1
arch/arm64/include/asm/vmap_stack.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 2 // Copyright (C) 2017 Arm Ltd. 3 3 #ifndef __ASM_VMAP_STACK_H 4 4 #define __ASM_VMAP_STACK_H
+12 -1
arch/arm64/include/uapi/asm/hwcap.h
··· 18 18 #define _UAPI__ASM_HWCAP_H 19 19 20 20 /* 21 - * HWCAP flags - for elf_hwcap (in kernel) and AT_HWCAP 21 + * HWCAP flags - for AT_HWCAP 22 22 */ 23 23 #define HWCAP_FP (1 << 0) 24 24 #define HWCAP_ASIMD (1 << 1) ··· 52 52 #define HWCAP_SB (1 << 29) 53 53 #define HWCAP_PACA (1 << 30) 54 54 #define HWCAP_PACG (1UL << 31) 55 + 56 + /* 57 + * HWCAP2 flags - for AT_HWCAP2 58 + */ 59 + #define HWCAP2_DCPODP (1 << 0) 60 + #define HWCAP2_SVE2 (1 << 1) 61 + #define HWCAP2_SVEAES (1 << 2) 62 + #define HWCAP2_SVEPMULL (1 << 3) 63 + #define HWCAP2_SVEBITPERM (1 << 4) 64 + #define HWCAP2_SVESHA3 (1 << 5) 65 + #define HWCAP2_SVESM4 (1 << 6) 55 66 56 67 #endif /* _UAPI__ASM_HWCAP_H */
+6 -5
arch/arm64/kernel/Makefile
··· 7 7 AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 8 8 CFLAGS_armv8_deprecated.o := -I$(src) 9 9 10 - CFLAGS_REMOVE_ftrace.o = -pg 11 - CFLAGS_REMOVE_insn.o = -pg 12 - CFLAGS_REMOVE_return_address.o = -pg 10 + CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) 11 + CFLAGS_REMOVE_insn.o = $(CC_FLAGS_FTRACE) 12 + CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) 13 13 14 14 # Object file lists. 15 15 obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ ··· 27 27 $(obj)/%.stub.o: $(obj)/%.o FORCE 28 28 $(call if_changed,objcopy) 29 29 30 - obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ 31 - sys_compat.o 30 + obj-$(CONFIG_COMPAT) += sys32.o signal32.o \ 31 + sigreturn32.o sys_compat.o 32 + obj-$(CONFIG_KUSER_HELPERS) += kuser32.o 32 33 obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o 33 34 obj-$(CONFIG_MODULES) += module.o 34 35 obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
+1 -1
arch/arm64/kernel/asm-offsets.c
··· 94 94 DEFINE(CLOCK_REALTIME, CLOCK_REALTIME); 95 95 DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC); 96 96 DEFINE(CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_RAW); 97 - DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC); 97 + DEFINE(CLOCK_REALTIME_RES, offsetof(struct vdso_data, hrtimer_res)); 98 98 DEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE); 99 99 DEFINE(CLOCK_MONOTONIC_COARSE,CLOCK_MONOTONIC_COARSE); 100 100 DEFINE(CLOCK_COARSE_RES, LOW_RES_NSEC);
+188 -68
arch/arm64/kernel/cpu_errata.c
··· 19 19 #include <linux/arm-smccc.h> 20 20 #include <linux/psci.h> 21 21 #include <linux/types.h> 22 + #include <linux/cpu.h> 22 23 #include <asm/cpu.h> 23 24 #include <asm/cputype.h> 24 25 #include <asm/cpufeature.h> ··· 110 109 111 110 atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); 112 111 113 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 114 112 #include <asm/mmu_context.h> 115 113 #include <asm/cacheflush.h> 116 114 ··· 131 131 __flush_icache_range((uintptr_t)dst, (uintptr_t)dst + SZ_2K); 132 132 } 133 133 134 - static void __install_bp_hardening_cb(bp_hardening_cb_t fn, 135 - const char *hyp_vecs_start, 136 - const char *hyp_vecs_end) 134 + static void install_bp_hardening_cb(bp_hardening_cb_t fn, 135 + const char *hyp_vecs_start, 136 + const char *hyp_vecs_end) 137 137 { 138 138 static DEFINE_RAW_SPINLOCK(bp_lock); 139 139 int cpu, slot = -1; ··· 169 169 #define __smccc_workaround_1_smc_start NULL 170 170 #define __smccc_workaround_1_smc_end NULL 171 171 172 - static void __install_bp_hardening_cb(bp_hardening_cb_t fn, 172 + static void install_bp_hardening_cb(bp_hardening_cb_t fn, 173 173 const char *hyp_vecs_start, 174 174 const char *hyp_vecs_end) 175 175 { 176 176 __this_cpu_write(bp_hardening_data.fn, fn); 177 177 } 178 178 #endif /* CONFIG_KVM_INDIRECT_VECTORS */ 179 - 180 - static void install_bp_hardening_cb(const struct arm64_cpu_capabilities *entry, 181 - bp_hardening_cb_t fn, 182 - const char *hyp_vecs_start, 183 - const char *hyp_vecs_end) 184 - { 185 - u64 pfr0; 186 - 187 - if (!entry->matches(entry, SCOPE_LOCAL_CPU)) 188 - return; 189 - 190 - pfr0 = read_cpuid(ID_AA64PFR0_EL1); 191 - if (cpuid_feature_extract_unsigned_field(pfr0, ID_AA64PFR0_CSV2_SHIFT)) 192 - return; 193 - 194 - __install_bp_hardening_cb(fn, hyp_vecs_start, hyp_vecs_end); 195 - } 196 179 197 180 #include <uapi/linux/psci.h> 198 181 #include <linux/arm-smccc.h> ··· 203 220 : "=&r" (tmp)); 204 221 } 205 222 206 - static void 207 - enable_smccc_arch_workaround_1(const struct arm64_cpu_capabilities *entry) 223 + static bool __nospectre_v2; 224 + static int __init parse_nospectre_v2(char *str) 225 + { 226 + __nospectre_v2 = true; 227 + return 0; 228 + } 229 + early_param("nospectre_v2", parse_nospectre_v2); 230 + 231 + /* 232 + * -1: No workaround 233 + * 0: No workaround required 234 + * 1: Workaround installed 235 + */ 236 + static int detect_harden_bp_fw(void) 208 237 { 209 238 bp_hardening_cb_t cb; 210 239 void *smccc_start, *smccc_end; 211 240 struct arm_smccc_res res; 212 241 u32 midr = read_cpuid_id(); 213 242 214 - if (!entry->matches(entry, SCOPE_LOCAL_CPU)) 215 - return; 216 - 217 243 if (psci_ops.smccc_version == SMCCC_VERSION_1_0) 218 - return; 244 + return -1; 219 245 220 246 switch (psci_ops.conduit) { 221 247 case PSCI_CONDUIT_HVC: 222 248 arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, 223 249 ARM_SMCCC_ARCH_WORKAROUND_1, &res); 224 - if ((int)res.a0 < 0) 225 - return; 226 - cb = call_hvc_arch_workaround_1; 227 - /* This is a guest, no need to patch KVM vectors */ 228 - smccc_start = NULL; 229 - smccc_end = NULL; 250 + switch ((int)res.a0) { 251 + case 1: 252 + /* Firmware says we're just fine */ 253 + return 0; 254 + case 0: 255 + cb = call_hvc_arch_workaround_1; 256 + /* This is a guest, no need to patch KVM vectors */ 257 + smccc_start = NULL; 258 + smccc_end = NULL; 259 + break; 260 + default: 261 + return -1; 262 + } 230 263 break; 231 264 232 265 case PSCI_CONDUIT_SMC: 233 266 arm_smccc_1_1_smc(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, 234 267 ARM_SMCCC_ARCH_WORKAROUND_1, &res); 235 - if ((int)res.a0 < 0) 236 - return; 237 - cb = call_smc_arch_workaround_1; 238 - smccc_start = __smccc_workaround_1_smc_start; 239 - smccc_end = __smccc_workaround_1_smc_end; 268 + switch ((int)res.a0) { 269 + case 1: 270 + /* Firmware says we're just fine */ 271 + return 0; 272 + case 0: 273 + cb = call_smc_arch_workaround_1; 274 + smccc_start = __smccc_workaround_1_smc_start; 275 + smccc_end = __smccc_workaround_1_smc_end; 276 + break; 277 + default: 278 + return -1; 279 + } 240 280 break; 241 281 242 282 default: 243 - return; 283 + return -1; 244 284 } 245 285 246 286 if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || 247 287 ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) 248 288 cb = qcom_link_stack_sanitization; 249 289 250 - install_bp_hardening_cb(entry, cb, smccc_start, smccc_end); 290 + if (IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) 291 + install_bp_hardening_cb(cb, smccc_start, smccc_end); 251 292 252 - return; 293 + return 1; 253 294 } 254 - #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ 255 295 256 - #ifdef CONFIG_ARM64_SSBD 257 296 DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required); 258 297 259 298 int ssbd_state __read_mostly = ARM64_SSBD_KERNEL; 299 + static bool __ssb_safe = true; 260 300 261 301 static const struct ssbd_options { 262 302 const char *str; ··· 349 343 350 344 void arm64_set_ssbd_mitigation(bool state) 351 345 { 346 + if (!IS_ENABLED(CONFIG_ARM64_SSBD)) { 347 + pr_info_once("SSBD disabled by kernel configuration\n"); 348 + return; 349 + } 350 + 352 351 if (this_cpu_has_cap(ARM64_SSBS)) { 353 352 if (state) 354 353 asm volatile(SET_PSTATE_SSBS(0)); ··· 383 372 struct arm_smccc_res res; 384 373 bool required = true; 385 374 s32 val; 375 + bool this_cpu_safe = false; 386 376 387 377 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); 388 378 379 + if (cpu_mitigations_off()) 380 + ssbd_state = ARM64_SSBD_FORCE_DISABLE; 381 + 382 + /* delay setting __ssb_safe until we get a firmware response */ 383 + if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list)) 384 + this_cpu_safe = true; 385 + 389 386 if (this_cpu_has_cap(ARM64_SSBS)) { 387 + if (!this_cpu_safe) 388 + __ssb_safe = false; 390 389 required = false; 391 390 goto out_printmsg; 392 391 } 393 392 394 393 if (psci_ops.smccc_version == SMCCC_VERSION_1_0) { 395 394 ssbd_state = ARM64_SSBD_UNKNOWN; 395 + if (!this_cpu_safe) 396 + __ssb_safe = false; 396 397 return false; 397 398 } 398 399 ··· 421 398 422 399 default: 423 400 ssbd_state = ARM64_SSBD_UNKNOWN; 401 + if (!this_cpu_safe) 402 + __ssb_safe = false; 424 403 return false; 425 404 } 426 405 ··· 431 406 switch (val) { 432 407 case SMCCC_RET_NOT_SUPPORTED: 433 408 ssbd_state = ARM64_SSBD_UNKNOWN; 409 + if (!this_cpu_safe) 410 + __ssb_safe = false; 434 411 return false; 435 412 413 + /* machines with mixed mitigation requirements must not return this */ 436 414 case SMCCC_RET_NOT_REQUIRED: 437 415 pr_info_once("%s mitigation not required\n", entry->desc); 438 416 ssbd_state = ARM64_SSBD_MITIGATED; 439 417 return false; 440 418 441 419 case SMCCC_RET_SUCCESS: 420 + __ssb_safe = false; 442 421 required = true; 443 422 break; 444 423 ··· 452 423 453 424 default: 454 425 WARN_ON(1); 426 + if (!this_cpu_safe) 427 + __ssb_safe = false; 455 428 return false; 456 429 } 457 430 ··· 493 462 494 463 return required; 495 464 } 496 - #endif /* CONFIG_ARM64_SSBD */ 465 + 466 + /* known invulnerable cores */ 467 + static const struct midr_range arm64_ssb_cpus[] = { 468 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), 469 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), 470 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), 471 + {}, 472 + }; 497 473 498 474 static void __maybe_unused 499 475 cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused) ··· 545 507 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \ 546 508 CAP_MIDR_RANGE_LIST(midr_list) 547 509 548 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 510 + /* Track overall mitigation state. We are only mitigated if all cores are ok */ 511 + static bool __hardenbp_enab = true; 512 + static bool __spectrev2_safe = true; 549 513 550 514 /* 551 - * List of CPUs where we need to issue a psci call to 552 - * harden the branch predictor. 515 + * List of CPUs that do not need any Spectre-v2 mitigation at all. 553 516 */ 554 - static const struct midr_range arm64_bp_harden_smccc_cpus[] = { 555 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 556 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 557 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), 558 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), 559 - MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), 560 - MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), 561 - MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR_V1), 562 - MIDR_ALL_VERSIONS(MIDR_QCOM_FALKOR), 563 - MIDR_ALL_VERSIONS(MIDR_NVIDIA_DENVER), 564 - {}, 517 + static const struct midr_range spectre_v2_safe_list[] = { 518 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), 519 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), 520 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), 521 + { /* sentinel */ } 565 522 }; 566 523 567 - #endif 524 + /* 525 + * Track overall bp hardening for all heterogeneous cores in the machine. 526 + * We are only considered "safe" if all booted cores are known safe. 527 + */ 528 + static bool __maybe_unused 529 + check_branch_predictor(const struct arm64_cpu_capabilities *entry, int scope) 530 + { 531 + int need_wa; 532 + 533 + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible()); 534 + 535 + /* If the CPU has CSV2 set, we're safe */ 536 + if (cpuid_feature_extract_unsigned_field(read_cpuid(ID_AA64PFR0_EL1), 537 + ID_AA64PFR0_CSV2_SHIFT)) 538 + return false; 539 + 540 + /* Alternatively, we have a list of unaffected CPUs */ 541 + if (is_midr_in_range_list(read_cpuid_id(), spectre_v2_safe_list)) 542 + return false; 543 + 544 + /* Fallback to firmware detection */ 545 + need_wa = detect_harden_bp_fw(); 546 + if (!need_wa) 547 + return false; 548 + 549 + __spectrev2_safe = false; 550 + 551 + if (!IS_ENABLED(CONFIG_HARDEN_BRANCH_PREDICTOR)) { 552 + pr_warn_once("spectrev2 mitigation disabled by kernel configuration\n"); 553 + __hardenbp_enab = false; 554 + return false; 555 + } 556 + 557 + /* forced off */ 558 + if (__nospectre_v2 || cpu_mitigations_off()) { 559 + pr_info_once("spectrev2 mitigation disabled by command line option\n"); 560 + __hardenbp_enab = false; 561 + return false; 562 + } 563 + 564 + if (need_wa < 0) { 565 + pr_warn_once("ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware\n"); 566 + __hardenbp_enab = false; 567 + } 568 + 569 + return (need_wa > 0); 570 + } 568 571 569 572 #ifdef CONFIG_HARDEN_EL2_VECTORS 570 573 ··· 678 599 /* Cortex-A53 r0p[01] : ARM errata 819472 */ 679 600 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1), 680 601 #endif 602 + {}, 603 + }; 604 + #endif 605 + 606 + #ifdef CONFIG_ARM64_ERRATUM_1188873 607 + static const struct midr_range erratum_1188873_list[] = { 608 + /* Cortex-A76 r0p0 to r2p0 */ 609 + MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0), 610 + /* Neoverse-N1 r0p0 to r2p0 */ 611 + MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 2, 0), 681 612 {}, 682 613 }; 683 614 #endif ··· 790 701 ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), 791 702 }, 792 703 #endif 793 - #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 794 704 { 795 705 .capability = ARM64_HARDEN_BRANCH_PREDICTOR, 796 - .cpu_enable = enable_smccc_arch_workaround_1, 797 - ERRATA_MIDR_RANGE_LIST(arm64_bp_harden_smccc_cpus), 706 + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, 707 + .matches = check_branch_predictor, 798 708 }, 799 - #endif 800 709 #ifdef CONFIG_HARDEN_EL2_VECTORS 801 710 { 802 711 .desc = "EL2 vector hardening", ··· 802 715 ERRATA_MIDR_RANGE_LIST(arm64_harden_el2_vectors), 803 716 }, 804 717 #endif 805 - #ifdef CONFIG_ARM64_SSBD 806 718 { 807 719 .desc = "Speculative Store Bypass Disable", 808 720 .capability = ARM64_SSBD, 809 721 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, 810 722 .matches = has_ssbd_mitigation, 723 + .midr_range_list = arm64_ssb_cpus, 811 724 }, 812 - #endif 813 725 #ifdef CONFIG_ARM64_ERRATUM_1188873 814 726 { 815 - /* Cortex-A76 r0p0 to r2p0 */ 816 727 .desc = "ARM erratum 1188873", 817 728 .capability = ARM64_WORKAROUND_1188873, 818 - ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0), 729 + ERRATA_MIDR_RANGE_LIST(erratum_1188873_list), 819 730 }, 820 731 #endif 821 732 #ifdef CONFIG_ARM64_ERRATUM_1165522 ··· 827 742 { 828 743 } 829 744 }; 745 + 746 + ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr, 747 + char *buf) 748 + { 749 + return sprintf(buf, "Mitigation: __user pointer sanitization\n"); 750 + } 751 + 752 + ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, 753 + char *buf) 754 + { 755 + if (__spectrev2_safe) 756 + return sprintf(buf, "Not affected\n"); 757 + 758 + if (__hardenbp_enab) 759 + return sprintf(buf, "Mitigation: Branch predictor hardening\n"); 760 + 761 + return sprintf(buf, "Vulnerable\n"); 762 + } 763 + 764 + ssize_t cpu_show_spec_store_bypass(struct device *dev, 765 + struct device_attribute *attr, char *buf) 766 + { 767 + if (__ssb_safe) 768 + return sprintf(buf, "Not affected\n"); 769 + 770 + switch (ssbd_state) { 771 + case ARM64_SSBD_KERNEL: 772 + case ARM64_SSBD_FORCE_ENABLE: 773 + if (IS_ENABLED(CONFIG_ARM64_SSBD)) 774 + return sprintf(buf, 775 + "Mitigation: Speculative Store Bypass disabled via prctl\n"); 776 + } 777 + 778 + return sprintf(buf, "Vulnerable\n"); 779 + }
+1
arch/arm64/kernel/cpu_ops.c
··· 85 85 pr_err("%pOF: missing enable-method property\n", 86 86 dn); 87 87 } 88 + of_node_put(dn); 88 89 } else { 89 90 enable_method = acpi_get_enable_method(cpu); 90 91 if (!enable_method) {
+142 -51
arch/arm64/kernel/cpufeature.c
··· 25 25 #include <linux/stop_machine.h> 26 26 #include <linux/types.h> 27 27 #include <linux/mm.h> 28 + #include <linux/cpu.h> 28 29 #include <asm/cpu.h> 29 30 #include <asm/cpufeature.h> 30 31 #include <asm/cpu_ops.h> ··· 36 35 #include <asm/traps.h> 37 36 #include <asm/virt.h> 38 37 39 - unsigned long elf_hwcap __read_mostly; 40 - EXPORT_SYMBOL_GPL(elf_hwcap); 38 + /* Kernel representation of AT_HWCAP and AT_HWCAP2 */ 39 + static unsigned long elf_hwcap __read_mostly; 41 40 42 41 #ifdef CONFIG_COMPAT 43 42 #define COMPAT_ELF_HWCAP_DEFAULT \ ··· 182 181 183 182 static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = { 184 183 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR1_SSBS_SHIFT, 4, ID_AA64PFR1_SSBS_PSTATE_NI), 184 + ARM64_FTR_END, 185 + }; 186 + 187 + static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = { 188 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0), 189 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0), 190 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0), 191 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0), 192 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0), 185 193 ARM64_FTR_END, 186 194 }; 187 195 ··· 402 392 /* Op1 = 0, CRn = 0, CRm = 4 */ 403 393 ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0), 404 394 ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_id_aa64pfr1), 405 - ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_raz), 395 + ARM64_FTR_REG(SYS_ID_AA64ZFR0_EL1, ftr_id_aa64zfr0), 406 396 407 397 /* Op1 = 0, CRn = 0, CRm = 5 */ 408 398 ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0), ··· 957 947 return has_cpuid_feature(entry, scope); 958 948 } 959 949 960 - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 950 + static bool __meltdown_safe = true; 961 951 static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ 962 952 963 953 static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, ··· 976 966 MIDR_ALL_VERSIONS(MIDR_HISI_TSV110), 977 967 { /* sentinel */ } 978 968 }; 979 - char const *str = "command line option"; 969 + char const *str = "kpti command line option"; 970 + bool meltdown_safe; 971 + 972 + meltdown_safe = is_midr_in_range_list(read_cpuid_id(), kpti_safe_list); 973 + 974 + /* Defer to CPU feature registers */ 975 + if (has_cpuid_feature(entry, scope)) 976 + meltdown_safe = true; 977 + 978 + if (!meltdown_safe) 979 + __meltdown_safe = false; 980 980 981 981 /* 982 982 * For reasons that aren't entirely clear, enabling KPTI on Cavium ··· 998 978 __kpti_forced = -1; 999 979 } 1000 980 981 + /* Useful for KASLR robustness */ 982 + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_offset() > 0) { 983 + if (!__kpti_forced) { 984 + str = "KASLR"; 985 + __kpti_forced = 1; 986 + } 987 + } 988 + 989 + if (cpu_mitigations_off() && !__kpti_forced) { 990 + str = "mitigations=off"; 991 + __kpti_forced = -1; 992 + } 993 + 994 + if (!IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) { 995 + pr_info_once("kernel page table isolation disabled by kernel configuration\n"); 996 + return false; 997 + } 998 + 1001 999 /* Forced? */ 1002 1000 if (__kpti_forced) { 1003 1001 pr_info_once("kernel page table isolation forced %s by %s\n", ··· 1023 985 return __kpti_forced > 0; 1024 986 } 1025 987 1026 - /* Useful for KASLR robustness */ 1027 - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) 1028 - return kaslr_offset() > 0; 1029 - 1030 - /* Don't force KPTI for CPUs that are not vulnerable */ 1031 - if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) 1032 - return false; 1033 - 1034 - /* Defer to CPU feature registers */ 1035 - return !has_cpuid_feature(entry, scope); 988 + return !meltdown_safe; 1036 989 } 1037 990 991 + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1038 992 static void 1039 993 kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) 1040 994 { ··· 1056 1026 1057 1027 return; 1058 1028 } 1029 + #else 1030 + static void 1031 + kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) 1032 + { 1033 + } 1034 + #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ 1059 1035 1060 1036 static int __init parse_kpti(char *str) 1061 1037 { ··· 1075 1039 return 0; 1076 1040 } 1077 1041 early_param("kpti", parse_kpti); 1078 - #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ 1079 1042 1080 1043 #ifdef CONFIG_ARM64_HW_AFDBM 1081 1044 static inline void __cpu_enable_hw_dbm(void) ··· 1341 1306 .field_pos = ID_AA64PFR0_EL0_SHIFT, 1342 1307 .min_field_value = ID_AA64PFR0_EL0_32BIT_64BIT, 1343 1308 }, 1344 - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1345 1309 { 1346 1310 .desc = "Kernel page table isolation (KPTI)", 1347 1311 .capability = ARM64_UNMAP_KERNEL_AT_EL0, ··· 1356 1322 .matches = unmap_kernel_at_el0, 1357 1323 .cpu_enable = kpti_install_ng_mappings, 1358 1324 }, 1359 - #endif 1360 1325 { 1361 1326 /* FP/SIMD is not implemented */ 1362 1327 .capability = ARM64_HAS_NO_FPSIMD, ··· 1372 1339 .sys_reg = SYS_ID_AA64ISAR1_EL1, 1373 1340 .field_pos = ID_AA64ISAR1_DPB_SHIFT, 1374 1341 .min_field_value = 1, 1342 + }, 1343 + { 1344 + .desc = "Data cache clean to Point of Deep Persistence", 1345 + .capability = ARM64_HAS_DCPODP, 1346 + .type = ARM64_CPUCAP_SYSTEM_FEATURE, 1347 + .matches = has_cpuid_feature, 1348 + .sys_reg = SYS_ID_AA64ISAR1_EL1, 1349 + .sign = FTR_UNSIGNED, 1350 + .field_pos = ID_AA64ISAR1_DPB_SHIFT, 1351 + .min_field_value = 2, 1375 1352 }, 1376 1353 #endif 1377 1354 #ifdef CONFIG_ARM64_SVE ··· 1614 1571 #endif 1615 1572 1616 1573 static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { 1617 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_PMULL), 1618 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_AES), 1619 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA1), 1620 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA2), 1621 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_SHA512), 1622 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_CRC32), 1623 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_ATOMICS), 1624 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RDM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_ASIMDRDM), 1625 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA3), 1626 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SM3), 1627 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM4_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SM4), 1628 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_DP_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_ASIMDDP), 1629 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_FHM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_ASIMDFHM), 1630 - HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_FLAGM), 1631 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_FP), 1632 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_FPHP), 1633 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_ASIMD), 1634 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_ASIMDHP), 1635 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_DIT_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_DIT), 1636 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DPB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_DCPOP), 1637 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_JSCVT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_JSCVT), 1638 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_FCMA_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_FCMA), 1639 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_LRCPC), 1640 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_ILRCPC), 1641 - HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_SB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SB), 1642 - HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_USCAT), 1574 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_PMULL), 1575 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_AES), 1576 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA1), 1577 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA2), 1578 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_SHA512), 1579 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_CRC32), 1580 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ATOMICS), 1581 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_RDM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDRDM), 1582 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SHA3), 1583 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM3), 1584 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM4_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SM4), 1585 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_DP_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDDP), 1586 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_FHM_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDFHM), 1587 + HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_TS_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FLAGM), 1588 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_FP), 1589 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FPHP), 1590 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, KERNEL_HWCAP_ASIMD), 1591 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_ASIMDHP), 1592 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_DIT_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DIT), 1593 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DPB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_DCPOP), 1594 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_DPB_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_DCPODP), 1595 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_JSCVT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_JSCVT), 1596 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_FCMA_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_FCMA), 1597 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_LRCPC), 1598 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, KERNEL_HWCAP_ILRCPC), 1599 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_SB_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_SB), 1600 + HWCAP_CAP(SYS_ID_AA64MMFR2_EL1, ID_AA64MMFR2_AT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, KERNEL_HWCAP_USCAT), 1643 1601 #ifdef CONFIG_ARM64_SVE 1644 - HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, HWCAP_SVE), 1602 + HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_SVE_SHIFT, FTR_UNSIGNED, ID_AA64PFR0_SVE, CAP_HWCAP, KERNEL_HWCAP_SVE), 1603 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SVEVER_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SVEVER_SVE2, CAP_HWCAP, KERNEL_HWCAP_SVE2), 1604 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES, CAP_HWCAP, KERNEL_HWCAP_SVEAES), 1605 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_AES_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_AES_PMULL, CAP_HWCAP, KERNEL_HWCAP_SVEPMULL), 1606 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_BITPERM_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_BITPERM, CAP_HWCAP, KERNEL_HWCAP_SVEBITPERM), 1607 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SHA3_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SHA3, CAP_HWCAP, KERNEL_HWCAP_SVESHA3), 1608 + HWCAP_CAP(SYS_ID_AA64ZFR0_EL1, ID_AA64ZFR0_SM4_SHIFT, FTR_UNSIGNED, ID_AA64ZFR0_SM4, CAP_HWCAP, KERNEL_HWCAP_SVESM4), 1645 1609 #endif 1646 - HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, HWCAP_SSBS), 1610 + HWCAP_CAP(SYS_ID_AA64PFR1_EL1, ID_AA64PFR1_SSBS_SHIFT, FTR_UNSIGNED, ID_AA64PFR1_SSBS_PSTATE_INSNS, CAP_HWCAP, KERNEL_HWCAP_SSBS), 1647 1611 #ifdef CONFIG_ARM64_PTR_AUTH 1648 - HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches, CAP_HWCAP, HWCAP_PACA), 1649 - HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches, CAP_HWCAP, HWCAP_PACG), 1612 + HWCAP_MULTI_CAP(ptr_auth_hwcap_addr_matches, CAP_HWCAP, KERNEL_HWCAP_PACA), 1613 + HWCAP_MULTI_CAP(ptr_auth_hwcap_gen_matches, CAP_HWCAP, KERNEL_HWCAP_PACG), 1650 1614 #endif 1651 1615 {}, 1652 1616 }; ··· 1673 1623 { 1674 1624 switch (cap->hwcap_type) { 1675 1625 case CAP_HWCAP: 1676 - elf_hwcap |= cap->hwcap; 1626 + cpu_set_feature(cap->hwcap); 1677 1627 break; 1678 1628 #ifdef CONFIG_COMPAT 1679 1629 case CAP_COMPAT_HWCAP: ··· 1696 1646 1697 1647 switch (cap->hwcap_type) { 1698 1648 case CAP_HWCAP: 1699 - rc = (elf_hwcap & cap->hwcap) != 0; 1649 + rc = cpu_have_feature(cap->hwcap); 1700 1650 break; 1701 1651 #ifdef CONFIG_COMPAT 1702 1652 case CAP_COMPAT_HWCAP: ··· 1717 1667 static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps) 1718 1668 { 1719 1669 /* We support emulation of accesses to CPU ID feature registers */ 1720 - elf_hwcap |= HWCAP_CPUID; 1670 + cpu_set_named_feature(CPUID); 1721 1671 for (; hwcaps->matches; hwcaps++) 1722 1672 if (hwcaps->matches(hwcaps, cpucap_default_scope(hwcaps))) 1723 1673 cap_set_elf_hwcap(hwcaps); ··· 1997 1947 return false; 1998 1948 } 1999 1949 1950 + void cpu_set_feature(unsigned int num) 1951 + { 1952 + WARN_ON(num >= MAX_CPU_FEATURES); 1953 + elf_hwcap |= BIT(num); 1954 + } 1955 + EXPORT_SYMBOL_GPL(cpu_set_feature); 1956 + 1957 + bool cpu_have_feature(unsigned int num) 1958 + { 1959 + WARN_ON(num >= MAX_CPU_FEATURES); 1960 + return elf_hwcap & BIT(num); 1961 + } 1962 + EXPORT_SYMBOL_GPL(cpu_have_feature); 1963 + 1964 + unsigned long cpu_get_elf_hwcap(void) 1965 + { 1966 + /* 1967 + * We currently only populate the first 32 bits of AT_HWCAP. Please 1968 + * note that for userspace compatibility we guarantee that bits 62 1969 + * and 63 will always be returned as 0. 1970 + */ 1971 + return lower_32_bits(elf_hwcap); 1972 + } 1973 + 1974 + unsigned long cpu_get_elf_hwcap2(void) 1975 + { 1976 + return upper_32_bits(elf_hwcap); 1977 + } 1978 + 2000 1979 static void __init setup_system_capabilities(void) 2001 1980 { 2002 1981 /* ··· 2180 2101 } 2181 2102 2182 2103 core_initcall(enable_mrs_emulation); 2104 + 2105 + ssize_t cpu_show_meltdown(struct device *dev, struct device_attribute *attr, 2106 + char *buf) 2107 + { 2108 + if (__meltdown_safe) 2109 + return sprintf(buf, "Not affected\n"); 2110 + 2111 + if (arm64_kernel_unmapped_at_el0()) 2112 + return sprintf(buf, "Mitigation: PTI\n"); 2113 + 2114 + return sprintf(buf, "Vulnerable\n"); 2115 + }
+8 -1
arch/arm64/kernel/cpuinfo.c
··· 85 85 "sb", 86 86 "paca", 87 87 "pacg", 88 + "dcpodp", 89 + "sve2", 90 + "sveaes", 91 + "svepmull", 92 + "svebitperm", 93 + "svesha3", 94 + "svesm4", 88 95 NULL 89 96 }; 90 97 ··· 174 167 #endif /* CONFIG_COMPAT */ 175 168 } else { 176 169 for (j = 0; hwcap_str[j]; j++) 177 - if (elf_hwcap & (1 << j)) 170 + if (cpu_have_feature(j)) 178 171 seq_printf(m, " %s", hwcap_str[j]); 179 172 } 180 173 seq_puts(m, "\n");
+67 -48
arch/arm64/kernel/debug-monitors.c
··· 135 135 */ 136 136 static int clear_os_lock(unsigned int cpu) 137 137 { 138 + write_sysreg(0, osdlr_el1); 138 139 write_sysreg(0, oslar_el1); 139 140 isb(); 140 141 return 0; ··· 164 163 } 165 164 NOKPROBE_SYMBOL(clear_regs_spsr_ss); 166 165 167 - /* EL1 Single Step Handler hooks */ 168 - static LIST_HEAD(step_hook); 169 - static DEFINE_SPINLOCK(step_hook_lock); 166 + static DEFINE_SPINLOCK(debug_hook_lock); 167 + static LIST_HEAD(user_step_hook); 168 + static LIST_HEAD(kernel_step_hook); 170 169 171 - void register_step_hook(struct step_hook *hook) 170 + static void register_debug_hook(struct list_head *node, struct list_head *list) 172 171 { 173 - spin_lock(&step_hook_lock); 174 - list_add_rcu(&hook->node, &step_hook); 175 - spin_unlock(&step_hook_lock); 172 + spin_lock(&debug_hook_lock); 173 + list_add_rcu(node, list); 174 + spin_unlock(&debug_hook_lock); 175 + 176 176 } 177 177 178 - void unregister_step_hook(struct step_hook *hook) 178 + static void unregister_debug_hook(struct list_head *node) 179 179 { 180 - spin_lock(&step_hook_lock); 181 - list_del_rcu(&hook->node); 182 - spin_unlock(&step_hook_lock); 180 + spin_lock(&debug_hook_lock); 181 + list_del_rcu(node); 182 + spin_unlock(&debug_hook_lock); 183 183 synchronize_rcu(); 184 + } 185 + 186 + void register_user_step_hook(struct step_hook *hook) 187 + { 188 + register_debug_hook(&hook->node, &user_step_hook); 189 + } 190 + 191 + void unregister_user_step_hook(struct step_hook *hook) 192 + { 193 + unregister_debug_hook(&hook->node); 194 + } 195 + 196 + void register_kernel_step_hook(struct step_hook *hook) 197 + { 198 + register_debug_hook(&hook->node, &kernel_step_hook); 199 + } 200 + 201 + void unregister_kernel_step_hook(struct step_hook *hook) 202 + { 203 + unregister_debug_hook(&hook->node); 184 204 } 185 205 186 206 /* ··· 213 191 static int call_step_hook(struct pt_regs *regs, unsigned int esr) 214 192 { 215 193 struct step_hook *hook; 194 + struct list_head *list; 216 195 int retval = DBG_HOOK_ERROR; 196 + 197 + list = user_mode(regs) ? &user_step_hook : &kernel_step_hook; 217 198 218 199 rcu_read_lock(); 219 200 220 - list_for_each_entry_rcu(hook, &step_hook, node) { 201 + list_for_each_entry_rcu(hook, list, node) { 221 202 retval = hook->fn(regs, esr); 222 203 if (retval == DBG_HOOK_HANDLED) 223 204 break; ··· 247 222 "User debug trap"); 248 223 } 249 224 250 - static int single_step_handler(unsigned long addr, unsigned int esr, 225 + static int single_step_handler(unsigned long unused, unsigned int esr, 251 226 struct pt_regs *regs) 252 227 { 253 228 bool handler_found = false; ··· 259 234 if (!reinstall_suspended_bps(regs)) 260 235 return 0; 261 236 262 - #ifdef CONFIG_KPROBES 263 - if (kprobe_single_step_handler(regs, esr) == DBG_HOOK_HANDLED) 264 - handler_found = true; 265 - #endif 266 237 if (!handler_found && call_step_hook(regs, esr) == DBG_HOOK_HANDLED) 267 238 handler_found = true; 268 239 ··· 285 264 } 286 265 NOKPROBE_SYMBOL(single_step_handler); 287 266 288 - /* 289 - * Breakpoint handler is re-entrant as another breakpoint can 290 - * hit within breakpoint handler, especically in kprobes. 291 - * Use reader/writer locks instead of plain spinlock. 292 - */ 293 - static LIST_HEAD(break_hook); 294 - static DEFINE_SPINLOCK(break_hook_lock); 267 + static LIST_HEAD(user_break_hook); 268 + static LIST_HEAD(kernel_break_hook); 295 269 296 - void register_break_hook(struct break_hook *hook) 270 + void register_user_break_hook(struct break_hook *hook) 297 271 { 298 - spin_lock(&break_hook_lock); 299 - list_add_rcu(&hook->node, &break_hook); 300 - spin_unlock(&break_hook_lock); 272 + register_debug_hook(&hook->node, &user_break_hook); 301 273 } 302 274 303 - void unregister_break_hook(struct break_hook *hook) 275 + void unregister_user_break_hook(struct break_hook *hook) 304 276 { 305 - spin_lock(&break_hook_lock); 306 - list_del_rcu(&hook->node); 307 - spin_unlock(&break_hook_lock); 308 - synchronize_rcu(); 277 + unregister_debug_hook(&hook->node); 278 + } 279 + 280 + void register_kernel_break_hook(struct break_hook *hook) 281 + { 282 + register_debug_hook(&hook->node, &kernel_break_hook); 283 + } 284 + 285 + void unregister_kernel_break_hook(struct break_hook *hook) 286 + { 287 + unregister_debug_hook(&hook->node); 309 288 } 310 289 311 290 static int call_break_hook(struct pt_regs *regs, unsigned int esr) 312 291 { 313 292 struct break_hook *hook; 293 + struct list_head *list; 314 294 int (*fn)(struct pt_regs *regs, unsigned int esr) = NULL; 315 295 296 + list = user_mode(regs) ? &user_break_hook : &kernel_break_hook; 297 + 316 298 rcu_read_lock(); 317 - list_for_each_entry_rcu(hook, &break_hook, node) 318 - if ((esr & hook->esr_mask) == hook->esr_val) 299 + list_for_each_entry_rcu(hook, list, node) { 300 + unsigned int comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK; 301 + 302 + if ((comment & ~hook->mask) == hook->imm) 319 303 fn = hook->fn; 304 + } 320 305 rcu_read_unlock(); 321 306 322 307 return fn ? fn(regs, esr) : DBG_HOOK_ERROR; 323 308 } 324 309 NOKPROBE_SYMBOL(call_break_hook); 325 310 326 - static int brk_handler(unsigned long addr, unsigned int esr, 311 + static int brk_handler(unsigned long unused, unsigned int esr, 327 312 struct pt_regs *regs) 328 313 { 329 - bool handler_found = false; 314 + if (call_break_hook(regs, esr) == DBG_HOOK_HANDLED) 315 + return 0; 330 316 331 - #ifdef CONFIG_KPROBES 332 - if ((esr & BRK64_ESR_MASK) == BRK64_ESR_KPROBES) { 333 - if (kprobe_breakpoint_handler(regs, esr) == DBG_HOOK_HANDLED) 334 - handler_found = true; 335 - } 336 - #endif 337 - if (!handler_found && call_break_hook(regs, esr) == DBG_HOOK_HANDLED) 338 - handler_found = true; 339 - 340 - if (!handler_found && user_mode(regs)) { 317 + if (user_mode(regs)) { 341 318 send_user_sigtrap(TRAP_BRKPT); 342 - } else if (!handler_found) { 319 + } else { 343 320 pr_warn("Unexpected kernel BRK exception at EL1\n"); 344 321 return -EFAULT; 345 322 }
+17 -2
arch/arm64/kernel/entry.S
··· 336 336 alternative_else_nop_endif 337 337 #endif 338 338 3: 339 + #ifdef CONFIG_ARM64_ERRATUM_1188873 340 + alternative_if_not ARM64_WORKAROUND_1188873 341 + b 4f 342 + alternative_else_nop_endif 343 + /* 344 + * if (x22.mode32 == cntkctl_el1.el0vcten) 345 + * cntkctl_el1.el0vcten = ~cntkctl_el1.el0vcten 346 + */ 347 + mrs x1, cntkctl_el1 348 + eon x0, x1, x22, lsr #3 349 + tbz x0, #1, 4f 350 + eor x1, x1, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN 351 + msr cntkctl_el1, x1 352 + 4: 353 + #endif 339 354 apply_ssbd 0, x0, x1 340 355 .endif 341 356 ··· 377 362 .if \el == 0 378 363 alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 379 364 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 380 - bne 4f 365 + bne 5f 381 366 msr far_el1, x30 382 367 tramp_alias x30, tramp_exit_native 383 368 br x30 384 - 4: 369 + 5: 385 370 tramp_alias x30, tramp_exit_compat 386 371 br x30 387 372 #endif
+2 -2
arch/arm64/kernel/fpsimd.c
··· 1258 1258 */ 1259 1259 static int __init fpsimd_init(void) 1260 1260 { 1261 - if (elf_hwcap & HWCAP_FP) { 1261 + if (cpu_have_named_feature(FP)) { 1262 1262 fpsimd_pm_init(); 1263 1263 fpsimd_hotplug_init(); 1264 1264 } else { 1265 1265 pr_notice("Floating-point is not implemented\n"); 1266 1266 } 1267 1267 1268 - if (!(elf_hwcap & HWCAP_ASIMD)) 1268 + if (!cpu_have_named_feature(ASIMD)) 1269 1269 pr_notice("Advanced SIMD is not implemented\n"); 1270 1270 1271 1271 return sve_sysctl_init();
+6 -6
arch/arm64/kernel/head.S
··· 505 505 * kernel is intended to run at EL2. 506 506 */ 507 507 mrs x2, id_aa64mmfr1_el1 508 - ubfx x2, x2, #8, #4 508 + ubfx x2, x2, #ID_AA64MMFR1_VHE_SHIFT, #4 509 509 #else 510 510 mov x2, xzr 511 511 #endif ··· 538 538 #ifdef CONFIG_ARM_GIC_V3 539 539 /* GICv3 system register access */ 540 540 mrs x0, id_aa64pfr0_el1 541 - ubfx x0, x0, #24, #4 541 + ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #4 542 542 cbz x0, 3f 543 543 544 544 mrs_s x0, SYS_ICC_SRE_EL2 ··· 564 564 #endif 565 565 566 566 /* EL2 debug */ 567 - mrs x1, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer 568 - sbfx x0, x1, #8, #4 567 + mrs x1, id_aa64dfr0_el1 568 + sbfx x0, x1, #ID_AA64DFR0_PMUVER_SHIFT, #4 569 569 cmp x0, #1 570 570 b.lt 4f // Skip if no PMU present 571 571 mrs x0, pmcr_el0 // Disable debug access traps ··· 574 574 csel x3, xzr, x0, lt // all PMU counters from EL1 575 575 576 576 /* Statistical profiling */ 577 - ubfx x0, x1, #32, #4 // Check ID_AA64DFR0_EL1 PMSVer 577 + ubfx x0, x1, #ID_AA64DFR0_PMSVER_SHIFT, #4 578 578 cbz x0, 7f // Skip if SPE not present 579 579 cbnz x2, 6f // VHE? 580 580 mrs_s x4, SYS_PMBIDR_EL1 // If SPE available at EL2, ··· 684 684 * with MMU turned off. 685 685 */ 686 686 ENTRY(__early_cpu_boot_status) 687 - .long 0 687 + .quad 0 688 688 689 689 .popsection 690 690
+11 -19
arch/arm64/kernel/kgdb.c
··· 244 244 245 245 static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr) 246 246 { 247 - if (user_mode(regs)) 248 - return DBG_HOOK_ERROR; 249 - 250 247 kgdb_handle_exception(1, SIGTRAP, 0, regs); 251 248 return DBG_HOOK_HANDLED; 252 249 } ··· 251 254 252 255 static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) 253 256 { 254 - if (user_mode(regs)) 255 - return DBG_HOOK_ERROR; 256 - 257 257 compiled_break = 1; 258 258 kgdb_handle_exception(1, SIGTRAP, 0, regs); 259 259 ··· 260 266 261 267 static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) 262 268 { 263 - if (user_mode(regs) || !kgdb_single_step) 269 + if (!kgdb_single_step) 264 270 return DBG_HOOK_ERROR; 265 271 266 272 kgdb_handle_exception(1, SIGTRAP, 0, regs); ··· 269 275 NOKPROBE_SYMBOL(kgdb_step_brk_fn); 270 276 271 277 static struct break_hook kgdb_brkpt_hook = { 272 - .esr_mask = 0xffffffff, 273 - .esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_DYN_DBG_BRK_IMM), 274 - .fn = kgdb_brk_fn 278 + .fn = kgdb_brk_fn, 279 + .imm = KGDB_DYN_DBG_BRK_IMM, 275 280 }; 276 281 277 282 static struct break_hook kgdb_compiled_brkpt_hook = { 278 - .esr_mask = 0xffffffff, 279 - .esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_COMPILED_DBG_BRK_IMM), 280 - .fn = kgdb_compiled_brk_fn 283 + .fn = kgdb_compiled_brk_fn, 284 + .imm = KGDB_COMPILED_DBG_BRK_IMM, 281 285 }; 282 286 283 287 static struct step_hook kgdb_step_hook = { ··· 324 332 if (ret != 0) 325 333 return ret; 326 334 327 - register_break_hook(&kgdb_brkpt_hook); 328 - register_break_hook(&kgdb_compiled_brkpt_hook); 329 - register_step_hook(&kgdb_step_hook); 335 + register_kernel_break_hook(&kgdb_brkpt_hook); 336 + register_kernel_break_hook(&kgdb_compiled_brkpt_hook); 337 + register_kernel_step_hook(&kgdb_step_hook); 330 338 return 0; 331 339 } 332 340 ··· 337 345 */ 338 346 void kgdb_arch_exit(void) 339 347 { 340 - unregister_break_hook(&kgdb_brkpt_hook); 341 - unregister_break_hook(&kgdb_compiled_brkpt_hook); 342 - unregister_step_hook(&kgdb_step_hook); 348 + unregister_kernel_break_hook(&kgdb_brkpt_hook); 349 + unregister_kernel_break_hook(&kgdb_compiled_brkpt_hook); 350 + unregister_kernel_step_hook(&kgdb_step_hook); 343 351 unregister_die_notifier(&kgdb_notifier); 344 352 } 345 353
+6 -60
arch/arm64/kernel/kuser32.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 2 - * Low-level user helpers placed in the vectors page for AArch32. 3 + * AArch32 user helpers. 3 4 * Based on the kuser helpers in arch/arm/kernel/entry-armv.S. 4 5 * 5 6 * Copyright (C) 2005-2011 Nicolas Pitre <nico@fluxnic.net> 6 - * Copyright (C) 2012 ARM Ltd. 7 + * Copyright (C) 2012-2018 ARM Ltd. 7 8 * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - * 12 - * This program is distributed in the hope that it will be useful, 13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - * GNU General Public License for more details. 16 - * 17 - * You should have received a copy of the GNU General Public License 18 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 - * 20 - * 21 - * AArch32 user helpers. 22 - * 23 - * Each segment is 32-byte aligned and will be moved to the top of the high 24 - * vector page. New segments (if ever needed) must be added in front of 25 - * existing ones. This mechanism should be used only for things that are 26 - * really small and justified, and not be abused freely. 9 + * The kuser helpers below are mapped at a fixed address by 10 + * aarch32_setup_additional_pages() and are provided for compatibility 11 + * reasons with 32 bit (aarch32) applications that need them. 27 12 * 28 13 * See Documentation/arm/kernel_user_helpers.txt for formal definitions. 29 14 */ ··· 62 77 .word ((__kuser_helper_end - __kuser_helper_start) >> 5) 63 78 .globl __kuser_helper_end 64 79 __kuser_helper_end: 65 - 66 - /* 67 - * AArch32 sigreturn code 68 - * 69 - * For ARM syscalls, the syscall number has to be loaded into r7. 70 - * We do not support an OABI userspace. 71 - * 72 - * For Thumb syscalls, we also pass the syscall number via r7. We therefore 73 - * need two 16-bit instructions. 74 - */ 75 - .globl __aarch32_sigret_code_start 76 - __aarch32_sigret_code_start: 77 - 78 - /* 79 - * ARM Code 80 - */ 81 - .byte __NR_compat_sigreturn, 0x70, 0xa0, 0xe3 // mov r7, #__NR_compat_sigreturn 82 - .byte __NR_compat_sigreturn, 0x00, 0x00, 0xef // svc #__NR_compat_sigreturn 83 - 84 - /* 85 - * Thumb code 86 - */ 87 - .byte __NR_compat_sigreturn, 0x27 // svc #__NR_compat_sigreturn 88 - .byte __NR_compat_sigreturn, 0xdf // mov r7, #__NR_compat_sigreturn 89 - 90 - /* 91 - * ARM code 92 - */ 93 - .byte __NR_compat_rt_sigreturn, 0x70, 0xa0, 0xe3 // mov r7, #__NR_compat_rt_sigreturn 94 - .byte __NR_compat_rt_sigreturn, 0x00, 0x00, 0xef // svc #__NR_compat_rt_sigreturn 95 - 96 - /* 97 - * Thumb code 98 - */ 99 - .byte __NR_compat_rt_sigreturn, 0x27 // svc #__NR_compat_rt_sigreturn 100 - .byte __NR_compat_rt_sigreturn, 0xdf // mov r7, #__NR_compat_rt_sigreturn 101 - 102 - .globl __aarch32_sigret_code_end 103 - __aarch32_sigret_code_end:
+2 -2
arch/arm64/kernel/perf_event.c
··· 431 431 return val; 432 432 } 433 433 434 - static inline u64 armv8pmu_read_counter(struct perf_event *event) 434 + static u64 armv8pmu_read_counter(struct perf_event *event) 435 435 { 436 436 struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu); 437 437 struct hw_perf_event *hwc = &event->hw; ··· 468 468 } 469 469 } 470 470 471 - static inline void armv8pmu_write_counter(struct perf_event *event, u64 value) 471 + static void armv8pmu_write_counter(struct perf_event *event, u64 value) 472 472 { 473 473 struct arm_pmu *cpu_pmu = to_arm_pmu(event->pmu); 474 474 struct hw_perf_event *hwc = &event->hw;
+14 -8
arch/arm64/kernel/probes/kprobes.c
··· 439 439 return DBG_HOOK_ERROR; 440 440 } 441 441 442 - int __kprobes 442 + static int __kprobes 443 443 kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) 444 444 { 445 445 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 446 446 int retval; 447 - 448 - if (user_mode(regs)) 449 - return DBG_HOOK_ERROR; 450 447 451 448 /* return error if this is not our step */ 452 449 retval = kprobe_ss_hit(kcb, instruction_pointer(regs)); ··· 458 461 return retval; 459 462 } 460 463 461 - int __kprobes 464 + static struct step_hook kprobes_step_hook = { 465 + .fn = kprobe_single_step_handler, 466 + }; 467 + 468 + static int __kprobes 462 469 kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) 463 470 { 464 - if (user_mode(regs)) 465 - return DBG_HOOK_ERROR; 466 - 467 471 kprobe_handler(regs); 468 472 return DBG_HOOK_HANDLED; 469 473 } 474 + 475 + static struct break_hook kprobes_break_hook = { 476 + .imm = KPROBES_BRK_IMM, 477 + .fn = kprobe_breakpoint_handler, 478 + }; 470 479 471 480 /* 472 481 * Provide a blacklist of symbols identifying ranges which cannot be kprobed. ··· 602 599 603 600 int __init arch_init_kprobes(void) 604 601 { 602 + register_kernel_break_hook(&kprobes_break_hook); 603 + register_kernel_step_hook(&kprobes_step_hook); 604 + 605 605 return 0; 606 606 }
+7 -12
arch/arm64/kernel/probes/uprobes.c
··· 171 171 static int uprobe_breakpoint_handler(struct pt_regs *regs, 172 172 unsigned int esr) 173 173 { 174 - if (user_mode(regs) && uprobe_pre_sstep_notifier(regs)) 174 + if (uprobe_pre_sstep_notifier(regs)) 175 175 return DBG_HOOK_HANDLED; 176 176 177 177 return DBG_HOOK_ERROR; ··· 182 182 { 183 183 struct uprobe_task *utask = current->utask; 184 184 185 - if (user_mode(regs)) { 186 - WARN_ON(utask && 187 - (instruction_pointer(regs) != utask->xol_vaddr + 4)); 188 - 189 - if (uprobe_post_sstep_notifier(regs)) 190 - return DBG_HOOK_HANDLED; 191 - } 185 + WARN_ON(utask && (instruction_pointer(regs) != utask->xol_vaddr + 4)); 186 + if (uprobe_post_sstep_notifier(regs)) 187 + return DBG_HOOK_HANDLED; 192 188 193 189 return DBG_HOOK_ERROR; 194 190 } 195 191 196 192 /* uprobe breakpoint handler hook */ 197 193 static struct break_hook uprobes_break_hook = { 198 - .esr_mask = BRK64_ESR_MASK, 199 - .esr_val = BRK64_ESR_UPROBES, 194 + .imm = UPROBES_BRK_IMM, 200 195 .fn = uprobe_breakpoint_handler, 201 196 }; 202 197 ··· 202 207 203 208 static int __init arch_init_uprobes(void) 204 209 { 205 - register_break_hook(&uprobes_break_hook); 206 - register_step_hook(&uprobes_step_hook); 210 + register_user_break_hook(&uprobes_break_hook); 211 + register_user_step_hook(&uprobes_step_hook); 207 212 208 213 return 0; 209 214 }
+1 -2
arch/arm64/kernel/signal32.c
··· 403 403 if (ka->sa.sa_flags & SA_SIGINFO) 404 404 idx += 3; 405 405 406 - retcode = AARCH32_VECTORS_BASE + 407 - AARCH32_KERN_SIGRET_CODE_OFFSET + 406 + retcode = (unsigned long)current->mm->context.vdso + 408 407 (idx << 2) + thumb; 409 408 } 410 409
+46
arch/arm64/kernel/sigreturn32.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * AArch32 sigreturn code. 4 + * Based on the kuser helpers in arch/arm/kernel/entry-armv.S. 5 + * 6 + * Copyright (C) 2005-2011 Nicolas Pitre <nico@fluxnic.net> 7 + * Copyright (C) 2012-2018 ARM Ltd. 8 + * 9 + * For ARM syscalls, the syscall number has to be loaded into r7. 10 + * We do not support an OABI userspace. 11 + * 12 + * For Thumb syscalls, we also pass the syscall number via r7. We therefore 13 + * need two 16-bit instructions. 14 + */ 15 + 16 + #include <asm/unistd.h> 17 + 18 + .globl __aarch32_sigret_code_start 19 + __aarch32_sigret_code_start: 20 + 21 + /* 22 + * ARM Code 23 + */ 24 + .byte __NR_compat_sigreturn, 0x70, 0xa0, 0xe3 // mov r7, #__NR_compat_sigreturn 25 + .byte __NR_compat_sigreturn, 0x00, 0x00, 0xef // svc #__NR_compat_sigreturn 26 + 27 + /* 28 + * Thumb code 29 + */ 30 + .byte __NR_compat_sigreturn, 0x27 // svc #__NR_compat_sigreturn 31 + .byte __NR_compat_sigreturn, 0xdf // mov r7, #__NR_compat_sigreturn 32 + 33 + /* 34 + * ARM code 35 + */ 36 + .byte __NR_compat_rt_sigreturn, 0x70, 0xa0, 0xe3 // mov r7, #__NR_compat_rt_sigreturn 37 + .byte __NR_compat_rt_sigreturn, 0x00, 0x00, 0xef // svc #__NR_compat_rt_sigreturn 38 + 39 + /* 40 + * Thumb code 41 + */ 42 + .byte __NR_compat_rt_sigreturn, 0x27 // svc #__NR_compat_rt_sigreturn 43 + .byte __NR_compat_rt_sigreturn, 0xdf // mov r7, #__NR_compat_rt_sigreturn 44 + 45 + .globl __aarch32_sigret_code_end 46 + __aarch32_sigret_code_end:
+1 -1
arch/arm64/kernel/sys.c
··· 31 31 32 32 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, 33 33 unsigned long, prot, unsigned long, flags, 34 - unsigned long, fd, off_t, off) 34 + unsigned long, fd, unsigned long, off) 35 35 { 36 36 if (offset_in_page(off) != 0) 37 37 return -EINVAL;
+14 -19
arch/arm64/kernel/traps.c
··· 462 462 case ESR_ELx_SYS64_ISS_CRM_DC_CVAC: /* DC CVAC, gets promoted */ 463 463 __user_cache_maint("dc civac", address, ret); 464 464 break; 465 + case ESR_ELx_SYS64_ISS_CRM_DC_CVADP: /* DC CVADP */ 466 + __user_cache_maint("sys 3, c7, c13, 1", address, ret); 467 + break; 465 468 case ESR_ELx_SYS64_ISS_CRM_DC_CVAP: /* DC CVAP */ 466 469 __user_cache_maint("sys 3, c7, c12, 1", address, ret); 467 470 break; ··· 499 496 { 500 497 int rt = ESR_ELx_SYS64_ISS_RT(esr); 501 498 502 - pt_regs_write_reg(regs, rt, arch_counter_get_cntvct()); 499 + pt_regs_write_reg(regs, rt, arch_timer_read_counter()); 503 500 arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE); 504 501 } 505 502 ··· 671 668 { 672 669 int rt = (esr & ESR_ELx_CP15_64_ISS_RT_MASK) >> ESR_ELx_CP15_64_ISS_RT_SHIFT; 673 670 int rt2 = (esr & ESR_ELx_CP15_64_ISS_RT2_MASK) >> ESR_ELx_CP15_64_ISS_RT2_SHIFT; 674 - u64 val = arch_counter_get_cntvct(); 671 + u64 val = arch_timer_read_counter(); 675 672 676 673 pt_regs_write_reg(regs, rt, lower_32_bits(val)); 677 674 pt_regs_write_reg(regs, rt2, upper_32_bits(val)); ··· 953 950 954 951 static int bug_handler(struct pt_regs *regs, unsigned int esr) 955 952 { 956 - if (user_mode(regs)) 957 - return DBG_HOOK_ERROR; 958 - 959 953 switch (report_bug(regs->pc, regs)) { 960 954 case BUG_TRAP_TYPE_BUG: 961 955 die("Oops - BUG", regs, 0); ··· 972 972 } 973 973 974 974 static struct break_hook bug_break_hook = { 975 - .esr_val = 0xf2000000 | BUG_BRK_IMM, 976 - .esr_mask = 0xffffffff, 977 975 .fn = bug_handler, 976 + .imm = BUG_BRK_IMM, 978 977 }; 979 978 980 979 #ifdef CONFIG_KASAN_SW_TAGS ··· 990 991 size_t size = KASAN_ESR_SIZE(esr); 991 992 u64 addr = regs->regs[0]; 992 993 u64 pc = regs->pc; 993 - 994 - if (user_mode(regs)) 995 - return DBG_HOOK_ERROR; 996 994 997 995 kasan_report(addr, size, write, pc); 998 996 ··· 1015 1019 return DBG_HOOK_HANDLED; 1016 1020 } 1017 1021 1018 - #define KASAN_ESR_VAL (0xf2000000 | KASAN_BRK_IMM) 1019 - #define KASAN_ESR_MASK 0xffffff00 1020 - 1021 1022 static struct break_hook kasan_break_hook = { 1022 - .esr_val = KASAN_ESR_VAL, 1023 - .esr_mask = KASAN_ESR_MASK, 1024 - .fn = kasan_handler, 1023 + .fn = kasan_handler, 1024 + .imm = KASAN_BRK_IMM, 1025 + .mask = KASAN_BRK_MASK, 1025 1026 }; 1026 1027 #endif 1027 1028 ··· 1030 1037 struct pt_regs *regs) 1031 1038 { 1032 1039 #ifdef CONFIG_KASAN_SW_TAGS 1033 - if ((esr & KASAN_ESR_MASK) == KASAN_ESR_VAL) 1040 + unsigned int comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK; 1041 + 1042 + if ((comment & ~KASAN_BRK_MASK) == KASAN_BRK_IMM) 1034 1043 return kasan_handler(regs, esr) != DBG_HOOK_HANDLED; 1035 1044 #endif 1036 1045 return bug_handler(regs, esr) != DBG_HOOK_HANDLED; ··· 1041 1046 /* This registration must happen early, before debug_traps_init(). */ 1042 1047 void __init trap_init(void) 1043 1048 { 1044 - register_break_hook(&bug_break_hook); 1049 + register_kernel_break_hook(&bug_break_hook); 1045 1050 #ifdef CONFIG_KASAN_SW_TAGS 1046 - register_break_hook(&kasan_break_hook); 1051 + register_kernel_break_hook(&kasan_break_hook); 1047 1052 #endif 1048 1053 }
+107 -38
arch/arm64/kernel/vdso.c
··· 1 1 /* 2 - * VDSO implementation for AArch64 and vector page setup for AArch32. 2 + * VDSO implementations. 3 3 * 4 4 * Copyright (C) 2012 ARM Limited 5 5 * ··· 53 53 /* 54 54 * Create and map the vectors page for AArch32 tasks. 55 55 */ 56 - static struct page *vectors_page[1] __ro_after_init; 56 + #define C_VECTORS 0 57 + #define C_SIGPAGE 1 58 + #define C_PAGES (C_SIGPAGE + 1) 59 + static struct page *aarch32_vdso_pages[C_PAGES] __ro_after_init; 60 + static const struct vm_special_mapping aarch32_vdso_spec[C_PAGES] = { 61 + { 62 + .name = "[vectors]", /* ABI */ 63 + .pages = &aarch32_vdso_pages[C_VECTORS], 64 + }, 65 + { 66 + .name = "[sigpage]", /* ABI */ 67 + .pages = &aarch32_vdso_pages[C_SIGPAGE], 68 + }, 69 + }; 57 70 58 - static int __init alloc_vectors_page(void) 71 + static int aarch32_alloc_kuser_vdso_page(void) 59 72 { 60 73 extern char __kuser_helper_start[], __kuser_helper_end[]; 61 - extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[]; 62 - 63 74 int kuser_sz = __kuser_helper_end - __kuser_helper_start; 64 - int sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start; 65 - unsigned long vpage; 75 + unsigned long vdso_page; 66 76 67 - vpage = get_zeroed_page(GFP_ATOMIC); 77 + if (!IS_ENABLED(CONFIG_KUSER_HELPERS)) 78 + return 0; 68 79 69 - if (!vpage) 80 + vdso_page = get_zeroed_page(GFP_ATOMIC); 81 + if (!vdso_page) 70 82 return -ENOMEM; 71 83 72 - /* kuser helpers */ 73 - memcpy((void *)vpage + 0x1000 - kuser_sz, __kuser_helper_start, 74 - kuser_sz); 75 - 76 - /* sigreturn code */ 77 - memcpy((void *)vpage + AARCH32_KERN_SIGRET_CODE_OFFSET, 78 - __aarch32_sigret_code_start, sigret_sz); 79 - 80 - flush_icache_range(vpage, vpage + PAGE_SIZE); 81 - vectors_page[0] = virt_to_page(vpage); 82 - 84 + memcpy((void *)(vdso_page + 0x1000 - kuser_sz), __kuser_helper_start, 85 + kuser_sz); 86 + aarch32_vdso_pages[C_VECTORS] = virt_to_page(vdso_page); 87 + flush_dcache_page(aarch32_vdso_pages[C_VECTORS]); 83 88 return 0; 84 89 } 85 - arch_initcall(alloc_vectors_page); 86 90 87 - int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) 91 + static int __init aarch32_alloc_vdso_pages(void) 92 + { 93 + extern char __aarch32_sigret_code_start[], __aarch32_sigret_code_end[]; 94 + int sigret_sz = __aarch32_sigret_code_end - __aarch32_sigret_code_start; 95 + unsigned long sigpage; 96 + int ret; 97 + 98 + sigpage = get_zeroed_page(GFP_ATOMIC); 99 + if (!sigpage) 100 + return -ENOMEM; 101 + 102 + memcpy((void *)sigpage, __aarch32_sigret_code_start, sigret_sz); 103 + aarch32_vdso_pages[C_SIGPAGE] = virt_to_page(sigpage); 104 + flush_dcache_page(aarch32_vdso_pages[C_SIGPAGE]); 105 + 106 + ret = aarch32_alloc_kuser_vdso_page(); 107 + if (ret) 108 + free_page(sigpage); 109 + 110 + return ret; 111 + } 112 + arch_initcall(aarch32_alloc_vdso_pages); 113 + 114 + static int aarch32_kuser_helpers_setup(struct mm_struct *mm) 115 + { 116 + void *ret; 117 + 118 + if (!IS_ENABLED(CONFIG_KUSER_HELPERS)) 119 + return 0; 120 + 121 + /* 122 + * Avoid VM_MAYWRITE for compatibility with arch/arm/, where it's 123 + * not safe to CoW the page containing the CPU exception vectors. 124 + */ 125 + ret = _install_special_mapping(mm, AARCH32_VECTORS_BASE, PAGE_SIZE, 126 + VM_READ | VM_EXEC | 127 + VM_MAYREAD | VM_MAYEXEC, 128 + &aarch32_vdso_spec[C_VECTORS]); 129 + 130 + return PTR_ERR_OR_ZERO(ret); 131 + } 132 + 133 + static int aarch32_sigreturn_setup(struct mm_struct *mm) 134 + { 135 + unsigned long addr; 136 + void *ret; 137 + 138 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0); 139 + if (IS_ERR_VALUE(addr)) { 140 + ret = ERR_PTR(addr); 141 + goto out; 142 + } 143 + 144 + /* 145 + * VM_MAYWRITE is required to allow gdb to Copy-on-Write and 146 + * set breakpoints. 147 + */ 148 + ret = _install_special_mapping(mm, addr, PAGE_SIZE, 149 + VM_READ | VM_EXEC | VM_MAYREAD | 150 + VM_MAYWRITE | VM_MAYEXEC, 151 + &aarch32_vdso_spec[C_SIGPAGE]); 152 + if (IS_ERR(ret)) 153 + goto out; 154 + 155 + mm->context.vdso = (void *)addr; 156 + 157 + out: 158 + return PTR_ERR_OR_ZERO(ret); 159 + } 160 + 161 + int aarch32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) 88 162 { 89 163 struct mm_struct *mm = current->mm; 90 - unsigned long addr = AARCH32_VECTORS_BASE; 91 - static const struct vm_special_mapping spec = { 92 - .name = "[vectors]", 93 - .pages = vectors_page, 94 - 95 - }; 96 - void *ret; 164 + int ret; 97 165 98 166 if (down_write_killable(&mm->mmap_sem)) 99 167 return -EINTR; 100 - current->mm->context.vdso = (void *)addr; 101 168 102 - /* Map vectors page at the high address. */ 103 - ret = _install_special_mapping(mm, addr, PAGE_SIZE, 104 - VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC, 105 - &spec); 169 + ret = aarch32_kuser_helpers_setup(mm); 170 + if (ret) 171 + goto out; 106 172 173 + ret = aarch32_sigreturn_setup(mm); 174 + 175 + out: 107 176 up_write(&mm->mmap_sem); 108 - 109 - return PTR_ERR_OR_ZERO(ret); 177 + return ret; 110 178 } 111 179 #endif /* CONFIG_COMPAT */ 112 180 ··· 214 146 } 215 147 216 148 vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT; 217 - pr_info("vdso: %ld pages (%ld code @ %p, %ld data @ %p)\n", 218 - vdso_pages + 1, vdso_pages, vdso_start, 1L, vdso_data); 219 149 220 150 /* Allocate the vDSO pagelist, plus a page for the data. */ 221 151 vdso_pagelist = kcalloc(vdso_pages + 1, sizeof(struct page *), ··· 297 231 tk->tkr_mono.shift; 298 232 vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec; 299 233 vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec; 234 + 235 + /* Read without the seqlock held by clock_getres() */ 236 + WRITE_ONCE(vdso_data->hrtimer_res, hrtimer_resolution); 300 237 301 238 if (!use_syscall) { 302 239 /* tkr_mono.cycle_last == tkr_raw.cycle_last */
+5 -14
arch/arm64/kernel/vdso/Makefile
··· 12 12 targets := $(obj-vdso) vdso.so vdso.so.dbg 13 13 obj-vdso := $(addprefix $(obj)/, $(obj-vdso)) 14 14 15 - ccflags-y := -shared -fno-common -fno-builtin 16 - ccflags-y += -nostdlib -Wl,-soname=linux-vdso.so.1 \ 17 - $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) 15 + ldflags-y := -shared -nostdlib -soname=linux-vdso.so.1 \ 16 + $(call ld-option, --hash-style=sysv) -n -T 18 17 19 18 # Disable gcov profiling for VDSO code 20 19 GCOV_PROFILE := n 21 - 22 - # Workaround for bare-metal (ELF) toolchains that neglect to pass -shared 23 - # down to collect2, resulting in silent corruption of the vDSO image. 24 - ccflags-y += -Wl,-shared 25 20 26 21 obj-y += vdso.o 27 22 extra-y += vdso.lds ··· 26 31 $(obj)/vdso.o : $(obj)/vdso.so 27 32 28 33 # Link rule for the .so file, .lds has to be first 29 - $(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) 30 - $(call if_changed,vdsold) 34 + $(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE 35 + $(call if_changed,ld) 31 36 32 37 # Strip rule for the .so file 33 38 $(obj)/%.so: OBJCOPYFLAGS := -S ··· 37 42 # Generate VDSO offsets using helper script 38 43 gen-vdsosym := $(srctree)/$(src)/gen_vdso_offsets.sh 39 44 quiet_cmd_vdsosym = VDSOSYM $@ 40 - define cmd_vdsosym 41 - $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@ 42 - endef 45 + cmd_vdsosym = $(NM) $< | $(gen-vdsosym) | LC_ALL=C sort > $@ 43 46 44 47 include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE 45 48 $(call if_changed,vdsosym) ··· 47 54 $(call if_changed_dep,vdsoas) 48 55 49 56 # Actual build commands 50 - quiet_cmd_vdsold = VDSOL $@ 51 - cmd_vdsold = $(CC) $(c_flags) -Wl,-n -Wl,-T $^ -o $@ 52 57 quiet_cmd_vdsoas = VDSOA $@ 53 58 cmd_vdsoas = $(CC) $(a_flags) -c -o $@ $< 54 59
+14 -8
arch/arm64/kernel/vdso/gettimeofday.S
··· 73 73 movn x_tmp, #0xff00, lsl #48 74 74 and \res, x_tmp, \res 75 75 mul \res, \res, \mult 76 + /* 77 + * Fake address dependency from the value computed from the counter 78 + * register to subsequent data page accesses so that the sequence 79 + * locking also orders the read of the counter. 80 + */ 81 + and x_tmp, \res, xzr 82 + add vdso_data, vdso_data, x_tmp 76 83 .endm 77 84 78 85 /* ··· 154 147 /* w11 = cs_mono_mult, w12 = cs_shift */ 155 148 ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] 156 149 ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] 157 - seqcnt_check fail=1b 158 150 159 151 get_nsec_per_sec res=x9 160 152 lsl x9, x9, x12 161 153 162 154 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 155 + seqcnt_check fail=1b 163 156 get_ts_realtime res_sec=x10, res_nsec=x11, \ 164 157 clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 165 158 ··· 218 211 /* w11 = cs_mono_mult, w12 = cs_shift */ 219 212 ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] 220 213 ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] 221 - seqcnt_check fail=realtime 222 214 223 215 /* All computations are done with left-shifted nsecs. */ 224 216 get_nsec_per_sec res=x9 225 217 lsl x9, x9, x12 226 218 227 219 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 220 + seqcnt_check fail=realtime 228 221 get_ts_realtime res_sec=x10, res_nsec=x11, \ 229 222 clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 230 223 clock_gettime_return, shift=1 ··· 238 231 ldp w11, w12, [vdso_data, #VDSO_CS_MONO_MULT] 239 232 ldp x13, x14, [vdso_data, #VDSO_XTIME_CLK_SEC] 240 233 ldp x3, x4, [vdso_data, #VDSO_WTM_CLK_SEC] 241 - seqcnt_check fail=monotonic 242 234 243 235 /* All computations are done with left-shifted nsecs. */ 244 236 lsl x4, x4, x12 ··· 245 239 lsl x9, x9, x12 246 240 247 241 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 242 + seqcnt_check fail=monotonic 248 243 get_ts_realtime res_sec=x10, res_nsec=x11, \ 249 244 clock_nsec=x15, xtime_sec=x13, xtime_nsec=x14, nsec_to_sec=x9 250 245 ··· 260 253 /* w11 = cs_raw_mult, w12 = cs_shift */ 261 254 ldp w12, w11, [vdso_data, #VDSO_CS_SHIFT] 262 255 ldp x13, x14, [vdso_data, #VDSO_RAW_TIME_SEC] 263 - seqcnt_check fail=monotonic_raw 264 256 265 257 /* All computations are done with left-shifted nsecs. */ 266 258 get_nsec_per_sec res=x9 267 259 lsl x9, x9, x12 268 260 269 261 get_clock_shifted_nsec res=x15, cycle_last=x10, mult=x11 262 + seqcnt_check fail=monotonic_raw 270 263 get_ts_clock_raw res_sec=x10, res_nsec=x11, \ 271 264 clock_nsec=x15, nsec_to_sec=x9 272 265 ··· 308 301 ccmp w0, #CLOCK_MONOTONIC_RAW, #0x4, ne 309 302 b.ne 1f 310 303 311 - ldr x2, 5f 304 + adr vdso_data, _vdso_data 305 + ldr w2, [vdso_data, #CLOCK_REALTIME_RES] 312 306 b 2f 313 307 1: 314 308 cmp w0, #CLOCK_REALTIME_COARSE 315 309 ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne 316 310 b.ne 4f 317 - ldr x2, 6f 311 + ldr x2, 5f 318 312 2: 319 313 cbz x1, 3f 320 314 stp xzr, x2, [x1] ··· 329 321 svc #0 330 322 ret 331 323 5: 332 - .quad CLOCK_REALTIME_RES 333 - 6: 334 324 .quad CLOCK_COARSE_RES 335 325 .cfi_endproc 336 326 ENDPROC(__kernel_clock_getres)
+1 -1
arch/arm64/lib/Makefile
··· 24 24 -fcall-saved-x10 -fcall-saved-x11 -fcall-saved-x12 \ 25 25 -fcall-saved-x13 -fcall-saved-x14 -fcall-saved-x15 \ 26 26 -fcall-saved-x18 -fomit-frame-pointer 27 - CFLAGS_REMOVE_atomic_ll_sc.o := -pg 27 + CFLAGS_REMOVE_atomic_ll_sc.o := $(CC_FLAGS_FTRACE) 28 28 GCOV_PROFILE_atomic_ll_sc.o := n 29 29 KASAN_SANITIZE_atomic_ll_sc.o := n 30 30 KCOV_INSTRUMENT_atomic_ll_sc.o := n
+5 -11
arch/arm64/mm/fault.c
··· 148 148 /* 149 149 * Dump out the page tables associated with 'addr' in the currently active mm. 150 150 */ 151 - void show_pte(unsigned long addr) 151 + static void show_pte(unsigned long addr) 152 152 { 153 153 struct mm_struct *mm; 154 154 pgd_t *pgdp; ··· 810 810 debug_fault_info[nr].name = name; 811 811 } 812 812 813 - asmlinkage int __exception do_debug_exception(unsigned long addr_if_watchpoint, 814 - unsigned int esr, 815 - struct pt_regs *regs) 813 + asmlinkage void __exception do_debug_exception(unsigned long addr_if_watchpoint, 814 + unsigned int esr, 815 + struct pt_regs *regs) 816 816 { 817 817 const struct fault_info *inf = esr_to_debug_fault_info(esr); 818 818 unsigned long pc = instruction_pointer(regs); 819 - int rv; 820 819 821 820 /* 822 821 * Tell lockdep we disabled irqs in entry.S. Do nothing if they were ··· 827 828 if (user_mode(regs) && !is_ttbr0_addr(pc)) 828 829 arm64_apply_bp_hardening(); 829 830 830 - if (!inf->fn(addr_if_watchpoint, esr, regs)) { 831 - rv = 1; 832 - } else { 831 + if (inf->fn(addr_if_watchpoint, esr, regs)) { 833 832 arm64_notify_die(inf->name, regs, 834 833 inf->sig, inf->code, (void __user *)pc, esr); 835 - rv = 0; 836 834 } 837 835 838 836 if (interrupts_enabled(regs)) 839 837 trace_hardirqs_on(); 840 - 841 - return rv; 842 838 } 843 839 NOKPROBE_SYMBOL(do_debug_exception);
+3 -2
arch/arm64/mm/init.c
··· 377 377 base + size > memblock_start_of_DRAM() + 378 378 linear_region_size, 379 379 "initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) { 380 - initrd_start = 0; 380 + phys_initrd_size = 0; 381 381 } else { 382 382 memblock_remove(base, size); /* clear MEMBLOCK_ flags */ 383 383 memblock_add(base, size); ··· 440 440 early_memtest(min << PAGE_SHIFT, max << PAGE_SHIFT); 441 441 442 442 max_pfn = max_low_pfn = max; 443 + min_low_pfn = min; 443 444 444 445 arm64_numa_init(); 445 446 /* ··· 536 535 else 537 536 swiotlb_force = SWIOTLB_NO_FORCE; 538 537 539 - set_max_mapnr(pfn_to_page(max_pfn) - mem_map); 538 + set_max_mapnr(max_pfn - PHYS_PFN_OFFSET); 540 539 541 540 #ifndef CONFIG_SPARSEMEM_VMEMMAP 542 541 free_unused_memmap();
+33 -14
arch/arm64/mm/mmu.c
··· 97 97 } 98 98 EXPORT_SYMBOL(phys_mem_access_prot); 99 99 100 - static phys_addr_t __init early_pgtable_alloc(void) 100 + static phys_addr_t __init early_pgtable_alloc(int shift) 101 101 { 102 102 phys_addr_t phys; 103 103 void *ptr; ··· 174 174 static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, 175 175 unsigned long end, phys_addr_t phys, 176 176 pgprot_t prot, 177 - phys_addr_t (*pgtable_alloc)(void), 177 + phys_addr_t (*pgtable_alloc)(int), 178 178 int flags) 179 179 { 180 180 unsigned long next; ··· 184 184 if (pmd_none(pmd)) { 185 185 phys_addr_t pte_phys; 186 186 BUG_ON(!pgtable_alloc); 187 - pte_phys = pgtable_alloc(); 187 + pte_phys = pgtable_alloc(PAGE_SHIFT); 188 188 __pmd_populate(pmdp, pte_phys, PMD_TYPE_TABLE); 189 189 pmd = READ_ONCE(*pmdp); 190 190 } ··· 208 208 209 209 static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, 210 210 phys_addr_t phys, pgprot_t prot, 211 - phys_addr_t (*pgtable_alloc)(void), int flags) 211 + phys_addr_t (*pgtable_alloc)(int), int flags) 212 212 { 213 213 unsigned long next; 214 214 pmd_t *pmdp; ··· 246 246 static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, 247 247 unsigned long end, phys_addr_t phys, 248 248 pgprot_t prot, 249 - phys_addr_t (*pgtable_alloc)(void), int flags) 249 + phys_addr_t (*pgtable_alloc)(int), int flags) 250 250 { 251 251 unsigned long next; 252 252 pud_t pud = READ_ONCE(*pudp); ··· 258 258 if (pud_none(pud)) { 259 259 phys_addr_t pmd_phys; 260 260 BUG_ON(!pgtable_alloc); 261 - pmd_phys = pgtable_alloc(); 261 + pmd_phys = pgtable_alloc(PMD_SHIFT); 262 262 __pud_populate(pudp, pmd_phys, PUD_TYPE_TABLE); 263 263 pud = READ_ONCE(*pudp); 264 264 } ··· 294 294 295 295 static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, 296 296 phys_addr_t phys, pgprot_t prot, 297 - phys_addr_t (*pgtable_alloc)(void), 297 + phys_addr_t (*pgtable_alloc)(int), 298 298 int flags) 299 299 { 300 300 unsigned long next; ··· 304 304 if (pgd_none(pgd)) { 305 305 phys_addr_t pud_phys; 306 306 BUG_ON(!pgtable_alloc); 307 - pud_phys = pgtable_alloc(); 307 + pud_phys = pgtable_alloc(PUD_SHIFT); 308 308 __pgd_populate(pgdp, pud_phys, PUD_TYPE_TABLE); 309 309 pgd = READ_ONCE(*pgdp); 310 310 } ··· 345 345 static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, 346 346 unsigned long virt, phys_addr_t size, 347 347 pgprot_t prot, 348 - phys_addr_t (*pgtable_alloc)(void), 348 + phys_addr_t (*pgtable_alloc)(int), 349 349 int flags) 350 350 { 351 351 unsigned long addr, length, end, next; ··· 371 371 } while (pgdp++, addr = next, addr != end); 372 372 } 373 373 374 - static phys_addr_t pgd_pgtable_alloc(void) 374 + static phys_addr_t __pgd_pgtable_alloc(int shift) 375 375 { 376 376 void *ptr = (void *)__get_free_page(PGALLOC_GFP); 377 - if (!ptr || !pgtable_page_ctor(virt_to_page(ptr))) 378 - BUG(); 377 + BUG_ON(!ptr); 379 378 380 379 /* Ensure the zeroed page is visible to the page table walker */ 381 380 dsb(ishst); 382 381 return __pa(ptr); 382 + } 383 + 384 + static phys_addr_t pgd_pgtable_alloc(int shift) 385 + { 386 + phys_addr_t pa = __pgd_pgtable_alloc(shift); 387 + 388 + /* 389 + * Call proper page table ctor in case later we need to 390 + * call core mm functions like apply_to_page_range() on 391 + * this pre-allocated page table. 392 + * 393 + * We don't select ARCH_ENABLE_SPLIT_PMD_PTLOCK if pmd is 394 + * folded, and if so pgtable_pmd_page_ctor() becomes nop. 395 + */ 396 + if (shift == PAGE_SHIFT) 397 + BUG_ON(!pgtable_page_ctor(phys_to_page(pa))); 398 + else if (shift == PMD_SHIFT) 399 + BUG_ON(!pgtable_pmd_page_ctor(phys_to_page(pa))); 400 + 401 + return pa; 383 402 } 384 403 385 404 /* ··· 602 583 /* Map only the text into the trampoline page table */ 603 584 memset(tramp_pg_dir, 0, PGD_SIZE); 604 585 __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE, 605 - prot, pgd_pgtable_alloc, 0); 586 + prot, __pgd_pgtable_alloc, 0); 606 587 607 588 /* Map both the text and data into the kernel page table */ 608 589 __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot); ··· 1074 1055 flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; 1075 1056 1076 1057 __create_pgd_mapping(swapper_pg_dir, start, __phys_to_virt(start), 1077 - size, PAGE_KERNEL, pgd_pgtable_alloc, flags); 1058 + size, PAGE_KERNEL, __pgd_pgtable_alloc, flags); 1078 1059 1079 1060 return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, 1080 1061 altmap, want_memblock);
+12 -13
arch/arm64/mm/numa.c
··· 124 124 } 125 125 126 126 /* 127 - * Set the cpu to node and mem mapping 127 + * Set the cpu to node and mem mapping 128 128 */ 129 129 void numa_store_cpu_info(unsigned int cpu) 130 130 { ··· 200 200 #endif 201 201 202 202 /** 203 - * numa_add_memblk - Set node id to memblk 203 + * numa_add_memblk() - Set node id to memblk 204 204 * @nid: NUMA node ID of the new memblk 205 205 * @start: Start address of the new memblk 206 206 * @end: End address of the new memblk ··· 223 223 return ret; 224 224 } 225 225 226 - /** 226 + /* 227 227 * Initialize NODE_DATA for a node on the local memory 228 228 */ 229 229 static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn) ··· 257 257 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn; 258 258 } 259 259 260 - /** 260 + /* 261 261 * numa_free_distance 262 262 * 263 263 * The current table is freed. ··· 277 277 numa_distance = NULL; 278 278 } 279 279 280 - /** 281 - * 280 + /* 282 281 * Create a new NUMA distance table. 283 - * 284 282 */ 285 283 static int __init numa_alloc_distance(void) 286 284 { ··· 309 311 } 310 312 311 313 /** 312 - * numa_set_distance - Set inter node NUMA distance from node to node. 314 + * numa_set_distance() - Set inter node NUMA distance from node to node. 313 315 * @from: the 'from' node to set distance 314 316 * @to: the 'to' node to set distance 315 317 * @distance: NUMA distance ··· 319 321 * 320 322 * If @from or @to is higher than the highest known node or lower than zero 321 323 * or @distance doesn't make sense, the call is ignored. 322 - * 323 324 */ 324 325 void __init numa_set_distance(int from, int to, int distance) 325 326 { ··· 344 347 numa_distance[from * numa_distance_cnt + to] = distance; 345 348 } 346 349 347 - /** 350 + /* 348 351 * Return NUMA distance @from to @to 349 352 */ 350 353 int __node_distance(int from, int to) ··· 419 422 } 420 423 421 424 /** 422 - * dummy_numa_init - Fallback dummy NUMA init 425 + * dummy_numa_init() - Fallback dummy NUMA init 423 426 * 424 427 * Used if there's no underlying NUMA architecture, NUMA initialization 425 428 * fails, or NUMA is disabled on the command line. 426 429 * 427 430 * Must online at least one node (node 0) and add memory blocks that cover all 428 431 * allowed memory. It is unlikely that this function fails. 432 + * 433 + * Return: 0 on success, -errno on failure. 429 434 */ 430 435 static int __init dummy_numa_init(void) 431 436 { ··· 453 454 } 454 455 455 456 /** 456 - * arm64_numa_init - Initialize NUMA 457 + * arm64_numa_init() - Initialize NUMA 457 458 * 458 - * Try each configured NUMA initialization method until one succeeds. The 459 + * Try each configured NUMA initialization method until one succeeds. The 459 460 * last fallback is dummy single node config encomapssing whole memory. 460 461 */ 461 462 void __init arm64_numa_init(void)
+18 -16
arch/arm64/mm/proc.S
··· 65 65 mrs x2, tpidr_el0 66 66 mrs x3, tpidrro_el0 67 67 mrs x4, contextidr_el1 68 - mrs x5, cpacr_el1 69 - mrs x6, tcr_el1 70 - mrs x7, vbar_el1 71 - mrs x8, mdscr_el1 72 - mrs x9, oslsr_el1 73 - mrs x10, sctlr_el1 68 + mrs x5, osdlr_el1 69 + mrs x6, cpacr_el1 70 + mrs x7, tcr_el1 71 + mrs x8, vbar_el1 72 + mrs x9, mdscr_el1 73 + mrs x10, oslsr_el1 74 + mrs x11, sctlr_el1 74 75 alternative_if_not ARM64_HAS_VIRT_HOST_EXTN 75 - mrs x11, tpidr_el1 76 + mrs x12, tpidr_el1 76 77 alternative_else 77 - mrs x11, tpidr_el2 78 + mrs x12, tpidr_el2 78 79 alternative_endif 79 - mrs x12, sp_el0 80 + mrs x13, sp_el0 80 81 stp x2, x3, [x0] 81 - stp x4, xzr, [x0, #16] 82 - stp x5, x6, [x0, #32] 83 - stp x7, x8, [x0, #48] 84 - stp x9, x10, [x0, #64] 85 - stp x11, x12, [x0, #80] 82 + stp x4, x5, [x0, #16] 83 + stp x6, x7, [x0, #32] 84 + stp x8, x9, [x0, #48] 85 + stp x10, x11, [x0, #64] 86 + stp x12, x13, [x0, #80] 86 87 ret 87 88 ENDPROC(cpu_do_suspend) 88 89 ··· 106 105 msr cpacr_el1, x6 107 106 108 107 /* Don't change t0sz here, mask those bits when restoring */ 109 - mrs x5, tcr_el1 110 - bfi x8, x5, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH 108 + mrs x7, tcr_el1 109 + bfi x8, x7, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH 111 110 112 111 msr tcr_el1, x8 113 112 msr vbar_el1, x9 ··· 131 130 /* 132 131 * Restore oslsr_el1 by writing oslar_el1 133 132 */ 133 + msr osdlr_el1, x5 134 134 ubfx x11, x11, #1, #1 135 135 msr oslar_el1, x11 136 136 reset_pmuserenr_el0 x0 // Disable PMU access from EL0
+121 -29
drivers/acpi/arm64/iort.c
··· 356 356 if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { 357 357 if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || 358 358 node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX || 359 - node->type == ACPI_IORT_NODE_SMMU_V3) { 359 + node->type == ACPI_IORT_NODE_SMMU_V3 || 360 + node->type == ACPI_IORT_NODE_PMCG) { 360 361 *id_out = map->output_base; 361 362 return parent; 362 363 } ··· 395 394 } 396 395 397 396 return smmu->id_mapping_index; 397 + case ACPI_IORT_NODE_PMCG: 398 + return 0; 398 399 default: 399 400 return -EINVAL; 400 401 } ··· 1221 1218 } 1222 1219 } 1223 1220 1224 - static bool __init arm_smmu_v3_is_coherent(struct acpi_iort_node *node) 1221 + static void __init arm_smmu_v3_dma_configure(struct device *dev, 1222 + struct acpi_iort_node *node) 1225 1223 { 1226 1224 struct acpi_iort_smmu_v3 *smmu; 1225 + enum dev_dma_attr attr; 1227 1226 1228 1227 /* Retrieve SMMUv3 specific data */ 1229 1228 smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 1230 1229 1231 - return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE; 1230 + attr = (smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE) ? 1231 + DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; 1232 + 1233 + /* We expect the dma masks to be equivalent for all SMMUv3 set-ups */ 1234 + dev->dma_mask = &dev->coherent_dma_mask; 1235 + 1236 + /* Configure DMA for the page table walker */ 1237 + acpi_dma_configure(dev, attr); 1232 1238 } 1233 1239 1234 1240 #if defined(CONFIG_ACPI_NUMA) 1235 1241 /* 1236 1242 * set numa proximity domain for smmuv3 device 1237 1243 */ 1238 - static void __init arm_smmu_v3_set_proximity(struct device *dev, 1244 + static int __init arm_smmu_v3_set_proximity(struct device *dev, 1239 1245 struct acpi_iort_node *node) 1240 1246 { 1241 1247 struct acpi_iort_smmu_v3 *smmu; 1242 1248 1243 1249 smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 1244 1250 if (smmu->flags & ACPI_IORT_SMMU_V3_PXM_VALID) { 1245 - set_dev_node(dev, acpi_map_pxm_to_node(smmu->pxm)); 1251 + int node = acpi_map_pxm_to_node(smmu->pxm); 1252 + 1253 + if (node != NUMA_NO_NODE && !node_online(node)) 1254 + return -EINVAL; 1255 + 1256 + set_dev_node(dev, node); 1246 1257 pr_info("SMMU-v3[%llx] Mapped to Proximity domain %d\n", 1247 1258 smmu->base_address, 1248 1259 smmu->pxm); 1249 1260 } 1261 + return 0; 1250 1262 } 1251 1263 #else 1252 1264 #define arm_smmu_v3_set_proximity NULL ··· 1319 1301 } 1320 1302 } 1321 1303 1322 - static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node) 1304 + static void __init arm_smmu_dma_configure(struct device *dev, 1305 + struct acpi_iort_node *node) 1323 1306 { 1324 1307 struct acpi_iort_smmu *smmu; 1308 + enum dev_dma_attr attr; 1325 1309 1326 1310 /* Retrieve SMMU specific data */ 1327 1311 smmu = (struct acpi_iort_smmu *)node->node_data; 1328 1312 1329 - return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK; 1313 + attr = (smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK) ? 1314 + DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; 1315 + 1316 + /* We expect the dma masks to be equivalent for SMMU set-ups */ 1317 + dev->dma_mask = &dev->coherent_dma_mask; 1318 + 1319 + /* Configure DMA for the page table walker */ 1320 + acpi_dma_configure(dev, attr); 1321 + } 1322 + 1323 + static int __init arm_smmu_v3_pmcg_count_resources(struct acpi_iort_node *node) 1324 + { 1325 + struct acpi_iort_pmcg *pmcg; 1326 + 1327 + /* Retrieve PMCG specific data */ 1328 + pmcg = (struct acpi_iort_pmcg *)node->node_data; 1329 + 1330 + /* 1331 + * There are always 2 memory resources. 1332 + * If the overflow_gsiv is present then add that for a total of 3. 1333 + */ 1334 + return pmcg->overflow_gsiv ? 3 : 2; 1335 + } 1336 + 1337 + static void __init arm_smmu_v3_pmcg_init_resources(struct resource *res, 1338 + struct acpi_iort_node *node) 1339 + { 1340 + struct acpi_iort_pmcg *pmcg; 1341 + 1342 + /* Retrieve PMCG specific data */ 1343 + pmcg = (struct acpi_iort_pmcg *)node->node_data; 1344 + 1345 + res[0].start = pmcg->page0_base_address; 1346 + res[0].end = pmcg->page0_base_address + SZ_4K - 1; 1347 + res[0].flags = IORESOURCE_MEM; 1348 + res[1].start = pmcg->page1_base_address; 1349 + res[1].end = pmcg->page1_base_address + SZ_4K - 1; 1350 + res[1].flags = IORESOURCE_MEM; 1351 + 1352 + if (pmcg->overflow_gsiv) 1353 + acpi_iort_register_irq(pmcg->overflow_gsiv, "overflow", 1354 + ACPI_EDGE_SENSITIVE, &res[2]); 1355 + } 1356 + 1357 + static struct acpi_platform_list pmcg_plat_info[] __initdata = { 1358 + /* HiSilicon Hip08 Platform */ 1359 + {"HISI ", "HIP08 ", 0, ACPI_SIG_IORT, greater_than_or_equal, 1360 + "Erratum #162001800", IORT_SMMU_V3_PMCG_HISI_HIP08}, 1361 + { } 1362 + }; 1363 + 1364 + static int __init arm_smmu_v3_pmcg_add_platdata(struct platform_device *pdev) 1365 + { 1366 + u32 model; 1367 + int idx; 1368 + 1369 + idx = acpi_match_platform_list(pmcg_plat_info); 1370 + if (idx >= 0) 1371 + model = pmcg_plat_info[idx].data; 1372 + else 1373 + model = IORT_SMMU_V3_PMCG_GENERIC; 1374 + 1375 + return platform_device_add_data(pdev, &model, sizeof(model)); 1330 1376 } 1331 1377 1332 1378 struct iort_dev_config { 1333 1379 const char *name; 1334 1380 int (*dev_init)(struct acpi_iort_node *node); 1335 - bool (*dev_is_coherent)(struct acpi_iort_node *node); 1381 + void (*dev_dma_configure)(struct device *dev, 1382 + struct acpi_iort_node *node); 1336 1383 int (*dev_count_resources)(struct acpi_iort_node *node); 1337 1384 void (*dev_init_resources)(struct resource *res, 1338 1385 struct acpi_iort_node *node); 1339 - void (*dev_set_proximity)(struct device *dev, 1386 + int (*dev_set_proximity)(struct device *dev, 1340 1387 struct acpi_iort_node *node); 1388 + int (*dev_add_platdata)(struct platform_device *pdev); 1341 1389 }; 1342 1390 1343 1391 static const struct iort_dev_config iort_arm_smmu_v3_cfg __initconst = { 1344 1392 .name = "arm-smmu-v3", 1345 - .dev_is_coherent = arm_smmu_v3_is_coherent, 1393 + .dev_dma_configure = arm_smmu_v3_dma_configure, 1346 1394 .dev_count_resources = arm_smmu_v3_count_resources, 1347 1395 .dev_init_resources = arm_smmu_v3_init_resources, 1348 1396 .dev_set_proximity = arm_smmu_v3_set_proximity, ··· 1416 1332 1417 1333 static const struct iort_dev_config iort_arm_smmu_cfg __initconst = { 1418 1334 .name = "arm-smmu", 1419 - .dev_is_coherent = arm_smmu_is_coherent, 1335 + .dev_dma_configure = arm_smmu_dma_configure, 1420 1336 .dev_count_resources = arm_smmu_count_resources, 1421 - .dev_init_resources = arm_smmu_init_resources 1337 + .dev_init_resources = arm_smmu_init_resources, 1338 + }; 1339 + 1340 + static const struct iort_dev_config iort_arm_smmu_v3_pmcg_cfg __initconst = { 1341 + .name = "arm-smmu-v3-pmcg", 1342 + .dev_count_resources = arm_smmu_v3_pmcg_count_resources, 1343 + .dev_init_resources = arm_smmu_v3_pmcg_init_resources, 1344 + .dev_add_platdata = arm_smmu_v3_pmcg_add_platdata, 1422 1345 }; 1423 1346 1424 1347 static __init const struct iort_dev_config *iort_get_dev_cfg( ··· 1436 1345 return &iort_arm_smmu_v3_cfg; 1437 1346 case ACPI_IORT_NODE_SMMU: 1438 1347 return &iort_arm_smmu_cfg; 1348 + case ACPI_IORT_NODE_PMCG: 1349 + return &iort_arm_smmu_v3_pmcg_cfg; 1439 1350 default: 1440 1351 return NULL; 1441 1352 } ··· 1455 1362 struct fwnode_handle *fwnode; 1456 1363 struct platform_device *pdev; 1457 1364 struct resource *r; 1458 - enum dev_dma_attr attr; 1459 1365 int ret, count; 1460 1366 1461 1367 pdev = platform_device_alloc(ops->name, PLATFORM_DEVID_AUTO); 1462 1368 if (!pdev) 1463 1369 return -ENOMEM; 1464 1370 1465 - if (ops->dev_set_proximity) 1466 - ops->dev_set_proximity(&pdev->dev, node); 1371 + if (ops->dev_set_proximity) { 1372 + ret = ops->dev_set_proximity(&pdev->dev, node); 1373 + if (ret) 1374 + goto dev_put; 1375 + } 1467 1376 1468 1377 count = ops->dev_count_resources(node); 1469 1378 ··· 1488 1393 goto dev_put; 1489 1394 1490 1395 /* 1491 - * Add a copy of IORT node pointer to platform_data to 1492 - * be used to retrieve IORT data information. 1396 + * Platform devices based on PMCG nodes uses platform_data to 1397 + * pass the hardware model info to the driver. For others, add 1398 + * a copy of IORT node pointer to platform_data to be used to 1399 + * retrieve IORT data information. 1493 1400 */ 1494 - ret = platform_device_add_data(pdev, &node, sizeof(node)); 1401 + if (ops->dev_add_platdata) 1402 + ret = ops->dev_add_platdata(pdev); 1403 + else 1404 + ret = platform_device_add_data(pdev, &node, sizeof(node)); 1405 + 1495 1406 if (ret) 1496 1407 goto dev_put; 1497 - 1498 - /* 1499 - * We expect the dma masks to be equivalent for 1500 - * all SMMUs set-ups 1501 - */ 1502 - pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 1503 1408 1504 1409 fwnode = iort_get_fwnode(node); 1505 1410 ··· 1510 1415 1511 1416 pdev->dev.fwnode = fwnode; 1512 1417 1513 - attr = ops->dev_is_coherent && ops->dev_is_coherent(node) ? 1514 - DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; 1515 - 1516 - /* Configure DMA for the page table walker */ 1517 - acpi_dma_configure(&pdev->dev, attr); 1418 + if (ops->dev_dma_configure) 1419 + ops->dev_dma_configure(&pdev->dev, node); 1518 1420 1519 1421 iort_set_device_domain(&pdev->dev, node); 1520 1422
+66 -74
drivers/clocksource/arm_arch_timer.c
··· 149 149 return val; 150 150 } 151 151 152 + static u64 arch_counter_get_cntpct_stable(void) 153 + { 154 + return __arch_counter_get_cntpct_stable(); 155 + } 156 + 157 + static u64 arch_counter_get_cntpct(void) 158 + { 159 + return __arch_counter_get_cntpct(); 160 + } 161 + 162 + static u64 arch_counter_get_cntvct_stable(void) 163 + { 164 + return __arch_counter_get_cntvct_stable(); 165 + } 166 + 167 + static u64 arch_counter_get_cntvct(void) 168 + { 169 + return __arch_counter_get_cntvct(); 170 + } 171 + 152 172 /* 153 173 * Default to cp15 based access because arm64 uses this function for 154 174 * sched_clock() before DT is probed and the cp15 method is guaranteed ··· 336 316 } 337 317 #endif 338 318 339 - #ifdef CONFIG_ARM64_ERRATUM_1188873 340 - static u64 notrace arm64_1188873_read_cntvct_el0(void) 341 - { 342 - return read_sysreg(cntvct_el0); 343 - } 344 - #endif 345 - 346 319 #ifdef CONFIG_SUN50I_ERRATUM_UNKNOWN1 347 320 /* 348 321 * The low bits of the counter registers are indeterminate while bit 10 or ··· 382 369 DEFINE_PER_CPU(const struct arch_timer_erratum_workaround *, timer_unstable_counter_workaround); 383 370 EXPORT_SYMBOL_GPL(timer_unstable_counter_workaround); 384 371 385 - DEFINE_STATIC_KEY_FALSE(arch_timer_read_ool_enabled); 386 - EXPORT_SYMBOL_GPL(arch_timer_read_ool_enabled); 372 + static atomic_t timer_unstable_counter_workaround_in_use = ATOMIC_INIT(0); 387 373 388 374 static void erratum_set_next_event_tval_generic(const int access, unsigned long evt, 389 375 struct clock_event_device *clk) ··· 464 452 .desc = "ARM erratum 858921", 465 453 .read_cntpct_el0 = arm64_858921_read_cntpct_el0, 466 454 .read_cntvct_el0 = arm64_858921_read_cntvct_el0, 467 - }, 468 - #endif 469 - #ifdef CONFIG_ARM64_ERRATUM_1188873 470 - { 471 - .match_type = ate_match_local_cap_id, 472 - .id = (void *)ARM64_WORKAROUND_1188873, 473 - .desc = "ARM erratum 1188873", 474 - .read_cntvct_el0 = arm64_1188873_read_cntvct_el0, 475 455 }, 476 456 #endif 477 457 #ifdef CONFIG_SUN50I_ERRATUM_UNKNOWN1 ··· 553 549 per_cpu(timer_unstable_counter_workaround, i) = wa; 554 550 } 555 551 556 - /* 557 - * Use the locked version, as we're called from the CPU 558 - * hotplug framework. Otherwise, we end-up in deadlock-land. 559 - */ 560 - static_branch_enable_cpuslocked(&arch_timer_read_ool_enabled); 552 + if (wa->read_cntvct_el0 || wa->read_cntpct_el0) 553 + atomic_set(&timer_unstable_counter_workaround_in_use, 1); 561 554 562 555 /* 563 556 * Don't use the vdso fastpath if errata require using the ··· 571 570 static void arch_timer_check_ool_workaround(enum arch_timer_erratum_match_type type, 572 571 void *arg) 573 572 { 574 - const struct arch_timer_erratum_workaround *wa; 573 + const struct arch_timer_erratum_workaround *wa, *__wa; 575 574 ate_match_fn_t match_fn = NULL; 576 575 bool local = false; 577 576 ··· 595 594 if (!wa) 596 595 return; 597 596 598 - if (needs_unstable_timer_counter_workaround()) { 599 - const struct arch_timer_erratum_workaround *__wa; 600 - __wa = __this_cpu_read(timer_unstable_counter_workaround); 601 - if (__wa && wa != __wa) 602 - pr_warn("Can't enable workaround for %s (clashes with %s\n)", 603 - wa->desc, __wa->desc); 597 + __wa = __this_cpu_read(timer_unstable_counter_workaround); 598 + if (__wa && wa != __wa) 599 + pr_warn("Can't enable workaround for %s (clashes with %s\n)", 600 + wa->desc, __wa->desc); 604 601 605 - if (__wa) 606 - return; 607 - } 602 + if (__wa) 603 + return; 608 604 609 605 arch_timer_enable_workaround(wa, local); 610 606 pr_info("Enabling %s workaround for %s\n", 611 607 local ? "local" : "global", wa->desc); 612 608 } 613 609 614 - #define erratum_handler(fn, r, ...) \ 615 - ({ \ 616 - bool __val; \ 617 - if (needs_unstable_timer_counter_workaround()) { \ 618 - const struct arch_timer_erratum_workaround *__wa; \ 619 - __wa = __this_cpu_read(timer_unstable_counter_workaround); \ 620 - if (__wa && __wa->fn) { \ 621 - r = __wa->fn(__VA_ARGS__); \ 622 - __val = true; \ 623 - } else { \ 624 - __val = false; \ 625 - } \ 626 - } else { \ 627 - __val = false; \ 628 - } \ 629 - __val; \ 630 - }) 631 - 632 610 static bool arch_timer_this_cpu_has_cntvct_wa(void) 633 611 { 634 - const struct arch_timer_erratum_workaround *wa; 612 + return has_erratum_handler(read_cntvct_el0); 613 + } 635 614 636 - wa = __this_cpu_read(timer_unstable_counter_workaround); 637 - return wa && wa->read_cntvct_el0; 615 + static bool arch_timer_counter_has_wa(void) 616 + { 617 + return atomic_read(&timer_unstable_counter_workaround_in_use); 638 618 } 639 619 #else 640 620 #define arch_timer_check_ool_workaround(t,a) do { } while(0) 641 - #define erratum_set_next_event_tval_virt(...) ({BUG(); 0;}) 642 - #define erratum_set_next_event_tval_phys(...) ({BUG(); 0;}) 643 - #define erratum_handler(fn, r, ...) ({false;}) 644 621 #define arch_timer_this_cpu_has_cntvct_wa() ({false;}) 622 + #define arch_timer_counter_has_wa() ({false;}) 645 623 #endif /* CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND */ 646 624 647 625 static __always_inline irqreturn_t timer_handler(const int access, ··· 713 733 static int arch_timer_set_next_event_virt(unsigned long evt, 714 734 struct clock_event_device *clk) 715 735 { 716 - int ret; 717 - 718 - if (erratum_handler(set_next_event_virt, ret, evt, clk)) 719 - return ret; 720 - 721 736 set_next_event(ARCH_TIMER_VIRT_ACCESS, evt, clk); 722 737 return 0; 723 738 } ··· 720 745 static int arch_timer_set_next_event_phys(unsigned long evt, 721 746 struct clock_event_device *clk) 722 747 { 723 - int ret; 724 - 725 - if (erratum_handler(set_next_event_phys, ret, evt, clk)) 726 - return ret; 727 - 728 748 set_next_event(ARCH_TIMER_PHYS_ACCESS, evt, clk); 729 749 return 0; 730 750 } ··· 744 774 clk->features = CLOCK_EVT_FEAT_ONESHOT; 745 775 746 776 if (type == ARCH_TIMER_TYPE_CP15) { 777 + typeof(clk->set_next_event) sne; 778 + 779 + arch_timer_check_ool_workaround(ate_match_local_cap_id, NULL); 780 + 747 781 if (arch_timer_c3stop) 748 782 clk->features |= CLOCK_EVT_FEAT_C3STOP; 749 783 clk->name = "arch_sys_timer"; ··· 758 784 case ARCH_TIMER_VIRT_PPI: 759 785 clk->set_state_shutdown = arch_timer_shutdown_virt; 760 786 clk->set_state_oneshot_stopped = arch_timer_shutdown_virt; 761 - clk->set_next_event = arch_timer_set_next_event_virt; 787 + sne = erratum_handler(set_next_event_virt); 762 788 break; 763 789 case ARCH_TIMER_PHYS_SECURE_PPI: 764 790 case ARCH_TIMER_PHYS_NONSECURE_PPI: 765 791 case ARCH_TIMER_HYP_PPI: 766 792 clk->set_state_shutdown = arch_timer_shutdown_phys; 767 793 clk->set_state_oneshot_stopped = arch_timer_shutdown_phys; 768 - clk->set_next_event = arch_timer_set_next_event_phys; 794 + sne = erratum_handler(set_next_event_phys); 769 795 break; 770 796 default: 771 797 BUG(); 772 798 } 773 799 774 - arch_timer_check_ool_workaround(ate_match_local_cap_id, NULL); 800 + clk->set_next_event = sne; 775 801 } else { 776 802 clk->features |= CLOCK_EVT_FEAT_DYNIRQ; 777 803 clk->name = "arch_mem_timer"; ··· 804 830 cntkctl |= (divider << ARCH_TIMER_EVT_TRIGGER_SHIFT) 805 831 | ARCH_TIMER_VIRT_EVT_EN; 806 832 arch_timer_set_cntkctl(cntkctl); 833 + #ifdef CONFIG_ARM64 834 + cpu_set_named_feature(EVTSTRM); 835 + #else 807 836 elf_hwcap |= HWCAP_EVTSTRM; 837 + #endif 808 838 #ifdef CONFIG_COMPAT 809 839 compat_elf_hwcap |= COMPAT_HWCAP_EVTSTRM; 810 840 #endif ··· 973 995 974 996 /* Register the CP15 based counter if we have one */ 975 997 if (type & ARCH_TIMER_TYPE_CP15) { 976 - if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) || 977 - arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) 978 - arch_timer_read_counter = arch_counter_get_cntvct; 979 - else 980 - arch_timer_read_counter = arch_counter_get_cntpct; 998 + u64 (*rd)(void); 981 999 1000 + if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) || 1001 + arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) { 1002 + if (arch_timer_counter_has_wa()) 1003 + rd = arch_counter_get_cntvct_stable; 1004 + else 1005 + rd = arch_counter_get_cntvct; 1006 + } else { 1007 + if (arch_timer_counter_has_wa()) 1008 + rd = arch_counter_get_cntpct_stable; 1009 + else 1010 + rd = arch_counter_get_cntpct; 1011 + } 1012 + 1013 + arch_timer_read_counter = rd; 982 1014 clocksource_counter.archdata.vdso_direct = vdso_default; 983 1015 } else { 984 1016 arch_timer_read_counter = arch_counter_get_cntvct_mem; ··· 1040 1052 } else if (action == CPU_PM_ENTER_FAILED || action == CPU_PM_EXIT) { 1041 1053 arch_timer_set_cntkctl(__this_cpu_read(saved_cntkctl)); 1042 1054 1055 + #ifdef CONFIG_ARM64 1056 + if (cpu_have_named_feature(EVTSTRM)) 1057 + #else 1043 1058 if (elf_hwcap & HWCAP_EVTSTRM) 1059 + #endif 1044 1060 cpumask_set_cpu(smp_processor_id(), &evtstrm_available); 1045 1061 } 1046 1062 return NOTIFY_OK;
+3
drivers/firmware/arm_sdei.c
··· 165 165 166 166 return err; 167 167 } 168 + NOKPROBE_SYMBOL(invoke_sdei_fn); 168 169 169 170 static struct sdei_event *sdei_event_find(u32 event_num) 170 171 { ··· 880 879 { 881 880 arm_smccc_smc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res); 882 881 } 882 + NOKPROBE_SYMBOL(sdei_smccc_smc); 883 883 884 884 static void sdei_smccc_hvc(unsigned long function_id, 885 885 unsigned long arg0, unsigned long arg1, ··· 889 887 { 890 888 arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res); 891 889 } 890 + NOKPROBE_SYMBOL(sdei_smccc_hvc); 892 891 893 892 int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb, 894 893 sdei_event_callback *critical_cb)
+3 -3
drivers/firmware/efi/libstub/Makefile
··· 16 16 17 17 # arm64 uses the full KBUILD_CFLAGS so it's necessary to explicitly 18 18 # disable the stackleak plugin 19 - cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) -fpie \ 20 - $(DISABLE_STACKLEAK_PLUGIN) 21 - cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ 19 + cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ 20 + -fpie $(DISABLE_STACKLEAK_PLUGIN) 21 + cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ 22 22 -fno-builtin -fpic \ 23 23 $(call cc-option,-mno-single-pic-base) 24 24
+9
drivers/perf/Kconfig
··· 52 52 depends on ARM_PMU && ACPI 53 53 def_bool y 54 54 55 + config ARM_SMMU_V3_PMU 56 + tristate "ARM SMMUv3 Performance Monitors Extension" 57 + depends on ARM64 && ACPI && ARM_SMMU_V3 58 + help 59 + Provides support for the ARM SMMUv3 Performance Monitor Counter 60 + Groups (PMCG), which provide monitoring of transactions passing 61 + through the SMMU and allow the resulting information to be filtered 62 + based on the Stream ID of the corresponding master. 63 + 55 64 config ARM_DSU_PMU 56 65 tristate "ARM DynamIQ Shared Unit (DSU) PMU" 57 66 depends on ARM64
+1
drivers/perf/Makefile
··· 4 4 obj-$(CONFIG_ARM_DSU_PMU) += arm_dsu_pmu.o 5 5 obj-$(CONFIG_ARM_PMU) += arm_pmu.o arm_pmu_platform.o 6 6 obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o 7 + obj-$(CONFIG_ARM_SMMU_V3_PMU) += arm_smmuv3_pmu.o 7 8 obj-$(CONFIG_HISI_PMU) += hisilicon/ 8 9 obj-$(CONFIG_QCOM_L2_PMU) += qcom_l2_pmu.o 9 10 obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o
+12 -9
drivers/perf/arm-cci.c
··· 1684 1684 raw_spin_lock_init(&cci_pmu->hw_events.pmu_lock); 1685 1685 mutex_init(&cci_pmu->reserve_mutex); 1686 1686 atomic_set(&cci_pmu->active_events, 0); 1687 - cci_pmu->cpu = get_cpu(); 1688 1687 1689 - ret = cci_pmu_init(cci_pmu, pdev); 1690 - if (ret) { 1691 - put_cpu(); 1692 - return ret; 1693 - } 1694 - 1688 + cci_pmu->cpu = raw_smp_processor_id(); 1689 + g_cci_pmu = cci_pmu; 1695 1690 cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_CCI_ONLINE, 1696 1691 "perf/arm/cci:online", NULL, 1697 1692 cci_pmu_offline_cpu); 1698 - put_cpu(); 1699 - g_cci_pmu = cci_pmu; 1693 + 1694 + ret = cci_pmu_init(cci_pmu, pdev); 1695 + if (ret) 1696 + goto error_pmu_init; 1697 + 1700 1698 pr_info("ARM %s PMU driver probed", cci_pmu->model->name); 1701 1699 return 0; 1700 + 1701 + error_pmu_init: 1702 + cpuhp_remove_state(CPUHP_AP_PERF_ARM_CCI_ONLINE); 1703 + g_cci_pmu = NULL; 1704 + return ret; 1702 1705 } 1703 1706 1704 1707 static int cci_pmu_remove(struct platform_device *pdev)
+13 -12
drivers/perf/arm-ccn.c
··· 167 167 168 168 struct hrtimer hrtimer; 169 169 170 - cpumask_t cpu; 170 + unsigned int cpu; 171 171 struct hlist_node node; 172 172 173 173 struct pmu pmu; ··· 559 559 { 560 560 struct arm_ccn *ccn = pmu_to_arm_ccn(dev_get_drvdata(dev)); 561 561 562 - return cpumap_print_to_pagebuf(true, buf, &ccn->dt.cpu); 562 + return cpumap_print_to_pagebuf(true, buf, cpumask_of(ccn->dt.cpu)); 563 563 } 564 564 565 565 static struct device_attribute arm_ccn_pmu_cpumask_attr = ··· 759 759 * mitigate this, we enforce CPU assignment to one, selected 760 760 * processor (the one described in the "cpumask" attribute). 761 761 */ 762 - event->cpu = cpumask_first(&ccn->dt.cpu); 762 + event->cpu = ccn->dt.cpu; 763 763 764 764 node_xp = CCN_CONFIG_NODE(event->attr.config); 765 765 type = CCN_CONFIG_TYPE(event->attr.config); ··· 1215 1215 struct arm_ccn *ccn = container_of(dt, struct arm_ccn, dt); 1216 1216 unsigned int target; 1217 1217 1218 - if (!cpumask_test_and_clear_cpu(cpu, &dt->cpu)) 1218 + if (cpu != dt->cpu) 1219 1219 return 0; 1220 1220 target = cpumask_any_but(cpu_online_mask, cpu); 1221 1221 if (target >= nr_cpu_ids) 1222 1222 return 0; 1223 1223 perf_pmu_migrate_context(&dt->pmu, cpu, target); 1224 - cpumask_set_cpu(target, &dt->cpu); 1224 + dt->cpu = target; 1225 1225 if (ccn->irq) 1226 - WARN_ON(irq_set_affinity_hint(ccn->irq, &dt->cpu) != 0); 1226 + WARN_ON(irq_set_affinity_hint(ccn->irq, cpumask_of(dt->cpu))); 1227 1227 return 0; 1228 1228 } 1229 1229 ··· 1299 1299 } 1300 1300 1301 1301 /* Pick one CPU which we will use to collect data from CCN... */ 1302 - cpumask_set_cpu(get_cpu(), &ccn->dt.cpu); 1302 + ccn->dt.cpu = raw_smp_processor_id(); 1303 1303 1304 1304 /* Also make sure that the overflow interrupt is handled by this CPU */ 1305 1305 if (ccn->irq) { 1306 - err = irq_set_affinity_hint(ccn->irq, &ccn->dt.cpu); 1306 + err = irq_set_affinity_hint(ccn->irq, cpumask_of(ccn->dt.cpu)); 1307 1307 if (err) { 1308 1308 dev_err(ccn->dev, "Failed to set interrupt affinity!\n"); 1309 1309 goto error_set_affinity; 1310 1310 } 1311 1311 } 1312 1312 1313 + cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1314 + &ccn->dt.node); 1315 + 1313 1316 err = perf_pmu_register(&ccn->dt.pmu, name, -1); 1314 1317 if (err) 1315 1318 goto error_pmu_register; 1316 1319 1317 - cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1318 - &ccn->dt.node); 1319 - put_cpu(); 1320 1320 return 0; 1321 1321 1322 1322 error_pmu_register: 1323 + cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_CCN_ONLINE, 1324 + &ccn->dt.node); 1323 1325 error_set_affinity: 1324 - put_cpu(); 1325 1326 error_choose_name: 1326 1327 ida_simple_remove(&arm_ccn_pmu_ida, ccn->dt.id); 1327 1328 for (i = 0; i < ccn->num_xps; i++)
+865
drivers/perf/arm_smmuv3_pmu.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + /* 4 + * This driver adds support for perf events to use the Performance 5 + * Monitor Counter Groups (PMCG) associated with an SMMUv3 node 6 + * to monitor that node. 7 + * 8 + * SMMUv3 PMCG devices are named as smmuv3_pmcg_<phys_addr_page> where 9 + * <phys_addr_page> is the physical page address of the SMMU PMCG wrapped 10 + * to 4K boundary. For example, the PMCG at 0xff88840000 is named 11 + * smmuv3_pmcg_ff88840 12 + * 13 + * Filtering by stream id is done by specifying filtering parameters 14 + * with the event. options are: 15 + * filter_enable - 0 = no filtering, 1 = filtering enabled 16 + * filter_span - 0 = exact match, 1 = pattern match 17 + * filter_stream_id - pattern to filter against 18 + * 19 + * To match a partial StreamID where the X most-significant bits must match 20 + * but the Y least-significant bits might differ, STREAMID is programmed 21 + * with a value that contains: 22 + * STREAMID[Y - 1] == 0. 23 + * STREAMID[Y - 2:0] == 1 (where Y > 1). 24 + * The remainder of implemented bits of STREAMID (X bits, from bit Y upwards) 25 + * contain a value to match from the corresponding bits of event StreamID. 26 + * 27 + * Example: perf stat -e smmuv3_pmcg_ff88840/transaction,filter_enable=1, 28 + * filter_span=1,filter_stream_id=0x42/ -a netperf 29 + * Applies filter pattern 0x42 to transaction events, which means events 30 + * matching stream ids 0x42 and 0x43 are counted. Further filtering 31 + * information is available in the SMMU documentation. 32 + * 33 + * SMMU events are not attributable to a CPU, so task mode and sampling 34 + * are not supported. 35 + */ 36 + 37 + #include <linux/acpi.h> 38 + #include <linux/acpi_iort.h> 39 + #include <linux/bitfield.h> 40 + #include <linux/bitops.h> 41 + #include <linux/cpuhotplug.h> 42 + #include <linux/cpumask.h> 43 + #include <linux/device.h> 44 + #include <linux/errno.h> 45 + #include <linux/interrupt.h> 46 + #include <linux/irq.h> 47 + #include <linux/kernel.h> 48 + #include <linux/list.h> 49 + #include <linux/msi.h> 50 + #include <linux/perf_event.h> 51 + #include <linux/platform_device.h> 52 + #include <linux/smp.h> 53 + #include <linux/sysfs.h> 54 + #include <linux/types.h> 55 + 56 + #define SMMU_PMCG_EVCNTR0 0x0 57 + #define SMMU_PMCG_EVCNTR(n, stride) (SMMU_PMCG_EVCNTR0 + (n) * (stride)) 58 + #define SMMU_PMCG_EVTYPER0 0x400 59 + #define SMMU_PMCG_EVTYPER(n) (SMMU_PMCG_EVTYPER0 + (n) * 4) 60 + #define SMMU_PMCG_SID_SPAN_SHIFT 29 61 + #define SMMU_PMCG_SMR0 0xA00 62 + #define SMMU_PMCG_SMR(n) (SMMU_PMCG_SMR0 + (n) * 4) 63 + #define SMMU_PMCG_CNTENSET0 0xC00 64 + #define SMMU_PMCG_CNTENCLR0 0xC20 65 + #define SMMU_PMCG_INTENSET0 0xC40 66 + #define SMMU_PMCG_INTENCLR0 0xC60 67 + #define SMMU_PMCG_OVSCLR0 0xC80 68 + #define SMMU_PMCG_OVSSET0 0xCC0 69 + #define SMMU_PMCG_CFGR 0xE00 70 + #define SMMU_PMCG_CFGR_SID_FILTER_TYPE BIT(23) 71 + #define SMMU_PMCG_CFGR_MSI BIT(21) 72 + #define SMMU_PMCG_CFGR_RELOC_CTRS BIT(20) 73 + #define SMMU_PMCG_CFGR_SIZE GENMASK(13, 8) 74 + #define SMMU_PMCG_CFGR_NCTR GENMASK(5, 0) 75 + #define SMMU_PMCG_CR 0xE04 76 + #define SMMU_PMCG_CR_ENABLE BIT(0) 77 + #define SMMU_PMCG_CEID0 0xE20 78 + #define SMMU_PMCG_CEID1 0xE28 79 + #define SMMU_PMCG_IRQ_CTRL 0xE50 80 + #define SMMU_PMCG_IRQ_CTRL_IRQEN BIT(0) 81 + #define SMMU_PMCG_IRQ_CFG0 0xE58 82 + #define SMMU_PMCG_IRQ_CFG1 0xE60 83 + #define SMMU_PMCG_IRQ_CFG2 0xE64 84 + 85 + /* MSI config fields */ 86 + #define MSI_CFG0_ADDR_MASK GENMASK_ULL(51, 2) 87 + #define MSI_CFG2_MEMATTR_DEVICE_nGnRE 0x1 88 + 89 + #define SMMU_PMCG_DEFAULT_FILTER_SPAN 1 90 + #define SMMU_PMCG_DEFAULT_FILTER_SID GENMASK(31, 0) 91 + 92 + #define SMMU_PMCG_MAX_COUNTERS 64 93 + #define SMMU_PMCG_ARCH_MAX_EVENTS 128 94 + 95 + #define SMMU_PMCG_PA_SHIFT 12 96 + 97 + #define SMMU_PMCG_EVCNTR_RDONLY BIT(0) 98 + 99 + static int cpuhp_state_num; 100 + 101 + struct smmu_pmu { 102 + struct hlist_node node; 103 + struct perf_event *events[SMMU_PMCG_MAX_COUNTERS]; 104 + DECLARE_BITMAP(used_counters, SMMU_PMCG_MAX_COUNTERS); 105 + DECLARE_BITMAP(supported_events, SMMU_PMCG_ARCH_MAX_EVENTS); 106 + unsigned int irq; 107 + unsigned int on_cpu; 108 + struct pmu pmu; 109 + unsigned int num_counters; 110 + struct device *dev; 111 + void __iomem *reg_base; 112 + void __iomem *reloc_base; 113 + u64 counter_mask; 114 + u32 options; 115 + bool global_filter; 116 + u32 global_filter_span; 117 + u32 global_filter_sid; 118 + }; 119 + 120 + #define to_smmu_pmu(p) (container_of(p, struct smmu_pmu, pmu)) 121 + 122 + #define SMMU_PMU_EVENT_ATTR_EXTRACTOR(_name, _config, _start, _end) \ 123 + static inline u32 get_##_name(struct perf_event *event) \ 124 + { \ 125 + return FIELD_GET(GENMASK_ULL(_end, _start), \ 126 + event->attr._config); \ 127 + } \ 128 + 129 + SMMU_PMU_EVENT_ATTR_EXTRACTOR(event, config, 0, 15); 130 + SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_stream_id, config1, 0, 31); 131 + SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_span, config1, 32, 32); 132 + SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_enable, config1, 33, 33); 133 + 134 + static inline void smmu_pmu_enable(struct pmu *pmu) 135 + { 136 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(pmu); 137 + 138 + writel(SMMU_PMCG_IRQ_CTRL_IRQEN, 139 + smmu_pmu->reg_base + SMMU_PMCG_IRQ_CTRL); 140 + writel(SMMU_PMCG_CR_ENABLE, smmu_pmu->reg_base + SMMU_PMCG_CR); 141 + } 142 + 143 + static inline void smmu_pmu_disable(struct pmu *pmu) 144 + { 145 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(pmu); 146 + 147 + writel(0, smmu_pmu->reg_base + SMMU_PMCG_CR); 148 + writel(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CTRL); 149 + } 150 + 151 + static inline void smmu_pmu_counter_set_value(struct smmu_pmu *smmu_pmu, 152 + u32 idx, u64 value) 153 + { 154 + if (smmu_pmu->counter_mask & BIT(32)) 155 + writeq(value, smmu_pmu->reloc_base + SMMU_PMCG_EVCNTR(idx, 8)); 156 + else 157 + writel(value, smmu_pmu->reloc_base + SMMU_PMCG_EVCNTR(idx, 4)); 158 + } 159 + 160 + static inline u64 smmu_pmu_counter_get_value(struct smmu_pmu *smmu_pmu, u32 idx) 161 + { 162 + u64 value; 163 + 164 + if (smmu_pmu->counter_mask & BIT(32)) 165 + value = readq(smmu_pmu->reloc_base + SMMU_PMCG_EVCNTR(idx, 8)); 166 + else 167 + value = readl(smmu_pmu->reloc_base + SMMU_PMCG_EVCNTR(idx, 4)); 168 + 169 + return value; 170 + } 171 + 172 + static inline void smmu_pmu_counter_enable(struct smmu_pmu *smmu_pmu, u32 idx) 173 + { 174 + writeq(BIT(idx), smmu_pmu->reg_base + SMMU_PMCG_CNTENSET0); 175 + } 176 + 177 + static inline void smmu_pmu_counter_disable(struct smmu_pmu *smmu_pmu, u32 idx) 178 + { 179 + writeq(BIT(idx), smmu_pmu->reg_base + SMMU_PMCG_CNTENCLR0); 180 + } 181 + 182 + static inline void smmu_pmu_interrupt_enable(struct smmu_pmu *smmu_pmu, u32 idx) 183 + { 184 + writeq(BIT(idx), smmu_pmu->reg_base + SMMU_PMCG_INTENSET0); 185 + } 186 + 187 + static inline void smmu_pmu_interrupt_disable(struct smmu_pmu *smmu_pmu, 188 + u32 idx) 189 + { 190 + writeq(BIT(idx), smmu_pmu->reg_base + SMMU_PMCG_INTENCLR0); 191 + } 192 + 193 + static inline void smmu_pmu_set_evtyper(struct smmu_pmu *smmu_pmu, u32 idx, 194 + u32 val) 195 + { 196 + writel(val, smmu_pmu->reg_base + SMMU_PMCG_EVTYPER(idx)); 197 + } 198 + 199 + static inline void smmu_pmu_set_smr(struct smmu_pmu *smmu_pmu, u32 idx, u32 val) 200 + { 201 + writel(val, smmu_pmu->reg_base + SMMU_PMCG_SMR(idx)); 202 + } 203 + 204 + static void smmu_pmu_event_update(struct perf_event *event) 205 + { 206 + struct hw_perf_event *hwc = &event->hw; 207 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 208 + u64 delta, prev, now; 209 + u32 idx = hwc->idx; 210 + 211 + do { 212 + prev = local64_read(&hwc->prev_count); 213 + now = smmu_pmu_counter_get_value(smmu_pmu, idx); 214 + } while (local64_cmpxchg(&hwc->prev_count, prev, now) != prev); 215 + 216 + /* handle overflow. */ 217 + delta = now - prev; 218 + delta &= smmu_pmu->counter_mask; 219 + 220 + local64_add(delta, &event->count); 221 + } 222 + 223 + static void smmu_pmu_set_period(struct smmu_pmu *smmu_pmu, 224 + struct hw_perf_event *hwc) 225 + { 226 + u32 idx = hwc->idx; 227 + u64 new; 228 + 229 + if (smmu_pmu->options & SMMU_PMCG_EVCNTR_RDONLY) { 230 + /* 231 + * On platforms that require this quirk, if the counter starts 232 + * at < half_counter value and wraps, the current logic of 233 + * handling the overflow may not work. It is expected that, 234 + * those platforms will have full 64 counter bits implemented 235 + * so that such a possibility is remote(eg: HiSilicon HIP08). 236 + */ 237 + new = smmu_pmu_counter_get_value(smmu_pmu, idx); 238 + } else { 239 + /* 240 + * We limit the max period to half the max counter value 241 + * of the counter size, so that even in the case of extreme 242 + * interrupt latency the counter will (hopefully) not wrap 243 + * past its initial value. 244 + */ 245 + new = smmu_pmu->counter_mask >> 1; 246 + smmu_pmu_counter_set_value(smmu_pmu, idx, new); 247 + } 248 + 249 + local64_set(&hwc->prev_count, new); 250 + } 251 + 252 + static void smmu_pmu_set_event_filter(struct perf_event *event, 253 + int idx, u32 span, u32 sid) 254 + { 255 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 256 + u32 evtyper; 257 + 258 + evtyper = get_event(event) | span << SMMU_PMCG_SID_SPAN_SHIFT; 259 + smmu_pmu_set_evtyper(smmu_pmu, idx, evtyper); 260 + smmu_pmu_set_smr(smmu_pmu, idx, sid); 261 + } 262 + 263 + static int smmu_pmu_apply_event_filter(struct smmu_pmu *smmu_pmu, 264 + struct perf_event *event, int idx) 265 + { 266 + u32 span, sid; 267 + unsigned int num_ctrs = smmu_pmu->num_counters; 268 + bool filter_en = !!get_filter_enable(event); 269 + 270 + span = filter_en ? get_filter_span(event) : 271 + SMMU_PMCG_DEFAULT_FILTER_SPAN; 272 + sid = filter_en ? get_filter_stream_id(event) : 273 + SMMU_PMCG_DEFAULT_FILTER_SID; 274 + 275 + /* Support individual filter settings */ 276 + if (!smmu_pmu->global_filter) { 277 + smmu_pmu_set_event_filter(event, idx, span, sid); 278 + return 0; 279 + } 280 + 281 + /* Requested settings same as current global settings*/ 282 + if (span == smmu_pmu->global_filter_span && 283 + sid == smmu_pmu->global_filter_sid) 284 + return 0; 285 + 286 + if (!bitmap_empty(smmu_pmu->used_counters, num_ctrs)) 287 + return -EAGAIN; 288 + 289 + smmu_pmu_set_event_filter(event, 0, span, sid); 290 + smmu_pmu->global_filter_span = span; 291 + smmu_pmu->global_filter_sid = sid; 292 + return 0; 293 + } 294 + 295 + static int smmu_pmu_get_event_idx(struct smmu_pmu *smmu_pmu, 296 + struct perf_event *event) 297 + { 298 + int idx, err; 299 + unsigned int num_ctrs = smmu_pmu->num_counters; 300 + 301 + idx = find_first_zero_bit(smmu_pmu->used_counters, num_ctrs); 302 + if (idx == num_ctrs) 303 + /* The counters are all in use. */ 304 + return -EAGAIN; 305 + 306 + err = smmu_pmu_apply_event_filter(smmu_pmu, event, idx); 307 + if (err) 308 + return err; 309 + 310 + set_bit(idx, smmu_pmu->used_counters); 311 + 312 + return idx; 313 + } 314 + 315 + /* 316 + * Implementation of abstract pmu functionality required by 317 + * the core perf events code. 318 + */ 319 + 320 + static int smmu_pmu_event_init(struct perf_event *event) 321 + { 322 + struct hw_perf_event *hwc = &event->hw; 323 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 324 + struct device *dev = smmu_pmu->dev; 325 + struct perf_event *sibling; 326 + u16 event_id; 327 + 328 + if (event->attr.type != event->pmu->type) 329 + return -ENOENT; 330 + 331 + if (hwc->sample_period) { 332 + dev_dbg(dev, "Sampling not supported\n"); 333 + return -EOPNOTSUPP; 334 + } 335 + 336 + if (event->cpu < 0) { 337 + dev_dbg(dev, "Per-task mode not supported\n"); 338 + return -EOPNOTSUPP; 339 + } 340 + 341 + /* Verify specified event is supported on this PMU */ 342 + event_id = get_event(event); 343 + if (event_id < SMMU_PMCG_ARCH_MAX_EVENTS && 344 + (!test_bit(event_id, smmu_pmu->supported_events))) { 345 + dev_dbg(dev, "Invalid event %d for this PMU\n", event_id); 346 + return -EINVAL; 347 + } 348 + 349 + /* Don't allow groups with mixed PMUs, except for s/w events */ 350 + if (event->group_leader->pmu != event->pmu && 351 + !is_software_event(event->group_leader)) { 352 + dev_dbg(dev, "Can't create mixed PMU group\n"); 353 + return -EINVAL; 354 + } 355 + 356 + for_each_sibling_event(sibling, event->group_leader) { 357 + if (sibling->pmu != event->pmu && 358 + !is_software_event(sibling)) { 359 + dev_dbg(dev, "Can't create mixed PMU group\n"); 360 + return -EINVAL; 361 + } 362 + } 363 + 364 + hwc->idx = -1; 365 + 366 + /* 367 + * Ensure all events are on the same cpu so all events are in the 368 + * same cpu context, to avoid races on pmu_enable etc. 369 + */ 370 + event->cpu = smmu_pmu->on_cpu; 371 + 372 + return 0; 373 + } 374 + 375 + static void smmu_pmu_event_start(struct perf_event *event, int flags) 376 + { 377 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 378 + struct hw_perf_event *hwc = &event->hw; 379 + int idx = hwc->idx; 380 + 381 + hwc->state = 0; 382 + 383 + smmu_pmu_set_period(smmu_pmu, hwc); 384 + 385 + smmu_pmu_counter_enable(smmu_pmu, idx); 386 + } 387 + 388 + static void smmu_pmu_event_stop(struct perf_event *event, int flags) 389 + { 390 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 391 + struct hw_perf_event *hwc = &event->hw; 392 + int idx = hwc->idx; 393 + 394 + if (hwc->state & PERF_HES_STOPPED) 395 + return; 396 + 397 + smmu_pmu_counter_disable(smmu_pmu, idx); 398 + /* As the counter gets updated on _start, ignore PERF_EF_UPDATE */ 399 + smmu_pmu_event_update(event); 400 + hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE; 401 + } 402 + 403 + static int smmu_pmu_event_add(struct perf_event *event, int flags) 404 + { 405 + struct hw_perf_event *hwc = &event->hw; 406 + int idx; 407 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 408 + 409 + idx = smmu_pmu_get_event_idx(smmu_pmu, event); 410 + if (idx < 0) 411 + return idx; 412 + 413 + hwc->idx = idx; 414 + hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; 415 + smmu_pmu->events[idx] = event; 416 + local64_set(&hwc->prev_count, 0); 417 + 418 + smmu_pmu_interrupt_enable(smmu_pmu, idx); 419 + 420 + if (flags & PERF_EF_START) 421 + smmu_pmu_event_start(event, flags); 422 + 423 + /* Propagate changes to the userspace mapping. */ 424 + perf_event_update_userpage(event); 425 + 426 + return 0; 427 + } 428 + 429 + static void smmu_pmu_event_del(struct perf_event *event, int flags) 430 + { 431 + struct hw_perf_event *hwc = &event->hw; 432 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu); 433 + int idx = hwc->idx; 434 + 435 + smmu_pmu_event_stop(event, flags | PERF_EF_UPDATE); 436 + smmu_pmu_interrupt_disable(smmu_pmu, idx); 437 + smmu_pmu->events[idx] = NULL; 438 + clear_bit(idx, smmu_pmu->used_counters); 439 + 440 + perf_event_update_userpage(event); 441 + } 442 + 443 + static void smmu_pmu_event_read(struct perf_event *event) 444 + { 445 + smmu_pmu_event_update(event); 446 + } 447 + 448 + /* cpumask */ 449 + 450 + static ssize_t smmu_pmu_cpumask_show(struct device *dev, 451 + struct device_attribute *attr, 452 + char *buf) 453 + { 454 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(dev_get_drvdata(dev)); 455 + 456 + return cpumap_print_to_pagebuf(true, buf, cpumask_of(smmu_pmu->on_cpu)); 457 + } 458 + 459 + static struct device_attribute smmu_pmu_cpumask_attr = 460 + __ATTR(cpumask, 0444, smmu_pmu_cpumask_show, NULL); 461 + 462 + static struct attribute *smmu_pmu_cpumask_attrs[] = { 463 + &smmu_pmu_cpumask_attr.attr, 464 + NULL 465 + }; 466 + 467 + static struct attribute_group smmu_pmu_cpumask_group = { 468 + .attrs = smmu_pmu_cpumask_attrs, 469 + }; 470 + 471 + /* Events */ 472 + 473 + static ssize_t smmu_pmu_event_show(struct device *dev, 474 + struct device_attribute *attr, char *page) 475 + { 476 + struct perf_pmu_events_attr *pmu_attr; 477 + 478 + pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr); 479 + 480 + return sprintf(page, "event=0x%02llx\n", pmu_attr->id); 481 + } 482 + 483 + #define SMMU_EVENT_ATTR(name, config) \ 484 + PMU_EVENT_ATTR(name, smmu_event_attr_##name, \ 485 + config, smmu_pmu_event_show) 486 + SMMU_EVENT_ATTR(cycles, 0); 487 + SMMU_EVENT_ATTR(transaction, 1); 488 + SMMU_EVENT_ATTR(tlb_miss, 2); 489 + SMMU_EVENT_ATTR(config_cache_miss, 3); 490 + SMMU_EVENT_ATTR(trans_table_walk_access, 4); 491 + SMMU_EVENT_ATTR(config_struct_access, 5); 492 + SMMU_EVENT_ATTR(pcie_ats_trans_rq, 6); 493 + SMMU_EVENT_ATTR(pcie_ats_trans_passed, 7); 494 + 495 + static struct attribute *smmu_pmu_events[] = { 496 + &smmu_event_attr_cycles.attr.attr, 497 + &smmu_event_attr_transaction.attr.attr, 498 + &smmu_event_attr_tlb_miss.attr.attr, 499 + &smmu_event_attr_config_cache_miss.attr.attr, 500 + &smmu_event_attr_trans_table_walk_access.attr.attr, 501 + &smmu_event_attr_config_struct_access.attr.attr, 502 + &smmu_event_attr_pcie_ats_trans_rq.attr.attr, 503 + &smmu_event_attr_pcie_ats_trans_passed.attr.attr, 504 + NULL 505 + }; 506 + 507 + static umode_t smmu_pmu_event_is_visible(struct kobject *kobj, 508 + struct attribute *attr, int unused) 509 + { 510 + struct device *dev = kobj_to_dev(kobj); 511 + struct smmu_pmu *smmu_pmu = to_smmu_pmu(dev_get_drvdata(dev)); 512 + struct perf_pmu_events_attr *pmu_attr; 513 + 514 + pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr); 515 + 516 + if (test_bit(pmu_attr->id, smmu_pmu->supported_events)) 517 + return attr->mode; 518 + 519 + return 0; 520 + } 521 + 522 + static struct attribute_group smmu_pmu_events_group = { 523 + .name = "events", 524 + .attrs = smmu_pmu_events, 525 + .is_visible = smmu_pmu_event_is_visible, 526 + }; 527 + 528 + /* Formats */ 529 + PMU_FORMAT_ATTR(event, "config:0-15"); 530 + PMU_FORMAT_ATTR(filter_stream_id, "config1:0-31"); 531 + PMU_FORMAT_ATTR(filter_span, "config1:32"); 532 + PMU_FORMAT_ATTR(filter_enable, "config1:33"); 533 + 534 + static struct attribute *smmu_pmu_formats[] = { 535 + &format_attr_event.attr, 536 + &format_attr_filter_stream_id.attr, 537 + &format_attr_filter_span.attr, 538 + &format_attr_filter_enable.attr, 539 + NULL 540 + }; 541 + 542 + static struct attribute_group smmu_pmu_format_group = { 543 + .name = "format", 544 + .attrs = smmu_pmu_formats, 545 + }; 546 + 547 + static const struct attribute_group *smmu_pmu_attr_grps[] = { 548 + &smmu_pmu_cpumask_group, 549 + &smmu_pmu_events_group, 550 + &smmu_pmu_format_group, 551 + NULL 552 + }; 553 + 554 + /* 555 + * Generic device handlers 556 + */ 557 + 558 + static int smmu_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) 559 + { 560 + struct smmu_pmu *smmu_pmu; 561 + unsigned int target; 562 + 563 + smmu_pmu = hlist_entry_safe(node, struct smmu_pmu, node); 564 + if (cpu != smmu_pmu->on_cpu) 565 + return 0; 566 + 567 + target = cpumask_any_but(cpu_online_mask, cpu); 568 + if (target >= nr_cpu_ids) 569 + return 0; 570 + 571 + perf_pmu_migrate_context(&smmu_pmu->pmu, cpu, target); 572 + smmu_pmu->on_cpu = target; 573 + WARN_ON(irq_set_affinity_hint(smmu_pmu->irq, cpumask_of(target))); 574 + 575 + return 0; 576 + } 577 + 578 + static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data) 579 + { 580 + struct smmu_pmu *smmu_pmu = data; 581 + u64 ovsr; 582 + unsigned int idx; 583 + 584 + ovsr = readq(smmu_pmu->reloc_base + SMMU_PMCG_OVSSET0); 585 + if (!ovsr) 586 + return IRQ_NONE; 587 + 588 + writeq(ovsr, smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0); 589 + 590 + for_each_set_bit(idx, (unsigned long *)&ovsr, smmu_pmu->num_counters) { 591 + struct perf_event *event = smmu_pmu->events[idx]; 592 + struct hw_perf_event *hwc; 593 + 594 + if (WARN_ON_ONCE(!event)) 595 + continue; 596 + 597 + smmu_pmu_event_update(event); 598 + hwc = &event->hw; 599 + 600 + smmu_pmu_set_period(smmu_pmu, hwc); 601 + } 602 + 603 + return IRQ_HANDLED; 604 + } 605 + 606 + static void smmu_pmu_free_msis(void *data) 607 + { 608 + struct device *dev = data; 609 + 610 + platform_msi_domain_free_irqs(dev); 611 + } 612 + 613 + static void smmu_pmu_write_msi_msg(struct msi_desc *desc, struct msi_msg *msg) 614 + { 615 + phys_addr_t doorbell; 616 + struct device *dev = msi_desc_to_dev(desc); 617 + struct smmu_pmu *pmu = dev_get_drvdata(dev); 618 + 619 + doorbell = (((u64)msg->address_hi) << 32) | msg->address_lo; 620 + doorbell &= MSI_CFG0_ADDR_MASK; 621 + 622 + writeq_relaxed(doorbell, pmu->reg_base + SMMU_PMCG_IRQ_CFG0); 623 + writel_relaxed(msg->data, pmu->reg_base + SMMU_PMCG_IRQ_CFG1); 624 + writel_relaxed(MSI_CFG2_MEMATTR_DEVICE_nGnRE, 625 + pmu->reg_base + SMMU_PMCG_IRQ_CFG2); 626 + } 627 + 628 + static void smmu_pmu_setup_msi(struct smmu_pmu *pmu) 629 + { 630 + struct msi_desc *desc; 631 + struct device *dev = pmu->dev; 632 + int ret; 633 + 634 + /* Clear MSI address reg */ 635 + writeq_relaxed(0, pmu->reg_base + SMMU_PMCG_IRQ_CFG0); 636 + 637 + /* MSI supported or not */ 638 + if (!(readl(pmu->reg_base + SMMU_PMCG_CFGR) & SMMU_PMCG_CFGR_MSI)) 639 + return; 640 + 641 + ret = platform_msi_domain_alloc_irqs(dev, 1, smmu_pmu_write_msi_msg); 642 + if (ret) { 643 + dev_warn(dev, "failed to allocate MSIs\n"); 644 + return; 645 + } 646 + 647 + desc = first_msi_entry(dev); 648 + if (desc) 649 + pmu->irq = desc->irq; 650 + 651 + /* Add callback to free MSIs on teardown */ 652 + devm_add_action(dev, smmu_pmu_free_msis, dev); 653 + } 654 + 655 + static int smmu_pmu_setup_irq(struct smmu_pmu *pmu) 656 + { 657 + unsigned long flags = IRQF_NOBALANCING | IRQF_SHARED | IRQF_NO_THREAD; 658 + int irq, ret = -ENXIO; 659 + 660 + smmu_pmu_setup_msi(pmu); 661 + 662 + irq = pmu->irq; 663 + if (irq) 664 + ret = devm_request_irq(pmu->dev, irq, smmu_pmu_handle_irq, 665 + flags, "smmuv3-pmu", pmu); 666 + return ret; 667 + } 668 + 669 + static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu) 670 + { 671 + u64 counter_present_mask = GENMASK_ULL(smmu_pmu->num_counters - 1, 0); 672 + 673 + smmu_pmu_disable(&smmu_pmu->pmu); 674 + 675 + /* Disable counter and interrupt */ 676 + writeq_relaxed(counter_present_mask, 677 + smmu_pmu->reg_base + SMMU_PMCG_CNTENCLR0); 678 + writeq_relaxed(counter_present_mask, 679 + smmu_pmu->reg_base + SMMU_PMCG_INTENCLR0); 680 + writeq_relaxed(counter_present_mask, 681 + smmu_pmu->reloc_base + SMMU_PMCG_OVSCLR0); 682 + } 683 + 684 + static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu) 685 + { 686 + u32 model; 687 + 688 + model = *(u32 *)dev_get_platdata(smmu_pmu->dev); 689 + 690 + switch (model) { 691 + case IORT_SMMU_V3_PMCG_HISI_HIP08: 692 + /* HiSilicon Erratum 162001800 */ 693 + smmu_pmu->options |= SMMU_PMCG_EVCNTR_RDONLY; 694 + break; 695 + } 696 + 697 + dev_notice(smmu_pmu->dev, "option mask 0x%x\n", smmu_pmu->options); 698 + } 699 + 700 + static int smmu_pmu_probe(struct platform_device *pdev) 701 + { 702 + struct smmu_pmu *smmu_pmu; 703 + struct resource *res_0, *res_1; 704 + u32 cfgr, reg_size; 705 + u64 ceid_64[2]; 706 + int irq, err; 707 + char *name; 708 + struct device *dev = &pdev->dev; 709 + 710 + smmu_pmu = devm_kzalloc(dev, sizeof(*smmu_pmu), GFP_KERNEL); 711 + if (!smmu_pmu) 712 + return -ENOMEM; 713 + 714 + smmu_pmu->dev = dev; 715 + platform_set_drvdata(pdev, smmu_pmu); 716 + 717 + smmu_pmu->pmu = (struct pmu) { 718 + .task_ctx_nr = perf_invalid_context, 719 + .pmu_enable = smmu_pmu_enable, 720 + .pmu_disable = smmu_pmu_disable, 721 + .event_init = smmu_pmu_event_init, 722 + .add = smmu_pmu_event_add, 723 + .del = smmu_pmu_event_del, 724 + .start = smmu_pmu_event_start, 725 + .stop = smmu_pmu_event_stop, 726 + .read = smmu_pmu_event_read, 727 + .attr_groups = smmu_pmu_attr_grps, 728 + .capabilities = PERF_PMU_CAP_NO_EXCLUDE, 729 + }; 730 + 731 + res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 732 + smmu_pmu->reg_base = devm_ioremap_resource(dev, res_0); 733 + if (IS_ERR(smmu_pmu->reg_base)) 734 + return PTR_ERR(smmu_pmu->reg_base); 735 + 736 + cfgr = readl_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CFGR); 737 + 738 + /* Determine if page 1 is present */ 739 + if (cfgr & SMMU_PMCG_CFGR_RELOC_CTRS) { 740 + res_1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 741 + smmu_pmu->reloc_base = devm_ioremap_resource(dev, res_1); 742 + if (IS_ERR(smmu_pmu->reloc_base)) 743 + return PTR_ERR(smmu_pmu->reloc_base); 744 + } else { 745 + smmu_pmu->reloc_base = smmu_pmu->reg_base; 746 + } 747 + 748 + irq = platform_get_irq(pdev, 0); 749 + if (irq > 0) 750 + smmu_pmu->irq = irq; 751 + 752 + ceid_64[0] = readq_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CEID0); 753 + ceid_64[1] = readq_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CEID1); 754 + bitmap_from_arr32(smmu_pmu->supported_events, (u32 *)ceid_64, 755 + SMMU_PMCG_ARCH_MAX_EVENTS); 756 + 757 + smmu_pmu->num_counters = FIELD_GET(SMMU_PMCG_CFGR_NCTR, cfgr) + 1; 758 + 759 + smmu_pmu->global_filter = !!(cfgr & SMMU_PMCG_CFGR_SID_FILTER_TYPE); 760 + 761 + reg_size = FIELD_GET(SMMU_PMCG_CFGR_SIZE, cfgr); 762 + smmu_pmu->counter_mask = GENMASK_ULL(reg_size, 0); 763 + 764 + smmu_pmu_reset(smmu_pmu); 765 + 766 + err = smmu_pmu_setup_irq(smmu_pmu); 767 + if (err) { 768 + dev_err(dev, "Setup irq failed, PMU @%pa\n", &res_0->start); 769 + return err; 770 + } 771 + 772 + name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "smmuv3_pmcg_%llx", 773 + (res_0->start) >> SMMU_PMCG_PA_SHIFT); 774 + if (!name) { 775 + dev_err(dev, "Create name failed, PMU @%pa\n", &res_0->start); 776 + return -EINVAL; 777 + } 778 + 779 + smmu_pmu_get_acpi_options(smmu_pmu); 780 + 781 + /* Pick one CPU to be the preferred one to use */ 782 + smmu_pmu->on_cpu = raw_smp_processor_id(); 783 + WARN_ON(irq_set_affinity_hint(smmu_pmu->irq, 784 + cpumask_of(smmu_pmu->on_cpu))); 785 + 786 + err = cpuhp_state_add_instance_nocalls(cpuhp_state_num, 787 + &smmu_pmu->node); 788 + if (err) { 789 + dev_err(dev, "Error %d registering hotplug, PMU @%pa\n", 790 + err, &res_0->start); 791 + goto out_cpuhp_err; 792 + } 793 + 794 + err = perf_pmu_register(&smmu_pmu->pmu, name, -1); 795 + if (err) { 796 + dev_err(dev, "Error %d registering PMU @%pa\n", 797 + err, &res_0->start); 798 + goto out_unregister; 799 + } 800 + 801 + dev_info(dev, "Registered PMU @ %pa using %d counters with %s filter settings\n", 802 + &res_0->start, smmu_pmu->num_counters, 803 + smmu_pmu->global_filter ? "Global(Counter0)" : 804 + "Individual"); 805 + 806 + return 0; 807 + 808 + out_unregister: 809 + cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node); 810 + out_cpuhp_err: 811 + put_cpu(); 812 + return err; 813 + } 814 + 815 + static int smmu_pmu_remove(struct platform_device *pdev) 816 + { 817 + struct smmu_pmu *smmu_pmu = platform_get_drvdata(pdev); 818 + 819 + perf_pmu_unregister(&smmu_pmu->pmu); 820 + cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node); 821 + 822 + return 0; 823 + } 824 + 825 + static void smmu_pmu_shutdown(struct platform_device *pdev) 826 + { 827 + struct smmu_pmu *smmu_pmu = platform_get_drvdata(pdev); 828 + 829 + smmu_pmu_disable(&smmu_pmu->pmu); 830 + } 831 + 832 + static struct platform_driver smmu_pmu_driver = { 833 + .driver = { 834 + .name = "arm-smmu-v3-pmcg", 835 + }, 836 + .probe = smmu_pmu_probe, 837 + .remove = smmu_pmu_remove, 838 + .shutdown = smmu_pmu_shutdown, 839 + }; 840 + 841 + static int __init arm_smmu_pmu_init(void) 842 + { 843 + cpuhp_state_num = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, 844 + "perf/arm/pmcg:online", 845 + NULL, 846 + smmu_pmu_offline_cpu); 847 + if (cpuhp_state_num < 0) 848 + return cpuhp_state_num; 849 + 850 + return platform_driver_register(&smmu_pmu_driver); 851 + } 852 + module_init(arm_smmu_pmu_init); 853 + 854 + static void __exit arm_smmu_pmu_exit(void) 855 + { 856 + platform_driver_unregister(&smmu_pmu_driver); 857 + cpuhp_remove_multi_state(cpuhp_state_num); 858 + } 859 + 860 + module_exit(arm_smmu_pmu_exit); 861 + 862 + MODULE_DESCRIPTION("PMU driver for ARM SMMUv3 Performance Monitors Extension"); 863 + MODULE_AUTHOR("Neil Leeder <nleeder@codeaurora.org>"); 864 + MODULE_AUTHOR("Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>"); 865 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/watchdog/sbsa_gwdt.c
··· 161 161 timeleft += readl(gwdt->control_base + SBSA_GWDT_WOR); 162 162 163 163 timeleft += lo_hi_readq(gwdt->control_base + SBSA_GWDT_WCV) - 164 - arch_counter_get_cntvct(); 164 + arch_timer_read_counter(); 165 165 166 166 do_div(timeleft, gwdt->clk); 167 167
+6 -2
include/asm-generic/futex.h
··· 23 23 * 24 24 * Return: 25 25 * 0 - On success 26 - * <0 - On error 26 + * -EFAULT - User access resulted in a page fault 27 + * -EAGAIN - Atomic operation was unable to complete due to contention 28 + * -ENOSYS - Operation not supported 27 29 */ 28 30 static inline int 29 31 arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr) ··· 87 85 * 88 86 * Return: 89 87 * 0 - On success 90 - * <0 - On error 88 + * -EFAULT - User access resulted in a page fault 89 + * -EAGAIN - Atomic operation was unable to complete due to contention 90 + * -ENOSYS - Function not implemented (only if !HAVE_FUTEX_CMPXCHG) 91 91 */ 92 92 static inline int 93 93 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
+8
include/linux/acpi_iort.h
··· 26 26 #define IORT_IRQ_MASK(irq) (irq & 0xffffffffULL) 27 27 #define IORT_IRQ_TRIGGER_MASK(irq) ((irq >> 32) & 0xffffffffULL) 28 28 29 + /* 30 + * PMCG model identifiers for use in smmu pmu driver. Please note 31 + * that this is purely for the use of software and has nothing to 32 + * do with hardware or with IORT specification. 33 + */ 34 + #define IORT_SMMU_V3_PMCG_GENERIC 0x00000000 /* Generic SMMUv3 PMCG */ 35 + #define IORT_SMMU_V3_PMCG_HISI_HIP08 0x00000001 /* HiSilicon HIP08 PMCG */ 36 + 29 37 int iort_register_domain_token(int trans_id, phys_addr_t base, 30 38 struct fwnode_handle *fw_node); 31 39 void iort_deregister_domain_token(int trans_id);
+117 -71
kernel/futex.c
··· 1311 1311 1312 1312 static int lock_pi_update_atomic(u32 __user *uaddr, u32 uval, u32 newval) 1313 1313 { 1314 + int err; 1314 1315 u32 uninitialized_var(curval); 1315 1316 1316 1317 if (unlikely(should_fail_futex(true))) 1317 1318 return -EFAULT; 1318 1319 1319 - if (unlikely(cmpxchg_futex_value_locked(&curval, uaddr, uval, newval))) 1320 - return -EFAULT; 1320 + err = cmpxchg_futex_value_locked(&curval, uaddr, uval, newval); 1321 + if (unlikely(err)) 1322 + return err; 1321 1323 1322 1324 /* If user space value changed, let the caller retry */ 1323 1325 return curval != uval ? -EAGAIN : 0; ··· 1504 1502 if (unlikely(should_fail_futex(true))) 1505 1503 ret = -EFAULT; 1506 1504 1507 - if (cmpxchg_futex_value_locked(&curval, uaddr, uval, newval)) { 1508 - ret = -EFAULT; 1509 - 1510 - } else if (curval != uval) { 1505 + ret = cmpxchg_futex_value_locked(&curval, uaddr, uval, newval); 1506 + if (!ret && (curval != uval)) { 1511 1507 /* 1512 1508 * If a unconditional UNLOCK_PI operation (user space did not 1513 1509 * try the TID->0 transition) raced with a waiter setting the ··· 1700 1700 double_lock_hb(hb1, hb2); 1701 1701 op_ret = futex_atomic_op_inuser(op, uaddr2); 1702 1702 if (unlikely(op_ret < 0)) { 1703 - 1704 1703 double_unlock_hb(hb1, hb2); 1705 1704 1706 - #ifndef CONFIG_MMU 1707 - /* 1708 - * we don't get EFAULT from MMU faults if we don't have an MMU, 1709 - * but we might get them from range checking 1710 - */ 1711 - ret = op_ret; 1712 - goto out_put_keys; 1713 - #endif 1714 - 1715 - if (unlikely(op_ret != -EFAULT)) { 1705 + if (!IS_ENABLED(CONFIG_MMU) || 1706 + unlikely(op_ret != -EFAULT && op_ret != -EAGAIN)) { 1707 + /* 1708 + * we don't get EFAULT from MMU faults if we don't have 1709 + * an MMU, but we might get them from range checking 1710 + */ 1716 1711 ret = op_ret; 1717 1712 goto out_put_keys; 1718 1713 } 1719 1714 1720 - ret = fault_in_user_writeable(uaddr2); 1721 - if (ret) 1722 - goto out_put_keys; 1715 + if (op_ret == -EFAULT) { 1716 + ret = fault_in_user_writeable(uaddr2); 1717 + if (ret) 1718 + goto out_put_keys; 1719 + } 1723 1720 1724 - if (!(flags & FLAGS_SHARED)) 1721 + if (!(flags & FLAGS_SHARED)) { 1722 + cond_resched(); 1725 1723 goto retry_private; 1724 + } 1726 1725 1727 1726 put_futex_key(&key2); 1728 1727 put_futex_key(&key1); 1728 + cond_resched(); 1729 1729 goto retry; 1730 1730 } 1731 1731 ··· 2350 2350 u32 uval, uninitialized_var(curval), newval; 2351 2351 struct task_struct *oldowner, *newowner; 2352 2352 u32 newtid; 2353 - int ret; 2353 + int ret, err = 0; 2354 2354 2355 2355 lockdep_assert_held(q->lock_ptr); 2356 2356 ··· 2421 2421 if (!pi_state->owner) 2422 2422 newtid |= FUTEX_OWNER_DIED; 2423 2423 2424 - if (get_futex_value_locked(&uval, uaddr)) 2425 - goto handle_fault; 2424 + err = get_futex_value_locked(&uval, uaddr); 2425 + if (err) 2426 + goto handle_err; 2426 2427 2427 2428 for (;;) { 2428 2429 newval = (uval & FUTEX_OWNER_DIED) | newtid; 2429 2430 2430 - if (cmpxchg_futex_value_locked(&curval, uaddr, uval, newval)) 2431 - goto handle_fault; 2431 + err = cmpxchg_futex_value_locked(&curval, uaddr, uval, newval); 2432 + if (err) 2433 + goto handle_err; 2434 + 2432 2435 if (curval == uval) 2433 2436 break; 2434 2437 uval = curval; ··· 2459 2456 return 0; 2460 2457 2461 2458 /* 2462 - * To handle the page fault we need to drop the locks here. That gives 2463 - * the other task (either the highest priority waiter itself or the 2464 - * task which stole the rtmutex) the chance to try the fixup of the 2465 - * pi_state. So once we are back from handling the fault we need to 2466 - * check the pi_state after reacquiring the locks and before trying to 2467 - * do another fixup. When the fixup has been done already we simply 2468 - * return. 2459 + * In order to reschedule or handle a page fault, we need to drop the 2460 + * locks here. In the case of a fault, this gives the other task 2461 + * (either the highest priority waiter itself or the task which stole 2462 + * the rtmutex) the chance to try the fixup of the pi_state. So once we 2463 + * are back from handling the fault we need to check the pi_state after 2464 + * reacquiring the locks and before trying to do another fixup. When 2465 + * the fixup has been done already we simply return. 2469 2466 * 2470 2467 * Note: we hold both hb->lock and pi_mutex->wait_lock. We can safely 2471 2468 * drop hb->lock since the caller owns the hb -> futex_q relation. 2472 2469 * Dropping the pi_mutex->wait_lock requires the state revalidate. 2473 2470 */ 2474 - handle_fault: 2471 + handle_err: 2475 2472 raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock); 2476 2473 spin_unlock(q->lock_ptr); 2477 2474 2478 - ret = fault_in_user_writeable(uaddr); 2475 + switch (err) { 2476 + case -EFAULT: 2477 + ret = fault_in_user_writeable(uaddr); 2478 + break; 2479 + 2480 + case -EAGAIN: 2481 + cond_resched(); 2482 + ret = 0; 2483 + break; 2484 + 2485 + default: 2486 + WARN_ON_ONCE(1); 2487 + ret = err; 2488 + break; 2489 + } 2479 2490 2480 2491 spin_lock(q->lock_ptr); 2481 2492 raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock); ··· 3058 3041 * A unconditional UNLOCK_PI op raced against a waiter 3059 3042 * setting the FUTEX_WAITERS bit. Try again. 3060 3043 */ 3061 - if (ret == -EAGAIN) { 3062 - put_futex_key(&key); 3063 - goto retry; 3064 - } 3044 + if (ret == -EAGAIN) 3045 + goto pi_retry; 3065 3046 /* 3066 3047 * wake_futex_pi has detected invalid state. Tell user 3067 3048 * space. ··· 3074 3059 * preserve the WAITERS bit not the OWNER_DIED one. We are the 3075 3060 * owner. 3076 3061 */ 3077 - if (cmpxchg_futex_value_locked(&curval, uaddr, uval, 0)) { 3062 + if ((ret = cmpxchg_futex_value_locked(&curval, uaddr, uval, 0))) { 3078 3063 spin_unlock(&hb->lock); 3079 - goto pi_faulted; 3064 + switch (ret) { 3065 + case -EFAULT: 3066 + goto pi_faulted; 3067 + 3068 + case -EAGAIN: 3069 + goto pi_retry; 3070 + 3071 + default: 3072 + WARN_ON_ONCE(1); 3073 + goto out_putkey; 3074 + } 3080 3075 } 3081 3076 3082 3077 /* ··· 3099 3074 out_putkey: 3100 3075 put_futex_key(&key); 3101 3076 return ret; 3077 + 3078 + pi_retry: 3079 + put_futex_key(&key); 3080 + cond_resched(); 3081 + goto retry; 3102 3082 3103 3083 pi_faulted: 3104 3084 put_futex_key(&key); ··· 3465 3435 static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi) 3466 3436 { 3467 3437 u32 uval, uninitialized_var(nval), mval; 3438 + int err; 3468 3439 3469 3440 /* Futex address must be 32bit aligned */ 3470 3441 if ((((unsigned long)uaddr) % sizeof(*uaddr)) != 0) ··· 3475 3444 if (get_user(uval, uaddr)) 3476 3445 return -1; 3477 3446 3478 - if ((uval & FUTEX_TID_MASK) == task_pid_vnr(curr)) { 3479 - /* 3480 - * Ok, this dying thread is truly holding a futex 3481 - * of interest. Set the OWNER_DIED bit atomically 3482 - * via cmpxchg, and if the value had FUTEX_WAITERS 3483 - * set, wake up a waiter (if any). (We have to do a 3484 - * futex_wake() even if OWNER_DIED is already set - 3485 - * to handle the rare but possible case of recursive 3486 - * thread-death.) The rest of the cleanup is done in 3487 - * userspace. 3488 - */ 3489 - mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED; 3490 - /* 3491 - * We are not holding a lock here, but we want to have 3492 - * the pagefault_disable/enable() protection because 3493 - * we want to handle the fault gracefully. If the 3494 - * access fails we try to fault in the futex with R/W 3495 - * verification via get_user_pages. get_user() above 3496 - * does not guarantee R/W access. If that fails we 3497 - * give up and leave the futex locked. 3498 - */ 3499 - if (cmpxchg_futex_value_locked(&nval, uaddr, uval, mval)) { 3447 + if ((uval & FUTEX_TID_MASK) != task_pid_vnr(curr)) 3448 + return 0; 3449 + 3450 + /* 3451 + * Ok, this dying thread is truly holding a futex 3452 + * of interest. Set the OWNER_DIED bit atomically 3453 + * via cmpxchg, and if the value had FUTEX_WAITERS 3454 + * set, wake up a waiter (if any). (We have to do a 3455 + * futex_wake() even if OWNER_DIED is already set - 3456 + * to handle the rare but possible case of recursive 3457 + * thread-death.) The rest of the cleanup is done in 3458 + * userspace. 3459 + */ 3460 + mval = (uval & FUTEX_WAITERS) | FUTEX_OWNER_DIED; 3461 + 3462 + /* 3463 + * We are not holding a lock here, but we want to have 3464 + * the pagefault_disable/enable() protection because 3465 + * we want to handle the fault gracefully. If the 3466 + * access fails we try to fault in the futex with R/W 3467 + * verification via get_user_pages. get_user() above 3468 + * does not guarantee R/W access. If that fails we 3469 + * give up and leave the futex locked. 3470 + */ 3471 + if ((err = cmpxchg_futex_value_locked(&nval, uaddr, uval, mval))) { 3472 + switch (err) { 3473 + case -EFAULT: 3500 3474 if (fault_in_user_writeable(uaddr)) 3501 3475 return -1; 3502 3476 goto retry; 3503 - } 3504 - if (nval != uval) 3477 + 3478 + case -EAGAIN: 3479 + cond_resched(); 3505 3480 goto retry; 3506 3481 3507 - /* 3508 - * Wake robust non-PI futexes here. The wakeup of 3509 - * PI futexes happens in exit_pi_state(): 3510 - */ 3511 - if (!pi && (uval & FUTEX_WAITERS)) 3512 - futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY); 3482 + default: 3483 + WARN_ON_ONCE(1); 3484 + return err; 3485 + } 3513 3486 } 3487 + 3488 + if (nval != uval) 3489 + goto retry; 3490 + 3491 + /* 3492 + * Wake robust non-PI futexes here. The wakeup of 3493 + * PI futexes happens in exit_pi_state(): 3494 + */ 3495 + if (!pi && (uval & FUTEX_WAITERS)) 3496 + futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY); 3497 + 3514 3498 return 0; 3515 3499 } 3516 3500
+4 -4
mm/kasan/Makefile
··· 6 6 UBSAN_SANITIZE_tags.o := n 7 7 KCOV_INSTRUMENT := n 8 8 9 - CFLAGS_REMOVE_common.o = -pg 10 - CFLAGS_REMOVE_generic.o = -pg 11 - CFLAGS_REMOVE_generic_report.o = -pg 12 - CFLAGS_REMOVE_tags.o = -pg 9 + CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) 10 + CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE) 11 + CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE) 12 + CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) 13 13 14 14 # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 15 15 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
+1 -1
virt/kvm/arm/mmu.c
··· 189 189 VM_BUG_ON(pmd_thp_or_huge(*pmd)); 190 190 pmd_clear(pmd); 191 191 kvm_tlb_flush_vmid_ipa(kvm, addr); 192 - pte_free_kernel(NULL, pte_table); 192 + free_page((unsigned long)pte_table); 193 193 put_page(virt_to_page(pmd)); 194 194 } 195 195