]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/xe3p_lpg: flush shrinker bo cachelines manually
authorTejas Upadhyay <tejas.upadhyay@intel.com>
Thu, 5 Mar 2026 12:19:04 +0000 (17:49 +0530)
committerTejas Upadhyay <tejas.upadhyay@intel.com>
Mon, 23 Mar 2026 09:53:24 +0000 (15:23 +0530)
XA, new pat_index introduced post xe3p_lpg, is memory shared between the
CPU and GPU is treated differently from other GPU memory when the Media
engine is power-gated.

XA is *always* flushed, like at the end-of-submssion (and maybe other
places), just that internally as an optimisation hw doesn't need to make
that a full flush (which will also include XA) when Media is
off/powergated, since it doesn't need to worry about GT caches vs Media
coherency, and only CPU vs GPU coherency, so can make that flush a
targeted XA flush, since stuff tagged with XA now means it's shared with
the CPU. The main implication is that we now need to somehow flush non-XA
before freeing system memory pages, otherwise dirty cachelines could be
flushed after the free (like if Media suddenly turns on and does a full
flush)

V4: Add comments for L2 flush path
V3(Thomas/MattA/MattR): Restrict userptr with non-xa, then no need to
                        flush manually
V2(MattA): Expand commit description

Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://patch.msgid.link/20260305121902.1892593-7-tejas.upadhyay@intel.com
Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com>
drivers/gpu/drm/xe/xe_bo.c
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_device.h

index 22179b2df85c5acf1bc0c2eae0013dd39f54c5ef..216e1d8635f41abf497560bf07555a9971dd735c 100644 (file)
@@ -689,7 +689,12 @@ static int xe_bo_trigger_rebind(struct xe_device *xe, struct xe_bo *bo,
 
                if (!xe_vm_in_fault_mode(vm)) {
                        drm_gpuvm_bo_evict(vm_bo, true);
-                       continue;
+                       /*
+                        * L2 cache may not be flushed, so ensure that is done in
+                        * xe_vm_invalidate_vma() below
+                        */
+                       if (!xe_device_is_l2_flush_optimized(xe))
+                               continue;
                }
 
                if (!idle) {
index e77a3a3db73dbf8509d857b58a2dc3964d9aa0ca..daf2c815082c2c346d668bcfa4869848ae0787e0 100644 (file)
@@ -1094,6 +1094,29 @@ static void tdf_request_sync(struct xe_device *xe)
        }
 }
 
+/**
+ * xe_device_is_l2_flush_optimized - if L2 flush is optimized by HW
+ * @xe: The device to check.
+ *
+ * Return: true if the HW device optimizing L2 flush, false otherwise.
+ */
+bool xe_device_is_l2_flush_optimized(struct xe_device *xe)
+{
+       /* XA is *always* flushed, like at the end-of-submssion (and maybe other
+        * places), just that internally as an optimisation hw doesn't need to make
+        * that a full flush (which will also include XA) when Media is
+        * off/powergated, since it doesn't need to worry about GT caches vs Media
+        * coherency, and only CPU vs GPU coherency, so can make that flush a
+        * targeted XA flush, since stuff tagged with XA now means it's shared with
+        * the CPU. The main implication is that we now need to somehow flush non-XA before
+        * freeing system memory pages, otherwise dirty cachelines could be flushed after the free
+        * (like if Media suddenly turns on and does a full flush)
+        */
+       if (GRAPHICS_VER(xe) >= 35 && !IS_DGFX(xe))
+               return true;
+       return false;
+}
+
 void xe_device_l2_flush(struct xe_device *xe)
 {
        struct xe_gt *gt;
index c4d26700266115f91330cff0a115a716e6899c50..e4b9de8d8e95c8fe9b4b6461364ec94c1d110c54 100644 (file)
@@ -188,6 +188,7 @@ void xe_device_snapshot_print(struct xe_device *xe, struct drm_printer *p);
 u64 xe_device_canonicalize_addr(struct xe_device *xe, u64 address);
 u64 xe_device_uncanonicalize_addr(struct xe_device *xe, u64 address);
 
+bool xe_device_is_l2_flush_optimized(struct xe_device *xe);
 void xe_device_td_flush(struct xe_device *xe);
 void xe_device_l2_flush(struct xe_device *xe);