drm/i915: Remove unused bits of i915_vma/active api
Subsystems (2)
PATCH v2 1/10 drm/i915: Remove unused bits of i915_vma/active api
From: Maarten Lankhorst <[email protected]>
When reworking the code to move the eviction fence to the object, the best code is removed code.
Remove some functions that are unused, and change the function definition if it's only used in 1 place.
--- drivers/gpu/drm/i915/i915_active.c | 28 +++------------------------- drivers/gpu/drm/i915/i915_active.h | 17 +---------------- drivers/gpu/drm/i915/i915_vma.c | 2 +- drivers/gpu/drm/i915/i915_vma.h | 2 -- 4 files changed, 5 insertions(+), 44 deletions(-)
drivers/gpu/drm/i915/i915_active.c +3 -25
@@ -426,8 +426,9 @@ replace_barrier(struct i915_active *ref, struct i915_active_fence *active)return true; } -int i915_active_ref (struct i915_active *ref,u64 idx,struct dma_fence *fence) +int i915_active_add_request (struct i915_active *ref,struct i915_request *rq) { +struct dma_fence *fence = &rq->fence;struct i915_active_fence *active;int err;
@@ -436,7 +437,7 @@ int i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence)if (err)return err; - active =active_instance (ref, idx); + active =active_instance (ref,i915_request_timeline (rq)->fence_context);if (!active) { err = -ENOMEM ; goto out;
@@ -477,29 +478,6 @@ __i915_active_set_fence(struct i915_active *ref,return prev; } -static struct i915_active_fence * -__active_fence (struct i915_active *ref,u64 idx) -{ -struct active_node *it; - - it =__active_lookup (ref, idx); -if (unlikely (!it)) {/* Contention with parallel tree builders! */ -spin_lock_irq (&ref->tree_lock); - it =__active_lookup (ref, idx); -spin_unlock_irq (&ref->tree_lock); - } -GEM_BUG_ON (!it);/* slot must be preallocated */ - -return &it->base; -} - -struct dma_fence * -__i915_active_ref (struct i915_active *ref,u64 idx,struct dma_fence *fence) -{ -/* Only valid while active, see i915_active_acquire_for_context() */ -return __i915_active_set_fence (ref,__active_fence (ref, idx), fence); -} -struct dma_fence *i915_active_set_exclusive (struct i915_active *ref,struct dma_fence *f) {
drivers/gpu/drm/i915/i915_active.h +1 -16
@@ -164,26 +164,11 @@ void __i915_active_init(struct i915_active *ref,__i915_active_init (ref, active, retire, flags, &__mkey, &__wkey); \ }while (0 ) -struct dma_fence * -__i915_active_ref (struct i915_active *ref,u64 idx,struct dma_fence *fence); -int i915_active_ref (struct i915_active *ref,u64 idx,struct dma_fence *fence); - -static inline int -i915_active_add_request (struct i915_active *ref,struct i915_request *rq) -{ -return i915_active_ref (ref, -i915_request_timeline (rq)->fence_context, - &rq->fence); -} +int i915_active_add_request(struct i915_active *ref, struct i915_request *rq);struct dma_fence *i915_active_set_exclusive (struct i915_active *ref,struct dma_fence *f); -static inline bool i915_active_has_exclusive (struct i915_active *ref) -{ -return rcu_access_pointer (ref->excl.fence); -} -int __i915_active_wait (struct i915_active *ref,int state);static inline int i915_active_wait (struct i915_active *ref) {
drivers/gpu/drm/i915/i915_vma.c +1 -1
@@ -1220,7 +1220,7 @@ __i915_request_await_bind(struct i915_request *rq, struct i915_vma *vma)return __i915_request_await_exclusive (rq, &vma->active); } -int __i915_vma_move_to_active (struct i915_vma *vma,struct i915_request *rq) +static int __i915_vma_move_to_active (struct i915_vma *vma,struct i915_request *rq) {int err;
drivers/gpu/drm/i915/i915_vma.h +0 -2
@@ -55,8 +55,6 @@ static inline bool i915_vma_is_active(const struct i915_vma *vma)/* do not reserve memory to prevent deadlocks */ #define __EXEC_OBJECT_NO_RESERVE BIT(31) -int __must_check __i915_vma_move_to_active (struct i915_vma *vma, -struct i915_request *rq); int __must_check _i915_vma_move_to_active(struct i915_vma *vma, struct i915_request *rq, struct dma_fence *fence,
Signature · 1 line
2.26.3
PATCH v2 2/10 drm/i915: Remove gen6_ppgtt_unpin_all
From: Maarten Lankhorst <[email protected]>
gen6_ppgtt_unpin_all is unused, kill it.
--- drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 11 ----------- drivers/gpu/drm/i915/gt/gen6_ppgtt.h | 1 - 2 files changed, 12 deletions(-)
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +0 -11
@@ -404,17 +404,6 @@ void gen6_ppgtt_unpin(struct i915_ppgtt *base)i915_vma_unpin (ppgtt->vma); } -void gen6_ppgtt_unpin_all (struct i915_ppgtt *base) -{ -struct gen6_ppgtt *ppgtt =to_gen6_ppgtt (base); - -if (!atomic_read (&ppgtt->pin_count)) -return ; - -i915_vma_unpin (ppgtt->vma); -atomic_set (&ppgtt->pin_count,0 ); -} -struct i915_ppgtt *gen6_ppgtt_create (struct intel_gt *gt) {struct i915_ggtt *const ggtt = gt->ggtt;
drivers/gpu/drm/i915/gt/gen6_ppgtt.h +0 -1
@@ -71,7 +71,6 @@ static inline struct gen6_ppgtt *to_gen6_ppgtt(struct i915_ppgtt *base)int gen6_ppgtt_pin (struct i915_ppgtt *base,struct i915_gem_ww_ctx *ww);void gen6_ppgtt_unpin (struct i915_ppgtt *base); -void gen6_ppgtt_unpin_all (struct i915_ppgtt *base);void gen6_ppgtt_enable (struct intel_gt *gt);void gen7_ppgtt_enable (struct intel_gt *gt);struct i915_ppgtt *gen6_ppgtt_create (struct intel_gt *gt);
Signature · 1 line
2.26.3
PATCH v2 3/10 drm/i915: Create a dummy object for gen6 ppgtt
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
We currently have to special case vma->obj being NULL because of gen6 ppgtt and mock_engine. Fix gen6 ppgtt, so we may soon be able to remove a few checks. As the object only exists as a fake object pointing to ggtt, we have no backing storage, so no real object is created. It just has to look real enough.
Also kill pin_mutex, it's not compatible with ww locking, and we can use the vm lock instead.
v2:
- Drop IS_SHRINKABLE and shorten overly long line
v3:
- Checkpatch fix for alignment
--- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 44 ++++--- drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 123 +++++++++++-------- drivers/gpu/drm/i915/gt/gen6_ppgtt.h | 1 - drivers/gpu/drm/i915/i915_drv.h | 4 + 4 files changed, 100 insertions(+), 72 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_internal.c +26 -18
@@ -145,24 +145,10 @@ static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = { .put_pages = i915_gem_object_put_pages_internal, }; -/** -* i915_gem_object_create_internal: create an object with volatile pages -* @i915: the i915 device -* @size: the size in bytes of backing storage to allocate for the object -* -* Creates a new object that wraps some internal memory for private use. -* This object is not backed by swappable storage, and as such its contents -* are volatile and only valid whilst pinned. If the object is reaped by the -* shrinker, its pages and data will be discarded. Equally, it is not a full -* GEM object and so not valid for access from userspace. This makes it useful -* for hardware interfaces like ringbuffers (which are pinned from the time -* the request is written to the time the hardware stops accessing it), but -* not for contexts (which need to be preserved when not active for later -* reuse). Note that it is not cleared upon allocation. -*/ struct drm_i915_gem_object * -i915_gem_object_create_internal (struct drm_i915_private *i915, -phys_addr_t size) +__i915_gem_object_create_internal (struct drm_i915_private *i915, +const struct drm_i915_gem_object_ops *ops, +phys_addr_t size) {static struct lock_class_key lock_class;struct drm_i915_gem_object *obj;
@@ -179,7 +165,7 @@ i915_gem_object_create_internal(struct drm_i915_private *i915,return ERR_PTR (-ENOMEM );drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &i915_gem_object_internal_ops, &lock_class,0 ); +i915_gem_object_init (obj, ops, &lock_class,0 ); obj->mem_flags |=I915_BO_FLAG_STRUCT_PAGE ;/*
@@ -199,3 +185,25 @@ i915_gem_object_create_internal(struct drm_i915_private *i915,return obj; } + +/** +* i915_gem_object_create_internal: create an object with volatile pages +* @i915: the i915 device +* @size: the size in bytes of backing storage to allocate for the object +* +* Creates a new object that wraps some internal memory for private use. +* This object is not backed by swappable storage, and as such its contents +* are volatile and only valid whilst pinned. If the object is reaped by the +* shrinker, its pages and data will be discarded. Equally, it is not a full +* GEM object and so not valid for access from userspace. This makes it useful +* for hardware interfaces like ringbuffers (which are pinned from the time +* the request is written to the time the hardware stops accessing it), but +* not for contexts (which need to be preserved when not active for later +* reuse). Note that it is not cleared upon allocation. +*/ +struct drm_i915_gem_object * +i915_gem_object_create_internal (struct drm_i915_private *i915, +phys_addr_t size) +{ +return __i915_gem_object_create_internal (i915, &i915_gem_object_internal_ops, size); +}
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +70 -53
180 lines not on this page · raw message
drivers/gpu/drm/i915/gt/gen6_ppgtt.h +0 -1
@@ -19,7 +19,6 @@ struct gen6_ppgtt {u32 pp_dir;atomic_t pin_count; -struct mutex pin_mutex;bool scan_for_unused_pt; };
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1932,6 +1932,10 @@ int i915_gem_evict_vm(struct i915_address_space *vm);struct drm_i915_gem_object *i915_gem_object_create_internal (struct drm_i915_private *dev_priv,phys_addr_t size); +struct drm_i915_gem_object * +__i915_gem_object_create_internal (struct drm_i915_private *dev_priv, +const struct drm_i915_gem_object_ops *ops, +phys_addr_t size);/* i915_gem_tiling.c */ static inline bool i915_gem_object_needs_bit17_swizzle (struct drm_i915_gem_object *obj)
Signature · 1 line
2.26.3
PATCH v2 4/10 drm/i915: Create a full object for mock_ring, v2.
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
This allows us to finally get rid of all the assumptions that vma->obj is NULL.
Changes since v1:
- Ensure the mock_ring vma is pinned to prevent a fault.
- Pin it high to avoid failure in evict_for_vma selftest.
--- drivers/gpu/drm/i915/gt/mock_engine.c | 38 ++++++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/mock_engine.c +28 -10
@@ -35,9 +35,31 @@ static void mock_timeline_unpin(struct intel_timeline *tl)atomic_dec (&tl->pin_count); } +static struct i915_vma *create_ring_vma (struct i915_ggtt *ggtt,int size) +{ +struct i915_address_space *vm = &ggtt->vm; +struct drm_i915_private *i915 = vm->i915; +struct drm_i915_gem_object *obj; +struct i915_vma *vma; + + obj =i915_gem_object_create_internal (i915, size); +if (IS_ERR (obj)) +return ERR_CAST (obj); + + vma =i915_vma_instance (obj, vm,NULL ); +if (IS_ERR (vma)) + goto err; + +return vma; + +err: +i915_gem_object_put (obj); +return vma; +} +static struct intel_ring *mock_ring (struct intel_engine_cs *engine) { -const unsigned long sz =PAGE_SIZE /2 ; +const unsigned long sz =PAGE_SIZE ;struct intel_ring *ring; ring =kzalloc (sizeof (*ring) + sz,GFP_KERNEL );
@@ -50,15 +72,11 @@ static struct intel_ring *mock_ring(struct intel_engine_cs *engine) ring->vaddr = (void *)(ring +1 );atomic_set (&ring->pin_count,1 ); - ring->vma =i915_vma_alloc (); -if (!ring->vma) { + ring->vma =create_ring_vma (engine->gt->ggtt,PAGE_SIZE ); +if (IS_ERR (ring->vma)) {kfree (ring);return NULL ; } -i915_active_init (&ring->vma->active,NULL ,NULL ,0 ); -__set_bit (I915_VMA_GGTT_BIT ,__i915_vma_flags (ring->vma)); -__set_bit (DRM_MM_NODE_ALLOCATED_BIT , &ring->vma->node.flags); - ring->vma->node.size = sz;intel_ring_update_space (ring);
@@ -67,8 +85,7 @@ static struct intel_ring *mock_ring(struct intel_engine_cs *engine)static void mock_ring_free (struct intel_ring *ring) { -i915_active_fini (&ring->vma->active); -i915_vma_free (ring->vma); +i915_vma_put (ring->vma);kfree (ring); }
@@ -125,6 +142,7 @@ static void mock_context_unpin(struct intel_context *ce)static void mock_context_post_unpin (struct intel_context *ce) { +i915_vma_unpin (ce->ring->vma); }static void mock_context_destroy (struct kref *ref)
@@ -169,7 +187,7 @@ static int mock_context_alloc(struct intel_context *ce)static int mock_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww,void **unused) { -return 0 ; +return i915_vma_pin_ww (ce->ring->vma, ww,0 ,0 ,PIN_GLOBAL |PIN_HIGH ); }static int mock_context_pin (struct intel_context *ce,void *unused)
Signature · 1 line
2.26.3
PATCH v2 5/10 drm/i915: vma is always backed by an object.
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
vma->obj and vma->resv are now never NULL, and some checks can be removed.
--- drivers/gpu/drm/i915/gt/intel_context.c | 2 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 2 +- drivers/gpu/drm/i915/i915_vma.c | 48 ++++++++----------- drivers/gpu/drm/i915/i915_vma.h | 3 -- 4 files changed, 22 insertions(+), 33 deletions(-)
drivers/gpu/drm/i915/gt/intel_context.c +1 -1
@@ -219,7 +219,7 @@ int __intel_context_do_pin_ww(struct intel_context *ce,*/ err =i915_gem_object_lock (ce->timeline->hwsp_ggtt->obj, ww); -if (!err && ce->ring->vma->obj) +if (!err) err =i915_gem_object_lock (ce->ring->vma->obj, ww);if (!err && ce->state) err =i915_gem_object_lock (ce->state->obj, ww);
drivers/gpu/drm/i915/gt/intel_ring_submission.c +1 -1
@@ -1357,7 +1357,7 @@ int intel_ring_submission_setup(struct intel_engine_cs *engine) err =i915_gem_object_lock (timeline->hwsp_ggtt->obj, &ww);if (!err && gen7_wa_vma) err =i915_gem_object_lock (gen7_wa_vma->obj, &ww); -if (!err && engine->legacy.ring->vma->obj) +if (!err) err =i915_gem_object_lock (engine->legacy.ring->vma->obj, &ww);if (!err) err =intel_timeline_pin (timeline, &ww);
drivers/gpu/drm/i915/i915_vma.c +20 -28
116 lines not on this page · raw message
drivers/gpu/drm/i915/i915_vma.h +0 -3
@@ -416,9 +416,6 @@ static inline void i915_vma_clear_scanout(struct i915_vma *vma) list_for_each_entry(V, &(OBJ)->vma.list, obj_link) \ for_each_until(!i915_vma_is_ggtt(V)) -struct i915_vma *i915_vma_alloc (void ); -void i915_vma_free (struct i915_vma *vma); -struct i915_vma *i915_vma_make_unshrinkable (struct i915_vma *vma);void i915_vma_make_shrinkable (struct i915_vma *vma);void i915_vma_make_purgeable (struct i915_vma *vma);
Signature · 1 line
2.26.3
PATCH v2 6/10 drm/i915/pm: Move CONTEXT_VALID_BIT check
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
Resetting will clear the CONTEXT_VALID_BIT, so wait until after that to test.
--- drivers/gpu/drm/i915/gt/intel_engine_pm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_pm.c +3 -2
@@ -52,8 +52,6 @@ static int __engine_unpark(struct intel_wakeref *wf)/* Discard stale context state from across idling */ ce = engine->kernel_context;if (ce) { -GEM_BUG_ON (test_bit (CONTEXT_VALID_BIT , &ce->flags)); -/* Flush all pending HW writes before we touch the context */ while (unlikely (intel_context_inflight (ce)))intel_engine_flush_submission (engine);
@@ -68,6 +66,9 @@ static int __engine_unpark(struct intel_wakeref *wf) ce->timeline->seqno,READ_ONCE (*ce->timeline->hwsp_seqno), ce->ring->emit); + +GEM_BUG_ON (test_bit (CONTEXT_VALID_BIT , &ce->flags)); +GEM_BUG_ON (ce->timeline->seqno !=READ_ONCE (*ce->timeline->hwsp_seqno)); }
Signature · 1 line
2.26.3
PATCH v2 7/10 drm/i915: Remove resv from i915_vma
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
It's just an alias to vma->obj->base.resv, no need to duplicate it.
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 4 ++-- drivers/gpu/drm/i915/i915_vma.c | 9 ++++----- drivers/gpu/drm/i915/i915_vma.h | 6 +++--- drivers/gpu/drm/i915/i915_vma_types.h | 1 - 4 files changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -2
@@ -1001,7 +1001,7 @@ static int eb_validate_vmas(struct i915_execbuffer *eb) }if (!(ev->flags &EXEC_OBJECT_WRITE )) { - err =dma_resv_reserve_shared (vma->resv,1 ); + err =dma_resv_reserve_shared (vma->obj->base.resv,1 );if (err)return err; }
@@ -2175,7 +2175,7 @@ static int eb_parse(struct i915_execbuffer *eb) goto err_trampoline; } - err =dma_resv_reserve_shared (shadow->resv,1 ); + err =dma_resv_reserve_shared (shadow->obj->base.resv,1 );if (err) goto err_trampoline;
drivers/gpu/drm/i915/i915_vma.c +4 -5
@@ -116,7 +116,6 @@ vma_create(struct drm_i915_gem_object *obj, vma->vm =i915_vm_get (vm); vma->ops = &vm->vma_ops; vma->obj = obj; - vma->resv = obj->base.resv; vma->size = obj->base.size; vma->display_alignment =I915_GTT_MIN_ALIGNMENT ;
@@ -1032,7 +1031,7 @@ int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,GEM_BUG_ON (!i915_vma_is_ggtt (vma));#ifdef CONFIG_LOCKDEP -WARN_ON (!ww &&dma_resv_held (vma->resv)); +WARN_ON (!ww &&dma_resv_held (vma->obj->base.resv));#endif do {
@@ -1251,19 +1250,19 @@ int _i915_vma_move_to_active(struct i915_vma *vma, }if (fence) { -dma_resv_add_excl_fence (vma->resv, fence); +dma_resv_add_excl_fence (vma->obj->base.resv, fence); obj->write_domain =I915_GEM_DOMAIN_RENDER ; obj->read_domains =0 ; } }else {if (!(flags & __EXEC_OBJECT_NO_RESERVE)) { - err =dma_resv_reserve_shared (vma->resv,1 ); + err =dma_resv_reserve_shared (vma->obj->base.resv,1 );if (unlikely (err))return err; }if (fence) { -dma_resv_add_shared_fence (vma->resv, fence); +dma_resv_add_shared_fence (vma->obj->base.resv, fence); obj->write_domain =0 ; } }
drivers/gpu/drm/i915/i915_vma.h +3 -3
@@ -232,16 +232,16 @@ static inline void __i915_vma_put(struct i915_vma *vma)kref_put (&vma->ref, i915_vma_release); } -#define assert_vma_held (vma) dma_resv_assert_held((vma)->resv) +#define assert_vma_held (vma) dma_resv_assert_held((vma)->obj->base.resv)static inline void i915_vma_lock (struct i915_vma *vma) { -dma_resv_lock (vma->resv,NULL ); +dma_resv_lock (vma->obj->base.resv,NULL ); }static inline void i915_vma_unlock (struct i915_vma *vma) { -dma_resv_unlock (vma->resv); +dma_resv_unlock (vma->obj->base.resv); }int __must_check
drivers/gpu/drm/i915/i915_vma_types.h +0 -1
@@ -178,7 +178,6 @@ struct i915_vma {const struct i915_vma_ops *ops;struct drm_i915_gem_object *obj; -struct dma_resv *resv;/** Alias of obj->resv */ struct sg_table *pages;void __iomem *iomap;
Signature · 1 line
2.26.3
PATCH v2 8/10 drm/i915: Rework context handling in hugepages selftests
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
In the next commit, we don't evict when refcount = 0, so we need to call drain freed objects, because we want to pin new bo's in the same place, causing a test failure.
Furthermore, since each subtest is separated, it's a lot better to use i915_live_selftests, so each subtest starts with a clean slate, and a clean address space.
v2:
- Make hugepage_ctx static. Reported-by: kernel test robot <[email protected]>
--- .../gpu/drm/i915/gem/selftests/huge_pages.c | 128 +++++++++++------- 1 file changed, 80 insertions(+), 48 deletions(-)
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +80 -48
@@ -22,6 +22,22 @@#include "selftests/mock_region.h" #include "selftests/i915_random.h" +static struct i915_gem_context *hugepage_ctx (struct drm_i915_private *i915, +struct file *file) +{ +struct i915_gem_context *ctx =live_context (i915, file); +struct i915_address_space *vm; + +if (IS_ERR (ctx)) +return ctx; + + vm = ctx->vm; +if (vm) +WRITE_ONCE (vm->scrub_64K, true); + +return ctx; +} +static const unsigned int page_sizes[] = {I915_GTT_PAGE_SIZE_2M ,I915_GTT_PAGE_SIZE_64K ,
@@ -959,6 +975,8 @@ static int igt_mock_ppgtt_64K(void *arg)__i915_gem_object_put_pages (obj);i915_gem_object_unlock (obj);i915_gem_object_put (obj); + +i915_gem_drain_freed_objects (i915); } }
@@ -1080,10 +1098,6 @@ static int __igt_write_huge(struct intel_context *ce,if (IS_ERR (vma))return PTR_ERR (vma); - err =i915_vma_unbind (vma); -if (err) -return err; - err =i915_vma_pin (vma, size,0 , flags | offset);if (err) {/*
@@ -1117,7 +1131,7 @@ static int __igt_write_huge(struct intel_context *ce,return err; } -static int igt_write_huge (struct i915_gem_context *ctx, +static int igt_write_huge (struct drm_i915_private *i915,struct drm_i915_gem_object *obj) {struct i915_gem_engines *engines;
@@ -1127,6 +1141,8 @@ static int igt_write_huge(struct i915_gem_context *ctx,IGT_TIMEOUT (end_time);unsigned int max_page_size;unsigned int count; +struct i915_gem_context *ctx; +struct file *file;u64 max;u64 num;u64 size;
@@ -1134,6 +1150,16 @@ static int igt_write_huge(struct i915_gem_context *ctx,int i, n;int err =0 ; + file =mock_file (i915); +if (IS_ERR (file)) +return PTR_ERR (file); + + ctx =hugepage_ctx (i915, file); +if (IS_ERR (ctx)) { + err =PTR_ERR (ctx); + goto out; + } +GEM_BUG_ON (!i915_gem_object_has_pinned_pages (obj)); size = obj->base.size;
@@ -1153,7 +1179,7 @@ static int igt_write_huge(struct i915_gem_context *ctx, }i915_gem_context_unlock_engines (ctx);if (!n) -return 0 ; + goto out;/* * To keep things interesting when alternating between engines in our
@@ -1215,6 +1241,8 @@ static int igt_write_huge(struct i915_gem_context *ctx,kfree (order); +out: +fput (file);return err; }
@@ -1277,8 +1305,7 @@ static u32 igt_random_size(struct rnd_state *prng,static int igt_ppgtt_smoke_huge (void *arg) { -struct i915_gem_context *ctx = arg; -struct drm_i915_private *i915 = ctx->i915; +struct drm_i915_private *i915 = arg;struct drm_i915_gem_object *obj;I915_RND_STATE (prng);struct {
@@ -1302,6 +1329,7 @@ static int igt_ppgtt_smoke_huge(void *arg)u32 min = backends[i].min;u32 max = backends[i].max;u32 size = max; + try_again: size =igt_random_size (&prng, min,rounddown_pow_of_two (size));
@@ -1336,7 +1364,7 @@ static int igt_ppgtt_smoke_huge(void *arg) goto out_unpin; } - err =igt_write_huge (ctx, obj); + err =igt_write_huge (i915, obj);if (err) {pr_err ("%s write-huge failed with size=%u, i=%d\n" , __func__, size, i);
@@ -1363,8 +1391,7 @@ static int igt_ppgtt_smoke_huge(void *arg)static int igt_ppgtt_sanity_check (void *arg) { -struct i915_gem_context *ctx = arg; -struct drm_i915_private *i915 = ctx->i915; +struct drm_i915_private *i915 = arg;unsigned int supported =INTEL_INFO (i915)->page_sizes;struct {igt_create_fn fn;
@@ -1431,7 +1458,7 @@ static int igt_ppgtt_sanity_check(void *arg)if (pages) obj->mm.page_sizes.sg = pages; - err =igt_write_huge (ctx, obj); + err =igt_write_huge (i915, obj);i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);
@@ -1458,15 +1485,27 @@ static int igt_ppgtt_sanity_check(void *arg)static int igt_tmpfs_fallback (void *arg) { -struct i915_gem_context *ctx = arg; -struct drm_i915_private *i915 = ctx->i915; +struct drm_i915_private *i915 = arg; +struct i915_address_space *vm; +struct i915_gem_context *ctx;struct vfsmount *gemfs = i915->mm.gemfs; -struct i915_address_space *vm =i915_gem_context_get_eb_vm (ctx);struct drm_i915_gem_object *obj;struct i915_vma *vma; +struct file *file;u32 *vaddr;int err =0 ; + file =mock_file (i915); +if (IS_ERR (file)) +return PTR_ERR (file); + + ctx =hugepage_ctx (i915, file); +if (IS_ERR (ctx)) { + err =PTR_ERR (ctx); + goto out; + } + vm =i915_gem_context_get_eb_vm (ctx); +/* * Make sure that we don't burst into a ball of flames upon falling back * to tmpfs, which we rely on if on the off-chance we encouter a failure
@@ -1510,33 +1549,47 @@ static int igt_tmpfs_fallback(void *arg) i915->mm.gemfs = gemfs;i915_vm_put (vm); +out: +fput (file);return err; }static int igt_shrink_thp (void *arg) { -struct i915_gem_context *ctx = arg; -struct drm_i915_private *i915 = ctx->i915; -struct i915_address_space *vm =i915_gem_context_get_eb_vm (ctx); +struct drm_i915_private *i915 = arg; +struct i915_address_space *vm; +struct i915_gem_context *ctx;struct drm_i915_gem_object *obj;struct i915_gem_engines_iter it;struct intel_context *ce;struct i915_vma *vma; +struct file *file;unsigned int flags =PIN_USER ;unsigned int n;bool should_swap; -int err =0 ; +int err; + +if (!igt_can_allocate_thp (i915)) { +pr_info ("missing THP support, skipping\n" ); +return 0 ; + } + + file =mock_file (i915); +if (IS_ERR (file)) +return PTR_ERR (file); + + ctx =hugepage_ctx (i915, file); +if (IS_ERR (ctx)) { + err =PTR_ERR (ctx); + goto out; + } + vm =i915_gem_context_get_eb_vm (ctx);/* * Sanity check shrinking huge-paged object -- make sure nothing blows * up. */ -if (!igt_can_allocate_thp (i915)) { -pr_info ("missing THP support, skipping\n" ); - goto out_vm; - } - obj =i915_gem_object_create_shmem (i915,SZ_2M );if (IS_ERR (obj)) { err =PTR_ERR (obj);
@@ -1626,7 +1679,8 @@ static int igt_shrink_thp(void *arg)i915_gem_object_put (obj); out_vm:i915_vm_put (vm); - +out: +fput (file);return err; }
@@ -1687,10 +1741,6 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915)SUBTEST (igt_ppgtt_smoke_huge), SUBTEST(igt_ppgtt_sanity_check), }; -struct i915_gem_context *ctx; -struct i915_address_space *vm; -struct file *file; -int err;if (!HAS_PPGTT (i915)) {pr_info ("PPGTT not supported, skipping live-selftests\n" );
@@ -1700,23 +1750,5 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915)if (intel_gt_is_wedged (&i915->gt))return 0 ; - file =mock_file (i915); -if (IS_ERR (file)) -return PTR_ERR (file); - - ctx =live_context (i915, file); -if (IS_ERR (ctx)) { - err =PTR_ERR (ctx); - goto out_file; - } - - vm = ctx->vm; -if (vm) -WRITE_ONCE (vm->scrub_64K, true); - - err =i915_subtests (tests, ctx); - -out_file: -fput (file); -return err; +return i915_live_subtests (tests, i915); }
Signature · 1 line
2.26.3
PATCH v2 9/10 drm/i915: Drain the ttm delayed workqueue too
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
Lets be thorough here. Users of the TTM backend would likely expect this behaviour.
--- drivers/gpu/drm/i915/i915_drv.h | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/i915_drv.h +1 -0
@@ -1818,6 +1818,7 @@ static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)*/ while (atomic_read (&i915->mm.free_count)) {flush_work (&i915->mm.free_work); +flush_delayed_work (&i915->bdev.wq);rcu_barrier (); } }
Signature · 1 line
2.26.3
PATCH v2 10/10 drm/i915: Require object lock when freeing pages during destruction
In reply to Matthew AuldFrom: Maarten Lankhorst <[email protected]>
TTM already requires this, and we require it for delayed destroy.
--- drivers/gpu/drm/i915/gem/i915_gem_object.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_object.c +5 -0
@@ -257,6 +257,8 @@ static void __i915_gem_object_free_mmaps(struct drm_i915_gem_object *obj)*/ void __i915_gem_object_pages_fini (struct drm_i915_gem_object *obj) { +assert_object_held (obj); +if (!list_empty (&obj->vma.list)) {struct i915_vma *vma;
@@ -323,7 +325,10 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915, obj->ops->delayed_free (obj);continue ; } + +i915_gem_object_lock (obj,NULL );__i915_gem_object_pages_fini (obj); +i915_gem_object_unlock (obj);__i915_gem_free_object (obj);/* But keep the pointer alive for RCU-protected lookups */
Signature · 1 line
2.26.3