Skip to content

Commit f3f1dfd

Browse files
committed
powerpc/perf/imc: Use cpu_to_node() not topology_physical_package_id()
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: 885dcd7 ("powerpc/perf: Add nest IMC PMU support") Cc: stable@vger.kernel.org # v4.14+ 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>
1 parent 62b49c4 commit f3f1dfd

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎arch/powerpc/perf/imc-pmu.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static int nest_imc_event_init(struct perf_event *event)
467467
* Nest HW counter memory resides in a per-chip reserve-memory (HOMER).
468468
* Get the base memory addresss for this cpu.
469469
*/
470-
chip_id = topology_physical_package_id(event->cpu);
470+
chip_id = cpu_to_chip_id(event->cpu);
471471
pcni = pmu->mem_info;
472472
do {
473473
if (pcni->id == chip_id) {
@@ -524,19 +524,19 @@ static int nest_imc_event_init(struct perf_event *event)
524524
*/
525525
static int core_imc_mem_init(int cpu, int size)
526526
{
527-
int phys_id, rc = 0, core_id = (cpu / threads_per_core);
527+
int nid, rc = 0, core_id = (cpu / threads_per_core);
528528
struct imc_mem_info *mem_info;
529529

530530
/*
531531
* alloc_pages_node() will allocate memory for core in the
532532
* local node only.
533533
*/
534-
phys_id = topology_physical_package_id(cpu);
534+
nid = cpu_to_node(cpu);
535535
mem_info = &core_imc_pmu->mem_info[core_id];
536536
mem_info->id = core_id;
537537

538538
/* We need only vbase for core counters */
539-
mem_info->vbase = page_address(alloc_pages_node(phys_id,
539+
mem_info->vbase = page_address(alloc_pages_node(nid,
540540
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE |
541541
__GFP_NOWARN, get_order(size)));
542542
if (!mem_info->vbase)
@@ -797,14 +797,14 @@ static int core_imc_event_init(struct perf_event *event)
797797
static int thread_imc_mem_alloc(int cpu_id, int size)
798798
{
799799
u64 ldbar_value, *local_mem = per_cpu(thread_imc_mem, cpu_id);
800-
int phys_id = topology_physical_package_id(cpu_id);
800+
int nid = cpu_to_node(cpu_id);
801801

802802
if (!local_mem) {
803803
/*
804804
* This case could happen only once at start, since we dont
805805
* free the memory in cpu offline path.
806806
*/
807-
local_mem = page_address(alloc_pages_node(phys_id,
807+
local_mem = page_address(alloc_pages_node(nid,
808808
GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE |
809809
__GFP_NOWARN, get_order(size)));
810810
if (!local_mem)

0 commit comments

Comments
 (0)