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