* [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init
@ 2018-12-18 6:20 Anju T Sudhakar
2018-12-19 5:53 ` Madhavan Srinivasan
2019-05-03 6:59 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Anju T Sudhakar @ 2018-12-18 6:20 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
non zero vbase elements in the array, since the allocation is done for
nr_chips + 1.
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 | 2 +-
arch/powerpc/platforms/powernv/opal-imc.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 4f34c75..d1009fe 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -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;
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index 58a0794..3d27f02 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -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;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init
2018-12-18 6:20 [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init Anju T Sudhakar
@ 2018-12-19 5:53 ` Madhavan Srinivasan
2019-05-03 6:59 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Madhavan Srinivasan @ 2018-12-19 5:53 UTC (permalink / raw)
To: Anju T Sudhakar, mpe; +Cc: linuxppc-dev, dan.carpenter
On 18/12/18 11:50 AM, Anju T Sudhakar wrote:
> 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.
Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
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.
> 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 | 2 +-
> arch/powerpc/platforms/powernv/opal-imc.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
> index 4f34c75..d1009fe 100644
> --- a/arch/powerpc/perf/imc-pmu.c
> +++ b/arch/powerpc/perf/imc-pmu.c
> @@ -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;
> diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
> index 58a0794..3d27f02 100644
> --- a/arch/powerpc/platforms/powernv/opal-imc.c
> +++ b/arch/powerpc/platforms/powernv/opal-imc.c
> @@ -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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init
2018-12-18 6:20 [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init Anju T Sudhakar
2018-12-19 5:53 ` Madhavan Srinivasan
@ 2019-05-03 6:59 ` Michael Ellerman
1 sibling, 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-12-18 at 06:20:41 UTC, Anju T Sudhakar wrote:
> 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.
>
> 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>
> Reviewed-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/860b7d2286236170a36f94946d03ca98
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-03 7:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-18 6:20 [PATCH v2] powerpc/perf: Fix loop exit condition in nest_imc_event_init Anju T Sudhakar
2018-12-19 5:53 ` Madhavan Srinivasan
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).