powerpc/perf/imc: Use cpu_to_node() not topology_physical_package_id()
authorMichael Ellerman <mpe@ellerman.id.au>
Sun, 15 Oct 2017 18:43:41 +0000 (00:13 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Nov 2017 08:40:56 +0000 (08:40 +0000)
commit f3f1dfd600ff82b18b7ea73d80eb27f476a6aa97 upstream.

init_imc_pmu() uses topology_physical_package_id() to detect the
node id of the processor it is on to get local memory, but that's
wrong, and can lead to crashes. Fix it to use cpu_to_node().

Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
Reported-By: Rob Lippert <rlippert@google.com>
Tested-By: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/powerpc/perf/imc-pmu.c

index 36344117c680b9e0500b345c18f98d11cb246134..cf64e16f92c255cd1fe7e054922d90b408b6f69d 100644 (file)
@@ -467,7 +467,7 @@ static int nest_imc_event_init(struct perf_event *event)
         * Nest HW counter memory resides in a per-chip reserve-memory (HOMER).
         * Get the base memory addresss for this cpu.
         */
-       chip_id = topology_physical_package_id(event->cpu);
+       chip_id = cpu_to_chip_id(event->cpu);
        pcni = pmu->mem_info;
        do {
                if (pcni->id == chip_id) {
@@ -524,19 +524,19 @@ static int nest_imc_event_init(struct perf_event *event)
  */
 static int core_imc_mem_init(int cpu, int size)
 {
-       int phys_id, rc = 0, core_id = (cpu / threads_per_core);
+       int nid, rc = 0, core_id = (cpu / threads_per_core);
        struct imc_mem_info *mem_info;
 
        /*
         * alloc_pages_node() will allocate memory for core in the
         * local node only.
         */
-       phys_id = topology_physical_package_id(cpu);
+       nid = cpu_to_node(cpu);
        mem_info = &core_imc_pmu->mem_info[core_id];
        mem_info->id = core_id;
 
        /* We need only vbase for core counters */
-       mem_info->vbase = page_address(alloc_pages_node(phys_id,
+       mem_info->vbase = page_address(alloc_pages_node(nid,
                                          GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE |
                                          __GFP_NOWARN, get_order(size)));
        if (!mem_info->vbase)
@@ -797,14 +797,14 @@ static int core_imc_event_init(struct perf_event *event)
 static int thread_imc_mem_alloc(int cpu_id, int size)
 {
        u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, cpu_id);
-       int phys_id = topology_physical_package_id(cpu_id);
+       int nid = cpu_to_node(cpu_id);
 
        if (!local_mem) {
                /*
                 * This case could happen only once at start, since we dont
                 * free the memory in cpu offline path.
                 */
-               local_mem = page_address(alloc_pages_node(phys_id,
+               local_mem = page_address(alloc_pages_node(nid,
                                  GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE |
                                  __GFP_NOWARN, get_order(size)));
                if (!local_mem)