]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/etnaviv: hold GPU lock across perfmon sampling
authorLucas Stach <l.stach@pengutronix.de>
Fri, 5 Jul 2024 20:00:09 +0000 (22:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 14 Dec 2024 18:50:56 +0000 (19:50 +0100)
[ Upstream commit 37dc4737447a7667f8e9ec790dac251da057eb27 ]

The perfmon sampling mutates shared GPU state (e.g. VIVS_HI_CLOCK_CONTROL
to select the pipe for the perf counter reads). To avoid clashing with
other functions mutating the same state (e.g. etnaviv_gpu_update_clock)
the perfmon sampling needs to hold the GPU lock.

Fixes: 68dc0b295dcb ("drm/etnaviv: use 'sync points' for performance monitor requests")
Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/etnaviv/etnaviv_gpu.c

index 9def75f04e5b6d918c3a7fd5a4c91bb01c09c724..0fff51dc97755b69f8a80f3f7d3bb25debab5977 100644 (file)
@@ -1292,6 +1292,8 @@ static void sync_point_perfmon_sample_pre(struct etnaviv_gpu *gpu,
 {
        u32 val;
 
+       mutex_lock(&gpu->lock);
+
        /* disable clock gating */
        val = gpu_read_power(gpu, VIVS_PM_POWER_CONTROLS);
        val &= ~VIVS_PM_POWER_CONTROLS_ENABLE_MODULE_CLOCK_GATING;
@@ -1303,6 +1305,8 @@ static void sync_point_perfmon_sample_pre(struct etnaviv_gpu *gpu,
        gpu_write(gpu, VIVS_HI_CLOCK_CONTROL, val);
 
        sync_point_perfmon_sample(gpu, event, ETNA_PM_PROCESS_PRE);
+
+       mutex_unlock(&gpu->lock);
 }
 
 static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu,
@@ -1312,13 +1316,9 @@ static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu,
        unsigned int i;
        u32 val;
 
-       sync_point_perfmon_sample(gpu, event, ETNA_PM_PROCESS_POST);
-
-       for (i = 0; i < submit->nr_pmrs; i++) {
-               const struct etnaviv_perfmon_request *pmr = submit->pmrs + i;
+       mutex_lock(&gpu->lock);
 
-               *pmr->bo_vma = pmr->sequence;
-       }
+       sync_point_perfmon_sample(gpu, event, ETNA_PM_PROCESS_POST);
 
        /* disable debug register */
        val = gpu_read(gpu, VIVS_HI_CLOCK_CONTROL);
@@ -1329,6 +1329,14 @@ static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu,
        val = gpu_read_power(gpu, VIVS_PM_POWER_CONTROLS);
        val |= VIVS_PM_POWER_CONTROLS_ENABLE_MODULE_CLOCK_GATING;
        gpu_write_power(gpu, VIVS_PM_POWER_CONTROLS, val);
+
+       mutex_unlock(&gpu->lock);
+
+       for (i = 0; i < submit->nr_pmrs; i++) {
+               const struct etnaviv_perfmon_request *pmr = submit->pmrs + i;
+
+               *pmr->bo_vma = pmr->sequence;
+       }
 }