* [PATCH] powerpc/perf: Fix loop exit condition in nest_imc_event_init
@ 2018-11-27 8:24 Anju T Sudhakar
2018-11-27 8:24 ` [PATCH] powerpc/perf: Return accordingly on invalid chip-id in Anju T Sudhakar
0 siblings, 1 reply; 3+ messages in thread
From: Anju T Sudhakar @ 2018-11-27 8:24 UTC (permalink / raw)
To: mpe; +Cc: maddy, linuxppc-dev, anju, dan.carpenter
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.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 885dcd709ba91 ( powerpc/perf: Add nest IMC PMU support)
Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
---
arch/powerpc/perf/imc-pmu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 78514170cf71..e9dc771f3e3d 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] powerpc/perf: Return accordingly on invalid chip-id in
2018-11-27 8:24 [PATCH] powerpc/perf: Fix loop exit condition in nest_imc_event_init Anju T Sudhakar
@ 2018-11-27 8:24 ` Anju T Sudhakar
2019-05-03 6:59 ` Michael Ellerman
0 siblings, 1 reply; 3+ messages in thread
From: Anju T Sudhakar @ 2018-11-27 8:24 UTC (permalink / raw)
To: mpe; +Cc: maddy, linuxppc-dev, anju, dan.carpenter
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.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 885dcd709ba91 ("powerpc/perf: Add nest IMC PMU support")
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
---
arch/powerpc/perf/imc-pmu.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 6954636b16d1..78514170cf71 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -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) {
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/perf: Return accordingly on invalid chip-id in
2018-11-27 8:24 ` [PATCH] powerpc/perf: Return accordingly on invalid chip-id in Anju T Sudhakar
@ 2019-05-03 6:59 ` Michael Ellerman
0 siblings, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2019-05-03 6:59 UTC (permalink / raw)
To: Anju T Sudhakar; +Cc: maddy, linuxppc-dev, anju, dan.carpenter
On Tue, 2018-11-27 at 08:24:52 UTC, Anju T Sudhakar wrote:
> 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.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Fixes: 885dcd709ba91 ("powerpc/perf: Add nest IMC PMU support")
> Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
> Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a913e5e8b43be1d3897a141ce61c1ec0
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-03 7:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-27 8:24 [PATCH] powerpc/perf: Fix loop exit condition in nest_imc_event_init Anju T Sudhakar
2018-11-27 8:24 ` [PATCH] powerpc/perf: Return accordingly on invalid chip-id in Anju T Sudhakar
2019-05-03 6:59 ` Michael Ellerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).