Merge tag 'powerpc-4.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux

Pull powerpc fixes from Michael Ellerman:
"A small batch of fixes, about 50% tagged for stable and the rest for
recently merged code.

There's one more fix for the >128T handling on hash. Once a process
had requested a single mmap above 128T we would then always search
above 128T. The correct behaviour is to consider the hint address in
isolation for each mmap request.

Then a couple of fixes for the IMC PMU, a missing EXPORT_SYMBOL in
VAS, a fix for STRICT_KERNEL_RWX on 32-bit, and a fix to correctly
identify P9 DD2.1 but in code that is currently not used by default.

Thanks to: Aneesh Kumar K.V, Christophe Leroy, Madhavan Srinivasan,
Sukadev Bhattiprolu"

* tag 'powerpc-4.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux:
powerpc/64s: Fix Power9 DD2.1 logic in DT CPU features
powerpc/perf: Fix IMC_MAX_PMU macro
powerpc/perf: Fix pmu_count to count only nest imc pmus
powerpc: Fix boot on BOOK3S_32 with CONFIG_STRICT_KERNEL_RWX
powerpc/perf/imc: Use cpu_to_node() not topology_physical_package_id()
powerpc/vas: Export chip_to_vas_id()
powerpc/64s/slice: Use addr limit when computing slice mask

