Skip to content

Commit

Permalink
drm/xe/pm: fix unbalanced ref handling
Browse files Browse the repository at this point in the history
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)

Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/193
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
  • Loading branch information
Matthew Auld authored and Rodrigo Vivi committed Dec 19, 2023
1 parent 84ff550 commit 5b7e50e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/xe/xe_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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);
}

Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/xe/xe_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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;
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/xe/xe_pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5b7e50e

Please sign in to comment.