Skip to content

Commit c086bfc

Browse files
hghimiralucasdemarchi
authored andcommitted
drm/xe/pm: Capture errors and handle them
xe_pm_init may encounter failures for various reasons, such as a failure in initializing drmm_mutex, or when dealing with a d3cold-capable device for vram_threshold sysfs creation and setting default threshold. Presently, all these potential failures are disregarded. Move d3cold.lock initialization to xe_pm_init_early and cause driver abort if mutex initialization has failed. For xe_pm_init failures cleanup the driver and return error code -v2 Make mutex init cleaner (Lucas) Cc: Lucas De Marchi <[email protected]> Cc: Rodrigo Vivi <[email protected]> Signed-off-by: Himal Prasad Ghimiray <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent e3d0839 commit c086bfc

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

drivers/gpu/drm/xe/xe_device_sysfs.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,14 @@ static void xe_device_sysfs_fini(struct drm_device *drm, void *arg)
7676
sysfs_remove_file(&xe->drm.dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
7777
}
7878

79-
void xe_device_sysfs_init(struct xe_device *xe)
79+
int xe_device_sysfs_init(struct xe_device *xe)
8080
{
8181
struct device *dev = xe->drm.dev;
8282
int ret;
8383

8484
ret = sysfs_create_file(&dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
85-
if (ret) {
86-
drm_warn(&xe->drm, "Failed to create sysfs file\n");
87-
return;
88-
}
89-
90-
ret = drmm_add_action_or_reset(&xe->drm, xe_device_sysfs_fini, xe);
9185
if (ret)
92-
drm_warn(&xe->drm, "Failed to add sysfs fini drm action\n");
86+
return ret;
87+
88+
return drmm_add_action_or_reset(&xe->drm, xe_device_sysfs_fini, xe);
9389
}

drivers/gpu/drm/xe/xe_device_sysfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
struct xe_device;
1010

11-
void xe_device_sysfs_init(struct xe_device *xe);
11+
int xe_device_sysfs_init(struct xe_device *xe);
1212

1313
#endif

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,18 +781,26 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
781781
str_yes_no(xe_device_has_sriov(xe)),
782782
xe_sriov_mode_to_string(xe_device_sriov_mode(xe)));
783783

784-
xe_pm_init_early(xe);
784+
err = xe_pm_init_early(xe);
785+
if (err)
786+
return err;
785787

786788
err = xe_device_probe(xe);
787789
if (err)
788790
return err;
789791

790-
xe_pm_init(xe);
792+
err = xe_pm_init(xe);
793+
if (err)
794+
goto err_driver_cleanup;
791795

792796
drm_dbg(&xe->drm, "d3cold: capable=%s\n",
793797
str_yes_no(xe->d3cold.capable));
794798

795799
return 0;
800+
801+
err_driver_cleanup:
802+
xe_pci_remove(pdev);
803+
return err;
796804
}
797805

798806
static void xe_pci_shutdown(struct pci_dev *pdev)

drivers/gpu/drm/xe/xe_pm.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,34 +214,54 @@ static void xe_pm_runtime_init(struct xe_device *xe)
214214
pm_runtime_put(dev);
215215
}
216216

217-
void xe_pm_init_early(struct xe_device *xe)
217+
int xe_pm_init_early(struct xe_device *xe)
218218
{
219+
int err;
220+
219221
INIT_LIST_HEAD(&xe->mem_access.vram_userfault.list);
220-
drmm_mutex_init(&xe->drm, &xe->mem_access.vram_userfault.lock);
222+
223+
err = drmm_mutex_init(&xe->drm, &xe->mem_access.vram_userfault.lock);
224+
if (err)
225+
return err;
226+
227+
err = drmm_mutex_init(&xe->drm, &xe->d3cold.lock);
228+
if (err)
229+
return err;
230+
231+
return 0;
221232
}
222233

223234
/**
224235
* xe_pm_init - Initialize Xe Power Management
225236
* @xe: xe device instance
226237
*
227238
* This component is responsible for System and Device sleep states.
239+
*
240+
* Returns 0 for success, negative error code otherwise.
228241
*/
229-
void xe_pm_init(struct xe_device *xe)
242+
int xe_pm_init(struct xe_device *xe)
230243
{
244+
int err;
245+
231246
/* For now suspend/resume is only allowed with GuC */
232247
if (!xe_device_uc_enabled(xe))
233-
return;
234-
235-
drmm_mutex_init(&xe->drm, &xe->d3cold.lock);
248+
return 0;
236249

237250
xe->d3cold.capable = xe_pm_pci_d3cold_capable(xe);
238251

239252
if (xe->d3cold.capable) {
240-
xe_device_sysfs_init(xe);
241-
xe_pm_set_vram_threshold(xe, DEFAULT_VRAM_THRESHOLD);
253+
err = xe_device_sysfs_init(xe);
254+
if (err)
255+
return err;
256+
257+
err = xe_pm_set_vram_threshold(xe, DEFAULT_VRAM_THRESHOLD);
258+
if (err)
259+
return err;
242260
}
243261

244262
xe_pm_runtime_init(xe);
263+
264+
return 0;
245265
}
246266

247267
/**

drivers/gpu/drm/xe/xe_pm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct xe_device;
2020
int xe_pm_suspend(struct xe_device *xe);
2121
int xe_pm_resume(struct xe_device *xe);
2222

23-
void xe_pm_init_early(struct xe_device *xe);
24-
void xe_pm_init(struct xe_device *xe);
23+
int xe_pm_init_early(struct xe_device *xe);
24+
int xe_pm_init(struct xe_device *xe);
2525
void xe_pm_runtime_fini(struct xe_device *xe);
2626
bool xe_pm_runtime_suspended(struct xe_device *xe);
2727
int xe_pm_runtime_suspend(struct xe_device *xe);

0 commit comments

Comments
 (0)