Skip to content

Commit 480ae79

Browse files
mlankhorstdanvet
authored andcommitted
drm/i915/selftests: Prepare gtt tests for obj->mm.lock removal
We need to lock the global gtt dma_resv, use i915_vm_lock_objects to handle this correctly. Add ww handling for this where required. Add the object lock around unpin/put pages, and use the unlocked versions of pin_pages and pin_map where required. Signed-off-by: Maarten Lankhorst <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b91e1b1 commit 480ae79

File tree

1 file changed

+67
-25
lines changed

1 file changed

+67
-25
lines changed

drivers/gpu/drm/i915/selftests/i915_gem_gtt.c

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size)
130130
obj->cache_level = I915_CACHE_NONE;
131131

132132
/* Preallocate the "backing storage" */
133-
if (i915_gem_object_pin_pages(obj))
133+
if (i915_gem_object_pin_pages_unlocked(obj))
134134
goto err_obj;
135135

136136
i915_gem_object_unpin_pages(obj);
@@ -146,6 +146,7 @@ static int igt_ppgtt_alloc(void *arg)
146146
{
147147
struct drm_i915_private *dev_priv = arg;
148148
struct i915_ppgtt *ppgtt;
149+
struct i915_gem_ww_ctx ww;
149150
u64 size, last, limit;
150151
int err = 0;
151152

@@ -171,6 +172,12 @@ static int igt_ppgtt_alloc(void *arg)
171172
limit = totalram_pages() << PAGE_SHIFT;
172173
limit = min(ppgtt->vm.total, limit);
173174

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+
174181
/* Check we can allocate the entire range */
175182
for (size = 4096; size <= limit; size <<= 2) {
176183
struct i915_vm_pt_stash stash = {};
@@ -215,6 +222,13 @@ static int igt_ppgtt_alloc(void *arg)
215222
}
216223

217224
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+
218232
i915_vm_put(&ppgtt->vm);
219233
return err;
220234
}
@@ -276,7 +290,7 @@ static int lowlevel_hole(struct i915_address_space *vm,
276290

277291
GEM_BUG_ON(obj->base.size != BIT_ULL(size));
278292

279-
if (i915_gem_object_pin_pages(obj)) {
293+
if (i915_gem_object_pin_pages_unlocked(obj)) {
280294
i915_gem_object_put(obj);
281295
kfree(order);
282296
break;
@@ -297,20 +311,36 @@ static int lowlevel_hole(struct i915_address_space *vm,
297311

298312
if (vm->allocate_va_range) {
299313
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;
300322

323+
err = -ENOMEM;
301324
if (i915_vm_alloc_pt_stash(vm, &stash,
302325
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;
309327

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));
312332

313333
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;
314344
}
315345

316346
mock_vma->pages = obj->mm.pages;
@@ -1166,7 +1196,7 @@ static int igt_ggtt_page(void *arg)
11661196
if (IS_ERR(obj))
11671197
return PTR_ERR(obj);
11681198

1169-
err = i915_gem_object_pin_pages(obj);
1199+
err = i915_gem_object_pin_pages_unlocked(obj);
11701200
if (err)
11711201
goto out_free;
11721202

@@ -1333,7 +1363,7 @@ static int igt_gtt_reserve(void *arg)
13331363
goto out;
13341364
}
13351365

1336-
err = i915_gem_object_pin_pages(obj);
1366+
err = i915_gem_object_pin_pages_unlocked(obj);
13371367
if (err) {
13381368
i915_gem_object_put(obj);
13391369
goto out;
@@ -1385,7 +1415,7 @@ static int igt_gtt_reserve(void *arg)
13851415
goto out;
13861416
}
13871417

1388-
err = i915_gem_object_pin_pages(obj);
1418+
err = i915_gem_object_pin_pages_unlocked(obj);
13891419
if (err) {
13901420
i915_gem_object_put(obj);
13911421
goto out;
@@ -1549,7 +1579,7 @@ static int igt_gtt_insert(void *arg)
15491579
goto out;
15501580
}
15511581

1552-
err = i915_gem_object_pin_pages(obj);
1582+
err = i915_gem_object_pin_pages_unlocked(obj);
15531583
if (err) {
15541584
i915_gem_object_put(obj);
15551585
goto out;
@@ -1658,7 +1688,7 @@ static int igt_gtt_insert(void *arg)
16581688
goto out;
16591689
}
16601690

1661-
err = i915_gem_object_pin_pages(obj);
1691+
err = i915_gem_object_pin_pages_unlocked(obj);
16621692
if (err) {
16631693
i915_gem_object_put(obj);
16641694
goto out;
@@ -1829,7 +1859,7 @@ static int igt_cs_tlb(void *arg)
18291859
goto out_vm;
18301860
}
18311861

1832-
batch = i915_gem_object_pin_map(bbe, I915_MAP_WC);
1862+
batch = i915_gem_object_pin_map_unlocked(bbe, I915_MAP_WC);
18331863
if (IS_ERR(batch)) {
18341864
err = PTR_ERR(batch);
18351865
goto out_put_bbe;
@@ -1845,7 +1875,7 @@ static int igt_cs_tlb(void *arg)
18451875
}
18461876

18471877
/* 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);
18491879
if (IS_ERR(batch)) {
18501880
err = PTR_ERR(batch);
18511881
goto out_put_act;
@@ -1892,7 +1922,7 @@ static int igt_cs_tlb(void *arg)
18921922
goto out_put_out;
18931923
GEM_BUG_ON(vma->node.start != vm->total - PAGE_SIZE);
18941924

1895-
result = i915_gem_object_pin_map(out, I915_MAP_WB);
1925+
result = i915_gem_object_pin_map_unlocked(out, I915_MAP_WB);
18961926
if (IS_ERR(result)) {
18971927
err = PTR_ERR(result);
18981928
goto out_put_out;
@@ -1908,6 +1938,7 @@ static int igt_cs_tlb(void *arg)
19081938
while (!__igt_timeout(end_time, NULL)) {
19091939
struct i915_vm_pt_stash stash = {};
19101940
struct i915_request *rq;
1941+
struct i915_gem_ww_ctx ww;
19111942
u64 offset;
19121943

19131944
offset = igt_random_offset(&prng,
@@ -1926,19 +1957,30 @@ static int igt_cs_tlb(void *arg)
19261957
if (err)
19271958
goto end;
19281959

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+
19291966
err = i915_vm_alloc_pt_stash(vm, &stash, chunk_size);
19301967
if (err)
1931-
goto end;
1968+
goto end_ww;
19321969

19331970
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);
19401973

19411974
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;
19421984

19431985
/* Prime the TLB with the dummy pages */
19441986
for (i = 0; i < count; i++) {

0 commit comments

Comments
 (0)