1 From 796f969672c3ccafe78d092aef05be6de0fac156 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 19 Oct 2020 21:38:25 +0100
4 Subject: drm/i915/gem: Flush coherency domains on first set-domain-ioctl
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 From: Chris Wilson <chris@chris-wilson.co.uk>
11 [ Upstream commit 59dd13ad310793757e34afa489dd6fc8544fc3da ]
13 Avoid skipping what appears to be a no-op set-domain-ioctl if the cache
14 coherency state is inconsistent with our target domain. This also has
15 the utility of using the population of the pages to validate the backing
18 The danger in skipping the first set-domain is leaving the cache
19 inconsistent and submitting stale data, or worse leaving the clean data
20 in the cache and not flushing it to the GPU. The impact should be small
21 as it requires a no-op set-domain as the very first ioctl in a
22 particular sequence not found in typical userspace.
24 Reported-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
25 Fixes: 754a25442705 ("drm/i915: Skip object locking around a no-op set-domain ioctl")
26 Testcase: igt/gem_mmap_offset/blt-coherency
27 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
28 Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
29 Cc: Matthew Auld <matthew.william.auld@gmail.com>
30 Cc: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
31 Cc: <stable@vger.kernel.org> # v5.2+
32 Reviewed-by: Matthew Auld <matthew.auld@intel.com>
33 Link: https://patchwork.freedesktop.org/patch/msgid/20201019203825.10966-1-chris@chris-wilson.co.uk
34 (cherry picked from commit 44c2200afcd59f441b43f27829b4003397cc495d)
35 Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
36 Signed-off-by: Sasha Levin <sashal@kernel.org>
38 drivers/gpu/drm/i915/gem/i915_gem_domain.c | 28 ++++++++++------------
39 1 file changed, 13 insertions(+), 15 deletions(-)
41 diff --git a/drivers/gpu/drm/i915/gem/i915_gem_domain.c b/drivers/gpu/drm/i915/gem/i915_gem_domain.c
42 index 7f76fc68f498a..ba8758011e297 100644
43 --- a/drivers/gpu/drm/i915/gem/i915_gem_domain.c
44 +++ b/drivers/gpu/drm/i915/gem/i915_gem_domain.c
45 @@ -484,21 +484,6 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
50 - * Already in the desired write domain? Nothing for us to do!
52 - * We apply a little bit of cunning here to catch a broader set of
53 - * no-ops. If obj->write_domain is set, we must be in the same
54 - * obj->read_domains, and only that domain. Therefore, if that
55 - * obj->write_domain matches the request read_domains, we are
56 - * already in the same read/write domain and can skip the operation,
57 - * without having to further check the requested write_domain.
59 - if (READ_ONCE(obj->write_domain) == read_domains) {
65 * Try to flush the object off the GPU without holding the lock.
66 * We will repeat the flush holding the lock in the normal manner
67 @@ -536,6 +521,19 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
72 + * Already in the desired write domain? Nothing for us to do!
74 + * We apply a little bit of cunning here to catch a broader set of
75 + * no-ops. If obj->write_domain is set, we must be in the same
76 + * obj->read_domains, and only that domain. Therefore, if that
77 + * obj->write_domain matches the request read_domains, we are
78 + * already in the same read/write domain and can skip the operation,
79 + * without having to further check the requested write_domain.
81 + if (READ_ONCE(obj->write_domain) == read_domains)
84 err = i915_gem_object_lock_interruptible(obj);