From: Chris Wilson <chris@chris-wilson.co.uk> To: intel-gfx@lists.freedesktop.org Subject: [PATCH 06/28] drm/i915/selftests: Verify mmap_gtt revocation on unbinding Date: Thu, 7 Nov 2019 08:12:30 +0000 [thread overview] Message-ID: <20191107081252.10542-6-chris@chris-wilson.co.uk> (raw) In-Reply-To: <20191107081252.10542-1-chris@chris-wilson.co.uk> Whenever, we unbind (or change fence registers) on an object, we must revoke any and all mmap_gtt using the previous bindings. Those user PTEs point at the GGTT which know points into a new object, the wrong object. Ergo, those PTEs must be cleared so that any user access provokes a new page fault. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com> --- .../drm/i915/gem/selftests/i915_gem_mman.c | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c index d5ae491a0367..19060fdc83f6 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c @@ -793,6 +793,115 @@ static int igt_mmap_gtt(void *arg) return err; } +static int check_present_pte(pte_t *pte, unsigned long addr, void *data) +{ + if (!pte_present(*pte) || pte_none(*pte)) { + pr_err("missing PTE:%lx\n", + (addr - (unsigned long)data) >> PAGE_SHIFT); + return -EINVAL; + } + + return 0; +} + +static int check_absent_pte(pte_t *pte, unsigned long addr, void *data) +{ + if (pte_present(*pte) && !pte_none(*pte)) { + pr_err("present PTE:%lx; expected to be revoked\n", + (addr - (unsigned long)data) >> PAGE_SHIFT); + return -EINVAL; + } + + return 0; +} + +static int check_present(unsigned long addr, unsigned long len) +{ + return apply_to_page_range(current->mm, addr, len, + check_present_pte, (void *)addr); +} + +static int check_absent(unsigned long addr, unsigned long len) +{ + return apply_to_page_range(current->mm, addr, len, + check_absent_pte, (void *)addr); +} + +static int prefault_range(u64 start, u64 len) +{ + const char __user *addr, *end; + char __maybe_unused c; + + addr = u64_to_user_ptr(start); + end = addr + len; + + for (; addr < end; addr += PAGE_SIZE) { + int err = __get_user(c, addr); + if (err) + return err; + } + + return __get_user(c, end - 1); +} + +static int igt_mmap_gtt_revoke(void *arg) +{ + struct drm_i915_private *i915 = arg; + struct drm_i915_gem_object *obj; + unsigned long addr; + int err; + + if (!i915_ggtt_has_aperture(&i915->ggtt)) + return 0; + + obj = i915_gem_object_create_internal(i915, SZ_4M); + if (IS_ERR(obj)) + return PTR_ERR(obj); + + err = create_mmap_offset(obj); + if (err) + goto out; + + addr = igt_mmap_node(i915, &obj->base.vma_node, + 0, PROT_WRITE, MAP_SHARED); + if (IS_ERR_VALUE(addr)) { + err = addr; + goto out; + } + + err = prefault_range(addr, obj->base.size); + if (err) + goto out_unmap; + + GEM_BUG_ON(!atomic_read(&obj->bind_count)); + + err = check_present(addr, obj->base.size); + if (err) + goto out_unmap; + + /* + * After unbinding the object from the GGTT, its address may be reused + * for other objects. Ergo we have to revoke the previous mmap PTE + * access as it no longer points to the same object. + */ + err = i915_gem_object_unbind(obj, I915_GEM_OBJECT_UNBIND_ACTIVE); + if (err) { + pr_err("Failed to unbind object!\n"); + goto out_unmap; + } + GEM_BUG_ON(atomic_read(&obj->bind_count)); + + err = check_absent(addr, obj->base.size); + if (err) + goto out_unmap; + +out_unmap: + vm_munmap(addr, obj->base.size); +out: + i915_gem_object_put(obj); + return err; +} + int i915_gem_mman_live_selftests(struct drm_i915_private *i915) { static const struct i915_subtest tests[] = { @@ -800,6 +909,7 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_smoke_tiling), SUBTEST(igt_mmap_offset_exhaustion), SUBTEST(igt_mmap_gtt), + SUBTEST(igt_mmap_gtt_revoke), }; return i915_subtests(tests, i915); -- 2.24.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk> To: intel-gfx@lists.freedesktop.org Subject: [Intel-gfx] [PATCH 06/28] drm/i915/selftests: Verify mmap_gtt revocation on unbinding Date: Thu, 7 Nov 2019 08:12:30 +0000 [thread overview] Message-ID: <20191107081252.10542-6-chris@chris-wilson.co.uk> (raw) Message-ID: <20191107081230.zjNY1hwHzrG2nIWYTSb8c0wEcIk2mVe9nR4VoEW4Lh8@z> (raw) In-Reply-To: <20191107081252.10542-1-chris@chris-wilson.co.uk> Whenever, we unbind (or change fence registers) on an object, we must revoke any and all mmap_gtt using the previous bindings. Those user PTEs point at the GGTT which know points into a new object, the wrong object. Ergo, those PTEs must be cleared so that any user access provokes a new page fault. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com> --- .../drm/i915/gem/selftests/i915_gem_mman.c | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c index d5ae491a0367..19060fdc83f6 100644 --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c @@ -793,6 +793,115 @@ static int igt_mmap_gtt(void *arg) return err; } +static int check_present_pte(pte_t *pte, unsigned long addr, void *data) +{ + if (!pte_present(*pte) || pte_none(*pte)) { + pr_err("missing PTE:%lx\n", + (addr - (unsigned long)data) >> PAGE_SHIFT); + return -EINVAL; + } + + return 0; +} + +static int check_absent_pte(pte_t *pte, unsigned long addr, void *data) +{ + if (pte_present(*pte) && !pte_none(*pte)) { + pr_err("present PTE:%lx; expected to be revoked\n", + (addr - (unsigned long)data) >> PAGE_SHIFT); + return -EINVAL; + } + + return 0; +} + +static int check_present(unsigned long addr, unsigned long len) +{ + return apply_to_page_range(current->mm, addr, len, + check_present_pte, (void *)addr); +} + +static int check_absent(unsigned long addr, unsigned long len) +{ + return apply_to_page_range(current->mm, addr, len, + check_absent_pte, (void *)addr); +} + +static int prefault_range(u64 start, u64 len) +{ + const char __user *addr, *end; + char __maybe_unused c; + + addr = u64_to_user_ptr(start); + end = addr + len; + + for (; addr < end; addr += PAGE_SIZE) { + int err = __get_user(c, addr); + if (err) + return err; + } + + return __get_user(c, end - 1); +} + +static int igt_mmap_gtt_revoke(void *arg) +{ + struct drm_i915_private *i915 = arg; + struct drm_i915_gem_object *obj; + unsigned long addr; + int err; + + if (!i915_ggtt_has_aperture(&i915->ggtt)) + return 0; + + obj = i915_gem_object_create_internal(i915, SZ_4M); + if (IS_ERR(obj)) + return PTR_ERR(obj); + + err = create_mmap_offset(obj); + if (err) + goto out; + + addr = igt_mmap_node(i915, &obj->base.vma_node, + 0, PROT_WRITE, MAP_SHARED); + if (IS_ERR_VALUE(addr)) { + err = addr; + goto out; + } + + err = prefault_range(addr, obj->base.size); + if (err) + goto out_unmap; + + GEM_BUG_ON(!atomic_read(&obj->bind_count)); + + err = check_present(addr, obj->base.size); + if (err) + goto out_unmap; + + /* + * After unbinding the object from the GGTT, its address may be reused + * for other objects. Ergo we have to revoke the previous mmap PTE + * access as it no longer points to the same object. + */ + err = i915_gem_object_unbind(obj, I915_GEM_OBJECT_UNBIND_ACTIVE); + if (err) { + pr_err("Failed to unbind object!\n"); + goto out_unmap; + } + GEM_BUG_ON(atomic_read(&obj->bind_count)); + + err = check_absent(addr, obj->base.size); + if (err) + goto out_unmap; + +out_unmap: + vm_munmap(addr, obj->base.size); +out: + i915_gem_object_put(obj); + return err; +} + int i915_gem_mman_live_selftests(struct drm_i915_private *i915) { static const struct i915_subtest tests[] = { @@ -800,6 +909,7 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) SUBTEST(igt_smoke_tiling), SUBTEST(igt_mmap_offset_exhaustion), SUBTEST(igt_mmap_gtt), + SUBTEST(igt_mmap_gtt_revoke), }; return i915_subtests(tests, i915); -- 2.24.0 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-11-07 8:13 UTC|newest] Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-11-07 8:12 [PATCH 01/28] drm/i915: Leave the aliasing-ppgtt size alone Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 02/28] drm: Move EXPORT_SYMBOL_FOR_TESTS_ONLY under a separate Kconfig Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 03/28] drm: Expose a method for creating anonymous struct file around drm_minor Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 04/28] drm/i915/selftests: Replace mock_file hackery with drm's true fake Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 05/28] drm/i915/selftests: Wrap vm_mmap() around GEM objects Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` Chris Wilson [this message] 2019-11-07 8:12 ` [Intel-gfx] [PATCH 06/28] drm/i915/selftests: Verify mmap_gtt revocation on unbinding Chris Wilson 2019-11-07 8:12 ` [PATCH 07/28] drm/i915/userptr: Try to acquire the page lock around set_page_dirty() Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 08/28] drm/i915/gem: Safely acquire the ctx->vm when copying Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 09/28] drm/i915/selftests: Exercise parallel blit operations on a single ctx Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 10/28] drm/i915/selftests: Perform some basic cycle counting of MI ops Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:39 ` Mika Kuoppala 2019-11-07 8:39 ` [Intel-gfx] " Mika Kuoppala 2019-11-07 8:47 ` Chris Wilson 2019-11-07 8:47 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 11/28] drm/i915/selftests: Mock the engine sorting for easy validation Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 12/28] drm/i915: Use a ctor for TYPESAFE_BY_RCU i915_request Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 13/28] drm/i915: Drop GEM context as a direct link from i915_request Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 14/28] drm/i915: Push the use-semaphore marker onto the intel_context Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 15/28] drm/i915: Remove i915->kernel_context Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 16/28] drm/i915: Move i915_gem_init_contexts() earlier Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 17/28] drm/i915/gt: Defer engine registration until fully initialised Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 12:22 ` Mika Kuoppala 2019-11-07 12:22 ` [Intel-gfx] " Mika Kuoppala 2019-11-07 8:12 ` [PATCH 18/28] drm/i915/gt: Pull GT initialisation under intel_gt_init() Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 19/28] drm/i915/gt: Merge engine init/setup loops Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 20/28] drm/i915/gt: Expose engine properties via sysfs Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 21/28] drm/i915/gt: Expose engine->mmio_base " Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 22/28] drm/i915/gt: Expose timeslice duration to sysfs Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 23/28] drm/i915/gt: Expose reset stop timeout via sysfs Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 24/28] drm/i915/gt: Expose preempt reset " Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 25/28] drm/i915/gt: Expose heartbeat interval " Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 26/28] drm/i915: Flush idle barriers when waiting Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 27/28] drm/i915: Allow userspace to specify ringsize on construction Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 8:12 ` [PATCH 28/28] drm/i915/gem: Honour O_NONBLOCK before throttling execbuf submissions Chris Wilson 2019-11-07 8:12 ` [Intel-gfx] " Chris Wilson 2019-11-07 11:18 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/28] drm/i915: Leave the aliasing-ppgtt size alone Patchwork 2019-11-07 11:18 ` [Intel-gfx] " Patchwork 2019-11-07 11:30 ` ✗ Fi.CI.SPARSE: " Patchwork 2019-11-07 11:30 ` [Intel-gfx] " Patchwork 2019-11-07 11:39 ` ✗ Fi.CI.BAT: failure " Patchwork 2019-11-07 11:39 ` [Intel-gfx] " Patchwork
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191107081252.10542-6-chris@chris-wilson.co.uk \ --to=chris@chris-wilson.co.uk \ --cc=intel-gfx@lists.freedesktop.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.