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 Catalin Marinas:

- kdump support, including two necessary memblock additions:
memblock_clear_nomap() and memblock_cap_memory_range()

- ARMv8.3 HWCAP bits for JavaScript conversion instructions, complex
numbers and weaker release consistency

- arm64 ACPI platform MSI support

- arm perf updates: ACPI PMU support, L3 cache PMU in some Qualcomm
SoCs, Cortex-A53 L2 cache events and DTLB refills, MAINTAINERS update
for DT perf bindings

- architected timer errata framework (the arch/arm64 changes only)

- support for DMA_ATTR_FORCE_CONTIGUOUS in the arm64 iommu DMA API

- arm64 KVM refactoring to use common system register definitions

- remove support for ASID-tagged VIVT I-cache (no ARMv8 implementation
using it and deprecated in the architecture) together with some
I-cache handling clean-up

- PE/COFF EFI header clean-up/hardening

- define BUG() instruction without CONFIG_BUG

* tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (92 commits)
arm64: Fix the DMA mmap and get_sgtable API with DMA_ATTR_FORCE_CONTIGUOUS
arm64: Print DT machine model in setup_machine_fdt()
arm64: pmu: Wire-up Cortex A53 L2 cache events and DTLB refills
arm64: module: split core and init PLT sections
arm64: pmuv3: handle pmuv3+
arm64: Add CNTFRQ_EL0 trap handler
arm64: Silence spurious kbuild warning on menuconfig
arm64: pmuv3: use arm_pmu ACPI framework
arm64: pmuv3: handle !PMUv3 when probing
drivers/perf: arm_pmu: add ACPI framework
arm64: add function to get a cpu's MADT GICC table
drivers/perf: arm_pmu: split out platform device probe logic
drivers/perf: arm_pmu: move irq request/free into probe
drivers/perf: arm_pmu: split cpu-local irq request/free
drivers/perf: arm_pmu: rename irq request/free functions
drivers/perf: arm_pmu: handle no platform_device
drivers/perf: arm_pmu: simplify cpu_pmu_request_irqs()
drivers/perf: arm_pmu: factor out pmu registration
drivers/perf: arm_pmu: fold init into alloc
drivers/perf: arm_pmu: define armpmu_init_fn
...

