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:
"Nothing major this time around.

Apart from the usual perf/PMU updates, some page table cleanups, the
notable features are average CPU frequency based on the AMUv1
counters, CONFIG_HOTPLUG_SMT and MOPS instructions (memcpy/memset) in
the uaccess routines.

Perf and PMUs:

- Support for the 'Rainier' CPU PMU from Arm

- Preparatory driver changes and cleanups that pave the way for BRBE
support

- Support for partial virtualisation of the Apple-M1 PMU

- Support for the second event filter in Arm CSPMU designs

- Minor fixes and cleanups (CMN and DWC PMUs)

- Enable EL2 requirements for FEAT_PMUv3p9

Power, CPU topology:

- Support for AMUv1-based average CPU frequency

- Run-time SMT control wired up for arm64 (CONFIG_HOTPLUG_SMT). It
adds a generic topology_is_primary_thread() function overridden by
x86 and powerpc

New(ish) features:

- MOPS (memcpy/memset) support for the uaccess routines

Security/confidential compute:

- Fix the DMA address for devices used in Realms with Arm CCA. The
CCA architecture uses the address bit to differentiate between
shared and private addresses

- Spectre-BHB: assume CPUs Linux doesn't know about vulnerable by
default

Memory management clean-ups:

- Drop the P*D_TABLE_BIT definition in preparation for 128-bit PTEs

- Some minor page table accessor clean-ups

- PIE/POE (permission indirection/overlay) helpers clean-up

Kselftests:

- MTE: skip hugetlb tests if MTE is not supported on such mappings
and user correct naming for sync/async tag checking modes

Miscellaneous:

- Add a PKEY_UNRESTRICTED definition as 0 to uapi (toolchain people
request)

- Sysreg updates for new register fields

- CPU type info for some Qualcomm Kryo cores"

* tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: (72 commits)
arm64: mm: Don't use %pK through printk
perf/arm_cspmu: Fix missing io.h include
arm64: errata: Add newer ARM cores to the spectre_bhb_loop_affected() lists
arm64: cputype: Add MIDR_CORTEX_A76AE
arm64: errata: Add KRYO 2XX/3XX/4XX silver cores to Spectre BHB safe list
arm64: errata: Assume that unknown CPUs _are_ vulnerable to Spectre BHB
arm64: errata: Add QCOM_KRYO_4XX_GOLD to the spectre_bhb_k24_list
arm64/sysreg: Enforce whole word match for open/close tokens
arm64/sysreg: Fix unbalanced closing block
arm64: Kconfig: Enable HOTPLUG_SMT
arm64: topology: Support SMT control on ACPI based system
arch_topology: Support SMT control for OF based system
cpu/SMT: Provide a default topology_is_primary_thread()
arm64/mm: Define PTDESC_ORDER
perf/arm_cspmu: Add PMEVFILT2R support
perf/arm_cspmu: Generalise event filtering
perf/arm_cspmu: Move register definitons to header
arm64/kernel: Always use level 2 or higher for early mappings
arm64/mm: Drop PXD_TABLE_BIT
arm64/mm: Check pmd_table() in pmd_trans_huge()
...

