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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull arm64 fixes from Will Deacon:

- Preserve old 'tt_core' UAPI for Hisilicon L3C PMU driver

- Ensure linear alias of kprobes instruction page is not writable

- Fix kernel stack unwinding from BPF

- Fix build warnings from the Fujitsu uncore PMU documentation

- Fix hang with deferred 'struct page' initialisation and MTE

- Consolidate KPTI page-table re-writing code

* tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux:
arm64: mte: Do not flag the zero page as PG_mte_tagged
docs: perf: Fujitsu: Fix htmldocs build warnings and errors
arm64: mm: Move KPTI helpers to mmu.c
tracing: Fix the bug where bpf_get_stackid returns -EFAULT on the ARM64
arm64: kprobes: call set_memory_rox() for kprobe page
drivers/perf: hisi: Add tt_core_deprecated for compatibility

+154 -118
+6 -1
Documentation/admin-guide/perf/fujitsu_uncore_pmu.rst
··· 15 15 options in sysfs, see /sys/bus/event_sources/devices/mac_iod<iod>_mac<mac>_ch<ch>/ 16 16 and /sys/bus/event_sources/devices/pci_iod<iod>_pci<pci>/. 17 17 This driver exports: 18 + 18 19 - formats, used by perf user space and other tools to configure events 19 20 - events, used by perf user space and other tools to create events 20 - symbolically, e.g.: 21 + symbolically, e.g.:: 22 + 21 23 perf stat -a -e mac_iod0_mac0_ch0/event=0x21/ ls 22 24 perf stat -a -e pci_iod0_pci0/event=0x24/ ls 25 + 23 26 - cpumask, used by perf user space and other tools to know on which CPUs 24 27 to open the events 25 28 26 29 This driver supports the following events for MAC: 30 + 27 31 - cycles 28 32 This event counts MAC cycles at MAC frequency. 29 33 - read-count ··· 81 77 perf stat -e mac_iod0_mac0_ch0/ea-mac/ ls 82 78 83 79 And, this driver supports the following events for PCI: 80 + 84 81 - pci-port0-cycles 85 82 This event counts PCI cycles at PCI frequency in port0. 86 83 - pci-port0-read-count
+4
Documentation/admin-guide/perf/hisi-pmu.rst
··· 66 66 67 67 This will only count the operations from core/thread 0 and 1 in this cluster. 68 68 69 + User should not use tt_core_deprecated to specify the core/thread filtering. 70 + This option is provided for backward compatiblility and only support 8bit 71 + which may not cover all the core/thread sharing L3C. 72 + 69 73 2. Tracetag allow the user to chose to count only read, write or atomic 70 74 operations via the tt_req parameeter in perf. The default value counts all 71 75 operations. tt_req is 3bits, 3'b100 represents read operations, 3'b101
+1
arch/arm64/include/asm/ftrace.h
··· 153 153 regs->pc = afregs->pc; 154 154 regs->regs[29] = afregs->fp; 155 155 regs->regs[30] = afregs->lr; 156 + regs->pstate = PSR_MODE_EL1h; 156 157 return regs; 157 158 } 158 159
+6 -1
arch/arm64/include/asm/mmu.h
··· 79 79 extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot); 80 80 extern void mark_linear_text_alias_ro(void); 81 81 extern int split_kernel_leaf_mapping(unsigned long start, unsigned long end); 82 - extern void init_idmap_kpti_bbml2_flag(void); 83 82 extern void linear_map_maybe_split_to_ptes(void); 84 83 85 84 /* ··· 105 106 106 107 return true; 107 108 } 109 + 110 + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 111 + void kpti_install_ng_mappings(void); 112 + #else 113 + static inline void kpti_install_ng_mappings(void) {} 114 + #endif 108 115 109 116 #endif /* !__ASSEMBLY__ */ 110 117 #endif
+7 -101
arch/arm64/kernel/cpufeature.c
··· 1941 1941 } 1942 1942 #endif 1943 1943 1944 - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1945 - #define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT)) 1946 - 1947 - extern 1948 - void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt, 1949 - phys_addr_t size, pgprot_t prot, 1950 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), int flags); 1951 - 1952 - static phys_addr_t __initdata kpti_ng_temp_alloc; 1953 - 1954 - static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type) 1955 - { 1956 - kpti_ng_temp_alloc -= PAGE_SIZE; 1957 - return kpti_ng_temp_alloc; 1958 - } 1959 - 1960 - static int __init __kpti_install_ng_mappings(void *__unused) 1961 - { 1962 - typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long); 1963 - extern kpti_remap_fn idmap_kpti_install_ng_mappings; 1964 - kpti_remap_fn *remap_fn; 1965 - 1966 - int cpu = smp_processor_id(); 1967 - int levels = CONFIG_PGTABLE_LEVELS; 1968 - int order = order_base_2(levels); 1969 - u64 kpti_ng_temp_pgd_pa = 0; 1970 - pgd_t *kpti_ng_temp_pgd; 1971 - u64 alloc = 0; 1972 - 1973 - if (levels == 5 && !pgtable_l5_enabled()) 1974 - levels = 4; 1975 - else if (levels == 4 && !pgtable_l4_enabled()) 1976 - levels = 3; 1977 - 1978 - remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings); 1979 - 1980 - if (!cpu) { 1981 - alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order); 1982 - kpti_ng_temp_pgd = (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE); 1983 - kpti_ng_temp_alloc = kpti_ng_temp_pgd_pa = __pa(kpti_ng_temp_pgd); 1984 - 1985 - // 1986 - // Create a minimal page table hierarchy that permits us to map 1987 - // the swapper page tables temporarily as we traverse them. 1988 - // 1989 - // The physical pages are laid out as follows: 1990 - // 1991 - // +--------+-/-------+-/------ +-/------ +-\\\--------+ 1992 - // : PTE[] : | PMD[] : | PUD[] : | P4D[] : ||| PGD[] : 1993 - // +--------+-\-------+-\------ +-\------ +-///--------+ 1994 - // ^ 1995 - // The first page is mapped into this hierarchy at a PMD_SHIFT 1996 - // aligned virtual address, so that we can manipulate the PTE 1997 - // level entries while the mapping is active. The first entry 1998 - // covers the PTE[] page itself, the remaining entries are free 1999 - // to be used as a ad-hoc fixmap. 2000 - // 2001 - create_kpti_ng_temp_pgd(kpti_ng_temp_pgd, __pa(alloc), 2002 - KPTI_NG_TEMP_VA, PAGE_SIZE, PAGE_KERNEL, 2003 - kpti_ng_pgd_alloc, 0); 2004 - } 2005 - 2006 - cpu_install_idmap(); 2007 - remap_fn(cpu, num_online_cpus(), kpti_ng_temp_pgd_pa, KPTI_NG_TEMP_VA); 2008 - cpu_uninstall_idmap(); 2009 - 2010 - if (!cpu) { 2011 - free_pages(alloc, order); 2012 - arm64_use_ng_mappings = true; 2013 - } 2014 - 2015 - return 0; 2016 - } 2017 - 2018 - static void __init kpti_install_ng_mappings(void) 2019 - { 2020 - /* Check whether KPTI is going to be used */ 2021 - if (!arm64_kernel_unmapped_at_el0()) 2022 - return; 2023 - 2024 - /* 2025 - * We don't need to rewrite the page-tables if either we've done 2026 - * it already or we have KASLR enabled and therefore have not 2027 - * created any global mappings at all. 2028 - */ 2029 - if (arm64_use_ng_mappings) 2030 - return; 2031 - 2032 - init_idmap_kpti_bbml2_flag(); 2033 - stop_machine(__kpti_install_ng_mappings, NULL, cpu_online_mask); 2034 - } 2035 - 2036 - #else 2037 - static inline void kpti_install_ng_mappings(void) 2038 - { 2039 - } 2040 - #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ 2041 - 2042 1944 static void cpu_enable_kpti(struct arm64_cpu_capabilities const *cap) 2043 1945 { 2044 1946 if (__this_cpu_read(this_cpu_vector) == vectors) { ··· 2321 2419 #ifdef CONFIG_ARM64_MTE 2322 2420 static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) 2323 2421 { 2422 + static bool cleared_zero_page = false; 2423 + 2324 2424 sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0); 2325 2425 2326 2426 mte_cpu_setup(); 2327 2427 2328 2428 /* 2329 2429 * Clear the tags in the zero page. This needs to be done via the 2330 - * linear map which has the Tagged attribute. 2430 + * linear map which has the Tagged attribute. Since this page is 2431 + * always mapped as pte_special(), set_pte_at() will not attempt to 2432 + * clear the tags or set PG_mte_tagged. 2331 2433 */ 2332 - if (try_page_mte_tagging(ZERO_PAGE(0))) { 2434 + if (!cleared_zero_page) { 2435 + cleared_zero_page = true; 2333 2436 mte_clear_page_tags(lm_alias(empty_zero_page)); 2334 - set_page_mte_tagged(ZERO_PAGE(0)); 2335 2437 } 2336 2438 2337 2439 kasan_init_hw_tags_cpu();
+1 -1
arch/arm64/kernel/mte.c
··· 478 478 if (folio_test_hugetlb(folio)) 479 479 WARN_ON_ONCE(!folio_test_hugetlb_mte_tagged(folio)); 480 480 else 481 - WARN_ON_ONCE(!page_mte_tagged(page)); 481 + WARN_ON_ONCE(!page_mte_tagged(page) && !is_zero_page(page)); 482 482 483 483 /* limit access to the end of the page */ 484 484 offset = offset_in_page(addr);
+12
arch/arm64/kernel/probes/kprobes.c
··· 10 10 11 11 #define pr_fmt(fmt) "kprobes: " fmt 12 12 13 + #include <linux/execmem.h> 13 14 #include <linux/extable.h> 14 15 #include <linux/kasan.h> 15 16 #include <linux/kernel.h> ··· 41 40 42 41 static void __kprobes 43 42 post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *); 43 + 44 + void *alloc_insn_page(void) 45 + { 46 + void *addr; 47 + 48 + addr = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE); 49 + if (!addr) 50 + return NULL; 51 + set_memory_rox((unsigned long)addr, 1); 52 + return addr; 53 + } 44 54 45 55 static void __kprobes arch_prepare_ss_slot(struct kprobe *p) 46 56 {
+88 -10
arch/arm64/mm/mmu.c
··· 470 470 mutex_unlock(&fixmap_lock); 471 471 } 472 472 473 - #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 474 - extern __alias(__create_pgd_mapping_locked) 475 - void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt, 476 - phys_addr_t size, pgprot_t prot, 477 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 478 - int flags); 479 - #endif 480 - 481 473 #define INVALID_PHYS_ADDR (-1ULL) 482 474 483 475 static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp, ··· 815 823 816 824 u32 idmap_kpti_bbml2_flag; 817 825 818 - void __init init_idmap_kpti_bbml2_flag(void) 826 + static void __init init_idmap_kpti_bbml2_flag(void) 819 827 { 820 828 WRITE_ONCE(idmap_kpti_bbml2_flag, 1); 821 829 /* Must be visible to other CPUs before stop_machine() is called. */ ··· 1127 1135 } 1128 1136 1129 1137 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1130 - static pgprot_t kernel_exec_prot(void) 1138 + #define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT)) 1139 + 1140 + static phys_addr_t kpti_ng_temp_alloc __initdata; 1141 + 1142 + static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type) 1143 + { 1144 + kpti_ng_temp_alloc -= PAGE_SIZE; 1145 + return kpti_ng_temp_alloc; 1146 + } 1147 + 1148 + static int __init __kpti_install_ng_mappings(void *__unused) 1149 + { 1150 + typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long); 1151 + extern kpti_remap_fn idmap_kpti_install_ng_mappings; 1152 + kpti_remap_fn *remap_fn; 1153 + 1154 + int cpu = smp_processor_id(); 1155 + int levels = CONFIG_PGTABLE_LEVELS; 1156 + int order = order_base_2(levels); 1157 + u64 kpti_ng_temp_pgd_pa = 0; 1158 + pgd_t *kpti_ng_temp_pgd; 1159 + u64 alloc = 0; 1160 + 1161 + if (levels == 5 && !pgtable_l5_enabled()) 1162 + levels = 4; 1163 + else if (levels == 4 && !pgtable_l4_enabled()) 1164 + levels = 3; 1165 + 1166 + remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings); 1167 + 1168 + if (!cpu) { 1169 + alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order); 1170 + kpti_ng_temp_pgd = (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE); 1171 + kpti_ng_temp_alloc = kpti_ng_temp_pgd_pa = __pa(kpti_ng_temp_pgd); 1172 + 1173 + // 1174 + // Create a minimal page table hierarchy that permits us to map 1175 + // the swapper page tables temporarily as we traverse them. 1176 + // 1177 + // The physical pages are laid out as follows: 1178 + // 1179 + // +--------+-/-------+-/------ +-/------ +-\\\--------+ 1180 + // : PTE[] : | PMD[] : | PUD[] : | P4D[] : ||| PGD[] : 1181 + // +--------+-\-------+-\------ +-\------ +-///--------+ 1182 + // ^ 1183 + // The first page is mapped into this hierarchy at a PMD_SHIFT 1184 + // aligned virtual address, so that we can manipulate the PTE 1185 + // level entries while the mapping is active. The first entry 1186 + // covers the PTE[] page itself, the remaining entries are free 1187 + // to be used as a ad-hoc fixmap. 1188 + // 1189 + __create_pgd_mapping_locked(kpti_ng_temp_pgd, __pa(alloc), 1190 + KPTI_NG_TEMP_VA, PAGE_SIZE, PAGE_KERNEL, 1191 + kpti_ng_pgd_alloc, 0); 1192 + } 1193 + 1194 + cpu_install_idmap(); 1195 + remap_fn(cpu, num_online_cpus(), kpti_ng_temp_pgd_pa, KPTI_NG_TEMP_VA); 1196 + cpu_uninstall_idmap(); 1197 + 1198 + if (!cpu) { 1199 + free_pages(alloc, order); 1200 + arm64_use_ng_mappings = true; 1201 + } 1202 + 1203 + return 0; 1204 + } 1205 + 1206 + void __init kpti_install_ng_mappings(void) 1207 + { 1208 + /* Check whether KPTI is going to be used */ 1209 + if (!arm64_kernel_unmapped_at_el0()) 1210 + return; 1211 + 1212 + /* 1213 + * We don't need to rewrite the page-tables if either we've done 1214 + * it already or we have KASLR enabled and therefore have not 1215 + * created any global mappings at all. 1216 + */ 1217 + if (arm64_use_ng_mappings) 1218 + return; 1219 + 1220 + init_idmap_kpti_bbml2_flag(); 1221 + stop_machine(__kpti_install_ng_mappings, NULL, cpu_online_mask); 1222 + } 1223 + 1224 + static pgprot_t __init kernel_exec_prot(void) 1131 1225 { 1132 1226 return rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC; 1133 1227 }
+29 -4
drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c
··· 57 57 #define L3C_V2_NR_EVENTS 0xFF 58 58 59 59 HISI_PMU_EVENT_ATTR_EXTRACTOR(ext, config, 17, 16); 60 + /* 61 + * Remain the config1:0-7 for backward compatibility if some existing users 62 + * hardcode the config1:0-7 directly without parsing the sysfs attribute. 63 + */ 64 + HISI_PMU_EVENT_ATTR_EXTRACTOR(tt_core_deprecated, config1, 7, 0); 60 65 HISI_PMU_EVENT_ATTR_EXTRACTOR(tt_req, config1, 10, 8); 61 66 HISI_PMU_EVENT_ATTR_EXTRACTOR(datasrc_cfg, config1, 15, 11); 62 67 HISI_PMU_EVENT_ATTR_EXTRACTOR(datasrc_skt, config1, 16, 16); ··· 98 93 struct hisi_l3c_pmu_ext *l3c_pmu_ext = pmu->l3c_pmu.dev_info->private; 99 94 100 95 return l3c_pmu_ext->support_ext; 96 + } 97 + 98 + /* 99 + * tt_core was extended to cover all the CPUs sharing the L3 and was moved from 100 + * config1:0-7 to config2:0-*. Try it first and fallback to tt_core_deprecated 101 + * if user's still using the deprecated one. 102 + */ 103 + static u32 hisi_l3c_pmu_get_tt_core(struct perf_event *event) 104 + { 105 + u32 core = hisi_get_tt_core(event); 106 + 107 + if (core) 108 + return core; 109 + 110 + return hisi_get_tt_core_deprecated(event); 101 111 } 102 112 103 113 static int hisi_l3c_pmu_get_event_idx(struct perf_event *event) ··· 279 259 static void hisi_l3c_pmu_config_core_tracetag(struct perf_event *event) 280 260 { 281 261 struct hw_perf_event *hwc = &event->hw; 282 - u32 core = hisi_get_tt_core(event); 262 + u32 core = hisi_l3c_pmu_get_tt_core(event); 283 263 284 264 if (core) { 285 265 u32 val; ··· 300 280 static void hisi_l3c_pmu_clear_core_tracetag(struct perf_event *event) 301 281 { 302 282 struct hw_perf_event *hwc = &event->hw; 303 - u32 core = hisi_get_tt_core(event); 283 + u32 core = hisi_l3c_pmu_get_tt_core(event); 304 284 305 285 if (core) { 306 286 u32 val; ··· 320 300 321 301 static bool hisi_l3c_pmu_have_filter(struct perf_event *event) 322 302 { 323 - return hisi_get_tt_req(event) || hisi_get_tt_core(event) || 303 + return hisi_get_tt_req(event) || hisi_l3c_pmu_get_tt_core(event) || 324 304 hisi_get_datasrc_cfg(event) || hisi_get_datasrc_skt(event); 325 305 } 326 306 ··· 349 329 int ext = hisi_get_ext(event); 350 330 351 331 if (ext < 0 || ext > hisi_l3c_pmu->ext_num) 332 + return -EINVAL; 333 + 334 + if (hisi_get_tt_core(event) && hisi_get_tt_core_deprecated(event)) 352 335 return -EINVAL; 353 336 354 337 return 0; ··· 625 602 626 603 static struct attribute *hisi_l3c_pmu_v2_format_attr[] = { 627 604 HISI_PMU_FORMAT_ATTR(event, "config:0-7"), 628 - HISI_PMU_FORMAT_ATTR(tt_core, "config2:0-15"), 605 + HISI_PMU_FORMAT_ATTR(tt_core_deprecated, "config1:0-7"), 629 606 HISI_PMU_FORMAT_ATTR(tt_req, "config1:8-10"), 630 607 HISI_PMU_FORMAT_ATTR(datasrc_cfg, "config1:11-15"), 631 608 HISI_PMU_FORMAT_ATTR(datasrc_skt, "config1:16"), 609 + HISI_PMU_FORMAT_ATTR(tt_core, "config2:0-15"), 632 610 NULL 633 611 }; 634 612 ··· 641 617 static struct attribute *hisi_l3c_pmu_v3_format_attr[] = { 642 618 HISI_PMU_FORMAT_ATTR(event, "config:0-7"), 643 619 HISI_PMU_FORMAT_ATTR(ext, "config:16-17"), 620 + HISI_PMU_FORMAT_ATTR(tt_core_deprecated, "config1:0-7"), 644 621 HISI_PMU_FORMAT_ATTR(tt_req, "config1:8-10"), 645 622 HISI_PMU_FORMAT_ATTR(tt_core, "config2:0-15"), 646 623 NULL