drm/xe/pm: fix unbalanced ref handling
Subsystems (2)
PATCH v2 1/1 drm/xe/pm: fix unbalanced ref handling
In local_pci_probe() the core kernel increments the rpm for the device, just before calling into the probe hook. If the driver/device supports runtime pm it is then meant to put this ref during probe (like we do in xe_pm_runtime_init()). However when removing the device we then also need to take the reference back, otherwise the ref that is put in pci_device_remove() will be unbalanced when for example unloading the driver, leading to warnings like:
[ 3808.596345] xe 0000:03:00.0: Runtime PM usage count underflow!
Fix this by incrementing the rpm ref when removing the device.
v2:
- Improve the terminology in the commit message; s/drop/put/ etc (Lucas & Rodrigo)
- Also call pm_runtime_forbid(dev) (Rodrigo)
--- drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_pm.c | 8 ++++++++ drivers/gpu/drm/xe/xe_pm.h | 1 + 3 files changed, 10 insertions(+)
drivers/gpu/drm/xe/xe_pci.c +1 -0
@@ -441,6 +441,7 @@ static void xe_pci_remove(struct pci_dev *pdev)return ;xe_device_remove (xe); +xe_pm_runtime_fini (xe);pci_set_drvdata (pdev,NULL ); }
drivers/gpu/drm/xe/xe_pm.c +8 -0
@@ -128,6 +128,14 @@ void xe_pm_runtime_init(struct xe_device *xe)pm_runtime_put_autosuspend (dev); } +void xe_pm_runtime_fini (struct xe_device *xe) +{ +struct device *dev = xe->drm.dev; + +pm_runtime_get_sync (dev); +pm_runtime_forbid (dev); +} +int xe_pm_runtime_suspend (struct xe_device *xe) {struct xe_gt *gt;
drivers/gpu/drm/xe/xe_pm.h +1 -0
@@ -14,6 +14,7 @@ int xe_pm_suspend(struct xe_device *xe);int xe_pm_resume (struct xe_device *xe);void xe_pm_runtime_init (struct xe_device *xe); +void xe_pm_runtime_fini (struct xe_device *xe);int xe_pm_runtime_suspend (struct xe_device *xe);int xe_pm_runtime_resume (struct xe_device *xe);int xe_pm_runtime_get (struct xe_device *xe);
Signature · 1 line
2.39.1
Quoted 16 lines · Matthew Auld
In
local_pci_probe()the core kernel increments the rpm for the device, just before calling into the probe hook. If the driver/device supports runtime pm it is then meant to put this ref during probe (like we do inxe_pm_runtime_init()). However when removing the device we then also need to take the reference back, otherwise the ref that is put inpci_device_remove()will be unbalanced when for example unloading the driver, leading to warnings like:[ 3808.596345] xe 0000:03:00.0: Runtime PM usage count underflow!Fix this by incrementing the rpm ref when removing the device.
v2:
- Improve the terminology in the commit message; s/drop/put/ etc (Lucas & Rodrigo)
- Also callpm_runtime_forbid(dev)(Rodrigo)
Quoted 5 lines
Signed-off-by Matthew Auld <[email protected]>Cc Lucas De Marchi <[email protected]>Cc Rodrigo Vivi <[email protected]>Reviewed-by Rodrigo Vivi <[email protected]>
Lucas De Marchi
Quoted 52 lines
---
drivers/gpu/drm/xe/xe_pci.c | 1 + drivers/gpu/drm/xe/xe_pm.c | 8 ++++++++ drivers/gpu/drm/xe/xe_pm.h | 1 + 3 files changed, 10 insertions(+)drivers/gpu/drm/xe/xe_pci.c +1
-0@@ -441,6 +441,7 @@ static void xe_pci_remove(struct pci_dev *pdev)return ;xe_device_remove (xe); +xe_pm_runtime_fini (xe);pci_set_drvdata (pdev,NULL ); }drivers/gpu/drm/xe/xe_pm.c +8
-0@@ -128,6 +128,14 @@ void xe_pm_runtime_init(struct xe_device *xe)pm_runtime_put_autosuspend (dev); } +void xe_pm_runtime_fini (struct xe_device *xe) +{ +struct device *dev = xe->drm.dev; + +pm_runtime_get_sync (dev); +pm_runtime_forbid (dev); +} +int xe_pm_runtime_suspend (struct xe_device *xe) {struct xe_gt *gt;drivers/gpu/drm/xe/xe_pm.h +1
-0@@ -14,6 +14,7 @@ int xe_pm_suspend(struct xe_device *xe);int xe_pm_resume (struct xe_device *xe);void xe_pm_runtime_init (struct xe_device *xe); +void xe_pm_runtime_fini (struct xe_device *xe);int xe_pm_runtime_suspend (struct xe_device *xe);int xe_pm_runtime_resume (struct xe_device *xe);int xe_pm_runtime_get (struct xe_device *xe);Signature · 1 line
2.39.1