Fix another sysfs duplication error when reinitializing the device:

  sysfs: cannot create duplicate filename '.../enforce_isolation'

Fix this by:
  - improve amdgpu_gfx_sysfs_init error unwinding so partially-created
    gfx sysfs files are removed on registration failure.
  - added adev->gfx.sysfs_registered tracking so gfx sysfs cleanup is
    idempotent when harware teardown runs before the existing software
    teardown cleanup path.
  - calling amdgpu_gfx_sysfs_fini from amdgpu_device_fini_hw before the
    general device sysfs cleanup.

Signed-off-by: Geoffrey McRae <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 32 +++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h    |  2 ++
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 5442a1fc1c37..7278d68f8021 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4242,6 +4242,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
        }
        amdgpu_fence_driver_hw_fini(adev);

+       amdgpu_gfx_sysfs_fini(adev);
        amdgpu_device_sys_interface_fini(adev);

        /* disable ras feature must before hw fini */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index a5b835d0c166..a4616d54adcc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -2195,6 +2195,8 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev)
 {
        int r;

+       adev->gfx.sysfs_registered = false;
+
        r = amdgpu_gfx_sysfs_xcp_init(adev);
        if (r) {
                dev_err(adev->dev, "failed to create xcp sysfs files");
@@ -2202,23 +2204,39 @@ int amdgpu_gfx_sysfs_init(struct amdgpu_device *adev)
        }

        r = amdgpu_gfx_sysfs_isolation_shader_init(adev);
-       if (r)
+       if (r) {
                dev_err(adev->dev, "failed to create isolation sysfs files");
+               goto err_isolation_shader;
+       }

        r = amdgpu_gfx_sysfs_reset_mask_init(adev);
-       if (r)
+       if (r) {
                dev_err(adev->dev, "failed to create reset mask sysfs files");
+               goto err_reset_mask;
+       }

+       adev->gfx.sysfs_registered = true;
+
+       return 0;
+
+err_reset_mask:
+       amdgpu_gfx_sysfs_reset_mask_fini(adev);
+       amdgpu_gfx_sysfs_isolation_shader_fini(adev);
+err_isolation_shader:
+       amdgpu_gfx_sysfs_xcp_fini(adev);
        return r;
 }

 void amdgpu_gfx_sysfs_fini(struct amdgpu_device *adev)
 {
-       if (adev->dev->kobj.sd) {
-               amdgpu_gfx_sysfs_xcp_fini(adev);
-               amdgpu_gfx_sysfs_isolation_shader_fini(adev);
-               amdgpu_gfx_sysfs_reset_mask_fini(adev);
-       }
+       if (!adev->gfx.sysfs_registered)
+               return;
+
+       amdgpu_gfx_sysfs_xcp_fini(adev);
+       amdgpu_gfx_sysfs_isolation_shader_fini(adev);
+       amdgpu_gfx_sysfs_reset_mask_fini(adev);
+
+       adev->gfx.sysfs_registered = false;
 }

 static void amdgpu_gfx_reset_start_compute_scheds(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 9432107c96a1..64cb1c1e51fb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -477,6 +477,8 @@ struct amdgpu_gfx {
        struct amdgpu_irq_src           rlc_poison_irq;
        struct sq_work                  sq_work;

+       bool                            sysfs_registered;
+
        /* gfx status */
        uint32_t                        gfx_current_status;
        /* ce ram size*/
--
2.43.0

Reply via email to