* [PATCH 0/2] perf/smmuv3: Add runtime PM support
@ 2026-11-18 10:19 Amita Mishra
2026-11-18 10:19 ` [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains Amita Mishra
2026-11-18 10:19 ` [PATCH 2/2] perf/smmuv3: Add runtime PM support Amita Mishra
0 siblings, 2 replies; 4+ messages in thread
From: Amita Mishra @ 2026-11-18 10:19 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Robin Murphy, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
amitamishra
On some SoCs, SMMUv3 Performance Monitor Counter Groups (PMCGs) reside
in switchable subsystem power domains rather than an always-on domain.
Currently, when such a PMCG is probed, the power domain is attached and
powered on, and remains powered on indefinitely even when no perf events
are active.
This series adds runtime power management support for SMMUv3 PMCG
devices that are attached to a PM domain:
- Patch 1 documents the optional power-domains property in the
arm,smmu-v3-pmcg devicetree binding.
- Patch 2 adds runtime PM support to the arm_smmuv3_pmu driver, keeping
the PMCG powered only while probe or at least one perf event is
active, and guarding post-event perf context and shared IRQ callbacks
against accessing registers of a suspended PMCG.
Amita Mishra (2):
dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains
perf/smmuv3: Add runtime PM support
.../bindings/perf/arm,smmu-v3-pmcg.yaml | 3 +
drivers/perf/arm_smmuv3_pmu.c | 134 +++++++++++++++---
2 files changed, 118 insertions(+), 19 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.56.1.703.gf848ed807c-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains
2026-11-18 10:19 [PATCH 0/2] perf/smmuv3: Add runtime PM support Amita Mishra
@ 2026-11-18 10:19 ` Amita Mishra
2026-11-18 10:19 ` [PATCH 2/2] perf/smmuv3: Add runtime PM support Amita Mishra
1 sibling, 0 replies; 4+ messages in thread
From: Amita Mishra @ 2026-11-18 10:19 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Robin Murphy, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
amitamishra
On some SoCs, SMMUv3 Performance Monitor Counter Groups (PMCGs) reside
in switchable power domains rather than an always-on domain.
Document the optional power-domains property so that runtime power
management can manage the PMCG power state.
Signed-off-by: Amita Mishra <amitamishra@google.com>
---
Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml b/Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml
index a4b53a6a1ebf..aea6623bb98c 100644
--- a/Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml
+++ b/Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml
@@ -36,6 +36,9 @@ properties:
msi-parent: true
+ power-domains:
+ maxItems: 1
+
required:
- compatible
- reg
--
2.56.1.703.gf848ed807c-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] perf/smmuv3: Add runtime PM support
2026-11-18 10:19 [PATCH 0/2] perf/smmuv3: Add runtime PM support Amita Mishra
2026-11-18 10:19 ` [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains Amita Mishra
@ 2026-11-18 10:19 ` Amita Mishra
2026-11-18 10:44 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Amita Mishra @ 2026-11-18 10:19 UTC (permalink / raw)
To: Will Deacon, Mark Rutland, Robin Murphy, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: linux-arm-kernel, linux-perf-users, devicetree, linux-kernel,
amitamishra
On SoCs where an SMMUv3 PMCG resides in a switchable power domain,
probing the PMCG attaches and powers on the domain, but without runtime
PM support the domain remains permanently powered on even when no perf
events are active.
Add runtime PM support for PMCG devices attached to a PM domain:
- Enable runtime PM while holding a reference before setting up the IRQ
and registering the PMU, then drop the reference once probe completes
so an idle PMCG can suspend.
- Resume and hold a runtime PM reference in smmu_pmu_event_init() for
each active event and release it in event->destroy().
- Register runtime PM callbacks to disable the PMU on suspend and reset
it on resume.
- Guard smmu_pmu_enable(), smmu_pmu_disable(), and smmu_pmu_handle_irq()
with smmu_pmu_in_use() because perf_ctx_enable()/perf_ctx_disable()
and shared or late IRQs can still run after the last event is removed
and the PMCG is powered off. Keep unconditional register disable in
__smmu_pmu_disable() for reset, runtime suspend, and active shutdown.
Signed-off-by: Amita Mishra <amitamishra@google.com>
---
drivers/perf/arm_smmuv3_pmu.c | 134 +++++++++++++++++++++++++++++-----
1 file changed, 115 insertions(+), 19 deletions(-)
diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index 97440b6233c6..e9da99b4a086 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -50,6 +50,7 @@
#include <linux/of.h>
#include <linux/perf_event.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/smp.h>
#include <linux/sysfs.h>
#include <linux/types.h>
@@ -151,15 +152,33 @@ SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_stream_id, config1, 0, 31);
SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_span, config1, 32, 32);
SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_enable, config1, 33, 33);
-static inline void smmu_pmu_enable(struct pmu *pmu)
+static inline void __smmu_pmu_enable(struct smmu_pmu *smmu_pmu)
{
- struct smmu_pmu *smmu_pmu = to_smmu_pmu(pmu);
-
writel(SMMU_PMCG_IRQ_CTRL_IRQEN,
smmu_pmu->reg_base + SMMU_PMCG_IRQ_CTRL);
writel(SMMU_PMCG_CR_ENABLE, smmu_pmu->reg_base + SMMU_PMCG_CR);
}
+/*
+ * perf keeps calling ->pmu_enable()/->pmu_disable() for a PMU in a CPU context
+ * after its last event there is gone, and a shared or late interrupt can call
+ * the IRQ handler. Without counters in use, no event holds a runtime PM
+ * reference and the PMCG may be powered off, so its registers must not be
+ * touched. used_counters only changes in ->add()/->del() on the event's CPU.
+ */
+static inline bool smmu_pmu_in_use(struct smmu_pmu *smmu_pmu)
+{
+ return !bitmap_empty(smmu_pmu->used_counters, smmu_pmu->num_counters);
+}
+
+static inline void smmu_pmu_enable(struct pmu *pmu)
+{
+ struct smmu_pmu *smmu_pmu = to_smmu_pmu(pmu);
+
+ if (smmu_pmu_in_use(smmu_pmu))
+ __smmu_pmu_enable(smmu_pmu);
+}
+
static int smmu_pmu_apply_event_filter(struct smmu_pmu *smmu_pmu,
struct perf_event *event, int idx);
@@ -174,12 +193,18 @@ static inline void smmu_pmu_enable_quirk_hip08_09(struct pmu *pmu)
smmu_pmu_enable(pmu);
}
+static inline void __smmu_pmu_disable(struct smmu_pmu *smmu_pmu)
+{
+ writel(0, smmu_pmu->reg_base + SMMU_PMCG_CR);
+ writel(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CTRL);
+}
+
static inline void smmu_pmu_disable(struct pmu *pmu)
{
struct smmu_pmu *smmu_pmu = to_smmu_pmu(pmu);
- writel(0, smmu_pmu->reg_base + SMMU_PMCG_CR);
- writel(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CTRL);
+ if (smmu_pmu_in_use(smmu_pmu))
+ __smmu_pmu_disable(smmu_pmu);
}
static inline void smmu_pmu_disable_quirk_hip08_09(struct pmu *pmu)
@@ -392,6 +417,14 @@ static bool smmu_pmu_events_compatible(struct perf_event *curr,
* the core perf events code.
*/
+static void smmu_pmu_event_destroy(struct perf_event *event)
+{
+ struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu);
+
+ /* Only set when smmu_pmu_event_init() took a reference. */
+ pm_runtime_put(smmu_pmu->dev);
+}
+
static int smmu_pmu_event_init(struct perf_event *event)
{
struct hw_perf_event *hwc = &event->hw;
@@ -439,18 +472,26 @@ static int smmu_pmu_event_init(struct perf_event *event)
hwc->idx = -1;
- if (event->group_leader == event)
- return 0;
+ if (event->group_leader != event) {
+ for_each_sibling_event(sibling, event->group_leader) {
+ if (is_software_event(sibling))
+ continue;
- for_each_sibling_event(sibling, event->group_leader) {
- if (is_software_event(sibling))
- continue;
+ if (!smmu_pmu_events_compatible(sibling, event))
+ return -EINVAL;
- if (!smmu_pmu_events_compatible(sibling, event))
- return -EINVAL;
+ if (++group_num_events > smmu_pmu->num_counters)
+ return -EINVAL;
+ }
+ }
- if (++group_num_events > smmu_pmu->num_counters)
- return -EINVAL;
+ /* The same condition smmu_pmu_probe() enables runtime PM on. */
+ if (dev->pm_domain) {
+ int ret = pm_runtime_resume_and_get(dev);
+
+ if (ret < 0)
+ return ret;
+ event->destroy = smmu_pmu_event_destroy;
}
return 0;
@@ -692,6 +733,9 @@ static irqreturn_t smmu_pmu_handle_irq(int irq_num, void *data)
u64 ovsr;
unsigned int idx;
+ if (!smmu_pmu_in_use(smmu_pmu))
+ return IRQ_NONE;
+
ovsr = readq(smmu_pmu->reloc_base + SMMU_PMCG_OVSSET0);
if (!ovsr)
return IRQ_NONE;
@@ -779,7 +823,7 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)
{
u64 counter_present_mask = GENMASK_ULL(smmu_pmu->num_counters - 1, 0);
- smmu_pmu_disable(&smmu_pmu->pmu);
+ __smmu_pmu_disable(smmu_pmu);
/* Disable counter and interrupt */
writeq_relaxed(counter_present_mask,
@@ -910,10 +954,21 @@ static int smmu_pmu_probe(struct platform_device *pdev)
smmu_pmu_reset(smmu_pmu);
+ /*
+ * Runtime PM must be enabled before the IRQ handler and the PMU go
+ * live: from then on ->event_init() takes a reference for each event.
+ * Hold one until probe is done.
+ */
+ if (dev->pm_domain) {
+ pm_runtime_get_noresume(dev);
+ pm_runtime_set_active(dev);
+ pm_runtime_enable(dev);
+ }
+
err = smmu_pmu_setup_irq(smmu_pmu);
if (err) {
dev_err(dev, "Setup irq failed, PMU @%pa\n", &res_0->start);
- return err;
+ goto out_rpm;
}
smmu_pmu_get_iidr(smmu_pmu);
@@ -922,7 +977,8 @@ static int smmu_pmu_probe(struct platform_device *pdev)
(res_0->start) >> SMMU_PMCG_PA_SHIFT);
if (!name) {
dev_err(dev, "Create name failed, PMU @%pa\n", &res_0->start);
- return -EINVAL;
+ err = -EINVAL;
+ goto out_rpm;
}
if (!dev->of_node)
@@ -947,7 +1003,7 @@ static int smmu_pmu_probe(struct platform_device *pdev)
if (err) {
dev_err(dev, "Error %d registering hotplug, PMU @%pa\n",
err, &res_0->start);
- return err;
+ goto out_rpm;
}
err = perf_pmu_register(&smmu_pmu->pmu, name, -1);
@@ -962,10 +1018,19 @@ static int smmu_pmu_probe(struct platform_device *pdev)
smmu_pmu->global_filter ? "Global(Counter0)" :
"Individual");
+ if (dev->pm_domain)
+ pm_runtime_put_sync(dev);
+
return 0;
out_unregister:
cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node);
+out_rpm:
+ if (dev->pm_domain) {
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_put_noidle(dev);
+ }
return err;
}
@@ -975,15 +1040,45 @@ static void smmu_pmu_remove(struct platform_device *pdev)
perf_pmu_unregister(&smmu_pmu->pmu);
cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node);
+ if (pdev->dev.pm_domain)
+ pm_runtime_disable(&pdev->dev);
}
static void smmu_pmu_shutdown(struct platform_device *pdev)
{
struct smmu_pmu *smmu_pmu = platform_get_drvdata(pdev);
- smmu_pmu_disable(&smmu_pmu->pmu);
+ if (pdev->dev.pm_domain) {
+ if (pm_runtime_get_if_active(&pdev->dev) <= 0)
+ return;
+ __smmu_pmu_disable(smmu_pmu);
+ pm_runtime_put(&pdev->dev);
+ return;
+ }
+
+ __smmu_pmu_disable(smmu_pmu);
+}
+
+static int smmu_pmu_runtime_suspend(struct device *dev)
+{
+ struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
+
+ __smmu_pmu_disable(smmu_pmu);
+ return 0;
}
+static int smmu_pmu_runtime_resume(struct device *dev)
+{
+ struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
+
+ smmu_pmu_reset(smmu_pmu);
+ return 0;
+}
+
+static const struct dev_pm_ops smmu_pmu_pm_ops = {
+ RUNTIME_PM_OPS(smmu_pmu_runtime_suspend, smmu_pmu_runtime_resume, NULL)
+};
+
#ifdef CONFIG_OF
static const struct of_device_id smmu_pmu_of_match[] = {
{ .compatible = "arm,smmu-v3-pmcg" },
@@ -996,6 +1091,7 @@ static struct platform_driver smmu_pmu_driver = {
.driver = {
.name = "arm-smmu-v3-pmcg",
.of_match_table = of_match_ptr(smmu_pmu_of_match),
+ .pm = pm_ptr(&smmu_pmu_pm_ops),
.suppress_bind_attrs = true,
},
.probe = smmu_pmu_probe,
--
2.56.1.703.gf848ed807c-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] perf/smmuv3: Add runtime PM support
2026-11-18 10:19 ` [PATCH 2/2] perf/smmuv3: Add runtime PM support Amita Mishra
@ 2026-11-18 10:44 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-18 10:44 UTC (permalink / raw)
To: Amita Mishra; +Cc: linux-perf-users, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] perf/smmuv3: missing MSI register restore in
smmu_pmu_runtime_resume()
- [High] perf/smmuv3: unpowered MMIO writes in smmu_pmu_write_msi_msg()
--
commit 3367ecb885d7f9e9f0717d0698079ca0810697a6
Author: Amita Mishra <amitamishra@google.com>
perf/smmuv3: Add runtime PM support
This commit adds runtime PM support for SMMUv3 PMCG devices attached to a
power domain so that idle PMCGs can be powered off when no perf events are
active.
> diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
> index 97440b6233c6e..e9da99b4a0866 100644
> --- a/drivers/perf/arm_smmuv3_pmu.c
> +++ b/drivers/perf/arm_smmuv3_pmu.c
[ ... ]
> @@ -975,15 +1040,45 @@ static void smmu_pmu_remove(struct platform_device *pdev)
>
> perf_pmu_unregister(&smmu_pmu->pmu);
> cpuhp_state_remove_instance_nocalls(cpuhp_state_num, &smmu_pmu->node);
> + if (pdev->dev.pm_domain)
> + pm_runtime_disable(&pdev->dev);
> }
[Severity: High]
Can tearing down or retargeting the MSI while the PMCG is runtime-suspended
write to SMMU_PMCG_IRQ_CFG0, SMMU_PMCG_IRQ_CFG1, and SMMU_PMCG_IRQ_CFG2
while the power domain is off?
When the driver is unbound with no active events, __device_release_driver()
leaves the device runtime-suspended and smmu_pmu_remove() disables runtime
PM. devres_release_all() then frees the devm_request_irq() handler via
free_irq() -> irq_domain_deactivate_irq() -> msi_domain_deactivate() ->
smmu_pmu_write_msi_msg(), which writes to the unpowered PMCG registers and
triggers an external abort or SError. The same unpowered write happens if
smmu_pmu->on_cpu is offlined while suspended and smmu_pmu_offline_cpu()
calls irq_set_affinity() -> msi_domain_set_affinity() ->
smmu_pmu_write_msi_msg().
>
> static void smmu_pmu_shutdown(struct platform_device *pdev)
> {
> struct smmu_pmu *smmu_pmu = platform_get_drvdata(pdev);
>
> - smmu_pmu_disable(&smmu_pmu->pmu);
> + if (pdev->dev.pm_domain) {
> + if (pm_runtime_get_if_active(&pdev->dev) <= 0)
> + return;
> + __smmu_pmu_disable(smmu_pmu);
> + pm_runtime_put(&pdev->dev);
> + return;
> + }
> +
> + __smmu_pmu_disable(smmu_pmu);
> }
>
> +static int smmu_pmu_runtime_suspend(struct device *dev)
> +{
> + struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
> +
> + __smmu_pmu_disable(smmu_pmu);
> + return 0;
> +}
>
> +static int smmu_pmu_runtime_resume(struct device *dev)
> +{
> + struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
> +
> + smmu_pmu_reset(smmu_pmu);
> + return 0;
> +}
[Severity: High]
Does smmu_pmu_runtime_resume() lose the MSI configuration programmed in
SMMU_PMCG_IRQ_CFG0, SMMU_PMCG_IRQ_CFG1, and SMMU_PMCG_IRQ_CFG2 when the
power domain is powered off and back on?
During probe, smmu_pmu_setup_irq() clears SMMU_PMCG_IRQ_CFG0 and
devm_request_irq() activates the MSI via smmu_pmu_write_msi_msg(), before
pm_runtime_put_sync() at the end of smmu_pmu_probe() suspends the device
and drops power to those registers:
drivers/perf/arm_smmuv3_pmu.c:smmu_pmu_write_msi_msg() {
...
writeq_relaxed(doorbell, pmu->reg_base + SMMU_PMCG_IRQ_CFG0);
writel_relaxed(msg->data, pmu->reg_base + SMMU_PMCG_IRQ_CFG1);
writel_relaxed(MSI_CFG2_MEMATTR_DEVICE_nGnRE,
pmu->reg_base + SMMU_PMCG_IRQ_CFG2);
}
When smmu_pmu_event_init() later resumes the device,
smmu_pmu_runtime_resume() only calls smmu_pmu_reset(), leaving the MSI
registers unprogrammed (or leaving SMMU_PMCG_IRQ_CFG0 at its UNKNOWN reset
value when wired interrupts are used on an MSI-capable PMCG) so counter
overflow interrupts do not work.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118101913.3135869-1-amitamishra@google.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 10:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 10:19 [PATCH 0/2] perf/smmuv3: Add runtime PM support Amita Mishra
2026-11-18 10:19 ` [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains Amita Mishra
2026-11-18 10:19 ` [PATCH 2/2] perf/smmuv3: Add runtime PM support Amita Mishra
2026-11-18 10:44 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox