powerpc/perf: Fix loop exit condition in nest_imc_event_init
PATCH 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 nodes in the system.
--- arch/powerpc/perf/imc-pmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/perf/imc-pmu.c +2 -2
@@ -459,7 +459,7 @@ static void nest_imc_counters_release(struct perf_event *event)static int nest_imc_event_init (struct perf_event *event) { -int chip_id, rc, node_id; +int chip_id, rc, node_id, nr_chips =num_possible_nodes ();u32 l_config, config = event->attr.config;struct imc_mem_info *pcni;struct imc_pmu *pmu;
@@ -508,7 +508,7 @@ static int nest_imc_event_init(struct perf_event *event)break ; } pcni++; - }while (pcni); + }while (--nr_chips);if (!flag)return -ENODEV ;
Signature · 1 line
2.17.1
PATCH 1/1 powerpc/perf: Return accordingly on invalid chip-id in
Nest hardware counter memory resides in a per-chip reserve-memory. During nest_imc_event_init(), chip-id of the event-cpu is considered to calculate the base memory addresss for that cpu. Return, proper error condition if the chip_id calculated is invalid.
--- arch/powerpc/perf/imc-pmu.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/powerpc/perf/imc-pmu.c +5 -0
@@ -496,6 +496,11 @@ static int nest_imc_event_init(struct perf_event *event)* Get the base memory addresss for this cpu. */ chip_id =cpu_to_chip_id (event->cpu); + +/* Return, if chip_id is not valid */ +if (chip_id <0 ) +return -ENODEV ; + pcni = pmu->mem_info; do { if (pcni->id == chip_id) {
Signature · 1 line
2.17.1
Michael Ellerman
AppliedRe: [PATCH] powerpc/perf: Return accordingly on invalid chip-id in
Quoted 9 lines · Anju T Sudhakar
Nest hardware counter memory resides in a per-chip reserve-memory. During
nest_imc_event_init(), chip-id of the event-cpu is considered to calculate the base memory addresss for that cpu. Return, proper error condition if thechip_idcalculated is invalid.Reported-by Dan Carpenter <[email protected]>Fixes 885dcd709ba91 ("powerpc/perf: Add nest IMC PMU support")Reviewed-by Madhavan Srinivasan <[email protected]>Signed-off-by Anju T Sudhakar <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a913e5e8b43be1d3897a141ce61c1ec0
cheers