Skip to contentSkip to conversation

perf/smmuv3: Add runtime PM support

PATCH In review Amita Mishra 4 participants 9 messages Nov 18 – Nov 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf/smmuv3: Add runtime PM support

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

Signature · 1 line
2.56.1.703.gf848ed807c-goog
#1 lore raw

PATCH 1/2 dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains

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.

---
 Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml +3 -0
index a4b53a6a1ebf..aea6623bb98c 100644
@@ -36,6 +36,9 @@ properties:
 
   msi-parent: true
 
+  power-domains:
+    maxItems: 1
+
 required:
   - compatible
   - reg
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#2 lore raw

Re: [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH 1/2] dt-bindings: perf: arm,smmu-v3-pmcg: Allow power-domains

In reply to Amita Mishra
Quoted 5 lines · Amita Mishra

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.

Isn't power-domain-consumer one of the common schemas that's automatically applicable to any node anyway? I would think that unless we have a specific expectation and description of what each power-domains entry should represent - which we cannot reasonably do in a binding that is for the architectural PMCG interface rather than any specific implementation of such - we'd be better off just leaving it implicit.

Quoted 10 lines
---
  Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml | 3 +++
  1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml +0 -0
index a4b53a6a1ebf..aea6623bb98c 100644

Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml properties: · line 40

Quoted 5 lines
Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml +2 -0
@@ -36,6 +36,9 @@ properties:
 
    msi-parent: true
 
+  power-domains:
+    maxItems: 1

Even for existing implementations it would be quite possible for a PMCG to be functionally dependent on multiple power domains (yes some of them should usually be hierarchical, but still...) - what justifies 1 being the only "correct" number?

Thanks,
Robin.

Quoted 4 lines
Documentation/devicetree/bindings/perf/arm,smmu-v3-pmcg.yaml +1 -0
+
  required:
    - compatible
    - reg
#4 lore raw

PATCH 2/2 perf/smmuv3: Add runtime PM support

In reply to Amita Mishra

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.

---
 drivers/perf/arm_smmuv3_pmu.c | 134 +++++++++++++++++++++++++++++-----
 1 file changed, 115 insertions(+), 19 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +115 -19
index 97440b6233c6..e9da99b4a086 100644
@@ -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,
Signature · 1 line
2.56.1.703.gf848ed807c-goog
#5 lore raw
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…

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 <[email protected]>

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.

Quoted 4 lines
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 97440b6233c6e..e9da99b4a0866 100644

[ ... ]

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1045

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
@@ -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().

Quoted 22 lines
drivers/perf/arm_smmuv3_pmu.c +14 -1
 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);

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev)

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +9 -0
+	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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw
In reply to Amita Mishra

On Wed, Nov 18, 2026 at 10:19:13AM +0000, Amita Mishra wrote:

Hi Amita,

[email protected]
Please CC the iommu list as well.

Quoted 4 lines

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.

I'm interested to know which PMCGs are these? Upstream arm-smmu-v3 doesn't have runtime PM yet, thus, a PMCG that shares its SMMU's power domain gains nothing from this today: the SMMU keeps the domain on anyway

With my arm-smmu-v3 runtime PM series [1], the SMMU lets go of the domain once it has no active clients, and then a PMCG without runtime PM would be the one keeping it on, the two series seem to fit together. For TBU PMCGs in a subsystem's domain this matters either way.

I'm wondering if you have PMCGs in power-domains that are neither tied to the SMMU power-domain and nor it's clients' power-domain? (That'd be a bit odd but possible).

[...]

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_event_init(struct perf_event *event) · line 495

