Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / gem / selftests / huge_pages.c
blob1f35e71429b47e1507d7da62ddbe63f66e76dc66
1 /*
2 * SPDX-License-Identifier: MIT
4 * Copyright © 2017 Intel Corporation
5 */
7 #include <linux/prime_numbers.h>
9 #include "i915_selftest.h"
11 #include "gem/i915_gem_region.h"
12 #include "gem/i915_gem_lmem.h"
13 #include "gem/i915_gem_pm.h"
15 #include "gt/intel_gt.h"
17 #include "igt_gem_utils.h"
18 #include "mock_context.h"
20 #include "selftests/mock_drm.h"
21 #include "selftests/mock_gem_device.h"
22 #include "selftests/mock_region.h"
23 #include "selftests/i915_random.h"
25 static const unsigned int page_sizes[] = {
26 I915_GTT_PAGE_SIZE_2M,
27 I915_GTT_PAGE_SIZE_64K,
28 I915_GTT_PAGE_SIZE_4K,
31 static unsigned int get_largest_page_size(struct drm_i915_private *i915,
32 u64 rem)
34 int i;
36 for (i = 0; i < ARRAY_SIZE(page_sizes); ++i) {
37 unsigned int page_size = page_sizes[i];
39 if (HAS_PAGE_SIZES(i915, page_size) && rem >= page_size)
40 return page_size;
43 return 0;
46 static void huge_pages_free_pages(struct sg_table *st)
48 struct scatterlist *sg;
50 for (sg = st->sgl; sg; sg = __sg_next(sg)) {
51 if (sg_page(sg))
52 __free_pages(sg_page(sg), get_order(sg->length));
55 sg_free_table(st);
56 kfree(st);
59 static int get_huge_pages(struct drm_i915_gem_object *obj)
61 #define GFP (GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY)
62 unsigned int page_mask = obj->mm.page_mask;
63 struct sg_table *st;
64 struct scatterlist *sg;
65 unsigned int sg_page_sizes;
66 u64 rem;
68 st = kmalloc(sizeof(*st), GFP);
69 if (!st)
70 return -ENOMEM;
72 if (sg_alloc_table(st, obj->base.size >> PAGE_SHIFT, GFP)) {
73 kfree(st);
74 return -ENOMEM;
77 rem = obj->base.size;
78 sg = st->sgl;
79 st->nents = 0;
80 sg_page_sizes = 0;
83 * Our goal here is simple, we want to greedily fill the object from
84 * largest to smallest page-size, while ensuring that we use *every*
85 * page-size as per the given page-mask.
87 do {
88 unsigned int bit = ilog2(page_mask);
89 unsigned int page_size = BIT(bit);
90 int order = get_order(page_size);
92 do {
93 struct page *page;
95 GEM_BUG_ON(order >= MAX_ORDER);
96 page = alloc_pages(GFP | __GFP_ZERO, order);
97 if (!page)
98 goto err;
100 sg_set_page(sg, page, page_size, 0);
101 sg_page_sizes |= page_size;
102 st->nents++;
104 rem -= page_size;
105 if (!rem) {
106 sg_mark_end(sg);
107 break;
110 sg = __sg_next(sg);
111 } while ((rem - ((page_size-1) & page_mask)) >= page_size);
113 page_mask &= (page_size-1);
114 } while (page_mask);
116 if (i915_gem_gtt_prepare_pages(obj, st))
117 goto err;
119 GEM_BUG_ON(sg_page_sizes != obj->mm.page_mask);
120 __i915_gem_object_set_pages(obj, st, sg_page_sizes);
122 return 0;
124 err:
125 sg_set_page(sg, NULL, 0, 0);
126 sg_mark_end(sg);
127 huge_pages_free_pages(st);
129 return -ENOMEM;
132 static void put_huge_pages(struct drm_i915_gem_object *obj,
133 struct sg_table *pages)
135 i915_gem_gtt_finish_pages(obj, pages);
136 huge_pages_free_pages(pages);
138 obj->mm.dirty = false;
141 static const struct drm_i915_gem_object_ops huge_page_ops = {
142 .name = "huge-gem",
143 .flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE |
144 I915_GEM_OBJECT_IS_SHRINKABLE,
145 .get_pages = get_huge_pages,
146 .put_pages = put_huge_pages,
149 static struct drm_i915_gem_object *
150 huge_pages_object(struct drm_i915_private *i915,
151 u64 size,
152 unsigned int page_mask)
154 static struct lock_class_key lock_class;
155 struct drm_i915_gem_object *obj;
157 GEM_BUG_ON(!size);
158 GEM_BUG_ON(!IS_ALIGNED(size, BIT(__ffs(page_mask))));
160 if (size >> PAGE_SHIFT > INT_MAX)
161 return ERR_PTR(-E2BIG);
163 if (overflows_type(size, obj->base.size))
164 return ERR_PTR(-E2BIG);
166 obj = i915_gem_object_alloc();
167 if (!obj)
168 return ERR_PTR(-ENOMEM);
170 drm_gem_private_object_init(&i915->drm, &obj->base, size);
171 i915_gem_object_init(obj, &huge_page_ops, &lock_class);
173 i915_gem_object_set_volatile(obj);
175 obj->write_domain = I915_GEM_DOMAIN_CPU;
176 obj->read_domains = I915_GEM_DOMAIN_CPU;
177 obj->cache_level = I915_CACHE_NONE;
179 obj->mm.page_mask = page_mask;
181 return obj;
184 static int fake_get_huge_pages(struct drm_i915_gem_object *obj)
186 struct drm_i915_private *i915 = to_i915(obj->base.dev);
187 const u64 max_len = rounddown_pow_of_two(UINT_MAX);
188 struct sg_table *st;
189 struct scatterlist *sg;
190 unsigned int sg_page_sizes;
191 u64 rem;
193 st = kmalloc(sizeof(*st), GFP);
194 if (!st)
195 return -ENOMEM;
197 if (sg_alloc_table(st, obj->base.size >> PAGE_SHIFT, GFP)) {
198 kfree(st);
199 return -ENOMEM;
202 /* Use optimal page sized chunks to fill in the sg table */
203 rem = obj->base.size;
204 sg = st->sgl;
205 st->nents = 0;
206 sg_page_sizes = 0;
207 do {
208 unsigned int page_size = get_largest_page_size(i915, rem);
209 unsigned int len = min(page_size * div_u64(rem, page_size),
210 max_len);
212 GEM_BUG_ON(!page_size);
214 sg->offset = 0;
215 sg->length = len;
216 sg_dma_len(sg) = len;
217 sg_dma_address(sg) = page_size;
219 sg_page_sizes |= len;
221 st->nents++;
223 rem -= len;
224 if (!rem) {
225 sg_mark_end(sg);
226 break;
229 sg = sg_next(sg);
230 } while (1);
232 i915_sg_trim(st);
234 __i915_gem_object_set_pages(obj, st, sg_page_sizes);
236 return 0;
239 static int fake_get_huge_pages_single(struct drm_i915_gem_object *obj)
241 struct drm_i915_private *i915 = to_i915(obj->base.dev);
242 struct sg_table *st;
243 struct scatterlist *sg;
244 unsigned int page_size;
246 st = kmalloc(sizeof(*st), GFP);
247 if (!st)
248 return -ENOMEM;
250 if (sg_alloc_table(st, 1, GFP)) {
251 kfree(st);
252 return -ENOMEM;
255 sg = st->sgl;
256 st->nents = 1;
258 page_size = get_largest_page_size(i915, obj->base.size);
259 GEM_BUG_ON(!page_size);
261 sg->offset = 0;
262 sg->length = obj->base.size;
263 sg_dma_len(sg) = obj->base.size;
264 sg_dma_address(sg) = page_size;
266 __i915_gem_object_set_pages(obj, st, sg->length);
268 return 0;
269 #undef GFP
272 static void fake_free_huge_pages(struct drm_i915_gem_object *obj,
273 struct sg_table *pages)
275 sg_free_table(pages);
276 kfree(pages);
279 static void fake_put_huge_pages(struct drm_i915_gem_object *obj,
280 struct sg_table *pages)
282 fake_free_huge_pages(obj, pages);
283 obj->mm.dirty = false;
286 static const struct drm_i915_gem_object_ops fake_ops = {
287 .name = "fake-gem",
288 .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
289 .get_pages = fake_get_huge_pages,
290 .put_pages = fake_put_huge_pages,
293 static const struct drm_i915_gem_object_ops fake_ops_single = {
294 .name = "fake-gem",
295 .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
296 .get_pages = fake_get_huge_pages_single,
297 .put_pages = fake_put_huge_pages,
300 static struct drm_i915_gem_object *
301 fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single)
303 static struct lock_class_key lock_class;
304 struct drm_i915_gem_object *obj;
306 GEM_BUG_ON(!size);
307 GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE));
309 if (size >> PAGE_SHIFT > UINT_MAX)
310 return ERR_PTR(-E2BIG);
312 if (overflows_type(size, obj->base.size))
313 return ERR_PTR(-E2BIG);
315 obj = i915_gem_object_alloc();
316 if (!obj)
317 return ERR_PTR(-ENOMEM);
319 drm_gem_private_object_init(&i915->drm, &obj->base, size);
321 if (single)
322 i915_gem_object_init(obj, &fake_ops_single, &lock_class);
323 else
324 i915_gem_object_init(obj, &fake_ops, &lock_class);
326 i915_gem_object_set_volatile(obj);
328 obj->write_domain = I915_GEM_DOMAIN_CPU;
329 obj->read_domains = I915_GEM_DOMAIN_CPU;
330 obj->cache_level = I915_CACHE_NONE;
332 return obj;
335 static int igt_check_page_sizes(struct i915_vma *vma)
337 struct drm_i915_private *i915 = vma->vm->i915;
338 unsigned int supported = INTEL_INFO(i915)->page_sizes;
339 struct drm_i915_gem_object *obj = vma->obj;
340 int err;
342 /* We have to wait for the async bind to complete before our asserts */
343 err = i915_vma_sync(vma);
344 if (err)
345 return err;
347 if (!HAS_PAGE_SIZES(i915, vma->page_sizes.sg)) {
348 pr_err("unsupported page_sizes.sg=%u, supported=%u\n",
349 vma->page_sizes.sg & ~supported, supported);
350 err = -EINVAL;
353 if (!HAS_PAGE_SIZES(i915, vma->page_sizes.gtt)) {
354 pr_err("unsupported page_sizes.gtt=%u, supported=%u\n",
355 vma->page_sizes.gtt & ~supported, supported);
356 err = -EINVAL;
359 if (vma->page_sizes.phys != obj->mm.page_sizes.phys) {
360 pr_err("vma->page_sizes.phys(%u) != obj->mm.page_sizes.phys(%u)\n",
361 vma->page_sizes.phys, obj->mm.page_sizes.phys);
362 err = -EINVAL;
365 if (vma->page_sizes.sg != obj->mm.page_sizes.sg) {
366 pr_err("vma->page_sizes.sg(%u) != obj->mm.page_sizes.sg(%u)\n",
367 vma->page_sizes.sg, obj->mm.page_sizes.sg);
368 err = -EINVAL;
371 if (obj->mm.page_sizes.gtt) {
372 pr_err("obj->page_sizes.gtt(%u) should never be set\n",
373 obj->mm.page_sizes.gtt);
374 err = -EINVAL;
377 return err;
380 static int igt_mock_exhaust_device_supported_pages(void *arg)
382 struct i915_ppgtt *ppgtt = arg;
383 struct drm_i915_private *i915 = ppgtt->vm.i915;
384 unsigned int saved_mask = INTEL_INFO(i915)->page_sizes;
385 struct drm_i915_gem_object *obj;
386 struct i915_vma *vma;
387 int i, j, single;
388 int err;
391 * Sanity check creating objects with every valid page support
392 * combination for our mock device.
395 for (i = 1; i < BIT(ARRAY_SIZE(page_sizes)); i++) {
396 unsigned int combination = SZ_4K; /* Required for ppGTT */
398 for (j = 0; j < ARRAY_SIZE(page_sizes); j++) {
399 if (i & BIT(j))
400 combination |= page_sizes[j];
403 mkwrite_device_info(i915)->page_sizes = combination;
405 for (single = 0; single <= 1; ++single) {
406 obj = fake_huge_pages_object(i915, combination, !!single);
407 if (IS_ERR(obj)) {
408 err = PTR_ERR(obj);
409 goto out_device;
412 if (obj->base.size != combination) {
413 pr_err("obj->base.size=%zu, expected=%u\n",
414 obj->base.size, combination);
415 err = -EINVAL;
416 goto out_put;
419 vma = i915_vma_instance(obj, &ppgtt->vm, NULL);
420 if (IS_ERR(vma)) {
421 err = PTR_ERR(vma);
422 goto out_put;
425 err = i915_vma_pin(vma, 0, 0, PIN_USER);
426 if (err)
427 goto out_put;
429 err = igt_check_page_sizes(vma);
431 if (vma->page_sizes.sg != combination) {
432 pr_err("page_sizes.sg=%u, expected=%u\n",
433 vma->page_sizes.sg, combination);
434 err = -EINVAL;
437 i915_vma_unpin(vma);
438 i915_gem_object_put(obj);
440 if (err)
441 goto out_device;
445 goto out_device;
447 out_put:
448 i915_gem_object_put(obj);
449 out_device:
450 mkwrite_device_info(i915)->page_sizes = saved_mask;
452 return err;
455 static int igt_mock_memory_region_huge_pages(void *arg)
457 const unsigned int flags[] = { 0, I915_BO_ALLOC_CONTIGUOUS };
458 struct i915_ppgtt *ppgtt = arg;
459 struct drm_i915_private *i915 = ppgtt->vm.i915;
460 unsigned long supported = INTEL_INFO(i915)->page_sizes;
461 struct intel_memory_region *mem;
462 struct drm_i915_gem_object *obj;
463 struct i915_vma *vma;
464 int bit;
465 int err = 0;
467 mem = mock_region_create(i915, 0, SZ_2G, I915_GTT_PAGE_SIZE_4K, 0);
468 if (IS_ERR(mem)) {
469 pr_err("%s failed to create memory region\n", __func__);
470 return PTR_ERR(mem);
473 for_each_set_bit(bit, &supported, ilog2(I915_GTT_MAX_PAGE_SIZE) + 1) {
474 unsigned int page_size = BIT(bit);
475 resource_size_t phys;
476 int i;
478 for (i = 0; i < ARRAY_SIZE(flags); ++i) {
479 obj = i915_gem_object_create_region(mem, page_size,
480 flags[i]);
481 if (IS_ERR(obj)) {
482 err = PTR_ERR(obj);
483 goto out_region;
486 vma = i915_vma_instance(obj, &ppgtt->vm, NULL);
487 if (IS_ERR(vma)) {
488 err = PTR_ERR(vma);
489 goto out_put;
492 err = i915_vma_pin(vma, 0, 0, PIN_USER);
493 if (err)
494 goto out_put;
496 err = igt_check_page_sizes(vma);
497 if (err)
498 goto out_unpin;
500 phys = i915_gem_object_get_dma_address(obj, 0);
501 if (!IS_ALIGNED(phys, page_size)) {
502 pr_err("%s addr misaligned(%pa) page_size=%u\n",
503 __func__, &phys, page_size);
504 err = -EINVAL;
505 goto out_unpin;
508 if (vma->page_sizes.gtt != page_size) {
509 pr_err("%s page_sizes.gtt=%u, expected=%u\n",
510 __func__, vma->page_sizes.gtt,
511 page_size);
512 err = -EINVAL;
513 goto out_unpin;
516 i915_vma_unpin(vma);
517 __i915_gem_object_put_pages(obj);
518 i915_gem_object_put(obj);
522 goto out_region;
524 out_unpin:
525 i915_vma_unpin(vma);
526 out_put:
527 i915_gem_object_put(obj);
528 out_region:
529 intel_memory_region_put(mem);
530 return err;
533 static int igt_mock_ppgtt_misaligned_dma(void *arg)
535 struct i915_ppgtt *ppgtt = arg;
536 struct drm_i915_private *i915 = ppgtt->vm.i915;
537 unsigned long supported = INTEL_INFO(i915)->page_sizes;
538 struct drm_i915_gem_object *obj;
539 int bit;
540 int err;
543 * Sanity check dma misalignment for huge pages -- the dma addresses we
544 * insert into the paging structures need to always respect the page
545 * size alignment.
548 bit = ilog2(I915_GTT_PAGE_SIZE_64K);
550 for_each_set_bit_from(bit, &supported,
551 ilog2(I915_GTT_MAX_PAGE_SIZE) + 1) {
552 IGT_TIMEOUT(end_time);
553 unsigned int page_size = BIT(bit);
554 unsigned int flags = PIN_USER | PIN_OFFSET_FIXED;
555 unsigned int offset;
556 unsigned int size =
557 round_up(page_size, I915_GTT_PAGE_SIZE_2M) << 1;
558 struct i915_vma *vma;
560 obj = fake_huge_pages_object(i915, size, true);
561 if (IS_ERR(obj))
562 return PTR_ERR(obj);
564 if (obj->base.size != size) {
565 pr_err("obj->base.size=%zu, expected=%u\n",
566 obj->base.size, size);
567 err = -EINVAL;
568 goto out_put;
571 err = i915_gem_object_pin_pages(obj);
572 if (err)
573 goto out_put;
575 /* Force the page size for this object */
576 obj->mm.page_sizes.sg = page_size;
578 vma = i915_vma_instance(obj, &ppgtt->vm, NULL);
579 if (IS_ERR(vma)) {
580 err = PTR_ERR(vma);
581 goto out_unpin;
584 err = i915_vma_pin(vma, 0, 0, flags);
585 if (err)
586 goto out_unpin;
589 err = igt_check_page_sizes(vma);
591 if (vma->page_sizes.gtt != page_size) {
592 pr_err("page_sizes.gtt=%u, expected %u\n",
593 vma->page_sizes.gtt, page_size);
594 err = -EINVAL;
597 i915_vma_unpin(vma);
599 if (err)
600 goto out_unpin;
603 * Try all the other valid offsets until the next
604 * boundary -- should always fall back to using 4K
605 * pages.
607 for (offset = 4096; offset < page_size; offset += 4096) {
608 err = i915_vma_unbind(vma);
609 if (err)
610 goto out_unpin;
612 err = i915_vma_pin(vma, 0, 0, flags | offset);
613 if (err)
614 goto out_unpin;
616 err = igt_check_page_sizes(vma);
618 if (vma->page_sizes.gtt != I915_GTT_PAGE_SIZE_4K) {
619 pr_err("page_sizes.gtt=%u, expected %llu\n",
620 vma->page_sizes.gtt, I915_GTT_PAGE_SIZE_4K);
621 err = -EINVAL;
624 i915_vma_unpin(vma);
626 if (err)
627 goto out_unpin;
629 if (igt_timeout(end_time,
630 "%s timed out at offset %x with page-size %x\n",
631 __func__, offset, page_size))
632 break;
635 i915_gem_object_unpin_pages(obj);
636 __i915_gem_object_put_pages(obj);
637 i915_gem_object_put(obj);
640 return 0;
642 out_unpin:
643 i915_gem_object_unpin_pages(obj);
644 out_put:
645 i915_gem_object_put(obj);
647 return err;
650 static void close_object_list(struct list_head *objects,
651 struct i915_ppgtt *ppgtt)
653 struct drm_i915_gem_object *obj, *on;
655 list_for_each_entry_safe(obj, on, objects, st_link) {
656 list_del(&obj->st_link);
657 i915_gem_object_unpin_pages(obj);
658 __i915_gem_object_put_pages(obj);
659 i915_gem_object_put(obj);
663 static int igt_mock_ppgtt_huge_fill(void *arg)
665 struct i915_ppgtt *ppgtt = arg;
666 struct drm_i915_private *i915 = ppgtt->vm.i915;
667 unsigned long max_pages = ppgtt->vm.total >> PAGE_SHIFT;
668 unsigned long page_num;
669 bool single = false;
670 LIST_HEAD(objects);
671 IGT_TIMEOUT(end_time);
672 int err = -ENODEV;
674 for_each_prime_number_from(page_num, 1, max_pages) {
675 struct drm_i915_gem_object *obj;
676 u64 size = page_num << PAGE_SHIFT;
677 struct i915_vma *vma;
678 unsigned int expected_gtt = 0;
679 int i;
681 obj = fake_huge_pages_object(i915, size, single);
682 if (IS_ERR(obj)) {
683 err = PTR_ERR(obj);
684 break;
687 if (obj->base.size != size) {
688 pr_err("obj->base.size=%zd, expected=%llu\n",
689 obj->base.size, size);
690 i915_gem_object_put(obj);
691 err = -EINVAL;
692 break;
695 err = i915_gem_object_pin_pages(obj);
696 if (err) {
697 i915_gem_object_put(obj);
698 break;
701 list_add(&obj->st_link, &objects);
703 vma = i915_vma_instance(obj, &ppgtt->vm, NULL);
704 if (IS_ERR(vma)) {
705 err = PTR_ERR(vma);
706 break;
709 err = i915_vma_pin(vma, 0, 0, PIN_USER);
710 if (err)
711 break;
713 err = igt_check_page_sizes(vma);
714 if (err) {
715 i915_vma_unpin(vma);
716 break;
720 * Figure out the expected gtt page size knowing that we go from
721 * largest to smallest page size sg chunks, and that we align to
722 * the largest page size.
724 for (i = 0; i < ARRAY_SIZE(page_sizes); ++i) {
725 unsigned int page_size = page_sizes[i];
727 if (HAS_PAGE_SIZES(i915, page_size) &&
728 size >= page_size) {
729 expected_gtt |= page_size;
730 size &= page_size-1;
734 GEM_BUG_ON(!expected_gtt);
735 GEM_BUG_ON(size);
737 if (expected_gtt & I915_GTT_PAGE_SIZE_4K)
738 expected_gtt &= ~I915_GTT_PAGE_SIZE_64K;
740 i915_vma_unpin(vma);
742 if (vma->page_sizes.sg & I915_GTT_PAGE_SIZE_64K) {
743 if (!IS_ALIGNED(vma->node.start,
744 I915_GTT_PAGE_SIZE_2M)) {
745 pr_err("node.start(%llx) not aligned to 2M\n",
746 vma->node.start);
747 err = -EINVAL;
748 break;
751 if (!IS_ALIGNED(vma->node.size,
752 I915_GTT_PAGE_SIZE_2M)) {
753 pr_err("node.size(%llx) not aligned to 2M\n",
754 vma->node.size);
755 err = -EINVAL;
756 break;
760 if (vma->page_sizes.gtt != expected_gtt) {
761 pr_err("gtt=%u, expected=%u, size=%zd, single=%s\n",
762 vma->page_sizes.gtt, expected_gtt,
763 obj->base.size, yesno(!!single));
764 err = -EINVAL;
765 break;
768 if (igt_timeout(end_time,
769 "%s timed out at size %zd\n",
770 __func__, obj->base.size))
771 break;
773 single = !single;
776 close_object_list(&objects, ppgtt);
778 if (err == -ENOMEM || err == -ENOSPC)
779 err = 0;
781 return err;
784 static int igt_mock_ppgtt_64K(void *arg)
786 struct i915_ppgtt *ppgtt = arg;
787 struct drm_i915_private *i915 = ppgtt->vm.i915;
788 struct drm_i915_gem_object *obj;
789 const struct object_info {
790 unsigned int size;
791 unsigned int gtt;
792 unsigned int offset;
793 } objects[] = {
794 /* Cases with forced padding/alignment */
796 .size = SZ_64K,
797 .gtt = I915_GTT_PAGE_SIZE_64K,
798 .offset = 0,
801 .size = SZ_64K + SZ_4K,
802 .gtt = I915_GTT_PAGE_SIZE_4K,
803 .offset = 0,
806 .size = SZ_64K - SZ_4K,
807 .gtt = I915_GTT_PAGE_SIZE_4K,
808 .offset = 0,
811 .size = SZ_2M,
812 .gtt = I915_GTT_PAGE_SIZE_64K,
813 .offset = 0,
816 .size = SZ_2M - SZ_4K,
817 .gtt = I915_GTT_PAGE_SIZE_4K,
818 .offset = 0,
821 .size = SZ_2M + SZ_4K,
822 .gtt = I915_GTT_PAGE_SIZE_64K | I915_GTT_PAGE_SIZE_4K,
823 .offset = 0,
826 .size = SZ_2M + SZ_64K,
827 .gtt = I915_GTT_PAGE_SIZE_64K,
828 .offset = 0,
831 .size = SZ_2M - SZ_64K,
832 .gtt = I915_GTT_PAGE_SIZE_64K,
833 .offset = 0,
835 /* Try without any forced padding/alignment */
837 .size = SZ_64K,
838 .offset = SZ_2M,
839 .gtt = I915_GTT_PAGE_SIZE_4K,
842 .size = SZ_128K,
843 .offset = SZ_2M - SZ_64K,
844 .gtt = I915_GTT_PAGE_SIZE_4K,
847 struct i915_vma *vma;
848 int i, single;
849 int err;
852 * Sanity check some of the trickiness with 64K pages -- either we can
853 * safely mark the whole page-table(2M block) as 64K, or we have to
854 * always fallback to 4K.
857 if (!HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K))
858 return 0;
860 for (i = 0; i < ARRAY_SIZE(objects); ++i) {
861 unsigned int size = objects[i].size;
862 unsigned int expected_gtt = objects[i].gtt;
863 unsigned int offset = objects[i].offset;
864 unsigned int flags = PIN_USER;
866 for (single = 0; single <= 1; single++) {
867 obj = fake_huge_pages_object(i915, size, !!single);
868 if (IS_ERR(obj))
869 return PTR_ERR(obj);
871 err = i915_gem_object_pin_pages(obj);
872 if (err)
873 goto out_object_put;
876 * Disable 2M pages -- We only want to use 64K/4K pages
877 * for this test.
879 obj->mm.page_sizes.sg &= ~I915_GTT_PAGE_SIZE_2M;
881 vma = i915_vma_instance(obj, &ppgtt->vm, NULL);
882 if (IS_ERR(vma)) {
883 err = PTR_ERR(vma);
884 goto out_object_unpin;
887 if (offset)
888 flags |= PIN_OFFSET_FIXED | offset;
890 err = i915_vma_pin(vma, 0, 0, flags);
891 if (err)
892 goto out_object_unpin;
894 err = igt_check_page_sizes(vma);
895 if (err)
896 goto out_vma_unpin;
898 if (!offset && vma->page_sizes.sg & I915_GTT_PAGE_SIZE_64K) {
899 if (!IS_ALIGNED(vma->node.start,
900 I915_GTT_PAGE_SIZE_2M)) {
901 pr_err("node.start(%llx) not aligned to 2M\n",
902 vma->node.start);
903 err = -EINVAL;
904 goto out_vma_unpin;
907 if (!IS_ALIGNED(vma->node.size,
908 I915_GTT_PAGE_SIZE_2M)) {
909 pr_err("node.size(%llx) not aligned to 2M\n",
910 vma->node.size);
911 err = -EINVAL;
912 goto out_vma_unpin;
916 if (vma->page_sizes.gtt != expected_gtt) {
917 pr_err("gtt=%u, expected=%u, i=%d, single=%s\n",
918 vma->page_sizes.gtt, expected_gtt, i,
919 yesno(!!single));
920 err = -EINVAL;
921 goto out_vma_unpin;
924 i915_vma_unpin(vma);
925 i915_gem_object_unpin_pages(obj);
926 __i915_gem_object_put_pages(obj);
927 i915_gem_object_put(obj);
931 return 0;
933 out_vma_unpin:
934 i915_vma_unpin(vma);
935 out_object_unpin:
936 i915_gem_object_unpin_pages(obj);
937 out_object_put:
938 i915_gem_object_put(obj);
940 return err;
943 static int gpu_write(struct intel_context *ce,
944 struct i915_vma *vma,
945 u32 dw,
946 u32 val)
948 int err;
950 i915_gem_object_lock(vma->obj, NULL);
951 err = i915_gem_object_set_to_gtt_domain(vma->obj, true);
952 i915_gem_object_unlock(vma->obj);
953 if (err)
954 return err;
956 return igt_gpu_fill_dw(ce, vma, dw * sizeof(u32),
957 vma->size >> PAGE_SHIFT, val);
960 static int
961 __cpu_check_shmem(struct drm_i915_gem_object *obj, u32 dword, u32 val)
963 unsigned int needs_flush;
964 unsigned long n;
965 int err;
967 i915_gem_object_lock(obj, NULL);
968 err = i915_gem_object_prepare_read(obj, &needs_flush);
969 if (err)
970 goto err_unlock;
972 for (n = 0; n < obj->base.size >> PAGE_SHIFT; ++n) {
973 u32 *ptr = kmap_atomic(i915_gem_object_get_page(obj, n));
975 if (needs_flush & CLFLUSH_BEFORE)
976 drm_clflush_virt_range(ptr, PAGE_SIZE);
978 if (ptr[dword] != val) {
979 pr_err("n=%lu ptr[%u]=%u, val=%u\n",
980 n, dword, ptr[dword], val);
981 kunmap_atomic(ptr);
982 err = -EINVAL;
983 break;
986 kunmap_atomic(ptr);
989 i915_gem_object_finish_access(obj);
990 err_unlock:
991 i915_gem_object_unlock(obj);
993 return err;
996 static int __cpu_check_vmap(struct drm_i915_gem_object *obj, u32 dword, u32 val)
998 unsigned long n = obj->base.size >> PAGE_SHIFT;
999 u32 *ptr;
1000 int err;
1002 err = i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT);
1003 if (err)
1004 return err;
1006 ptr = i915_gem_object_pin_map(obj, I915_MAP_WC);
1007 if (IS_ERR(ptr))
1008 return PTR_ERR(ptr);
1010 ptr += dword;
1011 while (n--) {
1012 if (*ptr != val) {
1013 pr_err("base[%u]=%08x, val=%08x\n",
1014 dword, *ptr, val);
1015 err = -EINVAL;
1016 break;
1019 ptr += PAGE_SIZE / sizeof(*ptr);
1022 i915_gem_object_unpin_map(obj);
1023 return err;
1026 static int cpu_check(struct drm_i915_gem_object *obj, u32 dword, u32 val)
1028 if (i915_gem_object_has_struct_page(obj))
1029 return __cpu_check_shmem(obj, dword, val);
1030 else
1031 return __cpu_check_vmap(obj, dword, val);
1034 static int __igt_write_huge(struct intel_context *ce,
1035 struct drm_i915_gem_object *obj,
1036 u64 size, u64 offset,
1037 u32 dword, u32 val)
1039 unsigned int flags = PIN_USER | PIN_OFFSET_FIXED;
1040 struct i915_vma *vma;
1041 int err;
1043 vma = i915_vma_instance(obj, ce->vm, NULL);
1044 if (IS_ERR(vma))
1045 return PTR_ERR(vma);
1047 err = i915_vma_unbind(vma);
1048 if (err)
1049 return err;
1051 err = i915_vma_pin(vma, size, 0, flags | offset);
1052 if (err) {
1054 * The ggtt may have some pages reserved so
1055 * refrain from erroring out.
1057 if (err == -ENOSPC && i915_is_ggtt(ce->vm))
1058 err = 0;
1060 return err;
1063 err = igt_check_page_sizes(vma);
1064 if (err)
1065 goto out_vma_unpin;
1067 err = gpu_write(ce, vma, dword, val);
1068 if (err) {
1069 pr_err("gpu-write failed at offset=%llx\n", offset);
1070 goto out_vma_unpin;
1073 err = cpu_check(obj, dword, val);
1074 if (err) {
1075 pr_err("cpu-check failed at offset=%llx\n", offset);
1076 goto out_vma_unpin;
1079 out_vma_unpin:
1080 i915_vma_unpin(vma);
1081 return err;
1084 static int igt_write_huge(struct i915_gem_context *ctx,
1085 struct drm_i915_gem_object *obj)
1087 struct i915_gem_engines *engines;
1088 struct i915_gem_engines_iter it;
1089 struct intel_context *ce;
1090 I915_RND_STATE(prng);
1091 IGT_TIMEOUT(end_time);
1092 unsigned int max_page_size;
1093 unsigned int count;
1094 u64 max;
1095 u64 num;
1096 u64 size;
1097 int *order;
1098 int i, n;
1099 int err = 0;
1101 GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
1103 size = obj->base.size;
1104 if (obj->mm.page_sizes.sg & I915_GTT_PAGE_SIZE_64K)
1105 size = round_up(size, I915_GTT_PAGE_SIZE_2M);
1107 n = 0;
1108 count = 0;
1109 max = U64_MAX;
1110 for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
1111 count++;
1112 if (!intel_engine_can_store_dword(ce->engine))
1113 continue;
1115 max = min(max, ce->vm->total);
1116 n++;
1118 i915_gem_context_unlock_engines(ctx);
1119 if (!n)
1120 return 0;
1123 * To keep things interesting when alternating between engines in our
1124 * randomized order, lets also make feeding to the same engine a few
1125 * times in succession a possibility by enlarging the permutation array.
1127 order = i915_random_order(count * count, &prng);
1128 if (!order)
1129 return -ENOMEM;
1131 max_page_size = rounddown_pow_of_two(obj->mm.page_sizes.sg);
1132 max = div_u64(max - size, max_page_size);
1135 * Try various offsets in an ascending/descending fashion until we
1136 * timeout -- we want to avoid issues hidden by effectively always using
1137 * offset = 0.
1139 i = 0;
1140 engines = i915_gem_context_lock_engines(ctx);
1141 for_each_prime_number_from(num, 0, max) {
1142 u64 offset_low = num * max_page_size;
1143 u64 offset_high = (max - num) * max_page_size;
1144 u32 dword = offset_in_page(num) / 4;
1145 struct intel_context *ce;
1147 ce = engines->engines[order[i] % engines->num_engines];
1148 i = (i + 1) % (count * count);
1149 if (!ce || !intel_engine_can_store_dword(ce->engine))
1150 continue;
1153 * In order to utilize 64K pages we need to both pad the vma
1154 * size and ensure the vma offset is at the start of the pt
1155 * boundary, however to improve coverage we opt for testing both
1156 * aligned and unaligned offsets.
1158 if (obj->mm.page_sizes.sg & I915_GTT_PAGE_SIZE_64K)
1159 offset_low = round_down(offset_low,
1160 I915_GTT_PAGE_SIZE_2M);
1162 err = __igt_write_huge(ce, obj, size, offset_low,
1163 dword, num + 1);
1164 if (err)
1165 break;
1167 err = __igt_write_huge(ce, obj, size, offset_high,
1168 dword, num + 1);
1169 if (err)
1170 break;
1172 if (igt_timeout(end_time,
1173 "%s timed out on %s, offset_low=%llx offset_high=%llx, max_page_size=%x\n",
1174 __func__, ce->engine->name, offset_low, offset_high,
1175 max_page_size))
1176 break;
1178 i915_gem_context_unlock_engines(ctx);
1180 kfree(order);
1182 return err;
1185 typedef struct drm_i915_gem_object *
1186 (*igt_create_fn)(struct drm_i915_private *i915, u32 size, u32 flags);
1188 static inline bool igt_can_allocate_thp(struct drm_i915_private *i915)
1190 return i915->mm.gemfs && has_transparent_hugepage();
1193 static struct drm_i915_gem_object *
1194 igt_create_shmem(struct drm_i915_private *i915, u32 size, u32 flags)
1196 if (!igt_can_allocate_thp(i915)) {
1197 pr_info("%s missing THP support, skipping\n", __func__);
1198 return ERR_PTR(-ENODEV);
1201 return i915_gem_object_create_shmem(i915, size);
1204 static struct drm_i915_gem_object *
1205 igt_create_internal(struct drm_i915_private *i915, u32 size, u32 flags)
1207 return i915_gem_object_create_internal(i915, size);
1210 static struct drm_i915_gem_object *
1211 igt_create_system(struct drm_i915_private *i915, u32 size, u32 flags)
1213 return huge_pages_object(i915, size, size);
1216 static struct drm_i915_gem_object *
1217 igt_create_local(struct drm_i915_private *i915, u32 size, u32 flags)
1219 return i915_gem_object_create_lmem(i915, size, flags);
1222 static u32 igt_random_size(struct rnd_state *prng,
1223 u32 min_page_size,
1224 u32 max_page_size)
1226 u64 mask;
1227 u32 size;
1229 GEM_BUG_ON(!is_power_of_2(min_page_size));
1230 GEM_BUG_ON(!is_power_of_2(max_page_size));
1231 GEM_BUG_ON(min_page_size < PAGE_SIZE);
1232 GEM_BUG_ON(min_page_size > max_page_size);
1234 mask = ((max_page_size << 1ULL) - 1) & PAGE_MASK;
1235 size = prandom_u32_state(prng) & mask;
1236 if (size < min_page_size)
1237 size |= min_page_size;
1239 return size;
1242 static int igt_ppgtt_smoke_huge(void *arg)
1244 struct i915_gem_context *ctx = arg;
1245 struct drm_i915_private *i915 = ctx->i915;
1246 struct drm_i915_gem_object *obj;
1247 I915_RND_STATE(prng);
1248 struct {
1249 igt_create_fn fn;
1250 u32 min;
1251 u32 max;
1252 } backends[] = {
1253 { igt_create_internal, SZ_64K, SZ_2M, },
1254 { igt_create_shmem, SZ_64K, SZ_32M, },
1255 { igt_create_local, SZ_64K, SZ_1G, },
1257 int err;
1258 int i;
1261 * Sanity check that the HW uses huge pages correctly through our
1262 * various backends -- ensure that our writes land in the right place.
1265 for (i = 0; i < ARRAY_SIZE(backends); ++i) {
1266 u32 min = backends[i].min;
1267 u32 max = backends[i].max;
1268 u32 size = max;
1269 try_again:
1270 size = igt_random_size(&prng, min, rounddown_pow_of_two(size));
1272 obj = backends[i].fn(i915, size, 0);
1273 if (IS_ERR(obj)) {
1274 err = PTR_ERR(obj);
1275 if (err == -E2BIG) {
1276 size >>= 1;
1277 goto try_again;
1278 } else if (err == -ENODEV) {
1279 err = 0;
1280 continue;
1283 return err;
1286 err = i915_gem_object_pin_pages(obj);
1287 if (err) {
1288 if (err == -ENXIO || err == -E2BIG) {
1289 i915_gem_object_put(obj);
1290 size >>= 1;
1291 goto try_again;
1293 goto out_put;
1296 if (obj->mm.page_sizes.phys < min) {
1297 pr_info("%s unable to allocate huge-page(s) with size=%u, i=%d\n",
1298 __func__, size, i);
1299 err = -ENOMEM;
1300 goto out_unpin;
1303 err = igt_write_huge(ctx, obj);
1304 if (err) {
1305 pr_err("%s write-huge failed with size=%u, i=%d\n",
1306 __func__, size, i);
1308 out_unpin:
1309 i915_gem_object_unpin_pages(obj);
1310 __i915_gem_object_put_pages(obj);
1311 out_put:
1312 i915_gem_object_put(obj);
1314 if (err == -ENOMEM || err == -ENXIO)
1315 err = 0;
1317 if (err)
1318 break;
1320 cond_resched();
1323 return err;
1326 static int igt_ppgtt_sanity_check(void *arg)
1328 struct i915_gem_context *ctx = arg;
1329 struct drm_i915_private *i915 = ctx->i915;
1330 unsigned int supported = INTEL_INFO(i915)->page_sizes;
1331 struct {
1332 igt_create_fn fn;
1333 unsigned int flags;
1334 } backends[] = {
1335 { igt_create_system, 0, },
1336 { igt_create_local, I915_BO_ALLOC_CONTIGUOUS, },
1338 struct {
1339 u32 size;
1340 u32 pages;
1341 } combos[] = {
1342 { SZ_64K, SZ_64K },
1343 { SZ_2M, SZ_2M },
1344 { SZ_2M, SZ_64K },
1345 { SZ_2M - SZ_64K, SZ_64K },
1346 { SZ_2M - SZ_4K, SZ_64K | SZ_4K },
1347 { SZ_2M + SZ_4K, SZ_64K | SZ_4K },
1348 { SZ_2M + SZ_4K, SZ_2M | SZ_4K },
1349 { SZ_2M + SZ_64K, SZ_2M | SZ_64K },
1351 int i, j;
1352 int err;
1354 if (supported == I915_GTT_PAGE_SIZE_4K)
1355 return 0;
1358 * Sanity check that the HW behaves with a limited set of combinations.
1359 * We already have a bunch of randomised testing, which should give us
1360 * a decent amount of variation between runs, however we should keep
1361 * this to limit the chances of introducing a temporary regression, by
1362 * testing the most obvious cases that might make something blow up.
1365 for (i = 0; i < ARRAY_SIZE(backends); ++i) {
1366 for (j = 0; j < ARRAY_SIZE(combos); ++j) {
1367 struct drm_i915_gem_object *obj;
1368 u32 size = combos[j].size;
1369 u32 pages = combos[j].pages;
1371 obj = backends[i].fn(i915, size, backends[i].flags);
1372 if (IS_ERR(obj)) {
1373 err = PTR_ERR(obj);
1374 if (err == -ENODEV) {
1375 pr_info("Device lacks local memory, skipping\n");
1376 err = 0;
1377 break;
1380 return err;
1383 err = i915_gem_object_pin_pages(obj);
1384 if (err) {
1385 i915_gem_object_put(obj);
1386 goto out;
1389 GEM_BUG_ON(pages > obj->base.size);
1390 pages = pages & supported;
1392 if (pages)
1393 obj->mm.page_sizes.sg = pages;
1395 err = igt_write_huge(ctx, obj);
1397 i915_gem_object_unpin_pages(obj);
1398 __i915_gem_object_put_pages(obj);
1399 i915_gem_object_put(obj);
1401 if (err) {
1402 pr_err("%s write-huge failed with size=%u pages=%u i=%d, j=%d\n",
1403 __func__, size, pages, i, j);
1404 goto out;
1408 cond_resched();
1411 out:
1412 if (err == -ENOMEM)
1413 err = 0;
1415 return err;
1418 static int igt_tmpfs_fallback(void *arg)
1420 struct i915_gem_context *ctx = arg;
1421 struct drm_i915_private *i915 = ctx->i915;
1422 struct vfsmount *gemfs = i915->mm.gemfs;
1423 struct i915_address_space *vm = i915_gem_context_get_vm_rcu(ctx);
1424 struct drm_i915_gem_object *obj;
1425 struct i915_vma *vma;
1426 u32 *vaddr;
1427 int err = 0;
1430 * Make sure that we don't burst into a ball of flames upon falling back
1431 * to tmpfs, which we rely on if on the off-chance we encouter a failure
1432 * when setting up gemfs.
1435 i915->mm.gemfs = NULL;
1437 obj = i915_gem_object_create_shmem(i915, PAGE_SIZE);
1438 if (IS_ERR(obj)) {
1439 err = PTR_ERR(obj);
1440 goto out_restore;
1443 vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
1444 if (IS_ERR(vaddr)) {
1445 err = PTR_ERR(vaddr);
1446 goto out_put;
1448 *vaddr = 0xdeadbeaf;
1450 __i915_gem_object_flush_map(obj, 0, 64);
1451 i915_gem_object_unpin_map(obj);
1453 vma = i915_vma_instance(obj, vm, NULL);
1454 if (IS_ERR(vma)) {
1455 err = PTR_ERR(vma);
1456 goto out_put;
1459 err = i915_vma_pin(vma, 0, 0, PIN_USER);
1460 if (err)
1461 goto out_put;
1463 err = igt_check_page_sizes(vma);
1465 i915_vma_unpin(vma);
1466 out_put:
1467 i915_gem_object_put(obj);
1468 out_restore:
1469 i915->mm.gemfs = gemfs;
1471 i915_vm_put(vm);
1472 return err;
1475 static int igt_shrink_thp(void *arg)
1477 struct i915_gem_context *ctx = arg;
1478 struct drm_i915_private *i915 = ctx->i915;
1479 struct i915_address_space *vm = i915_gem_context_get_vm_rcu(ctx);
1480 struct drm_i915_gem_object *obj;
1481 struct i915_gem_engines_iter it;
1482 struct intel_context *ce;
1483 struct i915_vma *vma;
1484 unsigned int flags = PIN_USER;
1485 unsigned int n;
1486 int err = 0;
1489 * Sanity check shrinking huge-paged object -- make sure nothing blows
1490 * up.
1493 if (!igt_can_allocate_thp(i915)) {
1494 pr_info("missing THP support, skipping\n");
1495 goto out_vm;
1498 obj = i915_gem_object_create_shmem(i915, SZ_2M);
1499 if (IS_ERR(obj)) {
1500 err = PTR_ERR(obj);
1501 goto out_vm;
1504 vma = i915_vma_instance(obj, vm, NULL);
1505 if (IS_ERR(vma)) {
1506 err = PTR_ERR(vma);
1507 goto out_put;
1510 err = i915_vma_pin(vma, 0, 0, flags);
1511 if (err)
1512 goto out_put;
1514 if (obj->mm.page_sizes.phys < I915_GTT_PAGE_SIZE_2M) {
1515 pr_info("failed to allocate THP, finishing test early\n");
1516 goto out_unpin;
1519 err = igt_check_page_sizes(vma);
1520 if (err)
1521 goto out_unpin;
1523 n = 0;
1525 for_each_gem_engine(ce, i915_gem_context_lock_engines(ctx), it) {
1526 if (!intel_engine_can_store_dword(ce->engine))
1527 continue;
1529 err = gpu_write(ce, vma, n++, 0xdeadbeaf);
1530 if (err)
1531 break;
1533 i915_gem_context_unlock_engines(ctx);
1534 i915_vma_unpin(vma);
1535 if (err)
1536 goto out_put;
1539 * Now that the pages are *unpinned* shrink-all should invoke
1540 * shmem to truncate our pages.
1542 i915_gem_shrink_all(i915);
1543 if (i915_gem_object_has_pages(obj)) {
1544 pr_err("shrink-all didn't truncate the pages\n");
1545 err = -EINVAL;
1546 goto out_put;
1549 if (obj->mm.page_sizes.sg || obj->mm.page_sizes.phys) {
1550 pr_err("residual page-size bits left\n");
1551 err = -EINVAL;
1552 goto out_put;
1555 err = i915_vma_pin(vma, 0, 0, flags);
1556 if (err)
1557 goto out_put;
1559 while (n--) {
1560 err = cpu_check(obj, n, 0xdeadbeaf);
1561 if (err)
1562 break;
1565 out_unpin:
1566 i915_vma_unpin(vma);
1567 out_put:
1568 i915_gem_object_put(obj);
1569 out_vm:
1570 i915_vm_put(vm);
1572 return err;
1575 int i915_gem_huge_page_mock_selftests(void)
1577 static const struct i915_subtest tests[] = {
1578 SUBTEST(igt_mock_exhaust_device_supported_pages),
1579 SUBTEST(igt_mock_memory_region_huge_pages),
1580 SUBTEST(igt_mock_ppgtt_misaligned_dma),
1581 SUBTEST(igt_mock_ppgtt_huge_fill),
1582 SUBTEST(igt_mock_ppgtt_64K),
1584 struct drm_i915_private *dev_priv;
1585 struct i915_ppgtt *ppgtt;
1586 int err;
1588 dev_priv = mock_gem_device();
1589 if (!dev_priv)
1590 return -ENOMEM;
1592 /* Pretend to be a device which supports the 48b PPGTT */
1593 mkwrite_device_info(dev_priv)->ppgtt_type = INTEL_PPGTT_FULL;
1594 mkwrite_device_info(dev_priv)->ppgtt_size = 48;
1596 ppgtt = i915_ppgtt_create(&dev_priv->gt);
1597 if (IS_ERR(ppgtt)) {
1598 err = PTR_ERR(ppgtt);
1599 goto out_unlock;
1602 if (!i915_vm_is_4lvl(&ppgtt->vm)) {
1603 pr_err("failed to create 48b PPGTT\n");
1604 err = -EINVAL;
1605 goto out_put;
1608 /* If we were ever hit this then it's time to mock the 64K scratch */
1609 if (!i915_vm_has_scratch_64K(&ppgtt->vm)) {
1610 pr_err("PPGTT missing 64K scratch page\n");
1611 err = -EINVAL;
1612 goto out_put;
1615 err = i915_subtests(tests, ppgtt);
1617 out_put:
1618 i915_vm_put(&ppgtt->vm);
1619 out_unlock:
1620 mock_destroy_device(dev_priv);
1621 return err;
1624 int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915)
1626 static const struct i915_subtest tests[] = {
1627 SUBTEST(igt_shrink_thp),
1628 SUBTEST(igt_tmpfs_fallback),
1629 SUBTEST(igt_ppgtt_smoke_huge),
1630 SUBTEST(igt_ppgtt_sanity_check),
1632 struct i915_gem_context *ctx;
1633 struct i915_address_space *vm;
1634 struct file *file;
1635 int err;
1637 if (!HAS_PPGTT(i915)) {
1638 pr_info("PPGTT not supported, skipping live-selftests\n");
1639 return 0;
1642 if (intel_gt_is_wedged(&i915->gt))
1643 return 0;
1645 file = mock_file(i915);
1646 if (IS_ERR(file))
1647 return PTR_ERR(file);
1649 ctx = live_context(i915, file);
1650 if (IS_ERR(ctx)) {
1651 err = PTR_ERR(ctx);
1652 goto out_file;
1655 mutex_lock(&ctx->mutex);
1656 vm = i915_gem_context_vm(ctx);
1657 if (vm)
1658 WRITE_ONCE(vm->scrub_64K, true);
1659 mutex_unlock(&ctx->mutex);
1661 err = i915_subtests(tests, ctx);
1663 out_file:
1664 fput(file);
1665 return err;