drm/xe/pm: Capture errors and handle them
authorHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Fri, 12 Apr 2024 18:12:11 +0000 (23:42 +0530)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 18 Apr 2024 20:30:24 +0000 (13:30 -0700)
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 <lucas.demarchi@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240412181211.1155732-8-himal.prasad.ghimiray@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_device_sysfs.c
drivers/gpu/drm/xe/xe_device_sysfs.h
drivers/gpu/drm/xe/xe_pci.c
drivers/gpu/drm/xe/xe_pm.c
drivers/gpu/drm/xe/xe_pm.h

index e47c8ad1bb17a02da5e5f7c10d04ee4205da0434..21677b8cd9771c93164b76634253755079988a2f 100644 (file)
@@ -76,18 +76,14 @@ static void xe_device_sysfs_fini(struct drm_device *drm, void *arg)
        sysfs_remove_file(&xe->drm.dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
 }
 
-void xe_device_sysfs_init(struct xe_device *xe)
+int xe_device_sysfs_init(struct xe_device *xe)
 {
        struct device *dev = xe->drm.dev;
        int ret;
 
        ret = sysfs_create_file(&dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
-       if (ret) {
-               drm_warn(&xe->drm, "Failed to create sysfs file\n");
-               return;
-       }
-
-       ret = drmm_add_action_or_reset(&xe->drm, xe_device_sysfs_fini, xe);
        if (ret)
-               drm_warn(&xe->drm, "Failed to add sysfs fini drm action\n");
+               return ret;
+
+       return drmm_add_action_or_reset(&xe->drm, xe_device_sysfs_fini, xe);
 }
index 38b240684beeacb92e0ca097c50d142b03c95e03..f9e83d8bd2c7d55a9210292dd9dbd2ed25feaeda 100644 (file)
@@ -8,6 +8,6 @@
 
 struct xe_device;
 
-void xe_device_sysfs_init(struct xe_device *xe);
+int xe_device_sysfs_init(struct xe_device *xe);
 
 #endif
index fa2cc80a08a3b75dac9b648caed6432d8928b95e..65ea44672caba2d7900c680a125b10a49b6cba9a 100644 (file)
@@ -781,18 +781,26 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                str_yes_no(xe_device_has_sriov(xe)),
                xe_sriov_mode_to_string(xe_device_sriov_mode(xe)));
 
-       xe_pm_init_early(xe);
+       err = xe_pm_init_early(xe);
+       if (err)
+               return err;
 
        err = xe_device_probe(xe);
        if (err)
                return err;
 
-       xe_pm_init(xe);
+       err = xe_pm_init(xe);
+       if (err)
+               goto err_driver_cleanup;
 
        drm_dbg(&xe->drm, "d3cold: capable=%s\n",
                str_yes_no(xe->d3cold.capable));
 
        return 0;
+
+err_driver_cleanup:
+       xe_pci_remove(pdev);
+       return err;
 }
 
 static void xe_pci_shutdown(struct pci_dev *pdev)
index 0d5fbd715a25492fde589330ac08316a055c4e05..37fbeda12d3bdca6392798e52d3d634a13d40514 100644 (file)
@@ -214,10 +214,21 @@ static void xe_pm_runtime_init(struct xe_device *xe)
        pm_runtime_put(dev);
 }
 
-void xe_pm_init_early(struct xe_device *xe)
+int xe_pm_init_early(struct xe_device *xe)
 {
+       int err;
+
        INIT_LIST_HEAD(&xe->mem_access.vram_userfault.list);
-       drmm_mutex_init(&xe->drm, &xe->mem_access.vram_userfault.lock);
+
+       err = drmm_mutex_init(&xe->drm, &xe->mem_access.vram_userfault.lock);
+       if (err)
+               return err;
+
+       err = drmm_mutex_init(&xe->drm, &xe->d3cold.lock);
+       if (err)
+               return err;
+
+       return 0;
 }
 
 /**
@@ -225,23 +236,32 @@ void xe_pm_init_early(struct xe_device *xe)
  * @xe: xe device instance
  *
  * This component is responsible for System and Device sleep states.
+ *
+ * Returns 0 for success, negative error code otherwise.
  */
-void xe_pm_init(struct xe_device *xe)
+int xe_pm_init(struct xe_device *xe)
 {
+       int err;
+
        /* For now suspend/resume is only allowed with GuC */
        if (!xe_device_uc_enabled(xe))
-               return;
-
-       drmm_mutex_init(&xe->drm, &xe->d3cold.lock);
+               return 0;
 
        xe->d3cold.capable = xe_pm_pci_d3cold_capable(xe);
 
        if (xe->d3cold.capable) {
-               xe_device_sysfs_init(xe);
-               xe_pm_set_vram_threshold(xe, DEFAULT_VRAM_THRESHOLD);
+               err = xe_device_sysfs_init(xe);
+               if (err)
+                       return err;
+
+               err = xe_pm_set_vram_threshold(xe, DEFAULT_VRAM_THRESHOLD);
+               if (err)
+                       return err;
        }
 
        xe_pm_runtime_init(xe);
+
+       return 0;
 }
 
 /**
index 119b630ad1d189da824552b8958fe807b0832486..18b0613fe57b98255f13bd9027657cbad1fabaf2 100644 (file)
@@ -20,8 +20,8 @@ struct xe_device;
 int xe_pm_suspend(struct xe_device *xe);
 int xe_pm_resume(struct xe_device *xe);
 
-void xe_pm_init_early(struct xe_device *xe);
-void xe_pm_init(struct xe_device *xe);
+int xe_pm_init_early(struct xe_device *xe);
+int xe_pm_init(struct xe_device *xe);
 void xe_pm_runtime_fini(struct xe_device *xe);
 bool xe_pm_runtime_suspended(struct xe_device *xe);
 int xe_pm_runtime_suspend(struct xe_device *xe);