drm/amdgpu: Fix koops when accessing RAS EEPROM
authorLuben Tuikov <luben.tuikov@amd.com>
Fri, 30 Apr 2021 00:15:42 +0000 (20:15 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 1 Jul 2021 04:25:33 +0000 (00:25 -0400)
Debugfs RAS EEPROM files are available when
the ASIC supports RAS, and when the debugfs is
enabled, an also when "ras_enable" module
parameter is set to 0. However in this case,
we get a kernel oops when accessing some of
the "ras_..." controls in debugfs. The reason
for this is that struct amdgpu_ras::adev is
unset. This commit sets it, thus enabling access
to those facilities. Note that this facilitates
EEPROM access and not necessarily RAS features or
functionality.

Cc: Alexander Deucher <Alexander.Deucher@amd.com>
Cc: John Clements <john.clements@amd.com>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
Acked-by: Alexander Deucher <Alexander.Deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c

index 53a54ff..875874e 100644 (file)
@@ -1947,11 +1947,20 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
        bool exc_err_limit = false;
        int ret;
 
-       if (adev->ras_enabled && con)
-               data = &con->eh_data;
-       else
+       if (!con)
+               return 0;
+
+       /* Allow access to RAS EEPROM via debugfs, when the ASIC
+        * supports RAS and debugfs is enabled, but when
+        * adev->ras_enabled is unset, i.e. when "ras_enable"
+        * module parameter is set to 0.
+        */
+       con->adev = adev;
+
+       if (!adev->ras_enabled)
                return 0;
 
+       data = &con->eh_data;
        *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO);
        if (!*data) {
                ret = -ENOMEM;
@@ -1961,7 +1970,6 @@ int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
        mutex_init(&con->recovery_lock);
        INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
        atomic_set(&con->in_recovery, 0);
-       con->adev = adev;
 
        max_eeprom_records_count = amdgpu_ras_eeprom_max_record_count();
        amdgpu_ras_validate_threshold(adev, max_eeprom_records_count);