Quoted 8 lines
drivers/perf/arm_smmuv3_pmu.c +7 -0
+    /* 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;
     }

This keeps the domain powered for as long as the event exists, even while it is disabled or not scheduled. I'd be surprised if the production devices that use runtime PM keep a PMCG event open requiring this?

For a PMCG in the SMMU's domain, with [1] that means a perf event keeps the domain on while the SMMU itself is suspended (SMMUEN=0, GBPA=Abort). The SMMU only suspends once all its clients are idle, so apart from cycles there's nothing meaningful to count.

For a TBU PMCG, it keeps the subsystem's domain powered, which changes what's being measured: the TBU's TLBs and config caches survive what would otherwise be power-offs, so tlb_miss and config_cache_miss can under-report compared to the unmonitored system.

Which makes me question whether the PMCG needs runtime PM at all. It's a profiling tool, and I'd be surprised if production devices that use runtime PM keep PMCG events open. Without events nothing needs the PMCG powered, so all this buys is not pinning the domain while the driver is probed but unused..

Do you probe the PMCGs on production devices? If they're only used for profiling and not in-field, not loading the driver there (or leaving the node disabled) avoids the problem without runtime PM in the driver.

If we do need it, a couple of issues with the implementation below:

[...]

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1045

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
@@ -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);
 }

Events hold a module reference and bind/unbind is suppressed, so this only runs with no events, i.e. normally with the PMCG runtime-suspended. devres then frees the IRQ: free_irq() -> msi_domain_deactivate() -> smmu_pmu_write_msi_msg() writes to the unpowered PMCG, since the PM domain is only detached after devres in device_unbind_cleanup(). Wired interrupts are fine, and the CPU hotplug path Sashiko mentioned shouldn't rewrite the message with a GICv3 ITS parent, so in practice this is MSIs plus module unload.

With the MSI message cached by the core (see below), smmu_pmu_write_msi_msg() could simply skip the MMIO while the PMCG is suspended and leave it to resume. Note it would have to check pm_runtime_status_suspended(), since runtime PM is already disabled by the time devres runs. Alternatively, keep the PMCG resumed across the devres teardown.

[...]

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1076

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +7 -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;
+}

Sashiko flagged this too: after a power-off the IRQ configuration is gone, and smmu_pmu_reset() doesn't put it back. With MSIs, overflow interrupts stop arriving and counters wrap unnoticed. With a wired interrupt on an MSI-capable PMCG, IRQ_CFG0 comes back UNKNOWN, so an overflow can send an MSI write to a garbage address, which is exactly why probe clears it.

This is the same problem I had to solve for the SMMU in [1]: patches 7-8 make the genirq/msi core cache the message in irq_chip_write_msi_msg() and add msi_device_domain_restore_msi_msgs(), and arm_smmu_resume_msis() in patch 9 clears the IRQ_CFG0 registers and then calls it (a no-op for wired IRQs). The PMCG resume needs the same:

    writeq_relaxed(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CFG0);
    msi_device_domain_restore_msi_msgs(dev, MSI_DEFAULT_DOMAIN);

Minor: an autosuspend delay would avoid powering the domain on and off for every event open/close.

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/

#7 lore raw

Hi Pranjal,

Thanks for the thorough review and for adding [email protected] -- I'll make sure to include it on v2.

Quoted 10 lines · Pranjal Shrivastava
Quoted 4 lines · Amita Mishra

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.

I'm interested to know which PMCGs are these? Upstream arm-smmu-v3 doesn't have runtime PM yet, thus, a PMCG that shares its SMMU's power domain gains nothing from this today: the SMMU keeps the domain on anyway

Quoted 8 lines

With my arm-smmu-v3 runtime PM series [1], the SMMU lets go of the domain once it has no active clients, and then a PMCG without runtime PM would be the one keeping it on, the two series seem to fit together. For TBU PMCGs in a subsystem's domain this matters either way.

I'm wondering if you have PMCGs in power-domains that are neither tied to the SMMU power-domain and nor it's clients' power-domain? (That'd be a bit odd but possible).

They are the two cases you mentioned -- TBU PMCGs residing in switchable subsystem/client power domains (which already use runtime PM today), and TCU PMCGs sharing the SMMU power domain (which pair with your arm-smmu-v3 runtime PM series). There isn't a separate third power domain.

Quoted 9 lines

Which makes me question whether the PMCG needs runtime PM at all. It's a profiling tool, and I'd be surprised if production devices that use runtime PM keep PMCG events open. Without events nothing needs the PMCG powered, so all this buys is not pinning the domain while the driver is probed but unused..

Do you probe the PMCGs on production devices? If they're only used for profiling and not in-field, not loading the driver there (or leaving the node disabled) avoids the problem without runtime PM in the driver.

Yes -- the same SoC DT and kernel image are used across production and profiling/debug builds, and we want PMCGs available on demand for profiling without maintaining separate DTs or manually toggling drivers/nodes. Today, simply having the node enabled and probed pins the attached subsystem/SMMU power domain on permanently even when no perf events are ever opened, which causes power regressions on idle devices.

On holding the runtime PM reference for the lifetime of an event (event_init -> destroy): fair point about disabled events and the observer effect on TBU TLB/config-cache misses while profiling. Because perf's ->add()/->start()/->pmu_enable() callbacks run in atomic context, taking the reference in ->event_init() and dropping it in ->destroy() (similar to drivers/gpu/drm/xe/xe_pmu.c) was the cleanest way to keep the PMCG powered whenever events exist while allowing idle systems with no open events to power-gate.

Quoted 13 lines

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1045

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
@@ -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);
 }

Events hold a module reference and bind/unbind is suppressed, so this only runs with no events, i.e. normally with the PMCG runtime-suspended. devres then frees the IRQ: free_irq() -> msi_domain_deactivate() -> smmu_pmu_write_msi_msg() writes to the unpowered PMCG, since the PM domain is only detached after devres in device_unbind_cleanup().

[...]

Quoted 10 lines

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1076

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +7 -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;
+}

Sashiko flagged this too: after a power-off the IRQ configuration is gone, and smmu_pmu_reset() doesn't put it back.

[...]

Quoted 5 lines

This is the same problem I had to solve for the SMMU in [1]: patches 7-8 make the genirq/msi core cache the message in irq_chip_write_msi_msg() and add msi_device_domain_restore_msi_msgs(), and arm_smmu_resume_msis() in patch 9 clears the IRQ_CFG0 registers and then calls it (a no-op for wired IRQs).

Agreed on both MSI issues -- I'll fix them in v2. Since msi_device_domain_restore_msi_msgs() isn't in mainline yet, would you prefer that v2 stays standalone by caching the single msi_msg locally in struct smmu_pmu (clearing SMMU_PMCG_IRQ_CFG0 and restoring on resume, and skipping MMIO in smmu_pmu_write_msi_msg() while suspended), or should this wait/build on top of your genirq/msi patches from [1]?

Quoted 2 lines

Minor: an autosuspend delay would avoid powering the domain on and off for every event open/close.

Sounds good, I can add autosuspend support in v2 as well.

Regards,
Amita

Quoted 123 lines · Pranjal Shrivastava

On Wed, Nov 18, 2026 at 10:19:13AM +0000, Amita Mishra wrote:

Hi Amita,

[email protected]
Please CC the iommu list as well.

Quoted 4 lines

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.

I'm interested to know which PMCGs are these? Upstream arm-smmu-v3 doesn't have runtime PM yet, thus, a PMCG that shares its SMMU's power domain gains nothing from this today: the SMMU keeps the domain on anyway

With my arm-smmu-v3 runtime PM series [1], the SMMU lets go of the domain once it has no active clients, and then a PMCG without runtime PM would be the one keeping it on, the two series seem to fit together. For TBU PMCGs in a subsystem's domain this matters either way.

I'm wondering if you have PMCGs in power-domains that are neither tied to the SMMU power-domain and nor it's clients' power-domain? (That'd be a bit odd but possible).

[...]

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_event_init(struct perf_event *event) · line 495

Quoted 8 lines
drivers/perf/arm_smmuv3_pmu.c +7 -0
+    /* 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;
     }

This keeps the domain powered for as long as the event exists, even while it is disabled or not scheduled. I'd be surprised if the production devices that use runtime PM keep a PMCG event open requiring this?

For a PMCG in the SMMU's domain, with [1] that means a perf event keeps the domain on while the SMMU itself is suspended (SMMUEN=0, GBPA=Abort). The SMMU only suspends once all its clients are idle, so apart from cycles there's nothing meaningful to count.

For a TBU PMCG, it keeps the subsystem's domain powered, which changes what's being measured: the TBU's TLBs and config caches survive what would otherwise be power-offs, so tlb_miss and config_cache_miss can under-report compared to the unmonitored system.

Which makes me question whether the PMCG needs runtime PM at all. It's a profiling tool, and I'd be surprised if production devices that use runtime PM keep PMCG events open. Without events nothing needs the PMCG powered, so all this buys is not pinning the domain while the driver is probed but unused..

Do you probe the PMCGs on production devices? If they're only used for profiling and not in-field, not loading the driver there (or leaving the node disabled) avoids the problem without runtime PM in the driver.

If we do need it, a couple of issues with the implementation below:

[...]

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1045

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
@@ -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);
 }

Events hold a module reference and bind/unbind is suppressed, so this only runs with no events, i.e. normally with the PMCG runtime-suspended. devres then frees the IRQ: free_irq() -> msi_domain_deactivate() -> smmu_pmu_write_msi_msg() writes to the unpowered PMCG, since the PM domain is only detached after devres in device_unbind_cleanup(). Wired interrupts are fine, and the CPU hotplug path Sashiko mentioned shouldn't rewrite the message with a GICv3 ITS parent, so in practice this is MSIs plus module unload.

With the MSI message cached by the core (see below), smmu_pmu_write_msi_msg() could simply skip the MMIO while the PMCG is suspended and leave it to resume. Note it would have to check pm_runtime_status_suspended(), since runtime PM is already disabled by the time devres runs. Alternatively, keep the PMCG resumed across the devres teardown.

[...]

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1076

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +7 -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;
+}

Sashiko flagged this too: after a power-off the IRQ configuration is gone, and smmu_pmu_reset() doesn't put it back. With MSIs, overflow interrupts stop arriving and counters wrap unnoticed. With a wired interrupt on an MSI-capable PMCG, IRQ_CFG0 comes back UNKNOWN, so an overflow can send an MSI write to a garbage address, which is exactly why probe clears it.

This is the same problem I had to solve for the SMMU in [1]: patches 7-8 make the genirq/msi core cache the message in irq_chip_write_msi_msg() and add msi_device_domain_restore_msi_msgs(), and arm_smmu_resume_msis() in patch 9 clears the IRQ_CFG0 registers and then calls it (a no-op for wired IRQs). The PMCG resume needs the same:

    writeq_relaxed(0, smmu_pmu->reg_base + SMMU_PMCG_IRQ_CFG0);
    msi_device_domain_restore_msi_msgs(dev, MSI_DEFAULT_DOMAIN);

Minor: an autosuspend delay would avoid powering the domain on and off for every event open/close.

Thanks,
Praan

[1] https://lore.kernel.org/all/[email protected]/

#8 lore raw
In reply to Amita Mishra
Quoted 50 lines · Amita Mishra

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.

---
  drivers/perf/arm_smmuv3_pmu.c | 134 +++++++++++++++++++++++++++++-----
  1 file changed, 115 insertions(+), 19 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +2 -3
index 97440b6233c6..e9da99b4a086 100644
@@ -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);
  }
 

drivers/perf/arm_smmuv3_pmu.c SMMU_PMU_EVENT_ATTR_EXTRACTOR(filter_stream_id, config1, 0, 31); · line 171

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +10 -0
+/*
+ * 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);

This may as well just use SMMU_PMCG_MAX_COUNTERS, so that it can optimise to the trivial constant case. We know we're not going to mark any counters as used which we don't even have in the first place.

Quoted 21 lines
drivers/perf/arm_smmuv3_pmu.c +14 -0
+}
+
+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);

drivers/perf/arm_smmuv3_pmu.c static inline void smmu_pmu_enable_quirk_hip08_09(struct pmu *pmu) · line 207

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +4 -2
+}
+
  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);

...however I can't help but be wary of this somehow getting out of sync such that we might end up scheduling in a group on an initially-empty PMU with CR_ENABLE still set and the events starting to count immediately. Maybe it does work out, but given how convoluted all the possible enable/disable paths in the perf core are already with potential nesting and elision, it seems far from straightforward to reason about :/

drivers/perf/arm_smmuv3_pmu.c static bool smmu_pmu_events_compatible(struct perf_event *curr, · line 425

Quoted 13 lines
drivers/perf/arm_smmuv3_pmu.c +6 -0
  }
 
  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);

In isolation, "Only set" appearing to somehow refer to either the pm_runtime_put() call or its argument makes this comment more confusing than helpful.

Quoted 109 lines
drivers/perf/arm_smmuv3_pmu.c +41 -13
+}
+
  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);
+

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_probe(struct platform_device *pdev) · line 1033

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +6 -0
  	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);
+	}

Can we not just use the devm_ variants for auto-cleanup?

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1044

Quoted 9 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
  	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);

...especially since probe failure vs. driver unbind should not be leaving things in different states, surely?

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +0 -1
  }
 
  static void smmu_pmu_shutdown(struct platform_device *pdev)
  {
  	struct smmu_pmu *smmu_pmu = platform_get_drvdata(pdev);
 
-	smmu_pmu_disable(&smmu_pmu->pmu);

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1060

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +10 -0
+	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);
+}

TBH I'm not sure why there's a shutdown routine here at all - the entire kernel state is about to stop existing, so we really shouldn't need to waste yet more time faffing with RPM accounting. I'd be inclined to just drop the whole thing, to be consistent with pretty much every other PMU driver. Yes, perf core doesn't deschedule events on shutdown either, so at worst after a warm reboot we might find pending overflows, but driver probes should be robust and not make assumptions about the initial state of the hardware anyway (as indeed this one appears to be.)

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1066

Quoted 6 lines
drivers/perf/arm_smmuv3_pmu.c +6 -0
+
+static int smmu_pmu_runtime_suspend(struct device *dev)
+{
+	struct smmu_pmu *smmu_pmu = dev_get_drvdata(dev);
+
+	__smmu_pmu_disable(smmu_pmu);

Similarly, this seems entirely unnecessary - if we can only get here when no events are open, there already cannot be anything worth disabling (i.e. no running counters able to generate unexpected IRQs if the hardware doesn't actually lose state while logically suspended.)

Quoted 4 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
+	return 0;
  }
 
+static int smmu_pmu_runtime_resume(struct device *dev)

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_remove(struct platform_device *pdev) · line 1080

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +10 -0
+{
+	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)
+};

Consider DEFINE_SIMPLE_DEV_PM_OPS() for even more brevity.

Thanks,
Robin.

Quoted 12 lines
drivers/perf/arm_smmuv3_pmu.c +2 -0
+
  #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,