+3761 -1263
+12
Documentation/arm64/cpu-feature-registers.txt
··· 169 169 as available on the CPU where it is fetched and is not a system 170 170 wide safe value. 171 171 172 + 4) ID_AA64ISAR1_EL1 - Instruction set attribute register 1 173 + 174 + x--------------------------------------------------x 175 + | Name | bits | visible | 176 + |--------------------------------------------------| 177 + | LRCPC | [23-20] | y | 178 + |--------------------------------------------------| 179 + | FCMA | [19-16] | y | 180 + |--------------------------------------------------| 181 + | JSCVT | [15-12] | y | 182 + x--------------------------------------------------x 183 + 172 184 Appendix I: Example 173 185 --------------------------- 174 186
+45
Documentation/devicetree/bindings/chosen.txt
··· 52 52 book3e) by some versions of kexec-tools to tell the new kernel that it 53 53 is being booted by kexec, as the booting environment may differ (e.g. 54 54 a different secondary CPU release mechanism) 55 + 56 + linux,usable-memory-range 57 + ------------------------- 58 + 59 + This property (arm64 only) holds a base address and size, describing a 60 + limited region in which memory may be considered available for use by 61 + the kernel. Memory outside of this range is not available for use. 62 + 63 + This property describes a limitation: memory within this range is only 64 + valid when also described through another mechanism that the kernel 65 + would otherwise use to determine available memory (e.g. memory nodes 66 + or the EFI memory map). Valid memory may be sparse within the range. 67 + e.g. 68 + 69 + / { 70 + chosen { 71 + linux,usable-memory-range = <0x9 0xf0000000 0x0 0x10000000>; 72 + }; 73 + }; 74 + 75 + The main usage is for crash dump kernel to identify its own usable 76 + memory and exclude, at its boot time, any other memory areas that are 77 + part of the panicked kernel's memory. 78 + 79 + While this property does not represent a real hardware, the address 80 + and the size are expressed in #address-cells and #size-cells, 81 + respectively, of the root node. 82 + 83 + linux,elfcorehdr 84 + ---------------- 85 + 86 + This property (currently used only on arm64) holds the memory range, 87 + the address and the size, of the elf core header which mainly describes 88 + the panicked kernel's memory layout as PT_LOAD segments of elf format. 89 + e.g. 90 + 91 + / { 92 + chosen { 93 + linux,elfcorehdr = <0x9 0xfffff000 0x0 0x800>; 94 + }; 95 + }; 96 + 97 + While this property does not represent a real hardware, the address 98 + and the size are expressed in #address-cells and #size-cells, 99 + respectively, of the root node.
+15 -1
Documentation/kdump/kdump.txt
··· 18 18 a remote system. 19 19 20 20 Kdump and kexec are currently supported on the x86, x86_64, ppc64, ia64, 21 - s390x and arm architectures. 21 + s390x, arm and arm64 architectures. 22 22 23 23 When the system kernel boots, it reserves a small section of memory for 24 24 the dump-capture kernel. This ensures that ongoing Direct Memory Access ··· 249 249 250 250 AUTO_ZRELADDR=y 251 251 252 + Dump-capture kernel config options (Arch Dependent, arm64) 253 + ---------------------------------------------------------- 254 + 255 + - Please note that kvm of the dump-capture kernel will not be enabled 256 + on non-VHE systems even if it is configured. This is because the CPU 257 + will not be reset to EL2 on panic. 258 + 252 259 Extended crashkernel syntax 253 260 =========================== 254 261 ··· 312 305 kernel will automatically locate the crash kernel image within the 313 306 first 512MB of RAM if X is not given. 314 307 308 + On arm64, use "crashkernel=Y[@X]". Note that the start address of 309 + the kernel, X if explicitly specified, must be aligned to 2MiB (0x200000). 315 310 316 311 Load the Dump-capture Kernel 317 312 ============================ ··· 336 327 - Use image or bzImage 337 328 For arm: 338 329 - Use zImage 330 + For arm64: 331 + - Use vmlinux or Image 339 332 340 333 If you are using a uncompressed vmlinux image then use following command 341 334 to load dump-capture kernel. ··· 379 368 "1 maxcpus=1 cgroup_disable=memory" 380 369 381 370 For arm: 371 + "1 maxcpus=1 reset_devices" 372 + 373 + For arm64: 382 374 "1 maxcpus=1 reset_devices" 383 375 384 376 Notes on loading the dump-capture kernel:
+25
Documentation/perf/qcom_l3_pmu.txt
··· 1 + Qualcomm Datacenter Technologies L3 Cache Performance Monitoring Unit (PMU) 2 + =========================================================================== 3 + 4 + This driver supports the L3 cache PMUs found in Qualcomm Datacenter Technologies 5 + Centriq SoCs. The L3 cache on these SOCs is composed of multiple slices, shared 6 + by all cores within a socket. Each slice is exposed as a separate uncore perf 7 + PMU with device name l3cache_<socket>_<instance>. User space is responsible 8 + for aggregating across slices. 9 + 10 + The driver provides a description of its available events and configuration 11 + options in sysfs, see /sys/devices/l3cache*. Given that these are uncore PMUs 12 + the driver also exposes a "cpumask" sysfs attribute which contains a mask 13 + consisting of one CPU per socket which will be used to handle all the PMU 14 + events on that socket. 15 + 16 + The hardware implements 32bit event counters and has a flat 8bit event space 17 + exposed via the "event" format attribute. In addition to the 32bit physical 18 + counters the driver supports virtual 64bit hardware counters by using hardware 19 + counter chaining. This feature is exposed via the "lc" (long counter) format 20 + flag. E.g.: 21 + 22 + perf stat -e l3cache_0_0/read-miss,lc/ 23 + 24 + Given that these are uncore PMUs the driver does not support sampling, therefore 25 + "perf record" will not work. Per-task perf sessions are not supported.
+1
MAINTAINERS
··· 983 983 F: drivers/perf/* 984 984 F: include/linux/perf/arm_pmu.h 985 985 F: Documentation/devicetree/bindings/arm/pmu.txt 986 + F: Documentation/devicetree/bindings/perf/ 986 987 987 988 ARM PORT 988 989 M: Russell King <linux@armlinux.org.uk>
+11
arch/arm64/Kconfig
··· 736 736 but it is independent of the system firmware. And like a reboot 737 737 you can start any kernel with it, not just Linux. 738 738 739 + config CRASH_DUMP 740 + bool "Build kdump crash kernel" 741 + help 742 + Generate crash dump after being started by kexec. This should 743 + be normally only set in special crash dump kernels which are 744 + loaded in the main kernel with kexec-tools into a specially 745 + reserved region and then later executed after a crash by 746 + kdump/kexec. 747 + 748 + For more details see Documentation/kdump/kdump.txt 749 + 739 750 config XEN_DOM0 740 751 def_bool y 741 752 depends on XEN
+4
arch/arm64/Kconfig.debug
··· 92 92 the kernel that are only useful when using a debug build of the 93 93 UEFI firmware 94 94 95 + config ARM64_RELOC_TEST 96 + depends on m 97 + tristate "Relocation testing module" 98 + 95 99 source "drivers/hwtracing/coresight/Kconfig" 96 100 97 101 endmenu
+3 -1
arch/arm64/Makefile
··· 37 37 endif 38 38 endif 39 39 40 + ifeq ($(CONFIG_ARM64), y) 40 41 brokengasinst := $(call as-instr,1:\n.inst 0\n.rept . - 1b\n\nnop\n.endr\n,,-DCONFIG_BROKEN_GAS_INST=1) 41 42 42 - ifneq ($(brokengasinst),) 43 + ifneq ($(brokengasinst),) 43 44 $(warning Detected assembler with broken .inst; disassembly will be unreliable) 45 + endif 44 46 endif 45 47 46 48 KBUILD_CFLAGS += -mgeneral-regs-only $(lseinstr) $(brokengasinst)
+1
arch/arm64/configs/defconfig
··· 82 82 CONFIG_SECCOMP=y 83 83 CONFIG_XEN=y 84 84 CONFIG_KEXEC=y 85 + CONFIG_CRASH_DUMP=y 85 86 # CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 86 87 CONFIG_COMPAT=y 87 88 CONFIG_CPU_IDLE=y
+2
arch/arm64/include/asm/acpi.h
··· 85 85 return true; 86 86 } 87 87 88 + struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu); 89 + 88 90 static inline void arch_fix_phys_package_id(int num, u32 slot) { } 89 91 void __init acpi_init_cpus(void); 90 92
+13 -68
arch/arm64/include/asm/arch_gicv3.h
··· 20 20 21 21 #include <asm/sysreg.h> 22 22 23 - #define ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1) 24 - #define ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1) 25 - #define ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0) 26 - #define ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5) 27 - #define ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0) 28 - #define ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4) 29 - #define ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5) 30 - #define ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7) 31 - #define ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3) 32 - 33 - #define ICC_SRE_EL2 sys_reg(3, 4, 12, 9, 5) 34 - 35 - /* 36 - * System register definitions 37 - */ 38 - #define ICH_VSEIR_EL2 sys_reg(3, 4, 12, 9, 4) 39 - #define ICH_HCR_EL2 sys_reg(3, 4, 12, 11, 0) 40 - #define ICH_VTR_EL2 sys_reg(3, 4, 12, 11, 1) 41 - #define ICH_MISR_EL2 sys_reg(3, 4, 12, 11, 2) 42 - #define ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3) 43 - #define ICH_ELSR_EL2 sys_reg(3, 4, 12, 11, 5) 44 - #define ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7) 45 - 46 - #define __LR0_EL2(x) sys_reg(3, 4, 12, 12, x) 47 - #define __LR8_EL2(x) sys_reg(3, 4, 12, 13, x) 48 - 49 - #define ICH_LR0_EL2 __LR0_EL2(0) 50 - #define ICH_LR1_EL2 __LR0_EL2(1) 51 - #define ICH_LR2_EL2 __LR0_EL2(2) 52 - #define ICH_LR3_EL2 __LR0_EL2(3) 53 - #define ICH_LR4_EL2 __LR0_EL2(4) 54 - #define ICH_LR5_EL2 __LR0_EL2(5) 55 - #define ICH_LR6_EL2 __LR0_EL2(6) 56 - #define ICH_LR7_EL2 __LR0_EL2(7) 57 - #define ICH_LR8_EL2 __LR8_EL2(0) 58 - #define ICH_LR9_EL2 __LR8_EL2(1) 59 - #define ICH_LR10_EL2 __LR8_EL2(2) 60 - #define ICH_LR11_EL2 __LR8_EL2(3) 61 - #define ICH_LR12_EL2 __LR8_EL2(4) 62 - #define ICH_LR13_EL2 __LR8_EL2(5) 63 - #define ICH_LR14_EL2 __LR8_EL2(6) 64 - #define ICH_LR15_EL2 __LR8_EL2(7) 65 - 66 - #define __AP0Rx_EL2(x) sys_reg(3, 4, 12, 8, x) 67 - #define ICH_AP0R0_EL2 __AP0Rx_EL2(0) 68 - #define ICH_AP0R1_EL2 __AP0Rx_EL2(1) 69 - #define ICH_AP0R2_EL2 __AP0Rx_EL2(2) 70 - #define ICH_AP0R3_EL2 __AP0Rx_EL2(3) 71 - 72 - #define __AP1Rx_EL2(x) sys_reg(3, 4, 12, 9, x) 73 - #define ICH_AP1R0_EL2 __AP1Rx_EL2(0) 74 - #define ICH_AP1R1_EL2 __AP1Rx_EL2(1) 75 - #define ICH_AP1R2_EL2 __AP1Rx_EL2(2) 76 - #define ICH_AP1R3_EL2 __AP1Rx_EL2(3) 77 - 78 23 #ifndef __ASSEMBLY__ 79 24 80 25 #include <linux/stringify.h> 81 26 #include <asm/barrier.h> 82 27 #include <asm/cacheflush.h> 83 28 84 - #define read_gicreg read_sysreg_s 85 - #define write_gicreg write_sysreg_s 29 + #define read_gicreg(r) read_sysreg_s(SYS_ ## r) 30 + #define write_gicreg(v, r) write_sysreg_s(v, SYS_ ## r) 86 31 87 32 /* 88 33 * Low-level accessors ··· 38 93 39 94 static inline void gic_write_eoir(u32 irq) 40 95 { 41 - write_sysreg_s(irq, ICC_EOIR1_EL1); 96 + write_sysreg_s(irq, SYS_ICC_EOIR1_EL1); 42 97 isb(); 43 98 } 44 99 45 100 static inline void gic_write_dir(u32 irq) 46 101 { 47 - write_sysreg_s(irq, ICC_DIR_EL1); 102 + write_sysreg_s(irq, SYS_ICC_DIR_EL1); 48 103 isb(); 49 104 } 50 105 ··· 52 107 { 53 108 u64 irqstat; 54 109 55 - irqstat = read_sysreg_s(ICC_IAR1_EL1); 110 + irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1); 56 111 dsb(sy); 57 112 return irqstat; 58 113 } ··· 69 124 u64 irqstat; 70 125 71 126 nops(8); 72 - irqstat = read_sysreg_s(ICC_IAR1_EL1); 127 + irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1); 73 128 nops(4); 74 129 mb(); 75 130 ··· 78 133 79 134 static inline void gic_write_pmr(u32 val) 80 135 { 81 - write_sysreg_s(val, ICC_PMR_EL1); 136 + write_sysreg_s(val, SYS_ICC_PMR_EL1); 82 137 } 83 138 84 139 static inline void gic_write_ctlr(u32 val) 85 140 { 86 - write_sysreg_s(val, ICC_CTLR_EL1); 141 + write_sysreg_s(val, SYS_ICC_CTLR_EL1); 87 142 isb(); 88 143 } 89 144 90 145 static inline void gic_write_grpen1(u32 val) 91 146 { 92 - write_sysreg_s(val, ICC_GRPEN1_EL1); 147 + write_sysreg_s(val, SYS_ICC_GRPEN1_EL1); 93 148 isb(); 94 149 } 95 150 96 151 static inline void gic_write_sgi1r(u64 val) 97 152 { 98 - write_sysreg_s(val, ICC_SGI1R_EL1); 153 + write_sysreg_s(val, SYS_ICC_SGI1R_EL1); 99 154 } 100 155 101 156 static inline u32 gic_read_sre(void) 102 157 { 103 - return read_sysreg_s(ICC_SRE_EL1); 158 + return read_sysreg_s(SYS_ICC_SRE_EL1); 104 159 } 105 160 106 161 static inline void gic_write_sre(u32 val) 107 162 { 108 - write_sysreg_s(val, ICC_SRE_EL1); 163 + write_sysreg_s(val, SYS_ICC_SRE_EL1); 109 164 isb(); 110 165 } 111 166 112 167 static inline void gic_write_bpr1(u32 val) 113 168 { 114 - asm volatile("msr_s " __stringify(ICC_BPR1_EL1) ", %0" : : "r" (val)); 169 + write_sysreg_s(val, SYS_ICC_BPR1_EL1); 115 170 } 116 171 117 172 #define gic_read_typer(c) readq_relaxed(c)
+18 -14
arch/arm64/include/asm/bug.h
··· 20 20 21 21 #include <asm/brk-imm.h> 22 22 23 - #ifdef CONFIG_GENERIC_BUG 24 - #define HAVE_ARCH_BUG 25 - 26 23 #ifdef CONFIG_DEBUG_BUGVERBOSE 27 24 #define _BUGVERBOSE_LOCATION(file, line) __BUGVERBOSE_LOCATION(file, line) 28 25 #define __BUGVERBOSE_LOCATION(file, line) \ ··· 33 36 #define _BUGVERBOSE_LOCATION(file, line) 34 37 #endif 35 38 36 - #define _BUG_FLAGS(flags) __BUG_FLAGS(flags) 39 + #ifdef CONFIG_GENERIC_BUG 37 40 38 - #define __BUG_FLAGS(flags) asm volatile ( \ 41 + #define __BUG_ENTRY(flags) \ 39 42 ".pushsection __bug_table,\"a\"\n\t" \ 40 43 ".align 2\n\t" \ 41 44 "0: .long 1f - 0b\n\t" \ 42 45 _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \ 43 46 ".short " #flags "\n\t" \ 44 47 ".popsection\n" \ 45 - \ 46 - "1: brk %[imm]" \ 47 - :: [imm] "i" (BUG_BRK_IMM) \ 48 - ) 48 + "1: " 49 + #else 50 + #define __BUG_ENTRY(flags) "" 51 + #endif 49 52 50 - #define BUG() do { \ 51 - _BUG_FLAGS(0); \ 52 - unreachable(); \ 53 + #define __BUG_FLAGS(flags) \ 54 + asm volatile ( \ 55 + __BUG_ENTRY(flags) \ 56 + "brk %[imm]" :: [imm] "i" (BUG_BRK_IMM) \ 57 + ); 58 + 59 + 60 + #define BUG() do { \ 61 + __BUG_FLAGS(0); \ 62 + unreachable(); \ 53 63 } while (0) 54 64 55 - #define __WARN_FLAGS(flags) _BUG_FLAGS(BUGFLAG_WARNING|(flags)) 65 + #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags)) 56 66 57 - #endif /* ! CONFIG_GENERIC_BUG */ 67 + #define HAVE_ARCH_BUG 58 68 59 69 #include <asm-generic/bug.h> 60 70
+37 -1
arch/arm64/include/asm/cache.h
··· 16 16 #ifndef __ASM_CACHE_H 17 17 #define __ASM_CACHE_H 18 18 19 - #include <asm/cachetype.h> 19 + #include <asm/cputype.h> 20 + 21 + #define CTR_L1IP_SHIFT 14 22 + #define CTR_L1IP_MASK 3 23 + #define CTR_CWG_SHIFT 24 24 + #define CTR_CWG_MASK 15 25 + 26 + #define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK) 27 + 28 + #define ICACHE_POLICY_VPIPT 0 29 + #define ICACHE_POLICY_VIPT 2 30 + #define ICACHE_POLICY_PIPT 3 20 31 21 32 #define L1_CACHE_SHIFT 7 22 33 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) ··· 42 31 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES 43 32 44 33 #ifndef __ASSEMBLY__ 34 + 35 + #include <linux/bitops.h> 36 + 37 + #define ICACHEF_ALIASING 0 38 + #define ICACHEF_VPIPT 1 39 + extern unsigned long __icache_flags; 40 + 41 + /* 42 + * Whilst the D-side always behaves as PIPT on AArch64, aliasing is 43 + * permitted in the I-cache. 44 + */ 45 + static inline int icache_is_aliasing(void) 46 + { 47 + return test_bit(ICACHEF_ALIASING, &__icache_flags); 48 + } 49 + 50 + static inline int icache_is_vpipt(void) 51 + { 52 + return test_bit(ICACHEF_VPIPT, &__icache_flags); 53 + } 54 + 55 + static inline u32 cache_type_cwg(void) 56 + { 57 + return (read_cpuid_cachetype() >> CTR_CWG_SHIFT) & CTR_CWG_MASK; 58 + } 45 59 46 60 #define __read_mostly __attribute__((__section__(".data..read_mostly"))) 47 61
+1
arch/arm64/include/asm/cacheflush.h
··· 154 154 int set_memory_rw(unsigned long addr, int numpages); 155 155 int set_memory_x(unsigned long addr, int numpages); 156 156 int set_memory_nx(unsigned long addr, int numpages); 157 + int set_memory_valid(unsigned long addr, unsigned long size, int enable); 157 158 158 159 #endif
-100
arch/arm64/include/asm/cachetype.h
··· 1 - /* 2 - * Copyright (C) 2012 ARM Ltd. 3 - * 4 - * This program is free software; you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License version 2 as 6 - * published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 - * GNU General Public License for more details. 12 - * 13 - * You should have received a copy of the GNU General Public License 14 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 - */ 16 - #ifndef __ASM_CACHETYPE_H 17 - #define __ASM_CACHETYPE_H 18 - 19 - #include <asm/cputype.h> 20 - 21 - #define CTR_L1IP_SHIFT 14 22 - #define CTR_L1IP_MASK 3 23 - #define CTR_CWG_SHIFT 24 24 - #define CTR_CWG_MASK 15 25 - 26 - #define ICACHE_POLICY_RESERVED 0 27 - #define ICACHE_POLICY_AIVIVT 1 28 - #define ICACHE_POLICY_VIPT 2 29 - #define ICACHE_POLICY_PIPT 3 30 - 31 - #ifndef __ASSEMBLY__ 32 - 33 - #include <linux/bitops.h> 34 - 35 - #define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK) 36 - 37 - #define ICACHEF_ALIASING 0 38 - #define ICACHEF_AIVIVT 1 39 - 40 - extern unsigned long __icache_flags; 41 - 42 - /* 43 - * NumSets, bits[27:13] - (Number of sets in cache) - 1 44 - * Associativity, bits[12:3] - (Associativity of cache) - 1 45 - * LineSize, bits[2:0] - (Log2(Number of words in cache line)) - 2 46 - */ 47 - #define CCSIDR_EL1_WRITE_THROUGH BIT(31) 48 - #define CCSIDR_EL1_WRITE_BACK BIT(30) 49 - #define CCSIDR_EL1_READ_ALLOCATE BIT(29) 50 - #define CCSIDR_EL1_WRITE_ALLOCATE BIT(28) 51 - #define CCSIDR_EL1_LINESIZE_MASK 0x7 52 - #define CCSIDR_EL1_LINESIZE(x) ((x) & CCSIDR_EL1_LINESIZE_MASK) 53 - #define CCSIDR_EL1_ASSOCIATIVITY_SHIFT 3 54 - #define CCSIDR_EL1_ASSOCIATIVITY_MASK 0x3ff 55 - #define CCSIDR_EL1_ASSOCIATIVITY(x) \ 56 - (((x) >> CCSIDR_EL1_ASSOCIATIVITY_SHIFT) & CCSIDR_EL1_ASSOCIATIVITY_MASK) 57 - #define CCSIDR_EL1_NUMSETS_SHIFT 13 58 - #define CCSIDR_EL1_NUMSETS_MASK 0x7fff 59 - #define CCSIDR_EL1_NUMSETS(x) \ 60 - (((x) >> CCSIDR_EL1_NUMSETS_SHIFT) & CCSIDR_EL1_NUMSETS_MASK) 61 - 62 - #define CACHE_LINESIZE(x) (16 << CCSIDR_EL1_LINESIZE(x)) 63 - #define CACHE_NUMSETS(x) (CCSIDR_EL1_NUMSETS(x) + 1) 64 - #define CACHE_ASSOCIATIVITY(x) (CCSIDR_EL1_ASSOCIATIVITY(x) + 1) 65 - 66 - extern u64 __attribute_const__ cache_get_ccsidr(u64 csselr); 67 - 68 - /* Helpers for Level 1 Instruction cache csselr = 1L */ 69 - static inline int icache_get_linesize(void) 70 - { 71 - return CACHE_LINESIZE(cache_get_ccsidr(1L)); 72 - } 73 - 74 - static inline int icache_get_numsets(void) 75 - { 76 - return CACHE_NUMSETS(cache_get_ccsidr(1L)); 77 - } 78 - 79 - /* 80 - * Whilst the D-side always behaves as PIPT on AArch64, aliasing is 81 - * permitted in the I-cache. 82 - */ 83 - static inline int icache_is_aliasing(void) 84 - { 85 - return test_bit(ICACHEF_ALIASING, &__icache_flags); 86 - } 87 - 88 - static inline int icache_is_aivivt(void) 89 - { 90 - return test_bit(ICACHEF_AIVIVT, &__icache_flags); 91 - } 92 - 93 - static inline u32 cache_type_cwg(void) 94 - { 95 - return (read_cpuid_cachetype() >> CTR_CWG_SHIFT) & CTR_CWG_MASK; 96 - } 97 - 98 - #endif /* __ASSEMBLY__ */ 99 - 100 - #endif /* __ASM_CACHETYPE_H */
+2 -2
arch/arm64/include/asm/cpufeature.h
··· 226 226 void __init enable_errata_workarounds(void); 227 227 void verify_local_cpu_errata_workarounds(void); 228 228 229 - u64 read_system_reg(u32 id); 229 + u64 read_sanitised_ftr_reg(u32 id); 230 230 231 231 static inline bool cpu_supports_mixed_endian_el0(void) 232 232 { ··· 240 240 241 241 static inline bool system_supports_mixed_endian_el0(void) 242 242 { 243 - return id_aa64mmfr0_mixed_endian_el0(read_system_reg(SYS_ID_AA64MMFR0_EL1)); 243 + return id_aa64mmfr0_mixed_endian_el0(read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1)); 244 244 } 245 245 246 246 static inline bool system_supports_fpsimd(void)
+4
arch/arm64/include/asm/esr.h
··· 177 177 178 178 #define ESR_ELx_SYS64_ISS_SYS_CNTVCT (ESR_ELx_SYS64_ISS_SYS_VAL(3, 3, 2, 14, 0) | \ 179 179 ESR_ELx_SYS64_ISS_DIR_READ) 180 + 181 + #define ESR_ELx_SYS64_ISS_SYS_CNTFRQ (ESR_ELx_SYS64_ISS_SYS_VAL(3, 3, 0, 14, 0) | \ 182 + ESR_ELx_SYS64_ISS_DIR_READ) 183 + 180 184 #ifndef __ASSEMBLY__ 181 185 #include <asm/types.h> 182 186
+1 -1
arch/arm64/include/asm/hardirq.h
··· 20 20 #include <linux/threads.h> 21 21 #include <asm/irq.h> 22 22 23 - #define NR_IPI 6 23 + #define NR_IPI 7 24 24 25 25 typedef struct { 26 26 unsigned int __softirq_pending;
+2 -2
arch/arm64/include/asm/hw_breakpoint.h
··· 149 149 /* Determine number of BRP registers available. */ 150 150 static inline int get_num_brps(void) 151 151 { 152 - u64 dfr0 = read_system_reg(SYS_ID_AA64DFR0_EL1); 152 + u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); 153 153 return 1 + 154 154 cpuid_feature_extract_unsigned_field(dfr0, 155 155 ID_AA64DFR0_BRPS_SHIFT); ··· 158 158 /* Determine number of WRP registers available. */ 159 159 static inline int get_num_wrps(void) 160 160 { 161 - u64 dfr0 = read_system_reg(SYS_ID_AA64DFR0_EL1); 161 + u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); 162 162 return 1 + 163 163 cpuid_feature_extract_unsigned_field(dfr0, 164 164 ID_AA64DFR0_WRPS_SHIFT);
+51 -1
arch/arm64/include/asm/kexec.h
··· 40 40 static inline void crash_setup_regs(struct pt_regs *newregs, 41 41 struct pt_regs *oldregs) 42 42 { 43 - /* Empty routine needed to avoid build errors. */ 43 + if (oldregs) { 44 + memcpy(newregs, oldregs, sizeof(*newregs)); 45 + } else { 46 + u64 tmp1, tmp2; 47 + 48 + __asm__ __volatile__ ( 49 + "stp x0, x1, [%2, #16 * 0]\n" 50 + "stp x2, x3, [%2, #16 * 1]\n" 51 + "stp x4, x5, [%2, #16 * 2]\n" 52 + "stp x6, x7, [%2, #16 * 3]\n" 53 + "stp x8, x9, [%2, #16 * 4]\n" 54 + "stp x10, x11, [%2, #16 * 5]\n" 55 + "stp x12, x13, [%2, #16 * 6]\n" 56 + "stp x14, x15, [%2, #16 * 7]\n" 57 + "stp x16, x17, [%2, #16 * 8]\n" 58 + "stp x18, x19, [%2, #16 * 9]\n" 59 + "stp x20, x21, [%2, #16 * 10]\n" 60 + "stp x22, x23, [%2, #16 * 11]\n" 61 + "stp x24, x25, [%2, #16 * 12]\n" 62 + "stp x26, x27, [%2, #16 * 13]\n" 63 + "stp x28, x29, [%2, #16 * 14]\n" 64 + "mov %0, sp\n" 65 + "stp x30, %0, [%2, #16 * 15]\n" 66 + 67 + "/* faked current PSTATE */\n" 68 + "mrs %0, CurrentEL\n" 69 + "mrs %1, SPSEL\n" 70 + "orr %0, %0, %1\n" 71 + "mrs %1, DAIF\n" 72 + "orr %0, %0, %1\n" 73 + "mrs %1, NZCV\n" 74 + "orr %0, %0, %1\n" 75 + /* pc */ 76 + "adr %1, 1f\n" 77 + "1:\n" 78 + "stp %1, %0, [%2, #16 * 16]\n" 79 + : "=&r" (tmp1), "=&r" (tmp2) 80 + : "r" (newregs) 81 + : "memory" 82 + ); 83 + } 44 84 } 85 + 86 + #if defined(CONFIG_KEXEC_CORE) && defined(CONFIG_HIBERNATION) 87 + extern bool crash_is_nosave(unsigned long pfn); 88 + extern void crash_prepare_suspend(void); 89 + extern void crash_post_resume(void); 90 + #else 91 + static inline bool crash_is_nosave(unsigned long pfn) {return false; } 92 + static inline void crash_prepare_suspend(void) {} 93 + static inline void crash_post_resume(void) {} 94 + #endif 45 95 46 96 #endif /* __ASSEMBLY__ */ 47 97
+7 -6
arch/arm64/include/asm/kvm_mmu.h
··· 108 108 #else 109 109 110 110 #include <asm/pgalloc.h> 111 - #include <asm/cachetype.h> 111 + #include <asm/cache.h> 112 112 #include <asm/cacheflush.h> 113 113 #include <asm/mmu_context.h> 114 114 #include <asm/pgtable.h> ··· 242 242 243 243 kvm_flush_dcache_to_poc(va, size); 244 244 245 - if (!icache_is_aliasing()) { /* PIPT */ 246 - flush_icache_range((unsigned long)va, 247 - (unsigned long)va + size); 248 - } else if (!icache_is_aivivt()) { /* non ASID-tagged VIVT */ 245 + if (icache_is_aliasing()) { 249 246 /* any kind of VIPT cache */ 250 247 __flush_icache_all(); 248 + } else if (is_kernel_in_hyp_mode() || !icache_is_vpipt()) { 249 + /* PIPT or VPIPT at EL2 (see comment in __kvm_tlb_flush_vmid_ipa) */ 250 + flush_icache_range((unsigned long)va, 251 + (unsigned long)va + size); 251 252 } 252 253 } 253 254 ··· 308 307 309 308 static inline unsigned int kvm_get_vmid_bits(void) 310 309 { 311 - int reg = read_system_reg(SYS_ID_AA64MMFR1_EL1); 310 + int reg = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); 312 311 313 312 return (cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR1_VMIDBITS_SHIFT) == 2) ? 16 : 8; 314 313 }
+1
arch/arm64/include/asm/mmu.h
··· 37 37 unsigned long virt, phys_addr_t size, 38 38 pgprot_t prot, bool page_mappings_only); 39 39 extern void *fixmap_remap_fdt(phys_addr_t dt_phys); 40 + extern void mark_linear_text_alias_ro(void); 40 41 41 42 #endif
+7 -7
arch/arm64/include/asm/module.h
··· 17 17 #define __ASM_MODULE_H 18 18 19 19 #include <asm-generic/module.h> 20 - #include <asm/memory.h> 21 20 22 21 #define MODULE_ARCH_VERMAGIC "aarch64" 23 22 24 23 #ifdef CONFIG_ARM64_MODULE_PLTS 25 - struct mod_arch_specific { 24 + struct mod_plt_sec { 26 25 struct elf64_shdr *plt; 27 26 int plt_num_entries; 28 27 int plt_max_entries; 29 28 }; 29 + 30 + struct mod_arch_specific { 31 + struct mod_plt_sec core; 32 + struct mod_plt_sec init; 33 + }; 30 34 #endif 31 35 32 - u64 module_emit_plt_entry(struct module *mod, const Elf64_Rela *rela, 36 + u64 module_emit_plt_entry(struct module *mod, void *loc, const Elf64_Rela *rela, 33 37 Elf64_Sym *sym); 34 38 35 39 #ifdef CONFIG_RANDOMIZE_BASE 36 - #ifdef CONFIG_MODVERSIONS 37 - #define ARCH_RELOCATES_KCRCTAB 38 - #define reloc_start (kimage_vaddr - KIMAGE_VADDR) 39 - #endif 40 40 extern u64 module_alloc_base; 41 41 #else 42 42 #define module_alloc_base ((u64)_etext - MODULES_VSIZE)
+10
arch/arm64/include/asm/pgtable.h
··· 74 74 #define pte_user_exec(pte) (!(pte_val(pte) & PTE_UXN)) 75 75 #define pte_cont(pte) (!!(pte_val(pte) & PTE_CONT)) 76 76 77 + #define pte_cont_addr_end(addr, end) \ 78 + ({ unsigned long __boundary = ((addr) + CONT_PTE_SIZE) & CONT_PTE_MASK; \ 79 + (__boundary - 1 < (end) - 1) ? __boundary : (end); \ 80 + }) 81 + 82 + #define pmd_cont_addr_end(addr, end) \ 83 + ({ unsigned long __boundary = ((addr) + CONT_PMD_SIZE) & CONT_PMD_MASK; \ 84 + (__boundary - 1 < (end) - 1) ? __boundary : (end); \ 85 + }) 86 + 77 87 #ifdef CONFIG_ARM64_HW_AFDBM 78 88 #define pte_hw_dirty(pte) (pte_write(pte) && !(pte_val(pte) & PTE_RDONLY)) 79 89 #else
+2
arch/arm64/include/asm/processor.h
··· 50 50 #define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1) 51 51 52 52 struct debug_info { 53 + #ifdef CONFIG_HAVE_HW_BREAKPOINT 53 54 /* Have we suspended stepping by a debugger? */ 54 55 int suspended_step; 55 56 /* Allow breakpoints and watchpoints to be disabled for this thread. */ ··· 59 58 /* Hardware breakpoints pinned to this task. */ 60 59 struct perf_event *hbp_break[ARM_MAX_BRP]; 61 60 struct perf_event *hbp_watch[ARM_MAX_WRP]; 61 + #endif 62 62 }; 63 63 64 64 struct cpu_context {
+2
arch/arm64/include/asm/sections.h
··· 24 24 extern char __hyp_idmap_text_start[], __hyp_idmap_text_end[]; 25 25 extern char __hyp_text_start[], __hyp_text_end[]; 26 26 extern char __idmap_text_start[], __idmap_text_end[]; 27 + extern char __initdata_begin[], __initdata_end[]; 28 + extern char __inittext_begin[], __inittext_end[]; 27 29 extern char __irqentry_text_start[], __irqentry_text_end[]; 28 30 extern char __mmuoff_data_start[], __mmuoff_data_end[]; 29 31
+3
arch/arm64/include/asm/smp.h
··· 148 148 */ 149 149 bool cpus_are_stuck_in_kernel(void); 150 150 151 + extern void smp_send_crash_stop(void); 152 + extern bool smp_crash_stop_failed(void); 153 + 151 154 #endif /* ifndef __ASSEMBLY__ */ 152 155 153 156 #endif /* ifndef __ASM_SMP_H */
+160 -7
arch/arm64/include/asm/sysreg.h
··· 48 48 ((crn) << CRn_shift) | ((crm) << CRm_shift) | \ 49 49 ((op2) << Op2_shift)) 50 50 51 + #define sys_insn sys_reg 52 + 51 53 #define sys_reg_Op0(id) (((id) >> Op0_shift) & Op0_mask) 52 54 #define sys_reg_Op1(id) (((id) >> Op1_shift) & Op1_mask) 53 55 #define sys_reg_CRn(id) (((id) >> CRn_shift) & CRn_mask) ··· 83 81 84 82 #endif /* CONFIG_BROKEN_GAS_INST */ 85 83 84 + #define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4) 85 + #define REG_PSTATE_UAO_IMM sys_reg(0, 0, 4, 0, 3) 86 + 87 + #define SET_PSTATE_PAN(x) __emit_inst(0xd5000000 | REG_PSTATE_PAN_IMM | \ 88 + (!!x)<<8 | 0x1f) 89 + #define SET_PSTATE_UAO(x) __emit_inst(0xd5000000 | REG_PSTATE_UAO_IMM | \ 90 + (!!x)<<8 | 0x1f) 91 + 92 + #define SYS_DC_ISW sys_insn(1, 0, 7, 6, 2) 93 + #define SYS_DC_CSW sys_insn(1, 0, 7, 10, 2) 94 + #define SYS_DC_CISW sys_insn(1, 0, 7, 14, 2) 95 + 96 + #define SYS_OSDTRRX_EL1 sys_reg(2, 0, 0, 0, 2) 97 + #define SYS_MDCCINT_EL1 sys_reg(2, 0, 0, 2, 0) 98 + #define SYS_MDSCR_EL1 sys_reg(2, 0, 0, 2, 2) 99 + #define SYS_OSDTRTX_EL1 sys_reg(2, 0, 0, 3, 2) 100 + #define SYS_OSECCR_EL1 sys_reg(2, 0, 0, 6, 2) 101 + #define SYS_DBGBVRn_EL1(n) sys_reg(2, 0, 0, n, 4) 102 + #define SYS_DBGBCRn_EL1(n) sys_reg(2, 0, 0, n, 5) 103 + #define SYS_DBGWVRn_EL1(n) sys_reg(2, 0, 0, n, 6) 104 + #define SYS_DBGWCRn_EL1(n) sys_reg(2, 0, 0, n, 7) 105 + #define SYS_MDRAR_EL1 sys_reg(2, 0, 1, 0, 0) 106 + #define SYS_OSLAR_EL1 sys_reg(2, 0, 1, 0, 4) 107 + #define SYS_OSLSR_EL1 sys_reg(2, 0, 1, 1, 4) 108 + #define SYS_OSDLR_EL1 sys_reg(2, 0, 1, 3, 4) 109 + #define SYS_DBGPRCR_EL1 sys_reg(2, 0, 1, 4, 4) 110 + #define SYS_DBGCLAIMSET_EL1 sys_reg(2, 0, 7, 8, 6) 111 + #define SYS_DBGCLAIMCLR_EL1 sys_reg(2, 0, 7, 9, 6) 112 + #define SYS_DBGAUTHSTATUS_EL1 sys_reg(2, 0, 7, 14, 6) 113 + #define SYS_MDCCSR_EL0 sys_reg(2, 3, 0, 1, 0) 114 + #define SYS_DBGDTR_EL0 sys_reg(2, 3, 0, 4, 0) 115 + #define SYS_DBGDTRRX_EL0 sys_reg(2, 3, 0, 5, 0) 116 + #define SYS_DBGDTRTX_EL0 sys_reg(2, 3, 0, 5, 0) 117 + #define SYS_DBGVCR32_EL2 sys_reg(2, 4, 0, 7, 0) 118 + 86 119 #define SYS_MIDR_EL1 sys_reg(3, 0, 0, 0, 0) 87 120 #define SYS_MPIDR_EL1 sys_reg(3, 0, 0, 0, 5) 88 121 #define SYS_REVIDR_EL1 sys_reg(3, 0, 0, 0, 6) ··· 125 88 #define SYS_ID_PFR0_EL1 sys_reg(3, 0, 0, 1, 0) 126 89 #define SYS_ID_PFR1_EL1 sys_reg(3, 0, 0, 1, 1) 127 90 #define SYS_ID_DFR0_EL1 sys_reg(3, 0, 0, 1, 2) 91 + #define SYS_ID_AFR0_EL1 sys_reg(3, 0, 0, 1, 3) 128 92 #define SYS_ID_MMFR0_EL1 sys_reg(3, 0, 0, 1, 4) 129 93 #define SYS_ID_MMFR1_EL1 sys_reg(3, 0, 0, 1, 5) 130 94 #define SYS_ID_MMFR2_EL1 sys_reg(3, 0, 0, 1, 6) ··· 156 118 #define SYS_ID_AA64MMFR1_EL1 sys_reg(3, 0, 0, 7, 1) 157 119 #define SYS_ID_AA64MMFR2_EL1 sys_reg(3, 0, 0, 7, 2) 158 120 159 - #define SYS_CNTFRQ_EL0 sys_reg(3, 3, 14, 0, 0) 121 + #define SYS_SCTLR_EL1 sys_reg(3, 0, 1, 0, 0) 122 + #define SYS_ACTLR_EL1 sys_reg(3, 0, 1, 0, 1) 123 + #define SYS_CPACR_EL1 sys_reg(3, 0, 1, 0, 2) 124 + 125 + #define SYS_TTBR0_EL1 sys_reg(3, 0, 2, 0, 0) 126 + #define SYS_TTBR1_EL1 sys_reg(3, 0, 2, 0, 1) 127 + #define SYS_TCR_EL1 sys_reg(3, 0, 2, 0, 2) 128 + 129 + #define SYS_ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0) 130 + 131 + #define SYS_AFSR0_EL1 sys_reg(3, 0, 5, 1, 0) 132 + #define SYS_AFSR1_EL1 sys_reg(3, 0, 5, 1, 1) 133 + #define SYS_ESR_EL1 sys_reg(3, 0, 5, 2, 0) 134 + #define SYS_FAR_EL1 sys_reg(3, 0, 6, 0, 0) 135 + #define SYS_PAR_EL1 sys_reg(3, 0, 7, 4, 0) 136 + 137 + #define SYS_PMINTENSET_EL1 sys_reg(3, 0, 9, 14, 1) 138 + #define SYS_PMINTENCLR_EL1 sys_reg(3, 0, 9, 14, 2) 139 + 140 + #define SYS_MAIR_EL1 sys_reg(3, 0, 10, 2, 0) 141 + #define SYS_AMAIR_EL1 sys_reg(3, 0, 10, 3, 0) 142 + 143 + #define SYS_VBAR_EL1 sys_reg(3, 0, 12, 0, 0) 144 + 145 + #define SYS_ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1) 146 + #define SYS_ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5) 147 + #define SYS_ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0) 148 + #define SYS_ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1) 149 + #define SYS_ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3) 150 + #define SYS_ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4) 151 + #define SYS_ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5) 152 + #define SYS_ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7) 153 + 154 + #define SYS_CONTEXTIDR_EL1 sys_reg(3, 0, 13, 0, 1) 155 + #define SYS_TPIDR_EL1 sys_reg(3, 0, 13, 0, 4) 156 + 157 + #define SYS_CNTKCTL_EL1 sys_reg(3, 0, 14, 1, 0) 158 + 159 + #define SYS_CLIDR_EL1 sys_reg(3, 1, 0, 0, 1) 160 + #define SYS_AIDR_EL1 sys_reg(3, 1, 0, 0, 7) 161 + 162 + #define SYS_CSSELR_EL1 sys_reg(3, 2, 0, 0, 0) 163 + 160 164 #define SYS_CTR_EL0 sys_reg(3, 3, 0, 0, 1) 161 165 #define SYS_DCZID_EL0 sys_reg(3, 3, 0, 0, 7) 162 166 163 - #define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4) 164 - #define REG_PSTATE_UAO_IMM sys_reg(0, 0, 4, 0, 3) 167 + #define SYS_PMCR_EL0 sys_reg(3, 3, 9, 12, 0) 168 + #define SYS_PMCNTENSET_EL0 sys_reg(3, 3, 9, 12, 1) 169 + #define SYS_PMCNTENCLR_EL0 sys_reg(3, 3, 9, 12, 2) 170 + #define SYS_PMOVSCLR_EL0 sys_reg(3, 3, 9, 12, 3) 171 + #define SYS_PMSWINC_EL0 sys_reg(3, 3, 9, 12, 4) 172 + #define SYS_PMSELR_EL0 sys_reg(3, 3, 9, 12, 5) 173 + #define SYS_PMCEID0_EL0 sys_reg(3, 3, 9, 12, 6) 174 + #define SYS_PMCEID1_EL0 sys_reg(3, 3, 9, 12, 7) 175 + #define SYS_PMCCNTR_EL0 sys_reg(3, 3, 9, 13, 0) 176 + #define SYS_PMXEVTYPER_EL0 sys_reg(3, 3, 9, 13, 1) 177 + #define SYS_PMXEVCNTR_EL0 sys_reg(3, 3, 9, 13, 2) 178 + #define SYS_PMUSERENR_EL0 sys_reg(3, 3, 9, 14, 0) 179 + #define SYS_PMOVSSET_EL0 sys_reg(3, 3, 9, 14, 3) 165 180 166 - #define SET_PSTATE_PAN(x) __emit_inst(0xd5000000 | REG_PSTATE_PAN_IMM | \ 167 - (!!x)<<8 | 0x1f) 168 - #define SET_PSTATE_UAO(x) __emit_inst(0xd5000000 | REG_PSTATE_UAO_IMM | \ 169 - (!!x)<<8 | 0x1f) 181 + #define SYS_TPIDR_EL0 sys_reg(3, 3, 13, 0, 2) 182 + #define SYS_TPIDRRO_EL0 sys_reg(3, 3, 13, 0, 3) 183 + 184 + #define SYS_CNTFRQ_EL0 sys_reg(3, 3, 14, 0, 0) 185 + 186 + #define SYS_CNTP_TVAL_EL0 sys_reg(3, 3, 14, 2, 0) 187 + #define SYS_CNTP_CTL_EL0 sys_reg(3, 3, 14, 2, 1) 188 + #define SYS_CNTP_CVAL_EL0 sys_reg(3, 3, 14, 2, 2) 189 + 190 + #define __PMEV_op2(n) ((n) & 0x7) 191 + #define __CNTR_CRm(n) (0x8 | (((n) >> 3) & 0x3)) 192 + #define SYS_PMEVCNTRn_EL0(n) sys_reg(3, 3, 14, __CNTR_CRm(n), __PMEV_op2(n)) 193 + #define __TYPER_CRm(n) (0xc | (((n) >> 3) & 0x3)) 194 + #define SYS_PMEVTYPERn_EL0(n) sys_reg(3, 3, 14, __TYPER_CRm(n), __PMEV_op2(n)) 195 + 196 + #define SYS_PMCCFILTR_EL0 sys_reg (3, 3, 14, 15, 7) 197 + 198 + #define SYS_DACR32_EL2 sys_reg(3, 4, 3, 0, 0) 199 + #define SYS_IFSR32_EL2 sys_reg(3, 4, 5, 0, 1) 200 + #define SYS_FPEXC32_EL2 sys_reg(3, 4, 5, 3, 0) 201 + 202 + #define __SYS__AP0Rx_EL2(x) sys_reg(3, 4, 12, 8, x) 203 + #define SYS_ICH_AP0R0_EL2 __SYS__AP0Rx_EL2(0) 204 + #define SYS_ICH_AP0R1_EL2 __SYS__AP0Rx_EL2(1) 205 + #define SYS_ICH_AP0R2_EL2 __SYS__AP0Rx_EL2(2) 206 + #define SYS_ICH_AP0R3_EL2 __SYS__AP0Rx_EL2(3) 207 + 208 + #define __SYS__AP1Rx_EL2(x) sys_reg(3, 4, 12, 9, x) 209 + #define SYS_ICH_AP1R0_EL2 __SYS__AP1Rx_EL2(0) 210 + #define SYS_ICH_AP1R1_EL2 __SYS__AP1Rx_EL2(1) 211 + #define SYS_ICH_AP1R2_EL2 __SYS__AP1Rx_EL2(2) 212 + #define SYS_ICH_AP1R3_EL2 __SYS__AP1Rx_EL2(3) 213 + 214 + #define SYS_ICH_VSEIR_EL2 sys_reg(3, 4, 12, 9, 4) 215 + #define SYS_ICC_SRE_EL2 sys_reg(3, 4, 12, 9, 5) 216 + #define SYS_ICH_HCR_EL2 sys_reg(3, 4, 12, 11, 0) 217 + #define SYS_ICH_VTR_EL2 sys_reg(3, 4, 12, 11, 1) 218 + #define SYS_ICH_MISR_EL2 sys_reg(3, 4, 12, 11, 2) 219 + #define SYS_ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3) 220 + #define SYS_ICH_ELSR_EL2 sys_reg(3, 4, 12, 11, 5) 221 + #define SYS_ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7) 222 + 223 + #define __SYS__LR0_EL2(x) sys_reg(3, 4, 12, 12, x) 224 + #define SYS_ICH_LR0_EL2 __SYS__LR0_EL2(0) 225 + #define SYS_ICH_LR1_EL2 __SYS__LR0_EL2(1) 226 + #define SYS_ICH_LR2_EL2 __SYS__LR0_EL2(2) 227 + #define SYS_ICH_LR3_EL2 __SYS__LR0_EL2(3) 228 + #define SYS_ICH_LR4_EL2 __SYS__LR0_EL2(4) 229 + #define SYS_ICH_LR5_EL2 __SYS__LR0_EL2(5) 230 + #define SYS_ICH_LR6_EL2 __SYS__LR0_EL2(6) 231 + #define SYS_ICH_LR7_EL2 __SYS__LR0_EL2(7) 232 + 233 + #define __SYS__LR8_EL2(x) sys_reg(3, 4, 12, 13, x) 234 + #define SYS_ICH_LR8_EL2 __SYS__LR8_EL2(0) 235 + #define SYS_ICH_LR9_EL2 __SYS__LR8_EL2(1) 236 + #define SYS_ICH_LR10_EL2 __SYS__LR8_EL2(2) 237 + #define SYS_ICH_LR11_EL2 __SYS__LR8_EL2(3) 238 + #define SYS_ICH_LR12_EL2 __SYS__LR8_EL2(4) 239 + #define SYS_ICH_LR13_EL2 __SYS__LR8_EL2(5) 240 + #define SYS_ICH_LR14_EL2 __SYS__LR8_EL2(6) 241 + #define SYS_ICH_LR15_EL2 __SYS__LR8_EL2(7) 170 242 171 243 /* Common SCTLR_ELx flags. */ 172 244 #define SCTLR_ELx_EE (1 << 25) ··· 303 155 #define ID_AA64ISAR0_SHA2_SHIFT 12 304 156 #define ID_AA64ISAR0_SHA1_SHIFT 8 305 157 #define ID_AA64ISAR0_AES_SHIFT 4 158 + 159 + /* id_aa64isar1 */ 160 + #define ID_AA64ISAR1_LRCPC_SHIFT 20 161 + #define ID_AA64ISAR1_FCMA_SHIFT 16 162 + #define ID_AA64ISAR1_JSCVT_SHIFT 12 306 163 307 164 /* id_aa64pfr0 */ 308 165 #define ID_AA64PFR0_GIC_SHIFT 24
+3
arch/arm64/include/uapi/asm/hwcap.h
··· 32 32 #define HWCAP_ASIMDHP (1 << 10) 33 33 #define HWCAP_CPUID (1 << 11) 34 34 #define HWCAP_ASIMDRDM (1 << 12) 35 + #define HWCAP_JSCVT (1 << 13) 36 + #define HWCAP_FCMA (1 << 14) 37 + #define HWCAP_LRCPC (1 << 15) 35 38 36 39 #endif /* _UAPI__ASM_HWCAP_H */
+3
arch/arm64/kernel/Makefile
··· 50 50 arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o 51 51 arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ 52 52 cpu-reset.o 53 + arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o 54 + arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o 55 + arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 53 56 54 57 obj-y += $(arm64-obj-y) vdso/ probes/ 55 58 obj-m += $(arm64-obj-m)
+6 -5
arch/arm64/kernel/alternative.c
··· 105 105 return insn; 106 106 } 107 107 108 - static void __apply_alternatives(void *alt_region) 108 + static void __apply_alternatives(void *alt_region, bool use_linear_alias) 109 109 { 110 110 struct alt_instr *alt; 111 111 struct alt_region *region = alt_region; 112 - u32 *origptr, *replptr; 112 + u32 *origptr, *replptr, *updptr; 113 113 114 114 for (alt = region->begin; alt < region->end; alt++) { 115 115 u32 insn; ··· 124 124 125 125 origptr = ALT_ORIG_PTR(alt); 126 126 replptr = ALT_REPL_PTR(alt); 127 + updptr = use_linear_alias ? (u32 *)lm_alias(origptr) : origptr; 127 128 nr_inst = alt->alt_len / sizeof(insn); 128 129 129 130 for (i = 0; i < nr_inst; i++) { 130 131 insn = get_alt_insn(alt, origptr + i, replptr + i); 131 - *(origptr + i) = cpu_to_le32(insn); 132 + updptr[i] = cpu_to_le32(insn); 132 133 } 133 134 134 135 flush_icache_range((uintptr_t)origptr, ··· 156 155 isb(); 157 156 } else { 158 157 BUG_ON(patched); 159 - __apply_alternatives(&region); 158 + __apply_alternatives(&region, true); 160 159 /* Barriers provided by the cache flushing */ 161 160 WRITE_ONCE(patched, 1); 162 161 } ··· 177 176 .end = start + length, 178 177 }; 179 178 180 - __apply_alternatives(&region); 179 + __apply_alternatives(&region, false); 181 180 }
-38
arch/arm64/kernel/cacheinfo.c
··· 17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 19 20 - #include <linux/bitops.h> 21 20 #include <linux/cacheinfo.h> 22 - #include <linux/cpu.h> 23 - #include <linux/compiler.h> 24 21 #include <linux/of.h> 25 - 26 - #include <asm/cachetype.h> 27 - #include <asm/processor.h> 28 22 29 23 #define MAX_CACHE_LEVEL 7 /* Max 7 level supported */ 30 24 /* Ctypen, bits[3(n - 1) + 2 : 3(n - 1)], for n = 1 to 7 */ ··· 37 43 return CLIDR_CTYPE(clidr, level); 38 44 } 39 45 40 - /* 41 - * Cache Size Selection Register(CSSELR) selects which Cache Size ID 42 - * Register(CCSIDR) is accessible by specifying the required cache 43 - * level and the cache type. We need to ensure that no one else changes 44 - * CSSELR by calling this in non-preemtible context 45 - */ 46 - u64 __attribute_const__ cache_get_ccsidr(u64 csselr) 47 - { 48 - u64 ccsidr; 49 - 50 - WARN_ON(preemptible()); 51 - 52 - write_sysreg(csselr, csselr_el1); 53 - isb(); 54 - ccsidr = read_sysreg(ccsidr_el1); 55 - 56 - return ccsidr; 57 - } 58 - 59 46 static void ci_leaf_init(struct cacheinfo *this_leaf, 60 47 enum cache_type type, unsigned int level) 61 48 { 62 - bool is_icache = type & CACHE_TYPE_INST; 63 - u64 tmp = cache_get_ccsidr((level - 1) << 1 | is_icache); 64 - 65 49 this_leaf->level = level; 66 50 this_leaf->type = type; 67 - this_leaf->coherency_line_size = CACHE_LINESIZE(tmp); 68 - this_leaf->number_of_sets = CACHE_NUMSETS(tmp); 69 - this_leaf->ways_of_associativity = CACHE_ASSOCIATIVITY(tmp); 70 - this_leaf->size = this_leaf->number_of_sets * 71 - this_leaf->coherency_line_size * this_leaf->ways_of_associativity; 72 - this_leaf->attributes = 73 - ((tmp & CCSIDR_EL1_WRITE_THROUGH) ? CACHE_WRITE_THROUGH : 0) | 74 - ((tmp & CCSIDR_EL1_WRITE_BACK) ? CACHE_WRITE_BACK : 0) | 75 - ((tmp & CCSIDR_EL1_READ_ALLOCATE) ? CACHE_READ_ALLOCATE : 0) | 76 - ((tmp & CCSIDR_EL1_WRITE_ALLOCATE) ? CACHE_WRITE_ALLOCATE : 0); 77 51 } 78 52 79 53 static int __init_cache_level(unsigned int cpu)
+20 -10
arch/arm64/kernel/cpufeature.c
··· 97 97 ARM64_FTR_END, 98 98 }; 99 99 100 + static const struct arm64_ftr_bits ftr_id_aa64isar1[] = { 101 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, ID_AA64ISAR1_LRCPC_SHIFT, 4, 0), 102 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, ID_AA64ISAR1_FCMA_SHIFT, 4, 0), 103 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_EXACT, ID_AA64ISAR1_JSCVT_SHIFT, 4, 0), 104 + ARM64_FTR_END, 105 + }; 106 + 100 107 static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { 101 108 ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_EXACT, ID_AA64PFR0_GIC_SHIFT, 4, 0), 102 109 S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), ··· 160 153 /* 161 154 * Linux can handle differing I-cache policies. Userspace JITs will 162 155 * make use of *minLine. 163 - * If we have differing I-cache policies, report it as the weakest - AIVIVT. 156 + * If we have differing I-cache policies, report it as the weakest - VIPT. 164 157 */ 165 - ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_AIVIVT), /* L1Ip */ 158 + ARM64_FTR_BITS(FTR_VISIBLE, FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_VIPT), /* L1Ip */ 166 159 ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* IminLine */ 167 160 ARM64_FTR_END, 168 161 }; ··· 321 314 322 315 /* Op1 = 0, CRn = 0, CRm = 6 */ 323 316 ARM64_FTR_REG(SYS_ID_AA64ISAR0_EL1, ftr_id_aa64isar0), 324 - ARM64_FTR_REG(SYS_ID_AA64ISAR1_EL1, ftr_raz), 317 + ARM64_FTR_REG(SYS_ID_AA64ISAR1_EL1, ftr_id_aa64isar1), 325 318 326 319 /* Op1 = 0, CRn = 0, CRm = 7 */ 327 320 ARM64_FTR_REG(SYS_ID_AA64MMFR0_EL1, ftr_id_aa64mmfr0), ··· 592 585 * If we have AArch32, we care about 32-bit features for compat. 593 586 * If the system doesn't support AArch32, don't update them. 594 587 */ 595 - if (id_aa64pfr0_32bit_el0(read_system_reg(SYS_ID_AA64PFR0_EL1)) && 588 + if (id_aa64pfr0_32bit_el0(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1)) && 596 589 id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0)) { 597 590 598 591 taint |= check_update_ftr_reg(SYS_ID_DFR0_EL1, cpu, ··· 643 636 "Unsupported CPU feature variation.\n"); 644 637 } 645 638 646 - u64 read_system_reg(u32 id) 639 + u64 read_sanitised_ftr_reg(u32 id) 647 640 { 648 641 struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id); 649 642 ··· 656 649 case r: return read_sysreg_s(r) 657 650 658 651 /* 659 - * __raw_read_system_reg() - Used by a STARTING cpu before cpuinfo is populated. 652 + * __read_sysreg_by_encoding() - Used by a STARTING cpu before cpuinfo is populated. 660 653 * Read the system register on the current CPU 661 654 */ 662 - static u64 __raw_read_system_reg(u32 sys_id) 655 + static u64 __read_sysreg_by_encoding(u32 sys_id) 663 656 { 664 657 switch (sys_id) { 665 658 read_sysreg_case(SYS_ID_PFR0_EL1); ··· 716 709 717 710 WARN_ON(scope == SCOPE_LOCAL_CPU && preemptible()); 718 711 if (scope == SCOPE_SYSTEM) 719 - val = read_system_reg(entry->sys_reg); 712 + val = read_sanitised_ftr_reg(entry->sys_reg); 720 713 else 721 - val = __raw_read_system_reg(entry->sys_reg); 714 + val = __read_sysreg_by_encoding(entry->sys_reg); 722 715 723 716 return feature_matches(val, entry); 724 717 } ··· 768 761 769 762 static bool has_no_fpsimd(const struct arm64_cpu_capabilities *entry, int __unused) 770 763 { 771 - u64 pfr0 = read_system_reg(SYS_ID_AA64PFR0_EL1); 764 + u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); 772 765 773 766 return cpuid_feature_extract_signed_field(pfr0, 774 767 ID_AA64PFR0_FP_SHIFT) < 0; ··· 895 888 HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_FPHP), 896 889 HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_ASIMD), 897 890 HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_ASIMDHP), 891 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_JSCVT_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_JSCVT), 892 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_FCMA_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_FCMA), 893 + HWCAP_CAP(SYS_ID_AA64ISAR1_EL1, ID_AA64ISAR1_LRCPC_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_LRCPC), 898 894 {}, 899 895 }; 900 896
+19 -18
arch/arm64/kernel/cpuinfo.c
··· 15 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 #include <asm/arch_timer.h> 18 - #include <asm/cachetype.h> 18 + #include <asm/cache.h> 19 19 #include <asm/cpu.h> 20 20 #include <asm/cputype.h> 21 21 #include <asm/cpufeature.h> ··· 43 43 static struct cpuinfo_arm64 boot_cpu_data; 44 44 45 45 static char *icache_policy_str[] = { 46 - [ICACHE_POLICY_RESERVED] = "RESERVED/UNKNOWN", 47 - [ICACHE_POLICY_AIVIVT] = "AIVIVT", 48 - [ICACHE_POLICY_VIPT] = "VIPT", 49 - [ICACHE_POLICY_PIPT] = "PIPT", 46 + [0 ... ICACHE_POLICY_PIPT] = "RESERVED/UNKNOWN", 47 + [ICACHE_POLICY_VIPT] = "VIPT", 48 + [ICACHE_POLICY_PIPT] = "PIPT", 49 + [ICACHE_POLICY_VPIPT] = "VPIPT", 50 50 }; 51 51 52 52 unsigned long __icache_flags; ··· 65 65 "asimdhp", 66 66 "cpuid", 67 67 "asimdrdm", 68 + "jscvt", 69 + "fcma", 70 + "lrcpc", 68 71 NULL 69 72 }; 70 73 ··· 292 289 unsigned int cpu = smp_processor_id(); 293 290 u32 l1ip = CTR_L1IP(info->reg_ctr); 294 291 295 - if (l1ip != ICACHE_POLICY_PIPT) { 296 - /* 297 - * VIPT caches are non-aliasing if the VA always equals the PA 298 - * in all bit positions that are covered by the index. This is 299 - * the case if the size of a way (# of sets * line size) does 300 - * not exceed PAGE_SIZE. 301 - */ 302 - u32 waysize = icache_get_numsets() * icache_get_linesize(); 303 - 304 - if (l1ip != ICACHE_POLICY_VIPT || waysize > PAGE_SIZE) 305 - set_bit(ICACHEF_ALIASING, &__icache_flags); 292 + switch (l1ip) { 293 + case ICACHE_POLICY_PIPT: 294 + break; 295 + case ICACHE_POLICY_VPIPT: 296 + set_bit(ICACHEF_VPIPT, &__icache_flags); 297 + break; 298 + default: 299 + /* Fallthrough */ 300 + case ICACHE_POLICY_VIPT: 301 + /* Assume aliasing */ 302 + set_bit(ICACHEF_ALIASING, &__icache_flags); 306 303 } 307 - if (l1ip == ICACHE_POLICY_AIVIVT) 308 - set_bit(ICACHEF_AIVIVT, &__icache_flags); 309 304 310 305 pr_info("Detected %s I-cache on CPU%d\n", icache_policy_str[l1ip], cpu); 311 306 }
+71
arch/arm64/kernel/crash_dump.c
··· 1 + /* 2 + * Routines for doing kexec-based kdump 3 + * 4 + * Copyright (C) 2017 Linaro Limited 5 + * Author: AKASHI Takahiro <takahiro.akashi@linaro.org> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + 12 + #include <linux/crash_dump.h> 13 + #include <linux/errno.h> 14 + #include <linux/io.h> 15 + #include <linux/memblock.h> 16 + #include <linux/uaccess.h> 17 + #include <asm/memory.h> 18 + 19 + /** 20 + * copy_oldmem_page() - copy one page from old kernel memory 21 + * @pfn: page frame number to be copied 22 + * @buf: buffer where the copied page is placed 23 + * @csize: number of bytes to copy 24 + * @offset: offset in bytes into the page 25 + * @userbuf: if set, @buf is in a user address space 26 + * 27 + * This function copies one page from old kernel memory into buffer pointed by 28 + * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes 29 + * copied or negative error in case of failure. 30 + */ 31 + ssize_t copy_oldmem_page(unsigned long pfn, char *buf, 32 + size_t csize, unsigned long offset, 33 + int userbuf) 34 + { 35 + void *vaddr; 36 + 37 + if (!csize) 38 + return 0; 39 + 40 + vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, MEMREMAP_WB); 41 + if (!vaddr) 42 + return -ENOMEM; 43 + 44 + if (userbuf) { 45 + if (copy_to_user((char __user *)buf, vaddr + offset, csize)) { 46 + memunmap(vaddr); 47 + return -EFAULT; 48 + } 49 + } else { 50 + memcpy(buf, vaddr + offset, csize); 51 + } 52 + 53 + memunmap(vaddr); 54 + 55 + return csize; 56 + } 57 + 58 + /** 59 + * elfcorehdr_read - read from ELF core header 60 + * @buf: buffer where the data is placed 61 + * @csize: number of bytes to read 62 + * @ppos: address in the memory 63 + * 64 + * This function reads @count bytes from elf core header which exists 65 + * on crash dump kernel's memory. 66 + */ 67 + ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) 68 + { 69 + memcpy(buf, phys_to_virt((phys_addr_t)*ppos), count); 70 + return count; 71 + }
+1 -1
arch/arm64/kernel/debug-monitors.c
··· 36 36 /* Determine debug architecture. */ 37 37 u8 debug_monitors_arch(void) 38 38 { 39 - return cpuid_feature_extract_unsigned_field(read_system_reg(SYS_ID_AA64DFR0_EL1), 39 + return cpuid_feature_extract_unsigned_field(read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1), 40 40 ID_AA64DFR0_DEBUGVER_SHIFT); 41 41 } 42 42
+155
arch/arm64/kernel/efi-header.S
··· 1 + /* 2 + * Copyright (C) 2013 - 2017 Linaro, Ltd. 3 + * Copyright (C) 2013, 2014 Red Hat, Inc. 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + */ 9 + 10 + #include <linux/pe.h> 11 + #include <linux/sizes.h> 12 + 13 + .macro __EFI_PE_HEADER 14 + .long PE_MAGIC 15 + coff_header: 16 + .short IMAGE_FILE_MACHINE_ARM64 // Machine 17 + .short section_count // NumberOfSections 18 + .long 0 // TimeDateStamp 19 + .long 0 // PointerToSymbolTable 20 + .long 0 // NumberOfSymbols 21 + .short section_table - optional_header // SizeOfOptionalHeader 22 + .short IMAGE_FILE_DEBUG_STRIPPED | \ 23 + IMAGE_FILE_EXECUTABLE_IMAGE | \ 24 + IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics 25 + 26 + optional_header: 27 + .short PE_OPT_MAGIC_PE32PLUS // PE32+ format 28 + .byte 0x02 // MajorLinkerVersion 29 + .byte 0x14 // MinorLinkerVersion 30 + .long __initdata_begin - efi_header_end // SizeOfCode 31 + .long __pecoff_data_size // SizeOfInitializedData 32 + .long 0 // SizeOfUninitializedData 33 + .long __efistub_entry - _head // AddressOfEntryPoint 34 + .long efi_header_end - _head // BaseOfCode 35 + 36 + extra_header_fields: 37 + .quad 0 // ImageBase 38 + .long SZ_4K // SectionAlignment 39 + .long PECOFF_FILE_ALIGNMENT // FileAlignment 40 + .short 0 // MajorOperatingSystemVersion 41 + .short 0 // MinorOperatingSystemVersion 42 + .short 0 // MajorImageVersion 43 + .short 0 // MinorImageVersion 44 + .short 0 // MajorSubsystemVersion 45 + .short 0 // MinorSubsystemVersion 46 + .long 0 // Win32VersionValue 47 + 48 + .long _end - _head // SizeOfImage 49 + 50 + // Everything before the kernel image is considered part of the header 51 + .long efi_header_end - _head // SizeOfHeaders 52 + .long 0 // CheckSum 53 + .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem 54 + .short 0 // DllCharacteristics 55 + .quad 0 // SizeOfStackReserve 56 + .quad 0 // SizeOfStackCommit 57 + .quad 0 // SizeOfHeapReserve 58 + .quad 0 // SizeOfHeapCommit 59 + .long 0 // LoaderFlags 60 + .long (section_table - .) / 8 // NumberOfRvaAndSizes 61 + 62 + .quad 0 // ExportTable 63 + .quad 0 // ImportTable 64 + .quad 0 // ResourceTable 65 + .quad 0 // ExceptionTable 66 + .quad 0 // CertificationTable 67 + .quad 0 // BaseRelocationTable 68 + 69 + #ifdef CONFIG_DEBUG_EFI 70 + .long efi_debug_table - _head // DebugTable 71 + .long efi_debug_table_size 72 + #endif 73 + 74 + // Section table 75 + section_table: 76 + .ascii ".text\0\0\0" 77 + .long __initdata_begin - efi_header_end // VirtualSize 78 + .long efi_header_end - _head // VirtualAddress 79 + .long __initdata_begin - efi_header_end // SizeOfRawData 80 + .long efi_header_end - _head // PointerToRawData 81 + 82 + .long 0 // PointerToRelocations 83 + .long 0 // PointerToLineNumbers 84 + .short 0 // NumberOfRelocations 85 + .short 0 // NumberOfLineNumbers 86 + .long IMAGE_SCN_CNT_CODE | \ 87 + IMAGE_SCN_MEM_READ | \ 88 + IMAGE_SCN_MEM_EXECUTE // Characteristics 89 + 90 + .ascii ".data\0\0\0" 91 + .long __pecoff_data_size // VirtualSize 92 + .long __initdata_begin - _head // VirtualAddress 93 + .long __pecoff_data_rawsize // SizeOfRawData 94 + .long __initdata_begin - _head // PointerToRawData 95 + 96 + .long 0 // PointerToRelocations 97 + .long 0 // PointerToLineNumbers 98 + .short 0 // NumberOfRelocations 99 + .short 0 // NumberOfLineNumbers 100 + .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 101 + IMAGE_SCN_MEM_READ | \ 102 + IMAGE_SCN_MEM_WRITE // Characteristics 103 + 104 + .set section_count, (. - section_table) / 40 105 + 106 + #ifdef CONFIG_DEBUG_EFI 107 + /* 108 + * The debug table is referenced via its Relative Virtual Address (RVA), 109 + * which is only defined for those parts of the image that are covered 110 + * by a section declaration. Since this header is not covered by any 111 + * section, the debug table must be emitted elsewhere. So stick it in 112 + * the .init.rodata section instead. 113 + * 114 + * Note that the EFI debug entry itself may legally have a zero RVA, 115 + * which means we can simply put it right after the section headers. 116 + */ 117 + __INITRODATA 118 + 119 + .align 2 120 + efi_debug_table: 121 + // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY 122 + .long 0 // Characteristics 123 + .long 0 // TimeDateStamp 124 + .short 0 // MajorVersion 125 + .short 0 // MinorVersion 126 + .long IMAGE_DEBUG_TYPE_CODEVIEW // Type 127 + .long efi_debug_entry_size // SizeOfData 128 + .long 0 // RVA 129 + .long efi_debug_entry - _head // FileOffset 130 + 131 + .set efi_debug_table_size, . - efi_debug_table 132 + .previous 133 + 134 + efi_debug_entry: 135 + // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY 136 + .ascii "NB10" // Signature 137 + .long 0 // Unknown 138 + .long 0 // Unknown2 139 + .long 0 // Unknown3 140 + 141 + .asciz VMLINUX_PATH 142 + 143 + .set efi_debug_entry_size, . - efi_debug_entry 144 + #endif 145 + 146 + /* 147 + * EFI will load .text onwards at the 4k section alignment 148 + * described in the PE/COFF header. To ensure that instruction 149 + * sequences using an adrp and a :lo12: immediate will function 150 + * correctly at this alignment, we must ensure that .text is 151 + * placed at a 4k boundary in the Image to begin with. 152 + */ 153 + .align 12 154 + efi_header_end: 155 + .endm
+34 -188
arch/arm64/kernel/head.S
··· 42 42 #include <asm/thread_info.h> 43 43 #include <asm/virt.h> 44 44 45 + #include "efi-header.S" 46 + 45 47 #define __PHYS_OFFSET (KERNEL_START - TEXT_OFFSET) 46 48 47 49 #if (TEXT_OFFSET & 0xfff) != 0 ··· 91 89 .quad 0 // reserved 92 90 .quad 0 // reserved 93 91 .quad 0 // reserved 94 - .byte 0x41 // Magic number, "ARM\x64" 95 - .byte 0x52 96 - .byte 0x4d 97 - .byte 0x64 92 + .ascii "ARM\x64" // Magic number 98 93 #ifdef CONFIG_EFI 99 94 .long pe_header - _head // Offset to the PE header. 100 - #else 101 - .word 0 // reserved 102 - #endif 103 95 104 - #ifdef CONFIG_EFI 105 - .align 3 106 96 pe_header: 107 - .ascii "PE" 108 - .short 0 109 - coff_header: 110 - .short 0xaa64 // AArch64 111 - .short 2 // nr_sections 112 - .long 0 // TimeDateStamp 113 - .long 0 // PointerToSymbolTable 114 - .long 1 // NumberOfSymbols 115 - .short section_table - optional_header // SizeOfOptionalHeader 116 - .short 0x206 // Characteristics. 117 - // IMAGE_FILE_DEBUG_STRIPPED | 118 - // IMAGE_FILE_EXECUTABLE_IMAGE | 119 - // IMAGE_FILE_LINE_NUMS_STRIPPED 120 - optional_header: 121 - .short 0x20b // PE32+ format 122 - .byte 0x02 // MajorLinkerVersion 123 - .byte 0x14 // MinorLinkerVersion 124 - .long _end - efi_header_end // SizeOfCode 125 - .long 0 // SizeOfInitializedData 126 - .long 0 // SizeOfUninitializedData 127 - .long __efistub_entry - _head // AddressOfEntryPoint 128 - .long efi_header_end - _head // BaseOfCode 129 - 130 - extra_header_fields: 131 - .quad 0 // ImageBase 132 - .long 0x1000 // SectionAlignment 133 - .long PECOFF_FILE_ALIGNMENT // FileAlignment 134 - .short 0 // MajorOperatingSystemVersion 135 - .short 0 // MinorOperatingSystemVersion 136 - .short 0 // MajorImageVersion 137 - .short 0 // MinorImageVersion 138 - .short 0 // MajorSubsystemVersion 139 - .short 0 // MinorSubsystemVersion 140 - .long 0 // Win32VersionValue 141 - 142 - .long _end - _head // SizeOfImage 143 - 144 - // Everything before the kernel image is considered part of the header 145 - .long efi_header_end - _head // SizeOfHeaders 146 - .long 0 // CheckSum 147 - .short 0xa // Subsystem (EFI application) 148 - .short 0 // DllCharacteristics 149 - .quad 0 // SizeOfStackReserve 150 - .quad 0 // SizeOfStackCommit 151 - .quad 0 // SizeOfHeapReserve 152 - .quad 0 // SizeOfHeapCommit 153 - .long 0 // LoaderFlags 154 - .long (section_table - .) / 8 // NumberOfRvaAndSizes 155 - 156 - .quad 0 // ExportTable 157 - .quad 0 // ImportTable 158 - .quad 0 // ResourceTable 159 - .quad 0 // ExceptionTable 160 - .quad 0 // CertificationTable 161 - .quad 0 // BaseRelocationTable 162 - 163 - #ifdef CONFIG_DEBUG_EFI 164 - .long efi_debug_table - _head // DebugTable 165 - .long efi_debug_table_size 166 - #endif 167 - 168 - // Section table 169 - section_table: 170 - 171 - /* 172 - * The EFI application loader requires a relocation section 173 - * because EFI applications must be relocatable. This is a 174 - * dummy section as far as we are concerned. 175 - */ 176 - .ascii ".reloc" 177 - .byte 0 178 - .byte 0 // end of 0 padding of section name 179 - .long 0 180 - .long 0 181 - .long 0 // SizeOfRawData 182 - .long 0 // PointerToRawData 183 - .long 0 // PointerToRelocations 184 - .long 0 // PointerToLineNumbers 185 - .short 0 // NumberOfRelocations 186 - .short 0 // NumberOfLineNumbers 187 - .long 0x42100040 // Characteristics (section flags) 188 - 189 - 190 - .ascii ".text" 191 - .byte 0 192 - .byte 0 193 - .byte 0 // end of 0 padding of section name 194 - .long _end - efi_header_end // VirtualSize 195 - .long efi_header_end - _head // VirtualAddress 196 - .long _edata - efi_header_end // SizeOfRawData 197 - .long efi_header_end - _head // PointerToRawData 198 - 199 - .long 0 // PointerToRelocations (0 for executables) 200 - .long 0 // PointerToLineNumbers (0 for executables) 201 - .short 0 // NumberOfRelocations (0 for executables) 202 - .short 0 // NumberOfLineNumbers (0 for executables) 203 - .long 0xe0500020 // Characteristics (section flags) 204 - 205 - #ifdef CONFIG_DEBUG_EFI 206 - /* 207 - * The debug table is referenced via its Relative Virtual Address (RVA), 208 - * which is only defined for those parts of the image that are covered 209 - * by a section declaration. Since this header is not covered by any 210 - * section, the debug table must be emitted elsewhere. So stick it in 211 - * the .init.rodata section instead. 212 - * 213 - * Note that the EFI debug entry itself may legally have a zero RVA, 214 - * which means we can simply put it right after the section headers. 215 - */ 216 - __INITRODATA 217 - 218 - .align 2 219 - efi_debug_table: 220 - // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY 221 - .long 0 // Characteristics 222 - .long 0 // TimeDateStamp 223 - .short 0 // MajorVersion 224 - .short 0 // MinorVersion 225 - .long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW 226 - .long efi_debug_entry_size // SizeOfData 227 - .long 0 // RVA 228 - .long efi_debug_entry - _head // FileOffset 229 - 230 - .set efi_debug_table_size, . - efi_debug_table 231 - .previous 232 - 233 - efi_debug_entry: 234 - // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY 235 - .ascii "NB10" // Signature 236 - .long 0 // Unknown 237 - .long 0 // Unknown2 238 - .long 0 // Unknown3 239 - 240 - .asciz VMLINUX_PATH 241 - 242 - .set efi_debug_entry_size, . - efi_debug_entry 243 - #endif 244 - 245 - /* 246 - * EFI will load .text onwards at the 4k section alignment 247 - * described in the PE/COFF header. To ensure that instruction 248 - * sequences using an adrp and a :lo12: immediate will function 249 - * correctly at this alignment, we must ensure that .text is 250 - * placed at a 4k boundary in the Image to begin with. 251 - */ 252 - .align 12 253 - efi_header_end: 97 + __EFI_PE_HEADER 98 + #else 99 + .long 0 // reserved 254 100 #endif 255 101 256 102 __INIT ··· 384 534 ENTRY(el2_setup) 385 535 mrs x0, CurrentEL 386 536 cmp x0, #CurrentEL_EL2 387 - b.ne 1f 388 - mrs x0, sctlr_el2 389 - CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2 390 - CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 391 - msr sctlr_el2, x0 392 - b 2f 393 - 1: mrs x0, sctlr_el1 537 + b.eq 1f 538 + mrs x0, sctlr_el1 394 539 CPU_BE( orr x0, x0, #(3 << 24) ) // Set the EE and E0E bits for EL1 395 540 CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1 396 541 msr sctlr_el1, x0 ··· 393 548 isb 394 549 ret 395 550 396 - 2: 551 + 1: mrs x0, sctlr_el2 552 + CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2 553 + CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 554 + msr sctlr_el2, x0 555 + 397 556 #ifdef CONFIG_ARM64_VHE 398 557 /* 399 558 * Check for VHE being present. For the rest of the EL2 setup, ··· 443 594 cmp x0, #1 444 595 b.ne 3f 445 596 446 - mrs_s x0, ICC_SRE_EL2 597 + mrs_s x0, SYS_ICC_SRE_EL2 447 598 orr x0, x0, #ICC_SRE_EL2_SRE // Set ICC_SRE_EL2.SRE==1 448 599 orr x0, x0, #ICC_SRE_EL2_ENABLE // Set ICC_SRE_EL2.Enable==1 449 - msr_s ICC_SRE_EL2, x0 600 + msr_s SYS_ICC_SRE_EL2, x0 450 601 isb // Make sure SRE is now set 451 - mrs_s x0, ICC_SRE_EL2 // Read SRE back, 602 + mrs_s x0, SYS_ICC_SRE_EL2 // Read SRE back, 452 603 tbz x0, #0, 3f // and check that it sticks 453 - msr_s ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults 604 + msr_s SYS_ICH_HCR_EL2, xzr // Reset ICC_HCR_EL2 to defaults 454 605 455 606 3: 456 607 #endif ··· 460 611 mrs x1, mpidr_el1 461 612 msr vpidr_el2, x0 462 613 msr vmpidr_el2, x1 463 - 464 - /* 465 - * When VHE is not in use, early init of EL2 and EL1 needs to be 466 - * done here. 467 - * When VHE _is_ in use, EL1 will not be used in the host and 468 - * requires no configuration, and all non-hyp-specific EL2 setup 469 - * will be done via the _EL1 system register aliases in __cpu_setup. 470 - */ 471 - cbnz x2, 1f 472 - 473 - /* sctlr_el1 */ 474 - mov x0, #0x0800 // Set/clear RES{1,0} bits 475 - CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems 476 - CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems 477 - msr sctlr_el1, x0 478 - 479 - /* Coprocessor traps. */ 480 - mov x0, #0x33ff 481 - msr cptr_el2, x0 // Disable copro. traps to EL2 482 - 1: 483 614 484 615 #ifdef CONFIG_COMPAT 485 616 msr hstr_el2, xzr // Disable CP15 traps to EL2 ··· 497 668 ret 498 669 499 670 install_el2_stub: 671 + /* 672 + * When VHE is not in use, early init of EL2 and EL1 needs to be 673 + * done here. 674 + * When VHE _is_ in use, EL1 will not be used in the host and 675 + * requires no configuration, and all non-hyp-specific EL2 setup 676 + * will be done via the _EL1 system register aliases in __cpu_setup. 677 + */ 678 + /* sctlr_el1 */ 679 + mov x0, #0x0800 // Set/clear RES{1,0} bits 680 + CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems 681 + CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems 682 + msr sctlr_el1, x0 683 + 684 + /* Coprocessor traps. */ 685 + mov x0, #0x33ff 686 + msr cptr_el2, x0 // Disable copro. traps to EL2 687 + 500 688 /* Hypervisor stub */ 501 689 adr_l x0, __hyp_stub_vectors 502 690 msr vbar_el2, x0
+9 -1
arch/arm64/kernel/hibernate.c
··· 28 28 #include <asm/cacheflush.h> 29 29 #include <asm/cputype.h> 30 30 #include <asm/irqflags.h> 31 + #include <asm/kexec.h> 31 32 #include <asm/memory.h> 32 33 #include <asm/mmu_context.h> 33 34 #include <asm/pgalloc.h> ··· 103 102 unsigned long nosave_begin_pfn = sym_to_pfn(&__nosave_begin); 104 103 unsigned long nosave_end_pfn = sym_to_pfn(&__nosave_end - 1); 105 104 106 - return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn); 105 + return ((pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn)) || 106 + crash_is_nosave(pfn); 107 107 } 108 108 109 109 void notrace save_processor_state(void) ··· 288 286 local_dbg_save(flags); 289 287 290 288 if (__cpu_suspend_enter(&state)) { 289 + /* make the crash dump kernel image visible/saveable */ 290 + crash_prepare_suspend(); 291 + 291 292 sleep_cpu = smp_processor_id(); 292 293 ret = swsusp_save(); 293 294 } else { ··· 301 296 /* Clean kvm setup code to PoC? */ 302 297 if (el2_reset_needed()) 303 298 dcache_clean_range(__hyp_idmap_text_start, __hyp_idmap_text_end); 299 + 300 + /* make the crash dump kernel image protected again */ 301 + crash_post_resume(); 304 302 305 303 /* 306 304 * Tell the hibernation core that we've just restored
+161 -9
arch/arm64/kernel/machine_kexec.c
··· 9 9 * published by the Free Software Foundation. 10 10 */ 11 11 12 + #include <linux/interrupt.h> 13 + #include <linux/irq.h> 14 + #include <linux/kernel.h> 12 15 #include <linux/kexec.h> 16 + #include <linux/page-flags.h> 13 17 #include <linux/smp.h> 14 18 15 19 #include <asm/cacheflush.h> 16 20 #include <asm/cpu_ops.h> 21 + #include <asm/memory.h> 22 + #include <asm/mmu.h> 17 23 #include <asm/mmu_context.h> 24 + #include <asm/page.h> 18 25 19 26 #include "cpu-reset.h" 20 27 21 28 /* Global variables for the arm64_relocate_new_kernel routine. */ 22 29 extern const unsigned char arm64_relocate_new_kernel[]; 23 30 extern const unsigned long arm64_relocate_new_kernel_size; 24 - 25 - static unsigned long kimage_start; 26 31 27 32 /** 28 33 * kexec_image_info - For debugging output. ··· 69 64 */ 70 65 int machine_kexec_prepare(struct kimage *kimage) 71 66 { 72 - kimage_start = kimage->start; 73 - 74 67 kexec_image_info(kimage); 75 68 76 69 if (kimage->type != KEXEC_TYPE_CRASH && cpus_are_stuck_in_kernel()) { ··· 147 144 { 148 145 phys_addr_t reboot_code_buffer_phys; 149 146 void *reboot_code_buffer; 147 + bool in_kexec_crash = (kimage == kexec_crash_image); 148 + bool stuck_cpus = cpus_are_stuck_in_kernel(); 150 149 151 150 /* 152 151 * New cpus may have become stuck_in_kernel after we loaded the image. 153 152 */ 154 - BUG_ON(cpus_are_stuck_in_kernel() || (num_online_cpus() > 1)); 153 + BUG_ON(!in_kexec_crash && (stuck_cpus || (num_online_cpus() > 1))); 154 + WARN(in_kexec_crash && (stuck_cpus || smp_crash_stop_failed()), 155 + "Some CPUs may be stale, kdump will be unreliable.\n"); 155 156 156 157 reboot_code_buffer_phys = page_to_phys(kimage->control_code_page); 157 158 reboot_code_buffer = phys_to_virt(reboot_code_buffer_phys); ··· 190 183 kexec_list_flush(kimage); 191 184 192 185 /* Flush the new image if already in place. */ 193 - if (kimage->head & IND_DONE) 186 + if ((kimage != kexec_crash_image) && (kimage->head & IND_DONE)) 194 187 kexec_segment_flush(kimage); 195 188 196 189 pr_info("Bye!\n"); ··· 207 200 * relocation is complete. 208 201 */ 209 202 210 - cpu_soft_restart(1, reboot_code_buffer_phys, kimage->head, 211 - kimage_start, 0); 203 + cpu_soft_restart(kimage != kexec_crash_image, 204 + reboot_code_buffer_phys, kimage->head, kimage->start, 0); 212 205 213 206 BUG(); /* Should never get here. */ 214 207 } 215 208 209 + static void machine_kexec_mask_interrupts(void) 210 + { 211 + unsigned int i; 212 + struct irq_desc *desc; 213 + 214 + for_each_irq_desc(i, desc) { 215 + struct irq_chip *chip; 216 + int ret; 217 + 218 + chip = irq_desc_get_chip(desc); 219 + if (!chip) 220 + continue; 221 + 222 + /* 223 + * First try to remove the active state. If this 224 + * fails, try to EOI the interrupt. 225 + */ 226 + ret = irq_set_irqchip_state(i, IRQCHIP_STATE_ACTIVE, false); 227 + 228 + if (ret && irqd_irq_inprogress(&desc->irq_data) && 229 + chip->irq_eoi) 230 + chip->irq_eoi(&desc->irq_data); 231 + 232 + if (chip->irq_mask) 233 + chip->irq_mask(&desc->irq_data); 234 + 235 + if (chip->irq_disable && !irqd_irq_disabled(&desc->irq_data)) 236 + chip->irq_disable(&desc->irq_data); 237 + } 238 + } 239 + 240 + /** 241 + * machine_crash_shutdown - shutdown non-crashing cpus and save registers 242 + */ 216 243 void machine_crash_shutdown(struct pt_regs *regs) 217 244 { 218 - /* Empty routine needed to avoid build errors. */ 245 + local_irq_disable(); 246 + 247 + /* shutdown non-crashing cpus */ 248 + smp_send_crash_stop(); 249 + 250 + /* for crashing cpu */ 251 + crash_save_cpu(regs, smp_processor_id()); 252 + machine_kexec_mask_interrupts(); 253 + 254 + pr_info("Starting crashdump kernel...\n"); 255 + } 256 + 257 + void arch_kexec_protect_crashkres(void) 258 + { 259 + int i; 260 + 261 + kexec_segment_flush(kexec_crash_image); 262 + 263 + for (i = 0; i < kexec_crash_image->nr_segments; i++) 264 + set_memory_valid( 265 + __phys_to_virt(kexec_crash_image->segment[i].mem), 266 + kexec_crash_image->segment[i].memsz >> PAGE_SHIFT, 0); 267 + } 268 + 269 + void arch_kexec_unprotect_crashkres(void) 270 + { 271 + int i; 272 + 273 + for (i = 0; i < kexec_crash_image->nr_segments; i++) 274 + set_memory_valid( 275 + __phys_to_virt(kexec_crash_image->segment[i].mem), 276 + kexec_crash_image->segment[i].memsz >> PAGE_SHIFT, 1); 277 + } 278 + 279 + #ifdef CONFIG_HIBERNATION 280 + /* 281 + * To preserve the crash dump kernel image, the relevant memory segments 282 + * should be mapped again around the hibernation. 283 + */ 284 + void crash_prepare_suspend(void) 285 + { 286 + if (kexec_crash_image) 287 + arch_kexec_unprotect_crashkres(); 288 + } 289 + 290 + void crash_post_resume(void) 291 + { 292 + if (kexec_crash_image) 293 + arch_kexec_protect_crashkres(); 294 + } 295 + 296 + /* 297 + * crash_is_nosave 298 + * 299 + * Return true only if a page is part of reserved memory for crash dump kernel, 300 + * but does not hold any data of loaded kernel image. 301 + * 302 + * Note that all the pages in crash dump kernel memory have been initially 303 + * marked as Reserved in kexec_reserve_crashkres_pages(). 304 + * 305 + * In hibernation, the pages which are Reserved and yet "nosave" are excluded 306 + * from the hibernation iamge. crash_is_nosave() does thich check for crash 307 + * dump kernel and will reduce the total size of hibernation image. 308 + */ 309 + 310 + bool crash_is_nosave(unsigned long pfn) 311 + { 312 + int i; 313 + phys_addr_t addr; 314 + 315 + if (!crashk_res.end) 316 + return false; 317 + 318 + /* in reserved memory? */ 319 + addr = __pfn_to_phys(pfn); 320 + if ((addr < crashk_res.start) || (crashk_res.end < addr)) 321 + return false; 322 + 323 + if (!kexec_crash_image) 324 + return true; 325 + 326 + /* not part of loaded kernel image? */ 327 + for (i = 0; i < kexec_crash_image->nr_segments; i++) 328 + if (addr >= kexec_crash_image->segment[i].mem && 329 + addr < (kexec_crash_image->segment[i].mem + 330 + kexec_crash_image->segment[i].memsz)) 331 + return false; 332 + 333 + return true; 334 + } 335 + 336 + void crash_free_reserved_phys_range(unsigned long begin, unsigned long end) 337 + { 338 + unsigned long addr; 339 + struct page *page; 340 + 341 + for (addr = begin; addr < end; addr += PAGE_SIZE) { 342 + page = phys_to_page(addr); 343 + ClearPageReserved(page); 344 + free_reserved_page(page); 345 + } 346 + } 347 + #endif /* CONFIG_HIBERNATION */ 348 + 349 + void arch_crash_save_vmcoreinfo(void) 350 + { 351 + VMCOREINFO_NUMBER(VA_BITS); 352 + /* Please note VMCOREINFO_NUMBER() uses "%d", not "%x" */ 353 + vmcoreinfo_append_str("NUMBER(kimage_voffset)=0x%llx\n", 354 + kimage_voffset); 355 + vmcoreinfo_append_str("NUMBER(PHYS_OFFSET)=0x%llx\n", 356 + PHYS_OFFSET); 219 357 }
+63 -45
arch/arm64/kernel/module-plts.c
··· 1 1 /* 2 - * Copyright (C) 2014-2016 Linaro Ltd. <ard.biesheuvel@linaro.org> 2 + * Copyright (C) 2014-2017 Linaro Ltd. <ard.biesheuvel@linaro.org> 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License version 2 as ··· 26 26 __le32 br; /* br x16 */ 27 27 }; 28 28 29 - u64 module_emit_plt_entry(struct module *mod, const Elf64_Rela *rela, 29 + static bool in_init(const struct module *mod, void *loc) 30 + { 31 + return (u64)loc - (u64)mod->init_layout.base < mod->init_layout.size; 32 + } 33 + 34 + u64 module_emit_plt_entry(struct module *mod, void *loc, const Elf64_Rela *rela, 30 35 Elf64_Sym *sym) 31 36 { 32 - struct plt_entry *plt = (struct plt_entry *)mod->arch.plt->sh_addr; 33 - int i = mod->arch.plt_num_entries; 37 + struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core : 38 + &mod->arch.init; 39 + struct plt_entry *plt = (struct plt_entry *)pltsec->plt->sh_addr; 40 + int i = pltsec->plt_num_entries; 34 41 u64 val = sym->st_value + rela->r_addend; 35 - 36 - /* 37 - * We only emit PLT entries against undefined (SHN_UNDEF) symbols, 38 - * which are listed in the ELF symtab section, but without a type 39 - * or a size. 40 - * So, similar to how the module loader uses the Elf64_Sym::st_value 41 - * field to store the resolved addresses of undefined symbols, let's 42 - * borrow the Elf64_Sym::st_size field (whose value is never used by 43 - * the module loader, even for symbols that are defined) to record 44 - * the address of a symbol's associated PLT entry as we emit it for a 45 - * zero addend relocation (which is the only kind we have to deal with 46 - * in practice). This allows us to find duplicates without having to 47 - * go through the table every time. 48 - */ 49 - if (rela->r_addend == 0 && sym->st_size != 0) { 50 - BUG_ON(sym->st_size < (u64)plt || sym->st_size >= (u64)&plt[i]); 51 - return sym->st_size; 52 - } 53 - 54 - mod->arch.plt_num_entries++; 55 - BUG_ON(mod->arch.plt_num_entries > mod->arch.plt_max_entries); 56 42 57 43 /* 58 44 * MOVK/MOVN/MOVZ opcode: ··· 58 72 cpu_to_le32(0xd61f0200) 59 73 }; 60 74 61 - if (rela->r_addend == 0) 62 - sym->st_size = (u64)&plt[i]; 75 + /* 76 + * Check if the entry we just created is a duplicate. Given that the 77 + * relocations are sorted, this will be the last entry we allocated. 78 + * (if one exists). 79 + */ 80 + if (i > 0 && 81 + plt[i].mov0 == plt[i - 1].mov0 && 82 + plt[i].mov1 == plt[i - 1].mov1 && 83 + plt[i].mov2 == plt[i - 1].mov2) 84 + return (u64)&plt[i - 1]; 85 + 86 + pltsec->plt_num_entries++; 87 + BUG_ON(pltsec->plt_num_entries > pltsec->plt_max_entries); 63 88 64 89 return (u64)&plt[i]; 65 90 } ··· 101 104 return num > 0 && cmp_rela(rela + num, rela + num - 1) == 0; 102 105 } 103 106 104 - static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int num) 107 + static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int num, 108 + Elf64_Word dstidx) 105 109 { 106 110 unsigned int ret = 0; 107 111 Elf64_Sym *s; ··· 114 116 case R_AARCH64_CALL26: 115 117 /* 116 118 * We only have to consider branch targets that resolve 117 - * to undefined symbols. This is not simply a heuristic, 118 - * it is a fundamental limitation, since the PLT itself 119 - * is part of the module, and needs to be within 128 MB 120 - * as well, so modules can never grow beyond that limit. 119 + * to symbols that are defined in a different section. 120 + * This is not simply a heuristic, it is a fundamental 121 + * limitation, since there is no guaranteed way to emit 122 + * PLT entries sufficiently close to the branch if the 123 + * section size exceeds the range of a branch 124 + * instruction. So ignore relocations against defined 125 + * symbols if they live in the same section as the 126 + * relocation target. 121 127 */ 122 128 s = syms + ELF64_R_SYM(rela[i].r_info); 123 - if (s->st_shndx != SHN_UNDEF) 129 + if (s->st_shndx == dstidx) 124 130 break; 125 131 126 132 /* ··· 151 149 int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, 152 150 char *secstrings, struct module *mod) 153 151 { 154 - unsigned long plt_max_entries = 0; 152 + unsigned long core_plts = 0; 153 + unsigned long init_plts = 0; 155 154 Elf64_Sym *syms = NULL; 156 155 int i; 157 156 ··· 161 158 * entries. Record the symtab address as well. 162 159 */ 163 160 for (i = 0; i < ehdr->e_shnum; i++) { 164 - if (strcmp(".plt", secstrings + sechdrs[i].sh_name) == 0) 165 - mod->arch.plt = sechdrs + i; 161 + if (!strcmp(secstrings + sechdrs[i].sh_name, ".plt")) 162 + mod->arch.core.plt = sechdrs + i; 163 + else if (!strcmp(secstrings + sechdrs[i].sh_name, ".init.plt")) 164 + mod->arch.init.plt = sechdrs + i; 166 165 else if (sechdrs[i].sh_type == SHT_SYMTAB) 167 166 syms = (Elf64_Sym *)sechdrs[i].sh_addr; 168 167 } 169 168 170 - if (!mod->arch.plt) { 171 - pr_err("%s: module PLT section missing\n", mod->name); 169 + if (!mod->arch.core.plt || !mod->arch.init.plt) { 170 + pr_err("%s: module PLT section(s) missing\n", mod->name); 172 171 return -ENOEXEC; 173 172 } 174 173 if (!syms) { ··· 193 188 /* sort by type, symbol index and addend */ 194 189 sort(rels, numrels, sizeof(Elf64_Rela), cmp_rela, NULL); 195 190 196 - plt_max_entries += count_plts(syms, rels, numrels); 191 + if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0) 192 + core_plts += count_plts(syms, rels, numrels, 193 + sechdrs[i].sh_info); 194 + else 195 + init_plts += count_plts(syms, rels, numrels, 196 + sechdrs[i].sh_info); 197 197 } 198 198 199 - mod->arch.plt->sh_type = SHT_NOBITS; 200 - mod->arch.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; 201 - mod->arch.plt->sh_addralign = L1_CACHE_BYTES; 202 - mod->arch.plt->sh_size = plt_max_entries * sizeof(struct plt_entry); 203 - mod->arch.plt_num_entries = 0; 204 - mod->arch.plt_max_entries = plt_max_entries; 199 + mod->arch.core.plt->sh_type = SHT_NOBITS; 200 + mod->arch.core.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; 201 + mod->arch.core.plt->sh_addralign = L1_CACHE_BYTES; 202 + mod->arch.core.plt->sh_size = (core_plts + 1) * sizeof(struct plt_entry); 203 + mod->arch.core.plt_num_entries = 0; 204 + mod->arch.core.plt_max_entries = core_plts; 205 + 206 + mod->arch.init.plt->sh_type = SHT_NOBITS; 207 + mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; 208 + mod->arch.init.plt->sh_addralign = L1_CACHE_BYTES; 209 + mod->arch.init.plt->sh_size = (init_plts + 1) * sizeof(struct plt_entry); 210 + mod->arch.init.plt_num_entries = 0; 211 + mod->arch.init.plt_max_entries = init_plts; 212 + 205 213 return 0; 206 214 }
+1 -1
arch/arm64/kernel/module.c
··· 380 380 381 381 if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && 382 382 ovf == -ERANGE) { 383 - val = module_emit_plt_entry(me, &rel[i], sym); 383 + val = module_emit_plt_entry(me, loc, &rel[i], sym); 384 384 ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 385 385 26, AARCH64_INSN_IMM_26); 386 386 }
+1
arch/arm64/kernel/module.lds
··· 1 1 SECTIONS { 2 2 .plt (NOLOAD) : { BYTE(0) } 3 + .init.plt (NOLOAD) : { BYTE(0) } 3 4 }
+87 -33
arch/arm64/kernel/perf_event.c
··· 290 290 [C(L1I)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L1I_CACHE, 291 291 [C(L1I)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1I_CACHE_REFILL, 292 292 293 + [C(LL)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L2D_CACHE, 294 + [C(LL)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L2D_CACHE_REFILL, 295 + [C(LL)][C(OP_WRITE)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_L2D_CACHE, 296 + [C(LL)][C(OP_WRITE)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L2D_CACHE_REFILL, 297 + 298 + [C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1D_TLB_REFILL, 293 299 [C(ITLB)][C(OP_READ)][C(RESULT_MISS)] = ARMV8_PMUV3_PERFCTR_L1I_TLB_REFILL, 294 300 295 301 [C(BPU)][C(OP_READ)][C(RESULT_ACCESS)] = ARMV8_PMUV3_PERFCTR_BR_PRED, ··· 963 957 ARMV8_PMU_EVTYPE_EVENT); 964 958 } 965 959 960 + struct armv8pmu_probe_info { 961 + struct arm_pmu *pmu; 962 + bool present; 963 + }; 964 + 966 965 static void __armv8pmu_probe_pmu(void *info) 967 966 { 968 - struct arm_pmu *cpu_pmu = info; 967 + struct armv8pmu_probe_info *probe = info; 968 + struct arm_pmu *cpu_pmu = probe->pmu; 969 + u64 dfr0; 969 970 u32 pmceid[2]; 971 + int pmuver; 972 + 973 + dfr0 = read_sysreg(id_aa64dfr0_el1); 974 + pmuver = cpuid_feature_extract_signed_field(dfr0, 975 + ID_AA64DFR0_PMUVER_SHIFT); 976 + if (pmuver < 1) 977 + return; 978 + 979 + probe->present = true; 970 980 971 981 /* Read the nb of CNTx counters supported from PMNC */ 972 982 cpu_pmu->num_events = (armv8pmu_pmcr_read() >> ARMV8_PMU_PMCR_N_SHIFT) ··· 1001 979 1002 980 static int armv8pmu_probe_pmu(struct arm_pmu *cpu_pmu) 1003 981 { 1004 - return smp_call_function_any(&cpu_pmu->supported_cpus, 982 + struct armv8pmu_probe_info probe = { 983 + .pmu = cpu_pmu, 984 + .present = false, 985 + }; 986 + int ret; 987 + 988 + ret = smp_call_function_any(&cpu_pmu->supported_cpus, 1005 989 __armv8pmu_probe_pmu, 1006 - cpu_pmu, 1); 990 + &probe, 1); 991 + if (ret) 992 + return ret; 993 + 994 + return probe.present ? 0 : -ENODEV; 1007 995 } 1008 996 1009 - static void armv8_pmu_init(struct arm_pmu *cpu_pmu) 997 + static int armv8_pmu_init(struct arm_pmu *cpu_pmu) 1010 998 { 999 + int ret = armv8pmu_probe_pmu(cpu_pmu); 1000 + if (ret) 1001 + return ret; 1002 + 1011 1003 cpu_pmu->handle_irq = armv8pmu_handle_irq, 1012 1004 cpu_pmu->enable = armv8pmu_enable_event, 1013 1005 cpu_pmu->disable = armv8pmu_disable_event, ··· 1033 997 cpu_pmu->reset = armv8pmu_reset, 1034 998 cpu_pmu->max_period = (1LLU << 32) - 1, 1035 999 cpu_pmu->set_event_filter = armv8pmu_set_event_filter; 1000 + 1001 + return 0; 1036 1002 } 1037 1003 1038 1004 static int armv8_pmuv3_init(struct arm_pmu *cpu_pmu) 1039 1005 { 1040 - armv8_pmu_init(cpu_pmu); 1006 + int ret = armv8_pmu_init(cpu_pmu); 1007 + if (ret) 1008 + return ret; 1009 + 1041 1010 cpu_pmu->name = "armv8_pmuv3"; 1042 1011 cpu_pmu->map_event = armv8_pmuv3_map_event; 1043 1012 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1044 1013 &armv8_pmuv3_events_attr_group; 1045 1014 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1046 1015 &armv8_pmuv3_format_attr_group; 1047 - return armv8pmu_probe_pmu(cpu_pmu); 1016 + 1017 + return 0; 1048 1018 } 1049 1019 1050 1020 static int armv8_a53_pmu_init(struct arm_pmu *cpu_pmu) 1051 1021 { 1052 - armv8_pmu_init(cpu_pmu); 1022 + int ret = armv8_pmu_init(cpu_pmu); 1023 + if (ret) 1024 + return ret; 1025 + 1053 1026 cpu_pmu->name = "armv8_cortex_a53"; 1054 1027 cpu_pmu->map_event = armv8_a53_map_event; 1055 1028 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1056 1029 &armv8_pmuv3_events_attr_group; 1057 1030 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1058 1031 &armv8_pmuv3_format_attr_group; 1059 - return armv8pmu_probe_pmu(cpu_pmu); 1032 + 1033 + return 0; 1060 1034 } 1061 1035 1062 1036 static int armv8_a57_pmu_init(struct arm_pmu *cpu_pmu) 1063 1037 { 1064 - armv8_pmu_init(cpu_pmu); 1038 + int ret = armv8_pmu_init(cpu_pmu); 1039 + if (ret) 1040 + return ret; 1041 + 1065 1042 cpu_pmu->name = "armv8_cortex_a57"; 1066 1043 cpu_pmu->map_event = armv8_a57_map_event; 1067 1044 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1068 1045 &armv8_pmuv3_events_attr_group; 1069 1046 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1070 1047 &armv8_pmuv3_format_attr_group; 1071 - return armv8pmu_probe_pmu(cpu_pmu); 1048 + 1049 + return 0; 1072 1050 } 1073 1051 1074 1052 static int armv8_a72_pmu_init(struct arm_pmu *cpu_pmu) 1075 1053 { 1076 - armv8_pmu_init(cpu_pmu); 1054 + int ret = armv8_pmu_init(cpu_pmu); 1055 + if (ret) 1056 + return ret; 1057 + 1077 1058 cpu_pmu->name = "armv8_cortex_a72"; 1078 1059 cpu_pmu->map_event = armv8_a57_map_event; 1079 1060 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1080 1061 &armv8_pmuv3_events_attr_group; 1081 1062 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1082 1063 &armv8_pmuv3_format_attr_group; 1083 - return armv8pmu_probe_pmu(cpu_pmu); 1064 + 1065 + return 0; 1084 1066 } 1085 1067 1086 1068 static int armv8_thunder_pmu_init(struct arm_pmu *cpu_pmu) 1087 1069 { 1088 - armv8_pmu_init(cpu_pmu); 1070 + int ret = armv8_pmu_init(cpu_pmu); 1071 + if (ret) 1072 + return ret; 1073 + 1089 1074 cpu_pmu->name = "armv8_cavium_thunder"; 1090 1075 cpu_pmu->map_event = armv8_thunder_map_event; 1091 1076 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1092 1077 &armv8_pmuv3_events_attr_group; 1093 1078 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1094 1079 &armv8_pmuv3_format_attr_group; 1095 - return armv8pmu_probe_pmu(cpu_pmu); 1080 + 1081 + return 0; 1096 1082 } 1097 1083 1098 1084 static int armv8_vulcan_pmu_init(struct arm_pmu *cpu_pmu) 1099 1085 { 1100 - armv8_pmu_init(cpu_pmu); 1086 + int ret = armv8_pmu_init(cpu_pmu); 1087 + if (ret) 1088 + return ret; 1089 + 1101 1090 cpu_pmu->name = "armv8_brcm_vulcan"; 1102 1091 cpu_pmu->map_event = armv8_vulcan_map_event; 1103 1092 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = 1104 1093 &armv8_pmuv3_events_attr_group; 1105 1094 cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_FORMATS] = 1106 1095 &armv8_pmuv3_format_attr_group; 1107 - return armv8pmu_probe_pmu(cpu_pmu); 1096 + 1097 + return 0; 1108 1098 } 1109 1099 1110 1100 static const struct of_device_id armv8_pmu_of_device_ids[] = { ··· 1143 1081 {}, 1144 1082 }; 1145 1083 1146 - /* 1147 - * Non DT systems have their micro/arch events probed at run-time. 1148 - * A fairly complete list of generic events are provided and ones that 1149 - * aren't supported by the current PMU are disabled. 1150 - */ 1151 - static const struct pmu_probe_info armv8_pmu_probe_table[] = { 1152 - PMU_PROBE(0, 0, armv8_pmuv3_init), /* enable all defined counters */ 1153 - { /* sentinel value */ } 1154 - }; 1155 - 1156 1084 static int armv8_pmu_device_probe(struct platform_device *pdev) 1157 1085 { 1158 - if (acpi_disabled) 1159 - return arm_pmu_device_probe(pdev, armv8_pmu_of_device_ids, 1160 - NULL); 1161 - 1162 - return arm_pmu_device_probe(pdev, armv8_pmu_of_device_ids, 1163 - armv8_pmu_probe_table); 1086 + return arm_pmu_device_probe(pdev, armv8_pmu_of_device_ids, NULL); 1164 1087 } 1165 1088 1166 1089 static struct platform_driver armv8_pmu_driver = { ··· 1156 1109 .probe = armv8_pmu_device_probe, 1157 1110 }; 1158 1111 1159 - builtin_platform_driver(armv8_pmu_driver); 1112 + static int __init armv8_pmu_driver_init(void) 1113 + { 1114 + if (acpi_disabled) 1115 + return platform_driver_register(&armv8_pmu_driver); 1116 + else 1117 + return arm_pmu_acpi_probe(armv8_pmuv3_init); 1118 + } 1119 + device_initcall(armv8_pmu_driver_init)
-2
arch/arm64/kernel/process.c
··· 205 205 206 206 pr_cont("\n"); 207 207 } 208 - printk("\n"); 209 208 } 210 209 211 210 void show_regs(struct pt_regs * regs) 212 211 { 213 - printk("\n"); 214 212 __show_regs(regs); 215 213 } 216 214
+81
arch/arm64/kernel/reloc_test_core.c
··· 1 + /* 2 + * Copyright (C) 2017 Linaro, Ltd. <ard.biesheuvel@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + */ 9 + 10 + #include <linux/module.h> 11 + 12 + int sym64_rel; 13 + 14 + #define SYM64_ABS_VAL 0xffff880000cccccc 15 + #define SYM32_ABS_VAL 0xf800cccc 16 + #define SYM16_ABS_VAL 0xf8cc 17 + 18 + #define __SET_ABS(name, val) asm(".globl " #name "; .set "#name ", " #val) 19 + #define SET_ABS(name, val) __SET_ABS(name, val) 20 + 21 + SET_ABS(sym64_abs, SYM64_ABS_VAL); 22 + SET_ABS(sym32_abs, SYM32_ABS_VAL); 23 + SET_ABS(sym16_abs, SYM16_ABS_VAL); 24 + 25 + asmlinkage u64 absolute_data64(void); 26 + asmlinkage u64 absolute_data32(void); 27 + asmlinkage u64 absolute_data16(void); 28 + asmlinkage u64 signed_movw(void); 29 + asmlinkage u64 unsigned_movw(void); 30 + asmlinkage u64 relative_adrp(void); 31 + asmlinkage u64 relative_adr(void); 32 + asmlinkage u64 relative_data64(void); 33 + asmlinkage u64 relative_data32(void); 34 + asmlinkage u64 relative_data16(void); 35 + 36 + static struct { 37 + char name[32]; 38 + u64 (*f)(void); 39 + u64 expect; 40 + } const funcs[] = { 41 + { "R_AARCH64_ABS64", absolute_data64, UL(SYM64_ABS_VAL) }, 42 + { "R_AARCH64_ABS32", absolute_data32, UL(SYM32_ABS_VAL) }, 43 + { "R_AARCH64_ABS16", absolute_data16, UL(SYM16_ABS_VAL) }, 44 + { "R_AARCH64_MOVW_SABS_Gn", signed_movw, UL(SYM64_ABS_VAL) }, 45 + { "R_AARCH64_MOVW_UABS_Gn", unsigned_movw, UL(SYM64_ABS_VAL) }, 46 + #ifndef CONFIG_ARM64_ERRATUM_843419 47 + { "R_AARCH64_ADR_PREL_PG_HI21", relative_adrp, (u64)&sym64_rel }, 48 + #endif 49 + { "R_AARCH64_ADR_PREL_LO21", relative_adr, (u64)&sym64_rel }, 50 + { "R_AARCH64_PREL64", relative_data64, (u64)&sym64_rel }, 51 + { "R_AARCH64_PREL32", relative_data32, (u64)&sym64_rel }, 52 + { "R_AARCH64_PREL16", relative_data16, (u64)&sym64_rel }, 53 + }; 54 + 55 + static int reloc_test_init(void) 56 + { 57 + int i; 58 + 59 + pr_info("Relocation test:\n"); 60 + pr_info("-------------------------------------------------------\n"); 61 + 62 + for (i = 0; i < ARRAY_SIZE(funcs); i++) { 63 + u64 ret = funcs[i].f(); 64 + 65 + pr_info("%-31s 0x%016llx %s\n", funcs[i].name, ret, 66 + ret == funcs[i].expect ? "pass" : "fail"); 67 + if (ret != funcs[i].expect) 68 + pr_err("Relocation failed, expected 0x%016llx, not 0x%016llx\n", 69 + funcs[i].expect, ret); 70 + } 71 + return 0; 72 + } 73 + 74 + static void reloc_test_exit(void) 75 + { 76 + } 77 + 78 + module_init(reloc_test_init); 79 + module_exit(reloc_test_exit); 80 + 81 + MODULE_LICENSE("GPL v2");
+83
arch/arm64/kernel/reloc_test_syms.S
··· 1 + /* 2 + * Copyright (C) 2017 Linaro, Ltd. <ard.biesheuvel@linaro.org> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + */ 9 + 10 + #include <linux/linkage.h> 11 + 12 + ENTRY(absolute_data64) 13 + ldr x0, 0f 14 + ret 15 + 0: .quad sym64_abs 16 + ENDPROC(absolute_data64) 17 + 18 + ENTRY(absolute_data32) 19 + ldr w0, 0f 20 + ret 21 + 0: .long sym32_abs 22 + ENDPROC(absolute_data32) 23 + 24 + ENTRY(absolute_data16) 25 + adr x0, 0f 26 + ldrh w0, [x0] 27 + ret 28 + 0: .short sym16_abs, 0 29 + ENDPROC(absolute_data16) 30 + 31 + ENTRY(signed_movw) 32 + movz x0, #:abs_g2_s:sym64_abs 33 + movk x0, #:abs_g1_nc:sym64_abs 34 + movk x0, #:abs_g0_nc:sym64_abs 35 + ret 36 + ENDPROC(signed_movw) 37 + 38 + ENTRY(unsigned_movw) 39 + movz x0, #:abs_g3:sym64_abs 40 + movk x0, #:abs_g2_nc:sym64_abs 41 + movk x0, #:abs_g1_nc:sym64_abs 42 + movk x0, #:abs_g0_nc:sym64_abs 43 + ret 44 + ENDPROC(unsigned_movw) 45 + 46 + #ifndef CONFIG_ARM64_ERRATUM_843419 47 + 48 + ENTRY(relative_adrp) 49 + adrp x0, sym64_rel 50 + add x0, x0, #:lo12:sym64_rel 51 + ret 52 + ENDPROC(relative_adrp) 53 + 54 + #endif 55 + 56 + ENTRY(relative_adr) 57 + adr x0, sym64_rel 58 + ret 59 + ENDPROC(relative_adr) 60 + 61 + ENTRY(relative_data64) 62 + adr x1, 0f 63 + ldr x0, [x1] 64 + add x0, x0, x1 65 + ret 66 + 0: .quad sym64_rel - . 67 + ENDPROC(relative_data64) 68 + 69 + ENTRY(relative_data32) 70 + adr x1, 0f 71 + ldr w0, [x1] 72 + add x0, x0, x1 73 + ret 74 + 0: .long sym64_rel - . 75 + ENDPROC(relative_data32) 76 + 77 + ENTRY(relative_data16) 78 + adr x1, 0f 79 + ldrsh w0, [x1] 80 + add x0, x0, x1 81 + ret 82 + 0: .short sym64_rel - ., 0 83 + ENDPROC(relative_data16)
+10 -2
arch/arm64/kernel/setup.c
··· 31 31 #include <linux/screen_info.h> 32 32 #include <linux/init.h> 33 33 #include <linux/kexec.h> 34 - #include <linux/crash_dump.h> 35 34 #include <linux/root_dev.h> 36 35 #include <linux/cpu.h> 37 36 #include <linux/interrupt.h> ··· 180 181 static void __init setup_machine_fdt(phys_addr_t dt_phys) 181 182 { 182 183 void *dt_virt = fixmap_remap_fdt(dt_phys); 184 + const char *name; 183 185 184 186 if (!dt_virt || !early_init_dt_scan(dt_virt)) { 185 187 pr_crit("\n" ··· 193 193 cpu_relax(); 194 194 } 195 195 196 - dump_stack_set_arch_desc("%s (DT)", of_flat_dt_get_machine_name()); 196 + name = of_flat_dt_get_machine_name(); 197 + pr_info("Machine model: %s\n", name); 198 + dump_stack_set_arch_desc("%s (DT)", name); 197 199 } 198 200 199 201 static void __init request_standard_resources(void) ··· 228 226 if (kernel_data.start >= res->start && 229 227 kernel_data.end <= res->end) 230 228 request_resource(res, &kernel_data); 229 + #ifdef CONFIG_KEXEC_CORE 230 + /* Userspace will find "Crash kernel" region in /proc/iomem. */ 231 + if (crashk_res.end && crashk_res.start >= res->start && 232 + crashk_res.end <= res->end) 233 + request_resource(res, &crashk_res); 234 + #endif 231 235 } 232 236 } 233 237
+79
arch/arm64/kernel/smp.c
··· 39 39 #include <linux/completion.h> 40 40 #include <linux/of.h> 41 41 #include <linux/irq_work.h> 42 + #include <linux/kexec.h> 42 43 43 44 #include <asm/alternative.h> 44 45 #include <asm/atomic.h> ··· 77 76 IPI_RESCHEDULE, 78 77 IPI_CALL_FUNC, 79 78 IPI_CPU_STOP, 79 + IPI_CPU_CRASH_STOP, 80 80 IPI_TIMER, 81 81 IPI_IRQ_WORK, 82 82 IPI_WAKEUP ··· 436 434 setup_cpu_features(); 437 435 hyp_mode_check(); 438 436 apply_alternatives_all(); 437 + mark_linear_text_alias_ro(); 439 438 } 440 439 441 440 void __init smp_prepare_boot_cpu(void) ··· 521 518 static unsigned int cpu_count = 1; 522 519 523 520 #ifdef CONFIG_ACPI 521 + static struct acpi_madt_generic_interrupt cpu_madt_gicc[NR_CPUS]; 522 + 523 + struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu) 524 + { 525 + return &cpu_madt_gicc[cpu]; 526 + } 527 + 524 528 /* 525 529 * acpi_map_gic_cpu_interface - parse processor MADT entry 526 530 * ··· 562 552 return; 563 553 } 564 554 bootcpu_valid = true; 555 + cpu_madt_gicc[0] = *processor; 565 556 early_map_cpu_to_node(0, acpi_numa_get_nid(0, hwid)); 566 557 return; 567 558 } ··· 572 561 573 562 /* map the logical cpu id to cpu MPIDR */ 574 563 cpu_logical_map(cpu_count) = hwid; 564 + 565 + cpu_madt_gicc[cpu_count] = *processor; 575 566 576 567 /* 577 568 * Set-up the ACPI parking protocol cpu entries ··· 768 755 S(IPI_RESCHEDULE, "Rescheduling interrupts"), 769 756 S(IPI_CALL_FUNC, "Function call interrupts"), 770 757 S(IPI_CPU_STOP, "CPU stop interrupts"), 758 + S(IPI_CPU_CRASH_STOP, "CPU stop (for crash dump) interrupts"), 771 759 S(IPI_TIMER, "Timer broadcast interrupts"), 772 760 S(IPI_IRQ_WORK, "IRQ work interrupts"), 773 761 S(IPI_WAKEUP, "CPU wake-up interrupts"), ··· 843 829 cpu_relax(); 844 830 } 845 831 832 + #ifdef CONFIG_KEXEC_CORE 833 + static atomic_t waiting_for_crash_ipi = ATOMIC_INIT(0); 834 + #endif 835 + 836 + static void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs) 837 + { 838 + #ifdef CONFIG_KEXEC_CORE 839 + crash_save_cpu(regs, cpu); 840 + 841 + atomic_dec(&waiting_for_crash_ipi); 842 + 843 + local_irq_disable(); 844 + 845 + #ifdef CONFIG_HOTPLUG_CPU 846 + if (cpu_ops[cpu]->cpu_die) 847 + cpu_ops[cpu]->cpu_die(cpu); 848 + #endif 849 + 850 + /* just in case */ 851 + cpu_park_loop(); 852 + #endif 853 + } 854 + 846 855 /* 847 856 * Main handler for inter-processor interrupts 848 857 */ ··· 894 857 irq_enter(); 895 858 ipi_cpu_stop(cpu); 896 859 irq_exit(); 860 + break; 861 + 862 + case IPI_CPU_CRASH_STOP: 863 + if (IS_ENABLED(CONFIG_KEXEC_CORE)) { 864 + irq_enter(); 865 + ipi_cpu_crash_stop(cpu, regs); 866 + 867 + unreachable(); 868 + } 897 869 break; 898 870 899 871 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST ··· 976 930 pr_warning("SMP: failed to stop secondary CPUs %*pbl\n", 977 931 cpumask_pr_args(cpu_online_mask)); 978 932 } 933 + 934 + #ifdef CONFIG_KEXEC_CORE 935 + void smp_send_crash_stop(void) 936 + { 937 + cpumask_t mask; 938 + unsigned long timeout; 939 + 940 + if (num_online_cpus() == 1) 941 + return; 942 + 943 + cpumask_copy(&mask, cpu_online_mask); 944 + cpumask_clear_cpu(smp_processor_id(), &mask); 945 + 946 + atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); 947 + 948 + pr_crit("SMP: stopping secondary CPUs\n"); 949 + smp_cross_call(&mask, IPI_CPU_CRASH_STOP); 950 + 951 + /* Wait up to one second for other CPUs to stop */ 952 + timeout = USEC_PER_SEC; 953 + while ((atomic_read(&waiting_for_crash_ipi) > 0) && timeout--) 954 + udelay(1); 955 + 956 + if (atomic_read(&waiting_for_crash_ipi) > 0) 957 + pr_warning("SMP: failed to stop secondary CPUs %*pbl\n", 958 + cpumask_pr_args(&mask)); 959 + } 960 + 961 + bool smp_crash_stop_failed(void) 962 + { 963 + return (atomic_read(&waiting_for_crash_ipi) > 0); 964 + } 965 + #endif 979 966 980 967 /* 981 968 * not supported here
+14
arch/arm64/kernel/traps.c
··· 513 513 regs->pc += 4; 514 514 } 515 515 516 + static void cntfrq_read_handler(unsigned int esr, struct pt_regs *regs) 517 + { 518 + int rt = (esr & ESR_ELx_SYS64_ISS_RT_MASK) >> ESR_ELx_SYS64_ISS_RT_SHIFT; 519 + 520 + pt_regs_write_reg(regs, rt, read_sysreg(cntfrq_el0)); 521 + regs->pc += 4; 522 + } 523 + 516 524 struct sys64_hook { 517 525 unsigned int esr_mask; 518 526 unsigned int esr_val; ··· 544 536 .esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK, 545 537 .esr_val = ESR_ELx_SYS64_ISS_SYS_CNTVCT, 546 538 .handler = cntvct_read_handler, 539 + }, 540 + { 541 + /* Trap read access to CNTFRQ_EL0 */ 542 + .esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK, 543 + .esr_val = ESR_ELx_SYS64_ISS_SYS_CNTFRQ, 544 + .handler = cntfrq_read_handler, 547 545 }, 548 546 {}, 549 547 };
+18 -9
arch/arm64/kernel/vmlinux.lds.S
··· 143 143 144 144 . = ALIGN(SEGMENT_ALIGN); 145 145 __init_begin = .; 146 + __inittext_begin = .; 146 147 147 148 INIT_TEXT_SECTION(8) 148 149 .exit.text : { 149 150 ARM_EXIT_KEEP(EXIT_TEXT) 150 151 } 152 + 153 + . = ALIGN(4); 154 + .altinstructions : { 155 + __alt_instructions = .; 156 + *(.altinstructions) 157 + __alt_instructions_end = .; 158 + } 159 + .altinstr_replacement : { 160 + *(.altinstr_replacement) 161 + } 162 + 163 + . = ALIGN(PAGE_SIZE); 164 + __inittext_end = .; 165 + __initdata_begin = .; 151 166 152 167 .init.data : { 153 168 INIT_DATA ··· 179 164 180 165 PERCPU_SECTION(L1_CACHE_BYTES) 181 166 182 - . = ALIGN(4); 183 - .altinstructions : { 184 - __alt_instructions = .; 185 - *(.altinstructions) 186 - __alt_instructions_end = .; 187 - } 188 - .altinstr_replacement : { 189 - *(.altinstr_replacement) 190 - } 191 167 .rela : ALIGN(8) { 192 168 *(.rela .rela*) 193 169 } ··· 187 181 __rela_size = SIZEOF(.rela); 188 182 189 183 . = ALIGN(SEGMENT_ALIGN); 184 + __initdata_end = .; 190 185 __init_end = .; 191 186 192 187 _data = .; ··· 213 206 } 214 207 215 208 PECOFF_EDATA_PADDING 209 + __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 216 210 _edata = .; 217 211 218 212 BSS_SECTION(0, 0, 0) ··· 229 221 . += RESERVED_TTBR0_SIZE; 230 222 #endif 231 223 224 + __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 232 225 _end = .; 233 226 234 227 STABS_DEBUG
+22
arch/arm64/kvm/hyp/tlb.c
··· 94 94 dsb(ish); 95 95 isb(); 96 96 97 + /* 98 + * If the host is running at EL1 and we have a VPIPT I-cache, 99 + * then we must perform I-cache maintenance at EL2 in order for 100 + * it to have an effect on the guest. Since the guest cannot hit 101 + * I-cache lines allocated with a different VMID, we don't need 102 + * to worry about junk out of guest reset (we nuke the I-cache on 103 + * VMID rollover), but we do need to be careful when remapping 104 + * executable pages for the same guest. This can happen when KSM 105 + * takes a CoW fault on an executable page, copies the page into 106 + * a page that was previously mapped in the guest and then needs 107 + * to invalidate the guest view of the I-cache for that page 108 + * from EL1. To solve this, we invalidate the entire I-cache when 109 + * unmapping a page from a guest if we have a VPIPT I-cache but 110 + * the host is running at EL1. As above, we could do better if 111 + * we had the VA. 112 + * 113 + * The moral of this story is: if you have a VPIPT I-cache, then 114 + * you should be running with VHE enabled. 115 + */ 116 + if (!has_vhe() && icache_is_vpipt()) 117 + __flush_icache_all(); 118 + 97 119 __tlb_switch_to_host()(kvm); 98 120 } 99 121
+1 -1
arch/arm64/kvm/reset.c
··· 60 60 { 61 61 u64 pfr0; 62 62 63 - pfr0 = read_system_reg(SYS_ID_AA64PFR0_EL1); 63 + pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); 64 64 return !!(pfr0 & 0x20); 65 65 } 66 66
+2 -2
arch/arm64/kvm/sys_regs.c
··· 1183 1183 if (p->is_write) { 1184 1184 return ignore_write(vcpu, p); 1185 1185 } else { 1186 - u64 dfr = read_system_reg(SYS_ID_AA64DFR0_EL1); 1187 - u64 pfr = read_system_reg(SYS_ID_AA64PFR0_EL1); 1186 + u64 dfr = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); 1187 + u64 pfr = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); 1188 1188 u32 el3 = !!cpuid_feature_extract_unsigned_field(pfr, ID_AA64PFR0_EL3_SHIFT); 1189 1189 1190 1190 p->regval = ((((dfr >> ID_AA64DFR0_WRPS_SHIFT) & 0xf) << 28) |
-3
arch/arm64/mm/context.c
··· 119 119 120 120 /* Queue a TLB invalidate and flush the I-cache if necessary. */ 121 121 cpumask_setall(&tlb_flush_pending); 122 - 123 - if (icache_is_aivivt()) 124 - __flush_icache_all(); 125 122 } 126 123 127 124 static bool check_update_reserved_asid(u64 asid, u64 newasid)
+97 -31
arch/arm64/mm/dma-mapping.c
··· 308 308 sg->length, dir); 309 309 } 310 310 311 - static int __swiotlb_mmap(struct device *dev, 312 - struct vm_area_struct *vma, 313 - void *cpu_addr, dma_addr_t dma_addr, size_t size, 314 - unsigned long attrs) 311 + static int __swiotlb_mmap_pfn(struct vm_area_struct *vma, 312 + unsigned long pfn, size_t size) 315 313 { 316 314 int ret = -ENXIO; 317 315 unsigned long nr_vma_pages = (vma->vm_end - vma->vm_start) >> 318 316 PAGE_SHIFT; 319 317 unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 320 - unsigned long pfn = dma_to_phys(dev, dma_addr) >> PAGE_SHIFT; 321 318 unsigned long off = vma->vm_pgoff; 322 - 323 - vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot, 324 - is_device_dma_coherent(dev)); 325 - 326 - if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) 327 - return ret; 328 319 329 320 if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) { 330 321 ret = remap_pfn_range(vma, vma->vm_start, ··· 327 336 return ret; 328 337 } 329 338 330 - static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, 331 - void *cpu_addr, dma_addr_t handle, size_t size, 332 - unsigned long attrs) 339 + static int __swiotlb_mmap(struct device *dev, 340 + struct vm_area_struct *vma, 341 + void *cpu_addr, dma_addr_t dma_addr, size_t size, 342 + unsigned long attrs) 343 + { 344 + int ret; 345 + unsigned long pfn = dma_to_phys(dev, dma_addr) >> PAGE_SHIFT; 346 + 347 + vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot, 348 + is_device_dma_coherent(dev)); 349 + 350 + if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) 351 + return ret; 352 + 353 + return __swiotlb_mmap_pfn(vma, pfn, size); 354 + } 355 + 356 + static int __swiotlb_get_sgtable_page(struct sg_table *sgt, 357 + struct page *page, size_t size) 333 358 { 334 359 int ret = sg_alloc_table(sgt, 1, GFP_KERNEL); 335 360 336 361 if (!ret) 337 - sg_set_page(sgt->sgl, phys_to_page(dma_to_phys(dev, handle)), 338 - PAGE_ALIGN(size), 0); 362 + sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); 339 363 340 364 return ret; 365 + } 366 + 367 + static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, 368 + void *cpu_addr, dma_addr_t handle, size_t size, 369 + unsigned long attrs) 370 + { 371 + struct page *page = phys_to_page(dma_to_phys(dev, handle)); 372 + 373 + return __swiotlb_get_sgtable_page(sgt, page, size); 341 374 } 342 375 343 376 static int __swiotlb_dma_supported(struct device *hwdev, u64 mask) ··· 599 584 */ 600 585 gfp |= __GFP_ZERO; 601 586 602 - if (gfpflags_allow_blocking(gfp)) { 603 - struct page **pages; 604 - pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL, coherent); 605 - 606 - pages = iommu_dma_alloc(dev, iosize, gfp, attrs, ioprot, 607 - handle, flush_page); 608 - if (!pages) 609 - return NULL; 610 - 611 - addr = dma_common_pages_remap(pages, size, VM_USERMAP, prot, 612 - __builtin_return_address(0)); 613 - if (!addr) 614 - iommu_dma_free(dev, pages, iosize, handle); 615 - } else { 587 + if (!gfpflags_allow_blocking(gfp)) { 616 588 struct page *page; 617 589 /* 618 590 * In atomic context we can't remap anything, so we'll only ··· 623 621 __free_from_pool(addr, size); 624 622 addr = NULL; 625 623 } 624 + } else if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { 625 + pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL, coherent); 626 + struct page *page; 627 + 628 + page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, 629 + get_order(size), gfp); 630 + if (!page) 631 + return NULL; 632 + 633 + *handle = iommu_dma_map_page(dev, page, 0, iosize, ioprot); 634 + if (iommu_dma_mapping_error(dev, *handle)) { 635 + dma_release_from_contiguous(dev, page, 636 + size >> PAGE_SHIFT); 637 + return NULL; 638 + } 639 + if (!coherent) 640 + __dma_flush_area(page_to_virt(page), iosize); 641 + 642 + addr = dma_common_contiguous_remap(page, size, VM_USERMAP, 643 + prot, 644 + __builtin_return_address(0)); 645 + if (!addr) { 646 + iommu_dma_unmap_page(dev, *handle, iosize, 0, attrs); 647 + dma_release_from_contiguous(dev, page, 648 + size >> PAGE_SHIFT); 649 + } 650 + } else { 651 + pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL, coherent); 652 + struct page **pages; 653 + 654 + pages = iommu_dma_alloc(dev, iosize, gfp, attrs, ioprot, 655 + handle, flush_page); 656 + if (!pages) 657 + return NULL; 658 + 659 + addr = dma_common_pages_remap(pages, size, VM_USERMAP, prot, 660 + __builtin_return_address(0)); 661 + if (!addr) 662 + iommu_dma_free(dev, pages, iosize, handle); 626 663 } 627 664 return addr; 628 665 } ··· 673 632 674 633 size = PAGE_ALIGN(size); 675 634 /* 676 - * @cpu_addr will be one of 3 things depending on how it was allocated: 635 + * @cpu_addr will be one of 4 things depending on how it was allocated: 636 + * - A remapped array of pages for contiguous allocations. 677 637 * - A remapped array of pages from iommu_dma_alloc(), for all 678 638 * non-atomic allocations. 679 639 * - A non-cacheable alias from the atomic pool, for atomic ··· 686 644 if (__in_atomic_pool(cpu_addr, size)) { 687 645 iommu_dma_unmap_page(dev, handle, iosize, 0, 0); 688 646 __free_from_pool(cpu_addr, size); 647 + } else if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { 648 + struct page *page = vmalloc_to_page(cpu_addr); 649 + 650 + iommu_dma_unmap_page(dev, handle, iosize, 0, attrs); 651 + dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); 652 + dma_common_free_remap(cpu_addr, size, VM_USERMAP); 689 653 } else if (is_vmalloc_addr(cpu_addr)){ 690 654 struct vm_struct *area = find_vm_area(cpu_addr); 691 655 ··· 718 670 if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) 719 671 return ret; 720 672 673 + if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { 674 + /* 675 + * DMA_ATTR_FORCE_CONTIGUOUS allocations are always remapped, 676 + * hence in the vmalloc space. 677 + */ 678 + unsigned long pfn = vmalloc_to_pfn(cpu_addr); 679 + return __swiotlb_mmap_pfn(vma, pfn, size); 680 + } 681 + 721 682 area = find_vm_area(cpu_addr); 722 683 if (WARN_ON(!area || !area->pages)) 723 684 return -ENXIO; ··· 740 683 { 741 684 unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; 742 685 struct vm_struct *area = find_vm_area(cpu_addr); 686 + 687 + if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { 688 + /* 689 + * DMA_ATTR_FORCE_CONTIGUOUS allocations are always remapped, 690 + * hence in the vmalloc space. 691 + */ 692 + struct page *page = vmalloc_to_page(cpu_addr); 693 + return __swiotlb_get_sgtable_page(sgt, page, size); 694 + } 743 695 744 696 if (WARN_ON(!area || !area->pages)) 745 697 return -ENXIO;
+36 -19
arch/arm64/mm/fault.c
··· 174 174 return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR; 175 175 } 176 176 177 + static inline bool is_permission_fault(unsigned int esr, struct pt_regs *regs, 178 + unsigned long addr) 179 + { 180 + unsigned int ec = ESR_ELx_EC(esr); 181 + unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE; 182 + 183 + if (ec != ESR_ELx_EC_DABT_CUR && ec != ESR_ELx_EC_IABT_CUR) 184 + return false; 185 + 186 + if (fsc_type == ESR_ELx_FSC_PERM) 187 + return true; 188 + 189 + if (addr < USER_DS && system_uses_ttbr0_pan()) 190 + return fsc_type == ESR_ELx_FSC_FAULT && 191 + (regs->pstate & PSR_PAN_BIT); 192 + 193 + return false; 194 + } 195 + 177 196 /* 178 197 * The kernel tried to access some page that wasn't present. 179 198 */ 180 199 static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr, 181 200 unsigned int esr, struct pt_regs *regs) 182 201 { 202 + const char *msg; 203 + 183 204 /* 184 205 * Are we prepared to handle this kernel fault? 185 206 * We are almost certainly not prepared to handle instruction faults. ··· 212 191 * No handler, we'll have to terminate things with extreme prejudice. 213 192 */ 214 193 bust_spinlocks(1); 215 - pr_alert("Unable to handle kernel %s at virtual address %08lx\n", 216 - (addr < PAGE_SIZE) ? "NULL pointer dereference" : 217 - "paging request", addr); 194 + 195 + if (is_permission_fault(esr, regs, addr)) { 196 + if (esr & ESR_ELx_WNR) 197 + msg = "write to read-only memory"; 198 + else 199 + msg = "read from unreadable memory"; 200 + } else if (addr < PAGE_SIZE) { 201 + msg = "NULL pointer dereference"; 202 + } else { 203 + msg = "paging request"; 204 + } 205 + 206 + pr_alert("Unable to handle kernel %s at virtual address %08lx\n", msg, 207 + addr); 218 208 219 209 show_pte(mm, addr); 220 210 die("Oops", regs, esr); ··· 319 287 return fault; 320 288 } 321 289 322 - static inline bool is_permission_fault(unsigned int esr, struct pt_regs *regs) 323 - { 324 - unsigned int ec = ESR_ELx_EC(esr); 325 - unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE; 326 - 327 - if (ec != ESR_ELx_EC_DABT_CUR && ec != ESR_ELx_EC_IABT_CUR) 328 - return false; 329 - 330 - if (system_uses_ttbr0_pan()) 331 - return fsc_type == ESR_ELx_FSC_FAULT && 332 - (regs->pstate & PSR_PAN_BIT); 333 - else 334 - return fsc_type == ESR_ELx_FSC_PERM; 335 - } 336 - 337 290 static bool is_el0_instruction_abort(unsigned int esr) 338 291 { 339 292 return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW; ··· 356 339 mm_flags |= FAULT_FLAG_WRITE; 357 340 } 358 341 359 - if (addr < USER_DS && is_permission_fault(esr, regs)) { 342 + if (addr < USER_DS && is_permission_fault(esr, regs, addr)) { 360 343 /* regs->orig_addr_limit may be 0 if we entered from EL0 */ 361 344 if (regs->orig_addr_limit == KERNEL_DS) 362 345 die("Accessing user space memory with fs=KERNEL_DS", regs, esr);
+1 -3
arch/arm64/mm/flush.c
··· 22 22 #include <linux/pagemap.h> 23 23 24 24 #include <asm/cacheflush.h> 25 - #include <asm/cachetype.h> 25 + #include <asm/cache.h> 26 26 #include <asm/tlbflush.h> 27 27 28 28 void sync_icache_aliases(void *kaddr, unsigned long len) ··· 65 65 if (!test_and_set_bit(PG_dcache_clean, &page->flags)) 66 66 sync_icache_aliases(page_address(page), 67 67 PAGE_SIZE << compound_order(page)); 68 - else if (icache_is_aivivt()) 69 - __flush_icache_all(); 70 68 } 71 69 72 70 /*
+181
arch/arm64/mm/init.c
··· 30 30 #include <linux/gfp.h> 31 31 #include <linux/memblock.h> 32 32 #include <linux/sort.h> 33 + #include <linux/of.h> 33 34 #include <linux/of_fdt.h> 34 35 #include <linux/dma-mapping.h> 35 36 #include <linux/dma-contiguous.h> ··· 38 37 #include <linux/swiotlb.h> 39 38 #include <linux/vmalloc.h> 40 39 #include <linux/mm.h> 40 + #include <linux/kexec.h> 41 + #include <linux/crash_dump.h> 41 42 42 43 #include <asm/boot.h> 43 44 #include <asm/fixmap.h> ··· 80 77 early_param("initrd", early_initrd); 81 78 #endif 82 79 80 + #ifdef CONFIG_KEXEC_CORE 81 + /* 82 + * reserve_crashkernel() - reserves memory for crash kernel 83 + * 84 + * This function reserves memory area given in "crashkernel=" kernel command 85 + * line parameter. The memory reserved is used by dump capture kernel when 86 + * primary kernel is crashing. 87 + */ 88 + static void __init reserve_crashkernel(void) 89 + { 90 + unsigned long long crash_base, crash_size; 91 + int ret; 92 + 93 + ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), 94 + &crash_size, &crash_base); 95 + /* no crashkernel= or invalid value specified */ 96 + if (ret || !crash_size) 97 + return; 98 + 99 + crash_size = PAGE_ALIGN(crash_size); 100 + 101 + if (crash_base == 0) { 102 + /* Current arm64 boot protocol requires 2MB alignment */ 103 + crash_base = memblock_find_in_range(0, ARCH_LOW_ADDRESS_LIMIT, 104 + crash_size, SZ_2M); 105 + if (crash_base == 0) { 106 + pr_warn("cannot allocate crashkernel (size:0x%llx)\n", 107 + crash_size); 108 + return; 109 + } 110 + } else { 111 + /* User specifies base address explicitly. */ 112 + if (!memblock_is_region_memory(crash_base, crash_size)) { 113 + pr_warn("cannot reserve crashkernel: region is not memory\n"); 114 + return; 115 + } 116 + 117 + if (memblock_is_region_reserved(crash_base, crash_size)) { 118 + pr_warn("cannot reserve crashkernel: region overlaps reserved memory\n"); 119 + return; 120 + } 121 + 122 + if (!IS_ALIGNED(crash_base, SZ_2M)) { 123 + pr_warn("cannot reserve crashkernel: base address is not 2MB aligned\n"); 124 + return; 125 + } 126 + } 127 + memblock_reserve(crash_base, crash_size); 128 + 129 + pr_info("crashkernel reserved: 0x%016llx - 0x%016llx (%lld MB)\n", 130 + crash_base, crash_base + crash_size, crash_size >> 20); 131 + 132 + crashk_res.start = crash_base; 133 + crashk_res.end = crash_base + crash_size - 1; 134 + } 135 + 136 + static void __init kexec_reserve_crashkres_pages(void) 137 + { 138 + #ifdef CONFIG_HIBERNATION 139 + phys_addr_t addr; 140 + struct page *page; 141 + 142 + if (!crashk_res.end) 143 + return; 144 + 145 + /* 146 + * To reduce the size of hibernation image, all the pages are 147 + * marked as Reserved initially. 148 + */ 149 + for (addr = crashk_res.start; addr < (crashk_res.end + 1); 150 + addr += PAGE_SIZE) { 151 + page = phys_to_page(addr); 152 + SetPageReserved(page); 153 + } 154 + #endif 155 + } 156 + #else 157 + static void __init reserve_crashkernel(void) 158 + { 159 + } 160 + 161 + static void __init kexec_reserve_crashkres_pages(void) 162 + { 163 + } 164 + #endif /* CONFIG_KEXEC_CORE */ 165 + 166 + #ifdef CONFIG_CRASH_DUMP 167 + static int __init early_init_dt_scan_elfcorehdr(unsigned long node, 168 + const char *uname, int depth, void *data) 169 + { 170 + const __be32 *reg; 171 + int len; 172 + 173 + if (depth != 1 || strcmp(uname, "chosen") != 0) 174 + return 0; 175 + 176 + reg = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len); 177 + if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells))) 178 + return 1; 179 + 180 + elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &reg); 181 + elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &reg); 182 + 183 + return 1; 184 + } 185 + 186 + /* 187 + * reserve_elfcorehdr() - reserves memory for elf core header 188 + * 189 + * This function reserves the memory occupied by an elf core header 190 + * described in the device tree. This region contains all the 191 + * information about primary kernel's core image and is used by a dump 192 + * capture kernel to access the system memory on primary kernel. 193 + */ 194 + static void __init reserve_elfcorehdr(void) 195 + { 196 + of_scan_flat_dt(early_init_dt_scan_elfcorehdr, NULL); 197 + 198 + if (!elfcorehdr_size) 199 + return; 200 + 201 + if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) { 202 + pr_warn("elfcorehdr is overlapped\n"); 203 + return; 204 + } 205 + 206 + memblock_reserve(elfcorehdr_addr, elfcorehdr_size); 207 + 208 + pr_info("Reserving %lldKB of memory at 0x%llx for elfcorehdr\n", 209 + elfcorehdr_size >> 10, elfcorehdr_addr); 210 + } 211 + #else 212 + static void __init reserve_elfcorehdr(void) 213 + { 214 + } 215 + #endif /* CONFIG_CRASH_DUMP */ 83 216 /* 84 217 * Return the maximum physical address for ZONE_DMA (DMA_BIT_MASK(32)). It 85 218 * currently assumes that for memory starting above 4G, 32-bit devices will ··· 327 188 } 328 189 early_param("mem", early_mem); 329 190 191 + static int __init early_init_dt_scan_usablemem(unsigned long node, 192 + const char *uname, int depth, void *data) 193 + { 194 + struct memblock_region *usablemem = data; 195 + const __be32 *reg; 196 + int len; 197 + 198 + if (depth != 1 || strcmp(uname, "chosen") != 0) 199 + return 0; 200 + 201 + reg = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len); 202 + if (!reg || (len < (dt_root_addr_cells + dt_root_size_cells))) 203 + return 1; 204 + 205 + usablemem->base = dt_mem_next_cell(dt_root_addr_cells, &reg); 206 + usablemem->size = dt_mem_next_cell(dt_root_size_cells, &reg); 207 + 208 + return 1; 209 + } 210 + 211 + static void __init fdt_enforce_memory_region(void) 212 + { 213 + struct memblock_region reg = { 214 + .size = 0, 215 + }; 216 + 217 + of_scan_flat_dt(early_init_dt_scan_usablemem, &reg); 218 + 219 + if (reg.size) 220 + memblock_cap_memory_range(reg.base, reg.size); 221 + } 222 + 330 223 void __init arm64_memblock_init(void) 331 224 { 332 225 const s64 linear_region_size = -(s64)PAGE_OFFSET; 226 + 227 + /* Handle linux,usable-memory-range property */ 228 + fdt_enforce_memory_region(); 333 229 334 230 /* 335 231 * Ensure that the linear region takes up exactly half of the kernel ··· 471 297 arm64_dma_phys_limit = max_zone_dma_phys(); 472 298 else 473 299 arm64_dma_phys_limit = PHYS_MASK + 1; 300 + 301 + reserve_crashkernel(); 302 + 303 + reserve_elfcorehdr(); 304 + 474 305 dma_contiguous_reserve(arm64_dma_phys_limit); 475 306 476 307 memblock_allow_resize(); ··· 594 415 #endif 595 416 /* this will put all unused low memory onto the freelists */ 596 417 free_all_bootmem(); 418 + 419 + kexec_reserve_crashkres_pages(); 597 420 598 421 mem_init_print_info(NULL); 599 422
+204 -107
arch/arm64/mm/mmu.c
··· 22 22 #include <linux/kernel.h> 23 23 #include <linux/errno.h> 24 24 #include <linux/init.h> 25 + #include <linux/ioport.h> 26 + #include <linux/kexec.h> 25 27 #include <linux/libfdt.h> 26 28 #include <linux/mman.h> 27 29 #include <linux/nodemask.h> ··· 44 42 #include <asm/memblock.h> 45 43 #include <asm/mmu_context.h> 46 44 #include <asm/ptdump.h> 45 + 46 + #define NO_BLOCK_MAPPINGS BIT(0) 47 + #define NO_CONT_MAPPINGS BIT(1) 47 48 48 49 u64 idmap_t0sz = TCR_T0SZ(VA_BITS); 49 50 ··· 108 103 */ 109 104 static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE; 110 105 111 - return old == 0 || new == 0 || ((old ^ new) & ~mask) == 0; 106 + /* creating or taking down mappings is always safe */ 107 + if (old == 0 || new == 0) 108 + return true; 109 + 110 + /* live contiguous mappings may not be manipulated at all */ 111 + if ((old | new) & PTE_CONT) 112 + return false; 113 + 114 + return ((old ^ new) & ~mask) == 0; 112 115 } 113 116 114 - static void alloc_init_pte(pmd_t *pmd, unsigned long addr, 115 - unsigned long end, unsigned long pfn, 116 - pgprot_t prot, 117 - phys_addr_t (*pgtable_alloc)(void)) 117 + static void init_pte(pmd_t *pmd, unsigned long addr, unsigned long end, 118 + phys_addr_t phys, pgprot_t prot) 118 119 { 119 120 pte_t *pte; 120 - 121 - BUG_ON(pmd_sect(*pmd)); 122 - if (pmd_none(*pmd)) { 123 - phys_addr_t pte_phys; 124 - BUG_ON(!pgtable_alloc); 125 - pte_phys = pgtable_alloc(); 126 - pte = pte_set_fixmap(pte_phys); 127 - __pmd_populate(pmd, pte_phys, PMD_TYPE_TABLE); 128 - pte_clear_fixmap(); 129 - } 130 - BUG_ON(pmd_bad(*pmd)); 131 121 132 122 pte = pte_set_fixmap_offset(pmd, addr); 133 123 do { 134 124 pte_t old_pte = *pte; 135 125 136 - set_pte(pte, pfn_pte(pfn, prot)); 137 - pfn++; 126 + set_pte(pte, pfn_pte(__phys_to_pfn(phys), prot)); 138 127 139 128 /* 140 129 * After the PTE entry has been populated once, we ··· 136 137 */ 137 138 BUG_ON(!pgattr_change_is_safe(pte_val(old_pte), pte_val(*pte))); 138 139 140 + phys += PAGE_SIZE; 139 141 } while (pte++, addr += PAGE_SIZE, addr != end); 140 142 141 143 pte_clear_fixmap(); 142 144 } 143 145 144 - static void alloc_init_pmd(pud_t *pud, unsigned long addr, unsigned long end, 145 - phys_addr_t phys, pgprot_t prot, 146 - phys_addr_t (*pgtable_alloc)(void), 147 - bool page_mappings_only) 146 + static void alloc_init_cont_pte(pmd_t *pmd, unsigned long addr, 147 + unsigned long end, phys_addr_t phys, 148 + pgprot_t prot, 149 + phys_addr_t (*pgtable_alloc)(void), 150 + int flags) 148 151 { 149 - pmd_t *pmd; 150 152 unsigned long next; 151 153 152 - /* 153 - * Check for initial section mappings in the pgd/pud and remove them. 154 - */ 155 - BUG_ON(pud_sect(*pud)); 156 - if (pud_none(*pud)) { 157 - phys_addr_t pmd_phys; 154 + BUG_ON(pmd_sect(*pmd)); 155 + if (pmd_none(*pmd)) { 156 + phys_addr_t pte_phys; 158 157 BUG_ON(!pgtable_alloc); 159 - pmd_phys = pgtable_alloc(); 160 - pmd = pmd_set_fixmap(pmd_phys); 161 - __pud_populate(pud, pmd_phys, PUD_TYPE_TABLE); 162 - pmd_clear_fixmap(); 158 + pte_phys = pgtable_alloc(); 159 + __pmd_populate(pmd, pte_phys, PMD_TYPE_TABLE); 163 160 } 164 - BUG_ON(pud_bad(*pud)); 161 + BUG_ON(pmd_bad(*pmd)); 162 + 163 + do { 164 + pgprot_t __prot = prot; 165 + 166 + next = pte_cont_addr_end(addr, end); 167 + 168 + /* use a contiguous mapping if the range is suitably aligned */ 169 + if ((((addr | next | phys) & ~CONT_PTE_MASK) == 0) && 170 + (flags & NO_CONT_MAPPINGS) == 0) 171 + __prot = __pgprot(pgprot_val(prot) | PTE_CONT); 172 + 173 + init_pte(pmd, addr, next, phys, __prot); 174 + 175 + phys += next - addr; 176 + } while (addr = next, addr != end); 177 + } 178 + 179 + static void init_pmd(pud_t *pud, unsigned long addr, unsigned long end, 180 + phys_addr_t phys, pgprot_t prot, 181 + phys_addr_t (*pgtable_alloc)(void), int flags) 182 + { 183 + unsigned long next; 184 + pmd_t *pmd; 165 185 166 186 pmd = pmd_set_fixmap_offset(pud, addr); 167 187 do { ··· 190 172 191 173 /* try section mapping first */ 192 174 if (((addr | next | phys) & ~SECTION_MASK) == 0 && 193 - !page_mappings_only) { 175 + (flags & NO_BLOCK_MAPPINGS) == 0) { 194 176 pmd_set_huge(pmd, phys, prot); 195 177 196 178 /* ··· 200 182 BUG_ON(!pgattr_change_is_safe(pmd_val(old_pmd), 201 183 pmd_val(*pmd))); 202 184 } else { 203 - alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys), 204 - prot, pgtable_alloc); 185 + alloc_init_cont_pte(pmd, addr, next, phys, prot, 186 + pgtable_alloc, flags); 205 187 206 188 BUG_ON(pmd_val(old_pmd) != 0 && 207 189 pmd_val(old_pmd) != pmd_val(*pmd)); ··· 210 192 } while (pmd++, addr = next, addr != end); 211 193 212 194 pmd_clear_fixmap(); 195 + } 196 + 197 + static void alloc_init_cont_pmd(pud_t *pud, unsigned long addr, 198 + unsigned long end, phys_addr_t phys, 199 + pgprot_t prot, 200 + phys_addr_t (*pgtable_alloc)(void), int flags) 201 + { 202 + unsigned long next; 203 + 204 + /* 205 + * Check for initial section mappings in the pgd/pud. 206 + */ 207 + BUG_ON(pud_sect(*pud)); 208 + if (pud_none(*pud)) { 209 + phys_addr_t pmd_phys; 210 + BUG_ON(!pgtable_alloc); 211 + pmd_phys = pgtable_alloc(); 212 + __pud_populate(pud, pmd_phys, PUD_TYPE_TABLE); 213 + } 214 + BUG_ON(pud_bad(*pud)); 215 + 216 + do { 217 + pgprot_t __prot = prot; 218 + 219 + next = pmd_cont_addr_end(addr, end); 220 + 221 + /* use a contiguous mapping if the range is suitably aligned */ 222 + if ((((addr | next | phys) & ~CONT_PMD_MASK) == 0) && 223 + (flags & NO_CONT_MAPPINGS) == 0) 224 + __prot = __pgprot(pgprot_val(prot) | PTE_CONT); 225 + 226 + init_pmd(pud, addr, next, phys, __prot, pgtable_alloc, flags); 227 + 228 + phys += next - addr; 229 + } while (addr = next, addr != end); 213 230 } 214 231 215 232 static inline bool use_1G_block(unsigned long addr, unsigned long next, ··· 262 209 static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end, 263 210 phys_addr_t phys, pgprot_t prot, 264 211 phys_addr_t (*pgtable_alloc)(void), 265 - bool page_mappings_only) 212 + int flags) 266 213 { 267 214 pud_t *pud; 268 215 unsigned long next; ··· 284 231 /* 285 232 * For 4K granule only, attempt to put down a 1GB block 286 233 */ 287 - if (use_1G_block(addr, next, phys) && !page_mappings_only) { 234 + if (use_1G_block(addr, next, phys) && 235 + (flags & NO_BLOCK_MAPPINGS) == 0) { 288 236 pud_set_huge(pud, phys, prot); 289 237 290 238 /* ··· 295 241 BUG_ON(!pgattr_change_is_safe(pud_val(old_pud), 296 242 pud_val(*pud))); 297 243 } else { 298 - alloc_init_pmd(pud, addr, next, phys, prot, 299 - pgtable_alloc, page_mappings_only); 244 + alloc_init_cont_pmd(pud, addr, next, phys, prot, 245 + pgtable_alloc, flags); 300 246 301 247 BUG_ON(pud_val(old_pud) != 0 && 302 248 pud_val(old_pud) != pud_val(*pud)); ··· 311 257 unsigned long virt, phys_addr_t size, 312 258 pgprot_t prot, 313 259 phys_addr_t (*pgtable_alloc)(void), 314 - bool page_mappings_only) 260 + int flags) 315 261 { 316 262 unsigned long addr, length, end, next; 317 263 pgd_t *pgd = pgd_offset_raw(pgdir, virt); ··· 331 277 do { 332 278 next = pgd_addr_end(addr, end); 333 279 alloc_init_pud(pgd, addr, next, phys, prot, pgtable_alloc, 334 - page_mappings_only); 280 + flags); 335 281 phys += next - addr; 336 282 } while (pgd++, addr = next, addr != end); 337 283 } ··· 360 306 &phys, virt); 361 307 return; 362 308 } 363 - __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, false); 309 + __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, 310 + NO_CONT_MAPPINGS); 364 311 } 365 312 366 313 void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, 367 314 unsigned long virt, phys_addr_t size, 368 315 pgprot_t prot, bool page_mappings_only) 369 316 { 317 + int flags = 0; 318 + 370 319 BUG_ON(mm == &init_mm); 371 320 321 + if (page_mappings_only) 322 + flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; 323 + 372 324 __create_pgd_mapping(mm->pgd, phys, virt, size, prot, 373 - pgd_pgtable_alloc, page_mappings_only); 325 + pgd_pgtable_alloc, flags); 374 326 } 375 327 376 - static void create_mapping_late(phys_addr_t phys, unsigned long virt, 377 - phys_addr_t size, pgprot_t prot) 328 + static void update_mapping_prot(phys_addr_t phys, unsigned long virt, 329 + phys_addr_t size, pgprot_t prot) 378 330 { 379 331 if (virt < VMALLOC_START) { 380 - pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n", 332 + pr_warn("BUG: not updating mapping for %pa at 0x%016lx - outside kernel range\n", 381 333 &phys, virt); 382 334 return; 383 335 } 384 336 385 - __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, 386 - NULL, debug_pagealloc_enabled()); 337 + __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot, NULL, 338 + NO_CONT_MAPPINGS); 339 + 340 + /* flush the TLBs after updating live kernel mappings */ 341 + flush_tlb_kernel_range(virt, virt + size); 387 342 } 388 343 389 - static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, phys_addr_t end) 344 + static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, 345 + phys_addr_t end, pgprot_t prot, int flags) 390 346 { 391 - phys_addr_t kernel_start = __pa_symbol(_text); 392 - phys_addr_t kernel_end = __pa_symbol(__init_begin); 347 + __create_pgd_mapping(pgd, start, __phys_to_virt(start), end - start, 348 + prot, early_pgtable_alloc, flags); 349 + } 393 350 351 + void __init mark_linear_text_alias_ro(void) 352 + { 394 353 /* 395 - * Take care not to create a writable alias for the 396 - * read-only text and rodata sections of the kernel image. 354 + * Remove the write permissions from the linear alias of .text/.rodata 397 355 */ 398 - 399 - /* No overlap with the kernel text/rodata */ 400 - if (end < kernel_start || start >= kernel_end) { 401 - __create_pgd_mapping(pgd, start, __phys_to_virt(start), 402 - end - start, PAGE_KERNEL, 403 - early_pgtable_alloc, 404 - debug_pagealloc_enabled()); 405 - return; 406 - } 407 - 408 - /* 409 - * This block overlaps the kernel text/rodata mappings. 410 - * Map the portion(s) which don't overlap. 411 - */ 412 - if (start < kernel_start) 413 - __create_pgd_mapping(pgd, start, 414 - __phys_to_virt(start), 415 - kernel_start - start, PAGE_KERNEL, 416 - early_pgtable_alloc, 417 - debug_pagealloc_enabled()); 418 - if (kernel_end < end) 419 - __create_pgd_mapping(pgd, kernel_end, 420 - __phys_to_virt(kernel_end), 421 - end - kernel_end, PAGE_KERNEL, 422 - early_pgtable_alloc, 423 - debug_pagealloc_enabled()); 424 - 425 - /* 426 - * Map the linear alias of the [_text, __init_begin) interval as 427 - * read-only/non-executable. This makes the contents of the 428 - * region accessible to subsystems such as hibernate, but 429 - * protects it from inadvertent modification or execution. 430 - */ 431 - __create_pgd_mapping(pgd, kernel_start, __phys_to_virt(kernel_start), 432 - kernel_end - kernel_start, PAGE_KERNEL_RO, 433 - early_pgtable_alloc, debug_pagealloc_enabled()); 356 + update_mapping_prot(__pa_symbol(_text), (unsigned long)lm_alias(_text), 357 + (unsigned long)__init_begin - (unsigned long)_text, 358 + PAGE_KERNEL_RO); 434 359 } 435 360 436 361 static void __init map_mem(pgd_t *pgd) 437 362 { 363 + phys_addr_t kernel_start = __pa_symbol(_text); 364 + phys_addr_t kernel_end = __pa_symbol(__init_begin); 438 365 struct memblock_region *reg; 366 + int flags = 0; 367 + 368 + if (debug_pagealloc_enabled()) 369 + flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; 370 + 371 + /* 372 + * Take care not to create a writable alias for the 373 + * read-only text and rodata sections of the kernel image. 374 + * So temporarily mark them as NOMAP to skip mappings in 375 + * the following for-loop 376 + */ 377 + memblock_mark_nomap(kernel_start, kernel_end - kernel_start); 378 + #ifdef CONFIG_KEXEC_CORE 379 + if (crashk_res.end) 380 + memblock_mark_nomap(crashk_res.start, 381 + resource_size(&crashk_res)); 382 + #endif 439 383 440 384 /* map all the memory banks */ 441 385 for_each_memblock(memory, reg) { ··· 445 393 if (memblock_is_nomap(reg)) 446 394 continue; 447 395 448 - __map_memblock(pgd, start, end); 396 + __map_memblock(pgd, start, end, PAGE_KERNEL, flags); 449 397 } 398 + 399 + /* 400 + * Map the linear alias of the [_text, __init_begin) interval 401 + * as non-executable now, and remove the write permission in 402 + * mark_linear_text_alias_ro() below (which will be called after 403 + * alternative patching has completed). This makes the contents 404 + * of the region accessible to subsystems such as hibernate, 405 + * but protects it from inadvertent modification or execution. 406 + * Note that contiguous mappings cannot be remapped in this way, 407 + * so we should avoid them here. 408 + */ 409 + __map_memblock(pgd, kernel_start, kernel_end, 410 + PAGE_KERNEL, NO_CONT_MAPPINGS); 411 + memblock_clear_nomap(kernel_start, kernel_end - kernel_start); 412 + 413 + #ifdef CONFIG_KEXEC_CORE 414 + /* 415 + * Use page-level mappings here so that we can shrink the region 416 + * in page granularity and put back unused memory to buddy system 417 + * through /sys/kernel/kexec_crash_size interface. 418 + */ 419 + if (crashk_res.end) { 420 + __map_memblock(pgd, crashk_res.start, crashk_res.end + 1, 421 + PAGE_KERNEL, 422 + NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); 423 + memblock_clear_nomap(crashk_res.start, 424 + resource_size(&crashk_res)); 425 + } 426 + #endif 450 427 } 451 428 452 429 void mark_rodata_ro(void) 453 430 { 454 431 unsigned long section_size; 455 432 456 - section_size = (unsigned long)_etext - (unsigned long)_text; 457 - create_mapping_late(__pa_symbol(_text), (unsigned long)_text, 458 - section_size, PAGE_KERNEL_ROX); 459 433 /* 460 434 * mark .rodata as read only. Use __init_begin rather than __end_rodata 461 435 * to cover NOTES and EXCEPTION_TABLE. 462 436 */ 463 437 section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata; 464 - create_mapping_late(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, 438 + update_mapping_prot(__pa_symbol(__start_rodata), (unsigned long)__start_rodata, 465 439 section_size, PAGE_KERNEL_RO); 466 - 467 - /* flush the TLBs after updating live kernel mappings */ 468 - flush_tlb_all(); 469 440 470 441 debug_checkwx(); 471 442 } 472 443 473 444 static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end, 474 - pgprot_t prot, struct vm_struct *vma) 445 + pgprot_t prot, struct vm_struct *vma, 446 + int flags) 475 447 { 476 448 phys_addr_t pa_start = __pa_symbol(va_start); 477 449 unsigned long size = va_end - va_start; ··· 504 428 BUG_ON(!PAGE_ALIGNED(size)); 505 429 506 430 __create_pgd_mapping(pgd, pa_start, (unsigned long)va_start, size, prot, 507 - early_pgtable_alloc, debug_pagealloc_enabled()); 431 + early_pgtable_alloc, flags); 508 432 509 433 vma->addr = va_start; 510 434 vma->phys_addr = pa_start; ··· 515 439 vm_area_add_early(vma); 516 440 } 517 441 442 + static int __init parse_rodata(char *arg) 443 + { 444 + return strtobool(arg, &rodata_enabled); 445 + } 446 + early_param("rodata", parse_rodata); 447 + 518 448 /* 519 449 * Create fine-grained mappings for the kernel. 520 450 */ 521 451 static void __init map_kernel(pgd_t *pgd) 522 452 { 523 - static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_init, vmlinux_data; 453 + static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_inittext, 454 + vmlinux_initdata, vmlinux_data; 524 455 525 - map_kernel_segment(pgd, _text, _etext, PAGE_KERNEL_EXEC, &vmlinux_text); 526 - map_kernel_segment(pgd, __start_rodata, __init_begin, PAGE_KERNEL, &vmlinux_rodata); 527 - map_kernel_segment(pgd, __init_begin, __init_end, PAGE_KERNEL_EXEC, 528 - &vmlinux_init); 529 - map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data); 456 + /* 457 + * External debuggers may need to write directly to the text 458 + * mapping to install SW breakpoints. Allow this (only) when 459 + * explicitly requested with rodata=off. 460 + */ 461 + pgprot_t text_prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; 462 + 463 + /* 464 + * Only rodata will be remapped with different permissions later on, 465 + * all other segments are allowed to use contiguous mappings. 466 + */ 467 + map_kernel_segment(pgd, _text, _etext, text_prot, &vmlinux_text, 0); 468 + map_kernel_segment(pgd, __start_rodata, __inittext_begin, PAGE_KERNEL, 469 + &vmlinux_rodata, NO_CONT_MAPPINGS); 470 + map_kernel_segment(pgd, __inittext_begin, __inittext_end, text_prot, 471 + &vmlinux_inittext, 0); 472 + map_kernel_segment(pgd, __initdata_begin, __initdata_end, PAGE_KERNEL, 473 + &vmlinux_initdata, 0); 474 + map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data, 0); 530 475 531 476 if (!pgd_val(*pgd_offset_raw(pgd, FIXADDR_START))) { 532 477 /*
+9 -6
arch/arm64/mm/pageattr.c
··· 125 125 } 126 126 EXPORT_SYMBOL_GPL(set_memory_x); 127 127 128 - #ifdef CONFIG_DEBUG_PAGEALLOC 129 - void __kernel_map_pages(struct page *page, int numpages, int enable) 128 + int set_memory_valid(unsigned long addr, int numpages, int enable) 130 129 { 131 - unsigned long addr = (unsigned long) page_address(page); 132 - 133 130 if (enable) 134 - __change_memory_common(addr, PAGE_SIZE * numpages, 131 + return __change_memory_common(addr, PAGE_SIZE * numpages, 135 132 __pgprot(PTE_VALID), 136 133 __pgprot(0)); 137 134 else 138 - __change_memory_common(addr, PAGE_SIZE * numpages, 135 + return __change_memory_common(addr, PAGE_SIZE * numpages, 139 136 __pgprot(0), 140 137 __pgprot(PTE_VALID)); 138 + } 139 + 140 + #ifdef CONFIG_DEBUG_PAGEALLOC 141 + void __kernel_map_pages(struct page *page, int numpages, int enable) 142 + { 143 + set_memory_valid((unsigned long)page_address(page), numpages, enable); 141 144 } 142 145 #ifdef CONFIG_HIBERNATION 143 146 /*
+127 -31
drivers/acpi/arm64/iort.c
··· 225 225 226 226 if (iort_node->type == type && 227 227 ACPI_SUCCESS(callback(iort_node, context))) 228 - return iort_node; 228 + return iort_node; 229 229 230 230 iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, 231 231 iort_node->length); ··· 253 253 void *context) 254 254 { 255 255 struct device *dev = context; 256 - acpi_status status; 256 + acpi_status status = AE_NOT_FOUND; 257 257 258 258 if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT) { 259 259 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; 260 260 struct acpi_device *adev = to_acpi_device_node(dev->fwnode); 261 261 struct acpi_iort_named_component *ncomp; 262 262 263 - if (!adev) { 264 - status = AE_NOT_FOUND; 263 + if (!adev) 265 264 goto out; 266 - } 267 265 268 266 status = acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &buf); 269 267 if (ACPI_FAILURE(status)) { ··· 287 289 */ 288 290 status = pci_rc->pci_segment_number == pci_domain_nr(bus) ? 289 291 AE_OK : AE_NOT_FOUND; 290 - } else { 291 - status = AE_NOT_FOUND; 292 292 } 293 293 out: 294 294 return status; ··· 318 322 319 323 static 320 324 struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, 321 - u32 *id_out, u8 type_mask, 322 - int index) 325 + u32 *id_out, int index) 323 326 { 324 327 struct acpi_iort_node *parent; 325 328 struct acpi_iort_id_mapping *map; ··· 340 345 parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, 341 346 map->output_reference); 342 347 343 - if (!(IORT_TYPE_MASK(parent->type) & type_mask)) 344 - return NULL; 345 - 346 348 if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { 347 349 if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || 348 350 node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { ··· 351 359 return NULL; 352 360 } 353 361 354 - static struct acpi_iort_node *iort_node_map_rid(struct acpi_iort_node *node, 355 - u32 rid_in, u32 *rid_out, 356 - u8 type_mask) 362 + static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, 363 + u32 id_in, u32 *id_out, 364 + u8 type_mask) 357 365 { 358 - u32 rid = rid_in; 366 + u32 id = id_in; 359 367 360 368 /* Parse the ID mapping tree to find specified node type */ 361 369 while (node) { ··· 363 371 int i; 364 372 365 373 if (IORT_TYPE_MASK(node->type) & type_mask) { 366 - if (rid_out) 367 - *rid_out = rid; 374 + if (id_out) 375 + *id_out = id; 368 376 return node; 369 377 } 370 378 ··· 381 389 goto fail_map; 382 390 } 383 391 384 - /* Do the RID translation */ 392 + /* Do the ID translation */ 385 393 for (i = 0; i < node->mapping_count; i++, map++) { 386 - if (!iort_id_map(map, node->type, rid, &rid)) 394 + if (!iort_id_map(map, node->type, id, &id)) 387 395 break; 388 396 } 389 397 ··· 395 403 } 396 404 397 405 fail_map: 398 - /* Map input RID to output RID unchanged on mapping failure*/ 399 - if (rid_out) 400 - *rid_out = rid_in; 406 + /* Map input ID to output ID unchanged on mapping failure */ 407 + if (id_out) 408 + *id_out = id_in; 401 409 402 410 return NULL; 411 + } 412 + 413 + static 414 + struct acpi_iort_node *iort_node_map_platform_id(struct acpi_iort_node *node, 415 + u32 *id_out, u8 type_mask, 416 + int index) 417 + { 418 + struct acpi_iort_node *parent; 419 + u32 id; 420 + 421 + /* step 1: retrieve the initial dev id */ 422 + parent = iort_node_get_id(node, &id, index); 423 + if (!parent) 424 + return NULL; 425 + 426 + /* 427 + * optional step 2: map the initial dev id if its parent is not 428 + * the target type we want, map it again for the use cases such 429 + * as NC (named component) -> SMMU -> ITS. If the type is matched, 430 + * return the initial dev id and its parent pointer directly. 431 + */ 432 + if (!(IORT_TYPE_MASK(parent->type) & type_mask)) 433 + parent = iort_node_map_id(parent, id, id_out, type_mask); 434 + else 435 + if (id_out) 436 + *id_out = id; 437 + 438 + return parent; 403 439 } 404 440 405 441 static struct acpi_iort_node *iort_find_dev_node(struct device *dev) ··· 463 443 if (!node) 464 444 return req_id; 465 445 466 - iort_node_map_rid(node, req_id, &dev_id, IORT_MSI_TYPE); 446 + iort_node_map_id(node, req_id, &dev_id, IORT_MSI_TYPE); 467 447 return dev_id; 448 + } 449 + 450 + /** 451 + * iort_pmsi_get_dev_id() - Get the device id for a device 452 + * @dev: The device for which the mapping is to be done. 453 + * @dev_id: The device ID found. 454 + * 455 + * Returns: 0 for successful find a dev id, -ENODEV on error 456 + */ 457 + int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) 458 + { 459 + int i; 460 + struct acpi_iort_node *node; 461 + 462 + node = iort_find_dev_node(dev); 463 + if (!node) 464 + return -ENODEV; 465 + 466 + for (i = 0; i < node->mapping_count; i++) { 467 + if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i)) 468 + return 0; 469 + } 470 + 471 + return -ENODEV; 468 472 } 469 473 470 474 /** 471 475 * iort_dev_find_its_id() - Find the ITS identifier for a device 472 476 * @dev: The device. 477 + * @req_id: Device's requester ID 473 478 * @idx: Index of the ITS identifier list. 474 479 * @its_id: ITS identifier. 475 480 * ··· 510 465 if (!node) 511 466 return -ENXIO; 512 467 513 - node = iort_node_map_rid(node, req_id, NULL, IORT_MSI_TYPE); 468 + node = iort_node_map_id(node, req_id, NULL, IORT_MSI_TYPE); 514 469 if (!node) 515 470 return -ENXIO; 516 471 ··· 546 501 return NULL; 547 502 548 503 return irq_find_matching_fwnode(handle, DOMAIN_BUS_PCI_MSI); 504 + } 505 + 506 + /** 507 + * iort_get_platform_device_domain() - Find MSI domain related to a 508 + * platform device 509 + * @dev: the dev pointer associated with the platform device 510 + * 511 + * Returns: the MSI domain for this device, NULL otherwise 512 + */ 513 + static struct irq_domain *iort_get_platform_device_domain(struct device *dev) 514 + { 515 + struct acpi_iort_node *node, *msi_parent; 516 + struct fwnode_handle *iort_fwnode; 517 + struct acpi_iort_its_group *its; 518 + int i; 519 + 520 + /* find its associated iort node */ 521 + node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, 522 + iort_match_node_callback, dev); 523 + if (!node) 524 + return NULL; 525 + 526 + /* then find its msi parent node */ 527 + for (i = 0; i < node->mapping_count; i++) { 528 + msi_parent = iort_node_map_platform_id(node, NULL, 529 + IORT_MSI_TYPE, i); 530 + if (msi_parent) 531 + break; 532 + } 533 + 534 + if (!msi_parent) 535 + return NULL; 536 + 537 + /* Move to ITS specific data */ 538 + its = (struct acpi_iort_its_group *)msi_parent->node_data; 539 + 540 + iort_fwnode = iort_find_domain_token(its->identifiers[0]); 541 + if (!iort_fwnode) 542 + return NULL; 543 + 544 + return irq_find_matching_fwnode(iort_fwnode, DOMAIN_BUS_PLATFORM_MSI); 545 + } 546 + 547 + void acpi_configure_pmsi_domain(struct device *dev) 548 + { 549 + struct irq_domain *msi_domain; 550 + 551 + msi_domain = iort_get_platform_device_domain(dev); 552 + if (msi_domain) 553 + dev_set_msi_domain(dev, msi_domain); 549 554 } 550 555 551 556 static int __get_pci_rid(struct pci_dev *pdev, u16 alias, void *data) ··· 689 594 if (!node) 690 595 return NULL; 691 596 692 - parent = iort_node_map_rid(node, rid, &streamid, 693 - IORT_IOMMU_TYPE); 597 + parent = iort_node_map_id(node, rid, &streamid, 598 + IORT_IOMMU_TYPE); 694 599 695 600 ops = iort_iommu_xlate(dev, parent, streamid); 696 601 ··· 702 607 if (!node) 703 608 return NULL; 704 609 705 - parent = iort_node_get_id(node, &streamid, 706 - IORT_IOMMU_TYPE, i++); 610 + parent = iort_node_map_platform_id(node, &streamid, 611 + IORT_IOMMU_TYPE, i++); 707 612 708 613 while (parent) { 709 614 ops = iort_iommu_xlate(dev, parent, streamid); 710 615 711 - parent = iort_node_get_id(node, &streamid, 712 - IORT_IOMMU_TYPE, i++); 616 + parent = iort_node_map_platform_id(node, &streamid, 617 + IORT_IOMMU_TYPE, 618 + i++); 713 619 } 714 620 } 715 621
+6
drivers/acpi/glue.c
··· 6 6 * 7 7 * This file is released under the GPLv2. 8 8 */ 9 + 10 + #include <linux/acpi_iort.h> 9 11 #include <linux/export.h> 10 12 #include <linux/init.h> 11 13 #include <linux/list.h> ··· 16 14 #include <linux/rwsem.h> 17 15 #include <linux/acpi.h> 18 16 #include <linux/dma-mapping.h> 17 + #include <linux/platform_device.h> 19 18 20 19 #include "internal.h" 21 20 ··· 324 321 adev = ACPI_COMPANION(dev); 325 322 if (!adev) 326 323 goto out; 324 + 325 + if (dev->bus == &platform_bus_type) 326 + acpi_configure_pmsi_domain(dev); 327 327 328 328 if (type && type->setup) 329 329 type->setup(dev);
+26 -2
drivers/firmware/efi/libstub/fdt.c
··· 16 16 17 17 #include "efistub.h" 18 18 19 + #define EFI_DT_ADDR_CELLS_DEFAULT 2 20 + #define EFI_DT_SIZE_CELLS_DEFAULT 2 21 + 22 + static void fdt_update_cell_size(efi_system_table_t *sys_table, void *fdt) 23 + { 24 + int offset; 25 + 26 + offset = fdt_path_offset(fdt, "/"); 27 + /* Set the #address-cells and #size-cells values for an empty tree */ 28 + 29 + fdt_setprop_u32(fdt, offset, "#address-cells", 30 + EFI_DT_ADDR_CELLS_DEFAULT); 31 + 32 + fdt_setprop_u32(fdt, offset, "#size-cells", EFI_DT_SIZE_CELLS_DEFAULT); 33 + } 34 + 19 35 static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, 20 36 unsigned long orig_fdt_size, 21 37 void *fdt, int new_fdt_size, char *cmdline_ptr, ··· 58 42 } 59 43 } 60 44 61 - if (orig_fdt) 45 + if (orig_fdt) { 62 46 status = fdt_open_into(orig_fdt, fdt, new_fdt_size); 63 - else 47 + } else { 64 48 status = fdt_create_empty_tree(fdt, new_fdt_size); 49 + if (status == 0) { 50 + /* 51 + * Any failure from the following function is non 52 + * critical 53 + */ 54 + fdt_update_cell_size(sys_table, fdt); 55 + } 56 + } 65 57 66 58 if (status != 0) 67 59 goto fdt_set_fail;
+14
drivers/perf/Kconfig
··· 12 12 Say y if you want to use CPU performance monitors on ARM-based 13 13 systems. 14 14 15 + config ARM_PMU_ACPI 16 + depends on ARM_PMU && ACPI 17 + def_bool y 18 + 15 19 config QCOM_L2_PMU 16 20 bool "Qualcomm Technologies L2-cache PMU" 17 21 depends on ARCH_QCOM && ARM64 && PERF_EVENTS && ACPI ··· 24 20 in Qualcomm Technologies processors. 25 21 Adds the L2 cache PMU into the perf events subsystem for 26 22 monitoring L2 cache events. 23 + 24 + config QCOM_L3_PMU 25 + bool "Qualcomm Technologies L3-cache PMU" 26 + depends on ARCH_QCOM && ARM64 && PERF_EVENTS && ACPI 27 + select QCOM_IRQ_COMBINER 28 + help 29 + Provides support for the L3 cache performance monitor unit (PMU) 30 + in Qualcomm Technologies processors. 31 + Adds the L3 cache PMU into the perf events subsystem for 32 + monitoring L3 cache events. 27 33 28 34 config XGENE_PMU 29 35 depends on PERF_EVENTS && ARCH_XGENE
+3 -1
drivers/perf/Makefile
··· 1 - obj-$(CONFIG_ARM_PMU) += arm_pmu.o 1 + obj-$(CONFIG_ARM_PMU) += arm_pmu.o arm_pmu_platform.o 2 + obj-$(CONFIG_ARM_PMU_ACPI) += arm_pmu_acpi.o 2 3 obj-$(CONFIG_QCOM_L2_PMU) += qcom_l2_pmu.o 4 + obj-$(CONFIG_QCOM_L3_PMU) += qcom_l3_pmu.o 3 5 obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
+167 -377
drivers/perf/arm_pmu.c
··· 16 16 #include <linux/cpu_pm.h> 17 17 #include <linux/export.h> 18 18 #include <linux/kernel.h> 19 - #include <linux/of_device.h> 20 19 #include <linux/perf/arm_pmu.h> 21 20 #include <linux/platform_device.h> 22 21 #include <linux/slab.h> ··· 24 25 #include <linux/irq.h> 25 26 #include <linux/irqdesc.h> 26 27 27 - #include <asm/cputype.h> 28 28 #include <asm/irq_regs.h> 29 29 30 30 static int ··· 233 235 struct pmu_hw_events *hw_events = this_cpu_ptr(armpmu->hw_events); 234 236 struct hw_perf_event *hwc = &event->hw; 235 237 int idx; 236 - int err = 0; 237 238 238 239 /* An event following a process won't be stopped earlier */ 239 240 if (!cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus)) 240 241 return -ENOENT; 241 242 242 - perf_pmu_disable(event->pmu); 243 - 244 243 /* If we don't have a space for the counter then finish early. */ 245 244 idx = armpmu->get_event_idx(hw_events, event); 246 - if (idx < 0) { 247 - err = idx; 248 - goto out; 249 - } 245 + if (idx < 0) 246 + return idx; 250 247 251 248 /* 252 249 * If there is an event in the counter we are going to use then make ··· 258 265 /* Propagate our changes to the userspace mapping. */ 259 266 perf_event_update_userpage(event); 260 267 261 - out: 262 - perf_pmu_enable(event->pmu); 263 - return err; 268 + return 0; 264 269 } 265 270 266 271 static int ··· 314 323 return 0; 315 324 } 316 325 326 + static struct arm_pmu_platdata *armpmu_get_platdata(struct arm_pmu *armpmu) 327 + { 328 + struct platform_device *pdev = armpmu->plat_device; 329 + 330 + return pdev ? dev_get_platdata(&pdev->dev) : NULL; 331 + } 332 + 317 333 static irqreturn_t armpmu_dispatch_irq(int irq, void *dev) 318 334 { 319 335 struct arm_pmu *armpmu; 320 - struct platform_device *plat_device; 321 336 struct arm_pmu_platdata *plat; 322 337 int ret; 323 338 u64 start_clock, finish_clock; ··· 335 338 * dereference. 336 339 */ 337 340 armpmu = *(void **)dev; 338 - plat_device = armpmu->plat_device; 339 - plat = dev_get_platdata(&plat_device->dev); 341 + 342 + plat = armpmu_get_platdata(armpmu); 340 343 341 344 start_clock = sched_clock(); 342 345 if (plat && plat->handle_irq) ··· 347 350 348 351 perf_sample_event_took(finish_clock - start_clock); 349 352 return ret; 350 - } 351 - 352 - static void 353 - armpmu_release_hardware(struct arm_pmu *armpmu) 354 - { 355 - armpmu->free_irq(armpmu); 356 - } 357 - 358 - static int 359 - armpmu_reserve_hardware(struct arm_pmu *armpmu) 360 - { 361 - int err = armpmu->request_irq(armpmu, armpmu_dispatch_irq); 362 - if (err) { 363 - armpmu_release_hardware(armpmu); 364 - return err; 365 - } 366 - 367 - return 0; 368 - } 369 - 370 - static void 371 - hw_perf_event_destroy(struct perf_event *event) 372 - { 373 - struct arm_pmu *armpmu = to_arm_pmu(event->pmu); 374 - atomic_t *active_events = &armpmu->active_events; 375 - struct mutex *pmu_reserve_mutex = &armpmu->reserve_mutex; 376 - 377 - if (atomic_dec_and_mutex_lock(active_events, pmu_reserve_mutex)) { 378 - armpmu_release_hardware(armpmu); 379 - mutex_unlock(pmu_reserve_mutex); 380 - } 381 353 } 382 354 383 355 static int ··· 421 455 static int armpmu_event_init(struct perf_event *event) 422 456 { 423 457 struct arm_pmu *armpmu = to_arm_pmu(event->pmu); 424 - int err = 0; 425 - atomic_t *active_events = &armpmu->active_events; 426 458 427 459 /* 428 460 * Reject CPU-affine events for CPUs that are of a different class to ··· 440 476 if (armpmu->map_event(event) == -ENOENT) 441 477 return -ENOENT; 442 478 443 - event->destroy = hw_perf_event_destroy; 444 - 445 - if (!atomic_inc_not_zero(active_events)) { 446 - mutex_lock(&armpmu->reserve_mutex); 447 - if (atomic_read(active_events) == 0) 448 - err = armpmu_reserve_hardware(armpmu); 449 - 450 - if (!err) 451 - atomic_inc(active_events); 452 - mutex_unlock(&armpmu->reserve_mutex); 453 - } 454 - 455 - if (err) 456 - return err; 457 - 458 - err = __hw_perf_event_init(event); 459 - if (err) 460 - hw_perf_event_destroy(event); 461 - 462 - return err; 479 + return __hw_perf_event_init(event); 463 480 } 464 481 465 482 static void armpmu_enable(struct pmu *pmu) ··· 498 553 .attrs = armpmu_common_attrs, 499 554 }; 500 555 501 - static void armpmu_init(struct arm_pmu *armpmu) 502 - { 503 - atomic_set(&armpmu->active_events, 0); 504 - mutex_init(&armpmu->reserve_mutex); 505 - 506 - armpmu->pmu = (struct pmu) { 507 - .pmu_enable = armpmu_enable, 508 - .pmu_disable = armpmu_disable, 509 - .event_init = armpmu_event_init, 510 - .add = armpmu_add, 511 - .del = armpmu_del, 512 - .start = armpmu_start, 513 - .stop = armpmu_stop, 514 - .read = armpmu_read, 515 - .filter_match = armpmu_filter_match, 516 - .attr_groups = armpmu->attr_groups, 517 - }; 518 - armpmu->attr_groups[ARMPMU_ATTR_GROUP_COMMON] = 519 - &armpmu_common_attr_group; 520 - } 521 - 522 556 /* Set at runtime when we know what CPU type we are. */ 523 557 static struct arm_pmu *__oprofile_cpu_pmu; 524 558 ··· 525 601 } 526 602 EXPORT_SYMBOL_GPL(perf_num_counters); 527 603 528 - static void cpu_pmu_enable_percpu_irq(void *data) 604 + void armpmu_free_irq(struct arm_pmu *armpmu, int cpu) 529 605 { 530 - int irq = *(int *)data; 606 + struct pmu_hw_events __percpu *hw_events = armpmu->hw_events; 607 + int irq = per_cpu(hw_events->irq, cpu); 531 608 532 - enable_percpu_irq(irq, IRQ_TYPE_NONE); 533 - } 609 + if (!cpumask_test_and_clear_cpu(cpu, &armpmu->active_irqs)) 610 + return; 534 611 535 - static void cpu_pmu_disable_percpu_irq(void *data) 536 - { 537 - int irq = *(int *)data; 538 - 539 - disable_percpu_irq(irq); 540 - } 541 - 542 - static void cpu_pmu_free_irq(struct arm_pmu *cpu_pmu) 543 - { 544 - int i, irq, irqs; 545 - struct platform_device *pmu_device = cpu_pmu->plat_device; 546 - struct pmu_hw_events __percpu *hw_events = cpu_pmu->hw_events; 547 - 548 - irqs = min(pmu_device->num_resources, num_possible_cpus()); 549 - 550 - irq = platform_get_irq(pmu_device, 0); 551 - if (irq > 0 && irq_is_percpu(irq)) { 552 - on_each_cpu_mask(&cpu_pmu->supported_cpus, 553 - cpu_pmu_disable_percpu_irq, &irq, 1); 612 + if (irq_is_percpu(irq)) { 554 613 free_percpu_irq(irq, &hw_events->percpu_pmu); 555 - } else { 556 - for (i = 0; i < irqs; ++i) { 557 - int cpu = i; 558 - 559 - if (cpu_pmu->irq_affinity) 560 - cpu = cpu_pmu->irq_affinity[i]; 561 - 562 - if (!cpumask_test_and_clear_cpu(cpu, &cpu_pmu->active_irqs)) 563 - continue; 564 - irq = platform_get_irq(pmu_device, i); 565 - if (irq > 0) 566 - free_irq(irq, per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 567 - } 614 + cpumask_clear(&armpmu->active_irqs); 615 + return; 568 616 } 617 + 618 + free_irq(irq, per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 569 619 } 570 620 571 - static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) 621 + void armpmu_free_irqs(struct arm_pmu *armpmu) 572 622 { 573 - int i, err, irq, irqs; 574 - struct platform_device *pmu_device = cpu_pmu->plat_device; 575 - struct pmu_hw_events __percpu *hw_events = cpu_pmu->hw_events; 623 + int cpu; 576 624 577 - if (!pmu_device) 578 - return -ENODEV; 625 + for_each_cpu(cpu, &armpmu->supported_cpus) 626 + armpmu_free_irq(armpmu, cpu); 627 + } 579 628 580 - irqs = min(pmu_device->num_resources, num_possible_cpus()); 581 - if (irqs < 1) { 582 - pr_warn_once("perf/ARM: No irqs for PMU defined, sampling events not supported\n"); 629 + int armpmu_request_irq(struct arm_pmu *armpmu, int cpu) 630 + { 631 + int err = 0; 632 + struct pmu_hw_events __percpu *hw_events = armpmu->hw_events; 633 + const irq_handler_t handler = armpmu_dispatch_irq; 634 + int irq = per_cpu(hw_events->irq, cpu); 635 + if (!irq) 583 636 return 0; 584 - } 585 637 586 - irq = platform_get_irq(pmu_device, 0); 587 - if (irq > 0 && irq_is_percpu(irq)) { 638 + if (irq_is_percpu(irq) && cpumask_empty(&armpmu->active_irqs)) { 588 639 err = request_percpu_irq(irq, handler, "arm-pmu", 589 640 &hw_events->percpu_pmu); 590 - if (err) { 591 - pr_err("unable to request IRQ%d for ARM PMU counters\n", 592 - irq); 593 - return err; 594 - } 641 + } else if (irq_is_percpu(irq)) { 642 + int other_cpu = cpumask_first(&armpmu->active_irqs); 643 + int other_irq = per_cpu(hw_events->irq, other_cpu); 595 644 596 - on_each_cpu_mask(&cpu_pmu->supported_cpus, 597 - cpu_pmu_enable_percpu_irq, &irq, 1); 645 + if (irq != other_irq) { 646 + pr_warn("mismatched PPIs detected.\n"); 647 + err = -EINVAL; 648 + } 598 649 } else { 599 - for (i = 0; i < irqs; ++i) { 600 - int cpu = i; 601 - 602 - err = 0; 603 - irq = platform_get_irq(pmu_device, i); 604 - if (irq < 0) 605 - continue; 606 - 607 - if (cpu_pmu->irq_affinity) 608 - cpu = cpu_pmu->irq_affinity[i]; 609 - 610 - /* 611 - * If we have a single PMU interrupt that we can't shift, 612 - * assume that we're running on a uniprocessor machine and 613 - * continue. Otherwise, continue without this interrupt. 614 - */ 615 - if (irq_set_affinity(irq, cpumask_of(cpu)) && irqs > 1) { 616 - pr_warn("unable to set irq affinity (irq=%d, cpu=%u)\n", 617 - irq, cpu); 618 - continue; 619 - } 620 - 621 - err = request_irq(irq, handler, 622 - IRQF_NOBALANCING | IRQF_NO_THREAD, "arm-pmu", 623 - per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 624 - if (err) { 625 - pr_err("unable to request IRQ%d for ARM PMU counters\n", 626 - irq); 627 - return err; 628 - } 629 - 630 - cpumask_set_cpu(cpu, &cpu_pmu->active_irqs); 631 - } 650 + err = request_irq(irq, handler, 651 + IRQF_NOBALANCING | IRQF_NO_THREAD, "arm-pmu", 652 + per_cpu_ptr(&hw_events->percpu_pmu, cpu)); 632 653 } 633 654 655 + if (err) { 656 + pr_err("unable to request IRQ%d for ARM PMU counters\n", 657 + irq); 658 + return err; 659 + } 660 + 661 + cpumask_set_cpu(cpu, &armpmu->active_irqs); 662 + 634 663 return 0; 664 + } 665 + 666 + int armpmu_request_irqs(struct arm_pmu *armpmu) 667 + { 668 + int cpu, err; 669 + 670 + for_each_cpu(cpu, &armpmu->supported_cpus) { 671 + err = armpmu_request_irq(armpmu, cpu); 672 + if (err) 673 + break; 674 + } 675 + 676 + return err; 677 + } 678 + 679 + static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu) 680 + { 681 + struct pmu_hw_events __percpu *hw_events = pmu->hw_events; 682 + return per_cpu(hw_events->irq, cpu); 635 683 } 636 684 637 685 /* ··· 615 719 static int arm_perf_starting_cpu(unsigned int cpu, struct hlist_node *node) 616 720 { 617 721 struct arm_pmu *pmu = hlist_entry_safe(node, struct arm_pmu, node); 722 + int irq; 618 723 619 724 if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 620 725 return 0; 621 726 if (pmu->reset) 622 727 pmu->reset(pmu); 728 + 729 + irq = armpmu_get_cpu_irq(pmu, cpu); 730 + if (irq) { 731 + if (irq_is_percpu(irq)) { 732 + enable_percpu_irq(irq, IRQ_TYPE_NONE); 733 + return 0; 734 + } 735 + 736 + if (irq_force_affinity(irq, cpumask_of(cpu)) && 737 + num_possible_cpus() > 1) { 738 + pr_warn("unable to set irq affinity (irq=%d, cpu=%u)\n", 739 + irq, cpu); 740 + } 741 + } 742 + 743 + return 0; 744 + } 745 + 746 + static int arm_perf_teardown_cpu(unsigned int cpu, struct hlist_node *node) 747 + { 748 + struct arm_pmu *pmu = hlist_entry_safe(node, struct arm_pmu, node); 749 + int irq; 750 + 751 + if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) 752 + return 0; 753 + 754 + irq = armpmu_get_cpu_irq(pmu, cpu); 755 + if (irq && irq_is_percpu(irq)) 756 + disable_percpu_irq(irq); 757 + 623 758 return 0; 624 759 } 625 760 ··· 755 828 static int cpu_pmu_init(struct arm_pmu *cpu_pmu) 756 829 { 757 830 int err; 758 - int cpu; 759 - struct pmu_hw_events __percpu *cpu_hw_events; 760 831 761 - cpu_hw_events = alloc_percpu(struct pmu_hw_events); 762 - if (!cpu_hw_events) 763 - return -ENOMEM; 764 - 765 - err = cpuhp_state_add_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 766 - &cpu_pmu->node); 832 + err = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_STARTING, 833 + &cpu_pmu->node); 767 834 if (err) 768 - goto out_free; 835 + goto out; 769 836 770 837 err = cpu_pm_pmu_register(cpu_pmu); 771 838 if (err) 772 839 goto out_unregister; 773 - 774 - for_each_possible_cpu(cpu) { 775 - struct pmu_hw_events *events = per_cpu_ptr(cpu_hw_events, cpu); 776 - raw_spin_lock_init(&events->pmu_lock); 777 - events->percpu_pmu = cpu_pmu; 778 - } 779 - 780 - cpu_pmu->hw_events = cpu_hw_events; 781 - cpu_pmu->request_irq = cpu_pmu_request_irq; 782 - cpu_pmu->free_irq = cpu_pmu_free_irq; 783 - 784 - /* Ensure the PMU has sane values out of reset. */ 785 - if (cpu_pmu->reset) 786 - on_each_cpu_mask(&cpu_pmu->supported_cpus, cpu_pmu->reset, 787 - cpu_pmu, 1); 788 - 789 - /* If no interrupts available, set the corresponding capability flag */ 790 - if (!platform_get_irq(cpu_pmu->plat_device, 0)) 791 - cpu_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; 792 - 793 - /* 794 - * This is a CPU PMU potentially in a heterogeneous configuration (e.g. 795 - * big.LITTLE). This is not an uncore PMU, and we have taken ctx 796 - * sharing into account (e.g. with our pmu::filter_match callback and 797 - * pmu::event_init group validation). 798 - */ 799 - cpu_pmu->pmu.capabilities |= PERF_PMU_CAP_HETEROGENEOUS_CPUS; 800 840 801 841 return 0; 802 842 803 843 out_unregister: 804 844 cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 805 845 &cpu_pmu->node); 806 - out_free: 807 - free_percpu(cpu_hw_events); 846 + out: 808 847 return err; 809 848 } 810 849 ··· 779 886 cpu_pm_pmu_unregister(cpu_pmu); 780 887 cpuhp_state_remove_instance_nocalls(CPUHP_AP_PERF_ARM_STARTING, 781 888 &cpu_pmu->node); 782 - free_percpu(cpu_pmu->hw_events); 783 889 } 784 890 785 - /* 786 - * CPU PMU identification and probing. 787 - */ 788 - static int probe_current_pmu(struct arm_pmu *pmu, 789 - const struct pmu_probe_info *info) 891 + struct arm_pmu *armpmu_alloc(void) 790 892 { 791 - int cpu = get_cpu(); 792 - unsigned int cpuid = read_cpuid_id(); 793 - int ret = -ENODEV; 794 - 795 - pr_info("probing PMU on CPU %d\n", cpu); 796 - 797 - for (; info->init != NULL; info++) { 798 - if ((cpuid & info->mask) != info->cpuid) 799 - continue; 800 - ret = info->init(pmu); 801 - break; 802 - } 803 - 804 - put_cpu(); 805 - return ret; 806 - } 807 - 808 - static int of_pmu_irq_cfg(struct arm_pmu *pmu) 809 - { 810 - int *irqs, i = 0; 811 - bool using_spi = false; 812 - struct platform_device *pdev = pmu->plat_device; 813 - 814 - irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL); 815 - if (!irqs) 816 - return -ENOMEM; 817 - 818 - do { 819 - struct device_node *dn; 820 - int cpu, irq; 821 - 822 - /* See if we have an affinity entry */ 823 - dn = of_parse_phandle(pdev->dev.of_node, "interrupt-affinity", i); 824 - if (!dn) 825 - break; 826 - 827 - /* Check the IRQ type and prohibit a mix of PPIs and SPIs */ 828 - irq = platform_get_irq(pdev, i); 829 - if (irq > 0) { 830 - bool spi = !irq_is_percpu(irq); 831 - 832 - if (i > 0 && spi != using_spi) { 833 - pr_err("PPI/SPI IRQ type mismatch for %s!\n", 834 - dn->name); 835 - of_node_put(dn); 836 - kfree(irqs); 837 - return -EINVAL; 838 - } 839 - 840 - using_spi = spi; 841 - } 842 - 843 - /* Now look up the logical CPU number */ 844 - for_each_possible_cpu(cpu) { 845 - struct device_node *cpu_dn; 846 - 847 - cpu_dn = of_cpu_device_node_get(cpu); 848 - of_node_put(cpu_dn); 849 - 850 - if (dn == cpu_dn) 851 - break; 852 - } 853 - 854 - if (cpu >= nr_cpu_ids) { 855 - pr_warn("Failed to find logical CPU for %s\n", 856 - dn->name); 857 - of_node_put(dn); 858 - cpumask_setall(&pmu->supported_cpus); 859 - break; 860 - } 861 - of_node_put(dn); 862 - 863 - /* For SPIs, we need to track the affinity per IRQ */ 864 - if (using_spi) { 865 - if (i >= pdev->num_resources) 866 - break; 867 - 868 - irqs[i] = cpu; 869 - } 870 - 871 - /* Keep track of the CPUs containing this PMU type */ 872 - cpumask_set_cpu(cpu, &pmu->supported_cpus); 873 - i++; 874 - } while (1); 875 - 876 - /* If we didn't manage to parse anything, try the interrupt affinity */ 877 - if (cpumask_weight(&pmu->supported_cpus) == 0) { 878 - int irq = platform_get_irq(pdev, 0); 879 - 880 - if (irq > 0 && irq_is_percpu(irq)) { 881 - /* If using PPIs, check the affinity of the partition */ 882 - int ret; 883 - 884 - ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus); 885 - if (ret) { 886 - kfree(irqs); 887 - return ret; 888 - } 889 - } else { 890 - /* Otherwise default to all CPUs */ 891 - cpumask_setall(&pmu->supported_cpus); 892 - } 893 - } 894 - 895 - /* If we matched up the IRQ affinities, use them to route the SPIs */ 896 - if (using_spi && i == pdev->num_resources) 897 - pmu->irq_affinity = irqs; 898 - else 899 - kfree(irqs); 900 - 901 - return 0; 902 - } 903 - 904 - int arm_pmu_device_probe(struct platform_device *pdev, 905 - const struct of_device_id *of_table, 906 - const struct pmu_probe_info *probe_table) 907 - { 908 - const struct of_device_id *of_id; 909 - const int (*init_fn)(struct arm_pmu *); 910 - struct device_node *node = pdev->dev.of_node; 911 893 struct arm_pmu *pmu; 912 - int ret = -ENODEV; 894 + int cpu; 913 895 914 - pmu = kzalloc(sizeof(struct arm_pmu), GFP_KERNEL); 896 + pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); 915 897 if (!pmu) { 916 898 pr_info("failed to allocate PMU device!\n"); 917 - return -ENOMEM; 899 + goto out; 918 900 } 919 901 920 - armpmu_init(pmu); 921 - 922 - pmu->plat_device = pdev; 923 - 924 - if (node && (of_id = of_match_node(of_table, pdev->dev.of_node))) { 925 - init_fn = of_id->data; 926 - 927 - pmu->secure_access = of_property_read_bool(pdev->dev.of_node, 928 - "secure-reg-access"); 929 - 930 - /* arm64 systems boot only as non-secure */ 931 - if (IS_ENABLED(CONFIG_ARM64) && pmu->secure_access) { 932 - pr_warn("ignoring \"secure-reg-access\" property for arm64\n"); 933 - pmu->secure_access = false; 934 - } 935 - 936 - ret = of_pmu_irq_cfg(pmu); 937 - if (!ret) 938 - ret = init_fn(pmu); 939 - } else if (probe_table) { 940 - cpumask_setall(&pmu->supported_cpus); 941 - ret = probe_current_pmu(pmu, probe_table); 902 + pmu->hw_events = alloc_percpu(struct pmu_hw_events); 903 + if (!pmu->hw_events) { 904 + pr_info("failed to allocate per-cpu PMU data.\n"); 905 + goto out_free_pmu; 942 906 } 943 907 944 - if (ret) { 945 - pr_info("%s: failed to probe PMU!\n", of_node_full_name(node)); 946 - goto out_free; 908 + pmu->pmu = (struct pmu) { 909 + .pmu_enable = armpmu_enable, 910 + .pmu_disable = armpmu_disable, 911 + .event_init = armpmu_event_init, 912 + .add = armpmu_add, 913 + .del = armpmu_del, 914 + .start = armpmu_start, 915 + .stop = armpmu_stop, 916 + .read = armpmu_read, 917 + .filter_match = armpmu_filter_match, 918 + .attr_groups = pmu->attr_groups, 919 + /* 920 + * This is a CPU PMU potentially in a heterogeneous 921 + * configuration (e.g. big.LITTLE). This is not an uncore PMU, 922 + * and we have taken ctx sharing into account (e.g. with our 923 + * pmu::filter_match callback and pmu::event_init group 924 + * validation). 925 + */ 926 + .capabilities = PERF_PMU_CAP_HETEROGENEOUS_CPUS, 927 + }; 928 + 929 + pmu->attr_groups[ARMPMU_ATTR_GROUP_COMMON] = 930 + &armpmu_common_attr_group; 931 + 932 + for_each_possible_cpu(cpu) { 933 + struct pmu_hw_events *events; 934 + 935 + events = per_cpu_ptr(pmu->hw_events, cpu); 936 + raw_spin_lock_init(&events->pmu_lock); 937 + events->percpu_pmu = pmu; 947 938 } 948 939 940 + return pmu; 941 + 942 + out_free_pmu: 943 + kfree(pmu); 944 + out: 945 + return NULL; 946 + } 947 + 948 + void armpmu_free(struct arm_pmu *pmu) 949 + { 950 + free_percpu(pmu->hw_events); 951 + kfree(pmu); 952 + } 953 + 954 + int armpmu_register(struct arm_pmu *pmu) 955 + { 956 + int ret; 949 957 950 958 ret = cpu_pmu_init(pmu); 951 959 if (ret) 952 - goto out_free; 960 + return ret; 953 961 954 962 ret = perf_pmu_register(&pmu->pmu, pmu->name, -1); 955 963 if (ret) ··· 860 1066 __oprofile_cpu_pmu = pmu; 861 1067 862 1068 pr_info("enabled with %s PMU driver, %d counters available\n", 863 - pmu->name, pmu->num_events); 1069 + pmu->name, pmu->num_events); 864 1070 865 1071 return 0; 866 1072 867 1073 out_destroy: 868 1074 cpu_pmu_destroy(pmu); 869 - out_free: 870 - pr_info("%s: failed to register PMU devices!\n", 871 - of_node_full_name(node)); 872 - kfree(pmu->irq_affinity); 873 - kfree(pmu); 874 1075 return ret; 875 1076 } 876 1077 ··· 875 1086 876 1087 ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_STARTING, 877 1088 "perf/arm/pmu:starting", 878 - arm_perf_starting_cpu, NULL); 1089 + arm_perf_starting_cpu, 1090 + arm_perf_teardown_cpu); 879 1091 if (ret) 880 1092 pr_err("CPU hotplug notifier for ARM PMU could not be registered: %d\n", 881 1093 ret);
+256
drivers/perf/arm_pmu_acpi.c
··· 1 + /* 2 + * ACPI probing code for ARM performance counters. 3 + * 4 + * Copyright (C) 2017 ARM Ltd. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License version 2 as 8 + * published by the Free Software Foundation. 9 + */ 10 + 11 + #include <linux/acpi.h> 12 + #include <linux/cpumask.h> 13 + #include <linux/init.h> 14 + #include <linux/percpu.h> 15 + #include <linux/perf/arm_pmu.h> 16 + 17 + #include <asm/cputype.h> 18 + 19 + static DEFINE_PER_CPU(struct arm_pmu *, probed_pmus); 20 + static DEFINE_PER_CPU(int, pmu_irqs); 21 + 22 + static int arm_pmu_acpi_register_irq(int cpu) 23 + { 24 + struct acpi_madt_generic_interrupt *gicc; 25 + int gsi, trigger; 26 + 27 + gicc = acpi_cpu_get_madt_gicc(cpu); 28 + if (WARN_ON(!gicc)) 29 + return -EINVAL; 30 + 31 + gsi = gicc->performance_interrupt; 32 + if (gicc->flags & ACPI_MADT_PERFORMANCE_IRQ_MODE) 33 + trigger = ACPI_EDGE_SENSITIVE; 34 + else 35 + trigger = ACPI_LEVEL_SENSITIVE; 36 + 37 + /* 38 + * Helpfully, the MADT GICC doesn't have a polarity flag for the 39 + * "performance interrupt". Luckily, on compliant GICs the polarity is 40 + * a fixed value in HW (for both SPIs and PPIs) that we cannot change 41 + * from SW. 42 + * 43 + * Here we pass in ACPI_ACTIVE_HIGH to keep the core code happy. This 44 + * may not match the real polarity, but that should not matter. 45 + * 46 + * Other interrupt controllers are not supported with ACPI. 47 + */ 48 + return acpi_register_gsi(NULL, gsi, trigger, ACPI_ACTIVE_HIGH); 49 + } 50 + 51 + static void arm_pmu_acpi_unregister_irq(int cpu) 52 + { 53 + struct acpi_madt_generic_interrupt *gicc; 54 + int gsi; 55 + 56 + gicc = acpi_cpu_get_madt_gicc(cpu); 57 + if (!gicc) 58 + return; 59 + 60 + gsi = gicc->performance_interrupt; 61 + acpi_unregister_gsi(gsi); 62 + } 63 + 64 + static int arm_pmu_acpi_parse_irqs(void) 65 + { 66 + int irq, cpu, irq_cpu, err; 67 + 68 + for_each_possible_cpu(cpu) { 69 + irq = arm_pmu_acpi_register_irq(cpu); 70 + if (irq < 0) { 71 + err = irq; 72 + pr_warn("Unable to parse ACPI PMU IRQ for CPU%d: %d\n", 73 + cpu, err); 74 + goto out_err; 75 + } else if (irq == 0) { 76 + pr_warn("No ACPI PMU IRQ for CPU%d\n", cpu); 77 + } 78 + 79 + per_cpu(pmu_irqs, cpu) = irq; 80 + } 81 + 82 + return 0; 83 + 84 + out_err: 85 + for_each_possible_cpu(cpu) { 86 + irq = per_cpu(pmu_irqs, cpu); 87 + if (!irq) 88 + continue; 89 + 90 + arm_pmu_acpi_unregister_irq(cpu); 91 + 92 + /* 93 + * Blat all copies of the IRQ so that we only unregister the 94 + * corresponding GSI once (e.g. when we have PPIs). 95 + */ 96 + for_each_possible_cpu(irq_cpu) { 97 + if (per_cpu(pmu_irqs, irq_cpu) == irq) 98 + per_cpu(pmu_irqs, irq_cpu) = 0; 99 + } 100 + } 101 + 102 + return err; 103 + } 104 + 105 + static struct arm_pmu *arm_pmu_acpi_find_alloc_pmu(void) 106 + { 107 + unsigned long cpuid = read_cpuid_id(); 108 + struct arm_pmu *pmu; 109 + int cpu; 110 + 111 + for_each_possible_cpu(cpu) { 112 + pmu = per_cpu(probed_pmus, cpu); 113 + if (!pmu || pmu->acpi_cpuid != cpuid) 114 + continue; 115 + 116 + return pmu; 117 + } 118 + 119 + pmu = armpmu_alloc(); 120 + if (!pmu) { 121 + pr_warn("Unable to allocate PMU for CPU%d\n", 122 + smp_processor_id()); 123 + return NULL; 124 + } 125 + 126 + pmu->acpi_cpuid = cpuid; 127 + 128 + return pmu; 129 + } 130 + 131 + /* 132 + * This must run before the common arm_pmu hotplug logic, so that we can 133 + * associate a CPU and its interrupt before the common code tries to manage the 134 + * affinity and so on. 135 + * 136 + * Note that hotplug events are serialized, so we cannot race with another CPU 137 + * coming up. The perf core won't open events while a hotplug event is in 138 + * progress. 139 + */ 140 + static int arm_pmu_acpi_cpu_starting(unsigned int cpu) 141 + { 142 + struct arm_pmu *pmu; 143 + struct pmu_hw_events __percpu *hw_events; 144 + int irq; 145 + 146 + /* If we've already probed this CPU, we have nothing to do */ 147 + if (per_cpu(probed_pmus, cpu)) 148 + return 0; 149 + 150 + irq = per_cpu(pmu_irqs, cpu); 151 + 152 + pmu = arm_pmu_acpi_find_alloc_pmu(); 153 + if (!pmu) 154 + return -ENOMEM; 155 + 156 + cpumask_set_cpu(cpu, &pmu->supported_cpus); 157 + 158 + per_cpu(probed_pmus, cpu) = pmu; 159 + 160 + /* 161 + * Log and request the IRQ so the core arm_pmu code can manage it. In 162 + * some situations (e.g. mismatched PPIs), we may fail to request the 163 + * IRQ. However, it may be too late for us to do anything about it. 164 + * The common ARM PMU code will log a warning in this case. 165 + */ 166 + hw_events = pmu->hw_events; 167 + per_cpu(hw_events->irq, cpu) = irq; 168 + armpmu_request_irq(pmu, cpu); 169 + 170 + /* 171 + * Ideally, we'd probe the PMU here when we find the first matching 172 + * CPU. We can't do that for several reasons; see the comment in 173 + * arm_pmu_acpi_init(). 174 + * 175 + * So for the time being, we're done. 176 + */ 177 + return 0; 178 + } 179 + 180 + int arm_pmu_acpi_probe(armpmu_init_fn init_fn) 181 + { 182 + int pmu_idx = 0; 183 + int cpu, ret; 184 + 185 + if (acpi_disabled) 186 + return 0; 187 + 188 + /* 189 + * Initialise and register the set of PMUs which we know about right 190 + * now. Ideally we'd do this in arm_pmu_acpi_cpu_starting() so that we 191 + * could handle late hotplug, but this may lead to deadlock since we 192 + * might try to register a hotplug notifier instance from within a 193 + * hotplug notifier. 194 + * 195 + * There's also the problem of having access to the right init_fn, 196 + * without tying this too deeply into the "real" PMU driver. 197 + * 198 + * For the moment, as with the platform/DT case, we need at least one 199 + * of a PMU's CPUs to be online at probe time. 200 + */ 201 + for_each_possible_cpu(cpu) { 202 + struct arm_pmu *pmu = per_cpu(probed_pmus, cpu); 203 + char *base_name; 204 + 205 + if (!pmu || pmu->name) 206 + continue; 207 + 208 + ret = init_fn(pmu); 209 + if (ret == -ENODEV) { 210 + /* PMU not handled by this driver, or not present */ 211 + continue; 212 + } else if (ret) { 213 + pr_warn("Unable to initialise PMU for CPU%d\n", cpu); 214 + return ret; 215 + } 216 + 217 + base_name = pmu->name; 218 + pmu->name = kasprintf(GFP_KERNEL, "%s_%d", base_name, pmu_idx++); 219 + if (!pmu->name) { 220 + pr_warn("Unable to allocate PMU name for CPU%d\n", cpu); 221 + return -ENOMEM; 222 + } 223 + 224 + ret = armpmu_register(pmu); 225 + if (ret) { 226 + pr_warn("Failed to register PMU for CPU%d\n", cpu); 227 + return ret; 228 + } 229 + } 230 + 231 + return 0; 232 + } 233 + 234 + static int arm_pmu_acpi_init(void) 235 + { 236 + int ret; 237 + 238 + if (acpi_disabled) 239 + return 0; 240 + 241 + /* 242 + * We can't request IRQs yet, since we don't know the cookie value 243 + * until we know which CPUs share the same logical PMU. We'll handle 244 + * that in arm_pmu_acpi_cpu_starting(). 245 + */ 246 + ret = arm_pmu_acpi_parse_irqs(); 247 + if (ret) 248 + return ret; 249 + 250 + ret = cpuhp_setup_state(CPUHP_AP_PERF_ARM_ACPI_STARTING, 251 + "perf/arm/pmu_acpi:starting", 252 + arm_pmu_acpi_cpu_starting, NULL); 253 + 254 + return ret; 255 + } 256 + subsys_initcall(arm_pmu_acpi_init)
+235
drivers/perf/arm_pmu_platform.c
··· 1 + /* 2 + * platform_device probing code for ARM performance counters. 3 + * 4 + * Copyright (C) 2009 picoChip Designs, Ltd., Jamie Iles 5 + * Copyright (C) 2010 ARM Ltd., Will Deacon <will.deacon@arm.com> 6 + */ 7 + #define pr_fmt(fmt) "hw perfevents: " fmt 8 + 9 + #include <linux/bug.h> 10 + #include <linux/cpumask.h> 11 + #include <linux/device.h> 12 + #include <linux/errno.h> 13 + #include <linux/irq.h> 14 + #include <linux/irqdesc.h> 15 + #include <linux/kconfig.h> 16 + #include <linux/of.h> 17 + #include <linux/of_device.h> 18 + #include <linux/percpu.h> 19 + #include <linux/perf/arm_pmu.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/printk.h> 22 + #include <linux/smp.h> 23 + 24 + static int probe_current_pmu(struct arm_pmu *pmu, 25 + const struct pmu_probe_info *info) 26 + { 27 + int cpu = get_cpu(); 28 + unsigned int cpuid = read_cpuid_id(); 29 + int ret = -ENODEV; 30 + 31 + pr_info("probing PMU on CPU %d\n", cpu); 32 + 33 + for (; info->init != NULL; info++) { 34 + if ((cpuid & info->mask) != info->cpuid) 35 + continue; 36 + ret = info->init(pmu); 37 + break; 38 + } 39 + 40 + put_cpu(); 41 + return ret; 42 + } 43 + 44 + static int pmu_parse_percpu_irq(struct arm_pmu *pmu, int irq) 45 + { 46 + int cpu, ret; 47 + struct pmu_hw_events __percpu *hw_events = pmu->hw_events; 48 + 49 + ret = irq_get_percpu_devid_partition(irq, &pmu->supported_cpus); 50 + if (ret) 51 + return ret; 52 + 53 + for_each_cpu(cpu, &pmu->supported_cpus) 54 + per_cpu(hw_events->irq, cpu) = irq; 55 + 56 + return 0; 57 + } 58 + 59 + static bool pmu_has_irq_affinity(struct device_node *node) 60 + { 61 + return !!of_find_property(node, "interrupt-affinity", NULL); 62 + } 63 + 64 + static int pmu_parse_irq_affinity(struct device_node *node, int i) 65 + { 66 + struct device_node *dn; 67 + int cpu; 68 + 69 + /* 70 + * If we don't have an interrupt-affinity property, we guess irq 71 + * affinity matches our logical CPU order, as we used to assume. 72 + * This is fragile, so we'll warn in pmu_parse_irqs(). 73 + */ 74 + if (!pmu_has_irq_affinity(node)) 75 + return i; 76 + 77 + dn = of_parse_phandle(node, "interrupt-affinity", i); 78 + if (!dn) { 79 + pr_warn("failed to parse interrupt-affinity[%d] for %s\n", 80 + i, node->name); 81 + return -EINVAL; 82 + } 83 + 84 + /* Now look up the logical CPU number */ 85 + for_each_possible_cpu(cpu) { 86 + struct device_node *cpu_dn; 87 + 88 + cpu_dn = of_cpu_device_node_get(cpu); 89 + of_node_put(cpu_dn); 90 + 91 + if (dn == cpu_dn) 92 + break; 93 + } 94 + 95 + if (cpu >= nr_cpu_ids) { 96 + pr_warn("failed to find logical CPU for %s\n", dn->name); 97 + } 98 + 99 + of_node_put(dn); 100 + 101 + return cpu; 102 + } 103 + 104 + static int pmu_parse_irqs(struct arm_pmu *pmu) 105 + { 106 + int i = 0, num_irqs; 107 + struct platform_device *pdev = pmu->plat_device; 108 + struct pmu_hw_events __percpu *hw_events = pmu->hw_events; 109 + 110 + num_irqs = platform_irq_count(pdev); 111 + if (num_irqs < 0) { 112 + pr_err("unable to count PMU IRQs\n"); 113 + return num_irqs; 114 + } 115 + 116 + /* 117 + * In this case we have no idea which CPUs are covered by the PMU. 118 + * To match our prior behaviour, we assume all CPUs in this case. 119 + */ 120 + if (num_irqs == 0) { 121 + pr_warn("no irqs for PMU, sampling events not supported\n"); 122 + pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; 123 + cpumask_setall(&pmu->supported_cpus); 124 + return 0; 125 + } 126 + 127 + if (num_irqs == 1) { 128 + int irq = platform_get_irq(pdev, 0); 129 + if (irq && irq_is_percpu(irq)) 130 + return pmu_parse_percpu_irq(pmu, irq); 131 + } 132 + 133 + if (!pmu_has_irq_affinity(pdev->dev.of_node)) { 134 + pr_warn("no interrupt-affinity property for %s, guessing.\n", 135 + of_node_full_name(pdev->dev.of_node)); 136 + } 137 + 138 + /* 139 + * Some platforms have all PMU IRQs OR'd into a single IRQ, with a 140 + * special platdata function that attempts to demux them. 141 + */ 142 + if (dev_get_platdata(&pdev->dev)) 143 + cpumask_setall(&pmu->supported_cpus); 144 + 145 + for (i = 0; i < num_irqs; i++) { 146 + int cpu, irq; 147 + 148 + irq = platform_get_irq(pdev, i); 149 + if (WARN_ON(irq <= 0)) 150 + continue; 151 + 152 + if (irq_is_percpu(irq)) { 153 + pr_warn("multiple PPIs or mismatched SPI/PPI detected\n"); 154 + return -EINVAL; 155 + } 156 + 157 + cpu = pmu_parse_irq_affinity(pdev->dev.of_node, i); 158 + if (cpu < 0) 159 + return cpu; 160 + if (cpu >= nr_cpu_ids) 161 + continue; 162 + 163 + if (per_cpu(hw_events->irq, cpu)) { 164 + pr_warn("multiple PMU IRQs for the same CPU detected\n"); 165 + return -EINVAL; 166 + } 167 + 168 + per_cpu(hw_events->irq, cpu) = irq; 169 + cpumask_set_cpu(cpu, &pmu->supported_cpus); 170 + } 171 + 172 + return 0; 173 + } 174 + 175 + int arm_pmu_device_probe(struct platform_device *pdev, 176 + const struct of_device_id *of_table, 177 + const struct pmu_probe_info *probe_table) 178 + { 179 + const struct of_device_id *of_id; 180 + armpmu_init_fn init_fn; 181 + struct device_node *node = pdev->dev.of_node; 182 + struct arm_pmu *pmu; 183 + int ret = -ENODEV; 184 + 185 + pmu = armpmu_alloc(); 186 + if (!pmu) 187 + return -ENOMEM; 188 + 189 + pmu->plat_device = pdev; 190 + 191 + ret = pmu_parse_irqs(pmu); 192 + if (ret) 193 + goto out_free; 194 + 195 + if (node && (of_id = of_match_node(of_table, pdev->dev.of_node))) { 196 + init_fn = of_id->data; 197 + 198 + pmu->secure_access = of_property_read_bool(pdev->dev.of_node, 199 + "secure-reg-access"); 200 + 201 + /* arm64 systems boot only as non-secure */ 202 + if (IS_ENABLED(CONFIG_ARM64) && pmu->secure_access) { 203 + pr_warn("ignoring \"secure-reg-access\" property for arm64\n"); 204 + pmu->secure_access = false; 205 + } 206 + 207 + ret = init_fn(pmu); 208 + } else if (probe_table) { 209 + cpumask_setall(&pmu->supported_cpus); 210 + ret = probe_current_pmu(pmu, probe_table); 211 + } 212 + 213 + if (ret) { 214 + pr_info("%s: failed to probe PMU!\n", of_node_full_name(node)); 215 + goto out_free; 216 + } 217 + 218 + ret = armpmu_request_irqs(pmu); 219 + if (ret) 220 + goto out_free_irqs; 221 + 222 + ret = armpmu_register(pmu); 223 + if (ret) 224 + goto out_free; 225 + 226 + return 0; 227 + 228 + out_free_irqs: 229 + armpmu_free_irqs(pmu); 230 + out_free: 231 + pr_info("%s: failed to register PMU devices!\n", 232 + of_node_full_name(node)); 233 + armpmu_free(pmu); 234 + return ret; 235 + }
+849
drivers/perf/qcom_l3_pmu.c
··· 1 + /* 2 + * Driver for the L3 cache PMUs in Qualcomm Technologies chips. 3 + * 4 + * The driver supports a distributed cache architecture where the overall 5 + * cache for a socket is comprised of multiple slices each with its own PMU. 6 + * Access to each individual PMU is provided even though all CPUs share all 7 + * the slices. User space needs to aggregate to individual counts to provide 8 + * a global picture. 9 + * 10 + * See Documentation/perf/qcom_l3_pmu.txt for more details. 11 + * 12 + * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. 13 + * 14 + * This program is free software; you can redistribute it and/or modify 15 + * it under the terms of the GNU General Public License version 2 and 16 + * only version 2 as published by the Free Software Foundation. 17 + * 18 + * This program is distributed in the hope that it will be useful, 19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 + * GNU General Public License for more details. 22 + */ 23 + 24 + #include <linux/acpi.h> 25 + #include <linux/bitops.h> 26 + #include <linux/interrupt.h> 27 + #include <linux/io.h> 28 + #include <linux/list.h> 29 + #include <linux/module.h> 30 + #include <linux/perf_event.h> 31 + #include <linux/platform_device.h> 32 + 33 + /* 34 + * General constants 35 + */ 36 + 37 + /* Number of counters on each PMU */ 38 + #define L3_NUM_COUNTERS 8 39 + /* Mask for the event type field within perf_event_attr.config and EVTYPE reg */ 40 + #define L3_EVTYPE_MASK 0xFF 41 + /* 42 + * Bit position of the 'long counter' flag within perf_event_attr.config. 43 + * Reserve some space between the event type and this flag to allow expansion 44 + * in the event type field. 45 + */ 46 + #define L3_EVENT_LC_BIT 32 47 + 48 + /* 49 + * Register offsets 50 + */ 51 + 52 + /* Perfmon registers */ 53 + #define L3_HML3_PM_CR 0x000 54 + #define L3_HML3_PM_EVCNTR(__cntr) (0x420 + ((__cntr) & 0x7) * 8) 55 + #define L3_HML3_PM_CNTCTL(__cntr) (0x120 + ((__cntr) & 0x7) * 8) 56 + #define L3_HML3_PM_EVTYPE(__cntr) (0x220 + ((__cntr) & 0x7) * 8) 57 + #define L3_HML3_PM_FILTRA 0x300 58 + #define L3_HML3_PM_FILTRB 0x308 59 + #define L3_HML3_PM_FILTRC 0x310 60 + #define L3_HML3_PM_FILTRAM 0x304 61 + #define L3_HML3_PM_FILTRBM 0x30C 62 + #define L3_HML3_PM_FILTRCM 0x314 63 + 64 + /* Basic counter registers */ 65 + #define L3_M_BC_CR 0x500 66 + #define L3_M_BC_SATROLL_CR 0x504 67 + #define L3_M_BC_CNTENSET 0x508 68 + #define L3_M_BC_CNTENCLR 0x50C 69 + #define L3_M_BC_INTENSET 0x510 70 + #define L3_M_BC_INTENCLR 0x514 71 + #define L3_M_BC_GANG 0x718 72 + #define L3_M_BC_OVSR 0x740 73 + #define L3_M_BC_IRQCTL 0x96C 74 + 75 + /* 76 + * Bit field definitions 77 + */ 78 + 79 + /* L3_HML3_PM_CR */ 80 + #define PM_CR_RESET (0) 81 + 82 + /* L3_HML3_PM_XCNTCTL/L3_HML3_PM_CNTCTLx */ 83 + #define PMCNT_RESET (0) 84 + 85 + /* L3_HML3_PM_EVTYPEx */ 86 + #define EVSEL(__val) ((__val) & L3_EVTYPE_MASK) 87 + 88 + /* Reset value for all the filter registers */ 89 + #define PM_FLTR_RESET (0) 90 + 91 + /* L3_M_BC_CR */ 92 + #define BC_RESET (1UL << 1) 93 + #define BC_ENABLE (1UL << 0) 94 + 95 + /* L3_M_BC_SATROLL_CR */ 96 + #define BC_SATROLL_CR_RESET (0) 97 + 98 + /* L3_M_BC_CNTENSET */ 99 + #define PMCNTENSET(__cntr) (1UL << ((__cntr) & 0x7)) 100 + 101 + /* L3_M_BC_CNTENCLR */ 102 + #define PMCNTENCLR(__cntr) (1UL << ((__cntr) & 0x7)) 103 + #define BC_CNTENCLR_RESET (0xFF) 104 + 105 + /* L3_M_BC_INTENSET */ 106 + #define PMINTENSET(__cntr) (1UL << ((__cntr) & 0x7)) 107 + 108 + /* L3_M_BC_INTENCLR */ 109 + #define PMINTENCLR(__cntr) (1UL << ((__cntr) & 0x7)) 110 + #define BC_INTENCLR_RESET (0xFF) 111 + 112 + /* L3_M_BC_GANG */ 113 + #define GANG_EN(__cntr) (1UL << ((__cntr) & 0x7)) 114 + #define BC_GANG_RESET (0) 115 + 116 + /* L3_M_BC_OVSR */ 117 + #define PMOVSRCLR(__cntr) (1UL << ((__cntr) & 0x7)) 118 + #define PMOVSRCLR_RESET (0xFF) 119 + 120 + /* L3_M_BC_IRQCTL */ 121 + #define PMIRQONMSBEN(__cntr) (1UL << ((__cntr) & 0x7)) 122 + #define BC_IRQCTL_RESET (0x0) 123 + 124 + /* 125 + * Events 126 + */ 127 + 128 + #define L3_EVENT_CYCLES 0x01 129 + #define L3_EVENT_READ_HIT 0x20 130 + #define L3_EVENT_READ_MISS 0x21 131 + #define L3_EVENT_READ_HIT_D 0x22 132 + #define L3_EVENT_READ_MISS_D 0x23 133 + #define L3_EVENT_WRITE_HIT 0x24 134 + #define L3_EVENT_WRITE_MISS 0x25 135 + 136 + /* 137 + * Decoding of settings from perf_event_attr 138 + * 139 + * The config format for perf events is: 140 + * - config: bits 0-7: event type 141 + * bit 32: HW counter size requested, 0: 32 bits, 1: 64 bits 142 + */ 143 + 144 + static inline u32 get_event_type(struct perf_event *event) 145 + { 146 + return (event->attr.config) & L3_EVTYPE_MASK; 147 + } 148 + 149 + static inline bool event_uses_long_counter(struct perf_event *event) 150 + { 151 + return !!(event->attr.config & BIT_ULL(L3_EVENT_LC_BIT)); 152 + } 153 + 154 + static inline int event_num_counters(struct perf_event *event) 155 + { 156 + return event_uses_long_counter(event) ? 2 : 1; 157 + } 158 + 159 + /* 160 + * Main PMU, inherits from the core perf PMU type 161 + */ 162 + struct l3cache_pmu { 163 + struct pmu pmu; 164 + struct hlist_node node; 165 + void __iomem *regs; 166 + struct perf_event *events[L3_NUM_COUNTERS]; 167 + unsigned long used_mask[BITS_TO_LONGS(L3_NUM_COUNTERS)]; 168 + cpumask_t cpumask; 169 + }; 170 + 171 + #define to_l3cache_pmu(p) (container_of(p, struct l3cache_pmu, pmu)) 172 + 173 + /* 174 + * Type used to group hardware counter operations 175 + * 176 + * Used to implement two types of hardware counters, standard (32bits) and 177 + * long (64bits). The hardware supports counter chaining which we use to 178 + * implement long counters. This support is exposed via the 'lc' flag field 179 + * in perf_event_attr.config. 180 + */ 181 + struct l3cache_event_ops { 182 + /* Called to start event monitoring */ 183 + void (*start)(struct perf_event *event); 184 + /* Called to stop event monitoring */ 185 + void (*stop)(struct perf_event *event, int flags); 186 + /* Called to update the perf_event */ 187 + void (*update)(struct perf_event *event); 188 + }; 189 + 190 + /* 191 + * Implementation of long counter operations 192 + * 193 + * 64bit counters are implemented by chaining two of the 32bit physical 194 + * counters. The PMU only supports chaining of adjacent even/odd pairs 195 + * and for simplicity the driver always configures the odd counter to 196 + * count the overflows of the lower-numbered even counter. Note that since 197 + * the resulting hardware counter is 64bits no IRQs are required to maintain 198 + * the software counter which is also 64bits. 199 + */ 200 + 201 + static void qcom_l3_cache__64bit_counter_start(struct perf_event *event) 202 + { 203 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 204 + int idx = event->hw.idx; 205 + u32 evsel = get_event_type(event); 206 + u32 gang; 207 + 208 + /* Set the odd counter to count the overflows of the even counter */ 209 + gang = readl_relaxed(l3pmu->regs + L3_M_BC_GANG); 210 + gang |= GANG_EN(idx + 1); 211 + writel_relaxed(gang, l3pmu->regs + L3_M_BC_GANG); 212 + 213 + /* Initialize the hardware counters and reset prev_count*/ 214 + local64_set(&event->hw.prev_count, 0); 215 + writel_relaxed(0, l3pmu->regs + L3_HML3_PM_EVCNTR(idx + 1)); 216 + writel_relaxed(0, l3pmu->regs + L3_HML3_PM_EVCNTR(idx)); 217 + 218 + /* 219 + * Set the event types, the upper half must use zero and the lower 220 + * half the actual event type 221 + */ 222 + writel_relaxed(EVSEL(0), l3pmu->regs + L3_HML3_PM_EVTYPE(idx + 1)); 223 + writel_relaxed(EVSEL(evsel), l3pmu->regs + L3_HML3_PM_EVTYPE(idx)); 224 + 225 + /* Finally, enable the counters */ 226 + writel_relaxed(PMCNT_RESET, l3pmu->regs + L3_HML3_PM_CNTCTL(idx + 1)); 227 + writel_relaxed(PMCNTENSET(idx + 1), l3pmu->regs + L3_M_BC_CNTENSET); 228 + writel_relaxed(PMCNT_RESET, l3pmu->regs + L3_HML3_PM_CNTCTL(idx)); 229 + writel_relaxed(PMCNTENSET(idx), l3pmu->regs + L3_M_BC_CNTENSET); 230 + } 231 + 232 + static void qcom_l3_cache__64bit_counter_stop(struct perf_event *event, 233 + int flags) 234 + { 235 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 236 + int idx = event->hw.idx; 237 + u32 gang = readl_relaxed(l3pmu->regs + L3_M_BC_GANG); 238 + 239 + /* Disable the counters */ 240 + writel_relaxed(PMCNTENCLR(idx), l3pmu->regs + L3_M_BC_CNTENCLR); 241 + writel_relaxed(PMCNTENCLR(idx + 1), l3pmu->regs + L3_M_BC_CNTENCLR); 242 + 243 + /* Disable chaining */ 244 + writel_relaxed(gang & ~GANG_EN(idx + 1), l3pmu->regs + L3_M_BC_GANG); 245 + } 246 + 247 + static void qcom_l3_cache__64bit_counter_update(struct perf_event *event) 248 + { 249 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 250 + int idx = event->hw.idx; 251 + u32 hi, lo; 252 + u64 prev, new; 253 + 254 + do { 255 + prev = local64_read(&event->hw.prev_count); 256 + do { 257 + hi = readl_relaxed(l3pmu->regs + L3_HML3_PM_EVCNTR(idx + 1)); 258 + lo = readl_relaxed(l3pmu->regs + L3_HML3_PM_EVCNTR(idx)); 259 + } while (hi != readl_relaxed(l3pmu->regs + L3_HML3_PM_EVCNTR(idx + 1))); 260 + new = ((u64)hi << 32) | lo; 261 + } while (local64_cmpxchg(&event->hw.prev_count, prev, new) != prev); 262 + 263 + local64_add(new - prev, &event->count); 264 + } 265 + 266 + static const struct l3cache_event_ops event_ops_long = { 267 + .start = qcom_l3_cache__64bit_counter_start, 268 + .stop = qcom_l3_cache__64bit_counter_stop, 269 + .update = qcom_l3_cache__64bit_counter_update, 270 + }; 271 + 272 + /* 273 + * Implementation of standard counter operations 274 + * 275 + * 32bit counters use a single physical counter and a hardware feature that 276 + * asserts the overflow IRQ on the toggling of the most significant bit in 277 + * the counter. This feature allows the counters to be left free-running 278 + * without needing the usual reprogramming required to properly handle races 279 + * during concurrent calls to update. 280 + */ 281 + 282 + static void qcom_l3_cache__32bit_counter_start(struct perf_event *event) 283 + { 284 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 285 + int idx = event->hw.idx; 286 + u32 evsel = get_event_type(event); 287 + u32 irqctl = readl_relaxed(l3pmu->regs + L3_M_BC_IRQCTL); 288 + 289 + /* Set the counter to assert the overflow IRQ on MSB toggling */ 290 + writel_relaxed(irqctl | PMIRQONMSBEN(idx), l3pmu->regs + L3_M_BC_IRQCTL); 291 + 292 + /* Initialize the hardware counter and reset prev_count*/ 293 + local64_set(&event->hw.prev_count, 0); 294 + writel_relaxed(0, l3pmu->regs + L3_HML3_PM_EVCNTR(idx)); 295 + 296 + /* Set the event type */ 297 + writel_relaxed(EVSEL(evsel), l3pmu->regs + L3_HML3_PM_EVTYPE(idx)); 298 + 299 + /* Enable interrupt generation by this counter */ 300 + writel_relaxed(PMINTENSET(idx), l3pmu->regs + L3_M_BC_INTENSET); 301 + 302 + /* Finally, enable the counter */ 303 + writel_relaxed(PMCNT_RESET, l3pmu->regs + L3_HML3_PM_CNTCTL(idx)); 304 + writel_relaxed(PMCNTENSET(idx), l3pmu->regs + L3_M_BC_CNTENSET); 305 + } 306 + 307 + static void qcom_l3_cache__32bit_counter_stop(struct perf_event *event, 308 + int flags) 309 + { 310 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 311 + int idx = event->hw.idx; 312 + u32 irqctl = readl_relaxed(l3pmu->regs + L3_M_BC_IRQCTL); 313 + 314 + /* Disable the counter */ 315 + writel_relaxed(PMCNTENCLR(idx), l3pmu->regs + L3_M_BC_CNTENCLR); 316 + 317 + /* Disable interrupt generation by this counter */ 318 + writel_relaxed(PMINTENCLR(idx), l3pmu->regs + L3_M_BC_INTENCLR); 319 + 320 + /* Set the counter to not assert the overflow IRQ on MSB toggling */ 321 + writel_relaxed(irqctl & ~PMIRQONMSBEN(idx), l3pmu->regs + L3_M_BC_IRQCTL); 322 + } 323 + 324 + static void qcom_l3_cache__32bit_counter_update(struct perf_event *event) 325 + { 326 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 327 + int idx = event->hw.idx; 328 + u32 prev, new; 329 + 330 + do { 331 + prev = local64_read(&event->hw.prev_count); 332 + new = readl_relaxed(l3pmu->regs + L3_HML3_PM_EVCNTR(idx)); 333 + } while (local64_cmpxchg(&event->hw.prev_count, prev, new) != prev); 334 + 335 + local64_add(new - prev, &event->count); 336 + } 337 + 338 + static const struct l3cache_event_ops event_ops_std = { 339 + .start = qcom_l3_cache__32bit_counter_start, 340 + .stop = qcom_l3_cache__32bit_counter_stop, 341 + .update = qcom_l3_cache__32bit_counter_update, 342 + }; 343 + 344 + /* Retrieve the appropriate operations for the given event */ 345 + static 346 + const struct l3cache_event_ops *l3cache_event_get_ops(struct perf_event *event) 347 + { 348 + if (event_uses_long_counter(event)) 349 + return &event_ops_long; 350 + else 351 + return &event_ops_std; 352 + } 353 + 354 + /* 355 + * Top level PMU functions. 356 + */ 357 + 358 + static inline void qcom_l3_cache__init(struct l3cache_pmu *l3pmu) 359 + { 360 + int i; 361 + 362 + writel_relaxed(BC_RESET, l3pmu->regs + L3_M_BC_CR); 363 + 364 + /* 365 + * Use writel for the first programming command to ensure the basic 366 + * counter unit is stopped before proceeding 367 + */ 368 + writel(BC_SATROLL_CR_RESET, l3pmu->regs + L3_M_BC_SATROLL_CR); 369 + 370 + writel_relaxed(BC_CNTENCLR_RESET, l3pmu->regs + L3_M_BC_CNTENCLR); 371 + writel_relaxed(BC_INTENCLR_RESET, l3pmu->regs + L3_M_BC_INTENCLR); 372 + writel_relaxed(PMOVSRCLR_RESET, l3pmu->regs + L3_M_BC_OVSR); 373 + writel_relaxed(BC_GANG_RESET, l3pmu->regs + L3_M_BC_GANG); 374 + writel_relaxed(BC_IRQCTL_RESET, l3pmu->regs + L3_M_BC_IRQCTL); 375 + writel_relaxed(PM_CR_RESET, l3pmu->regs + L3_HML3_PM_CR); 376 + 377 + for (i = 0; i < L3_NUM_COUNTERS; ++i) { 378 + writel_relaxed(PMCNT_RESET, l3pmu->regs + L3_HML3_PM_CNTCTL(i)); 379 + writel_relaxed(EVSEL(0), l3pmu->regs + L3_HML3_PM_EVTYPE(i)); 380 + } 381 + 382 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRA); 383 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRAM); 384 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRB); 385 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRBM); 386 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRC); 387 + writel_relaxed(PM_FLTR_RESET, l3pmu->regs + L3_HML3_PM_FILTRCM); 388 + 389 + /* 390 + * Use writel here to ensure all programming commands are done 391 + * before proceeding 392 + */ 393 + writel(BC_ENABLE, l3pmu->regs + L3_M_BC_CR); 394 + } 395 + 396 + static irqreturn_t qcom_l3_cache__handle_irq(int irq_num, void *data) 397 + { 398 + struct l3cache_pmu *l3pmu = data; 399 + /* Read the overflow status register */ 400 + long status = readl_relaxed(l3pmu->regs + L3_M_BC_OVSR); 401 + int idx; 402 + 403 + if (status == 0) 404 + return IRQ_NONE; 405 + 406 + /* Clear the bits we read on the overflow status register */ 407 + writel_relaxed(status, l3pmu->regs + L3_M_BC_OVSR); 408 + 409 + for_each_set_bit(idx, &status, L3_NUM_COUNTERS) { 410 + struct perf_event *event; 411 + const struct l3cache_event_ops *ops; 412 + 413 + event = l3pmu->events[idx]; 414 + if (!event) 415 + continue; 416 + 417 + /* 418 + * Since the IRQ is not enabled for events using long counters 419 + * we should never see one of those here, however, be consistent 420 + * and use the ops indirections like in the other operations. 421 + */ 422 + 423 + ops = l3cache_event_get_ops(event); 424 + ops->update(event); 425 + } 426 + 427 + return IRQ_HANDLED; 428 + } 429 + 430 + /* 431 + * Implementation of abstract pmu functionality required by 432 + * the core perf events code. 433 + */ 434 + 435 + static void qcom_l3_cache__pmu_enable(struct pmu *pmu) 436 + { 437 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(pmu); 438 + 439 + /* Ensure the other programming commands are observed before enabling */ 440 + wmb(); 441 + 442 + writel_relaxed(BC_ENABLE, l3pmu->regs + L3_M_BC_CR); 443 + } 444 + 445 + static void qcom_l3_cache__pmu_disable(struct pmu *pmu) 446 + { 447 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(pmu); 448 + 449 + writel_relaxed(0, l3pmu->regs + L3_M_BC_CR); 450 + 451 + /* Ensure the basic counter unit is stopped before proceeding */ 452 + wmb(); 453 + } 454 + 455 + /* 456 + * We must NOT create groups containing events from multiple hardware PMUs, 457 + * although mixing different software and hardware PMUs is allowed. 458 + */ 459 + static bool qcom_l3_cache__validate_event_group(struct perf_event *event) 460 + { 461 + struct perf_event *leader = event->group_leader; 462 + struct perf_event *sibling; 463 + int counters = 0; 464 + 465 + if (leader->pmu != event->pmu && !is_software_event(leader)) 466 + return false; 467 + 468 + counters = event_num_counters(event); 469 + counters += event_num_counters(leader); 470 + 471 + list_for_each_entry(sibling, &leader->sibling_list, group_entry) { 472 + if (is_software_event(sibling)) 473 + continue; 474 + if (sibling->pmu != event->pmu) 475 + return false; 476 + counters += event_num_counters(sibling); 477 + } 478 + 479 + /* 480 + * If the group requires more counters than the HW has, it 481 + * cannot ever be scheduled. 482 + */ 483 + return counters <= L3_NUM_COUNTERS; 484 + } 485 + 486 + static int qcom_l3_cache__event_init(struct perf_event *event) 487 + { 488 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 489 + struct hw_perf_event *hwc = &event->hw; 490 + 491 + /* 492 + * Is the event for this PMU? 493 + */ 494 + if (event->attr.type != event->pmu->type) 495 + return -ENOENT; 496 + 497 + /* 498 + * There are no per-counter mode filters in the PMU. 499 + */ 500 + if (event->attr.exclude_user || event->attr.exclude_kernel || 501 + event->attr.exclude_hv || event->attr.exclude_idle) 502 + return -EINVAL; 503 + 504 + /* 505 + * Sampling not supported since these events are not core-attributable. 506 + */ 507 + if (hwc->sample_period) 508 + return -EINVAL; 509 + 510 + /* 511 + * Task mode not available, we run the counters as socket counters, 512 + * not attributable to any CPU and therefore cannot attribute per-task. 513 + */ 514 + if (event->cpu < 0) 515 + return -EINVAL; 516 + 517 + /* Validate the group */ 518 + if (!qcom_l3_cache__validate_event_group(event)) 519 + return -EINVAL; 520 + 521 + hwc->idx = -1; 522 + 523 + /* 524 + * Many perf core operations (eg. events rotation) operate on a 525 + * single CPU context. This is obvious for CPU PMUs, where one 526 + * expects the same sets of events being observed on all CPUs, 527 + * but can lead to issues for off-core PMUs, like this one, where 528 + * each event could be theoretically assigned to a different CPU. 529 + * To mitigate this, we enforce CPU assignment to one designated 530 + * processor (the one described in the "cpumask" attribute exported 531 + * by the PMU device). perf user space tools honor this and avoid 532 + * opening more than one copy of the events. 533 + */ 534 + event->cpu = cpumask_first(&l3pmu->cpumask); 535 + 536 + return 0; 537 + } 538 + 539 + static void qcom_l3_cache__event_start(struct perf_event *event, int flags) 540 + { 541 + struct hw_perf_event *hwc = &event->hw; 542 + const struct l3cache_event_ops *ops = l3cache_event_get_ops(event); 543 + 544 + hwc->state = 0; 545 + ops->start(event); 546 + } 547 + 548 + static void qcom_l3_cache__event_stop(struct perf_event *event, int flags) 549 + { 550 + struct hw_perf_event *hwc = &event->hw; 551 + const struct l3cache_event_ops *ops = l3cache_event_get_ops(event); 552 + 553 + if (hwc->state & PERF_HES_STOPPED) 554 + return; 555 + 556 + ops->stop(event, flags); 557 + if (flags & PERF_EF_UPDATE) 558 + ops->update(event); 559 + hwc->state |= PERF_HES_STOPPED | PERF_HES_UPTODATE; 560 + } 561 + 562 + static int qcom_l3_cache__event_add(struct perf_event *event, int flags) 563 + { 564 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 565 + struct hw_perf_event *hwc = &event->hw; 566 + int order = event_uses_long_counter(event) ? 1 : 0; 567 + int idx; 568 + 569 + /* 570 + * Try to allocate a counter. 571 + */ 572 + idx = bitmap_find_free_region(l3pmu->used_mask, L3_NUM_COUNTERS, order); 573 + if (idx < 0) 574 + /* The counters are all in use. */ 575 + return -EAGAIN; 576 + 577 + hwc->idx = idx; 578 + hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; 579 + l3pmu->events[idx] = event; 580 + 581 + if (flags & PERF_EF_START) 582 + qcom_l3_cache__event_start(event, 0); 583 + 584 + /* Propagate changes to the userspace mapping. */ 585 + perf_event_update_userpage(event); 586 + 587 + return 0; 588 + } 589 + 590 + static void qcom_l3_cache__event_del(struct perf_event *event, int flags) 591 + { 592 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(event->pmu); 593 + struct hw_perf_event *hwc = &event->hw; 594 + int order = event_uses_long_counter(event) ? 1 : 0; 595 + 596 + /* Stop and clean up */ 597 + qcom_l3_cache__event_stop(event, flags | PERF_EF_UPDATE); 598 + l3pmu->events[hwc->idx] = NULL; 599 + bitmap_release_region(l3pmu->used_mask, hwc->idx, order); 600 + 601 + /* Propagate changes to the userspace mapping. */ 602 + perf_event_update_userpage(event); 603 + } 604 + 605 + static void qcom_l3_cache__event_read(struct perf_event *event) 606 + { 607 + const struct l3cache_event_ops *ops = l3cache_event_get_ops(event); 608 + 609 + ops->update(event); 610 + } 611 + 612 + /* 613 + * Add sysfs attributes 614 + * 615 + * We export: 616 + * - formats, used by perf user space and other tools to configure events 617 + * - events, used by perf user space and other tools to create events 618 + * symbolically, e.g.: 619 + * perf stat -a -e l3cache_0_0/event=read-miss/ ls 620 + * perf stat -a -e l3cache_0_0/event=0x21/ ls 621 + * - cpumask, used by perf user space and other tools to know on which CPUs 622 + * to open the events 623 + */ 624 + 625 + /* formats */ 626 + 627 + static ssize_t l3cache_pmu_format_show(struct device *dev, 628 + struct device_attribute *attr, char *buf) 629 + { 630 + struct dev_ext_attribute *eattr; 631 + 632 + eattr = container_of(attr, struct dev_ext_attribute, attr); 633 + return sprintf(buf, "%s\n", (char *) eattr->var); 634 + } 635 + 636 + #define L3CACHE_PMU_FORMAT_ATTR(_name, _config) \ 637 + (&((struct dev_ext_attribute[]) { \ 638 + { .attr = __ATTR(_name, 0444, l3cache_pmu_format_show, NULL), \ 639 + .var = (void *) _config, } \ 640 + })[0].attr.attr) 641 + 642 + static struct attribute *qcom_l3_cache_pmu_formats[] = { 643 + L3CACHE_PMU_FORMAT_ATTR(event, "config:0-7"), 644 + L3CACHE_PMU_FORMAT_ATTR(lc, "config:" __stringify(L3_EVENT_LC_BIT)), 645 + NULL, 646 + }; 647 + 648 + static struct attribute_group qcom_l3_cache_pmu_format_group = { 649 + .name = "format", 650 + .attrs = qcom_l3_cache_pmu_formats, 651 + }; 652 + 653 + /* events */ 654 + 655 + static ssize_t l3cache_pmu_event_show(struct device *dev, 656 + struct device_attribute *attr, char *page) 657 + { 658 + struct perf_pmu_events_attr *pmu_attr; 659 + 660 + pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr); 661 + return sprintf(page, "event=0x%02llx\n", pmu_attr->id); 662 + } 663 + 664 + #define L3CACHE_EVENT_ATTR(_name, _id) \ 665 + (&((struct perf_pmu_events_attr[]) { \ 666 + { .attr = __ATTR(_name, 0444, l3cache_pmu_event_show, NULL), \ 667 + .id = _id, } \ 668 + })[0].attr.attr) 669 + 670 + static struct attribute *qcom_l3_cache_pmu_events[] = { 671 + L3CACHE_EVENT_ATTR(cycles, L3_EVENT_CYCLES), 672 + L3CACHE_EVENT_ATTR(read-hit, L3_EVENT_READ_HIT), 673 + L3CACHE_EVENT_ATTR(read-miss, L3_EVENT_READ_MISS), 674 + L3CACHE_EVENT_ATTR(read-hit-d-side, L3_EVENT_READ_HIT_D), 675 + L3CACHE_EVENT_ATTR(read-miss-d-side, L3_EVENT_READ_MISS_D), 676 + L3CACHE_EVENT_ATTR(write-hit, L3_EVENT_WRITE_HIT), 677 + L3CACHE_EVENT_ATTR(write-miss, L3_EVENT_WRITE_MISS), 678 + NULL 679 + }; 680 + 681 + static struct attribute_group qcom_l3_cache_pmu_events_group = { 682 + .name = "events", 683 + .attrs = qcom_l3_cache_pmu_events, 684 + }; 685 + 686 + /* cpumask */ 687 + 688 + static ssize_t qcom_l3_cache_pmu_cpumask_show(struct device *dev, 689 + struct device_attribute *attr, char *buf) 690 + { 691 + struct l3cache_pmu *l3pmu = to_l3cache_pmu(dev_get_drvdata(dev)); 692 + 693 + return cpumap_print_to_pagebuf(true, buf, &l3pmu->cpumask); 694 + } 695 + 696 + static DEVICE_ATTR(cpumask, 0444, qcom_l3_cache_pmu_cpumask_show, NULL); 697 + 698 + static struct attribute *qcom_l3_cache_pmu_cpumask_attrs[] = { 699 + &dev_attr_cpumask.attr, 700 + NULL, 701 + }; 702 + 703 + static struct attribute_group qcom_l3_cache_pmu_cpumask_attr_group = { 704 + .attrs = qcom_l3_cache_pmu_cpumask_attrs, 705 + }; 706 + 707 + /* 708 + * Per PMU device attribute groups 709 + */ 710 + static const struct attribute_group *qcom_l3_cache_pmu_attr_grps[] = { 711 + &qcom_l3_cache_pmu_format_group, 712 + &qcom_l3_cache_pmu_events_group, 713 + &qcom_l3_cache_pmu_cpumask_attr_group, 714 + NULL, 715 + }; 716 + 717 + /* 718 + * Probing functions and data. 719 + */ 720 + 721 + static int qcom_l3_cache_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) 722 + { 723 + struct l3cache_pmu *l3pmu = hlist_entry_safe(node, struct l3cache_pmu, node); 724 + 725 + /* If there is not a CPU/PMU association pick this CPU */ 726 + if (cpumask_empty(&l3pmu->cpumask)) 727 + cpumask_set_cpu(cpu, &l3pmu->cpumask); 728 + 729 + return 0; 730 + } 731 + 732 + static int qcom_l3_cache_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node) 733 + { 734 + struct l3cache_pmu *l3pmu = hlist_entry_safe(node, struct l3cache_pmu, node); 735 + unsigned int target; 736 + 737 + if (!cpumask_test_and_clear_cpu(cpu, &l3pmu->cpumask)) 738 + return 0; 739 + target = cpumask_any_but(cpu_online_mask, cpu); 740 + if (target >= nr_cpu_ids) 741 + return 0; 742 + perf_pmu_migrate_context(&l3pmu->pmu, cpu, target); 743 + cpumask_set_cpu(target, &l3pmu->cpumask); 744 + return 0; 745 + } 746 + 747 + static int qcom_l3_cache_pmu_probe(struct platform_device *pdev) 748 + { 749 + struct l3cache_pmu *l3pmu; 750 + struct acpi_device *acpi_dev; 751 + struct resource *memrc; 752 + int ret; 753 + char *name; 754 + 755 + /* Initialize the PMU data structures */ 756 + 757 + acpi_dev = ACPI_COMPANION(&pdev->dev); 758 + if (!acpi_dev) 759 + return -ENODEV; 760 + 761 + l3pmu = devm_kzalloc(&pdev->dev, sizeof(*l3pmu), GFP_KERNEL); 762 + name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "l3cache_%s_%s", 763 + acpi_dev->parent->pnp.unique_id, acpi_dev->pnp.unique_id); 764 + if (!l3pmu || !name) 765 + return -ENOMEM; 766 + 767 + l3pmu->pmu = (struct pmu) { 768 + .task_ctx_nr = perf_invalid_context, 769 + 770 + .pmu_enable = qcom_l3_cache__pmu_enable, 771 + .pmu_disable = qcom_l3_cache__pmu_disable, 772 + .event_init = qcom_l3_cache__event_init, 773 + .add = qcom_l3_cache__event_add, 774 + .del = qcom_l3_cache__event_del, 775 + .start = qcom_l3_cache__event_start, 776 + .stop = qcom_l3_cache__event_stop, 777 + .read = qcom_l3_cache__event_read, 778 + 779 + .attr_groups = qcom_l3_cache_pmu_attr_grps, 780 + }; 781 + 782 + memrc = platform_get_resource(pdev, IORESOURCE_MEM, 0); 783 + l3pmu->regs = devm_ioremap_resource(&pdev->dev, memrc); 784 + if (IS_ERR(l3pmu->regs)) { 785 + dev_err(&pdev->dev, "Can't map PMU @%pa\n", &memrc->start); 786 + return PTR_ERR(l3pmu->regs); 787 + } 788 + 789 + qcom_l3_cache__init(l3pmu); 790 + 791 + ret = platform_get_irq(pdev, 0); 792 + if (ret <= 0) 793 + return ret; 794 + 795 + ret = devm_request_irq(&pdev->dev, ret, qcom_l3_cache__handle_irq, 0, 796 + name, l3pmu); 797 + if (ret) { 798 + dev_err(&pdev->dev, "Request for IRQ failed for slice @%pa\n", 799 + &memrc->start); 800 + return ret; 801 + } 802 + 803 + /* Add this instance to the list used by the offline callback */ 804 + ret = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE, &l3pmu->node); 805 + if (ret) { 806 + dev_err(&pdev->dev, "Error %d registering hotplug", ret); 807 + return ret; 808 + } 809 + 810 + ret = perf_pmu_register(&l3pmu->pmu, name, -1); 811 + if (ret < 0) { 812 + dev_err(&pdev->dev, "Failed to register L3 cache PMU (%d)\n", ret); 813 + return ret; 814 + } 815 + 816 + dev_info(&pdev->dev, "Registered %s, type: %d\n", name, l3pmu->pmu.type); 817 + 818 + return 0; 819 + } 820 + 821 + static const struct acpi_device_id qcom_l3_cache_pmu_acpi_match[] = { 822 + { "QCOM8081", }, 823 + { } 824 + }; 825 + MODULE_DEVICE_TABLE(acpi, qcom_l3_cache_pmu_acpi_match); 826 + 827 + static struct platform_driver qcom_l3_cache_pmu_driver = { 828 + .driver = { 829 + .name = "qcom-l3cache-pmu", 830 + .acpi_match_table = ACPI_PTR(qcom_l3_cache_pmu_acpi_match), 831 + }, 832 + .probe = qcom_l3_cache_pmu_probe, 833 + }; 834 + 835 + static int __init register_qcom_l3_cache_pmu_driver(void) 836 + { 837 + int ret; 838 + 839 + /* Install a hook to update the reader CPU in case it goes offline */ 840 + ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE, 841 + "perf/qcom/l3cache:online", 842 + qcom_l3_cache_pmu_online_cpu, 843 + qcom_l3_cache_pmu_offline_cpu); 844 + if (ret) 845 + return ret; 846 + 847 + return platform_driver_register(&qcom_l3_cache_pmu_driver); 848 + } 849 + device_initcall(register_qcom_l3_cache_pmu_driver);
+3
include/linux/acpi_iort.h
··· 34 34 bool iort_node_match(u8 type); 35 35 u32 iort_msi_map_rid(struct device *dev, u32 req_id); 36 36 struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id); 37 + void acpi_configure_pmsi_domain(struct device *dev); 38 + int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id); 37 39 /* IOMMU interface */ 38 40 void iort_set_dma_mask(struct device *dev); 39 41 const struct iommu_ops *iort_iommu_configure(struct device *dev); ··· 47 45 static inline struct irq_domain *iort_get_device_domain(struct device *dev, 48 46 u32 req_id) 49 47 { return NULL; } 48 + static inline void acpi_configure_pmsi_domain(struct device *dev) { } 50 49 /* IOMMU interface */ 51 50 static inline void iort_set_dma_mask(struct device *dev) { } 52 51 static inline
+2
include/linux/cpuhotplug.h
··· 94 94 CPUHP_AP_ARM_VFP_STARTING, 95 95 CPUHP_AP_ARM64_DEBUG_MONITORS_STARTING, 96 96 CPUHP_AP_PERF_ARM_HW_BREAKPOINT_STARTING, 97 + CPUHP_AP_PERF_ARM_ACPI_STARTING, 97 98 CPUHP_AP_PERF_ARM_STARTING, 98 99 CPUHP_AP_ARM_L2X0_STARTING, 99 100 CPUHP_AP_ARM_ARCH_TIMER_STARTING, ··· 138 137 CPUHP_AP_PERF_ARM_CCN_ONLINE, 139 138 CPUHP_AP_PERF_ARM_L2X0_ONLINE, 140 139 CPUHP_AP_PERF_ARM_QCOM_L2_ONLINE, 140 + CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE, 141 141 CPUHP_AP_WORKQUEUE_ONLINE, 142 142 CPUHP_AP_RCUTREE_ONLINE, 143 143 CPUHP_AP_ONLINE_DYN,
+2
include/linux/memblock.h
··· 93 93 int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); 94 94 int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); 95 95 int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); 96 + int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); 96 97 ulong choose_memblock_flags(void); 97 98 98 99 /* Low level functions */ ··· 336 335 phys_addr_t memblock_start_of_DRAM(void); 337 336 phys_addr_t memblock_end_of_DRAM(void); 338 337 void memblock_enforce_memory_limit(phys_addr_t memory_limit); 338 + void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); 339 339 void memblock_mem_limit_remove_map(phys_addr_t limit); 340 340 bool memblock_is_memory(phys_addr_t addr); 341 341 int memblock_is_map_memory(phys_addr_t addr);
+92 -85
include/linux/pe.h
··· 23 23 24 24 #define MZ_MAGIC 0x5a4d /* "MZ" */ 25 25 26 - struct mz_hdr { 27 - uint16_t magic; /* MZ_MAGIC */ 28 - uint16_t lbsize; /* size of last used block */ 29 - uint16_t blocks; /* pages in file, 0x3 */ 30 - uint16_t relocs; /* relocations */ 31 - uint16_t hdrsize; /* header size in "paragraphs" */ 32 - uint16_t min_extra_pps; /* .bss */ 33 - uint16_t max_extra_pps; /* runtime limit for the arena size */ 34 - uint16_t ss; /* relative stack segment */ 35 - uint16_t sp; /* initial %sp register */ 36 - uint16_t checksum; /* word checksum */ 37 - uint16_t ip; /* initial %ip register */ 38 - uint16_t cs; /* initial %cs relative to load segment */ 39 - uint16_t reloc_table_offset; /* offset of the first relocation */ 40 - uint16_t overlay_num; /* overlay number. set to 0. */ 41 - uint16_t reserved0[4]; /* reserved */ 42 - uint16_t oem_id; /* oem identifier */ 43 - uint16_t oem_info; /* oem specific */ 44 - uint16_t reserved1[10]; /* reserved */ 45 - uint32_t peaddr; /* address of pe header */ 46 - char message[64]; /* message to print */ 47 - }; 48 - 49 - struct mz_reloc { 50 - uint16_t offset; 51 - uint16_t segment; 52 - }; 53 - 54 26 #define PE_MAGIC 0x00004550 /* "PE\0\0" */ 55 27 #define PE_OPT_MAGIC_PE32 0x010b 56 28 #define PE_OPT_MAGIC_PE32_ROM 0x0107 ··· 34 62 #define IMAGE_FILE_MACHINE_AMD64 0x8664 35 63 #define IMAGE_FILE_MACHINE_ARM 0x01c0 36 64 #define IMAGE_FILE_MACHINE_ARMV7 0x01c4 65 + #define IMAGE_FILE_MACHINE_ARM64 0xaa64 37 66 #define IMAGE_FILE_MACHINE_EBC 0x0ebc 38 67 #define IMAGE_FILE_MACHINE_I386 0x014c 39 68 #define IMAGE_FILE_MACHINE_IA64 0x0200 ··· 71 98 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 72 99 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 73 100 74 - struct pe_hdr { 75 - uint32_t magic; /* PE magic */ 76 - uint16_t machine; /* machine type */ 77 - uint16_t sections; /* number of sections */ 78 - uint32_t timestamp; /* time_t */ 79 - uint32_t symbol_table; /* symbol table offset */ 80 - uint32_t symbols; /* number of symbols */ 81 - uint16_t opt_hdr_size; /* size of optional header */ 82 - uint16_t flags; /* flags */ 83 - }; 84 - 85 101 #define IMAGE_FILE_OPT_ROM_MAGIC 0x107 86 102 #define IMAGE_FILE_OPT_PE32_MAGIC 0x10b 87 103 #define IMAGE_FILE_OPT_PE32_PLUS_MAGIC 0x20b ··· 95 133 #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800 96 134 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000 97 135 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000 136 + 137 + /* they actually defined 0x00000000 as well, but I think we'll skip that one. */ 138 + #define IMAGE_SCN_RESERVED_0 0x00000001 139 + #define IMAGE_SCN_RESERVED_1 0x00000002 140 + #define IMAGE_SCN_RESERVED_2 0x00000004 141 + #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* don't pad - obsolete */ 142 + #define IMAGE_SCN_RESERVED_3 0x00000010 143 + #define IMAGE_SCN_CNT_CODE 0x00000020 /* .text */ 144 + #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* .data */ 145 + #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* .bss */ 146 + #define IMAGE_SCN_LNK_OTHER 0x00000100 /* reserved */ 147 + #define IMAGE_SCN_LNK_INFO 0x00000200 /* .drectve comments */ 148 + #define IMAGE_SCN_RESERVED_4 0x00000400 149 + #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* .o only - scn to be rm'd*/ 150 + #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* .o only - COMDAT data */ 151 + #define IMAGE_SCN_RESERVED_5 0x00002000 /* spec omits this */ 152 + #define IMAGE_SCN_RESERVED_6 0x00004000 /* spec omits this */ 153 + #define IMAGE_SCN_GPREL 0x00008000 /* global pointer referenced data */ 154 + /* spec lists 0x20000 twice, I suspect they meant 0x10000 for one of them */ 155 + #define IMAGE_SCN_MEM_PURGEABLE 0x00010000 /* reserved for "future" use */ 156 + #define IMAGE_SCN_16BIT 0x00020000 /* reserved for "future" use */ 157 + #define IMAGE_SCN_LOCKED 0x00040000 /* reserved for "future" use */ 158 + #define IMAGE_SCN_PRELOAD 0x00080000 /* reserved for "future" use */ 159 + /* and here they just stuck a 1-byte integer in the middle of a bitfield */ 160 + #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 /* it does what it says on the box */ 161 + #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 162 + #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 163 + #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 164 + #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 165 + #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 166 + #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 167 + #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 168 + #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 169 + #define IMAGE_SCN_ALIGN_512BYTES 0x00a00000 170 + #define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000 171 + #define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000 172 + #define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000 173 + #define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000 174 + #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* extended relocations */ 175 + #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* scn can be discarded */ 176 + #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* cannot be cached */ 177 + #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* not pageable */ 178 + #define IMAGE_SCN_MEM_SHARED 0x10000000 /* can be shared */ 179 + #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* can be executed as code */ 180 + #define IMAGE_SCN_MEM_READ 0x40000000 /* readable */ 181 + #define IMAGE_SCN_MEM_WRITE 0x80000000 /* writeable */ 182 + 183 + #define IMAGE_DEBUG_TYPE_CODEVIEW 2 184 + 185 + #ifndef __ASSEMBLY__ 186 + 187 + struct mz_hdr { 188 + uint16_t magic; /* MZ_MAGIC */ 189 + uint16_t lbsize; /* size of last used block */ 190 + uint16_t blocks; /* pages in file, 0x3 */ 191 + uint16_t relocs; /* relocations */ 192 + uint16_t hdrsize; /* header size in "paragraphs" */ 193 + uint16_t min_extra_pps; /* .bss */ 194 + uint16_t max_extra_pps; /* runtime limit for the arena size */ 195 + uint16_t ss; /* relative stack segment */ 196 + uint16_t sp; /* initial %sp register */ 197 + uint16_t checksum; /* word checksum */ 198 + uint16_t ip; /* initial %ip register */ 199 + uint16_t cs; /* initial %cs relative to load segment */ 200 + uint16_t reloc_table_offset; /* offset of the first relocation */ 201 + uint16_t overlay_num; /* overlay number. set to 0. */ 202 + uint16_t reserved0[4]; /* reserved */ 203 + uint16_t oem_id; /* oem identifier */ 204 + uint16_t oem_info; /* oem specific */ 205 + uint16_t reserved1[10]; /* reserved */ 206 + uint32_t peaddr; /* address of pe header */ 207 + char message[64]; /* message to print */ 208 + }; 209 + 210 + struct mz_reloc { 211 + uint16_t offset; 212 + uint16_t segment; 213 + }; 214 + 215 + struct pe_hdr { 216 + uint32_t magic; /* PE magic */ 217 + uint16_t machine; /* machine type */ 218 + uint16_t sections; /* number of sections */ 219 + uint32_t timestamp; /* time_t */ 220 + uint32_t symbol_table; /* symbol table offset */ 221 + uint32_t symbols; /* number of symbols */ 222 + uint16_t opt_hdr_size; /* size of optional header */ 223 + uint16_t flags; /* flags */ 224 + }; 98 225 99 226 /* the fact that pe32 isn't padded where pe32+ is 64-bit means union won't 100 227 * work right. vomit. */ ··· 293 242 uint16_t num_lin_numbers; /* srsly. */ 294 243 uint32_t flags; 295 244 }; 296 - 297 - /* they actually defined 0x00000000 as well, but I think we'll skip that one. */ 298 - #define IMAGE_SCN_RESERVED_0 0x00000001 299 - #define IMAGE_SCN_RESERVED_1 0x00000002 300 - #define IMAGE_SCN_RESERVED_2 0x00000004 301 - #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* don't pad - obsolete */ 302 - #define IMAGE_SCN_RESERVED_3 0x00000010 303 - #define IMAGE_SCN_CNT_CODE 0x00000020 /* .text */ 304 - #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* .data */ 305 - #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* .bss */ 306 - #define IMAGE_SCN_LNK_OTHER 0x00000100 /* reserved */ 307 - #define IMAGE_SCN_LNK_INFO 0x00000200 /* .drectve comments */ 308 - #define IMAGE_SCN_RESERVED_4 0x00000400 309 - #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* .o only - scn to be rm'd*/ 310 - #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* .o only - COMDAT data */ 311 - #define IMAGE_SCN_RESERVED_5 0x00002000 /* spec omits this */ 312 - #define IMAGE_SCN_RESERVED_6 0x00004000 /* spec omits this */ 313 - #define IMAGE_SCN_GPREL 0x00008000 /* global pointer referenced data */ 314 - /* spec lists 0x20000 twice, I suspect they meant 0x10000 for one of them */ 315 - #define IMAGE_SCN_MEM_PURGEABLE 0x00010000 /* reserved for "future" use */ 316 - #define IMAGE_SCN_16BIT 0x00020000 /* reserved for "future" use */ 317 - #define IMAGE_SCN_LOCKED 0x00040000 /* reserved for "future" use */ 318 - #define IMAGE_SCN_PRELOAD 0x00080000 /* reserved for "future" use */ 319 - /* and here they just stuck a 1-byte integer in the middle of a bitfield */ 320 - #define IMAGE_SCN_ALIGN_1BYTES 0x00100000 /* it does what it says on the box */ 321 - #define IMAGE_SCN_ALIGN_2BYTES 0x00200000 322 - #define IMAGE_SCN_ALIGN_4BYTES 0x00300000 323 - #define IMAGE_SCN_ALIGN_8BYTES 0x00400000 324 - #define IMAGE_SCN_ALIGN_16BYTES 0x00500000 325 - #define IMAGE_SCN_ALIGN_32BYTES 0x00600000 326 - #define IMAGE_SCN_ALIGN_64BYTES 0x00700000 327 - #define IMAGE_SCN_ALIGN_128BYTES 0x00800000 328 - #define IMAGE_SCN_ALIGN_256BYTES 0x00900000 329 - #define IMAGE_SCN_ALIGN_512BYTES 0x00a00000 330 - #define IMAGE_SCN_ALIGN_1024BYTES 0x00b00000 331 - #define IMAGE_SCN_ALIGN_2048BYTES 0x00c00000 332 - #define IMAGE_SCN_ALIGN_4096BYTES 0x00d00000 333 - #define IMAGE_SCN_ALIGN_8192BYTES 0x00e00000 334 - #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* extended relocations */ 335 - #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 /* scn can be discarded */ 336 - #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* cannot be cached */ 337 - #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* not pageable */ 338 - #define IMAGE_SCN_MEM_SHARED 0x10000000 /* can be shared */ 339 - #define IMAGE_SCN_MEM_EXECUTE 0x20000000 /* can be executed as code */ 340 - #define IMAGE_SCN_MEM_READ 0x40000000 /* readable */ 341 - #define IMAGE_SCN_MEM_WRITE 0x80000000 /* writeable */ 342 245 343 246 enum x64_coff_reloc_type { 344 247 IMAGE_REL_AMD64_ABSOLUTE = 0, ··· 449 444 uint16_t revision; 450 445 uint16_t cert_type; 451 446 }; 447 + 448 + #endif /* !__ASSEMBLY__ */ 452 449 453 450 #endif /* __LINUX_PE_H */
+23 -6
include/linux/perf/arm_pmu.h
··· 75 75 * already have to allocate this struct per cpu. 76 76 */ 77 77 struct arm_pmu *percpu_pmu; 78 + 79 + int irq; 78 80 }; 79 81 80 82 enum armpmu_attr_groups { ··· 90 88 struct pmu pmu; 91 89 cpumask_t active_irqs; 92 90 cpumask_t supported_cpus; 93 - int *irq_affinity; 94 91 char *name; 95 92 irqreturn_t (*handle_irq)(int irq_num, void *dev); 96 93 void (*enable)(struct perf_event *event); ··· 105 104 void (*start)(struct arm_pmu *); 106 105 void (*stop)(struct arm_pmu *); 107 106 void (*reset)(void *); 108 - int (*request_irq)(struct arm_pmu *, irq_handler_t handler); 109 - void (*free_irq)(struct arm_pmu *); 110 107 int (*map_event)(struct perf_event *event); 111 108 int num_events; 112 - atomic_t active_events; 113 - struct mutex reserve_mutex; 114 109 u64 max_period; 115 110 bool secure_access; /* 32-bit ARM only */ 116 111 #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40 ··· 117 120 struct notifier_block cpu_pm_nb; 118 121 /* the attr_groups array must be NULL-terminated */ 119 122 const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1]; 123 + 124 + /* Only to be used by ACPI probing code */ 125 + unsigned long acpi_cpuid; 120 126 }; 121 127 122 128 #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu)) ··· 135 135 [PERF_COUNT_HW_CACHE_RESULT_MAX], 136 136 u32 raw_event_mask); 137 137 138 + typedef int (*armpmu_init_fn)(struct arm_pmu *); 139 + 138 140 struct pmu_probe_info { 139 141 unsigned int cpuid; 140 142 unsigned int mask; 141 - int (*init)(struct arm_pmu *); 143 + armpmu_init_fn init; 142 144 }; 143 145 144 146 #define PMU_PROBE(_cpuid, _mask, _fn) \ ··· 161 159 int arm_pmu_device_probe(struct platform_device *pdev, 162 160 const struct of_device_id *of_table, 163 161 const struct pmu_probe_info *probe_table); 162 + 163 + #ifdef CONFIG_ACPI 164 + int arm_pmu_acpi_probe(armpmu_init_fn init_fn); 165 + #else 166 + static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; } 167 + #endif 168 + 169 + /* Internal functions only for core arm_pmu code */ 170 + struct arm_pmu *armpmu_alloc(void); 171 + void armpmu_free(struct arm_pmu *pmu); 172 + int armpmu_register(struct arm_pmu *pmu); 173 + int armpmu_request_irqs(struct arm_pmu *armpmu); 174 + void armpmu_free_irqs(struct arm_pmu *armpmu); 175 + int armpmu_request_irq(struct arm_pmu *armpmu, int cpu); 176 + void armpmu_free_irq(struct arm_pmu *armpmu, int cpu); 164 177 165 178 #define ARMV8_PMU_PDEV_NAME "armv8-pmu" 166 179
+41 -15
mm/memblock.c
··· 805 805 } 806 806 807 807 /** 808 + * memblock_clear_nomap - Clear flag MEMBLOCK_NOMAP for a specified region. 809 + * @base: the base phys addr of the region 810 + * @size: the size of the region 811 + * 812 + * Return 0 on success, -errno on failure. 813 + */ 814 + int __init_memblock memblock_clear_nomap(phys_addr_t base, phys_addr_t size) 815 + { 816 + return memblock_setclr_flag(base, size, 0, MEMBLOCK_NOMAP); 817 + } 818 + 819 + /** 808 820 * __next_reserved_mem_region - next function for for_each_reserved_region() 809 821 * @idx: pointer to u64 loop variable 810 822 * @out_start: ptr to phys_addr_t for start address of the region, can be %NULL ··· 1543 1531 (phys_addr_t)ULLONG_MAX); 1544 1532 } 1545 1533 1534 + void __init memblock_cap_memory_range(phys_addr_t base, phys_addr_t size) 1535 + { 1536 + int start_rgn, end_rgn; 1537 + int i, ret; 1538 + 1539 + if (!size) 1540 + return; 1541 + 1542 + ret = memblock_isolate_range(&memblock.memory, base, size, 1543 + &start_rgn, &end_rgn); 1544 + if (ret) 1545 + return; 1546 + 1547 + /* remove all the MAP regions */ 1548 + for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) 1549 + if (!memblock_is_nomap(&memblock.memory.regions[i])) 1550 + memblock_remove_region(&memblock.memory, i); 1551 + 1552 + for (i = start_rgn - 1; i >= 0; i--) 1553 + if (!memblock_is_nomap(&memblock.memory.regions[i])) 1554 + memblock_remove_region(&memblock.memory, i); 1555 + 1556 + /* truncate the reserved regions */ 1557 + memblock_remove_range(&memblock.reserved, 0, base); 1558 + memblock_remove_range(&memblock.reserved, 1559 + base + size, (phys_addr_t)ULLONG_MAX); 1560 + } 1561 + 1546 1562 void __init memblock_mem_limit_remove_map(phys_addr_t limit) 1547 1563 { 1548 - struct memblock_type *type = &memblock.memory; 1549 1564 phys_addr_t max_addr; 1550 - int i, ret, start_rgn, end_rgn; 1551 1565 1552 1566 if (!limit) 1553 1567 return; ··· 1584 1546 if (max_addr == (phys_addr_t)ULLONG_MAX) 1585 1547 return; 1586 1548 1587 - ret = memblock_isolate_range(type, max_addr, (phys_addr_t)ULLONG_MAX, 1588 - &start_rgn, &end_rgn); 1589 - if (ret) 1590 - return; 1591 - 1592 - /* remove all the MAP regions above the limit */ 1593 - for (i = end_rgn - 1; i >= start_rgn; i--) { 1594 - if (!memblock_is_nomap(&type->regions[i])) 1595 - memblock_remove_region(type, i); 1596 - } 1597 - /* truncate the reserved regions */ 1598 - memblock_remove_range(&memblock.reserved, max_addr, 1599 - (phys_addr_t)ULLONG_MAX); 1549 + memblock_cap_memory_range(0, max_addr); 1600 1550 } 1601 1551 1602 1552 static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr)
+3 -1
virt/kvm/arm/vgic/vgic.c
··· 29 29 #define DEBUG_SPINLOCK_BUG_ON(p) 30 30 #endif 31 31 32 - struct vgic_global __section(.hyp.text) kvm_vgic_global_state = {.gicv3_cpuif = STATIC_KEY_FALSE_INIT,}; 32 + struct vgic_global kvm_vgic_global_state __ro_after_init = { 33 + .gicv3_cpuif = STATIC_KEY_FALSE_INIT, 34 + }; 33 35 34 36 /* 35 37 * Locking order is always: