Skip to contentSkip to conversation

powerpc/perf: Fix loop exit condition in nest_imc_event_init

PATCH Applied Anju T Sudhakar 3 participants 3 messages Dec 18, 2018 – May 3, 2019 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc/perf: Fix loop exit condition in nest_imc_event_init

The data structure (i.e struct imc_mem_info) to hold the memory address information for nest imc units is allocated based on the number of nodes in the system.

nest_imc_event_init() traverse this struct array to calculate the memory base address for the event-cpu. If we fail to find a match for the event cpu's chip-id in imc_mem_info struct array, then the do-while loop will iterate until we crash.

Fix this by changing the loop exit condition based on the number of non zero vbase elements in the array, since the allocation is done for nr_chips + 1.

Fixes 885dcd709ba91 ( powerpc/perf: Add nest IMC PMU support)
---
 arch/powerpc/perf/imc-pmu.c               | 2 +-
 arch/powerpc/platforms/powernv/opal-imc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/perf/imc-pmu.c +1 -1
index 4f34c75..d1009fe 100644
@@ -508,7 +508,7 @@ static int nest_imc_event_init(struct perf_event *event)
 			break;
 		}
 		pcni++;
-	} while (pcni);
+	} while (pcni->vbase != 0);
 
 	if (!flag)
 		return -ENODEV;
arch/powerpc/platforms/powernv/opal-imc.c +1 -1
index 58a0794..3d27f02 100644
@@ -127,7 +127,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,
 								nr_chips))
 		goto error;
 
-	pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(*pmu_ptr->mem_info),
+	pmu_ptr->mem_info = kcalloc(nr_chips + 1, sizeof(*pmu_ptr->mem_info),
 				    GFP_KERNEL);
 	if (!pmu_ptr->mem_info)
 		goto error;
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Anju T Sudhakar

The data structure (i.e struct imc_mem_info) to hold the memory address information for nest imc units is allocated based on the number of nodes in the system.

Quoted 8 lines

nest_imc_event_init() traverse this struct array to calculate the memory base address for the event-cpu. If we fail to find a match for the event cpu's chip-id in imc_mem_info struct array, then the do-while loop will iterate until we crash.

Fix this by changing the loop exit condition based on the number of non zero vbase elements in the array, since the allocation is done for nr_chips + 1.

B/w we will also need this patch to go along
https://patchwork.ozlabs.org/patch/1003669/

These 2 fixes need to go to stable also.

Quoted 34 lines
Fixes 885dcd709ba91 ( powerpc/perf: Add nest IMC PMU support)
---
  arch/powerpc/perf/imc-pmu.c               | 2 +-
  arch/powerpc/platforms/powernv/opal-imc.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/perf/imc-pmu.c +1 -1
index 4f34c75..d1009fe 100644
@@ -508,7 +508,7 @@ static int nest_imc_event_init(struct perf_event *event)
  			break;
  		}
  		pcni++;
-	} while (pcni);
+	} while (pcni->vbase != 0);
 
  	if (!flag)
  		return -ENODEV;
arch/powerpc/platforms/powernv/opal-imc.c +1 -1
index 58a0794..3d27f02 100644
@@ -127,7 +127,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,
  								nr_chips))
  		goto error;
 
-	pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(*pmu_ptr->mem_info),
+	pmu_ptr->mem_info = kcalloc(nr_chips + 1, sizeof(*pmu_ptr->mem_info),
  				    GFP_KERNEL);
  	if (!pmu_ptr->mem_info)
  		goto error;
#2 lore raw
In reply to Anju T Sudhakar
Quoted 9 lines · Anju T Sudhakar

The data structure (i.e struct imc_mem_info) to hold the memory address information for nest imc units is allocated based on the number of nodes in the system.

nest_imc_event_init() traverse this struct array to calculate the memory base address for the event-cpu. If we fail to find a match for the event cpu's chip-id in imc_mem_info struct array, then the do-while loop will iterate until we crash.

Quoted 8 lines

Fix this by changing the loop exit condition based on the number of non zero vbase elements in the array, since the allocation is done for nr_chips + 1.

Fixes 885dcd709ba91 ( powerpc/perf: Add nest IMC PMU support)

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/860b7d2286236170a36f94946d03ca98

cheers