Skip to contentSkip to conversation

bus: mhi: host: pci_generic: Fix runtime PM imbalance for no_m3 devices

PATCH Applied Alexandra Lu 3 participants 4 messages Aug 7 – Sep 26

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

PATCH 1/1 bus: mhi: host: pci_generic: Fix runtime PM imbalance for no_m3 devices

mhi_pci_probe() drops the runtime PM reference taken by local_pci_probe() only when the device supports both PME from D3hot and M3, but mhi_pci_remove() re-takes it based on PME capability alone, without checking no_m3.

For a device that is PME capable and has no_m3 set, probe therefore never drops the reference while remove takes an extra one, leaving the runtime PM usage count one higher after every bind/unbind cycle. That is benign for the device being removed, since the PCI core resumes it to D0 on unbind regardless, but the struct device outlives the binding, so the count accumulates across repeated cycles and can end up preventing runtime suspend altogether.

Cache no_m3 in the driver's private data, as is already done for reset_on_remove, and gate the removal side on it as well. Unlike reset_on_remove it is cached for virtual functions too, because the probe side gate tests info->no_m3 for physical and virtual functions alike.

QDU100 is currently the only device that sets no_m3.

Fixes 0494cf9793b7 ("bus: mhi: host: pci_generic: Disable runtime PM for QDU100")
Assisted-by Cursor:claude-opus-5
---
 drivers/bus/mhi/host/pci_generic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/bus/mhi/host/pci_generic.c +4 -1
index b636e2c23b4d..eda00a2e242c 100644
@@ -1097,6 +1097,7 @@ struct mhi_pci_device {
 	struct work_struct recovery_work;
 	struct timer_list health_check_timer;
 	unsigned long status;
+	bool no_m3;
 	bool reset_on_remove;
 };
 
@@ -1409,6 +1410,8 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	mhi_cntrl->mru = info->mru_default;
 	mhi_cntrl->name = info->name;
 
+	mhi_pdev->no_m3 = info->no_m3;
+
 	if (!pdev->is_virtfn)
 		mhi_pdev->reset_on_remove = info->reset_on_remove;
 
@@ -1497,7 +1500,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
 	}
 
 	/* balancing probe put_noidle */
-	if (pci_pme_capable(pdev, PCI_D3hot))
+	if (pci_pme_capable(pdev, PCI_D3hot) && !mhi_pdev->no_m3)
 		pm_runtime_get_noresume(&pdev->dev);
 
 	if (mhi_pdev->reset_on_remove)
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Alexandra Lu

mhi_pci_probe() drops the runtime PM reference taken by local_pci_probe() only when the device supports both PME from D3hot and M3, but mhi_pci_remove() re-takes it based on PME capability alone, without checking no_m3.

For a device that is PME capable and has no_m3 set, probe therefore never drops the reference while remove takes an extra one, leaving the runtime PM usage count one higher after every bind/unbind cycle. That is benign for the device being removed, since the PCI core resumes it to D0 on unbind regardless, but the struct device outlives the binding, so the count accumulates across repeated cycles and can end up preventing runtime suspend altogether.

Cache no_m3 in the driver's private data, as is already done for reset_on_remove, and gate the removal side on it as well. Unlike reset_on_remove it is cached for virtual functions too, because the probe side gate tests info->no_m3 for physical and virtual functions alike.

Quoted 5 lines

QDU100 is currently the only device that sets no_m3.

Fixes 0494cf9793b7 ("bus: mhi: host: pci_generic: Disable runtime PM for QDU100")
Assisted-by Cursor:claude-opus-5

Seems sane to me.

#2 lore raw
In reply to Alexandra Lu
Quoted 18 lines · Alexandra Lu

mhi_pci_probe() drops the runtime PM reference taken by local_pci_probe() only when the device supports both PME from D3hot and M3, but mhi_pci_remove() re-takes it based on PME capability alone, without checking no_m3.

For a device that is PME capable and has no_m3 set, probe therefore never drops the reference while remove takes an extra one, leaving the runtime PM usage count one higher after every bind/unbind cycle. That is benign for the device being removed, since the PCI core resumes it to D0 on unbind regardless, but the struct device outlives the binding, so the count accumulates across repeated cycles and can end up preventing runtime suspend altogether.

Cache no_m3 in the driver's private data, as is already done for reset_on_remove, and gate the removal side on it as well. Unlike reset_on_remove it is cached for virtual functions too, because the probe side gate tests info->no_m3 for physical and virtual functions alike.

Quoted 5 lines

QDU100 is currently the only device that sets no_m3.

Fixes 0494cf9793b7 ("bus: mhi: host: pci_generic: Disable runtime PM for QDU100")
Assisted-by Cursor:claude-opus-5

LGTM! But since the MHI tree is closed for v7.3, this patch will get applied only when v7.3-rc1 is released.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
maintainer Applied
#3 lore raw
In reply to Alexandra Lu
Quoted 13 lines · Alexandra Lu

mhi_pci_probe() drops the runtime PM reference taken by local_pci_probe() only when the device supports both PME from D3hot and M3, but mhi_pci_remove() re-takes it based on PME capability alone, without checking no_m3.

For a device that is PME capable and has no_m3 set, probe therefore never drops the reference while remove takes an extra one, leaving the runtime PM usage count one higher after every bind/unbind cycle. That is benign for the device being removed, since the PCI core resumes it to D0 on unbind regardless, but the struct device outlives the binding, so the count accumulates across repeated cycles and can end up preventing runtime suspend altogether.

Quoted 1 line

[...]

Applied, thanks!

[1/1] bus: mhi: host: pci_generic: Fix runtime PM imbalance for no_m3 devices

      commit: 95601e9948b42f82600ff2d9e0c2f699a067d561

Best regards,

Signature · 1 line
மணிவண்ணன் சதாசிவம்