+1111 -479
+16 -1
Documentation/admin-guide/pm/cpufreq.rst
··· 248 248 If that frequency cannot be determined, this attribute should not 249 249 be present. 250 250 251 + ``cpuinfo_avg_freq`` 252 + An average frequency (in KHz) of all CPUs belonging to a given policy, 253 + derived from a hardware provided feedback and reported on a time frame 254 + spanning at most few milliseconds. 255 + 256 + This is expected to be based on the frequency the hardware actually runs 257 + at and, as such, might require specialised hardware support (such as AMU 258 + extension on ARM). If one cannot be determined, this attribute should 259 + not be present. 260 + 261 + Note, that failed attempt to retrieve current frequency for a given 262 + CPU(s) will result in an appropriate error, i.e: EAGAIN for CPU that 263 + remains idle (raised on ARM). 264 + 251 265 ``cpuinfo_max_freq`` 252 266 Maximum possible operating frequency the CPUs belonging to this policy 253 267 can run at (in kHz). ··· 307 293 Some architectures (e.g. ``x86``) may attempt to provide information 308 294 more precisely reflecting the current CPU frequency through this 309 295 attribute, but that still may not be the exact current CPU frequency as 310 - seen by the hardware at the moment. 296 + seen by the hardware at the moment. This behavior though, is only 297 + available via c:macro:``CPUFREQ_ARCH_CUR_FREQ`` option. 311 298 312 299 ``scaling_driver`` 313 300 The scaling driver currently in use.
+22
Documentation/arch/arm64/booting.rst
··· 288 288 289 289 - SCR_EL3.FGTEn (bit 27) must be initialised to 0b1. 290 290 291 + For CPUs with the Fine Grained Traps 2 (FEAT_FGT2) extension present: 292 + 293 + - If EL3 is present and the kernel is entered at EL2: 294 + 295 + - SCR_EL3.FGTEn2 (bit 59) must be initialised to 0b1. 296 + 291 297 For CPUs with support for HCRX_EL2 (FEAT_HCX) present: 292 298 293 299 - If EL3 is present and the kernel is entered at EL2: ··· 387 381 - If the kernel is entered at EL1 and EL2 is present: 388 382 389 383 - SMCR_EL2.EZT0 (bit 30) must be initialised to 0b1. 384 + 385 + For CPUs with the Performance Monitors Extension (FEAT_PMUv3p9): 386 + 387 + - If EL3 is present: 388 + 389 + - MDCR_EL3.EnPM2 (bit 7) must be initialised to 0b1. 390 + 391 + - If the kernel is entered at EL1 and EL2 is present: 392 + 393 + - HDFGRTR2_EL2.nPMICNTR_EL0 (bit 2) must be initialised to 0b1. 394 + - HDFGRTR2_EL2.nPMICFILTR_EL0 (bit 3) must be initialised to 0b1. 395 + - HDFGRTR2_EL2.nPMUACR_EL1 (bit 4) must be initialised to 0b1. 396 + 397 + - HDFGWTR2_EL2.nPMICNTR_EL0 (bit 2) must be initialised to 0b1. 398 + - HDFGWTR2_EL2.nPMICFILTR_EL0 (bit 3) must be initialised to 0b1. 399 + - HDFGWTR2_EL2.nPMUACR_EL1 (bit 4) must be initialised to 0b1. 390 400 391 401 For CPUs with Memory Copy and Memory Set instructions (FEAT_MOPS): 392 402
+2 -1
arch/arm64/Kconfig
··· 251 251 select HAVE_KRETPROBES 252 252 select HAVE_GENERIC_VDSO 253 253 select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU 254 + select HOTPLUG_SMT if HOTPLUG_CPU 254 255 select IRQ_DOMAIN 255 256 select IRQ_FORCED_THREADING 256 257 select KASAN_VMALLOC if KASAN ··· 325 324 default 18 326 325 327 326 # max bits determined by the following formula: 328 - # VA_BITS - PAGE_SHIFT - 3 327 + # VA_BITS - PTDESC_TABLE_SHIFT 329 328 config ARCH_MMAP_RND_BITS_MAX 330 329 default 19 if ARM64_VA_BITS=36 331 330 default 24 if ARM64_VA_BITS=39
+1
arch/arm64/include/asm/apple_m1_pmu.h
··· 37 37 #define PMCR0_PMI_ENABLE_8_9 GENMASK(45, 44) 38 38 39 39 #define SYS_IMP_APL_PMCR1_EL1 sys_reg(3, 1, 15, 1, 0) 40 + #define SYS_IMP_APL_PMCR1_EL12 sys_reg(3, 1, 15, 7, 2) 40 41 #define PMCR1_COUNT_A64_EL0_0_7 GENMASK(15, 8) 41 42 #define PMCR1_COUNT_A64_EL1_0_7 GENMASK(23, 16) 42 43 #define PMCR1_COUNT_A64_EL0_8_9 GENMASK(41, 40)
+9 -1
arch/arm64/include/asm/asm-extable.h
··· 9 9 #define EX_TYPE_BPF 1 10 10 #define EX_TYPE_UACCESS_ERR_ZERO 2 11 11 #define EX_TYPE_KACCESS_ERR_ZERO 3 12 - #define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4 12 + #define EX_TYPE_UACCESS_CPY 4 13 + #define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 5 13 14 14 15 /* Data fields for EX_TYPE_UACCESS_ERR_ZERO */ 15 16 #define EX_DATA_REG_ERR_SHIFT 0 ··· 23 22 #define EX_DATA_REG_DATA GENMASK(4, 0) 24 23 #define EX_DATA_REG_ADDR_SHIFT 5 25 24 #define EX_DATA_REG_ADDR GENMASK(9, 5) 25 + 26 + /* Data fields for EX_TYPE_UACCESS_CPY */ 27 + #define EX_DATA_UACCESS_WRITE BIT(0) 26 28 27 29 #ifdef __ASSEMBLY__ 28 30 ··· 71 67 .ifnc \fixup, 72 68 _asm_extable_uaccess \insn, \fixup 73 69 .endif 70 + .endm 71 + 72 + .macro _asm_extable_uaccess_cpy, insn, fixup, uaccess_is_write 73 + __ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_UACCESS_CPY, \uaccess_is_write) 74 74 .endm 75 75 76 76 #else /* __ASSEMBLY__ */
+4
arch/arm64/include/asm/asm-uaccess.h
··· 61 61 9999: x; \ 62 62 _asm_extable_uaccess 9999b, l 63 63 64 + #define USER_CPY(l, uaccess_is_write, x...) \ 65 + 9999: x; \ 66 + _asm_extable_uaccess_cpy 9999b, l, uaccess_is_write 67 + 64 68 /* 65 69 * Generate the assembly for LDTR/STTR with exception table entries. 66 70 * This is complicated as there is no post-increment or pair versions of the
+14
arch/arm64/include/asm/cputype.h
··· 75 75 #define ARM_CPU_PART_CORTEX_A76 0xD0B 76 76 #define ARM_CPU_PART_NEOVERSE_N1 0xD0C 77 77 #define ARM_CPU_PART_CORTEX_A77 0xD0D 78 + #define ARM_CPU_PART_CORTEX_A76AE 0xD0E 78 79 #define ARM_CPU_PART_NEOVERSE_V1 0xD40 79 80 #define ARM_CPU_PART_CORTEX_A78 0xD41 80 81 #define ARM_CPU_PART_CORTEX_A78AE 0xD42 ··· 120 119 #define QCOM_CPU_PART_KRYO 0x200 121 120 #define QCOM_CPU_PART_KRYO_2XX_GOLD 0x800 122 121 #define QCOM_CPU_PART_KRYO_2XX_SILVER 0x801 122 + #define QCOM_CPU_PART_KRYO_3XX_GOLD 0x802 123 123 #define QCOM_CPU_PART_KRYO_3XX_SILVER 0x803 124 124 #define QCOM_CPU_PART_KRYO_4XX_GOLD 0x804 125 125 #define QCOM_CPU_PART_KRYO_4XX_SILVER 0x805 ··· 161 159 #define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76) 162 160 #define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1) 163 161 #define MIDR_CORTEX_A77 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A77) 162 + #define MIDR_CORTEX_A76AE MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76AE) 164 163 #define MIDR_NEOVERSE_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V1) 165 164 #define MIDR_CORTEX_A78 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78) 166 165 #define MIDR_CORTEX_A78AE MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78AE) ··· 199 196 #define MIDR_QCOM_KRYO MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO) 200 197 #define MIDR_QCOM_KRYO_2XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_GOLD) 201 198 #define MIDR_QCOM_KRYO_2XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_2XX_SILVER) 199 + #define MIDR_QCOM_KRYO_3XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_3XX_GOLD) 202 200 #define MIDR_QCOM_KRYO_3XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_3XX_SILVER) 203 201 #define MIDR_QCOM_KRYO_4XX_GOLD MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_GOLD) 204 202 #define MIDR_QCOM_KRYO_4XX_SILVER MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO_4XX_SILVER) 205 203 #define MIDR_QCOM_ORYON_X1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_ORYON_X1) 204 + 205 + /* 206 + * NOTES: 207 + * - Qualcomm Kryo 5XX Prime / Gold ID themselves as MIDR_CORTEX_A77 208 + * - Qualcomm Kryo 5XX Silver IDs itself as MIDR_QCOM_KRYO_4XX_SILVER 209 + * - Qualcomm Kryo 6XX Prime IDs itself as MIDR_CORTEX_X1 210 + * - Qualcomm Kryo 6XX Gold IDs itself as ARM_CPU_PART_CORTEX_A78 211 + * - Qualcomm Kryo 6XX Silver IDs itself as MIDR_CORTEX_A55 212 + */ 213 + 206 214 #define MIDR_NVIDIA_DENVER MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_DENVER) 207 215 #define MIDR_NVIDIA_CARMEL MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_CARMEL) 208 216 #define MIDR_FUJITSU_A64FX MIDR_CPU_MODEL(ARM_CPU_IMP_FUJITSU, FUJITSU_CPU_PART_A64FX)
+25
arch/arm64/include/asm/el2_setup.h
··· 259 259 .Lskip_fgt_\@: 260 260 .endm 261 261 262 + .macro __init_el2_fgt2 263 + mrs x1, id_aa64mmfr0_el1 264 + ubfx x1, x1, #ID_AA64MMFR0_EL1_FGT_SHIFT, #4 265 + cmp x1, #ID_AA64MMFR0_EL1_FGT_FGT2 266 + b.lt .Lskip_fgt2_\@ 267 + 268 + mov x0, xzr 269 + mrs x1, id_aa64dfr0_el1 270 + ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4 271 + cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9 272 + b.lt .Lskip_pmuv3p9_\@ 273 + 274 + orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0 275 + orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0 276 + orr x0, x0, #HDFGRTR2_EL2_nPMUACR_EL1 277 + .Lskip_pmuv3p9_\@: 278 + msr_s SYS_HDFGRTR2_EL2, x0 279 + msr_s SYS_HDFGWTR2_EL2, x0 280 + msr_s SYS_HFGRTR2_EL2, xzr 281 + msr_s SYS_HFGWTR2_EL2, xzr 282 + msr_s SYS_HFGITR2_EL2, xzr 283 + .Lskip_fgt2_\@: 284 + .endm 285 + 262 286 .macro __init_el2_gcs 263 287 mrs_s x1, SYS_ID_AA64PFR1_EL1 264 288 ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4 ··· 328 304 __init_el2_nvhe_idregs 329 305 __init_el2_cptr 330 306 __init_el2_fgt 307 + __init_el2_fgt2 331 308 __init_el2_gcs 332 309 .endm 333 310
+3 -1
arch/arm64/include/asm/extable.h
··· 33 33 (b)->data = (tmp).data; \ 34 34 } while (0) 35 35 36 + bool insn_may_access_user(unsigned long addr, unsigned long esr); 37 + 36 38 #ifdef CONFIG_BPF_JIT 37 39 bool ex_handler_bpf(const struct exception_table_entry *ex, 38 40 struct pt_regs *regs); ··· 47 45 } 48 46 #endif /* !CONFIG_BPF_JIT */ 49 47 50 - bool fixup_exception(struct pt_regs *regs); 48 + bool fixup_exception(struct pt_regs *regs, unsigned long esr); 51 49 #endif
-1
arch/arm64/include/asm/fpsimd.h
··· 80 80 extern void fpsimd_preserve_current_state(void); 81 81 extern void fpsimd_restore_current_state(void); 82 82 extern void fpsimd_update_current_state(struct user_fpsimd_state const *state); 83 - extern void fpsimd_kvm_prepare(void); 84 83 85 84 struct cpu_fp_state { 86 85 struct user_fpsimd_state *st;
+4 -4
arch/arm64/include/asm/kernel-pgtable.h
··· 45 45 #define SPAN_NR_ENTRIES(vstart, vend, shift) \ 46 46 ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1) 47 47 48 - #define EARLY_ENTRIES(vstart, vend, shift, add) \ 49 - (SPAN_NR_ENTRIES(vstart, vend, shift) + (add)) 48 + #define EARLY_ENTRIES(lvl, vstart, vend) \ 49 + SPAN_NR_ENTRIES(vstart, vend, SWAPPER_BLOCK_SHIFT + lvl * PTDESC_TABLE_SHIFT) 50 50 51 - #define EARLY_LEVEL(lvl, lvls, vstart, vend, add) \ 52 - (lvls > lvl ? EARLY_ENTRIES(vstart, vend, SWAPPER_BLOCK_SHIFT + lvl * (PAGE_SHIFT - 3), add) : 0) 51 + #define EARLY_LEVEL(lvl, lvls, vstart, vend, add) \ 52 + ((lvls) > (lvl) ? EARLY_ENTRIES(lvl, vstart, vend) + (add) : 0) 53 53 54 54 #define EARLY_PAGES(lvls, vstart, vend, add) (1 /* PGDIR page */ \ 55 55 + EARLY_LEVEL(3, (lvls), (vstart), (vend), add) /* each entry needs a next level page table */ \
+11
arch/arm64/include/asm/mem_encrypt.h
··· 21 21 return is_realm_world(); 22 22 } 23 23 24 + /* 25 + * For Arm CCA guests, canonical addresses are "encrypted", so no changes 26 + * required for dma_addr_encrypted(). 27 + * The unencrypted DMA buffers must be accessed via the unprotected IPA, 28 + * "top IPA bit" set. 29 + */ 30 + #define dma_addr_unencrypted(x) ((x) | PROT_NS_SHARED) 31 + 32 + /* Clear the "top" IPA bit while converting back */ 33 + #define dma_addr_canonical(x) ((x) & ~PROT_NS_SHARED) 34 + 24 35 #endif /* __ASM_MEM_ENCRYPT_H */
+18 -17
arch/arm64/include/asm/pgtable-hwdef.h
··· 7 7 8 8 #include <asm/memory.h> 9 9 10 + #define PTDESC_ORDER 3 11 + 12 + /* Number of VA bits resolved by a single translation table level */ 13 + #define PTDESC_TABLE_SHIFT (PAGE_SHIFT - PTDESC_ORDER) 14 + 10 15 /* 11 16 * Number of page-table levels required to address 'va_bits' wide 12 17 * address, without section mapping. We resolve the top (va_bits - PAGE_SHIFT) 13 - * bits with (PAGE_SHIFT - 3) bits at each page table level. Hence: 18 + * bits with PTDESC_TABLE_SHIFT bits at each page table level. Hence: 14 19 * 15 - * levels = DIV_ROUND_UP((va_bits - PAGE_SHIFT), (PAGE_SHIFT - 3)) 20 + * levels = DIV_ROUND_UP((va_bits - PAGE_SHIFT), PTDESC_TABLE_SHIFT) 16 21 * 17 22 * where DIV_ROUND_UP(n, d) => (((n) + (d) - 1) / (d)) 18 23 * 19 24 * We cannot include linux/kernel.h which defines DIV_ROUND_UP here 20 25 * due to build issues. So we open code DIV_ROUND_UP here: 21 26 * 22 - * ((((va_bits) - PAGE_SHIFT) + (PAGE_SHIFT - 3) - 1) / (PAGE_SHIFT - 3)) 27 + * ((((va_bits) - PAGE_SHIFT) + PTDESC_TABLE_SHIFT - 1) / PTDESC_TABLE_SHIFT) 23 28 * 24 29 * which gets simplified as : 25 30 */ 26 - #define ARM64_HW_PGTABLE_LEVELS(va_bits) (((va_bits) - 4) / (PAGE_SHIFT - 3)) 31 + #define ARM64_HW_PGTABLE_LEVELS(va_bits) \ 32 + (((va_bits) - PTDESC_ORDER - 1) / PTDESC_TABLE_SHIFT) 27 33 28 34 /* 29 35 * Size mapped by an entry at level n ( -1 <= n <= 3) 30 - * We map (PAGE_SHIFT - 3) at all translation levels and PAGE_SHIFT bits 36 + * We map PTDESC_TABLE_SHIFT at all translation levels and PAGE_SHIFT bits 31 37 * in the final page. The maximum number of translation levels supported by 32 38 * the architecture is 5. Hence, starting at level n, we have further 33 39 * ((4 - n) - 1) levels of translation excluding the offset within the page. 34 40 * So, the total number of bits mapped by an entry at level n is : 35 41 * 36 - * ((4 - n) - 1) * (PAGE_SHIFT - 3) + PAGE_SHIFT 42 + * ((4 - n) - 1) * PTDESC_TABLE_SHIFT + PAGE_SHIFT 37 43 * 38 44 * Rearranging it a bit we get : 39 - * (4 - n) * (PAGE_SHIFT - 3) + 3 45 + * (4 - n) * PTDESC_TABLE_SHIFT + PTDESC_ORDER 40 46 */ 41 - #define ARM64_HW_PGTABLE_LEVEL_SHIFT(n) ((PAGE_SHIFT - 3) * (4 - (n)) + 3) 47 + #define ARM64_HW_PGTABLE_LEVEL_SHIFT(n) (PTDESC_TABLE_SHIFT * (4 - (n)) + PTDESC_ORDER) 42 48 43 - #define PTRS_PER_PTE (1 << (PAGE_SHIFT - 3)) 49 + #define PTRS_PER_PTE (1 << PTDESC_TABLE_SHIFT) 44 50 45 51 /* 46 52 * PMD_SHIFT determines the size a level 2 page table entry can map. ··· 55 49 #define PMD_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(2) 56 50 #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT) 57 51 #define PMD_MASK (~(PMD_SIZE-1)) 58 - #define PTRS_PER_PMD (1 << (PAGE_SHIFT - 3)) 52 + #define PTRS_PER_PMD (1 << PTDESC_TABLE_SHIFT) 59 53 #endif 60 54 61 55 /* ··· 65 59 #define PUD_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(1) 66 60 #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT) 67 61 #define PUD_MASK (~(PUD_SIZE-1)) 68 - #define PTRS_PER_PUD (1 << (PAGE_SHIFT - 3)) 62 + #define PTRS_PER_PUD (1 << PTDESC_TABLE_SHIFT) 69 63 #endif 70 64 71 65 #if CONFIG_PGTABLE_LEVELS > 4 72 66 #define P4D_SHIFT ARM64_HW_PGTABLE_LEVEL_SHIFT(0) 73 67 #define P4D_SIZE (_AC(1, UL) << P4D_SHIFT) 74 68 #define P4D_MASK (~(P4D_SIZE-1)) 75 - #define PTRS_PER_P4D (1 << (PAGE_SHIFT - 3)) 69 + #define PTRS_PER_P4D (1 << PTDESC_TABLE_SHIFT) 76 70 #endif 77 71 78 72 /* ··· 103 97 * Level -1 descriptor (PGD). 104 98 */ 105 99 #define PGD_TYPE_TABLE (_AT(pgdval_t, 3) << 0) 106 - #define PGD_TABLE_BIT (_AT(pgdval_t, 1) << 1) 107 100 #define PGD_TYPE_MASK (_AT(pgdval_t, 3) << 0) 108 101 #define PGD_TABLE_AF (_AT(pgdval_t, 1) << 10) /* Ignored if no FEAT_HAFT */ 109 102 #define PGD_TABLE_PXN (_AT(pgdval_t, 1) << 59) ··· 112 107 * Level 0 descriptor (P4D). 113 108 */ 114 109 #define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) 115 - #define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) 116 110 #define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) 117 111 #define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) 118 112 #define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ ··· 123 119 * Level 1 descriptor (PUD). 124 120 */ 125 121 #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) 126 - #define PUD_TABLE_BIT (_AT(pudval_t, 1) << 1) 127 122 #define PUD_TYPE_MASK (_AT(pudval_t, 3) << 0) 128 123 #define PUD_TYPE_SECT (_AT(pudval_t, 1) << 0) 129 124 #define PUD_SECT_RDONLY (_AT(pudval_t, 1) << 7) /* AP[2] */ ··· 136 133 #define PMD_TYPE_MASK (_AT(pmdval_t, 3) << 0) 137 134 #define PMD_TYPE_TABLE (_AT(pmdval_t, 3) << 0) 138 135 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0) 139 - #define PMD_TABLE_BIT (_AT(pmdval_t, 1) << 1) 140 136 #define PMD_TABLE_AF (_AT(pmdval_t, 1) << 10) /* Ignored if no FEAT_HAFT */ 141 137 142 138 /* ··· 164 162 #define PTE_VALID (_AT(pteval_t, 1) << 0) 165 163 #define PTE_TYPE_MASK (_AT(pteval_t, 3) << 0) 166 164 #define PTE_TYPE_PAGE (_AT(pteval_t, 3) << 0) 167 - #define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1) 168 165 #define PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */ 169 166 #define PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */ 170 167 #define PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
+18 -18
arch/arm64/include/asm/pgtable-prot.h
··· 169 169 #define PAGE_GCS_RO __pgprot(_PAGE_GCS_RO) 170 170 171 171 #define PIE_E0 ( \ 172 - PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_GCS) | \ 173 - PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ 174 - PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ 175 - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX_O) | \ 176 - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX_O) | \ 177 - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R_O) | \ 178 - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW_O)) 172 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_GCS), PIE_GCS) | \ 173 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_GCS_RO), PIE_R) | \ 174 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_EXECONLY), PIE_X_O) | \ 175 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_READONLY_EXEC), PIE_RX_O) | \ 176 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RWX_O) | \ 177 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_READONLY), PIE_R_O) | \ 178 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_SHARED), PIE_RW_O)) 179 179 180 180 #define PIE_E1 ( \ 181 - PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS), PIE_NONE_O) | \ 182 - PIRx_ELx_PERM(pte_pi_index(_PAGE_GCS_RO), PIE_NONE_O) | \ 183 - PIRx_ELx_PERM(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ 184 - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \ 185 - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \ 186 - PIRx_ELx_PERM(pte_pi_index(_PAGE_READONLY), PIE_R) | \ 187 - PIRx_ELx_PERM(pte_pi_index(_PAGE_SHARED), PIE_RW) | \ 188 - PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_ROX), PIE_RX) | \ 189 - PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_EXEC), PIE_RWX) | \ 190 - PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL_RO), PIE_R) | \ 191 - PIRx_ELx_PERM(pte_pi_index(_PAGE_KERNEL), PIE_RW)) 181 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_GCS), PIE_NONE_O) | \ 182 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_GCS_RO), PIE_NONE_O) | \ 183 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_EXECONLY), PIE_NONE_O) | \ 184 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_READONLY_EXEC), PIE_R) | \ 185 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_SHARED_EXEC), PIE_RW) | \ 186 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_READONLY), PIE_R) | \ 187 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_SHARED), PIE_RW) | \ 188 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_KERNEL_ROX), PIE_RX) | \ 189 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_KERNEL_EXEC), PIE_RWX) | \ 190 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_KERNEL_RO), PIE_R) | \ 191 + PIRx_ELx_PERM_PREP(pte_pi_index(_PAGE_KERNEL), PIE_RW)) 192 192 193 193 #endif /* __ASM_PGTABLE_PROT_H */
+55 -25
arch/arm64/include/asm/pgtable.h
··· 68 68 #define pte_ERROR(e) \ 69 69 pr_err("%s:%d: bad pte %016llx.\n", __FILE__, __LINE__, pte_val(e)) 70 70 71 - /* 72 - * Macros to convert between a physical address and its placement in a 73 - * page table entry, taking care of 52-bit addresses. 74 - */ 75 71 #ifdef CONFIG_ARM64_PA_BITS_52 76 72 static inline phys_addr_t __pte_to_phys(pte_t pte) 77 73 { ··· 80 84 return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK; 81 85 } 82 86 #else 83 - #define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_LOW) 84 - #define __phys_to_pte_val(phys) (phys) 87 + static inline phys_addr_t __pte_to_phys(pte_t pte) 88 + { 89 + return pte_val(pte) & PTE_ADDR_LOW; 90 + } 91 + 92 + static inline pteval_t __phys_to_pte_val(phys_addr_t phys) 93 + { 94 + return phys; 95 + } 85 96 #endif 86 97 87 98 #define pte_pfn(pte) (__pte_to_phys(pte) >> PAGE_SHIFT) ··· 486 483 487 484 static inline pgprot_t mk_pud_sect_prot(pgprot_t prot) 488 485 { 489 - return __pgprot((pgprot_val(prot) & ~PUD_TABLE_BIT) | PUD_TYPE_SECT); 486 + return __pgprot((pgprot_val(prot) & ~PUD_TYPE_MASK) | PUD_TYPE_SECT); 490 487 } 491 488 492 489 static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot) 493 490 { 494 - return __pgprot((pgprot_val(prot) & ~PMD_TABLE_BIT) | PMD_TYPE_SECT); 491 + return __pgprot((pgprot_val(prot) & ~PMD_TYPE_MASK) | PMD_TYPE_SECT); 495 492 } 496 493 497 494 static inline pte_t pte_swp_mkexclusive(pte_t pte) ··· 551 548 #endif 552 549 553 550 #define pmd_present(pmd) pte_present(pmd_pte(pmd)) 554 - 555 - /* 556 - * THP definitions. 557 - */ 558 - 559 - #ifdef CONFIG_TRANSPARENT_HUGEPAGE 560 - static inline int pmd_trans_huge(pmd_t pmd) 561 - { 562 - return pmd_val(pmd) && pmd_present(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT); 563 - } 564 - #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 565 - 566 551 #define pmd_dirty(pmd) pte_dirty(pmd_pte(pmd)) 567 552 #define pmd_young(pmd) pte_young(pmd_pte(pmd)) 568 553 #define pmd_valid(pmd) pte_valid(pmd_pte(pmd)) ··· 576 585 577 586 #define pmd_write(pmd) pte_write(pmd_pte(pmd)) 578 587 579 - #define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) 588 + static inline pmd_t pmd_mkhuge(pmd_t pmd) 589 + { 590 + /* 591 + * It's possible that the pmd is present-invalid on entry 592 + * and in that case it needs to remain present-invalid on 593 + * exit. So ensure the VALID bit does not get modified. 594 + */ 595 + pmdval_t mask = PMD_TYPE_MASK & ~PTE_VALID; 596 + pmdval_t val = PMD_TYPE_SECT & ~PTE_VALID; 597 + 598 + return __pmd((pmd_val(pmd) & ~mask) | val); 599 + } 580 600 581 601 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 582 602 #define pmd_devmap(pmd) pte_devmap(pmd_pte(pmd)) ··· 615 613 #define pud_mkyoung(pud) pte_pud(pte_mkyoung(pud_pte(pud))) 616 614 #define pud_write(pud) pte_write(pud_pte(pud)) 617 615 618 - #define pud_mkhuge(pud) (__pud(pud_val(pud) & ~PUD_TABLE_BIT)) 616 + static inline pud_t pud_mkhuge(pud_t pud) 617 + { 618 + /* 619 + * It's possible that the pud is present-invalid on entry 620 + * and in that case it needs to remain present-invalid on 621 + * exit. So ensure the VALID bit does not get modified. 622 + */ 623 + pudval_t mask = PUD_TYPE_MASK & ~PTE_VALID; 624 + pudval_t val = PUD_TYPE_SECT & ~PTE_VALID; 625 + 626 + return __pud((pud_val(pud) & ~mask) | val); 627 + } 619 628 620 629 #define __pud_to_phys(pud) __pte_to_phys(pud_pte(pud)) 621 630 #define __phys_to_pud_val(phys) __phys_to_pte_val(phys) ··· 737 724 #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE) 738 725 #define pte_leaf_size(pte) (pte_cont(pte) ? CONT_PTE_SIZE : PAGE_SIZE) 739 726 727 + #ifdef CONFIG_TRANSPARENT_HUGEPAGE 728 + static inline int pmd_trans_huge(pmd_t pmd) 729 + { 730 + /* 731 + * If pmd is present-invalid, pmd_table() won't detect it 732 + * as a table, so force the valid bit for the comparison. 733 + */ 734 + return pmd_val(pmd) && pmd_present(pmd) && 735 + !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID)); 736 + } 737 + #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 738 + 740 739 #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 741 740 static inline bool pud_sect(pud_t pud) { return false; } 742 741 static inline bool pud_table(pud_t pud) { return true; } ··· 830 805 pr_err("%s:%d: bad pmd %016llx.\n", __FILE__, __LINE__, pmd_val(e)) 831 806 832 807 #define pud_none(pud) (!pud_val(pud)) 833 - #define pud_bad(pud) (!pud_table(pud)) 808 + #define pud_bad(pud) ((pud_val(pud) & PUD_TYPE_MASK) != \ 809 + PUD_TYPE_TABLE) 834 810 #define pud_present(pud) pte_present(pud_pte(pud)) 835 811 #ifndef __PAGETABLE_PMD_FOLDED 836 812 #define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) ··· 922 896 pr_err("%s:%d: bad pud %016llx.\n", __FILE__, __LINE__, pud_val(e)) 923 897 924 898 #define p4d_none(p4d) (pgtable_l4_enabled() && !p4d_val(p4d)) 925 - #define p4d_bad(p4d) (pgtable_l4_enabled() && !(p4d_val(p4d) & P4D_TABLE_BIT)) 899 + #define p4d_bad(p4d) (pgtable_l4_enabled() && \ 900 + ((p4d_val(p4d) & P4D_TYPE_MASK) != \ 901 + P4D_TYPE_TABLE)) 926 902 #define p4d_present(p4d) (!p4d_none(p4d)) 927 903 928 904 static inline void set_p4d(p4d_t *p4dp, p4d_t p4d) ··· 1051 1023 pr_err("%s:%d: bad p4d %016llx.\n", __FILE__, __LINE__, p4d_val(e)) 1052 1024 1053 1025 #define pgd_none(pgd) (pgtable_l5_enabled() && !pgd_val(pgd)) 1054 - #define pgd_bad(pgd) (pgtable_l5_enabled() && !(pgd_val(pgd) & PGD_TABLE_BIT)) 1026 + #define pgd_bad(pgd) (pgtable_l5_enabled() && \ 1027 + ((pgd_val(pgd) & PGD_TYPE_MASK) != \ 1028 + PGD_TYPE_TABLE)) 1055 1029 #define pgd_present(pgd) (!pgd_none(pgd)) 1056 1030 1057 1031 static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
+6 -5
arch/arm64/include/asm/por.h
··· 6 6 #ifndef _ASM_ARM64_POR_H 7 7 #define _ASM_ARM64_POR_H 8 8 9 - #define POR_BITS_PER_PKEY 4 10 - #define POR_ELx_IDX(por_elx, idx) (((por_elx) >> ((idx) * POR_BITS_PER_PKEY)) & 0xf) 9 + #include <asm/sysreg.h> 10 + 11 + #define POR_EL0_INIT POR_ELx_PERM_PREP(0, POE_RWX) 11 12 12 13 static inline bool por_elx_allows_read(u64 por, u8 pkey) 13 14 { 14 - u8 perm = POR_ELx_IDX(por, pkey); 15 + u8 perm = POR_ELx_PERM_GET(pkey, por); 15 16 16 17 return perm & POE_R; 17 18 } 18 19 19 20 static inline bool por_elx_allows_write(u64 por, u8 pkey) 20 21 { 21 - u8 perm = POR_ELx_IDX(por, pkey); 22 + u8 perm = POR_ELx_PERM_GET(pkey, por); 22 23 23 24 return perm & POE_W; 24 25 } 25 26 26 27 static inline bool por_elx_allows_exec(u64 por, u8 pkey) 27 28 { 28 - u8 perm = POR_ELx_IDX(por, pkey); 29 + u8 perm = POR_ELx_PERM_GET(pkey, por); 29 30 30 31 return perm & POE_X; 31 32 }
-1
arch/arm64/include/asm/spectre.h
··· 97 97 98 98 enum mitigation_state arm64_get_spectre_bhb_state(void); 99 99 bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, int scope); 100 - u8 spectre_bhb_loop_affected(int scope); 101 100 void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *__unused); 102 101 bool try_emulate_el1_ssbs(struct pt_regs *regs, u32 instr); 103 102
+10 -5
arch/arm64/include/asm/sysreg.h
··· 1062 1062 #define PIE_RX UL(0xa) 1063 1063 #define PIE_RW UL(0xc) 1064 1064 #define PIE_RWX UL(0xe) 1065 + #define PIE_MASK UL(0xf) 1065 1066 1066 - #define PIRx_ELx_PERM(idx, perm) ((perm) << ((idx) * 4)) 1067 + #define PIRx_ELx_BITS_PER_IDX 4 1068 + #define PIRx_ELx_PERM_SHIFT(idx) ((idx) * PIRx_ELx_BITS_PER_IDX) 1069 + #define PIRx_ELx_PERM_PREP(idx, perm) (((perm) & PIE_MASK) << PIRx_ELx_PERM_SHIFT(idx)) 1067 1070 1068 1071 /* 1069 1072 * Permission Overlay Extension (POE) permission encodings. ··· 1077 1074 #define POE_RX UL(0x3) 1078 1075 #define POE_W UL(0x4) 1079 1076 #define POE_RW UL(0x5) 1080 - #define POE_XW UL(0x6) 1081 - #define POE_RXW UL(0x7) 1077 + #define POE_WX UL(0x6) 1078 + #define POE_RWX UL(0x7) 1082 1079 #define POE_MASK UL(0xf) 1083 1080 1084 - /* Initial value for Permission Overlay Extension for EL0 */ 1085 - #define POR_EL0_INIT POE_RXW 1081 + #define POR_ELx_BITS_PER_IDX 4 1082 + #define POR_ELx_PERM_SHIFT(idx) ((idx) * POR_ELx_BITS_PER_IDX) 1083 + #define POR_ELx_PERM_GET(idx, reg) (((reg) >> POR_ELx_PERM_SHIFT(idx)) & POE_MASK) 1084 + #define POR_ELx_PERM_PREP(idx, perm) (((perm) & POE_MASK) << POR_ELx_PERM_SHIFT(idx)) 1086 1085 1087 1086 /* 1088 1087 * Definitions for Guarded Control Stack
+3 -3
arch/arm64/kernel/pi/map_range.c
··· 31 31 { 32 32 u64 cmask = (level == 3) ? CONT_PTE_SIZE - 1 : U64_MAX; 33 33 pteval_t protval = pgprot_val(prot) & ~PTE_TYPE_MASK; 34 - int lshift = (3 - level) * (PAGE_SHIFT - 3); 34 + int lshift = (3 - level) * PTDESC_TABLE_SHIFT; 35 35 u64 lmask = (PAGE_SIZE << lshift) - 1; 36 36 37 37 start &= PAGE_MASK; ··· 45 45 * clearing the mapping 46 46 */ 47 47 if (protval) 48 - protval |= (level < 3) ? PMD_TYPE_SECT : PTE_TYPE_PAGE; 48 + protval |= (level == 2) ? PMD_TYPE_SECT : PTE_TYPE_PAGE; 49 49 50 50 while (start < end) { 51 51 u64 next = min((start | lmask) + 1, PAGE_ALIGN(end)); 52 52 53 - if (level < 3 && (start | next | pa) & lmask) { 53 + if (level < 2 || (level == 2 && (start | next | pa) & lmask)) { 54 54 /* 55 55 * This chunk needs a finer grained mapping. Create a 56 56 * table mapping if necessary and recurse.
+113 -95
arch/arm64/kernel/proton-pack.c
··· 845 845 * This must be called with SCOPE_LOCAL_CPU for each type of CPU, before any 846 846 * SCOPE_SYSTEM call will give the right answer. 847 847 */ 848 - u8 spectre_bhb_loop_affected(int scope) 848 + static bool is_spectre_bhb_safe(int scope) 849 + { 850 + static const struct midr_range spectre_bhb_safe_list[] = { 851 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), 852 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), 853 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), 854 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A510), 855 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A520), 856 + MIDR_ALL_VERSIONS(MIDR_BRAHMA_B53), 857 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_2XX_SILVER), 858 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_3XX_SILVER), 859 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_SILVER), 860 + {}, 861 + }; 862 + static bool all_safe = true; 863 + 864 + if (scope != SCOPE_LOCAL_CPU) 865 + return all_safe; 866 + 867 + if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_safe_list)) 868 + return true; 869 + 870 + all_safe = false; 871 + 872 + return false; 873 + } 874 + 875 + static u8 spectre_bhb_loop_affected(void) 849 876 { 850 877 u8 k = 0; 851 - static u8 max_bhb_k; 852 878 853 - if (scope == SCOPE_LOCAL_CPU) { 854 - static const struct midr_range spectre_bhb_k32_list[] = { 855 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A78), 856 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A78AE), 857 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A78C), 858 - MIDR_ALL_VERSIONS(MIDR_CORTEX_X1), 859 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A710), 860 - MIDR_ALL_VERSIONS(MIDR_CORTEX_X2), 861 - MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), 862 - MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), 863 - {}, 864 - }; 865 - static const struct midr_range spectre_bhb_k24_list[] = { 866 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A76), 867 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A77), 868 - MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1), 869 - {}, 870 - }; 871 - static const struct midr_range spectre_bhb_k11_list[] = { 872 - MIDR_ALL_VERSIONS(MIDR_AMPERE1), 873 - {}, 874 - }; 875 - static const struct midr_range spectre_bhb_k8_list[] = { 876 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 877 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 878 - {}, 879 - }; 879 + static const struct midr_range spectre_bhb_k132_list[] = { 880 + MIDR_ALL_VERSIONS(MIDR_CORTEX_X3), 881 + MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), 882 + }; 883 + static const struct midr_range spectre_bhb_k38_list[] = { 884 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A715), 885 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), 886 + }; 887 + static const struct midr_range spectre_bhb_k32_list[] = { 888 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A78), 889 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A78AE), 890 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A78C), 891 + MIDR_ALL_VERSIONS(MIDR_CORTEX_X1), 892 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A710), 893 + MIDR_ALL_VERSIONS(MIDR_CORTEX_X2), 894 + MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), 895 + MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), 896 + {}, 897 + }; 898 + static const struct midr_range spectre_bhb_k24_list[] = { 899 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A76), 900 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A76AE), 901 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A77), 902 + MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1), 903 + MIDR_ALL_VERSIONS(MIDR_QCOM_KRYO_4XX_GOLD), 904 + {}, 905 + }; 906 + static const struct midr_range spectre_bhb_k11_list[] = { 907 + MIDR_ALL_VERSIONS(MIDR_AMPERE1), 908 + {}, 909 + }; 910 + static const struct midr_range spectre_bhb_k8_list[] = { 911 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), 912 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), 913 + {}, 914 + }; 880 915 881 - if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k32_list)) 882 - k = 32; 883 - else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k24_list)) 884 - k = 24; 885 - else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k11_list)) 886 - k = 11; 887 - else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k8_list)) 888 - k = 8; 889 - 890 - max_bhb_k = max(max_bhb_k, k); 891 - } else { 892 - k = max_bhb_k; 893 - } 916 + if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k132_list)) 917 + k = 132; 918 + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k38_list)) 919 + k = 38; 920 + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k32_list)) 921 + k = 32; 922 + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k24_list)) 923 + k = 24; 924 + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k11_list)) 925 + k = 11; 926 + else if (is_midr_in_range_list(read_cpuid_id(), spectre_bhb_k8_list)) 927 + k = 8; 894 928 895 929 return k; 896 930 } ··· 950 916 } 951 917 } 952 918 953 - static bool is_spectre_bhb_fw_affected(int scope) 919 + static bool has_spectre_bhb_fw_mitigation(void) 954 920 { 955 - static bool system_affected; 956 921 enum mitigation_state fw_state; 957 922 bool has_smccc = arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_NONE; 958 - static const struct midr_range spectre_bhb_firmware_mitigated_list[] = { 959 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), 960 - MIDR_ALL_VERSIONS(MIDR_CORTEX_A75), 961 - {}, 962 - }; 963 - bool cpu_in_list = is_midr_in_range_list(read_cpuid_id(), 964 - spectre_bhb_firmware_mitigated_list); 965 - 966 - if (scope != SCOPE_LOCAL_CPU) 967 - return system_affected; 968 923 969 924 fw_state = spectre_bhb_get_cpu_fw_mitigation_state(); 970 - if (cpu_in_list || (has_smccc && fw_state == SPECTRE_MITIGATED)) { 971 - system_affected = true; 972 - return true; 973 - } 974 - 975 - return false; 925 + return has_smccc && fw_state == SPECTRE_MITIGATED; 976 926 } 977 927 978 928 static bool supports_ecbhb(int scope) ··· 972 954 ID_AA64MMFR1_EL1_ECBHB_SHIFT); 973 955 } 974 956 957 + static u8 max_bhb_k; 958 + 975 959 bool is_spectre_bhb_affected(const struct arm64_cpu_capabilities *entry, 976 960 int scope) 977 961 { ··· 982 962 if (supports_csv2p3(scope)) 983 963 return false; 984 964 985 - if (supports_clearbhb(scope)) 986 - return true; 965 + if (is_spectre_bhb_safe(scope)) 966 + return false; 987 967 988 - if (spectre_bhb_loop_affected(scope)) 989 - return true; 968 + /* 969 + * At this point the core isn't known to be "safe" so we're going to 970 + * assume it's vulnerable. We still need to update `max_bhb_k` though, 971 + * but only if we aren't mitigating with clearbhb though. 972 + */ 973 + if (scope == SCOPE_LOCAL_CPU && !supports_clearbhb(SCOPE_LOCAL_CPU)) 974 + max_bhb_k = max(max_bhb_k, spectre_bhb_loop_affected()); 990 975 991 - if (is_spectre_bhb_fw_affected(scope)) 992 - return true; 993 - 994 - return false; 976 + return true; 995 977 } 996 978 997 979 static void this_cpu_set_vectors(enum arm64_bp_harden_el1_vectors slot) ··· 1024 1002 void spectre_bhb_enable_mitigation(const struct arm64_cpu_capabilities *entry) 1025 1003 { 1026 1004 bp_hardening_cb_t cpu_cb; 1027 - enum mitigation_state fw_state, state = SPECTRE_VULNERABLE; 1005 + enum mitigation_state state = SPECTRE_VULNERABLE; 1028 1006 struct bp_hardening_data *data = this_cpu_ptr(&bp_hardening_data); 1029 1007 1030 1008 if (!is_spectre_bhb_affected(entry, SCOPE_LOCAL_CPU)) ··· 1050 1028 this_cpu_set_vectors(EL1_VECTOR_BHB_CLEAR_INSN); 1051 1029 state = SPECTRE_MITIGATED; 1052 1030 set_bit(BHB_INSN, &system_bhb_mitigations); 1053 - } else if (spectre_bhb_loop_affected(SCOPE_LOCAL_CPU)) { 1031 + } else if (spectre_bhb_loop_affected()) { 1054 1032 /* 1055 1033 * Ensure KVM uses the indirect vector which will have the 1056 1034 * branchy-loop added. A57/A72-r0 will already have selected ··· 1063 1041 this_cpu_set_vectors(EL1_VECTOR_BHB_LOOP); 1064 1042 state = SPECTRE_MITIGATED; 1065 1043 set_bit(BHB_LOOP, &system_bhb_mitigations); 1066 - } else if (is_spectre_bhb_fw_affected(SCOPE_LOCAL_CPU)) { 1067 - fw_state = spectre_bhb_get_cpu_fw_mitigation_state(); 1068 - if (fw_state == SPECTRE_MITIGATED) { 1069 - /* 1070 - * Ensure KVM uses one of the spectre bp_hardening 1071 - * vectors. The indirect vector doesn't include the EL3 1072 - * call, so needs upgrading to 1073 - * HYP_VECTOR_SPECTRE_INDIRECT. 1074 - */ 1075 - if (!data->slot || data->slot == HYP_VECTOR_INDIRECT) 1076 - data->slot += 1; 1044 + } else if (has_spectre_bhb_fw_mitigation()) { 1045 + /* 1046 + * Ensure KVM uses one of the spectre bp_hardening 1047 + * vectors. The indirect vector doesn't include the EL3 1048 + * call, so needs upgrading to 1049 + * HYP_VECTOR_SPECTRE_INDIRECT. 1050 + */ 1051 + if (!data->slot || data->slot == HYP_VECTOR_INDIRECT) 1052 + data->slot += 1; 1077 1053 1078 - this_cpu_set_vectors(EL1_VECTOR_BHB_FW); 1054 + this_cpu_set_vectors(EL1_VECTOR_BHB_FW); 1079 1055 1080 - /* 1081 - * The WA3 call in the vectors supersedes the WA1 call 1082 - * made during context-switch. Uninstall any firmware 1083 - * bp_hardening callback. 1084 - */ 1085 - cpu_cb = spectre_v2_get_sw_mitigation_cb(); 1086 - if (__this_cpu_read(bp_hardening_data.fn) != cpu_cb) 1087 - __this_cpu_write(bp_hardening_data.fn, NULL); 1056 + /* 1057 + * The WA3 call in the vectors supersedes the WA1 call 1058 + * made during context-switch. Uninstall any firmware 1059 + * bp_hardening callback. 1060 + */ 1061 + cpu_cb = spectre_v2_get_sw_mitigation_cb(); 1062 + if (__this_cpu_read(bp_hardening_data.fn) != cpu_cb) 1063 + __this_cpu_write(bp_hardening_data.fn, NULL); 1088 1064 1089 - state = SPECTRE_MITIGATED; 1090 - set_bit(BHB_FW, &system_bhb_mitigations); 1091 - } 1065 + state = SPECTRE_MITIGATED; 1066 + set_bit(BHB_FW, &system_bhb_mitigations); 1092 1067 } 1093 1068 1094 1069 update_mitigation_state(&spectre_bhb_state, state); ··· 1119 1100 { 1120 1101 u8 rd; 1121 1102 u32 insn; 1122 - u16 loop_count = spectre_bhb_loop_affected(SCOPE_SYSTEM); 1123 1103 1124 1104 BUG_ON(nr_inst != 1); /* MOV -> MOV */ 1125 1105 ··· 1127 1109 1128 1110 insn = le32_to_cpu(*origptr); 1129 1111 rd = aarch64_insn_decode_register(AARCH64_INSN_REGTYPE_RD, insn); 1130 - insn = aarch64_insn_gen_movewide(rd, loop_count, 0, 1112 + insn = aarch64_insn_gen_movewide(rd, max_bhb_k, 0, 1131 1113 AARCH64_INSN_VARIANT_64BIT, 1132 1114 AARCH64_INSN_MOVEWIDE_ZERO); 1133 1115 *updptr++ = cpu_to_le32(insn);
+1 -1
arch/arm64/kernel/signal.c
··· 91 91 u64 por_enable_all = 0; 92 92 93 93 for (int pkey = 0; pkey < arch_max_pkey(); pkey++) 94 - por_enable_all |= POE_RXW << (pkey * POR_BITS_PER_PKEY); 94 + por_enable_all |= POR_ELx_PERM_PREP(pkey, POE_RWX); 95 95 96 96 ua_state->por_el0 = read_sysreg_s(SYS_POR_EL0); 97 97 write_sysreg_s(por_enable_all, SYS_POR_EL0);
+172 -10
arch/arm64/kernel/topology.c
··· 15 15 #include <linux/arch_topology.h> 16 16 #include <linux/cacheinfo.h> 17 17 #include <linux/cpufreq.h> 18 + #include <linux/cpu_smt.h> 18 19 #include <linux/init.h> 19 20 #include <linux/percpu.h> 21 + #include <linux/sched/isolation.h> 22 + #include <linux/xarray.h> 20 23 21 24 #include <asm/cpu.h> 22 25 #include <asm/cputype.h> ··· 40 37 return !!is_threaded; 41 38 } 42 39 40 + struct cpu_smt_info { 41 + unsigned int thread_num; 42 + int core_id; 43 + }; 44 + 43 45 /* 44 46 * Propagate the topology information of the processor_topology_node tree to the 45 47 * cpu_topology array. 46 48 */ 47 49 int __init parse_acpi_topology(void) 48 50 { 51 + unsigned int max_smt_thread_num = 1; 52 + struct cpu_smt_info *entry; 53 + struct xarray hetero_cpu; 54 + unsigned long hetero_id; 49 55 int cpu, topology_id; 50 56 51 57 if (acpi_disabled) 52 58 return 0; 59 + 60 + xa_init(&hetero_cpu); 53 61 54 62 for_each_possible_cpu(cpu) { 55 63 topology_id = find_acpi_cpu_topology(cpu, 0); ··· 71 57 cpu_topology[cpu].thread_id = topology_id; 72 58 topology_id = find_acpi_cpu_topology(cpu, 1); 73 59 cpu_topology[cpu].core_id = topology_id; 60 + 61 + /* 62 + * In the PPTT, CPUs below a node with the 'identical 63 + * implementation' flag have the same number of threads. 64 + * Count the number of threads for only one CPU (i.e. 65 + * one core_id) among those with the same hetero_id. 66 + * See the comment of find_acpi_cpu_topology_hetero_id() 67 + * for more details. 68 + * 69 + * One entry is created for each node having: 70 + * - the 'identical implementation' flag 71 + * - its parent not having the flag 72 + */ 73 + hetero_id = find_acpi_cpu_topology_hetero_id(cpu); 74 + entry = xa_load(&hetero_cpu, hetero_id); 75 + if (!entry) { 76 + entry = kzalloc(sizeof(*entry), GFP_KERNEL); 77 + WARN_ON_ONCE(!entry); 78 + 79 + if (entry) { 80 + entry->core_id = topology_id; 81 + entry->thread_num = 1; 82 + xa_store(&hetero_cpu, hetero_id, 83 + entry, GFP_KERNEL); 84 + } 85 + } else if (entry->core_id == topology_id) { 86 + entry->thread_num++; 87 + } 74 88 } else { 75 89 cpu_topology[cpu].thread_id = -1; 76 90 cpu_topology[cpu].core_id = topology_id; ··· 109 67 cpu_topology[cpu].package_id = topology_id; 110 68 } 111 69 70 + /* 71 + * This is a short loop since the number of XArray elements is the 72 + * number of heterogeneous CPU clusters. On a homogeneous system 73 + * there's only one entry in the XArray. 74 + */ 75 + xa_for_each(&hetero_cpu, hetero_id, entry) { 76 + max_smt_thread_num = max(max_smt_thread_num, entry->thread_num); 77 + xa_erase(&hetero_cpu, hetero_id); 78 + kfree(entry); 79 + } 80 + 81 + cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); 82 + xa_destroy(&hetero_cpu); 112 83 return 0; 113 84 } 114 85 #endif ··· 143 88 * initialized. 144 89 */ 145 90 static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, arch_max_freq_scale) = 1UL << (2 * SCHED_CAPACITY_SHIFT); 146 - static DEFINE_PER_CPU(u64, arch_const_cycles_prev); 147 - static DEFINE_PER_CPU(u64, arch_core_cycles_prev); 148 91 static cpumask_var_t amu_fie_cpus; 92 + 93 + struct amu_cntr_sample { 94 + u64 arch_const_cycles_prev; 95 + u64 arch_core_cycles_prev; 96 + unsigned long last_scale_update; 97 + }; 98 + 99 + static DEFINE_PER_CPU_SHARED_ALIGNED(struct amu_cntr_sample, cpu_amu_samples); 149 100 150 101 void update_freq_counters_refs(void) 151 102 { 152 - this_cpu_write(arch_core_cycles_prev, read_corecnt()); 153 - this_cpu_write(arch_const_cycles_prev, read_constcnt()); 103 + struct amu_cntr_sample *amu_sample = this_cpu_ptr(&cpu_amu_samples); 104 + 105 + amu_sample->arch_core_cycles_prev = read_corecnt(); 106 + amu_sample->arch_const_cycles_prev = read_constcnt(); 154 107 } 155 108 156 109 static inline bool freq_counters_valid(int cpu) 157 110 { 111 + struct amu_cntr_sample *amu_sample = per_cpu_ptr(&cpu_amu_samples, cpu); 112 + 158 113 if ((cpu >= nr_cpu_ids) || !cpumask_test_cpu(cpu, cpu_present_mask)) 159 114 return false; 160 115 ··· 173 108 return false; 174 109 } 175 110 176 - if (unlikely(!per_cpu(arch_const_cycles_prev, cpu) || 177 - !per_cpu(arch_core_cycles_prev, cpu))) { 111 + if (unlikely(!amu_sample->arch_const_cycles_prev || 112 + !amu_sample->arch_core_cycles_prev)) { 178 113 pr_debug("CPU%d: cycle counters are not enabled.\n", cpu); 179 114 return false; 180 115 } ··· 217 152 218 153 static void amu_scale_freq_tick(void) 219 154 { 155 + struct amu_cntr_sample *amu_sample = this_cpu_ptr(&cpu_amu_samples); 220 156 u64 prev_core_cnt, prev_const_cnt; 221 157 u64 core_cnt, const_cnt, scale; 222 158 223 - prev_const_cnt = this_cpu_read(arch_const_cycles_prev); 224 - prev_core_cnt = this_cpu_read(arch_core_cycles_prev); 159 + prev_const_cnt = amu_sample->arch_const_cycles_prev; 160 + prev_core_cnt = amu_sample->arch_core_cycles_prev; 225 161 226 162 update_freq_counters_refs(); 227 163 228 - const_cnt = this_cpu_read(arch_const_cycles_prev); 229 - core_cnt = this_cpu_read(arch_core_cycles_prev); 164 + const_cnt = amu_sample->arch_const_cycles_prev; 165 + core_cnt = amu_sample->arch_core_cycles_prev; 230 166 167 + /* 168 + * This should not happen unless the AMUs have been reset and the 169 + * counter values have not been restored - unlikely 170 + */ 231 171 if (unlikely(core_cnt <= prev_core_cnt || 232 172 const_cnt <= prev_const_cnt)) 233 173 return; ··· 252 182 253 183 scale = min_t(unsigned long, scale, SCHED_CAPACITY_SCALE); 254 184 this_cpu_write(arch_freq_scale, (unsigned long)scale); 185 + 186 + amu_sample->last_scale_update = jiffies; 255 187 } 256 188 257 189 static struct scale_freq_data amu_sfd = { 258 190 .source = SCALE_FREQ_SOURCE_ARCH, 259 191 .set_freq_scale = amu_scale_freq_tick, 260 192 }; 193 + 194 + static __always_inline bool amu_fie_cpu_supported(unsigned int cpu) 195 + { 196 + return cpumask_available(amu_fie_cpus) && 197 + cpumask_test_cpu(cpu, amu_fie_cpus); 198 + } 199 + 200 + void arch_cpu_idle_enter(void) 201 + { 202 + unsigned int cpu = smp_processor_id(); 203 + 204 + if (!amu_fie_cpu_supported(cpu)) 205 + return; 206 + 207 + /* Kick in AMU update but only if one has not happened already */ 208 + if (housekeeping_cpu(cpu, HK_TYPE_TICK) && 209 + time_is_before_jiffies(per_cpu(cpu_amu_samples.last_scale_update, cpu))) 210 + amu_scale_freq_tick(); 211 + } 212 + 213 + #define AMU_SAMPLE_EXP_MS 20 214 + 215 + int arch_freq_get_on_cpu(int cpu) 216 + { 217 + struct amu_cntr_sample *amu_sample; 218 + unsigned int start_cpu = cpu; 219 + unsigned long last_update; 220 + unsigned int freq = 0; 221 + u64 scale; 222 + 223 + if (!amu_fie_cpu_supported(cpu) || !arch_scale_freq_ref(cpu)) 224 + return -EOPNOTSUPP; 225 + 226 + while (1) { 227 + 228 + amu_sample = per_cpu_ptr(&cpu_amu_samples, cpu); 229 + 230 + last_update = amu_sample->last_scale_update; 231 + 232 + /* 233 + * For those CPUs that are in full dynticks mode, or those that have 234 + * not seen tick for a while, try an alternative source for the counters 235 + * (and thus freq scale), if available, for given policy: this boils 236 + * down to identifying an active cpu within the same freq domain, if any. 237 + */ 238 + if (!housekeeping_cpu(cpu, HK_TYPE_TICK) || 239 + time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) { 240 + struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 241 + int ref_cpu; 242 + 243 + if (!policy) 244 + return -EINVAL; 245 + 246 + if (!cpumask_intersects(policy->related_cpus, 247 + housekeeping_cpumask(HK_TYPE_TICK))) { 248 + cpufreq_cpu_put(policy); 249 + return -EOPNOTSUPP; 250 + } 251 + 252 + for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) { 253 + if (ref_cpu == start_cpu) { 254 + /* Prevent verifying same CPU twice */ 255 + ref_cpu = nr_cpu_ids; 256 + break; 257 + } 258 + if (!idle_cpu(ref_cpu)) 259 + break; 260 + } 261 + 262 + cpufreq_cpu_put(policy); 263 + 264 + if (ref_cpu >= nr_cpu_ids) 265 + /* No alternative to pull info from */ 266 + return -EAGAIN; 267 + 268 + cpu = ref_cpu; 269 + } else { 270 + break; 271 + } 272 + } 273 + /* 274 + * Reversed computation to the one used to determine 275 + * the arch_freq_scale value 276 + * (see amu_scale_freq_tick for details) 277 + */ 278 + scale = arch_scale_freq_capacity(cpu); 279 + freq = scale * arch_scale_freq_ref(cpu); 280 + freq >>= SCHED_CAPACITY_SHIFT; 281 + return freq; 282 + } 261 283 262 284 static void amu_fie_setup(const struct cpumask *cpus) 263 285 {
+4 -4
arch/arm64/kvm/at.c
··· 1090 1090 break; 1091 1091 } 1092 1092 1093 - if (pov_perms & ~POE_RXW) 1093 + if (pov_perms & ~POE_RWX) 1094 1094 pov_perms = POE_NONE; 1095 1095 1096 1096 if (wi->poe && wr->pov) { 1097 1097 wr->pr &= pov_perms & POE_R; 1098 - wr->px &= pov_perms & POE_X; 1099 1098 wr->pw &= pov_perms & POE_W; 1099 + wr->px &= pov_perms & POE_X; 1100 1100 } 1101 1101 1102 - if (uov_perms & ~POE_RXW) 1102 + if (uov_perms & ~POE_RWX) 1103 1103 uov_perms = POE_NONE; 1104 1104 1105 1105 if (wi->e0poe && wr->uov) { 1106 1106 wr->ur &= uov_perms & POE_R; 1107 - wr->ux &= uov_perms & POE_X; 1108 1107 wr->uw &= uov_perms & POE_W; 1108 + wr->ux &= uov_perms & POE_X; 1109 1109 } 1110 1110 } 1111 1111
+2 -2
arch/arm64/kvm/ptdump.c
··· 52 52 .set = "AF", 53 53 .clear = " ", 54 54 }, { 55 - .mask = PTE_TABLE_BIT | PTE_VALID, 56 - .val = PTE_VALID, 55 + .mask = PMD_TYPE_MASK, 56 + .val = PMD_TYPE_SECT, 57 57 .set = "BLK", 58 58 .clear = " ", 59 59 },
+21 -4
arch/arm64/lib/clear_user.S
··· 17 17 * Alignment fixed up by hardware. 18 18 */ 19 19 20 - .p2align 4 21 - // Alignment is for the loop, but since the prologue (including BTI) 22 - // is also 16 bytes we can keep any padding outside the function 23 20 SYM_FUNC_START(__arch_clear_user) 24 21 add x2, x0, x1 22 + 23 + #ifdef CONFIG_AS_HAS_MOPS 24 + .arch_extension mops 25 + alternative_if_not ARM64_HAS_MOPS 26 + b .Lno_mops 27 + alternative_else_nop_endif 28 + 29 + USER(9f, setpt [x0]!, x1!, xzr) 30 + USER(6f, setmt [x0]!, x1!, xzr) 31 + USER(6f, setet [x0]!, x1!, xzr) 32 + mov x0, #0 33 + ret 34 + .Lno_mops: 35 + #endif 36 + 25 37 subs x1, x1, #8 26 38 b.mi 2f 27 - 1: 39 + 40 + 1: .p2align 4 28 41 USER(9f, sttr xzr, [x0]) 29 42 add x0, x0, #8 30 43 subs x1, x1, #8 ··· 60 47 ret 61 48 62 49 // Exception fixups 50 + 6: b.cs 9f 51 + // Registers are in Option A format 52 + add x0, x0, x1 53 + b 9f 63 54 7: sub x0, x2, #5 // Adjust for faulting on the final byte... 64 55 8: add x0, x0, #4 // ...or the second word of the 4-7 byte case 65 56 9: sub x0, x2, x0
+10
arch/arm64/lib/copy_from_user.S
··· 52 52 stp \reg1, \reg2, [\ptr], \val 53 53 .endm 54 54 55 + .macro cpy1 dst, src, count 56 + .arch_extension mops 57 + USER_CPY(9997f, 0, cpyfprt [\dst]!, [\src]!, \count!) 58 + USER_CPY(9996f, 0, cpyfmrt [\dst]!, [\src]!, \count!) 59 + USER_CPY(9996f, 0, cpyfert [\dst]!, [\src]!, \count!) 60 + .endm 61 + 55 62 end .req x5 56 63 srcin .req x15 57 64 SYM_FUNC_START(__arch_copy_from_user) ··· 69 62 ret 70 63 71 64 // Exception fixups 65 + 9996: b.cs 9997f 66 + // Registers are in Option A format 67 + add dst, dst, count 72 68 9997: cmp dst, dstin 73 69 b.ne 9998f 74 70 // Before being absolutely sure we couldn't copy anything, try harder
+10
arch/arm64/lib/copy_template.S
··· 40 40 D_h .req x14 41 41 42 42 mov dst, dstin 43 + 44 + #ifdef CONFIG_AS_HAS_MOPS 45 + alternative_if_not ARM64_HAS_MOPS 46 + b .Lno_mops 47 + alternative_else_nop_endif 48 + cpy1 dst, src, count 49 + b .Lexitfunc 50 + .Lno_mops: 51 + #endif 52 + 43 53 cmp count, #16 44 54 /*When memory length is less than 16, the accessed are not aligned.*/ 45 55 b.lo .Ltiny15
+10
arch/arm64/lib/copy_to_user.S
··· 51 51 user_stp 9997f, \reg1, \reg2, \ptr, \val 52 52 .endm 53 53 54 + .macro cpy1 dst, src, count 55 + .arch_extension mops 56 + USER_CPY(9997f, 1, cpyfpwt [\dst]!, [\src]!, \count!) 57 + USER_CPY(9996f, 1, cpyfmwt [\dst]!, [\src]!, \count!) 58 + USER_CPY(9996f, 1, cpyfewt [\dst]!, [\src]!, \count!) 59 + .endm 60 + 54 61 end .req x5 55 62 srcin .req x15 56 63 SYM_FUNC_START(__arch_copy_to_user) ··· 68 61 ret 69 62 70 63 // Exception fixups 64 + 9996: b.cs 9997f 65 + // Registers are in Option A format 66 + add dst, dst, count 71 67 9997: cmp dst, dstin 72 68 b.ne 9998f 73 69 // Before being absolutely sure we couldn't copy anything, try harder
+39 -1
arch/arm64/mm/extable.c
··· 8 8 #include <linux/uaccess.h> 9 9 10 10 #include <asm/asm-extable.h> 11 + #include <asm/esr.h> 11 12 #include <asm/ptrace.h> 13 + 14 + static bool cpy_faulted_on_uaccess(const struct exception_table_entry *ex, 15 + unsigned long esr) 16 + { 17 + bool uaccess_is_write = FIELD_GET(EX_DATA_UACCESS_WRITE, ex->data); 18 + bool fault_on_write = esr & ESR_ELx_WNR; 19 + 20 + return uaccess_is_write == fault_on_write; 21 + } 22 + 23 + bool insn_may_access_user(unsigned long addr, unsigned long esr) 24 + { 25 + const struct exception_table_entry *ex = search_exception_tables(addr); 26 + 27 + if (!ex) 28 + return false; 29 + 30 + switch (ex->type) { 31 + case EX_TYPE_UACCESS_CPY: 32 + return cpy_faulted_on_uaccess(ex, esr); 33 + default: 34 + return true; 35 + } 36 + } 12 37 13 38 static inline unsigned long 14 39 get_ex_fixup(const struct exception_table_entry *ex) ··· 49 24 50 25 pt_regs_write_reg(regs, reg_err, -EFAULT); 51 26 pt_regs_write_reg(regs, reg_zero, 0); 27 + 28 + regs->pc = get_ex_fixup(ex); 29 + return true; 30 + } 31 + 32 + static bool ex_handler_uaccess_cpy(const struct exception_table_entry *ex, 33 + struct pt_regs *regs, unsigned long esr) 34 + { 35 + /* Do not fix up faults on kernel memory accesses */ 36 + if (!cpy_faulted_on_uaccess(ex, esr)) 37 + return false; 52 38 53 39 regs->pc = get_ex_fixup(ex); 54 40 return true; ··· 92 56 return true; 93 57 } 94 58 95 - bool fixup_exception(struct pt_regs *regs) 59 + bool fixup_exception(struct pt_regs *regs, unsigned long esr) 96 60 { 97 61 const struct exception_table_entry *ex; 98 62 ··· 106 70 case EX_TYPE_UACCESS_ERR_ZERO: 107 71 case EX_TYPE_KACCESS_ERR_ZERO: 108 72 return ex_handler_uaccess_err_zero(ex, regs); 73 + case EX_TYPE_UACCESS_CPY: 74 + return ex_handler_uaccess_cpy(ex, regs, esr); 109 75 case EX_TYPE_LOAD_UNALIGNED_ZEROPAD: 110 76 return ex_handler_load_unaligned_zeropad(ex, regs); 111 77 }
+2 -2
arch/arm64/mm/fault.c
··· 375 375 * Are we prepared to handle this kernel fault? 376 376 * We are almost certainly not prepared to handle instruction faults. 377 377 */ 378 - if (!is_el1_instruction_abort(esr) && fixup_exception(regs)) 378 + if (!is_el1_instruction_abort(esr) && fixup_exception(regs, esr)) 379 379 return; 380 380 381 381 if (WARN_RATELIMIT(is_spurious_el1_translation_fault(addr, esr, regs), ··· 606 606 die_kernel_fault("execution of user memory", 607 607 addr, esr, regs); 608 608 609 - if (!search_exception_tables(regs->pc)) 609 + if (!insn_may_access_user(regs->pc, esr)) 610 610 die_kernel_fault("access to user memory outside uaccess routines", 611 611 addr, esr, regs); 612 612 }
+10 -10
arch/arm64/mm/hugetlbpage.c
··· 334 334 switch (hp_size) { 335 335 #ifndef __PAGETABLE_PMD_FOLDED 336 336 case PUD_SIZE: 337 - return PGDIR_SIZE - PUD_SIZE; 337 + if (pud_sect_supported()) 338 + return PGDIR_SIZE - PUD_SIZE; 339 + break; 338 340 #endif 339 341 case CONT_PMD_SIZE: 340 342 return PUD_SIZE - CONT_PMD_SIZE; ··· 358 356 switch (pagesize) { 359 357 #ifndef __PAGETABLE_PMD_FOLDED 360 358 case PUD_SIZE: 361 - entry = pud_pte(pud_mkhuge(pte_pud(entry))); 359 + if (pud_sect_supported()) 360 + return pud_pte(pud_mkhuge(pte_pud(entry))); 362 361 break; 363 362 #endif 364 363 case CONT_PMD_SIZE: 365 - entry = pmd_pte(pmd_mkcont(pte_pmd(entry))); 366 - fallthrough; 364 + return pmd_pte(pmd_mkhuge(pmd_mkcont(pte_pmd(entry)))); 367 365 case PMD_SIZE: 368 - entry = pmd_pte(pmd_mkhuge(pte_pmd(entry))); 369 - break; 366 + return pmd_pte(pmd_mkhuge(pte_pmd(entry))); 370 367 case CONT_PTE_SIZE: 371 - entry = pte_mkcont(entry); 372 - break; 368 + return pte_mkcont(entry); 373 369 default: 374 - pr_warn("%s: unrecognized huge page size 0x%lx\n", 375 - __func__, pagesize); 376 370 break; 377 371 } 372 + pr_warn("%s: unrecognized huge page size 0x%lx\n", 373 + __func__, pagesize); 378 374 return entry; 379 375 } 380 376
+3 -3
arch/arm64/mm/kasan_init.c
··· 190 190 */ 191 191 static bool __init root_level_aligned(u64 addr) 192 192 { 193 - int shift = (ARM64_HW_PGTABLE_LEVELS(vabits_actual) - 1) * (PAGE_SHIFT - 3); 193 + int shift = (ARM64_HW_PGTABLE_LEVELS(vabits_actual) - 1) * PTDESC_TABLE_SHIFT; 194 194 195 195 return (addr % (PAGE_SIZE << shift)) == 0; 196 196 } ··· 245 245 */ 246 246 u64 vabits = IS_ENABLED(CONFIG_ARM64_64K_PAGES) ? VA_BITS 247 247 : vabits_actual; 248 - int shift = (ARM64_HW_PGTABLE_LEVELS(vabits) - 1) * (PAGE_SHIFT - 3); 248 + int shift = (ARM64_HW_PGTABLE_LEVELS(vabits) - 1) * PTDESC_TABLE_SHIFT; 249 249 250 250 return (addr & ~_PAGE_OFFSET(vabits)) >> (shift + PAGE_SHIFT); 251 251 } ··· 269 269 */ 270 270 static int __init next_level_idx(u64 addr) 271 271 { 272 - int shift = (ARM64_HW_PGTABLE_LEVELS(vabits_actual) - 2) * (PAGE_SHIFT - 3); 272 + int shift = (ARM64_HW_PGTABLE_LEVELS(vabits_actual) - 2) * PTDESC_TABLE_SHIFT; 273 273 274 274 return (addr >> (shift + PAGE_SHIFT)) % PTRS_PER_PTE; 275 275 }
+4 -6
arch/arm64/mm/mmu.c
··· 1558 1558 #ifdef CONFIG_ARCH_HAS_PKEYS 1559 1559 int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long init_val) 1560 1560 { 1561 - u64 new_por = POE_RXW; 1561 + u64 new_por; 1562 1562 u64 old_por; 1563 - u64 pkey_shift; 1564 1563 1565 1564 if (!system_supports_poe()) 1566 1565 return -ENOSPC; ··· 1573 1574 return -EINVAL; 1574 1575 1575 1576 /* Set the bits we need in POR: */ 1576 - new_por = POE_RXW; 1577 + new_por = POE_RWX; 1577 1578 if (init_val & PKEY_DISABLE_WRITE) 1578 1579 new_por &= ~POE_W; 1579 1580 if (init_val & PKEY_DISABLE_ACCESS) ··· 1584 1585 new_por &= ~POE_X; 1585 1586 1586 1587 /* Shift the bits in to the correct place in POR for pkey: */ 1587 - pkey_shift = pkey * POR_BITS_PER_PKEY; 1588 - new_por <<= pkey_shift; 1588 + new_por = POR_ELx_PERM_PREP(pkey, new_por); 1589 1589 1590 1590 /* Get old POR and mask off any old bits in place: */ 1591 1591 old_por = read_sysreg_s(SYS_POR_EL0); 1592 - old_por &= ~(POE_MASK << pkey_shift); 1592 + old_por &= ~(POE_MASK << POR_ELx_PERM_SHIFT(pkey)); 1593 1593 1594 1594 /* Write old part along with new part: */ 1595 1595 write_sysreg_s(old_por | new_por, SYS_POR_EL0);
+1 -1
arch/arm64/mm/physaddr.c
··· 10 10 phys_addr_t __virt_to_phys(unsigned long x) 11 11 { 12 12 WARN(!__is_lm_address(__tag_reset(x)), 13 - "virt_to_phys used for non-linear address: %pK (%pS)\n", 13 + "virt_to_phys used for non-linear address: %p (%pS)\n", 14 14 (void *)x, 15 15 (void *)x); 16 16
+2 -2
arch/arm64/mm/ptdump.c
··· 80 80 .set = "CON", 81 81 .clear = " ", 82 82 }, { 83 - .mask = PTE_TABLE_BIT | PTE_VALID, 84 - .val = PTE_VALID, 83 + .mask = PMD_TYPE_MASK, 84 + .val = PMD_TYPE_SECT, 85 85 .set = "BLK", 86 86 .clear = " ", 87 87 }, {
+17 -14
arch/arm64/tools/gen-sysreg.awk
··· 111 111 /^$/ { next } 112 112 /^[\t ]*#/ { next } 113 113 114 - /^SysregFields/ && block_current() == "Root" { 114 + $1 == "SysregFields" && block_current() == "Root" { 115 115 block_push("SysregFields") 116 116 117 117 expect_fields(2) ··· 127 127 next 128 128 } 129 129 130 - /^EndSysregFields/ && block_current() == "SysregFields" { 130 + $1 == "EndSysregFields" && block_current() == "SysregFields" { 131 + expect_fields(1) 131 132 if (next_bit > 0) 132 133 fatal("Unspecified bits in " reg) 133 134 ··· 146 145 next 147 146 } 148 147 149 - /^Sysreg/ && block_current() == "Root" { 148 + $1 == "Sysreg" && block_current() == "Root" { 150 149 block_push("Sysreg") 151 150 152 151 expect_fields(7) ··· 178 177 next 179 178 } 180 179 181 - /^EndSysreg/ && block_current() == "Sysreg" { 180 + $1 == "EndSysreg" && block_current() == "Sysreg" { 181 + expect_fields(1) 182 182 if (next_bit > 0) 183 183 fatal("Unspecified bits in " reg) 184 184 ··· 208 206 209 207 # Currently this is effectivey a comment, in future we may want to emit 210 208 # defines for the fields. 211 - (/^Fields/ || /^Mapping/) && block_current() == "Sysreg" { 209 + ($1 == "Fields" || $1 == "Mapping") && block_current() == "Sysreg" { 212 210 expect_fields(2) 213 211 214 212 if (next_bit != 63) ··· 226 224 } 227 225 228 226 229 - /^Res0/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 227 + $1 == "Res0" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 230 228 expect_fields(2) 231 229 parse_bitdef(reg, "RES0", $2) 232 230 field = "RES0_" msb "_" lsb ··· 236 234 next 237 235 } 238 236 239 - /^Res1/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 237 + $1 == "Res1" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 240 238 expect_fields(2) 241 239 parse_bitdef(reg, "RES1", $2) 242 240 field = "RES1_" msb "_" lsb ··· 246 244 next 247 245 } 248 246 249 - /^Unkn/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 247 + $1 == "Unkn" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 250 248 expect_fields(2) 251 249 parse_bitdef(reg, "UNKN", $2) 252 250 field = "UNKN_" msb "_" lsb ··· 256 254 next 257 255 } 258 256 259 - /^Field/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 257 + $1 == "Field" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 260 258 expect_fields(3) 261 259 field = $3 262 260 parse_bitdef(reg, field, $2) ··· 267 265 next 268 266 } 269 267 270 - /^Raz/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 268 + $1 == "Raz" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 271 269 expect_fields(2) 272 270 parse_bitdef(reg, field, $2) 273 271 274 272 next 275 273 } 276 274 277 - /^SignedEnum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 275 + $1 == "SignedEnum" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 278 276 block_push("Enum") 279 277 280 278 expect_fields(3) ··· 287 285 next 288 286 } 289 287 290 - /^UnsignedEnum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 288 + $1 == "UnsignedEnum" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 291 289 block_push("Enum") 292 290 293 291 expect_fields(3) ··· 300 298 next 301 299 } 302 300 303 - /^Enum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") { 301 + $1 == "Enum" && (block_current() == "Sysreg" || block_current() == "SysregFields") { 304 302 block_push("Enum") 305 303 306 304 expect_fields(3) ··· 312 310 next 313 311 } 314 312 315 - /^EndEnum/ && block_current() == "Enum" { 313 + $1 == "EndEnum" && block_current() == "Enum" { 314 + expect_fields(1) 316 315 317 316 field = null 318 317 msb = null
+104 -1
arch/arm64/tools/sysreg
··· 1664 1664 UnsignedEnum 59:56 FGT 1665 1665 0b0000 NI 1666 1666 0b0001 IMP 1667 + 0b0010 FGT2 1667 1668 EndEnum 1668 1669 Res0 55:48 1669 1670 UnsignedEnum 47:44 EXS ··· 1726 1725 0b0100 44 1727 1726 0b0101 48 1728 1727 0b0110 52 1728 + 0b0111 56 1729 1729 EndEnum 1730 1730 EndSysreg 1731 1731 ··· 2076 2074 Res0 4:2 2077 2075 Field 1 ExTRE 2078 2076 Field 0 E0TRE 2079 - EndSysregFields 2077 + EndSysreg 2080 2078 2081 2079 Sysreg SMPRI_EL1 3 0 1 2 4 2082 2080 Res0 63:4 ··· 2643 2641 EndSysreg 2644 2642 2645 2643 2644 + Sysreg HDFGRTR2_EL2 3 4 3 1 0 2645 + Res0 63:25 2646 + Field 24 nPMBMAR_EL1 2647 + Field 23 nMDSTEPOP_EL1 2648 + Field 22 nTRBMPAM_EL1 2649 + Res0 21 2650 + Field 20 nTRCITECR_EL1 2651 + Field 19 nPMSDSFR_EL1 2652 + Field 18 nSPMDEVAFF_EL1 2653 + Field 17 nSPMID 2654 + Field 16 nSPMSCR_EL1 2655 + Field 15 nSPMACCESSR_EL1 2656 + Field 14 nSPMCR_EL0 2657 + Field 13 nSPMOVS 2658 + Field 12 nSPMINTEN 2659 + Field 11 nSPMCNTEN 2660 + Field 10 nSPMSELR_EL0 2661 + Field 9 nSPMEVTYPERn_EL0 2662 + Field 8 nSPMEVCNTRn_EL0 2663 + Field 7 nPMSSCR_EL1 2664 + Field 6 nPMSSDATA 2665 + Field 5 nMDSELR_EL1 2666 + Field 4 nPMUACR_EL1 2667 + Field 3 nPMICFILTR_EL0 2668 + Field 2 nPMICNTR_EL0 2669 + Field 1 nPMIAR_EL1 2670 + Field 0 nPMECR_EL1 2671 + EndSysreg 2672 + 2673 + Sysreg HDFGWTR2_EL2 3 4 3 1 1 2674 + Res0 63:25 2675 + Field 24 nPMBMAR_EL1 2676 + Field 23 nMDSTEPOP_EL1 2677 + Field 22 nTRBMPAM_EL1 2678 + Field 21 nPMZR_EL0 2679 + Field 20 nTRCITECR_EL1 2680 + Field 19 nPMSDSFR_EL1 2681 + Res0 18:17 2682 + Field 16 nSPMSCR_EL1 2683 + Field 15 nSPMACCESSR_EL1 2684 + Field 14 nSPMCR_EL0 2685 + Field 13 nSPMOVS 2686 + Field 12 nSPMINTEN 2687 + Field 11 nSPMCNTEN 2688 + Field 10 nSPMSELR_EL0 2689 + Field 9 nSPMEVTYPERn_EL0 2690 + Field 8 nSPMEVCNTRn_EL0 2691 + Field 7 nPMSSCR_EL1 2692 + Res0 6 2693 + Field 5 nMDSELR_EL1 2694 + Field 4 nPMUACR_EL1 2695 + Field 3 nPMICFILTR_EL0 2696 + Field 2 nPMICNTR_EL0 2697 + Field 1 nPMIAR_EL1 2698 + Field 0 nPMECR_EL1 2699 + EndSysreg 2700 + 2701 + Sysreg HFGRTR2_EL2 3 4 3 1 2 2702 + Res0 63:15 2703 + Field 14 nACTLRALIAS_EL1 2704 + Field 13 nACTLRMASK_EL1 2705 + Field 12 nTCR2ALIAS_EL1 2706 + Field 11 nTCRALIAS_EL1 2707 + Field 10 nSCTLRALIAS2_EL1 2708 + Field 9 nSCTLRALIAS_EL1 2709 + Field 8 nCPACRALIAS_EL1 2710 + Field 7 nTCR2MASK_EL1 2711 + Field 6 nTCRMASK_EL1 2712 + Field 5 nSCTLR2MASK_EL1 2713 + Field 4 nSCTLRMASK_EL1 2714 + Field 3 nCPACRMASK_EL1 2715 + Field 2 nRCWSMASK_EL1 2716 + Field 1 nERXGSR_EL1 2717 + Field 0 nPFAR_EL1 2718 + EndSysreg 2719 + 2720 + Sysreg HFGWTR2_EL2 3 4 3 1 3 2721 + Res0 63:15 2722 + Field 14 nACTLRALIAS_EL1 2723 + Field 13 nACTLRMASK_EL1 2724 + Field 12 nTCR2ALIAS_EL1 2725 + Field 11 nTCRALIAS_EL1 2726 + Field 10 nSCTLRALIAS2_EL1 2727 + Field 9 nSCTLRALIAS_EL1 2728 + Field 8 nCPACRALIAS_EL1 2729 + Field 7 nTCR2MASK_EL1 2730 + Field 6 nTCRMASK_EL1 2731 + Field 5 nSCTLR2MASK_EL1 2732 + Field 4 nSCTLRMASK_EL1 2733 + Field 3 nCPACRMASK_EL1 2734 + Field 2 nRCWSMASK_EL1 2735 + Res0 1 2736 + Field 0 nPFAR_EL1 2737 + EndSysreg 2738 + 2646 2739 Sysreg HDFGRTR_EL2 3 4 3 1 4 2647 2740 Field 63 PMBIDR_EL1 2648 2741 Field 62 nPMSNEVFR_EL1 ··· 2908 2811 Field 2 AMEVCNTR01_EL0 2909 2812 Field 1 AMEVCNTR00_EL0 2910 2813 Field 0 AMCNTEN0 2814 + EndSysreg 2815 + 2816 + Sysreg HFGITR2_EL2 3 4 3 1 7 2817 + Res0 63:2 2818 + Field 1 nDCCIVAPS 2819 + Field 0 TSBCSYNC 2911 2820 EndSysreg 2912 2821 2913 2822 Sysreg ZCR_EL2 3 4 1 2 0
+1
arch/powerpc/include/asm/topology.h
··· 152 152 { 153 153 return cpu == cpu_first_thread_sibling(cpu); 154 154 } 155 + #define topology_is_primary_thread topology_is_primary_thread 155 156 156 157 static inline bool topology_smt_thread_allowed(unsigned int cpu) 157 158 {
+1 -1
arch/x86/include/asm/topology.h
··· 229 229 { 230 230 return cpumask_test_cpu(cpu, cpu_primary_thread_mask); 231 231 } 232 + #define topology_is_primary_thread topology_is_primary_thread 232 233 233 234 #else /* CONFIG_SMP */ 234 235 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; } 235 236 static inline int topology_max_smt_threads(void) { return 1; } 236 - static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } 237 237 static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; } 238 238 #endif /* !CONFIG_SMP */ 239 239
+1 -1
arch/x86/kernel/cpu/aperfmperf.c
··· 498 498 */ 499 499 #define MAX_SAMPLE_AGE ((unsigned long)HZ / 50) 500 500 501 - unsigned int arch_freq_get_on_cpu(int cpu) 501 + int arch_freq_get_on_cpu(int cpu) 502 502 { 503 503 struct aperfmperf *s = per_cpu_ptr(&cpu_samples, cpu); 504 504 unsigned int seq, freq;
+5 -2
arch/x86/kernel/cpu/proc.c
··· 86 86 seq_printf(m, "microcode\t: 0x%x\n", c->microcode); 87 87 88 88 if (cpu_has(c, X86_FEATURE_TSC)) { 89 - unsigned int freq = arch_freq_get_on_cpu(cpu); 89 + int freq = arch_freq_get_on_cpu(cpu); 90 90 91 - seq_printf(m, "cpu MHz\t\t: %u.%03u\n", freq / 1000, (freq % 1000)); 91 + if (freq < 0) 92 + seq_puts(m, "cpu MHz\t\t: Unknown\n"); 93 + else 94 + seq_printf(m, "cpu MHz\t\t: %u.%03u\n", freq / 1000, (freq % 1000)); 92 95 } 93 96 94 97 /* Cache size */
+23 -3
drivers/base/arch_topology.c
··· 11 11 #include <linux/cleanup.h> 12 12 #include <linux/cpu.h> 13 13 #include <linux/cpufreq.h> 14 + #include <linux/cpu_smt.h> 14 15 #include <linux/device.h> 15 16 #include <linux/of.h> 16 17 #include <linux/slab.h> ··· 29 28 static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data); 30 29 static struct cpumask scale_freq_counters_mask; 31 30 static bool scale_freq_invariant; 32 - DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 1; 31 + DEFINE_PER_CPU(unsigned long, capacity_freq_ref) = 0; 33 32 EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref); 34 33 35 34 static bool supports_scale_freq_counters(const struct cpumask *cpus) ··· 294 293 295 294 capacity_scale = 1; 296 295 for_each_possible_cpu(cpu) { 297 - capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); 296 + capacity = raw_capacity[cpu] * 297 + (per_cpu(capacity_freq_ref, cpu) ?: 1); 298 298 capacity_scale = max(capacity, capacity_scale); 299 299 } 300 300 301 301 pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale); 302 302 for_each_possible_cpu(cpu) { 303 - capacity = raw_capacity[cpu] * per_cpu(capacity_freq_ref, cpu); 303 + capacity = raw_capacity[cpu] * 304 + (per_cpu(capacity_freq_ref, cpu) ?: 1); 304 305 capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, 305 306 capacity_scale); 306 307 topology_set_cpu_scale(cpu, capacity); ··· 509 506 #endif 510 507 511 508 #if defined(CONFIG_ARM64) || defined(CONFIG_RISCV) 509 + 510 + /* Used to enable the SMT control */ 511 + static unsigned int max_smt_thread_num = 1; 512 + 512 513 /* 513 514 * This function returns the logic cpu number of the node. 514 515 * There are basically three kinds of return values: ··· 571 564 } 572 565 i++; 573 566 } while (1); 567 + 568 + max_smt_thread_num = max_t(unsigned int, max_smt_thread_num, i); 574 569 575 570 cpu = get_cpu_for_node(core); 576 571 if (cpu >= 0) { ··· 685 676 686 677 if (!has_socket) 687 678 ret = parse_cluster(socket, 0, -1, 0); 679 + 680 + /* 681 + * Reset the max_smt_thread_num to 1 on failure. Since on failure 682 + * we need to notify the framework the SMT is not supported, but 683 + * max_smt_thread_num can be initialized to the SMT thread number 684 + * of the cores which are successfully parsed. 685 + */ 686 + if (ret) 687 + max_smt_thread_num = 1; 688 + 689 + cpu_smt_set_num_threads(max_smt_thread_num, max_smt_thread_num); 688 690 689 691 return ret; 690 692 }
+12
drivers/cpufreq/Kconfig.x86
··· 340 340 option lets the probing code bypass some of those checks if the 341 341 parameter "relaxed_check=1" is passed to the module. 342 342 343 + config CPUFREQ_ARCH_CUR_FREQ 344 + default y 345 + bool "Current frequency derived from HW provided feedback" 346 + help 347 + This determines whether the scaling_cur_freq sysfs attribute returns 348 + the last requested frequency or a more precise value based on hardware 349 + provided feedback (as architected counters). 350 + Given that a more precise frequency can now be provided via the 351 + cpuinfo_avg_freq attribute, by enabling this option, 352 + scaling_cur_freq maintains the provision of a counter based frequency, 353 + for compatibility reasons. 354 +
+33 -5
drivers/cpufreq/cpufreq.c
··· 729 729 show_one(scaling_min_freq, min); 730 730 show_one(scaling_max_freq, max); 731 731 732 - __weak unsigned int arch_freq_get_on_cpu(int cpu) 732 + __weak int arch_freq_get_on_cpu(int cpu) 733 733 { 734 - return 0; 734 + return -EOPNOTSUPP; 735 + } 736 + 737 + static inline bool cpufreq_avg_freq_supported(struct cpufreq_policy *policy) 738 + { 739 + return arch_freq_get_on_cpu(policy->cpu) != -EOPNOTSUPP; 735 740 } 736 741 737 742 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf) 738 743 { 739 744 ssize_t ret; 740 - unsigned int freq; 745 + int freq; 741 746 742 - freq = arch_freq_get_on_cpu(policy->cpu); 743 - if (freq) 747 + freq = IS_ENABLED(CONFIG_CPUFREQ_ARCH_CUR_FREQ) 748 + ? arch_freq_get_on_cpu(policy->cpu) 749 + : 0; 750 + 751 + if (freq > 0) 744 752 ret = sysfs_emit(buf, "%u\n", freq); 745 753 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) 746 754 ret = sysfs_emit(buf, "%u\n", cpufreq_driver->get(policy->cpu)); ··· 790 782 return sysfs_emit(buf, "%u\n", cur_freq); 791 783 792 784 return sysfs_emit(buf, "<unknown>\n"); 785 + } 786 + 787 + /* 788 + * show_cpuinfo_avg_freq - average CPU frequency as detected by hardware 789 + */ 790 + static ssize_t show_cpuinfo_avg_freq(struct cpufreq_policy *policy, 791 + char *buf) 792 + { 793 + int avg_freq = arch_freq_get_on_cpu(policy->cpu); 794 + 795 + if (avg_freq > 0) 796 + return sysfs_emit(buf, "%u\n", avg_freq); 797 + return avg_freq != 0 ? avg_freq : -EINVAL; 793 798 } 794 799 795 800 /* ··· 967 946 } 968 947 969 948 cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400); 949 + cpufreq_freq_attr_ro(cpuinfo_avg_freq); 970 950 cpufreq_freq_attr_ro(cpuinfo_min_freq); 971 951 cpufreq_freq_attr_ro(cpuinfo_max_freq); 972 952 cpufreq_freq_attr_ro(cpuinfo_transition_latency); ··· 1091 1069 } 1092 1070 if (cpufreq_driver->get) { 1093 1071 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); 1072 + if (ret) 1073 + return ret; 1074 + } 1075 + 1076 + if (cpufreq_avg_freq_supported(policy)) { 1077 + ret = sysfs_create_file(&policy->kobj, &cpuinfo_avg_freq.attr); 1094 1078 if (ret) 1095 1079 return ret; 1096 1080 }
+45 -25
drivers/perf/apple_m1_cpu_pmu.c
··· 120 120 */ 121 121 M1_PMU_CFG_COUNT_USER = BIT(8), 122 122 M1_PMU_CFG_COUNT_KERNEL = BIT(9), 123 + M1_PMU_CFG_COUNT_HOST = BIT(10), 124 + M1_PMU_CFG_COUNT_GUEST = BIT(11), 123 125 }; 124 126 125 127 /* ··· 329 327 __m1_pmu_enable_counter_interrupt(index, false); 330 328 } 331 329 332 - static void m1_pmu_configure_counter(unsigned int index, u8 event, 333 - bool user, bool kernel) 330 + static void __m1_pmu_configure_event_filter(unsigned int index, bool user, 331 + bool kernel, bool host) 334 332 { 335 - u64 val, user_bit, kernel_bit; 336 - int shift; 333 + u64 clear, set, user_bit, kernel_bit; 337 334 338 335 switch (index) { 339 336 case 0 ... 7: ··· 347 346 BUG(); 348 347 } 349 348 350 - val = read_sysreg_s(SYS_IMP_APL_PMCR1_EL1); 351 - 349 + clear = set = 0; 352 350 if (user) 353 - val |= user_bit; 351 + set |= user_bit; 354 352 else 355 - val &= ~user_bit; 353 + clear |= user_bit; 356 354 357 355 if (kernel) 358 - val |= kernel_bit; 356 + set |= kernel_bit; 359 357 else 360 - val &= ~kernel_bit; 358 + clear |= kernel_bit; 361 359 362 - write_sysreg_s(val, SYS_IMP_APL_PMCR1_EL1); 360 + if (host) 361 + sysreg_clear_set_s(SYS_IMP_APL_PMCR1_EL1, clear, set); 362 + else if (is_kernel_in_hyp_mode()) 363 + sysreg_clear_set_s(SYS_IMP_APL_PMCR1_EL12, clear, set); 364 + } 365 + 366 + static void __m1_pmu_configure_eventsel(unsigned int index, u8 event) 367 + { 368 + u64 clear = 0, set = 0; 369 + int shift; 363 370 364 371 /* 365 372 * Counters 0 and 1 have fixed events. For anything else, ··· 380 371 break; 381 372 case 2 ... 5: 382 373 shift = (index - 2) * 8; 383 - val = read_sysreg_s(SYS_IMP_APL_PMESR0_EL1); 384 - val &= ~((u64)0xff << shift); 385 - val |= (u64)event << shift; 386 - write_sysreg_s(val, SYS_IMP_APL_PMESR0_EL1); 374 + clear |= (u64)0xff << shift; 375 + set |= (u64)event << shift; 376 + sysreg_clear_set_s(SYS_IMP_APL_PMESR0_EL1, clear, set); 387 377 break; 388 378 case 6 ... 9: 389 379 shift = (index - 6) * 8; 390 - val = read_sysreg_s(SYS_IMP_APL_PMESR1_EL1); 391 - val &= ~((u64)0xff << shift); 392 - val |= (u64)event << shift; 393 - write_sysreg_s(val, SYS_IMP_APL_PMESR1_EL1); 380 + clear |= (u64)0xff << shift; 381 + set |= (u64)event << shift; 382 + sysreg_clear_set_s(SYS_IMP_APL_PMESR1_EL1, clear, set); 394 383 break; 395 384 } 385 + } 386 + 387 + static void m1_pmu_configure_counter(unsigned int index, unsigned long config_base) 388 + { 389 + bool kernel = config_base & M1_PMU_CFG_COUNT_KERNEL; 390 + bool guest = config_base & M1_PMU_CFG_COUNT_GUEST; 391 + bool host = config_base & M1_PMU_CFG_COUNT_HOST; 392 + bool user = config_base & M1_PMU_CFG_COUNT_USER; 393 + u8 evt = config_base & M1_PMU_CFG_EVENT; 394 + 395 + __m1_pmu_configure_event_filter(index, user && host, kernel && host, true); 396 + __m1_pmu_configure_event_filter(index, user && guest, kernel && guest, false); 397 + __m1_pmu_configure_eventsel(index, evt); 396 398 } 397 399 398 400 /* arm_pmu backend */ ··· 416 396 user = event->hw.config_base & M1_PMU_CFG_COUNT_USER; 417 397 kernel = event->hw.config_base & M1_PMU_CFG_COUNT_KERNEL; 418 398 419 - m1_pmu_disable_counter_interrupt(event->hw.idx); 420 - m1_pmu_disable_counter(event->hw.idx); 421 - isb(); 422 - 423 - m1_pmu_configure_counter(event->hw.idx, evt, user, kernel); 399 + m1_pmu_configure_counter(event->hw.idx, event->hw.config_base); 424 400 m1_pmu_enable_counter(event->hw.idx); 425 401 m1_pmu_enable_counter_interrupt(event->hw.idx); 426 402 isb(); ··· 574 558 { 575 559 unsigned long config_base = 0; 576 560 577 - if (!attr->exclude_guest) { 561 + if (!attr->exclude_guest && !is_kernel_in_hyp_mode()) { 578 562 pr_debug("ARM performance counters do not support mode exclusion\n"); 579 563 return -EOPNOTSUPP; 580 564 } ··· 582 566 config_base |= M1_PMU_CFG_COUNT_KERNEL; 583 567 if (!attr->exclude_user) 584 568 config_base |= M1_PMU_CFG_COUNT_USER; 569 + if (!attr->exclude_host) 570 + config_base |= M1_PMU_CFG_COUNT_HOST; 571 + if (!attr->exclude_guest) 572 + config_base |= M1_PMU_CFG_COUNT_GUEST; 585 573 586 574 event->config_base = config_base; 587 575
+3 -2
drivers/perf/arm-cmn.c
··· 802 802 CMN_EVENT_ATTR(_model, ccha_##_name, CMN_TYPE_CCHA, _event) 803 803 #define CMN_EVENT_CCLA(_name, _event) \ 804 804 CMN_EVENT_ATTR(CMN_ANY, ccla_##_name, CMN_TYPE_CCLA, _event) 805 - #define CMN_EVENT_CCLA_RNI(_name, _event) \ 806 - CMN_EVENT_ATTR(CMN_ANY, ccla_rni_##_name, CMN_TYPE_CCLA_RNI, _event) 807 805 #define CMN_EVENT_HNS(_name, _event) \ 808 806 CMN_EVENT_ATTR(CMN_ANY, hns_##_name, CMN_TYPE_HNS, _event) 809 807 ··· 1796 1798 } else if (type == CMN_TYPE_XP && 1797 1799 (cmn->part == PART_CMN700 || cmn->part == PART_CMN_S3)) { 1798 1800 hw->wide_sel = true; 1801 + } else if (type == CMN_TYPE_RND) { 1802 + /* Secretly permit this as an alias for "rnid" events */ 1803 + type = CMN_TYPE_RNI; 1799 1804 } 1800 1805 1801 1806 /* This is sufficiently annoying to recalculate, so cache it */
+10 -22
drivers/perf/arm_cspmu/ampere_cspmu.c
··· 10 10 11 11 #include "arm_cspmu.h" 12 12 13 - #define PMAUXR0 0xD80 14 - #define PMAUXR1 0xD84 15 - #define PMAUXR2 0xD88 16 - #define PMAUXR3 0xD8C 13 + #define PMAUXR0 PMIMPDEF 14 + #define PMAUXR1 (PMIMPDEF + 0x4) 15 + #define PMAUXR2 (PMIMPDEF + 0x8) 16 + #define PMAUXR3 (PMIMPDEF + 0xC) 17 17 18 18 #define to_ampere_cspmu_ctx(cspmu) ((struct ampere_cspmu_ctx *)(cspmu->impl.ctx)) 19 19 ··· 132 132 return ctx->name; 133 133 } 134 134 135 - static u32 ampere_cspmu_event_filter(const struct perf_event *event) 135 + static void ampere_cspmu_set_cc_filter(struct arm_cspmu *cspmu, 136 + const struct perf_event *event) 136 137 { 137 138 /* 138 - * PMEVFILTR or PMCCFILTR aren't used in Ampere SoC PMU but are marked 139 - * as RES0. Make sure, PMCCFILTR is written zero. 139 + * PMCCFILTR is RES0, so this is just a dummy callback to override 140 + * the default implementation and avoid writing to it. 140 141 */ 141 - return 0; 142 142 } 143 143 144 144 static void ampere_cspmu_set_ev_filter(struct arm_cspmu *cspmu, 145 - struct hw_perf_event *hwc, 146 - u32 filter) 145 + const struct perf_event *event) 147 146 { 148 - struct perf_event *event; 149 - unsigned int idx; 150 147 u32 threshold, rank, bank; 151 - 152 - /* 153 - * At this point, all the events have the same filter settings. 154 - * Therefore, take the first event and use its configuration. 155 - */ 156 - idx = find_first_bit(cspmu->hw_events.used_ctrs, 157 - cspmu->cycle_counter_logical_idx); 158 - 159 - event = cspmu->hw_events.events[idx]; 160 148 161 149 threshold = get_threshold(event); 162 150 rank = get_rank(event); ··· 221 233 222 234 cspmu->impl.ctx = ctx; 223 235 224 - impl_ops->event_filter = ampere_cspmu_event_filter; 236 + impl_ops->set_cc_filter = ampere_cspmu_set_cc_filter; 225 237 impl_ops->set_ev_filter = ampere_cspmu_set_ev_filter; 226 238 impl_ops->validate_event = ampere_cspmu_validate_event; 227 239 impl_ops->get_name = ampere_cspmu_get_name;
+17 -64
drivers/perf/arm_cspmu/arm_cspmu.c
··· 40 40 ARM_CSPMU_EXT_ATTR(_name, arm_cspmu_cpumask_show, \ 41 41 (unsigned long)_config) 42 42 43 - /* 44 - * CoreSight PMU Arch register offsets. 45 - */ 46 - #define PMEVCNTR_LO 0x0 47 - #define PMEVCNTR_HI 0x4 48 - #define PMEVTYPER 0x400 49 - #define PMCCFILTR 0x47C 50 - #define PMEVFILTR 0xA00 51 - #define PMCNTENSET 0xC00 52 - #define PMCNTENCLR 0xC20 53 - #define PMINTENSET 0xC40 54 - #define PMINTENCLR 0xC60 55 - #define PMOVSCLR 0xC80 56 - #define PMOVSSET 0xCC0 57 - #define PMCFGR 0xE00 58 - #define PMCR 0xE04 59 - #define PMIIDR 0xE08 60 - 61 - /* PMCFGR register field */ 62 - #define PMCFGR_NCG GENMASK(31, 28) 63 - #define PMCFGR_HDBG BIT(24) 64 - #define PMCFGR_TRO BIT(23) 65 - #define PMCFGR_SS BIT(22) 66 - #define PMCFGR_FZO BIT(21) 67 - #define PMCFGR_MSI BIT(20) 68 - #define PMCFGR_UEN BIT(19) 69 - #define PMCFGR_NA BIT(17) 70 - #define PMCFGR_EX BIT(16) 71 - #define PMCFGR_CCD BIT(15) 72 - #define PMCFGR_CC BIT(14) 73 - #define PMCFGR_SIZE GENMASK(13, 8) 74 - #define PMCFGR_N GENMASK(7, 0) 75 - 76 - /* PMCR register field */ 77 - #define PMCR_TRO BIT(11) 78 - #define PMCR_HDBG BIT(10) 79 - #define PMCR_FZO BIT(9) 80 - #define PMCR_NA BIT(8) 81 - #define PMCR_DP BIT(5) 82 - #define PMCR_X BIT(4) 83 - #define PMCR_D BIT(3) 84 - #define PMCR_C BIT(2) 85 - #define PMCR_P BIT(1) 86 - #define PMCR_E BIT(0) 87 - 88 43 /* Each SET/CLR register supports up to 32 counters. */ 89 44 #define ARM_CSPMU_SET_CLR_COUNTER_SHIFT 5 90 45 #define ARM_CSPMU_SET_CLR_COUNTER_NUM \ ··· 66 111 static DEFINE_MUTEX(arm_cspmu_lock); 67 112 68 113 static void arm_cspmu_set_ev_filter(struct arm_cspmu *cspmu, 69 - struct hw_perf_event *hwc, u32 filter); 114 + const struct perf_event *event); 115 + static void arm_cspmu_set_cc_filter(struct arm_cspmu *cspmu, 116 + const struct perf_event *event); 70 117 71 118 static struct acpi_apmt_node *arm_cspmu_apmt_node(struct device *dev) 72 119 { ··· 183 226 static struct attribute *arm_cspmu_format_attrs[] = { 184 227 ARM_CSPMU_FORMAT_EVENT_ATTR, 185 228 ARM_CSPMU_FORMAT_FILTER_ATTR, 229 + ARM_CSPMU_FORMAT_FILTER2_ATTR, 186 230 NULL, 187 231 }; 188 232 ··· 206 248 static bool arm_cspmu_is_cycle_counter_event(const struct perf_event *event) 207 249 { 208 250 return (event->attr.config == ARM_CSPMU_EVT_CYCLES_DEFAULT); 209 - } 210 - 211 - static u32 arm_cspmu_event_filter(const struct perf_event *event) 212 - { 213 - return event->attr.config1 & ARM_CSPMU_FILTER_MASK; 214 251 } 215 252 216 253 static ssize_t arm_cspmu_identifier_show(struct device *dev, ··· 369 416 DEFAULT_IMPL_OP(get_name), 370 417 DEFAULT_IMPL_OP(is_cycle_counter_event), 371 418 DEFAULT_IMPL_OP(event_type), 372 - DEFAULT_IMPL_OP(event_filter), 419 + DEFAULT_IMPL_OP(set_cc_filter), 373 420 DEFAULT_IMPL_OP(set_ev_filter), 374 421 DEFAULT_IMPL_OP(event_attr_is_visible), 375 422 }; ··· 765 812 } 766 813 767 814 static void arm_cspmu_set_ev_filter(struct arm_cspmu *cspmu, 768 - struct hw_perf_event *hwc, 769 - u32 filter) 815 + const struct perf_event *event) 770 816 { 771 - u32 offset = PMEVFILTR + (4 * hwc->idx); 817 + u32 filter = event->attr.config1 & ARM_CSPMU_FILTER_MASK; 818 + u32 filter2 = event->attr.config2 & ARM_CSPMU_FILTER_MASK; 819 + u32 offset = 4 * event->hw.idx; 772 820 773 - writel(filter, cspmu->base0 + offset); 821 + writel(filter, cspmu->base0 + PMEVFILTR + offset); 822 + writel(filter2, cspmu->base0 + PMEVFILT2R + offset); 774 823 } 775 824 776 - static inline void arm_cspmu_set_cc_filter(struct arm_cspmu *cspmu, u32 filter) 825 + static void arm_cspmu_set_cc_filter(struct arm_cspmu *cspmu, 826 + const struct perf_event *event) 777 827 { 778 - u32 offset = PMCCFILTR; 828 + u32 filter = event->attr.config1 & ARM_CSPMU_FILTER_MASK; 779 829 780 - writel(filter, cspmu->base0 + offset); 830 + writel(filter, cspmu->base0 + PMCCFILTR); 781 831 } 782 832 783 833 static void arm_cspmu_start(struct perf_event *event, int pmu_flags) 784 834 { 785 835 struct arm_cspmu *cspmu = to_arm_cspmu(event->pmu); 786 836 struct hw_perf_event *hwc = &event->hw; 787 - u32 filter; 788 837 789 838 /* We always reprogram the counter */ 790 839 if (pmu_flags & PERF_EF_RELOAD) ··· 794 839 795 840 arm_cspmu_set_event_period(event); 796 841 797 - filter = cspmu->impl.ops.event_filter(event); 798 - 799 842 if (event->hw.extra_reg.idx == cspmu->cycle_counter_logical_idx) { 800 - arm_cspmu_set_cc_filter(cspmu, filter); 843 + cspmu->impl.ops.set_cc_filter(cspmu, event); 801 844 } else { 802 845 arm_cspmu_set_event(cspmu, hwc); 803 - cspmu->impl.ops.set_ev_filter(cspmu, hwc, filter); 846 + cspmu->impl.ops.set_ev_filter(cspmu, event); 804 847 } 805 848 806 849 hwc->state = 0;
+53 -4
drivers/perf/arm_cspmu/arm_cspmu.h
··· 47 47 /* Default filter format */ 48 48 #define ARM_CSPMU_FORMAT_FILTER_ATTR \ 49 49 ARM_CSPMU_FORMAT_ATTR(filter, "config1:0-31") 50 + #define ARM_CSPMU_FORMAT_FILTER2_ATTR \ 51 + ARM_CSPMU_FORMAT_ATTR(filter2, "config2:0-31") 50 52 51 53 /* 52 54 * This is the default event number for cycle count, if supported, since the ··· 66 64 67 65 /* The cycle counter, if implemented, is located at counter[31]. */ 68 66 #define ARM_CSPMU_CYCLE_CNTR_IDX 31 67 + 68 + /* 69 + * CoreSight PMU Arch register offsets. 70 + */ 71 + #define PMEVCNTR_LO 0x0 72 + #define PMEVCNTR_HI 0x4 73 + #define PMEVTYPER 0x400 74 + #define PMCCFILTR 0x47C 75 + #define PMEVFILT2R 0x800 76 + #define PMEVFILTR 0xA00 77 + #define PMCNTENSET 0xC00 78 + #define PMCNTENCLR 0xC20 79 + #define PMINTENSET 0xC40 80 + #define PMINTENCLR 0xC60 81 + #define PMOVSCLR 0xC80 82 + #define PMOVSSET 0xCC0 83 + #define PMIMPDEF 0xD80 84 + #define PMCFGR 0xE00 85 + #define PMCR 0xE04 86 + #define PMIIDR 0xE08 87 + 88 + /* PMCFGR register field */ 89 + #define PMCFGR_NCG GENMASK(31, 28) 90 + #define PMCFGR_HDBG BIT(24) 91 + #define PMCFGR_TRO BIT(23) 92 + #define PMCFGR_SS BIT(22) 93 + #define PMCFGR_FZO BIT(21) 94 + #define PMCFGR_MSI BIT(20) 95 + #define PMCFGR_UEN BIT(19) 96 + #define PMCFGR_NA BIT(17) 97 + #define PMCFGR_EX BIT(16) 98 + #define PMCFGR_CCD BIT(15) 99 + #define PMCFGR_CC BIT(14) 100 + #define PMCFGR_SIZE GENMASK(13, 8) 101 + #define PMCFGR_N GENMASK(7, 0) 102 + 103 + /* PMCR register field */ 104 + #define PMCR_TRO BIT(11) 105 + #define PMCR_HDBG BIT(10) 106 + #define PMCR_FZO BIT(9) 107 + #define PMCR_NA BIT(8) 108 + #define PMCR_DP BIT(5) 109 + #define PMCR_X BIT(4) 110 + #define PMCR_D BIT(3) 111 + #define PMCR_C BIT(2) 112 + #define PMCR_P BIT(1) 113 + #define PMCR_E BIT(0) 69 114 70 115 /* PMIIDR register field */ 71 116 #define ARM_CSPMU_PMIIDR_IMPLEMENTER GENMASK(11, 0) ··· 152 103 bool (*is_cycle_counter_event)(const struct perf_event *event); 153 104 /* Decode event type/id from configs */ 154 105 u32 (*event_type)(const struct perf_event *event); 155 - /* Decode filter value from configs */ 156 - u32 (*event_filter)(const struct perf_event *event); 157 - /* Set event filter */ 106 + /* Set event filters */ 107 + void (*set_cc_filter)(struct arm_cspmu *cspmu, 108 + const struct perf_event *event); 158 109 void (*set_ev_filter)(struct arm_cspmu *cspmu, 159 - struct hw_perf_event *hwc, u32 filter); 110 + const struct perf_event *event); 160 111 /* Implementation specific event validation */ 161 112 int (*validate_event)(struct arm_cspmu *cspmu, 162 113 struct perf_event *event);
+21 -1
drivers/perf/arm_cspmu/nvidia_cspmu.c
··· 6 6 7 7 /* Support for NVIDIA specific attributes. */ 8 8 9 + #include <linux/io.h> 9 10 #include <linux/module.h> 10 11 #include <linux/topology.h> 11 12 ··· 184 183 return filter_val; 185 184 } 186 185 186 + static void nv_cspmu_set_ev_filter(struct arm_cspmu *cspmu, 187 + const struct perf_event *event) 188 + { 189 + u32 filter = nv_cspmu_event_filter(event); 190 + u32 offset = PMEVFILTR + (4 * event->hw.idx); 191 + 192 + writel(filter, cspmu->base0 + offset); 193 + } 194 + 195 + static void nv_cspmu_set_cc_filter(struct arm_cspmu *cspmu, 196 + const struct perf_event *event) 197 + { 198 + u32 filter = nv_cspmu_event_filter(event); 199 + 200 + writel(filter, cspmu->base0 + PMCCFILTR); 201 + } 202 + 203 + 187 204 enum nv_cspmu_name_fmt { 188 205 NAME_FMT_GENERIC, 189 206 NAME_FMT_SOCKET ··· 341 322 cspmu->impl.ctx = ctx; 342 323 343 324 /* NVIDIA specific callbacks. */ 344 - impl_ops->event_filter = nv_cspmu_event_filter; 325 + impl_ops->set_cc_filter = nv_cspmu_set_cc_filter; 326 + impl_ops->set_ev_filter = nv_cspmu_set_ev_filter; 345 327 impl_ops->get_event_attrs = nv_cspmu_get_event_attrs; 346 328 impl_ops->get_format_attrs = nv_cspmu_get_format_attrs; 347 329 impl_ops->get_name = nv_cspmu_get_name;
+3 -5
drivers/perf/arm_pmu.c
··· 342 342 if (idx < 0) 343 343 return idx; 344 344 345 - /* 346 - * If there is an event in the counter we are going to use then make 347 - * sure it is disabled. 348 - */ 345 + /* The newly-allocated counter should be empty */ 346 + WARN_ON_ONCE(hw_events->events[idx]); 347 + 349 348 event->hw.idx = idx; 350 - armpmu->disable(event); 351 349 hw_events->events[idx] = event; 352 350 353 351 hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
+4 -7
drivers/perf/arm_pmuv3.c
··· 795 795 796 796 static void armv8pmu_enable_event(struct perf_event *event) 797 797 { 798 - /* 799 - * Enable counter and interrupt, and set the counter to count 800 - * the event that we're interested in. 801 - */ 802 - armv8pmu_disable_event_counter(event); 803 798 armv8pmu_write_event_type(event); 804 799 armv8pmu_enable_event_irq(event); 805 800 armv8pmu_enable_event_counter(event); ··· 820 825 else 821 826 armv8pmu_disable_user_access(); 822 827 828 + kvm_vcpu_pmu_resync_el0(); 829 + 823 830 /* Enable all counters */ 824 831 armv8pmu_pmcr_write(armv8pmu_pmcr_read() | ARMV8_PMU_PMCR_E); 825 - 826 - kvm_vcpu_pmu_resync_el0(); 827 832 } 828 833 829 834 static void armv8pmu_stop(struct arm_pmu *cpu_pmu) ··· 1364 1369 PMUV3_INIT_SIMPLE(armv8_neoverse_v2) 1365 1370 PMUV3_INIT_SIMPLE(armv8_neoverse_v3) 1366 1371 PMUV3_INIT_SIMPLE(armv8_neoverse_v3ae) 1372 + PMUV3_INIT_SIMPLE(armv8_rainier) 1367 1373 1368 1374 PMUV3_INIT_SIMPLE(armv8_nvidia_carmel) 1369 1375 PMUV3_INIT_SIMPLE(armv8_nvidia_denver) ··· 1412 1416 {.compatible = "arm,neoverse-v2-pmu", .data = armv8_neoverse_v2_pmu_init}, 1413 1417 {.compatible = "arm,neoverse-v3-pmu", .data = armv8_neoverse_v3_pmu_init}, 1414 1418 {.compatible = "arm,neoverse-v3ae-pmu", .data = armv8_neoverse_v3ae_pmu_init}, 1419 + {.compatible = "arm,rainier-pmu", .data = armv8_rainier_pmu_init}, 1415 1420 {.compatible = "cavium,thunder-pmu", .data = armv8_cavium_thunder_pmu_init}, 1416 1421 {.compatible = "brcm,vulcan-pmu", .data = armv8_brcm_vulcan_pmu_init}, 1417 1422 {.compatible = "nvidia,carmel-pmu", .data = armv8_nvidia_carmel_pmu_init},
-50
drivers/perf/arm_v7_pmu.c
··· 858 858 } 859 859 860 860 /* 861 - * Enable counter and interrupt, and set the counter to count 862 - * the event that we're interested in. 863 - */ 864 - 865 - /* 866 - * Disable counter 867 - */ 868 - armv7_pmnc_disable_counter(idx); 869 - 870 - /* 871 861 * Set event (if destined for PMNx counters) 872 862 * We only need to set the event for the cycle counter if we 873 863 * have the ability to perform event filtering. ··· 865 875 if (cpu_pmu->set_event_filter || idx != ARMV7_IDX_CYCLE_COUNTER) 866 876 armv7_pmnc_write_evtsel(idx, hwc->config_base); 867 877 868 - /* 869 - * Enable interrupt for this counter 870 - */ 871 878 armv7_pmnc_enable_intens(idx); 872 - 873 - /* 874 - * Enable counter 875 - */ 876 879 armv7_pmnc_enable_counter(idx); 877 880 } 878 881 ··· 881 898 return; 882 899 } 883 900 884 - /* 885 - * Disable counter and interrupt 886 - */ 887 - 888 - /* 889 - * Disable counter 890 - */ 891 901 armv7_pmnc_disable_counter(idx); 892 - 893 - /* 894 - * Disable interrupt for this counter 895 - */ 896 902 armv7_pmnc_disable_intens(idx); 897 903 } 898 904 ··· 1449 1477 int idx = hwc->idx; 1450 1478 1451 1479 /* 1452 - * Enable counter and interrupt, and set the counter to count 1453 - * the event that we're interested in. 1454 - */ 1455 - 1456 - /* Disable counter */ 1457 - armv7_pmnc_disable_counter(idx); 1458 - 1459 - /* 1460 1480 * Set event (if destined for PMNx counters) 1461 1481 * We set the event for the cycle counter because we 1462 1482 * have the ability to perform event filtering. ··· 1458 1494 else 1459 1495 armv7_pmnc_write_evtsel(idx, hwc->config_base); 1460 1496 1461 - /* Enable interrupt for this counter */ 1462 1497 armv7_pmnc_enable_intens(idx); 1463 - 1464 - /* Enable counter */ 1465 1498 armv7_pmnc_enable_counter(idx); 1466 1499 } 1467 1500 ··· 1759 1798 int idx = hwc->idx; 1760 1799 1761 1800 /* 1762 - * Enable counter and interrupt, and set the counter to count 1763 - * the event that we're interested in. 1764 - */ 1765 - 1766 - /* Disable counter */ 1767 - armv7_pmnc_disable_counter(idx); 1768 - 1769 - /* 1770 1801 * Set event (if destined for PMNx counters) 1771 1802 * We don't set the event for the cycle counter because we 1772 1803 * don't have the ability to perform event filtering. ··· 1768 1815 else if (idx != ARMV7_IDX_CYCLE_COUNTER) 1769 1816 armv7_pmnc_write_evtsel(idx, hwc->config_base); 1770 1817 1771 - /* Enable interrupt for this counter */ 1772 1818 armv7_pmnc_enable_intens(idx); 1773 - 1774 - /* Enable counter */ 1775 1819 armv7_pmnc_enable_counter(idx); 1776 1820 } 1777 1821
+34 -17
drivers/perf/dwc_pcie_pmu.c
··· 565 565 u32 sbdf; 566 566 567 567 sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn); 568 - plat_dev = platform_device_register_data(NULL, "dwc_pcie_pmu", sbdf, 569 - pdev, sizeof(*pdev)); 570 - 568 + plat_dev = platform_device_register_simple("dwc_pcie_pmu", sbdf, NULL, 0); 571 569 if (IS_ERR(plat_dev)) 572 570 return PTR_ERR(plat_dev); 573 571 574 572 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); 575 - if (!dev_info) 573 + if (!dev_info) { 574 + platform_device_unregister(plat_dev); 576 575 return -ENOMEM; 576 + } 577 577 578 578 /* Cache platform device to handle pci device hotplug */ 579 579 dev_info->plat_dev = plat_dev; ··· 614 614 615 615 static int dwc_pcie_pmu_probe(struct platform_device *plat_dev) 616 616 { 617 - struct pci_dev *pdev = plat_dev->dev.platform_data; 617 + struct pci_dev *pdev; 618 618 struct dwc_pcie_pmu *pcie_pmu; 619 619 char *name; 620 620 u32 sbdf; 621 621 u16 vsec; 622 622 int ret; 623 623 624 + sbdf = plat_dev->id; 625 + pdev = pci_get_domain_bus_and_slot(sbdf >> 16, PCI_BUS_NUM(sbdf & 0xffff), 626 + sbdf & 0xff); 627 + if (!pdev) { 628 + pr_err("No pdev found for the sbdf 0x%x\n", sbdf); 629 + return -ENODEV; 630 + } 631 + 624 632 vsec = dwc_pcie_des_cap(pdev); 625 633 if (!vsec) 626 634 return -ENODEV; 627 635 628 - sbdf = plat_dev->id; 636 + pci_dev_put(pdev); 629 637 name = devm_kasprintf(&plat_dev->dev, GFP_KERNEL, "dwc_rootport_%x", sbdf); 630 638 if (!name) 631 639 return -ENOMEM; ··· 648 640 pcie_pmu->on_cpu = -1; 649 641 pcie_pmu->pmu = (struct pmu){ 650 642 .name = name, 651 - .parent = &pdev->dev, 643 + .parent = &plat_dev->dev, 652 644 .module = THIS_MODULE, 653 645 .attr_groups = dwc_pcie_attr_groups, 654 646 .capabilities = PERF_PMU_CAP_NO_EXCLUDE, ··· 738 730 .driver = {.name = "dwc_pcie_pmu",}, 739 731 }; 740 732 733 + static void dwc_pcie_cleanup_devices(void) 734 + { 735 + struct dwc_pcie_dev_info *dev_info, *tmp; 736 + 737 + list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) { 738 + dwc_pcie_unregister_dev(dev_info); 739 + } 740 + } 741 + 741 742 static int __init dwc_pcie_pmu_init(void) 742 743 { 743 744 struct pci_dev *pdev = NULL; ··· 759 742 ret = dwc_pcie_register_dev(pdev); 760 743 if (ret) { 761 744 pci_dev_put(pdev); 762 - return ret; 745 + goto err_cleanup; 763 746 } 764 747 } 765 748 ··· 768 751 dwc_pcie_pmu_online_cpu, 769 752 dwc_pcie_pmu_offline_cpu); 770 753 if (ret < 0) 771 - return ret; 754 + goto err_cleanup; 772 755 773 756 dwc_pcie_pmu_hp_state = ret; 774 757 775 758 ret = platform_driver_register(&dwc_pcie_pmu_driver); 776 759 if (ret) 777 - goto platform_driver_register_err; 760 + goto err_remove_cpuhp; 778 761 779 762 ret = bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); 780 763 if (ret) 781 - goto platform_driver_register_err; 764 + goto err_unregister_driver; 782 765 notify = true; 783 766 784 767 return 0; 785 768 786 - platform_driver_register_err: 769 + err_unregister_driver: 770 + platform_driver_unregister(&dwc_pcie_pmu_driver); 771 + err_remove_cpuhp: 787 772 cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); 788 - 773 + err_cleanup: 774 + dwc_pcie_cleanup_devices(); 789 775 return ret; 790 776 } 791 777 792 778 static void __exit dwc_pcie_pmu_exit(void) 793 779 { 794 - struct dwc_pcie_dev_info *dev_info, *tmp; 795 - 796 780 if (notify) 797 781 bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); 798 - list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) 799 - dwc_pcie_unregister_dev(dev_info); 782 + dwc_pcie_cleanup_devices(); 800 783 platform_driver_unregister(&dwc_pcie_pmu_driver); 801 784 cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); 802 785 }
+1 -1
include/linux/cpufreq.h
··· 1184 1184 } 1185 1185 #endif 1186 1186 1187 - extern unsigned int arch_freq_get_on_cpu(int cpu); 1187 + extern int arch_freq_get_on_cpu(int cpu); 1188 1188 1189 1189 #ifndef arch_set_freq_scale 1190 1190 static __always_inline
+9 -4
include/linux/dma-direct.h
··· 78 78 #define phys_to_dma_unencrypted phys_to_dma 79 79 #endif 80 80 #else 81 - static inline dma_addr_t phys_to_dma_unencrypted(struct device *dev, 82 - phys_addr_t paddr) 81 + static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) 83 82 { 84 83 if (dev->dma_range_map) 85 84 return translate_phys_to_dma(dev, paddr); 86 85 return paddr; 87 86 } 88 87 88 + static inline dma_addr_t phys_to_dma_unencrypted(struct device *dev, 89 + phys_addr_t paddr) 90 + { 91 + return dma_addr_unencrypted(__phys_to_dma(dev, paddr)); 92 + } 89 93 /* 90 94 * If memory encryption is supported, phys_to_dma will set the memory encryption 91 95 * bit in the DMA address, and dma_to_phys will clear it. ··· 98 94 */ 99 95 static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) 100 96 { 101 - return __sme_set(phys_to_dma_unencrypted(dev, paddr)); 97 + return dma_addr_encrypted(__phys_to_dma(dev, paddr)); 102 98 } 103 99 104 100 static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr) 105 101 { 106 102 phys_addr_t paddr; 107 103 104 + dma_addr = dma_addr_canonical(dma_addr); 108 105 if (dev->dma_range_map) 109 106 paddr = translate_dma_to_phys(dev, dma_addr); 110 107 else 111 108 paddr = dma_addr; 112 109 113 - return __sme_clr(paddr); 110 + return paddr; 114 111 } 115 112 #endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */ 116 113
+23
include/linux/mem_encrypt.h
··· 26 26 */ 27 27 #define __sme_set(x) ((x) | sme_me_mask) 28 28 #define __sme_clr(x) ((x) & ~sme_me_mask) 29 + 30 + #define dma_addr_encrypted(x) __sme_set(x) 31 + #define dma_addr_canonical(x) __sme_clr(x) 32 + 29 33 #else 30 34 #define __sme_set(x) (x) 31 35 #define __sme_clr(x) (x) 36 + #endif 37 + 38 + /* 39 + * dma_addr_encrypted() and dma_addr_unencrypted() are for converting a given DMA 40 + * address to the respective type of addressing. 41 + * 42 + * dma_addr_canonical() is used to reverse any conversions for encrypted/decrypted 43 + * back to the canonical address. 44 + */ 45 + #ifndef dma_addr_encrypted 46 + #define dma_addr_encrypted(x) (x) 47 + #endif 48 + 49 + #ifndef dma_addr_unencrypted 50 + #define dma_addr_unencrypted(x) (x) 51 + #endif 52 + 53 + #ifndef dma_addr_canonical 54 + #define dma_addr_canonical(x) (x) 32 55 #endif 33 56 34 57 #endif /* __ASSEMBLY__ */
+7 -6
include/linux/perf/arm_pmu.h
··· 84 84 struct pmu pmu; 85 85 cpumask_t supported_cpus; 86 86 char *name; 87 - int pmuver; 88 87 irqreturn_t (*handle_irq)(struct arm_pmu *pmu); 89 88 void (*enable)(struct perf_event *event); 90 89 void (*disable)(struct perf_event *event); ··· 101 102 int (*map_event)(struct perf_event *event); 102 103 DECLARE_BITMAP(cntr_mask, ARMPMU_MAX_HWEVENTS); 103 104 bool secure_access; /* 32-bit ARM only */ 104 - #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40 105 - DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); 106 - #define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE 0x4000 107 - DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); 108 105 struct platform_device *plat_device; 109 106 struct pmu_hw_events __percpu *hw_events; 110 107 struct hlist_node node; 111 108 struct notifier_block cpu_pm_nb; 112 109 /* the attr_groups array must be NULL-terminated */ 113 110 const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1]; 114 - /* store the PMMIR_EL1 to expose slots */ 111 + 112 + /* PMUv3 only */ 113 + int pmuver; 115 114 u64 reg_pmmir; 115 + #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40 116 + DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); 117 + #define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE 0x4000 118 + DECLARE_BITMAP(pmceid_ext_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); 116 119 117 120 /* Only to be used by ACPI probing code */ 118 121 unsigned long acpi_cpuid;
+23
include/linux/topology.h
··· 240 240 } 241 241 #endif 242 242 243 + #ifndef topology_is_primary_thread 244 + 245 + static inline bool topology_is_primary_thread(unsigned int cpu) 246 + { 247 + /* 248 + * When disabling SMT, the primary thread of the SMT will remain 249 + * enabled/active. Architectures that have a special primary thread 250 + * (e.g. x86) need to override this function. Otherwise the first 251 + * thread in the SMT can be made the primary thread. 252 + * 253 + * The sibling cpumask of an offline CPU always contains the CPU 254 + * itself on architectures using the implementation of 255 + * CONFIG_GENERIC_ARCH_TOPOLOGY for building their topology. 256 + * Other architectures not using CONFIG_GENERIC_ARCH_TOPOLOGY for 257 + * building their topology have to check whether to use this default 258 + * implementation or to override it. 259 + */ 260 + return cpu == cpumask_first(topology_sibling_cpumask(cpu)); 261 + } 262 + #define topology_is_primary_thread topology_is_primary_thread 263 + 264 + #endif 265 + 243 266 static inline const struct cpumask *cpu_cpu_mask(int cpu) 244 267 { 245 268 return cpumask_of_node(cpu_to_node(cpu));
+1
include/uapi/asm-generic/mman-common.h
··· 85 85 /* compatibility flags */ 86 86 #define MAP_FILE 0 87 87 88 + #define PKEY_UNRESTRICTED 0x0 88 89 #define PKEY_DISABLE_ACCESS 0x1 89 90 #define PKEY_DISABLE_WRITE 0x2 90 91 #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\
+15 -4
tools/testing/selftests/arm64/mte/check_hugetlb_options.c
··· 227 227 int main(int argc, char *argv[]) 228 228 { 229 229 int err; 230 + void *map_ptr; 231 + unsigned long map_size; 230 232 231 233 err = mte_default_setup(); 232 234 if (err) ··· 244 242 ksft_print_msg("ERR: Unable allocate hugetlb pages\n"); 245 243 return KSFT_FAIL; 246 244 } 245 + 246 + /* Check if MTE supports hugetlb mappings */ 247 + map_size = default_huge_page_size(); 248 + map_ptr = mmap(NULL, map_size, PROT_READ | PROT_MTE, 249 + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); 250 + if (map_ptr == MAP_FAILED) 251 + ksft_exit_skip("PROT_MTE not supported with MAP_HUGETLB mappings\n"); 252 + else 253 + munmap(map_ptr, map_size); 247 254 248 255 /* Set test plan */ 249 256 ksft_set_plan(12); ··· 281 270 "Check clear PROT_MTE flags with private mapping and sync error mode and mmap/mprotect memory\n"); 282 271 283 272 evaluate_test(check_child_hugetlb_memory_mapping(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE | MAP_HUGETLB), 284 - "Check child hugetlb memory with private mapping, precise mode and mmap memory\n"); 273 + "Check child hugetlb memory with private mapping, sync error mode and mmap memory\n"); 285 274 evaluate_test(check_child_hugetlb_memory_mapping(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE | MAP_HUGETLB), 286 - "Check child hugetlb memory with private mapping, precise mode and mmap memory\n"); 275 + "Check child hugetlb memory with private mapping, async error mode and mmap memory\n"); 287 276 evaluate_test(check_child_hugetlb_memory_mapping(USE_MPROTECT, MTE_SYNC_ERR, MAP_PRIVATE | MAP_HUGETLB), 288 - "Check child hugetlb memory with private mapping, precise mode and mmap/mprotect memory\n"); 277 + "Check child hugetlb memory with private mapping, sync error mode and mmap/mprotect memory\n"); 289 278 evaluate_test(check_child_hugetlb_memory_mapping(USE_MPROTECT, MTE_ASYNC_ERR, MAP_PRIVATE | MAP_HUGETLB), 290 - "Check child hugetlb memory with private mapping, precise mode and mmap/mprotect memory\n"); 279 + "Check child hugetlb memory with private mapping, async error mode and mmap/mprotect memory\n"); 291 280 292 281 mte_restore_setup(); 293 282 free_hugetlb();
+3 -3
tools/testing/selftests/mm/mseal_test.c
··· 218 218 bool pkey_supported(void) 219 219 { 220 220 #if defined(__i386__) || defined(__x86_64__) /* arch */ 221 - int pkey = sys_pkey_alloc(0, 0); 221 + int pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 222 222 223 223 if (pkey > 0) 224 224 return true; ··· 1671 1671 setup_single_address_rw(size, &ptr); 1672 1672 FAIL_TEST_IF_FALSE(ptr != (void *)-1); 1673 1673 1674 - pkey = sys_pkey_alloc(0, 0); 1674 + pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 1675 1675 FAIL_TEST_IF_FALSE(pkey > 0); 1676 1676 1677 1677 ret = sys_mprotect_pkey((void *)ptr, size, PROT_READ | PROT_WRITE, pkey); ··· 1683 1683 } 1684 1684 1685 1685 /* sealing doesn't take effect if PKRU allow write. */ 1686 - set_pkey(pkey, 0); 1686 + set_pkey(pkey, PKEY_UNRESTRICTED); 1687 1687 ret = sys_madvise(ptr, size, MADV_DONTNEED); 1688 1688 FAIL_TEST_IF_FALSE(!ret); 1689 1689
+2 -1
tools/testing/selftests/mm/pkey-helpers.h
··· 13 13 #include <ucontext.h> 14 14 #include <sys/mman.h> 15 15 16 + #include <linux/mman.h> 16 17 #include <linux/types.h> 17 18 18 19 #include "../kselftest.h" ··· 194 193 static inline int kernel_has_pkeys(void) 195 194 { 196 195 /* try allocating a key and see if it succeeds */ 197 - int ret = sys_pkey_alloc(0, 0); 196 + int ret = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 198 197 if (ret <= 0) { 199 198 return 0; 200 199 }
+2 -2
tools/testing/selftests/mm/pkey_sighandler_tests.c
··· 311 311 __write_pkey_reg(pkey_reg); 312 312 313 313 /* Protect the new stack with MPK 1 */ 314 - pkey = sys_pkey_alloc(0, 0); 314 + pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 315 315 sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey); 316 316 317 317 /* Set up alternate signal stack that will use the default MPK */ ··· 484 484 __write_pkey_reg(pkey_reg); 485 485 486 486 /* Protect the stack with MPK 2 */ 487 - pkey = sys_pkey_alloc(0, 0); 487 + pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 488 488 sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey); 489 489 490 490 /* Set up alternate signal stack that will use the default MPK */
+1 -1
tools/testing/selftests/mm/protection_keys.c
··· 463 463 static int alloc_pkey(void) 464 464 { 465 465 int ret; 466 - unsigned long init_val = 0x0; 466 + unsigned long init_val = PKEY_UNRESTRICTED; 467 467 468 468 dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n", 469 469 __func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg);
+4 -1
tools/testing/selftests/powerpc/include/pkeys.h
··· 24 24 #undef PKEY_DISABLE_EXECUTE 25 25 #define PKEY_DISABLE_EXECUTE 0x4 26 26 27 + #undef PKEY_UNRESTRICTED 28 + #define PKEY_UNRESTRICTED 0x0 29 + 27 30 /* Older versions of libc do not define this */ 28 31 #ifndef SEGV_PKUERR 29 32 #define SEGV_PKUERR 4 ··· 96 93 SKIP_IF(!hash_mmu); 97 94 98 95 /* Check if the system call is supported */ 99 - pkey = sys_pkey_alloc(0, 0); 96 + pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 100 97 SKIP_IF(pkey < 0); 101 98 sys_pkey_free(pkey); 102 99
+1 -1
tools/testing/selftests/powerpc/mm/pkey_exec_prot.c
··· 72 72 73 73 switch (fault_type) { 74 74 case PKEY_DISABLE_ACCESS: 75 - pkey_set_rights(fault_pkey, 0); 75 + pkey_set_rights(fault_pkey, PKEY_UNRESTRICTED); 76 76 break; 77 77 case PKEY_DISABLE_EXECUTE: 78 78 /*
+1 -1
tools/testing/selftests/powerpc/mm/pkey_siginfo.c
··· 83 83 mprotect(pgstart, pgsize, PROT_EXEC)) 84 84 _exit(1); 85 85 else 86 - pkey_set_rights(pkey, 0); 86 + pkey_set_rights(pkey, PKEY_UNRESTRICTED); 87 87 88 88 fault_count++; 89 89 }
+3 -3
tools/testing/selftests/powerpc/ptrace/core-pkey.c
··· 95 95 /* Get some pkeys so that we can change their bits in the AMR. */ 96 96 pkey1 = sys_pkey_alloc(0, PKEY_DISABLE_EXECUTE); 97 97 if (pkey1 < 0) { 98 - pkey1 = sys_pkey_alloc(0, 0); 98 + pkey1 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 99 99 FAIL_IF(pkey1 < 0); 100 100 101 101 disable_execute = false; 102 102 } 103 103 104 - pkey2 = sys_pkey_alloc(0, 0); 104 + pkey2 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 105 105 FAIL_IF(pkey2 < 0); 106 106 107 - pkey3 = sys_pkey_alloc(0, 0); 107 + pkey3 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 108 108 FAIL_IF(pkey3 < 0); 109 109 110 110 info->amr |= 3ul << pkeyshift(pkey1) | 2ul << pkeyshift(pkey2);
+3 -3
tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c
··· 57 57 /* Get some pkeys so that we can change their bits in the AMR. */ 58 58 pkey1 = sys_pkey_alloc(0, PKEY_DISABLE_EXECUTE); 59 59 if (pkey1 < 0) { 60 - pkey1 = sys_pkey_alloc(0, 0); 60 + pkey1 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 61 61 CHILD_FAIL_IF(pkey1 < 0, &info->child_sync); 62 62 63 63 disable_execute = false; 64 64 } 65 65 66 - pkey2 = sys_pkey_alloc(0, 0); 66 + pkey2 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 67 67 CHILD_FAIL_IF(pkey2 < 0, &info->child_sync); 68 68 69 - pkey3 = sys_pkey_alloc(0, 0); 69 + pkey3 = sys_pkey_alloc(0, PKEY_UNRESTRICTED); 70 70 CHILD_FAIL_IF(pkey3 < 0, &info->child_sync); 71 71 72 72 info->amr1 |= 3ul << pkeyshift(pkey1);