]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/imagination: Access FW initialised state with READ/WRITE_ONCE
authorBrajesh Gupta <brajesh.gupta@imgtec.com>
Tue, 19 May 2026 08:25:29 +0000 (13:55 +0530)
committerMatt Coster <matt.coster@imgtec.com>
Tue, 19 May 2026 11:40:15 +0000 (12:40 +0100)
Update FW initialised state shared resource access with READ/WRITE_ONCE
to prevent following:
- Non-atomic access to variable in multi-thread/CPU case.
- Merge successive loads from the same variable.

Signed-off-by: Brajesh Gupta <brajesh.gupta@imgtec.com>
Reviewed-by: Matt Coster <matt.coster@imgtec.com>
Link: https://patch.msgid.link/20260519-b4-context_reset-v2-4-931018a7131d@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
drivers/gpu/drm/imagination/pvr_device.c
drivers/gpu/drm/imagination/pvr_fw.c
drivers/gpu/drm/imagination/pvr_mmu.c
drivers/gpu/drm/imagination/pvr_power.c

index 49696101b5470dba64f4c3c54f57e8e614658c83..2691ef9af0ca83a8687eed72b15ff134b7bed0a0 100644 (file)
@@ -213,7 +213,7 @@ static irqreturn_t pvr_device_irq_thread_handler(int irq, void *data)
        while (pvr_fw_irq_pending(pvr_dev)) {
                pvr_fw_irq_clear(pvr_dev);
 
-               if (pvr_dev->fw_dev.initialised) {
+               if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
                        pvr_fwccb_process(pvr_dev);
                        pvr_kccb_wake_up_waiters(pvr_dev);
                        pvr_device_process_active_queues(pvr_dev);
index b8ad3f1d222ccf9036aea6a7626b53eee918e92f..850a3ec8e7750fd88fc73c3991df5c4b7eb60079 100644 (file)
@@ -1004,7 +1004,7 @@ pvr_fw_init(struct pvr_device *pvr_dev)
                goto err_fw_stop;
        }
 
-       fw_dev->initialised = true;
+       WRITE_ONCE(fw_dev->initialised, true);
 
        return 0;
 
@@ -1044,7 +1044,7 @@ pvr_fw_fini(struct pvr_device *pvr_dev)
 {
        struct pvr_fw_device *fw_dev = &pvr_dev->fw_dev;
 
-       fw_dev->initialised = false;
+       WRITE_ONCE(fw_dev->initialised, false);
 
        pvr_fw_destroy_structures(pvr_dev);
        pvr_fw_object_unmap_and_destroy(pvr_dev->kccb.rtn_obj);
index e9fefcc4e23438f30bb4f5689f68859c17419fab..3cac482e10347cfd54d3138e060df56348268487 100644 (file)
@@ -134,7 +134,7 @@ int pvr_mmu_flush_exec(struct pvr_device *pvr_dev, bool wait)
                return -EIO;
 
        /* Can't flush MMU if the firmware hasn't been initialised yet. */
-       if (!pvr_dev->fw_dev.initialised)
+       if (!READ_ONCE(pvr_dev->fw_dev.initialised))
                goto err_drm_dev_exit;
 
        cmd_mmu_cache_data->cache_flags =
index a73a6815306b2567b27c09f718266d2bcdb0a016..0ed9e7be604b5e40f5c2031ff1167fb20b372c49 100644 (file)
@@ -216,7 +216,7 @@ pvr_watchdog_worker(struct work_struct *work)
        if (pm_runtime_get_if_in_use(from_pvr_device(pvr_dev)->dev) <= 0)
                goto out_requeue;
 
-       if (!pvr_dev->fw_dev.initialised)
+       if (!READ_ONCE(pvr_dev->fw_dev.initialised))
                goto out_pm_runtime_put;
 
        stalled = pvr_watchdog_kccb_stalled(pvr_dev);
@@ -378,7 +378,7 @@ pvr_power_device_suspend(struct device *dev)
        if (!drm_dev_enter(drm_dev, &idx))
                return -EIO;
 
-       if (pvr_dev->fw_dev.initialised) {
+       if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
                err = pvr_power_fw_disable(pvr_dev, false);
                if (err)
                        goto err_drm_dev_exit;
@@ -408,7 +408,7 @@ pvr_power_device_resume(struct device *dev)
        if (err)
                goto err_drm_dev_exit;
 
-       if (pvr_dev->fw_dev.initialised) {
+       if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
                err = pvr_power_fw_enable(pvr_dev);
                if (err)
                        goto err_power_off;
@@ -548,7 +548,7 @@ pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset)
                err = pvr_power_fw_disable(pvr_dev, hard_reset, false);
                if (!err) {
                        if (hard_reset) {
-                               pvr_dev->fw_dev.initialised = false;
+                               WRITE_ONCE(pvr_dev->fw_dev.initialised, false);
                                WARN_ON(pvr_power_device_suspend(from_pvr_device(pvr_dev)->dev));
 
                                err = pvr_fw_hard_reset(pvr_dev);
@@ -556,7 +556,7 @@ pvr_power_reset(struct pvr_device *pvr_dev, bool hard_reset)
                                        goto err_device_lost;
 
                                err = pvr_power_device_resume(from_pvr_device(pvr_dev)->dev);
-                               pvr_dev->fw_dev.initialised = true;
+                               WRITE_ONCE(pvr_dev->fw_dev.initialised, true);
                                if (err)
                                        goto err_device_lost;
                        } else {