linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup
@ 2020-01-14 20:25 Leonard Crestez
  2020-01-15  1:36 ` Joakim Zhang
  2020-01-15 12:49 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Leonard Crestez @ 2020-01-14 20:25 UTC (permalink / raw)
  To: Joakim Zhang, Will Deacon
  Cc: Frank Li, Mark Rutland, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel

This driver allocates a dynamic cpu hotplug state but never releases it.
If reloaded in a loop it will quickly trigger a WARN message:

	"No more dynamic states available for CPU hotplug"

Fix by calling cpuhp_remove_multi_state on remove like several other
perf pmu drivers.

Also fix the cleanup logic on probe error paths: add the missing
cpuhp_remove_multi_state call and properly check the return value from
cpuhp_state_add_instant_nocalls.

Fixes: 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance counter support to perf")
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>

---

Changes since v1:
* Handle cpuhp_state_add_instant_nocalls error with additional error
labels.
Link to v1: https://patchwork.kernel.org/patch/11302423/
---
 drivers/perf/fsl_imx8_ddr_perf.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c
index 3be61be1ba91..f144f1fd9b4d 100644
--- a/drivers/perf/fsl_imx8_ddr_perf.c
+++ b/drivers/perf/fsl_imx8_ddr_perf.c
@@ -631,17 +631,21 @@ static int ddr_perf_probe(struct platform_device *pdev)
 				      NULL,
 				      ddr_perf_offline_cpu);
 
 	if (ret < 0) {
 		dev_err(&pdev->dev, "cpuhp_setup_state_multi failed\n");
-		goto ddr_perf_err;
+		goto cpuhp_state_err;
 	}
 
 	pmu->cpuhp_state = ret;
 
 	/* Register the pmu instance for cpu hotplug */
-	cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+	ret = cpuhp_state_add_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+	if (ret) {
+		dev_err(&pdev->dev, "Error %d registering hotplug\n", ret);
+		goto cpuhp_instance_err;
+	}
 
 	/* Request irq */
 	irq = of_irq_get(np, 0);
 	if (irq < 0) {
 		dev_err(&pdev->dev, "Failed to get irq: %d", irq);
@@ -672,23 +676,25 @@ static int ddr_perf_probe(struct platform_device *pdev)
 		goto ddr_perf_err;
 
 	return 0;
 
 ddr_perf_err:
-	if (pmu->cpuhp_state)
-		cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
-
+	cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+cpuhp_instance_err:
+	cpuhp_remove_multi_state(pmu->cpuhp_state);
+cpuhp_state_err:
 	ida_simple_remove(&ddr_ida, pmu->id);
 	dev_warn(&pdev->dev, "i.MX8 DDR Perf PMU failed (%d), disabled\n", ret);
 	return ret;
 }
 
 static int ddr_perf_remove(struct platform_device *pdev)
 {
 	struct ddr_pmu *pmu = platform_get_drvdata(pdev);
 
 	cpuhp_state_remove_instance_nocalls(pmu->cpuhp_state, &pmu->node);
+	cpuhp_remove_multi_state(pmu->cpuhp_state);
 	irq_set_affinity_hint(pmu->irq, NULL);
 
 	perf_pmu_unregister(&pmu->pmu);
 
 	ida_simple_remove(&ddr_ida, pmu->id);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup
  2020-01-14 20:25 [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup Leonard Crestez
@ 2020-01-15  1:36 ` Joakim Zhang
  2020-01-15 12:49 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Joakim Zhang @ 2020-01-15  1:36 UTC (permalink / raw)
  To: Leonard Crestez, Will Deacon
  Cc: Frank Li, Mark Rutland, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel


> -----Original Message-----
> From: Leonard Crestez <leonard.crestez@nxp.com>
> Sent: 2020年1月15日 4:26
> To: Joakim Zhang <qiangqing.zhang@nxp.com>; Will Deacon <will@kernel.org>
> Cc: Frank Li <frank.li@nxp.com>; Mark Rutland <mark.rutland@arm.com>;
> Peter Zijlstra <peterz@infradead.org>; Ingo Molnar <mingo@redhat.com>;
> Arnaldo Carvalho de Melo <acme@kernel.org>; Alexander Shishkin
> <alexander.shishkin@linux.intel.com>; Jiri Olsa <jolsa@redhat.com>;
> Namhyung Kim <namhyung@kernel.org>; linux-kernel@vger.kernel.org
> Subject: [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup
> 
> This driver allocates a dynamic cpu hotplug state but never releases it.
> If reloaded in a loop it will quickly trigger a WARN message:
> 
> 	"No more dynamic states available for CPU hotplug"
> 
> Fix by calling cpuhp_remove_multi_state on remove like several other perf pmu
> drivers.
> 
> Also fix the cleanup logic on probe error paths: add the missing
> cpuhp_remove_multi_state call and properly check the return value from
> cpuhp_state_add_instant_nocalls.
> 
> Fixes: 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance counter
> support to perf")
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Acked-by: Joakim Zhang <qiangqing.zhang@nxp.com>

Best Regards,
Joakim Zhang

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup
  2020-01-14 20:25 [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup Leonard Crestez
  2020-01-15  1:36 ` Joakim Zhang
@ 2020-01-15 12:49 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2020-01-15 12:49 UTC (permalink / raw)
  To: Leonard Crestez
  Cc: Joakim Zhang, Frank Li, Mark Rutland, Peter Zijlstra,
	Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-kernel

On Tue, Jan 14, 2020 at 10:25:46PM +0200, Leonard Crestez wrote:
> This driver allocates a dynamic cpu hotplug state but never releases it.
> If reloaded in a loop it will quickly trigger a WARN message:
> 
> 	"No more dynamic states available for CPU hotplug"
> 
> Fix by calling cpuhp_remove_multi_state on remove like several other
> perf pmu drivers.
> 
> Also fix the cleanup logic on probe error paths: add the missing
> cpuhp_remove_multi_state call and properly check the return value from
> cpuhp_state_add_instant_nocalls.
> 
> Fixes: 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance counter support to perf")
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
> 
> ---
> 
> Changes since v1:
> * Handle cpuhp_state_add_instant_nocalls error with additional error
> labels.
> Link to v1: https://patchwork.kernel.org/patch/11302423/
> ---
>  drivers/perf/fsl_imx8_ddr_perf.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)

Thanks, I've queued this up with Joakim's ack.

Will

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-15 12:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 20:25 [PATCH v2] perf/imx_ddr: Fix cpu hotplug state cleanup Leonard Crestez
2020-01-15  1:36 ` Joakim Zhang
2020-01-15 12:49 ` Will Deacon

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).