From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51B22606A333 for ; Mon, 23 Nov 2026 16:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=LNhH4eY3; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=g8wz0s2s DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=ampCWU9YaRxYyU/2VqzGl7j5fZT5bJdrecIR7kU5Uc4=; b=LNhH4eY3lGh4RdB38+eSvaSZGY Lx5sxJFzX4uhW2S44YNifNm9sVMpGZ+sNig+fKhL13XL8yZRw/Wxjp4CWwMYfuFvIvMKPMmxez22D PSzD6P9pU6BYvtrWHuJxgDFPVSl3Oj5E/HAMJSdWBNifJQL5dO+CDmf+LKxB4xuMdzh33d2SvSe2O agOvOyqFM1YRa2uRNAiDnnTYd08PMk7QMZ0iZD32pGIFLFvYHbkRN2xZkLKV7mI/1/6+lPaTRCltc nHrdkN3zlWMyVsZstdK/dV4mfOUt2MnkYiRkgiZ+y4ykpflrxljVj9fH5azCb+m/twcqddsQW2dZU PT7MBp5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVWIh-000000044kf-0s4m; Mon, 23 Nov 2026 15:49:51 +0000 Received: from mail-pg1-x548.google.com ([2607:f8b0:4864:20::548]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVWIf-000000044k8-08Hs for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2026 15:49:50 +0000 Received: by mail-pg1-x548.google.com with SMTP id 41be03b00d2f7-cde9044a96aso797962a12.3 for ; Mon, 23 Nov 2026 07:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795448987; x=1796053787; darn=lists.infradead.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ampCWU9YaRxYyU/2VqzGl7j5fZT5bJdrecIR7kU5Uc4=; b=g8wz0s2sdJXLh31uhibtdSRsziLdqaZ02mM1sCvUWZCfnamYwtDqy0suHwPoKaUjLR SSNtenZnYbzNUXBJ0/D0zzg5PEqJaYo9IIKr+NDZAty60VrIsWtdONH1eCNYRabt+J4+ 1DPuvELvl8UEc46z/hfZc1wFth861i9Pl/A1stn2MGKuv+zSCRYD4nWoPjlLo19z1x45 XD4g6o1X5qmhdyEyuI7u2TZrA3n8rarecDHsfPinLh+OXaZ4kN7C4Q0fKVaMgVk2gjMJ +THTzG+yuBphfy4SPpDfW/EVqdVavCC6IVYwlKQbGbm9PVFFvcxYibbtV0yVdzB9trW+ KXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795448987; x=1796053787; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ampCWU9YaRxYyU/2VqzGl7j5fZT5bJdrecIR7kU5Uc4=; b=dZwCYG4iJAalNhfE89dep0UVlabx6gjURAu5Aqwx8Dj3S1AisW2f8P4pr+gfifQK/U 6nEbpahN4ashAAKJjqfLpGocA4sc6KI42NMoFnQ/dQG8EtEnbAtyApD+HkgY3NDhEnRp aAzuavNIcyimEyyI0K3l3yzdbxv0kJKpt/n+JVPtBFjllkstJ9eEZyc1GO2Uty7Wrd4r IDQq9gGkrrSmkqwJ5qDxA0BFhNcpEtaqyn/IZ/RzbTM5VrEi0whrFIR5ZLpbUl9hxG26 Ed3EJ0MGO6r+uWBFZ2H1TKdWTUgFXHk/KFvxgccgb/ZQQwcct3mRZy+eFLwZeMpU25w5 bmHQ== X-Forwarded-Encrypted: i=1; AL+hErGLEaks6NaS4K4jLX9y3qUVNu7x+lbYt3e4IesfdQBUREgLJzCIcvv4Er7xu0BGpezH+hZpWk8qJcfTng2RQG1V@lists.infradead.org X-Gm-Message-State: APuU4Z+TotfAaQPDuedvGvONOS3cAc5d32I/sUXNfxn1g6YyiwkxMS1S SZWEf2RxZQKKS0X4Y5ba28ZBHOjEniguJkGMpLG7E49sgMpAyqRhtcIkM6B32BhKGM6TUzC2Nx+ /ag== X-Received: from pfbfd26.prod.google.com ([2002:a05:6a00:2e9a:b0:8a0:70d8:a2ef]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:218b:b0:3f8:f0b1:e7c0 with SMTP id adf61e73a8af0-4014da5fc3emr11235211637.59.1795448987022; Mon, 23 Nov 2026 07:49:47 -0800 (PST) Date: Mon, 23 Nov 2026 15:49:45 +0000 In-Reply-To: <20261118101913.3135869-3-amitamishra@google.com> X-Archived-By: Mime-Version: 1.0 References: <20261118101913.3135869-3-amitamishra@google.com> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog Message-ID: <20261123154945.3083888-1-praan@google.com> Subject: Re: [PATCH 2/2] perf/smmuv3: Add runtime PM support From: Pranjal Shrivastava To: amitamishra@google.com Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, krzk+dt@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, robh@kernel.org, robin.murphy@arm.com, will@kernel.org, iommu@lists.linux.dev, smostafa@google.com Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261123_074949_103535_43C70AFC X-CRM114-Status: GOOD ( 31.56 ) X-Spam-Score: -9.5 (---------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-21.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Nov 18, 2026 at 10:19:13AM +0000, Amita Mishra wrote: Hi Amita, +iommu@lists.linux.dev Please CC the iommu list as well. > 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). [...] > + /* 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: [...] > @@ -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. [...] > +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/20260929034510.2023173-1-praan@google.com/