drm/amdgpu/smu: add metrics table lock for vega20 (v2)
authorAlex Deucher <alexander.deucher@amd.com>
Tue, 17 Dec 2019 14:51:40 +0000 (09:51 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Sun, 29 Dec 2019 06:58:12 +0000 (01:58 -0500)
To protect access to the metrics table.

v2: unlock on error

Bug: https://gitlab.freedesktop.org/drm/amd/issues/900
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Reviewed-by: Evan Quan <evan.quan@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/powerplay/vega20_ppt.c

index 60b9ff097142639d18fbc037f6cb2cfcfa2db3d8..0d3a3b0a934e9a767ebe98fa105c8ac80f39e863 100644 (file)
@@ -1678,17 +1678,20 @@ static int vega20_get_metrics_table(struct smu_context *smu,
        struct smu_table_context *smu_table= &smu->smu_table;
        int ret = 0;
 
+       mutex_lock(&smu->metrics_lock);
        if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
                ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
                                (void *)smu_table->metrics_table, false);
                if (ret) {
                        pr_info("Failed to export SMU metrics table!\n");
+                       mutex_unlock(&smu->metrics_lock);
                        return ret;
                }
                smu_table->metrics_time = jiffies;
        }
 
        memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+       mutex_unlock(&smu->metrics_lock);
 
        return ret;
 }