Skip to contentSkip to conversation

drm/i915/dmabuf: avoid global wbinvd on dma-buf import

PATCH Superseded Prabhakaran, Krishna 2 participants 2 messages Aug 7

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915/dmabuf: avoid global wbinvd on dma-buf import

From: Krishna Prabhakaran <[email protected]>

When i915 needs to make an imported dma-buf coherent for GPU access on non-LLC platforms, or for objects that bypass LLC, it currently calls wbinvd_on_all_cpus(). get_pages() runs whenever an imported buffer is pinned, so this triggers a whole-cache write-back and invalidate, broadcast by IPI to every CPU, on every execbuf submission involving an imported dma-buf. That stalls the entire machine for milliseconds and starves latency-sensitive work on unrelated cores (e.g. USB isochronous audio serviced on the VMM's main thread).

A dma-buf sg_table is not guaranteed to be backed by struct pages, and the importer has no way to tell, so drm_clflush_sg() cannot be used here. Instead vmap the buffer and flush that virtual range with drm_clflush_virt_range(): x86 uses PIPT caches, so flushing one virtual alias evicts the cache lines for every alias of the same physical pages. This provides the required coherency, locally and without an IPI.

Fall back to wbinvd only when the buffer cannot be vmapped or is backed by I/O memory, where there is no CPU-side range to clflush. The dma_resv lock required by dma_buf_vmap() is already held here via the imported object.

Fixes a035154da45d ("drm/i915/dmabuf: add paranoid flush-on-acquire")
---
 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +18 -8
index b43d34c7d641..1c1f3dc9c212 100644
@@ -10,6 +10,8 @@
 
 #include <asm/smp.h>
 
+#include <drm/drm_cache.h>
+
 #include "gem/i915_gem_dmabuf.h"
 #include "i915_drv.h"
 #include "i915_gem_object.h"
@@ -249,16 +251,24 @@ static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
 	 * DG1 is special here since it still snoops transactions even with
 	 * CACHE_NONE. This is not the case with other HAS_SNOOP platforms. We
 	 * might need to revisit this as we add new discrete platforms.
-	 *
-	 * XXX: Consider doing a vmap flush or something, where possible.
-	 * Currently we just do a heavy handed wbinvd_on_all_cpus() here since
-	 * the underlying sg_table might not even point to struct pages, so we
-	 * can't just call drm_clflush_sg or similar, like we do elsewhere in
-	 * the driver.
 	 */
 	if (i915_gem_object_can_bypass_llc(obj) ||
-	    (!HAS_LLC(i915) && !IS_DG1(i915)))
-		wbinvd_on_all_cpus();
+	    (!HAS_LLC(i915) && !IS_DG1(i915))) {
+		struct dma_buf *dma_buf = obj->base.import_attach->dmabuf;
+		struct iosys_map map;
+		int vmap_ret;
+
+		/* We already hold the dma_resv lock via the imported obj. */
+		vmap_ret = dma_buf_vmap(dma_buf, &map);
+		if (!vmap_ret && !map.is_iomem) {
+			drm_clflush_virt_range(map.vaddr, obj->base.size);
+			dma_buf_vunmap(dma_buf, &map);
+		} else {
+			if (!vmap_ret)
+				dma_buf_vunmap(dma_buf, &map);
+			wbinvd_on_all_cpus();
+		}
+	}
 
 	__i915_gem_object_set_pages(obj, sgt);
 
Signature · 1 line
2.43.0
#1 lore raw

✗ i915.CI.BAT: failure for series starting with [1/1] drm/i915/dmabuf: avoid global wbinvd on dma-buf import

== Series Details ==

== Series Details ==

Series: series starting with [1/1] drm/i915/dmabuf: avoid global wbinvd on dma-buf import
URL : https://patchwork.freedesktop.org/series/171760/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_18962 -> Patchwork_171760v1
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_171760v1 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes
introduced in Patchwork_171760v1, please notify your bug team ([email protected]) to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/index.html

Participating hosts (40 -> 36)
------------------------------

Missing (4): bat-dg2-13 bat-dg2-9 fi-snb-2520m bat-adls-6

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_171760v1:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live:
- bat-mtlp-8: [PASS][1] -> [DMESG-FAIL][2] +1 other test dmesg-fail
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-mtlp-8/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-mtlp-8/igt@[email protected]
- fi-elk-e7500: [PASS][3] -> [DMESG-FAIL][4] +1 other test dmesg-fail
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-elk-e7500/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-elk-e7500/igt@[email protected]
- fi-bsw-n3050: [PASS][5] -> [DMESG-FAIL][6] +1 other test dmesg-fail
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-bsw-n3050/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-bsw-n3050/igt@[email protected]
- bat-arlh-3: [PASS][7] -> [DMESG-FAIL][8] +1 other test dmesg-fail
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-arlh-3/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-arlh-3/igt@[email protected]
- fi-pnv-d510: [PASS][9] -> [DMESG-FAIL][10] +1 other test dmesg-fail
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-pnv-d510/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-pnv-d510/igt@[email protected]
- bat-apl-1: [PASS][11] -> [DMESG-FAIL][12] +1 other test dmesg-fail
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-apl-1/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-apl-1/igt@[email protected]
- bat-arlh-2: [PASS][13] -> [DMESG-FAIL][14] +1 other test dmesg-fail
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-arlh-2/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-arlh-2/igt@[email protected]
- fi-ilk-650: [PASS][15] -> [DMESG-FAIL][16] +1 other test dmesg-fail
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-ilk-650/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-ilk-650/igt@[email protected]

* igt@i915_selftest@live@dmabuf:
- bat-mtlp-9: [PASS][17] -> [DMESG-FAIL][18] +1 other test dmesg-fail
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-mtlp-9/igt@i915_selftest@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-mtlp-9/igt@i915_selftest@[email protected]
- bat-arls-6: [PASS][19] -> [DMESG-FAIL][20] +1 other test dmesg-fail
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/bat-arls-6/igt@i915_selftest@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/bat-arls-6/igt@i915_selftest@[email protected]
- fi-bsw-nick: [PASS][21] -> [DMESG-FAIL][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-bsw-nick/igt@i915_selftest@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-bsw-nick/igt@i915_selftest@[email protected]

Known issues
------------

Here are the changes found in Patchwork_171760v1 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@late_gt_pm:
- fi-bsw-nick: [PASS][23] -> [ABORT][24] ([i915#16562]) +1 other test abort
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18962/fi-bsw-nick/igt@i915_selftest@live@late_gt_pm.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/fi-bsw-nick/igt@i915_selftest@live@late_gt_pm.html

[i915#16562]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/16562

Build changes
-------------

* Linux: CI_DRM_18962 -> Patchwork_171760v1

CI-20190529: 20190529
CI_DRM_18962: 01d30c194951b8794c33f0d7f559bc4a1c9b7630 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_9043: 9043
Patchwork_171760v1: 01d30c194951b8794c33f0d7f559bc4a1c9b7630 @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_171760v1/index.html