Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Convert i915_perf to ww locking as well

We have the ordering of timeline->mutex vs resv_lock wrong,
convert the i915_pin_vma and intel_context_pin as well to
future-proof this.

We may need to do future changes to do this more transaction-like,
and only get down to a single i915_gem_ww_ctx, but for now this
should work.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200819140904.1708856-18-maarten.lankhorst@linux.intel.com
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

authored by

Maarten Lankhorst and committed by
Joonas Lahtinen
f00ecc2e c8d22594

+42 -15
+42 -15
drivers/gpu/drm/i915/i915_perf.c
··· 1195 1195 struct i915_gem_engines_iter it; 1196 1196 struct i915_gem_context *ctx = stream->ctx; 1197 1197 struct intel_context *ce; 1198 - int err; 1198 + struct i915_gem_ww_ctx ww; 1199 + int err = -ENODEV; 1199 1200 1200 1201 for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) { 1201 1202 if (ce->engine != stream->engine) /* first match! */ 1202 1203 continue; 1203 1204 1204 - /* 1205 - * As the ID is the gtt offset of the context's vma we 1206 - * pin the vma to ensure the ID remains fixed. 1207 - */ 1208 - err = intel_context_pin(ce); 1209 - if (err == 0) { 1210 - stream->pinned_ctx = ce; 1211 - break; 1212 - } 1205 + err = 0; 1206 + break; 1213 1207 } 1214 1208 i915_gem_context_unlock_engines(ctx); 1215 1209 1210 + if (err) 1211 + return ERR_PTR(err); 1212 + 1213 + i915_gem_ww_ctx_init(&ww, true); 1214 + retry: 1215 + /* 1216 + * As the ID is the gtt offset of the context's vma we 1217 + * pin the vma to ensure the ID remains fixed. 1218 + */ 1219 + err = intel_context_pin_ww(ce, &ww); 1220 + if (err == -EDEADLK) { 1221 + err = i915_gem_ww_ctx_backoff(&ww); 1222 + if (!err) 1223 + goto retry; 1224 + } 1225 + i915_gem_ww_ctx_fini(&ww); 1226 + 1227 + if (err) 1228 + return ERR_PTR(err); 1229 + 1230 + stream->pinned_ctx = ce; 1216 1231 return stream->pinned_ctx; 1217 1232 } 1218 1233 ··· 1938 1923 { 1939 1924 struct i915_request *rq; 1940 1925 struct i915_vma *vma; 1926 + struct i915_gem_ww_ctx ww; 1941 1927 int err; 1942 1928 1943 1929 vma = get_oa_vma(stream, oa_config); 1944 1930 if (IS_ERR(vma)) 1945 1931 return PTR_ERR(vma); 1946 1932 1947 - err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL | PIN_HIGH); 1933 + i915_gem_ww_ctx_init(&ww, true); 1934 + retry: 1935 + err = i915_gem_object_lock(vma->obj, &ww); 1948 1936 if (err) 1949 - goto err_vma_put; 1937 + goto err; 1938 + 1939 + err = i915_vma_pin_ww(vma, &ww, 0, 0, PIN_GLOBAL | PIN_HIGH); 1940 + if (err) 1941 + goto err; 1950 1942 1951 1943 intel_engine_pm_get(ce->engine); 1952 1944 rq = i915_request_create(ce); ··· 1975 1953 goto err_add_request; 1976 1954 } 1977 1955 1978 - i915_vma_lock(vma); 1979 1956 err = i915_request_await_object(rq, vma->obj, 0); 1980 1957 if (!err) 1981 1958 err = i915_vma_move_to_active(vma, rq, 0); 1982 - i915_vma_unlock(vma); 1983 1959 if (err) 1984 1960 goto err_add_request; 1985 1961 ··· 1991 1971 i915_request_add(rq); 1992 1972 err_vma_unpin: 1993 1973 i915_vma_unpin(vma); 1994 - err_vma_put: 1974 + err: 1975 + if (err == -EDEADLK) { 1976 + err = i915_gem_ww_ctx_backoff(&ww); 1977 + if (!err) 1978 + goto retry; 1979 + } 1980 + 1981 + i915_gem_ww_ctx_fini(&ww); 1995 1982 i915_vma_put(vma); 1996 1983 return err; 1997 1984 }