+66 -34
+1 -5
arch/powerpc/include/asm/imc-pmu.h
··· 21 #include <asm/opal.h> 22 23 /* 24 - * For static allocation of some of the structures. 25 - */ 26 - #define IMC_MAX_PMUS 32 27 - 28 - /* 29 * Compatibility macros for IMC devices 30 */ 31 #define IMC_DTB_COMPAT "ibm,opal-in-memory-counters" ··· 120 extern int init_imc_pmu(struct device_node *parent, 121 struct imc_pmu *pmu_ptr, int pmu_id); 122 extern void thread_imc_disable(void); 123 #endif /* __ASM_POWERPC_IMC_PMU_H */
··· 21 #include <asm/opal.h> 22 23 /* 24 * Compatibility macros for IMC devices 25 */ 26 #define IMC_DTB_COMPAT "ibm,opal-in-memory-counters" ··· 125 extern int init_imc_pmu(struct device_node *parent, 126 struct imc_pmu *pmu_ptr, int pmu_id); 127 extern void thread_imc_disable(void); 128 + extern int get_max_nest_dev(void); 129 #endif /* __ASM_POWERPC_IMC_PMU_H */
+2 -2
arch/powerpc/kernel/dt_cpu_ftrs.c
··· 735 */ 736 if ((version & 0xffffff00) == 0x004e0100) 737 cur_cpu_spec->cpu_features |= CPU_FTR_POWER9_DD1; 738 - else if ((version & 0xffffefff) == 0x004e0200) 739 - cur_cpu_spec->cpu_features &= ~CPU_FTR_POWER9_DD2_1; 740 } 741 742 static void __init cpufeatures_setup_finished(void)
··· 735 */ 736 if ((version & 0xffffff00) == 0x004e0100) 737 cur_cpu_spec->cpu_features |= CPU_FTR_POWER9_DD1; 738 + else if ((version & 0xffffefff) == 0x004e0201) 739 + cur_cpu_spec->cpu_features |= CPU_FTR_POWER9_DD2_1; 740 } 741 742 static void __init cpufeatures_setup_finished(void)
+2 -4
arch/powerpc/lib/code-patching.c
··· 21 #include <asm/tlbflush.h> 22 #include <asm/page.h> 23 #include <asm/code-patching.h> 24 25 static int __patch_instruction(unsigned int *addr, unsigned int instr) 26 { ··· 147 * During early early boot patch_instruction is called 148 * when text_poke_area is not ready, but we still need 149 * to allow patching. We just do the plain old patching 150 - * We use slab_is_available and per cpu read * via this_cpu_read 151 - * of text_poke_area. Per-CPU areas might not be up early 152 - * this can create problems with just using this_cpu_read() 153 */ 154 - if (!slab_is_available() || !this_cpu_read(text_poke_area)) 155 return __patch_instruction(addr, instr); 156 157 local_irq_save(flags);
··· 21 #include <asm/tlbflush.h> 22 #include <asm/page.h> 23 #include <asm/code-patching.h> 24 + #include <asm/setup.h> 25 26 static int __patch_instruction(unsigned int *addr, unsigned int instr) 27 { ··· 146 * During early early boot patch_instruction is called 147 * when text_poke_area is not ready, but we still need 148 * to allow patching. We just do the plain old patching 149 */ 150 + if (!this_cpu_read(*PTRRELOC(&text_poke_area))) 151 return __patch_instruction(addr, instr); 152 153 local_irq_save(flags);
+22 -12
arch/powerpc/mm/slice.c
··· 122 return !slice_area_is_free(mm, start, end - start); 123 } 124 125 - static void slice_mask_for_free(struct mm_struct *mm, struct slice_mask *ret) 126 { 127 unsigned long i; 128 ··· 134 if (!slice_low_has_vma(mm, i)) 135 ret->low_slices |= 1u << i; 136 137 - if (mm->context.slb_addr_limit <= SLICE_LOW_TOP) 138 return; 139 140 - for (i = 0; i < GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); i++) 141 if (!slice_high_has_vma(mm, i)) 142 __set_bit(i, ret->high_slices); 143 } 144 145 - static void slice_mask_for_size(struct mm_struct *mm, int psize, struct slice_mask *ret) 146 { 147 unsigned char *hpsizes; 148 int index, mask_index; ··· 158 if (((lpsizes >> (i * 4)) & 0xf) == psize) 159 ret->low_slices |= 1u << i; 160 161 hpsizes = mm->context.high_slices_psize; 162 - for (i = 0; i < GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); i++) { 163 mask_index = i & 0x1; 164 index = i >> 1; 165 if (((hpsizes[index] >> (mask_index * 4)) & 0xf) == psize) ··· 174 struct slice_mask mask, struct slice_mask available) 175 { 176 DECLARE_BITMAP(result, SLICE_NUM_HIGH); 177 unsigned long slice_count = GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); 178 179 bitmap_and(result, mask.high_slices, ··· 481 /* First make up a "good" mask of slices that have the right size 482 * already 483 */ 484 - slice_mask_for_size(mm, psize, &good_mask); 485 slice_print_mask(" good_mask", good_mask); 486 487 /* ··· 506 #ifdef CONFIG_PPC_64K_PAGES 507 /* If we support combo pages, we can allow 64k pages in 4k slices */ 508 if (psize == MMU_PAGE_64K) { 509 - slice_mask_for_size(mm, MMU_PAGE_4K, &compat_mask); 510 if (fixed) 511 slice_or_mask(&good_mask, &compat_mask); 512 } ··· 539 return newaddr; 540 } 541 } 542 - 543 - /* We don't fit in the good mask, check what other slices are 544 * empty and thus can be converted 545 */ 546 - slice_mask_for_free(mm, &potential_mask); 547 slice_or_mask(&potential_mask, &good_mask); 548 slice_print_mask(" potential", potential_mask); 549 ··· 753 { 754 struct slice_mask mask, available; 755 unsigned int psize = mm->context.user_psize; 756 757 if (radix_enabled()) 758 return 0; 759 760 slice_range_to_mask(addr, len, &mask); 761 - slice_mask_for_size(mm, psize, &available); 762 #ifdef CONFIG_PPC_64K_PAGES 763 /* We need to account for 4k slices too */ 764 if (psize == MMU_PAGE_64K) { 765 struct slice_mask compat_mask; 766 - slice_mask_for_size(mm, MMU_PAGE_4K, &compat_mask); 767 slice_or_mask(&available, &compat_mask); 768 } 769 #endif
··· 122 return !slice_area_is_free(mm, start, end - start); 123 } 124 125 + static void slice_mask_for_free(struct mm_struct *mm, struct slice_mask *ret, 126 + unsigned long high_limit) 127 { 128 unsigned long i; 129 ··· 133 if (!slice_low_has_vma(mm, i)) 134 ret->low_slices |= 1u << i; 135 136 + if (high_limit <= SLICE_LOW_TOP) 137 return; 138 139 + for (i = 0; i < GET_HIGH_SLICE_INDEX(high_limit); i++) 140 if (!slice_high_has_vma(mm, i)) 141 __set_bit(i, ret->high_slices); 142 } 143 144 + static void slice_mask_for_size(struct mm_struct *mm, int psize, struct slice_mask *ret, 145 + unsigned long high_limit) 146 { 147 unsigned char *hpsizes; 148 int index, mask_index; ··· 156 if (((lpsizes >> (i * 4)) & 0xf) == psize) 157 ret->low_slices |= 1u << i; 158 159 + if (high_limit <= SLICE_LOW_TOP) 160 + return; 161 + 162 hpsizes = mm->context.high_slices_psize; 163 + for (i = 0; i < GET_HIGH_SLICE_INDEX(high_limit); i++) { 164 mask_index = i & 0x1; 165 index = i >> 1; 166 if (((hpsizes[index] >> (mask_index * 4)) & 0xf) == psize) ··· 169 struct slice_mask mask, struct slice_mask available) 170 { 171 DECLARE_BITMAP(result, SLICE_NUM_HIGH); 172 + /* 173 + * Make sure we just do bit compare only to the max 174 + * addr limit and not the full bit map size. 175 + */ 176 unsigned long slice_count = GET_HIGH_SLICE_INDEX(mm->context.slb_addr_limit); 177 178 bitmap_and(result, mask.high_slices, ··· 472 /* First make up a "good" mask of slices that have the right size 473 * already 474 */ 475 + slice_mask_for_size(mm, psize, &good_mask, high_limit); 476 slice_print_mask(" good_mask", good_mask); 477 478 /* ··· 497 #ifdef CONFIG_PPC_64K_PAGES 498 /* If we support combo pages, we can allow 64k pages in 4k slices */ 499 if (psize == MMU_PAGE_64K) { 500 + slice_mask_for_size(mm, MMU_PAGE_4K, &compat_mask, high_limit); 501 if (fixed) 502 slice_or_mask(&good_mask, &compat_mask); 503 } ··· 530 return newaddr; 531 } 532 } 533 + /* 534 + * We don't fit in the good mask, check what other slices are 535 * empty and thus can be converted 536 */ 537 + slice_mask_for_free(mm, &potential_mask, high_limit); 538 slice_or_mask(&potential_mask, &good_mask); 539 slice_print_mask(" potential", potential_mask); 540 ··· 744 { 745 struct slice_mask mask, available; 746 unsigned int psize = mm->context.user_psize; 747 + unsigned long high_limit = mm->context.slb_addr_limit; 748 749 if (radix_enabled()) 750 return 0; 751 752 slice_range_to_mask(addr, len, &mask); 753 + slice_mask_for_size(mm, psize, &available, high_limit); 754 #ifdef CONFIG_PPC_64K_PAGES 755 /* We need to account for 4k slices too */ 756 if (psize == MMU_PAGE_64K) { 757 struct slice_mask compat_mask; 758 + slice_mask_for_size(mm, MMU_PAGE_4K, &compat_mask, high_limit); 759 slice_or_mask(&available, &compat_mask); 760 } 761 #endif
+18 -9
arch/powerpc/perf/imc-pmu.c
··· 26 */ 27 static DEFINE_MUTEX(nest_init_lock); 28 static DEFINE_PER_CPU(struct imc_pmu_ref *, local_nest_imc_refc); 29 - static struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS]; 30 static cpumask_t nest_imc_cpumask; 31 struct imc_pmu_ref *nest_imc_refc; 32 static int nest_pmus; ··· 286 static void nest_change_cpu_context(int old_cpu, int new_cpu) 287 { 288 struct imc_pmu **pn = per_nest_pmu_arr; 289 - int i; 290 291 if (old_cpu < 0 || new_cpu < 0) 292 return; 293 294 - for (i = 0; *pn && i < IMC_MAX_PMUS; i++, pn++) 295 perf_pmu_migrate_context(&(*pn)->pmu, old_cpu, new_cpu); 296 } 297 298 static int ppc_nest_imc_cpu_offline(unsigned int cpu) ··· 468 * Nest HW counter memory resides in a per-chip reserve-memory (HOMER). 469 * Get the base memory addresss for this cpu. 470 */ 471 - chip_id = topology_physical_package_id(event->cpu); 472 pcni = pmu->mem_info; 473 do { 474 if (pcni->id == chip_id) { ··· 525 */ 526 static int core_imc_mem_init(int cpu, int size) 527 { 528 - int phys_id, rc = 0, core_id = (cpu / threads_per_core); 529 struct imc_mem_info *mem_info; 530 531 /* 532 * alloc_pages_node() will allocate memory for core in the 533 * local node only. 534 */ 535 - phys_id = topology_physical_package_id(cpu); 536 mem_info = &core_imc_pmu->mem_info[core_id]; 537 mem_info->id = core_id; 538 539 /* We need only vbase for core counters */ 540 - mem_info->vbase = page_address(alloc_pages_node(phys_id, 541 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE | 542 __GFP_NOWARN, get_order(size))); 543 if (!mem_info->vbase) ··· 798 static int thread_imc_mem_alloc(int cpu_id, int size) 799 { 800 u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, cpu_id); 801 - int phys_id = topology_physical_package_id(cpu_id); 802 803 if (!local_mem) { 804 /* 805 * This case could happen only once at start, since we dont 806 * free the memory in cpu offline path. 807 */ 808 - local_mem = page_address(alloc_pages_node(phys_id, 809 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE | 810 __GFP_NOWARN, get_order(size))); 811 if (!local_mem) ··· 1195 kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs); 1196 kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]); 1197 kfree(pmu_ptr); 1198 return; 1199 } 1200 ··· 1220 return -ENOMEM; 1221 1222 /* Needed for hotplug/migration */ 1223 per_nest_pmu_arr[pmu_index] = pmu_ptr; 1224 break; 1225 case IMC_DOMAIN_CORE:
··· 26 */ 27 static DEFINE_MUTEX(nest_init_lock); 28 static DEFINE_PER_CPU(struct imc_pmu_ref *, local_nest_imc_refc); 29 + static struct imc_pmu **per_nest_pmu_arr; 30 static cpumask_t nest_imc_cpumask; 31 struct imc_pmu_ref *nest_imc_refc; 32 static int nest_pmus; ··· 286 static void nest_change_cpu_context(int old_cpu, int new_cpu) 287 { 288 struct imc_pmu **pn = per_nest_pmu_arr; 289 290 if (old_cpu < 0 || new_cpu < 0) 291 return; 292 293 + while (*pn) { 294 perf_pmu_migrate_context(&(*pn)->pmu, old_cpu, new_cpu); 295 + pn++; 296 + } 297 } 298 299 static int ppc_nest_imc_cpu_offline(unsigned int cpu) ··· 467 * Nest HW counter memory resides in a per-chip reserve-memory (HOMER). 468 * Get the base memory addresss for this cpu. 469 */ 470 + chip_id = cpu_to_chip_id(event->cpu); 471 pcni = pmu->mem_info; 472 do { 473 if (pcni->id == chip_id) { ··· 524 */ 525 static int core_imc_mem_init(int cpu, int size) 526 { 527 + int nid, rc = 0, core_id = (cpu / threads_per_core); 528 struct imc_mem_info *mem_info; 529 530 /* 531 * alloc_pages_node() will allocate memory for core in the 532 * local node only. 533 */ 534 + nid = cpu_to_node(cpu); 535 mem_info = &core_imc_pmu->mem_info[core_id]; 536 mem_info->id = core_id; 537 538 /* We need only vbase for core counters */ 539 + mem_info->vbase = page_address(alloc_pages_node(nid, 540 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE | 541 __GFP_NOWARN, get_order(size))); 542 if (!mem_info->vbase) ··· 797 static int thread_imc_mem_alloc(int cpu_id, int size) 798 { 799 u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, cpu_id); 800 + int nid = cpu_to_node(cpu_id); 801 802 if (!local_mem) { 803 /* 804 * This case could happen only once at start, since we dont 805 * free the memory in cpu offline path. 806 */ 807 + local_mem = page_address(alloc_pages_node(nid, 808 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE | 809 __GFP_NOWARN, get_order(size))); 810 if (!local_mem) ··· 1194 kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]->attrs); 1195 kfree(pmu_ptr->attr_groups[IMC_EVENT_ATTR]); 1196 kfree(pmu_ptr); 1197 + kfree(per_nest_pmu_arr); 1198 return; 1199 } 1200 ··· 1218 return -ENOMEM; 1219 1220 /* Needed for hotplug/migration */ 1221 + if (!per_nest_pmu_arr) { 1222 + per_nest_pmu_arr = kcalloc(get_max_nest_dev() + 1, 1223 + sizeof(struct imc_pmu *), 1224 + GFP_KERNEL); 1225 + if (!per_nest_pmu_arr) 1226 + return -ENOMEM; 1227 + } 1228 per_nest_pmu_arr[pmu_index] = pmu_ptr; 1229 break; 1230 case IMC_DOMAIN_CORE:
+20 -2
arch/powerpc/platforms/powernv/opal-imc.c
··· 153 put_online_cpus(); 154 } 155 156 static int opal_imc_counters_probe(struct platform_device *pdev) 157 { 158 struct device_node *imc_dev = pdev->dev.of_node; ··· 207 break; 208 } 209 210 - if (!imc_pmu_create(imc_dev, pmu_count, domain)) 211 - pmu_count++; 212 } 213 214 return 0;
··· 153 put_online_cpus(); 154 } 155 156 + int get_max_nest_dev(void) 157 + { 158 + struct device_node *node; 159 + u32 pmu_units = 0, type; 160 + 161 + for_each_compatible_node(node, NULL, IMC_DTB_UNIT_COMPAT) { 162 + if (of_property_read_u32(node, "type", &type)) 163 + continue; 164 + 165 + if (type == IMC_TYPE_CHIP) 166 + pmu_units++; 167 + } 168 + 169 + return pmu_units; 170 + } 171 + 172 static int opal_imc_counters_probe(struct platform_device *pdev) 173 { 174 struct device_node *imc_dev = pdev->dev.of_node; ··· 191 break; 192 } 193 194 + if (!imc_pmu_create(imc_dev, pmu_count, domain)) { 195 + if (domain == IMC_DOMAIN_NEST) 196 + pmu_count++; 197 + } 198 } 199 200 return 0;
+1
arch/powerpc/platforms/powernv/vas.c
··· 135 } 136 return -1; 137 } 138 139 static int vas_probe(struct platform_device *pdev) 140 {
··· 135 } 136 return -1; 137 } 138 + EXPORT_SYMBOL(chip_to_vas_id); 139 140 static int vas_probe(struct platform_device *pdev) 141 {