@@ -130,7 +130,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size)
130
130
obj -> cache_level = I915_CACHE_NONE ;
131
131
132
132
/* Preallocate the "backing storage" */
133
- if (i915_gem_object_pin_pages (obj ))
133
+ if (i915_gem_object_pin_pages_unlocked (obj ))
134
134
goto err_obj ;
135
135
136
136
i915_gem_object_unpin_pages (obj );
@@ -146,6 +146,7 @@ static int igt_ppgtt_alloc(void *arg)
146
146
{
147
147
struct drm_i915_private * dev_priv = arg ;
148
148
struct i915_ppgtt * ppgtt ;
149
+ struct i915_gem_ww_ctx ww ;
149
150
u64 size , last , limit ;
150
151
int err = 0 ;
151
152
@@ -171,6 +172,12 @@ static int igt_ppgtt_alloc(void *arg)
171
172
limit = totalram_pages () << PAGE_SHIFT ;
172
173
limit = min (ppgtt -> vm .total , limit );
173
174
175
+ i915_gem_ww_ctx_init (& ww , false);
176
+ retry :
177
+ err = i915_vm_lock_objects (& ppgtt -> vm , & ww );
178
+ if (err )
179
+ goto err_ppgtt_cleanup ;
180
+
174
181
/* Check we can allocate the entire range */
175
182
for (size = 4096 ; size <= limit ; size <<= 2 ) {
176
183
struct i915_vm_pt_stash stash = {};
@@ -215,6 +222,13 @@ static int igt_ppgtt_alloc(void *arg)
215
222
}
216
223
217
224
err_ppgtt_cleanup :
225
+ if (err == - EDEADLK ) {
226
+ err = i915_gem_ww_ctx_backoff (& ww );
227
+ if (!err )
228
+ goto retry ;
229
+ }
230
+ i915_gem_ww_ctx_fini (& ww );
231
+
218
232
i915_vm_put (& ppgtt -> vm );
219
233
return err ;
220
234
}
@@ -276,7 +290,7 @@ static int lowlevel_hole(struct i915_address_space *vm,
276
290
277
291
GEM_BUG_ON (obj -> base .size != BIT_ULL (size ));
278
292
279
- if (i915_gem_object_pin_pages (obj )) {
293
+ if (i915_gem_object_pin_pages_unlocked (obj )) {
280
294
i915_gem_object_put (obj );
281
295
kfree (order );
282
296
break ;
@@ -297,20 +311,36 @@ static int lowlevel_hole(struct i915_address_space *vm,
297
311
298
312
if (vm -> allocate_va_range ) {
299
313
struct i915_vm_pt_stash stash = {};
314
+ struct i915_gem_ww_ctx ww ;
315
+ int err ;
316
+
317
+ i915_gem_ww_ctx_init (& ww , false);
318
+ retry :
319
+ err = i915_vm_lock_objects (vm , & ww );
320
+ if (err )
321
+ goto alloc_vm_end ;
300
322
323
+ err = - ENOMEM ;
301
324
if (i915_vm_alloc_pt_stash (vm , & stash ,
302
325
BIT_ULL (size )))
303
- break ;
304
-
305
- if (i915_vm_pin_pt_stash (vm , & stash )) {
306
- i915_vm_free_pt_stash (vm , & stash );
307
- break ;
308
- }
326
+ goto alloc_vm_end ;
309
327
310
- vm -> allocate_va_range (vm , & stash ,
311
- addr , BIT_ULL (size ));
328
+ err = i915_vm_pin_pt_stash (vm , & stash );
329
+ if (!err )
330
+ vm -> allocate_va_range (vm , & stash ,
331
+ addr , BIT_ULL (size ));
312
332
313
333
i915_vm_free_pt_stash (vm , & stash );
334
+ alloc_vm_end :
335
+ if (err == - EDEADLK ) {
336
+ err = i915_gem_ww_ctx_backoff (& ww );
337
+ if (!err )
338
+ goto retry ;
339
+ }
340
+ i915_gem_ww_ctx_fini (& ww );
341
+
342
+ if (err )
343
+ break ;
314
344
}
315
345
316
346
mock_vma -> pages = obj -> mm .pages ;
@@ -1166,7 +1196,7 @@ static int igt_ggtt_page(void *arg)
1166
1196
if (IS_ERR (obj ))
1167
1197
return PTR_ERR (obj );
1168
1198
1169
- err = i915_gem_object_pin_pages (obj );
1199
+ err = i915_gem_object_pin_pages_unlocked (obj );
1170
1200
if (err )
1171
1201
goto out_free ;
1172
1202
@@ -1333,7 +1363,7 @@ static int igt_gtt_reserve(void *arg)
1333
1363
goto out ;
1334
1364
}
1335
1365
1336
- err = i915_gem_object_pin_pages (obj );
1366
+ err = i915_gem_object_pin_pages_unlocked (obj );
1337
1367
if (err ) {
1338
1368
i915_gem_object_put (obj );
1339
1369
goto out ;
@@ -1385,7 +1415,7 @@ static int igt_gtt_reserve(void *arg)
1385
1415
goto out ;
1386
1416
}
1387
1417
1388
- err = i915_gem_object_pin_pages (obj );
1418
+ err = i915_gem_object_pin_pages_unlocked (obj );
1389
1419
if (err ) {
1390
1420
i915_gem_object_put (obj );
1391
1421
goto out ;
@@ -1549,7 +1579,7 @@ static int igt_gtt_insert(void *arg)
1549
1579
goto out ;
1550
1580
}
1551
1581
1552
- err = i915_gem_object_pin_pages (obj );
1582
+ err = i915_gem_object_pin_pages_unlocked (obj );
1553
1583
if (err ) {
1554
1584
i915_gem_object_put (obj );
1555
1585
goto out ;
@@ -1658,7 +1688,7 @@ static int igt_gtt_insert(void *arg)
1658
1688
goto out ;
1659
1689
}
1660
1690
1661
- err = i915_gem_object_pin_pages (obj );
1691
+ err = i915_gem_object_pin_pages_unlocked (obj );
1662
1692
if (err ) {
1663
1693
i915_gem_object_put (obj );
1664
1694
goto out ;
@@ -1829,7 +1859,7 @@ static int igt_cs_tlb(void *arg)
1829
1859
goto out_vm ;
1830
1860
}
1831
1861
1832
- batch = i915_gem_object_pin_map (bbe , I915_MAP_WC );
1862
+ batch = i915_gem_object_pin_map_unlocked (bbe , I915_MAP_WC );
1833
1863
if (IS_ERR (batch )) {
1834
1864
err = PTR_ERR (batch );
1835
1865
goto out_put_bbe ;
@@ -1845,7 +1875,7 @@ static int igt_cs_tlb(void *arg)
1845
1875
}
1846
1876
1847
1877
/* Track the execution of each request by writing into different slot */
1848
- batch = i915_gem_object_pin_map (act , I915_MAP_WC );
1878
+ batch = i915_gem_object_pin_map_unlocked (act , I915_MAP_WC );
1849
1879
if (IS_ERR (batch )) {
1850
1880
err = PTR_ERR (batch );
1851
1881
goto out_put_act ;
@@ -1892,7 +1922,7 @@ static int igt_cs_tlb(void *arg)
1892
1922
goto out_put_out ;
1893
1923
GEM_BUG_ON (vma -> node .start != vm -> total - PAGE_SIZE );
1894
1924
1895
- result = i915_gem_object_pin_map (out , I915_MAP_WB );
1925
+ result = i915_gem_object_pin_map_unlocked (out , I915_MAP_WB );
1896
1926
if (IS_ERR (result )) {
1897
1927
err = PTR_ERR (result );
1898
1928
goto out_put_out ;
@@ -1908,6 +1938,7 @@ static int igt_cs_tlb(void *arg)
1908
1938
while (!__igt_timeout (end_time , NULL )) {
1909
1939
struct i915_vm_pt_stash stash = {};
1910
1940
struct i915_request * rq ;
1941
+ struct i915_gem_ww_ctx ww ;
1911
1942
u64 offset ;
1912
1943
1913
1944
offset = igt_random_offset (& prng ,
@@ -1926,19 +1957,30 @@ static int igt_cs_tlb(void *arg)
1926
1957
if (err )
1927
1958
goto end ;
1928
1959
1960
+ i915_gem_ww_ctx_init (& ww , false);
1961
+ retry :
1962
+ err = i915_vm_lock_objects (vm , & ww );
1963
+ if (err )
1964
+ goto end_ww ;
1965
+
1929
1966
err = i915_vm_alloc_pt_stash (vm , & stash , chunk_size );
1930
1967
if (err )
1931
- goto end ;
1968
+ goto end_ww ;
1932
1969
1933
1970
err = i915_vm_pin_pt_stash (vm , & stash );
1934
- if (err ) {
1935
- i915_vm_free_pt_stash (vm , & stash );
1936
- goto end ;
1937
- }
1938
-
1939
- vm -> allocate_va_range (vm , & stash , offset , chunk_size );
1971
+ if (!err )
1972
+ vm -> allocate_va_range (vm , & stash , offset , chunk_size );
1940
1973
1941
1974
i915_vm_free_pt_stash (vm , & stash );
1975
+ end_ww :
1976
+ if (err == - EDEADLK ) {
1977
+ err = i915_gem_ww_ctx_backoff (& ww );
1978
+ if (!err )
1979
+ goto retry ;
1980
+ }
1981
+ i915_gem_ww_ctx_fini (& ww );
1982
+ if (err )
1983
+ goto end ;
1942
1984
1943
1985
/* Prime the TLB with the dummy pages */
1944
1986
for (i = 0 ; i < count ; i ++ ) {
0 commit comments