]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/guc: READ/WRITE_ONCE ct->state
authorJonathan Cavitt <jonathan.cavitt@intel.com>
Mon, 22 Dec 2025 20:20:00 +0000 (20:20 +0000)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 23 Dec 2025 21:43:49 +0000 (16:43 -0500)
Use READ_ONCE and WRITE_ONCE when operating on ct->state
to prevent the compiler form ignoring important modifications
to its value.

Suggested-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patch.msgid.link/20251222201957.63245-6-jonathan.cavitt@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_guc_ct.c
drivers/gpu/drm/xe/xe_guc_ct.h

index f2148a8bf208daec8056ba5a60badb1c505d0143..dfbf76037b042b0fe04f8f122258b14ec3c8c886 100644 (file)
@@ -529,7 +529,12 @@ static void guc_ct_change_state(struct xe_guc_ct *ct,
        if (ct->g2h_outstanding)
                xe_pm_runtime_put(ct_to_xe(ct));
        ct->g2h_outstanding = 0;
-       ct->state = state;
+
+       /*
+        * WRITE_ONCE pairs with READ_ONCEs in xe_guc_ct_initialized and
+        * xe_guc_ct_enabled.
+        */
+       WRITE_ONCE(ct->state, state);
 
        xe_gt_dbg(gt, "GuC CT communication channel %s\n",
                  state == XE_GUC_CT_STATE_STOPPED ? "stopped" :
index 5599939f8fe1b4de66dc6934ca08592977affdaf..767365a33deeac7c99437686b8c69318a5d19ada 100644 (file)
@@ -30,12 +30,14 @@ void xe_guc_ct_print(struct xe_guc_ct *ct, struct drm_printer *p, bool want_ctb)
 
 static inline bool xe_guc_ct_initialized(struct xe_guc_ct *ct)
 {
-       return ct->state != XE_GUC_CT_STATE_NOT_INITIALIZED;
+       /* READ_ONCE pairs with WRITE_ONCE in guc_ct_change_state. */
+       return READ_ONCE(ct->state) != XE_GUC_CT_STATE_NOT_INITIALIZED;
 }
 
 static inline bool xe_guc_ct_enabled(struct xe_guc_ct *ct)
 {
-       return ct->state == XE_GUC_CT_STATE_ENABLED;
+       /* READ_ONCE pairs with WRITE_ONCE in guc_ct_change_state. */
+       return READ_ONCE(ct->state) == XE_GUC_CT_STATE_ENABLED;
 }
 
 static inline void xe_guc_ct_irq_handler(struct xe_guc_ct *ct)