drm/i915: Remove obj->mm.lock!
Subsystems (4)
v8 cover drm/i915: Remove obj->mm.lock!
New rebased version, now includes conversion to take a ww argument in the set_pages() callback, which completes the rework.
Maarten Lankhorst (68):
drm/i915: Do not share hwsp across contexts any more, v7. drm/i915: Pin timeline map after first timeline pin, v3. drm/i915: Move cmd parser pinning to execbuffer
drm/i915: Add missing -EDEADLK handling to execbuf pinning, v2. drm/i915: Ensure we hold the object mutex in pin correctly. drm/i915: Add gem object locking to madvise.
drm/i915: Move HAS_STRUCT_PAGE to obj->flags
drm/i915: Rework struct phys attachment handling drm/i915: Convert i915_gem_object_attach_phys() to ww locking, v2. drm/i915: make lockdep slightly happier about execbuf. drm/i915: Disable userptr pread/pwrite support.
drm/i915: No longer allow exporting userptr through dma-buf drm/i915: Reject more ioctls for userptr, v2.
drm/i915: Reject UNSYNCHRONIZED for userptr, v2. drm/i915: Make compilation of userptr code depend on MMU_NOTIFIER. drm/i915: Fix userptr so we do not have to worry about obj->mm.lock,
v7.
drm/i915: Flatten obj->mm.lock
drm/i915: Populate logical context during first pin.
drm/i915: Make ring submission compatible with obj->mm.lock removal,
v2.
drm/i915: Handle ww locking in init_status_page
drm/i915: Rework clflush to work correctly without obj->mm.lock.
drm/i915: Pass ww ctx to intel_pin_to_display_plane
drm/i915: Add object locking to vm_fault_cpu
drm/i915: Move pinning to inside engine_wa_list_verify()
drm/i915: Take reservation lock around i915_vma_pin.
drm/i915: Make lrc_init_wa_ctx compatible with ww locking, v3.
drm/i915: Make __engine_unpark() compatible with ww locking.
drm/i915: Take obj lock around set_domain ioctl
drm/i915: Defer pin calls in buffer pool until first use by caller.
drm/i915: Fix pread/pwrite to work with new locking rules.
drm/i915: Fix workarounds selftest, part 1
drm/i915: Add igt_spinner_pin() to allow for ww locking around
spinner.
drm/i915: Add ww locking around vm_access()
drm/i915: Increase ww locking for perf.
drm/i915: Lock ww in ucode objects correctly
drm/i915: Add ww locking to dma-buf ops.
drm/i915: Add missing ww lock in intel_dsb_prepare.
drm/i915: Fix ww locking in shmem_create_from_object
drm/i915: Use a single page table lock for each gtt.
drm/i915/selftests: Prepare huge_pages testcases for obj->mm.lock
removal.
drm/i915/selftests: Prepare client blit for obj->mm.lock removal.
drm/i915/selftests: Prepare coherency tests for obj->mm.lock removal.
drm/i915/selftests: Prepare context tests for obj->mm.lock removal.
drm/i915/selftests: Prepare dma-buf tests for obj->mm.lock removal.
drm/i915/selftests: Prepare execbuf tests for obj->mm.lock removal.
drm/i915/selftests: Prepare mman testcases for obj->mm.lock removal.
drm/i915/selftests: Prepare object tests for obj->mm.lock removal.
drm/i915/selftests: Prepare object blit tests for obj->mm.lock
removal.
drm/i915/selftests: Prepare igt_gem_utils for obj->mm.lock removal
drm/i915/selftests: Prepare context selftest for obj->mm.lock removal
drm/i915/selftests: Prepare hangcheck for obj->mm.lock removal
drm/i915/selftests: Prepare execlists and lrc selftests for
obj->mm.lock removal drm/i915/selftests: Prepare mocs tests for obj->mm.lock removal drm/i915/selftests: Prepare ring submission for obj->mm.lock removal drm/i915/selftests: Prepare timeline tests for obj->mm.lock removal drm/i915/selftests: Prepare i915_request tests for obj->mm.lock
removal
drm/i915/selftests: Prepare memory region tests for obj->mm.lock
removal
drm/i915/selftests: Prepare cs engine tests for obj->mm.lock removal drm/i915/selftests: Prepare gtt tests for obj->mm.lock removal drm/i915: Finally remove obj->mm.lock.
drm/i915: Keep userpointer bindings if seqcount is unchanged, v2. drm/i915: Move gt_revoke() slightly
drm/i915: Add missing -EDEADLK path in execbuffer ggtt pinning. drm/i915: Fix pin_map in scheduler selftests
drm/i915: Add ww parameter to get_pages() callback drm/i915: Add ww context to prepare_(read/write) drm/i915: Pass ww ctx to pin_map
drm/i915: Pass ww ctx to i915_gem_object_pin_pages
Thomas Hellström (1):
drm/i915: Prepare for obj->mm.lock removal, v2.
drivers/gpu/drm/i915/Makefile | 1 - drivers/gpu/drm/i915/display/intel_display.c | 71 +- drivers/gpu/drm/i915/display/intel_display.h | 2 +- drivers/gpu/drm/i915/display/intel_dsb.c | 2 +- drivers/gpu/drm/i915/display/intel_fbdev.c | 2 +- drivers/gpu/drm/i915/display/intel_overlay.c | 34 +- drivers/gpu/drm/i915/gem/i915_gem_clflush.c | 15 +- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 67 +- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 94 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 240 ++++- drivers/gpu/drm/i915/gem/i915_gem_fence.c | 95 -- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 9 +- drivers/gpu/drm/i915/gem/i915_gem_lmem.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 48 +- drivers/gpu/drm/i915/gem/i915_gem_object.c | 9 +- drivers/gpu/drm/i915/gem/i915_gem_object.h | 110 ++- .../gpu/drm/i915/gem/i915_gem_object_blt.c | 10 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 26 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 134 ++- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 110 +-- drivers/gpu/drm/i915/gem/i915_gem_pm.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_region.c | 7 +- drivers/gpu/drm/i915/gem/i915_gem_region.h | 7 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 42 +- drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 39 +- drivers/gpu/drm/i915/gem/i915_gem_shrinker.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 17 +- drivers/gpu/drm/i915/gem/i915_gem_tiling.c | 2 - drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 903 +++++++----------- .../drm/i915/gem/selftests/huge_gem_object.c | 7 +- .../gpu/drm/i915/gem/selftests/huge_pages.c | 49 +- .../i915/gem/selftests/i915_gem_client_blt.c | 8 +- .../i915/gem/selftests/i915_gem_coherency.c | 20 +- .../drm/i915/gem/selftests/i915_gem_context.c | 22 +- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 4 +- .../i915/gem/selftests/i915_gem_execbuffer.c | 2 +- .../drm/i915/gem/selftests/i915_gem_mman.c | 21 +- .../drm/i915/gem/selftests/i915_gem_object.c | 2 +- .../i915/gem/selftests/i915_gem_object_blt.c | 6 +- .../drm/i915/gem/selftests/i915_gem_phys.c | 10 +- .../drm/i915/gem/selftests/igt_gem_utils.c | 2 +- drivers/gpu/drm/i915/gt/gen2_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/gen6_engine_cs.c | 8 +- drivers/gpu/drm/i915/gt/gen7_renderclear.c | 2 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 13 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 40 +- drivers/gpu/drm/i915/gt/intel_engine_pm.c | 6 +- .../drm/i915/gt/intel_execlists_submission.c | 26 +- drivers/gpu/drm/i915/gt/intel_ggtt.c | 10 +- .../gpu/drm/i915/gt/intel_gt_buffer_pool.c | 47 +- .../gpu/drm/i915/gt/intel_gt_buffer_pool.h | 5 + .../drm/i915/gt/intel_gt_buffer_pool_types.h | 1 + drivers/gpu/drm/i915/gt/intel_gt_types.h | 4 - drivers/gpu/drm/i915/gt/intel_gtt.c | 54 +- drivers/gpu/drm/i915/gt/intel_gtt.h | 8 + drivers/gpu/drm/i915/gt/intel_lrc.c | 53 +- drivers/gpu/drm/i915/gt/intel_ppgtt.c | 3 +- drivers/gpu/drm/i915/gt/intel_renderstate.c | 4 +- drivers/gpu/drm/i915/gt/intel_reset.c | 5 +- drivers/gpu/drm/i915/gt/intel_ring.c | 2 +- .../gpu/drm/i915/gt/intel_ring_submission.c | 184 ++-- drivers/gpu/drm/i915/gt/intel_timeline.c | 427 ++------- drivers/gpu/drm/i915/gt/intel_timeline.h | 3 + .../gpu/drm/i915/gt/intel_timeline_types.h | 17 +- drivers/gpu/drm/i915/gt/intel_workarounds.c | 12 +- drivers/gpu/drm/i915/gt/mock_engine.c | 22 +- drivers/gpu/drm/i915/gt/selftest_context.c | 4 +- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 9 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 23 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 8 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 20 +- drivers/gpu/drm/i915/gt/selftest_mocs.c | 5 +- .../drm/i915/gt/selftest_ring_submission.c | 4 +- drivers/gpu/drm/i915/gt/selftest_rps.c | 10 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 174 ++-- .../gpu/drm/i915/gt/selftest_workarounds.c | 103 +- drivers/gpu/drm/i915/gt/shmem_utils.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_guc.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_guc_log.c | 4 +- drivers/gpu/drm/i915/gt/uc/intel_huc.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 2 +- drivers/gpu/drm/i915/gvt/cmd_parser.c | 4 +- drivers/gpu/drm/i915/gvt/dmabuf.c | 5 +- drivers/gpu/drm/i915/i915_active.c | 20 +- drivers/gpu/drm/i915/i915_cmd_parser.c | 104 +- drivers/gpu/drm/i915/i915_debugfs.c | 4 +- drivers/gpu/drm/i915/i915_drv.h | 18 +- drivers/gpu/drm/i915/i915_gem.c | 239 ++--- drivers/gpu/drm/i915/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/i915_memcpy.c | 2 +- drivers/gpu/drm/i915/i915_memcpy.h | 2 +- drivers/gpu/drm/i915/i915_perf.c | 60 +- drivers/gpu/drm/i915/i915_request.c | 4 - drivers/gpu/drm/i915/i915_request.h | 31 +- drivers/gpu/drm/i915/i915_selftest.h | 2 + drivers/gpu/drm/i915/i915_vma.c | 33 +- drivers/gpu/drm/i915/i915_vma.h | 20 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 97 +- drivers/gpu/drm/i915/selftests/i915_request.c | 10 +- .../gpu/drm/i915/selftests/i915_scheduler.c | 2 +- drivers/gpu/drm/i915/selftests/igt_spinner.c | 136 ++- drivers/gpu/drm/i915/selftests/igt_spinner.h | 5 + .../drm/i915/selftests/intel_memory_region.c | 18 +- drivers/gpu/drm/i915/selftests/mock_region.c | 4 +- 104 files changed, 2324 insertions(+), 2087 deletions(-) delete mode 100644 drivers/gpu/drm/i915/gem/i915_gem_fence.c
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 1/69 drm/i915: Do not share hwsp across contexts any more, v7.
Instead of sharing pages with breadcrumbs, give each timeline a single page. This allows unrelated timelines not to share locks any more during command submission.
As an additional benefit, seqno wraparound no longer requires i915_vma_pin, which means we no longer need to worry about a potential -EDEADLK at a point where we are ready to submit.
Changes since v1:
- Fix erroneous i915_vma_acquire that should be a i915_vma_release (ickle).
- Extra check for completion in intel_read_hwsp().
Changes since v2:
- Fix inconsistent indent in hwsp_alloc() (kbuild)
- memset entire cacheline to 0.
Changes since v3:
- Do same in intel_timeline_reset_seqno(), and clflush for good measure. Changes since v4:
- Use refcounting on timeline, instead of relying on i915_active.
- Fix waiting on kernel requests.
Changes since v5:
- Bump amount of slots to maximum (256), for best wraparounds.
- Add hwsp_offset to i915_request to fix potential wraparound hang.
- Ensure timeline wrap test works with the changes.
- Assign hwsp in intel_timeline_read_hwsp() within the rcu lock to fix a hang.
Changes since v6:
- Rename i915_request_active_offset to i915_request_active_seqno(), and elaborate the function. (tvrtko)
--- drivers/gpu/drm/i915/gt/gen2_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/gen6_engine_cs.c | 8 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 13 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/gt/intel_gt_types.h | 4 - drivers/gpu/drm/i915/gt/intel_timeline.c | 422 ++++-------------- .../gpu/drm/i915/gt/intel_timeline_types.h | 17 +- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 5 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 83 ++-- drivers/gpu/drm/i915/i915_request.c | 4 - drivers/gpu/drm/i915/i915_request.h | 31 +- 11 files changed, 175 insertions(+), 415 deletions(-)
drivers/gpu/drm/i915/gt/gen2_engine_cs.c +1 -1
@@ -143,7 +143,7 @@ static u32 *__gen2_emit_breadcrumb(struct i915_request *rq, u32 *cs, int flush, int post) { GEM_BUG_ON(i915_request_active_timeline(rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH ;
drivers/gpu/drm/i915/gt/gen6_engine_cs.c +4 -4
@@ -161,7 +161,7 @@ u32 *gen6_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_DC_FLUSH_ENABLE |PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset | + *cs++ =i915_request_active_seqno (rq) |PIPE_CONTROL_GLOBAL_GTT ; *cs++ = rq->fence.seqno;
@@ -359,7 +359,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_QW_WRITE |PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset; + *cs++ =i915_request_active_seqno (rq); *cs++ = rq->fence.seqno; *cs++ =MI_USER_INTERRUPT ;
@@ -374,7 +374,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)u32 *gen6_emit_breadcrumb_xcs (struct i915_request *rq,u32 *cs) {GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ; *cs++ =I915_GEM_HWS_SEQNO_ADDR |MI_FLUSH_DW_USE_GTT ;
@@ -394,7 +394,7 @@ u32 *gen7_emit_breadcrumb_xcs(struct i915_request *rq, u32 *cs)int i;GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_INVALIDATE_TLB |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ;
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +6 -7
@@ -338,15 +338,14 @@ static u32 preempt_address(struct intel_engine_cs *engine)static u32 hwsp_offset (const struct i915_request *rq) { -const struct intel_timeline_cacheline *cl; +const struct intel_timeline *tl; -/* Before the request is executed, the timeline/cachline is fixed */ +/* Before the request is executed, the timeline is fixed */ + tl =rcu_dereference_protected (rq->timeline, + !i915_request_signaled (rq)); - cl =rcu_dereference_protected (rq->hwsp_cacheline,1 ); -if (cl) -return cl->ggtt_offset; - -return rcu_dereference_protected (rq->timeline,1 )->hwsp_offset; +/* See the comment in i915_request_active_seqno(). */ +return page_mask_bits (tl->hwsp_offset) +offset_in_page (rq->hwsp_seqno); }int gen8_emit_init_breadcrumb (struct i915_request *rq)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -0
@@ -752,6 +752,7 @@ static int measure_breadcrumb_dw(struct intel_context *ce) frame->rq.engine = engine; frame->rq.context = ce;rcu_assign_pointer (frame->rq.timeline, ce->timeline); + frame->rq.hwsp_seqno = ce->timeline->hwsp_seqno; frame->ring.vaddr = frame->cs; frame->ring.size =sizeof (frame->cs);
drivers/gpu/drm/i915/gt/intel_gt_types.h +0 -4
@@ -45,10 +45,6 @@ struct intel_gt {struct intel_gt_timelines {spinlock_t lock;/* protects active_list */ struct list_head active_list; - -/* Pack multiple timelines' seqnos into the same page */ -spinlock_t hwsp_lock; -struct list_head hwsp_free_list; } timelines;struct intel_gt_requests {
drivers/gpu/drm/i915/gt/intel_timeline.c +84 -338
552 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_timeline_types.h +3 -14
@@ -17,7 +17,6 @@struct i915_vma ;struct i915_syncmap ;struct intel_gt ; -struct intel_timeline_hwsp ;struct intel_timeline {u64 fence_context;
@@ -44,12 +43,11 @@ struct intel_timeline {atomic_t pin_count;atomic_t active_count; +void *hwsp_map;const u32 *hwsp_seqno;struct i915_vma *hwsp_ggtt;u32 hwsp_offset; -struct intel_timeline_cacheline *hwsp_cacheline; -bool has_initial_breadcrumb;/**
@@ -66,6 +64,8 @@ struct intel_timeline {*/ struct i915_active_fence last_request; +struct i915_active active; +/** A chain of completed timelines ready for early retirement. */ struct intel_timeline *retire;
@@ -89,15 +89,4 @@ struct intel_timeline { struct rcu_head rcu; }; -struct intel_timeline_cacheline { -struct i915_active active; - -struct intel_timeline_hwsp *hwsp; -void *vaddr; - -u32 ggtt_offset; - -struct rcu_head rcu; -}; -#endif /* __I915_TIMELINE_TYPES_H__ */
drivers/gpu/drm/i915/gt/selftest_engine_cs.c +4 -1
@@ -41,6 +41,9 @@ static int perf_end(struct intel_gt *gt)static int write_timestamp (struct i915_request *rq,int slot) { +struct intel_timeline *tl = +rcu_dereference_protected (rq->timeline, + !i915_request_signaled (rq));u32 cmd;u32 *cs;
@@ -53,7 +56,7 @@ static int write_timestamp(struct i915_request *rq, int slot) cmd++; *cs++ = cmd; *cs++ =i915_mmio_reg_offset (RING_TIMESTAMP (rq->engine->mmio_base)); - *cs++ =i915_request_timeline (rq)->hwsp_offset + slot *sizeof (u32); + *cs++ = tl->hwsp_offset + slot *sizeof (u32); *cs++ =0 ;intel_ring_advance (rq, cs);
drivers/gpu/drm/i915/gt/selftest_timeline.c +51 -32
207 lines not on this page · raw message
drivers/gpu/drm/i915/i915_request.c +0 -4
@@ -794,7 +794,6 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->fence.seqno = seqno;RCU_INIT_POINTER (rq->timeline, tl); -RCU_INIT_POINTER (rq->hwsp_cacheline, tl->hwsp_cacheline); rq->hwsp_seqno = tl->hwsp_seqno;GEM_BUG_ON (__i915_request_is_complete (rq));
@@ -1039,9 +1038,6 @@ emit_semaphore_wait(struct i915_request *to,if (i915_request_has_initial_breadcrumb (to)) goto await_fence; -if (!rcu_access_pointer (from->hwsp_cacheline)) - goto await_fence; -/* * If this or its dependents are waiting on an external fence * that may fail catastrophically, then we want to avoid using
drivers/gpu/drm/i915/i915_request.h +21 -10
@@ -239,16 +239,6 @@ struct i915_request {*/ const u32 *hwsp_seqno; -/* -* If we need to access the timeline's seqno for this request in -* another request, we need to keep a read reference to this associated -* cacheline, so that we do not free and recycle it before the foreign -* observers have completed. Hence, we keep a pointer to the cacheline -* inside the timeline's HWSP vma, but it is only valid while this -* request has not completed and guarded by the timeline mutex. -*/ -struct intel_timeline_cacheline __rcu *hwsp_cacheline; -/** Position in the ring of the start of the request */ u32 head;
@@ -650,4 +640,25 @@ static inline bool i915_request_use_semaphores(const struct i915_request *rq) return intel_engine_has_semaphores(rq->engine); } +static inline u32 +i915_request_active_seqno (const struct i915_request *rq) +{ +u32 hwsp_phys_base = +page_mask_bits (i915_request_active_timeline (rq)->hwsp_offset); +u32 hwsp_relative_offset =offset_in_page (rq->hwsp_seqno); + +/* +* Because of wraparound, we cannot simply take tl->hwsp_offset, +* but instead use the fact that the relative for vaddr is the +* offset as for hwsp_offset. Take the top bits from tl->hwsp_offset +* and combine them with the relative offset in rq->hwsp_seqno. +* +* As rw->hwsp_seqno is rewritten when signaled, this only works +* when the request isn't signaled yet, but at that point you +* no longer need the offset. +*/ + +return hwsp_phys_base + hwsp_relative_offset; +} +#endif /* I915_REQUEST_H */
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 01/69] drm/i915: Do not share hwsp across contexts any more, v7.
First off, I'm just here asking questions right now trying to start getting my head around some of this stuff. Feel free to ignore me or tell me to go away if I'm being annoying. :-)
Quoted 105 lines · Maarten Lankhorst
Instead of sharing pages with breadcrumbs, give each timeline a single page. This allows unrelated timelines not to share locks any more during command submission.
As an additional benefit, seqno wraparound no longer requires
i915_vma_pin, which means we no longer need to worry about a potential-EDEADLKat a point where we are ready to submit.Changes since v1:
- Fix erroneousi915_vma_acquirethat should be ai915_vma_release(ickle).
- Extra check for completion inintel_read_hwsp().
Changes since v2:
- Fix inconsistent indent inhwsp_alloc()(kbuild)
- memset entire cacheline to 0.
Changes since v3:
- Do same inintel_timeline_reset_seqno(), and clflush for good measure. Changes since v4:
- Use refcounting on timeline, instead of relying oni915_active.
- Fix waiting on kernel requests.
Changes since v5:
- Bump amount of slots to maximum (256), for best wraparounds.
- Addhwsp_offsettoi915_requestto fix potential wraparound hang.
- Ensure timeline wrap test works with the changes.
- Assign hwsp inintel_timeline_read_hwsp()within the rcu lock to fix a hang.
Changes since v6:
- Renamei915_request_active_offsettoi915_request_active_seqno(), and elaborate the function. (tvrtko)Signed-off-by Maarten Lankhorst <[email protected]>Reviewed-by Thomas Hellström <[email protected]> #v1Reported-by kernel test robot <[email protected]>--- drivers/gpu/drm/i915/gt/gen2_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/gen6_engine_cs.c | 8 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 13 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/gt/intel_gt_types.h | 4 - drivers/gpu/drm/i915/gt/intel_timeline.c | 422 ++++-------------- .../gpu/drm/i915/gt/intel_timeline_types.h | 17 +- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 5 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 83 ++-- drivers/gpu/drm/i915/i915_request.c | 4 - drivers/gpu/drm/i915/i915_request.h | 31 +- 11 files changed, 175 insertions(+), 415 deletions(-)drivers/gpu/drm/i915/gt/gen2_engine_cs.c +1
-1@@ -143,7 +143,7 @@ static u32 *__gen2_emit_breadcrumb(struct i915_request *rq, u32 *cs, int flush, int post) { GEM_BUG_ON(i915_request_active_timeline(rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH ;drivers/gpu/drm/i915/gt/gen6_engine_cs.c +4
-4@@ -161,7 +161,7 @@ u32 *gen6_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_DC_FLUSH_ENABLE |PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset | + *cs++ =i915_request_active_seqno (rq) |PIPE_CONTROL_GLOBAL_GTT ; *cs++ = rq->fence.seqno;@@ -359,7 +359,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_QW_WRITE |PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset; + *cs++ =i915_request_active_seqno (rq); *cs++ = rq->fence.seqno; *cs++ =MI_USER_INTERRUPT ;@@ -374,7 +374,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)u32 *gen6_emit_breadcrumb_xcs (struct i915_request *rq,u32 *cs) {GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ; *cs++ =I915_GEM_HWS_SEQNO_ADDR |MI_FLUSH_DW_USE_GTT ;@@ -394,7 +394,7 @@ u32 *gen7_emit_breadcrumb_xcs(struct i915_request *rq, u32 *cs)int i;GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_INVALIDATE_TLB |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ;drivers/gpu/drm/i915/gt/gen8_engine_cs.c +0
-0
drivers/gpu/drm/i915/gt/gen8_engine_cs.c static u32 preempt_address(struct intel_engine_cs *engine) · line 345
Quoted 10 lines
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +4
-2@@ -338,15 +338,14 @@ static u32 preempt_address(struct intel_engine_cs *engine)static u32 hwsp_offset (const struct i915_request *rq) { -const struct intel_timeline_cacheline *cl; +const struct intel_timeline *tl; -/* Before the request is executed, the timeline/cachline is fixed */ +/* Before the request is executed, the timeline is fixed */ + tl =rcu_dereference_protected (rq->timeline, + !i915_request_signaled (rq));
Why is Gen8+ different from Gen2/6 here? In particular, why not use i915_request_active_timeline(rq) or, better yet, i915_request_active_seqno()? The primary difference I see is that the guard on the RCU is different but it's not immediately obvious to me why this should be different between hardware generations. Also, i915_request_active_seqno() returns a u32, but that could be fixed.
Quoted 976 lines
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +2
-5- cl =rcu_dereference_protected (rq->hwsp_cacheline,1 ); -if (cl) -return cl->ggtt_offset; - -return rcu_dereference_protected (rq->timeline,1 )->hwsp_offset; +/* See the comment in i915_request_active_seqno(). */ +return page_mask_bits (tl->hwsp_offset) +offset_in_page (rq->hwsp_seqno); }int gen8_emit_init_breadcrumb (struct i915_request *rq)drivers/gpu/drm/i915/gt/intel_engine_cs.c +1
-0@@ -752,6 +752,7 @@ static int measure_breadcrumb_dw(struct intel_context *ce) frame->rq.engine = engine; frame->rq.context = ce;rcu_assign_pointer (frame->rq.timeline, ce->timeline); + frame->rq.hwsp_seqno = ce->timeline->hwsp_seqno; frame->ring.vaddr = frame->cs; frame->ring.size =sizeof (frame->cs);drivers/gpu/drm/i915/gt/intel_gt_types.h +0
-4@@ -45,10 +45,6 @@ struct intel_gt {struct intel_gt_timelines {spinlock_t lock;/* protects active_list */ struct list_head active_list; - -/* Pack multiple timelines' seqnos into the same page */ -spinlock_t hwsp_lock; -struct list_head hwsp_free_list; } timelines;struct intel_gt_requests {drivers/gpu/drm/i915/gt/intel_timeline.c +84
-338@@ -11,21 +11,9 @@#include "intel_ring.h" #include "intel_timeline.h" -#define ptr_set_bit (ptr, bit) ((typeof(ptr))((unsigned long)(ptr) | BIT(bit))) -#define ptr_test_bit (ptr, bit) ((unsigned long)(ptr) & BIT(bit)) +#define TIMELINE_SEQNO_BYTES 8 -#define CACHELINE_BITS 6 -#define CACHELINE_FREE CACHELINE_BITS - -struct intel_timeline_hwsp { -struct intel_gt *gt; -struct intel_gt_timelines *gt_timelines; -struct list_head free_link; -struct i915_vma *vma; -u64 free_bitmap; -}; - -static struct i915_vma *__hwsp_alloc (struct intel_gt *gt) +static struct i915_vma *hwsp_alloc (struct intel_gt *gt) {struct drm_i915_private *i915 = gt->i915;struct drm_i915_gem_object *obj;@@ -44,220 +32,59 @@ static struct i915_vma *__hwsp_alloc(struct intel_gt *gt)return vma; } -static struct i915_vma * -hwsp_alloc (struct intel_timeline *timeline,unsigned int *cacheline) -{ -struct intel_gt_timelines *gt = &timeline->gt->timelines; -struct intel_timeline_hwsp *hwsp; - -BUILD_BUG_ON (BITS_PER_TYPE (u64) *CACHELINE_BYTES >PAGE_SIZE ); - -spin_lock_irq (>->hwsp_lock); - -/* hwsp_free_list only contains HWSP that have available cachelines */ - hwsp =list_first_entry_or_null (>->hwsp_free_list, -typeof (*hwsp), free_link); -if (!hwsp) { -struct i915_vma *vma; - -spin_unlock_irq (>->hwsp_lock); - - hwsp =kmalloc (sizeof (*hwsp),GFP_KERNEL ); -if (!hwsp) -return ERR_PTR (-ENOMEM ); - - vma =__hwsp_alloc (timeline->gt); -if (IS_ERR (vma)) { -kfree (hwsp); -return vma; - } - -GT_TRACE (timeline->gt,"new HWSP allocated\n" ); - - vma->private = hwsp; - hwsp->gt = timeline->gt; - hwsp->vma = vma; - hwsp->free_bitmap = ~0ull ; - hwsp->gt_timelines = gt; - -spin_lock_irq (>->hwsp_lock); -list_add (&hwsp->free_link, >->hwsp_free_list); - } - -GEM_BUG_ON (!hwsp->free_bitmap); - *cacheline =__ffs64 (hwsp->free_bitmap); - hwsp->free_bitmap &= ~BIT_ULL (*cacheline); -if (!hwsp->free_bitmap) -list_del (&hwsp->free_link); - -spin_unlock_irq (>->hwsp_lock); - -GEM_BUG_ON (hwsp->vma->private != hwsp); -return hwsp->vma; -} - -static void __idle_hwsp_free (struct intel_timeline_hwsp *hwsp,int cacheline) -{ -struct intel_gt_timelines *gt = hwsp->gt_timelines; -unsigned long flags; - -spin_lock_irqsave (>->hwsp_lock, flags); - -/* As a cacheline becomes available, publish the HWSP on the freelist */ -if (!hwsp->free_bitmap) -list_add_tail (&hwsp->free_link, >->hwsp_free_list); - -GEM_BUG_ON (cacheline >=BITS_PER_TYPE (hwsp->free_bitmap)); - hwsp->free_bitmap |=BIT_ULL (cacheline); - -/* And if no one is left using it, give the page back to the system */ -if (hwsp->free_bitmap == ~0ull ) { -i915_vma_put (hwsp->vma); -list_del (&hwsp->free_link); -kfree (hwsp); - } - -spin_unlock_irqrestore (>->hwsp_lock, flags); -} - -static void __rcu_cacheline_free (struct rcu_head *rcu) -{ -struct intel_timeline_cacheline *cl = -container_of (rcu,typeof (*cl), rcu); - -/* Must wait until after all *rq->hwsp are complete before removing */ -i915_gem_object_unpin_map (cl->hwsp->vma->obj); -__idle_hwsp_free (cl->hwsp,ptr_unmask_bits (cl->vaddr,CACHELINE_BITS )); - -i915_active_fini (&cl->active); -kfree (cl); -} - -static void __idle_cacheline_free (struct intel_timeline_cacheline *cl) -{ -GEM_BUG_ON (!i915_active_is_idle (&cl->active)); -call_rcu (&cl->rcu, __rcu_cacheline_free); -} -__i915_active_call -static void __cacheline_retire(struct i915_active *active) +static void __timeline_retire(struct i915_active *active) { -struct intel_timeline_cacheline *cl = -container_of (active,typeof (*cl), active); +struct intel_timeline *tl = +container_of (active,typeof (*tl), active); -i915_vma_unpin (cl->hwsp->vma); -if (ptr_test_bit (cl->vaddr,CACHELINE_FREE )) -__idle_cacheline_free (cl); +i915_vma_unpin (tl->hwsp_ggtt); +intel_timeline_put (tl); } -static int __cacheline_active (struct i915_active *active) +static int __timeline_active (struct i915_active *active) { -struct intel_timeline_cacheline *cl = -container_of (active,typeof (*cl), active); +struct intel_timeline *tl = +container_of (active,typeof (*tl), active); -__i915_vma_pin (cl->hwsp->vma); +__i915_vma_pin (tl->hwsp_ggtt); +intel_timeline_get (tl);return 0 ; } -static struct intel_timeline_cacheline * -cacheline_alloc (struct intel_timeline_hwsp *hwsp,unsigned int cacheline) -{ -struct intel_timeline_cacheline *cl; -void *vaddr; - -GEM_BUG_ON (cacheline >=BIT (CACHELINE_BITS )); - - cl =kmalloc (sizeof (*cl),GFP_KERNEL ); -if (!cl) -return ERR_PTR (-ENOMEM ); - - vaddr =i915_gem_object_pin_map (hwsp->vma->obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) { -kfree (cl); -return ERR_CAST (vaddr); - } - - cl->hwsp = hwsp; - cl->vaddr =page_pack_bits (vaddr, cacheline); - -i915_active_init (&cl->active, __cacheline_active, __cacheline_retire); - -return cl; -} - -static void cacheline_acquire (struct intel_timeline_cacheline *cl, -u32 ggtt_offset) -{ -if (!cl) -return ; - - cl->ggtt_offset = ggtt_offset; -i915_active_acquire (&cl->active); -} - -static void cacheline_release (struct intel_timeline_cacheline *cl) -{ -if (cl) -i915_active_release (&cl->active); -} - -static void cacheline_free (struct intel_timeline_cacheline *cl) -{ -if (!i915_active_acquire_if_busy (&cl->active)) { -__idle_cacheline_free (cl); -return ; - } - -GEM_BUG_ON (ptr_test_bit (cl->vaddr,CACHELINE_FREE )); - cl->vaddr =ptr_set_bit (cl->vaddr,CACHELINE_FREE ); - -i915_active_release (&cl->active); -} -static int intel_timeline_init (struct intel_timeline *timeline,struct intel_gt *gt,struct i915_vma *hwsp,unsigned int offset) {void *vaddr; +u32 *seqno;kref_init (&timeline->kref);atomic_set (&timeline->pin_count,0 ); timeline->gt = gt; - timeline->has_initial_breadcrumb = !hwsp; - timeline->hwsp_cacheline =NULL ; - -if (!hwsp) { -struct intel_timeline_cacheline *cl; -unsigned int cacheline; - - hwsp =hwsp_alloc (timeline, &cacheline); +if (hwsp) { + timeline->hwsp_offset = offset; + timeline->hwsp_ggtt =i915_vma_get (hwsp); + }else { + timeline->has_initial_breadcrumb = true; + hwsp =hwsp_alloc (gt);if (IS_ERR (hwsp))return PTR_ERR (hwsp); - - cl =cacheline_alloc (hwsp->private, cacheline); -if (IS_ERR (cl)) { -__idle_hwsp_free (hwsp->private, cacheline); -return PTR_ERR (cl); - } - - timeline->hwsp_cacheline = cl; - timeline->hwsp_offset = cacheline *CACHELINE_BYTES ; - - vaddr =page_mask_bits (cl->vaddr); - }else { - timeline->hwsp_offset = offset; - vaddr =i915_gem_object_pin_map (hwsp->obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) -return PTR_ERR (vaddr); + timeline->hwsp_ggtt = hwsp; } - timeline->hwsp_seqno = -memset (vaddr + timeline->hwsp_offset,0 ,CACHELINE_BYTES ); + vaddr =i915_gem_object_pin_map (hwsp->obj,I915_MAP_WB ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + timeline->hwsp_map = vaddr; + seqno = vaddr + timeline->hwsp_offset; +WRITE_ONCE (*seqno,0 ); + timeline->hwsp_seqno = seqno; - timeline->hwsp_ggtt =i915_vma_get (hwsp);GEM_BUG_ON (timeline->hwsp_offset >= hwsp->size); timeline->fence_context =dma_fence_context_alloc (1 );@@ -268,6 +95,7 @@ static int intel_timeline_init(struct intel_timeline *timeline,INIT_LIST_HEAD (&timeline->requests);i915_syncmap_init (&timeline->sync); +i915_active_init (&timeline->active, __timeline_active, __timeline_retire);return 0 ; }@@ -278,23 +106,18 @@ void intel_gt_init_timelines(struct intel_gt *gt)spin_lock_init (&timelines->lock);INIT_LIST_HEAD (&timelines->active_list); - -spin_lock_init (&timelines->hwsp_lock); -INIT_LIST_HEAD (&timelines->hwsp_free_list); } -static void intel_timeline_fini (struct intel_timeline *timeline) +static void intel_timeline_fini (struct rcu_head *rcu) { -GEM_BUG_ON (atomic_read (&timeline->pin_count)); -GEM_BUG_ON (!list_empty (&timeline->requests)); -GEM_BUG_ON (timeline->retire); +struct intel_timeline *timeline = + container_of(rcu, struct intel_timeline, rcu); -if (timeline->hwsp_cacheline) -cacheline_free (timeline->hwsp_cacheline); -else -i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj); +i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj);i915_vma_put (timeline->hwsp_ggtt); +i915_active_fini (&timeline->active); +kfree (timeline); } struct intel_timeline *@@ -360,9 +183,9 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)GT_TRACE (tl->gt,"timeline:%llx using HWSP offset:%x\n" , tl->fence_context, tl->hwsp_offset); -cacheline_acquire (tl->hwsp_cacheline, tl->hwsp_offset); +i915_active_acquire (&tl->active);if (atomic_fetch_inc (&tl->pin_count)) { -cacheline_release (tl->hwsp_cacheline); +i915_active_release (&tl->active);__i915_vma_unpin (tl->hwsp_ggtt); }@@ -371,9 +194,13 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)void intel_timeline_reset_seqno (const struct intel_timeline *tl) { +u32 *hwsp_seqno = (u32 *)tl->hwsp_seqno;/* Must be pinned to be writable, and no requests in flight. */ GEM_BUG_ON (!atomic_read (&tl->pin_count)); -WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno); + +memset (hwsp_seqno +1 ,0 ,TIMELINE_SEQNO_BYTES -sizeof (*hwsp_seqno)); +WRITE_ONCE (*hwsp_seqno, tl->seqno); +clflush (hwsp_seqno); }void intel_timeline_enter (struct intel_timeline *tl)@@ -449,106 +276,23 @@ static u32 timeline_advance(struct intel_timeline *tl)return tl->seqno +=1 + tl->has_initial_breadcrumb; } -static void timeline_rollback (struct intel_timeline *tl) -{ - tl->seqno -=1 + tl->has_initial_breadcrumb; -} - static noinline int__intel_timeline_get_seqno (struct intel_timeline *tl, -struct i915_request *rq,u32 *seqno) { -struct intel_timeline_cacheline *cl; -unsigned int cacheline; -struct i915_vma *vma; -void *vaddr; -int err; - -might_lock (&tl->gt->ggtt->vm.mutex); -GT_TRACE (tl->gt,"timeline:%llx wrapped\n" , tl->fence_context); - -/* -* If there is an outstanding GPU reference to this cacheline, -* such as it being sampled by a HW semaphore on another timeline, -* we cannot wraparound our seqno value (the HW semaphore does -* a strict greater-than-or-equals compare, not i915_seqno_passed). -* So if the cacheline is still busy, we must detach ourselves -* from it and leave it inflight alongside its users. -* -* However, if nobody is watching and we can guarantee that nobody -* will, we could simply reuse the same cacheline. -* -* if (i915_active_request_is_signaled(&tl->last_request) && -* i915_active_is_signaled(&tl->hwsp_cacheline->active)) -* return 0; -* -* That seems unlikely for a busy timeline that needed to wrap in -* the first place, so just replace the cacheline. -*/ - - vma =hwsp_alloc (tl, &cacheline); -if (IS_ERR (vma)) { - err =PTR_ERR (vma); - goto err_rollback; - } - - err =i915_ggtt_pin (vma,NULL ,0 ,PIN_HIGH ); -if (err) { -__idle_hwsp_free (vma->private, cacheline); - goto err_rollback; - } +u32 next_ofs =offset_in_page (tl->hwsp_offset +TIMELINE_SEQNO_BYTES ); - cl =cacheline_alloc (vma->private, cacheline); -if (IS_ERR (cl)) { - err =PTR_ERR (cl); -__idle_hwsp_free (vma->private, cacheline); - goto err_unpin; - } -GEM_BUG_ON (cl->hwsp->vma != vma); - -/* -* Attach the old cacheline to the current request, so that we only -* free it after the current request is retired, which ensures that -* all writes into the cacheline from previous requests are complete. -*/ - err =i915_active_ref (&tl->hwsp_cacheline->active, - tl->fence_context, - &rq->fence); -if (err) - goto err_cacheline; +/* w/a: bit 5 needs to be zero for MI_FLUSH_DW address. */ +if (TIMELINE_SEQNO_BYTES <=BIT (5 ) && (next_ofs &BIT (5 ))) + next_ofs =offset_in_page (next_ofs +BIT (5 )); -cacheline_release (tl->hwsp_cacheline);/* ownership now xfered to rq */ -cacheline_free (tl->hwsp_cacheline); - -i915_vma_unpin (tl->hwsp_ggtt);/* binding kept alive by old cacheline */ -i915_vma_put (tl->hwsp_ggtt); - - tl->hwsp_ggtt =i915_vma_get (vma); - - vaddr =page_mask_bits (cl->vaddr); - tl->hwsp_offset = cacheline *CACHELINE_BYTES ; - tl->hwsp_seqno = -memset (vaddr + tl->hwsp_offset,0 ,CACHELINE_BYTES ); - - tl->hwsp_offset +=i915_ggtt_offset (vma); -GT_TRACE (tl->gt,"timeline:%llx using HWSP offset:%x\n" , - tl->fence_context, tl->hwsp_offset); - -cacheline_acquire (cl, tl->hwsp_offset); - tl->hwsp_cacheline = cl; + tl->hwsp_offset =i915_ggtt_offset (tl->hwsp_ggtt) + next_ofs; + tl->hwsp_seqno = tl->hwsp_map + next_ofs; +intel_timeline_reset_seqno (tl); *seqno =timeline_advance (tl);GEM_BUG_ON (i915_seqno_passed (*tl->hwsp_seqno, *seqno));return 0 ; - -err_cacheline: -cacheline_free (cl); -err_unpin: -i915_vma_unpin (vma); -err_rollback: -timeline_rollback (tl); -return err; } int intel_timeline_get_seqno(struct intel_timeline *tl,@@ -558,51 +302,52 @@ int intel_timeline_get_seqno(struct intel_timeline *tl, *seqno =timeline_advance (tl);/* Replace the HWSP on wraparound for HW semaphores */ -if (unlikely (!*seqno && tl->hwsp_cacheline)) -return __intel_timeline_get_seqno (tl, rq, seqno); +if (unlikely (!*seqno && tl->has_initial_breadcrumb)) +return __intel_timeline_get_seqno (tl, seqno);return 0 ; } -static int cacheline_ref (struct intel_timeline_cacheline *cl, -struct i915_request *rq) -{ -return i915_active_add_request (&cl->active, rq); -} -int intel_timeline_read_hwsp (struct i915_request *from,struct i915_request *to,u32 *hwsp) { -struct intel_timeline_cacheline *cl; +struct intel_timeline *tl;int err; -GEM_BUG_ON (!rcu_access_pointer (from->hwsp_cacheline)); -rcu_read_lock (); - cl =rcu_dereference (from->hwsp_cacheline); -if (i915_request_signaled (from))/* confirm cacheline is valid */ - goto unlock; -if (unlikely (!i915_active_acquire_if_busy (&cl->active))) - goto unlock;/* seqno wrapped and completed! */ -if (unlikely (__i915_request_is_complete (from))) - goto release; + tl =rcu_dereference (from->timeline); +if (i915_request_signaled (from) || + !i915_active_acquire_if_busy (&tl->active)) + tl =NULL ; + +if (tl) { +/* hwsp_offset may wraparound, so use from->hwsp_seqno */ + *hwsp =i915_ggtt_offset (tl->hwsp_ggtt) + +offset_in_page (from->hwsp_seqno); + } + +/* ensure we wait on the right request, if not, we completed */ +if (tl &&__i915_request_is_complete (from)) { +i915_active_release (&tl->active); + tl =NULL ; + }rcu_read_unlock (); - err =cacheline_ref (cl, to); -if (err) +if (!tl) +return 1 ; + +/* Can't do semaphore waits on kernel context */ +if (!tl->has_initial_breadcrumb) { + err = -EINVAL ; goto out; + } + + err =i915_active_add_request (&tl->active, to); - *hwsp = cl->ggtt_offset; out: -i915_active_release (&cl->active); +i915_active_release (&tl->active);return err; - -release: -i915_active_release (&cl->active); -unlock: -rcu_read_unlock (); -return 1 ; }void intel_timeline_unpin (struct intel_timeline *tl)@@ -611,8 +356,7 @@ void intel_timeline_unpin(struct intel_timeline *tl)if (!atomic_dec_and_test (&tl->pin_count))return ; -cacheline_release (tl->hwsp_cacheline); - +i915_active_release (&tl->active);__i915_vma_unpin (tl->hwsp_ggtt); }@@ -621,8 +365,11 @@ void __intel_timeline_free(struct kref *kref)struct intel_timeline *timeline =container_of (kref,typeof (*timeline), kref); -intel_timeline_fini (timeline); -kfree_rcu (timeline, rcu); +GEM_BUG_ON (atomic_read (&timeline->pin_count)); +GEM_BUG_ON (!list_empty (&timeline->requests)); +GEM_BUG_ON (timeline->retire); + +call_rcu (&timeline->rcu, intel_timeline_fini); }void intel_gt_fini_timelines (struct intel_gt *gt)@@ -630,7 +377,6 @@ void intel_gt_fini_timelines(struct intel_gt *gt)struct intel_gt_timelines *timelines = >->timelines;GEM_BUG_ON (!list_empty (&timelines->active_list)); -GEM_BUG_ON (!list_empty (&timelines->hwsp_free_list)); } void intel_gt_show_timelines(struct intel_gt *gt,drivers/gpu/drm/i915/gt/intel_timeline_types.h +3
-14@@ -17,7 +17,6 @@struct i915_vma ;struct i915_syncmap ;struct intel_gt ; -struct intel_timeline_hwsp ;struct intel_timeline {u64 fence_context;@@ -44,12 +43,11 @@ struct intel_timeline {atomic_t pin_count;atomic_t active_count; +void *hwsp_map;const u32 *hwsp_seqno;struct i915_vma *hwsp_ggtt;u32 hwsp_offset; -struct intel_timeline_cacheline *hwsp_cacheline; -bool has_initial_breadcrumb;/** @@ -66,6 +64,8 @@ struct intel_timeline {*/ struct i915_active_fence last_request; +struct i915_active active; +/** A chain of completed timelines ready for early retirement. */ struct intel_timeline *retire;@@ -89,15 +89,4 @@ struct intel_timeline { struct rcu_head rcu; }; -struct intel_timeline_cacheline { -struct i915_active active; - -struct intel_timeline_hwsp *hwsp; -void *vaddr; - -u32 ggtt_offset; - -struct rcu_head rcu; -}; -#endif /* __I915_TIMELINE_TYPES_H__ */ drivers/gpu/drm/i915/gt/selftest_engine_cs.c +4
-1@@ -41,6 +41,9 @@ static int perf_end(struct intel_gt *gt)static int write_timestamp (struct i915_request *rq,int slot) { +struct intel_timeline *tl = +rcu_dereference_protected (rq->timeline, + !i915_request_signaled (rq));u32 cmd;u32 *cs;@@ -53,7 +56,7 @@ static int write_timestamp(struct i915_request *rq, int slot) cmd++; *cs++ = cmd; *cs++ =i915_mmio_reg_offset (RING_TIMESTAMP (rq->engine->mmio_base)); - *cs++ =i915_request_timeline (rq)->hwsp_offset + slot *sizeof (u32); + *cs++ = tl->hwsp_offset + slot *sizeof (u32); *cs++ =0 ;intel_ring_advance (rq, cs);drivers/gpu/drm/i915/gt/selftest_timeline.c +51
-32@@ -665,7 +665,7 @@ static int live_hwsp_wrap(void *arg)if (IS_ERR (tl))return PTR_ERR (tl); -if (!tl->has_initial_breadcrumb || !tl->hwsp_cacheline) +if (!tl->has_initial_breadcrumb) goto out_free; err =intel_timeline_pin (tl,NULL );@@ -832,12 +832,26 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt)return 0 ; } +static void switch_tl_lock (struct i915_request *from,struct i915_request *to) +{ +/* some light mutex juggling required; think co-routines */ + +if (from) { +lockdep_unpin_lock (&from->context->timeline->mutex, from->cookie); +mutex_unlock (&from->context->timeline->mutex); + } + +if (to) { +mutex_lock (&to->context->timeline->mutex); + to->cookie =lockdep_pin_lock (&to->context->timeline->mutex); + } +} +static int create_watcher (struct hwsp_watcher *w,struct intel_engine_cs *engine,int ringsz) {struct intel_context *ce; -struct intel_timeline *tl; ce =intel_context_create (engine);if (IS_ERR (ce))@@ -850,11 +864,8 @@ static int create_watcher(struct hwsp_watcher *w,return PTR_ERR (w->rq); w->addr =i915_ggtt_offset (w->vma); - tl = w->rq->context->timeline; -/* some light mutex juggling required; think co-routines */ -lockdep_unpin_lock (&tl->mutex, w->rq->cookie); -mutex_unlock (&tl->mutex); +switch_tl_lock (w->rq,NULL );return 0 ; }@@ -863,15 +874,13 @@ static int check_watcher(struct hwsp_watcher *w, const char *name, bool (*op)(u32 hwsp, u32 seqno)) {struct i915_request *rq =fetch_and_zero (&w->rq); -struct intel_timeline *tl = rq->context->timeline;u32 offset, end;int err;GEM_BUG_ON (w->addr -i915_ggtt_offset (w->vma) > w->vma->size);i915_request_get (rq); -mutex_lock (&tl->mutex); - rq->cookie =lockdep_pin_lock (&tl->mutex); +switch_tl_lock (NULL , rq);i915_request_add (rq);if (i915_request_wait (rq,0 ,HZ ) <0 ) {@@ -900,10 +909,7 @@ static int check_watcher(struct hwsp_watcher *w, const char *name,static void cleanup_watcher (struct hwsp_watcher *w) {if (w->rq) { -struct intel_timeline *tl = w->rq->context->timeline; - -mutex_lock (&tl->mutex); - w->rq->cookie =lockdep_pin_lock (&tl->mutex); +switch_tl_lock (NULL , w->rq);i915_request_add (w->rq); }@@ -941,7 +947,7 @@ static struct i915_request *wrap_timeline(struct i915_request *rq) }i915_request_put (rq); - rq =intel_context_create_request (ce); + rq =i915_request_create (ce);if (IS_ERR (rq))return rq;@@ -976,7 +982,7 @@ static int live_hwsp_read(void *arg)if (IS_ERR (tl))return PTR_ERR (tl); -if (!tl->hwsp_cacheline) +if (!tl->has_initial_breadcrumb) goto out_free;for (i =0 ; i <ARRAY_SIZE (watcher); i++) {@@ -998,7 +1004,7 @@ static int live_hwsp_read(void *arg) do { struct i915_sw_fence *submit; struct i915_request *rq; - u32 hwsp; + u32 hwsp, dummy; submit = heap_fence_create(GFP_KERNEL); if (!submit) {@@ -1016,14 +1022,26 @@ static int live_hwsp_read(void *arg) goto out; } -/* Skip to the end, saving 30 minutes of nops */ - tl->seqno =-10u +2 * (count &3 ); -WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno); ce->timeline =intel_timeline_get (tl); - rq =intel_context_create_request (ce); +/* Ensure timeline is mapped, done during first pin */ + err =intel_context_pin (ce); +if (err) { +intel_context_put (ce); + goto out; + } + +/* +* Start at a new wrap, and set seqno right before another wrap, +* saving 30 minutes of nops +*/ + tl->seqno =-12u +2 * (count &3 ); +__intel_timeline_get_seqno (tl, &dummy); + + rq =i915_request_create (ce);if (IS_ERR (rq)) { err =PTR_ERR (rq); +intel_context_unpin (ce);intel_context_put (ce); goto out; }@@ -1033,32 +1051,35 @@ static int live_hwsp_read(void *arg) GFP_KERNEL);if (err <0 ) {i915_request_add (rq); +intel_context_unpin (ce);intel_context_put (ce); goto out; } -mutex_lock (&watcher[0 ].rq->context->timeline->mutex); +switch_tl_lock (rq, watcher[0 ].rq); err =intel_timeline_read_hwsp (rq, watcher[0 ].rq, &hwsp);if (err ==0 ) err =emit_read_hwsp (watcher[0 ].rq,/* before */ rq->fence.seqno, hwsp, &watcher[0 ].addr); -mutex_unlock (&watcher[0 ].rq->context->timeline->mutex); +switch_tl_lock (watcher[0 ].rq, rq);if (err) {i915_request_add (rq); +intel_context_unpin (ce);intel_context_put (ce); goto out; } -mutex_lock (&watcher[1 ].rq->context->timeline->mutex); +switch_tl_lock (rq, watcher[1 ].rq); err =intel_timeline_read_hwsp (rq, watcher[1 ].rq, &hwsp);if (err ==0 ) err =emit_read_hwsp (watcher[1 ].rq,/* after */ rq->fence.seqno, hwsp, &watcher[1 ].addr); -mutex_unlock (&watcher[1 ].rq->context->timeline->mutex); +switch_tl_lock (watcher[1 ].rq, rq);if (err) {i915_request_add (rq); +intel_context_unpin (ce);intel_context_put (ce); goto out; }@@ -1067,6 +1088,7 @@ static int live_hwsp_read(void *arg)i915_request_add (rq); rq =wrap_timeline (rq); +intel_context_unpin (ce);intel_context_put (ce);if (IS_ERR (rq)) { err =PTR_ERR (rq);@@ -1106,8 +1128,8 @@ static int live_hwsp_read(void *arg) 3 * watcher[1].rq->ring->size)break ; - }while (!__igt_timeout (end_time,NULL )); -WRITE_ONCE (*(u32 *)tl->hwsp_seqno,0xdeadbeef ); + }while (!__igt_timeout (end_time,NULL ) && + count < (PAGE_SIZE /TIMELINE_SEQNO_BYTES -1 ) /2 );pr_info ("%s: simulated %lu wraps\n" , engine->name, count); err =check_watcher (&watcher[1 ],"after" , cmp_gte);@@ -1152,9 +1174,7 @@ static int live_hwsp_rollover_kernel(void *arg) }GEM_BUG_ON (i915_active_fence_isset (&tl->last_request)); - tl->seqno =0 ; -timeline_rollback (tl); -timeline_rollback (tl); + tl->seqno =-2u ;WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno);for (i =0 ; i <ARRAY_SIZE (rq); i++) {@@ -1234,11 +1254,10 @@ static int live_hwsp_rollover_user(void *arg) goto out; tl = ce->timeline; -if (!tl->has_initial_breadcrumb || !tl->hwsp_cacheline) +if (!tl->has_initial_breadcrumb) goto out; -timeline_rollback (tl); -timeline_rollback (tl); + tl->seqno =-4u ;WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno);for (i =0 ; i <ARRAY_SIZE (rq); i++) {drivers/gpu/drm/i915/i915_request.c +0
-4@@ -794,7 +794,6 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp) rq->fence.seqno = seqno;RCU_INIT_POINTER (rq->timeline, tl); -RCU_INIT_POINTER (rq->hwsp_cacheline, tl->hwsp_cacheline); rq->hwsp_seqno = tl->hwsp_seqno;GEM_BUG_ON (__i915_request_is_complete (rq));@@ -1039,9 +1038,6 @@ emit_semaphore_wait(struct i915_request *to,if (i915_request_has_initial_breadcrumb (to)) goto await_fence; -if (!rcu_access_pointer (from->hwsp_cacheline)) - goto await_fence; -/* * If this or its dependents are waiting on an external fence * that may fail catastrophically, then we want to avoid using drivers/gpu/drm/i915/i915_request.h +21
-11@@ -239,16 +239,6 @@ struct i915_request {*/ const u32 *hwsp_seqno; -/* -* If we need to access the timeline's seqno for this request in -* another request, we need to keep a read reference to this associated -* cacheline, so that we do not free and recycle it before the foreign -* observers have completed. Hence, we keep a pointer to the cacheline -* inside the timeline's HWSP vma, but it is only valid while this -* request has not completed and guarded by the timeline mutex. -*/ -struct intel_timeline_cacheline __rcu *hwsp_cacheline; -/** Position in the ring of the start of the request */ u32 head;@@ -650,4 +640,25 @@ static inline bool i915_request_use_semaphores(const struct i915_request *rq) return intel_engine_has_semaphores(rq->engine); } +static inline u32 +i915_request_active_seqno (const struct i915_request *rq) +{ +u32 hwsp_phys_base = +page_mask_bits (i915_request_active_timeline (rq)->hwsp_offset); +u32 hwsp_relative_offset =offset_in_page (rq->hwsp_seqno); + +/* +* Because of wraparound, we cannot simply take tl->hwsp_offset, +* but instead use the fact that the relative for vaddr is the +* offset as for hwsp_offset. Take the top bits from tl->hwsp_offset +* and combine them with the relative offset in rq->hwsp_seqno. +* +* As rw->hwsp_seqno is rewritten when signaled, this only works +* when the request isn't signaled yet, but at that point you +* no longer need the offset. +*/ + +return hwsp_phys_base + hwsp_relative_offset; +} +#endif /* I915_REQUEST_H */ --2.30.1
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 01/69] drm/i915: Do not share hwsp across contexts any more, v7.
Op 2021-03-11 om 22:22 schreef Jason Ekstrand:
Quoted 116 lines
First off, I'm just here asking questions right now trying to start getting my head around some of this stuff. Feel free to ignore me or tell me to go away if I'm being annoying. :-)
Quoted 110 lines · Maarten Lankhorst
Instead of sharing pages with breadcrumbs, give each timeline a single page. This allows unrelated timelines not to share locks any more during command submission.
As an additional benefit, seqno wraparound no longer requires
i915_vma_pin, which means we no longer need to worry about a potential-EDEADLKat a point where we are ready to submit.Changes since v1:
- Fix erroneousi915_vma_acquirethat should be ai915_vma_release(ickle).
- Extra check for completion inintel_read_hwsp().
Changes since v2:
- Fix inconsistent indent inhwsp_alloc()(kbuild)
- memset entire cacheline to 0.
Changes since v3:
- Do same inintel_timeline_reset_seqno(), and clflush for good measure. Changes since v4:
- Use refcounting on timeline, instead of relying oni915_active.
- Fix waiting on kernel requests.
Changes since v5:
- Bump amount of slots to maximum (256), for best wraparounds.
- Addhwsp_offsettoi915_requestto fix potential wraparound hang.
- Ensure timeline wrap test works with the changes.
- Assign hwsp inintel_timeline_read_hwsp()within the rcu lock to fix a hang.
Changes since v6:
- Renamei915_request_active_offsettoi915_request_active_seqno(), and elaborate the function. (tvrtko)Signed-off-by Maarten Lankhorst <[email protected]>Reviewed-by Thomas Hellström <[email protected]> #v1Reported-by kernel test robot <[email protected]>--- drivers/gpu/drm/i915/gt/gen2_engine_cs.c | 2 +- drivers/gpu/drm/i915/gt/gen6_engine_cs.c | 8 +- drivers/gpu/drm/i915/gt/gen8_engine_cs.c | 13 +- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 1 + drivers/gpu/drm/i915/gt/intel_gt_types.h | 4 - drivers/gpu/drm/i915/gt/intel_timeline.c | 422 ++++-------------- .../gpu/drm/i915/gt/intel_timeline_types.h | 17 +- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 5 +- drivers/gpu/drm/i915/gt/selftest_timeline.c | 83 ++-- drivers/gpu/drm/i915/i915_request.c | 4 - drivers/gpu/drm/i915/i915_request.h | 31 +- 11 files changed, 175 insertions(+), 415 deletions(-)drivers/gpu/drm/i915/gt/gen2_engine_cs.c +1
-1@@ -143,7 +143,7 @@ static u32 *__gen2_emit_breadcrumb(struct i915_request *rq, u32 *cs, int flush, int post) { GEM_BUG_ON(i915_request_active_timeline(rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH ;drivers/gpu/drm/i915/gt/gen6_engine_cs.c +4
-4@@ -161,7 +161,7 @@ u32 *gen6_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_DC_FLUSH_ENABLE |PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset | + *cs++ =i915_request_active_seqno (rq) |PIPE_CONTROL_GLOBAL_GTT ; *cs++ = rq->fence.seqno;@@ -359,7 +359,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)PIPE_CONTROL_QW_WRITE |PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_CS_STALL); - *cs++ =i915_request_active_timeline (rq)->hwsp_offset; + *cs++ =i915_request_active_seqno (rq); *cs++ = rq->fence.seqno; *cs++ =MI_USER_INTERRUPT ;@@ -374,7 +374,7 @@ u32 *gen7_emit_breadcrumb_rcs(struct i915_request *rq, u32 *cs)u32 *gen6_emit_breadcrumb_xcs (struct i915_request *rq,u32 *cs) {GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ; *cs++ =I915_GEM_HWS_SEQNO_ADDR |MI_FLUSH_DW_USE_GTT ;@@ -394,7 +394,7 @@ u32 *gen7_emit_breadcrumb_xcs(struct i915_request *rq, u32 *cs)int i;GEM_BUG_ON (i915_request_active_timeline (rq)->hwsp_ggtt != rq->engine->status_page.vma); -GEM_BUG_ON (offset_in_page (i915_request_active_timeline (rq)->hwsp_offset) !=I915_GEM_HWS_SEQNO_ADDR ); +GEM_BUG_ON (offset_in_page (rq->hwsp_seqno) !=I915_GEM_HWS_SEQNO_ADDR ); *cs++ =MI_FLUSH_DW |MI_INVALIDATE_TLB |MI_FLUSH_DW_OP_STOREDW |MI_FLUSH_DW_STORE_INDEX ;drivers/gpu/drm/i915/gt/gen8_engine_cs.c +1
-1@@ -338,15 +338,14 @@ static u32 preempt_address(struct intel_engine_cs *engine)static u32 hwsp_offset (const struct i915_request *rq) { -const struct intel_timeline_cacheline *cl; +const struct intel_timeline *tl;
Quoted 10 lines
drivers/gpu/drm/i915/gt/gen8_engine_cs.c static u32 preempt_address(struct intel_engine_cs *engine) · line 345
Quoted 4 lines
drivers/gpu/drm/i915/gt/gen8_engine_cs.c +3
-1-/* Before the request is executed, the timeline/cachline is fixed */ +/* Before the request is executed, the timeline is fixed */ + tl =rcu_dereference_protected (rq->timeline, + !i915_request_signaled (rq));Why is Gen8+ different from Gen2/6 here? In particular, why not use
i915_request_active_timeline(rq)or, better yet,i915_request_active_seqno()? The primary difference I see is that the guard on the RCU is different but it's not immediately obvious to me why this should be different between hardware generations. Also,i915_request_active_seqno()returns a u32, but that could be fixed.
The legacy rings different locking, and it was splatting on PROVE_RCU.
I didn't want to weaken it, so I just put in a different condition for gen8 that's slightly weaker, but still better than the '1'.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 2/69 drm/i915: Pin timeline map after first timeline pin, v3.
In reply to Maarten LankhorstWe're starting to require the reservation lock for pinning, so wait until we have that.
Update the selftests to handle this correctly, and ensure pin is called in live_hwsp_rollover_user() and mock_hwsp_freelist().
Changes since v1:
- Fix NULL + XX arithmatic, use casts. (kbuild)
Changes since v2:
- Clear entire cacheline when pinning.
--- drivers/gpu/drm/i915/gt/intel_timeline.c | 40 +++++++++---- drivers/gpu/drm/i915/gt/intel_timeline.h | 2 + drivers/gpu/drm/i915/gt/mock_engine.c | 22 ++++++- drivers/gpu/drm/i915/gt/selftest_timeline.c | 63 +++++++++++---------- drivers/gpu/drm/i915/i915_selftest.h | 2 + 5 files changed, 84 insertions(+), 45 deletions(-)
drivers/gpu/drm/i915/gt/intel_timeline.c +28 -12
@@ -52,14 +52,29 @@ static int __timeline_active(struct i915_active *active)return 0 ; } +I915_SELFTEST_EXPORT int +intel_timeline_pin_map (struct intel_timeline *timeline) +{ +struct drm_i915_gem_object *obj = timeline->hwsp_ggtt->obj; +u32 ofs =offset_in_page (timeline->hwsp_offset); +void *vaddr; + + vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + timeline->hwsp_map = vaddr; + timeline->hwsp_seqno =memset (vaddr + ofs,0 ,CACHELINE_BYTES ); +clflush (vaddr + ofs); + +return 0 ; +} +static int intel_timeline_init (struct intel_timeline *timeline,struct intel_gt *gt,struct i915_vma *hwsp,unsigned int offset) { -void *vaddr; -u32 *seqno; -kref_init (&timeline->kref);atomic_set (&timeline->pin_count,0 );
@@ -76,14 +91,8 @@ static int intel_timeline_init(struct intel_timeline *timeline, timeline->hwsp_ggtt = hwsp; } - vaddr =i915_gem_object_pin_map (hwsp->obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) -return PTR_ERR (vaddr); - - timeline->hwsp_map = vaddr; - seqno = vaddr + timeline->hwsp_offset; -WRITE_ONCE (*seqno,0 ); - timeline->hwsp_seqno = seqno; + timeline->hwsp_map =NULL ; + timeline->hwsp_seqno = (void *)(long )timeline->hwsp_offset;GEM_BUG_ON (timeline->hwsp_offset >= hwsp->size);
@@ -113,7 +122,8 @@ static void intel_timeline_fini(struct rcu_head *rcu)struct intel_timeline *timeline = container_of(rcu, struct intel_timeline, rcu); -i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj); +if (timeline->hwsp_map) +i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj);i915_vma_put (timeline->hwsp_ggtt);i915_active_fini (&timeline->active);
@@ -173,6 +183,12 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)if (atomic_add_unless (&tl->pin_count,1 ,0 ))return 0 ; +if (!tl->hwsp_map) { + err =intel_timeline_pin_map (tl); +if (err) +return err; + } + err =i915_ggtt_pin (tl->hwsp_ggtt, ww,0 ,PIN_HIGH );if (err)return err;
drivers/gpu/drm/i915/gt/intel_timeline.h +2 -0
@@ -98,4 +98,6 @@ intel_timeline_is_last(const struct intel_timeline *tl,return list_is_last_rcu (&rq->link, &tl->requests); } +I915_SELFTEST_DECLARE(int intel_timeline_pin_map(struct intel_timeline *tl)); +#endif
drivers/gpu/drm/i915/gt/mock_engine.c +20 -2
@@ -13,9 +13,20 @@#include "mock_engine.h" #include "selftests/mock_request.h" -static void mock_timeline_pin (struct intel_timeline *tl) +static int mock_timeline_pin (struct intel_timeline *tl) { +int err; + +if (WARN_ON (!i915_gem_object_trylock (tl->hwsp_ggtt->obj))) +return -EBUSY ; + + err =intel_timeline_pin_map (tl); +i915_gem_object_unlock (tl->hwsp_ggtt->obj); +if (err) +return err; +atomic_inc (&tl->pin_count); +return 0 ; }static void mock_timeline_unpin (struct intel_timeline *tl)
@@ -133,6 +144,8 @@ static void mock_context_destroy(struct kref *ref)static int mock_context_alloc (struct intel_context *ce) { +int err; + ce->ring =mock_ring (ce->engine);if (!ce->ring)return -ENOMEM ;
@@ -143,7 +156,12 @@ static int mock_context_alloc(struct intel_context *ce)return PTR_ERR (ce->timeline); } -mock_timeline_pin (ce->timeline); + err =mock_timeline_pin (ce->timeline); +if (err) { +intel_timeline_put (ce->timeline); + ce->timeline =NULL ; +return err; + }return 0 ; }
drivers/gpu/drm/i915/gt/selftest_timeline.c +32 -31
165 lines not on this page · raw message
drivers/gpu/drm/i915/i915_selftest.h +2 -0
@@ -107,6 +107,7 @@ int __i915_subtests(const char *caller,#define I915_SELFTEST_DECLARE (x) x#define I915_SELFTEST_ONLY (x) unlikely(x) +#define I915_SELFTEST_EXPORT #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */
@@ -116,6 +117,7 @@ static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }#define I915_SELFTEST_DECLARE (x)#define I915_SELFTEST_ONLY (x) 0 +#define I915_SELFTEST_EXPORT static#endif
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 02/69] drm/i915: Pin timeline map after first timeline pin, v3.
Quoted 34 lines · Maarten Lankhorst
We're starting to require the reservation lock for pinning, so wait until we have that.
Update the selftests to handle this correctly, and ensure pin is called in
live_hwsp_rollover_user()andmock_hwsp_freelist().Changes since v1:
- Fix NULL + XX arithmatic, use casts. (kbuild)
Changes since v2:
- Clear entire cacheline when pinning.Signed-off-by Maarten Lankhorst <[email protected]>Reported-by kernel test robot <[email protected]>Reviewed-by Thomas Hellström <[email protected]>--- drivers/gpu/drm/i915/gt/intel_timeline.c | 40 +++++++++---- drivers/gpu/drm/i915/gt/intel_timeline.h | 2 + drivers/gpu/drm/i915/gt/mock_engine.c | 22 ++++++- drivers/gpu/drm/i915/gt/selftest_timeline.c | 63 +++++++++++---------- drivers/gpu/drm/i915/i915_selftest.h | 2 + 5 files changed, 84 insertions(+), 45 deletions(-)drivers/gpu/drm/i915/gt/intel_timeline.c +3
-0@@ -52,14 +52,29 @@ static int __timeline_active(struct i915_active *active)return 0 ; } +I915_SELFTEST_EXPORT int +intel_timeline_pin_map (struct intel_timeline *timeline) +{
drivers/gpu/drm/i915/gt/intel_timeline.c static int __timeline_active(struct i915_active *active) · line 67
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +10
-0+struct drm_i915_gem_object *obj = timeline->hwsp_ggtt->obj; +u32 ofs =offset_in_page (timeline->hwsp_offset); +void *vaddr; + + vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + timeline->hwsp_map = vaddr; + timeline->hwsp_seqno =memset (vaddr + ofs,0 ,CACHELINE_BYTES );
What guarantees that hwsp_offset is cacheline-aligned? From what I saw in patch 1, it's incremented by 8 so only every 8th one is actually CL-aligned.
Quoted 20 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +5
-3+clflush (vaddr + ofs); + +return 0 ; +} +static int intel_timeline_init (struct intel_timeline *timeline,struct intel_gt *gt,struct i915_vma *hwsp,unsigned int offset) { -void *vaddr; -u32 *seqno; -kref_init (&timeline->kref);atomic_set (&timeline->pin_count,0 );@@ -76,14 +91,8 @@ static int intel_timeline_init(struct intel_timeline *timeline, timeline->hwsp_ggtt = hwsp; }
drivers/gpu/drm/i915/gt/intel_timeline.c static int intel_timeline_init(struct intel_timeline *timeline, · line 95
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +2
-8- vaddr =i915_gem_object_pin_map (hwsp->obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) -return PTR_ERR (vaddr); - - timeline->hwsp_map = vaddr; - seqno = vaddr + timeline->hwsp_offset; -WRITE_ONCE (*seqno,0 ); - timeline->hwsp_seqno = seqno; + timeline->hwsp_map =NULL ; + timeline->hwsp_seqno = (void *)(long )timeline->hwsp_offset;
Maybe uintptr_t instead of long? I think they're always the same on Linux but uintptr_t seems like the more "correct" type for this sort of thing.
Quoted 91 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +8
-1GEM_BUG_ON (timeline->hwsp_offset >= hwsp->size);@@ -113,7 +122,8 @@ static void intel_timeline_fini(struct rcu_head *rcu)struct intel_timeline *timeline = container_of(rcu, struct intel_timeline, rcu); -i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj); +if (timeline->hwsp_map) +i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj);i915_vma_put (timeline->hwsp_ggtt);i915_active_fini (&timeline->active);@@ -173,6 +183,12 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)if (atomic_add_unless (&tl->pin_count,1 ,0 ))return 0 ; +if (!tl->hwsp_map) { + err =intel_timeline_pin_map (tl); +if (err) +return err; + } + err =i915_ggtt_pin (tl->hwsp_ggtt, ww,0 ,PIN_HIGH );if (err)return err;drivers/gpu/drm/i915/gt/intel_timeline.h +2
-0@@ -98,4 +98,6 @@ intel_timeline_is_last(const struct intel_timeline *tl,return list_is_last_rcu (&rq->link, &tl->requests); } +I915_SELFTEST_DECLARE(int intel_timeline_pin_map(struct intel_timeline *tl)); +#endif drivers/gpu/drm/i915/gt/mock_engine.c +20
-2@@ -13,9 +13,20 @@#include "mock_engine.h" #include "selftests/mock_request.h" -static void mock_timeline_pin (struct intel_timeline *tl) +static int mock_timeline_pin (struct intel_timeline *tl) { +int err; + +if (WARN_ON (!i915_gem_object_trylock (tl->hwsp_ggtt->obj))) +return -EBUSY ; + + err =intel_timeline_pin_map (tl); +i915_gem_object_unlock (tl->hwsp_ggtt->obj); +if (err) +return err; +atomic_inc (&tl->pin_count); +return 0 ; }static void mock_timeline_unpin (struct intel_timeline *tl)@@ -133,6 +144,8 @@ static void mock_context_destroy(struct kref *ref)static int mock_context_alloc (struct intel_context *ce) { +int err; + ce->ring =mock_ring (ce->engine);if (!ce->ring)return -ENOMEM ;@@ -143,7 +156,12 @@ static int mock_context_alloc(struct intel_context *ce)return PTR_ERR (ce->timeline); } -mock_timeline_pin (ce->timeline); + err =mock_timeline_pin (ce->timeline); +if (err) { +intel_timeline_put (ce->timeline); + ce->timeline =NULL ; +return err; + }return 0 ; }drivers/gpu/drm/i915/gt/selftest_timeline.c +0
-0
drivers/gpu/drm/i915/gt/selftest_timeline.c static unsigned long hwsp_cacheline(struct intel_timeline *tl) · line 37
Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +1
-1@@ -34,7 +34,7 @@ static unsigned long hwsp_cacheline(struct intel_timeline *tl) {unsigned long address = (unsigned long )page_address (hwsp_page (tl)); -return (address + tl->hwsp_offset) /CACHELINE_BYTES ; +return (address +offset_in_page (tl->hwsp_offset)) /CACHELINE_BYTES ;
Does this belong in the previous commit? I've got no clue what I'm talking about here but it looks like it goes with the hwsp_offset wrapping changes in 01/69.
--Jason
Quoted 195 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +31
-30}#define CACHELINES_PER_PAGE (PAGE_SIZE / CACHELINE_BYTES)@@ -58,6 +58,7 @@ static void __mock_hwsp_record(struct mock_hwsp_freelist *state, tl =xchg (&state->history[idx], tl);if (tl) {radix_tree_delete (&state->cachelines,hwsp_cacheline (tl)); +intel_timeline_unpin (tl);intel_timeline_put (tl); } }@@ -77,6 +78,12 @@ static int __mock_hwsp_timeline(struct mock_hwsp_freelist *state,if (IS_ERR (tl))return PTR_ERR (tl); + err =intel_timeline_pin (tl,NULL ); +if (err) { +intel_timeline_put (tl); +return err; + } + cacheline =hwsp_cacheline (tl); err =radix_tree_insert (&state->cachelines, cacheline, tl);if (err) {@@ -84,6 +91,7 @@ static int __mock_hwsp_timeline(struct mock_hwsp_freelist *state,pr_err ("HWSP cacheline %lu already used; duplicate allocation!\n" , cacheline); } +intel_timeline_unpin (tl);intel_timeline_put (tl);return err; }@@ -451,7 +459,7 @@ static int emit_ggtt_store_dw(struct i915_request *rq, u32 addr, u32 value) }static struct i915_request * -tl_write (struct intel_timeline *tl,struct intel_engine_cs *engine,u32 value) +checked_tl_write (struct intel_timeline *tl,struct intel_engine_cs *engine,u32 value) {struct i915_request *rq;int err;@@ -462,6 +470,13 @@ tl_write(struct intel_timeline *tl, struct intel_engine_cs *engine, u32 value) goto out; } +if (READ_ONCE (*tl->hwsp_seqno) != tl->seqno) { +pr_err ("Timeline created with incorrect breadcrumb, found %x, expected %x\n" , + *tl->hwsp_seqno, tl->seqno); +intel_timeline_unpin (tl); +return ERR_PTR (-EINVAL ); + } + rq =intel_engine_create_kernel_request (engine);if (IS_ERR (rq)) goto out_unpin;@@ -483,25 +498,6 @@ tl_write(struct intel_timeline *tl, struct intel_engine_cs *engine, u32 value)return rq; } -static struct intel_timeline * -checked_intel_timeline_create (struct intel_gt *gt) -{ -struct intel_timeline *tl; - - tl =intel_timeline_create (gt); -if (IS_ERR (tl)) -return tl; - -if (READ_ONCE (*tl->hwsp_seqno) != tl->seqno) { -pr_err ("Timeline created with incorrect breadcrumb, found %x, expected %x\n" , - *tl->hwsp_seqno, tl->seqno); -intel_timeline_put (tl); -return ERR_PTR (-EINVAL ); - } - -return tl; -} -static int live_hwsp_engine (void *arg) {#define NUM_TIMELINES 4096@@ -534,13 +530,13 @@ static int live_hwsp_engine(void *arg)struct intel_timeline *tl;struct i915_request *rq; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl);break ; } - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);if (IS_ERR (rq)) {intel_timeline_put (tl); err =PTR_ERR (rq);@@ -607,14 +603,14 @@ static int live_hwsp_alternate(void *arg)if (!intel_engine_can_store_dword (engine))continue ; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl); goto out; }intel_engine_pm_get (engine); - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);intel_engine_pm_put (engine);if (IS_ERR (rq)) {intel_timeline_put (tl);@@ -1257,6 +1253,10 @@ static int live_hwsp_rollover_user(void *arg)if (!tl->has_initial_breadcrumb) goto out; + err =intel_context_pin (ce); +if (err) + goto out; + tl->seqno =-4u ;WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno);@@ -1266,7 +1266,7 @@ static int live_hwsp_rollover_user(void *arg) this =intel_context_create_request (ce);if (IS_ERR (this)) { err =PTR_ERR (this); - goto out; + goto out_unpin; } pr_debug("%s: create fence.seqnp:%d\n",@@ -1285,17 +1285,18 @@ static int live_hwsp_rollover_user(void *arg)if (i915_request_wait (rq[2 ],0 ,HZ /5 ) <0 ) {pr_err ("Wait for timeline wrap timed out!\n" ); err = -EIO ; - goto out; + goto out_unpin; }for (i =0 ; i <ARRAY_SIZE (rq); i++) {if (!i915_request_completed (rq[i])) {pr_err ("Pre-wrap request not completed!\n" ); err = -EINVAL ; - goto out; + goto out_unpin; } } - +out_unpin: +intel_context_unpin (ce); out:for (i =0 ; i <ARRAY_SIZE (rq); i++)i915_request_put (rq[i]);@@ -1337,13 +1338,13 @@ static int live_hwsp_recycle(void *arg)struct intel_timeline *tl;struct i915_request *rq; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl);break ; } - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);if (IS_ERR (rq)) {intel_timeline_put (tl); err =PTR_ERR (rq);drivers/gpu/drm/i915/i915_selftest.h +2
-1@@ -107,6 +107,7 @@ int __i915_subtests(const char *caller,#define I915_SELFTEST_DECLARE (x) x#define I915_SELFTEST_ONLY (x) unlikely(x) +#define I915_SELFTEST_EXPORT #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */ @@ -116,6 +117,7 @@ static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }#define I915_SELFTEST_DECLARE (x)#define I915_SELFTEST_ONLY (x) 0 +#define I915_SELFTEST_EXPORT static#endif --2.30.1
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 02/69] drm/i915: Pin timeline map after first timeline pin, v3.
Op 2021-03-11 om 22:44 schreef Jason Ekstrand:
Quoted 32 lines
Quoted 30 lines · Maarten Lankhorst
We're starting to require the reservation lock for pinning, so wait until we have that.
Update the selftests to handle this correctly, and ensure pin is called in
live_hwsp_rollover_user()andmock_hwsp_freelist().Changes since v1:
- Fix NULL + XX arithmatic, use casts. (kbuild)
Changes since v2:
- Clear entire cacheline when pinning.Signed-off-by Maarten Lankhorst <[email protected]>Reported-by kernel test robot <[email protected]>Reviewed-by Thomas Hellström <[email protected]>--- drivers/gpu/drm/i915/gt/intel_timeline.c | 40 +++++++++---- drivers/gpu/drm/i915/gt/intel_timeline.h | 2 + drivers/gpu/drm/i915/gt/mock_engine.c | 22 ++++++- drivers/gpu/drm/i915/gt/selftest_timeline.c | 63 +++++++++++---------- drivers/gpu/drm/i915/i915_selftest.h | 2 + 5 files changed, 84 insertions(+), 45 deletions(-)drivers/gpu/drm/i915/gt/intel_timeline.c +0
-0@@ -52,14 +52,29 @@ static int __timeline_active(struct i915_active *active)return 0 ; }
Quoted 16 lines
drivers/gpu/drm/i915/gt/intel_timeline.c static int __timeline_active(struct i915_active *active) · line 67
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +13
-0+I915_SELFTEST_EXPORT int +intel_timeline_pin_map (struct intel_timeline *timeline) +{ +struct drm_i915_gem_object *obj = timeline->hwsp_ggtt->obj; +u32 ofs =offset_in_page (timeline->hwsp_offset); +void *vaddr; + + vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + timeline->hwsp_map = vaddr; + timeline->hwsp_seqno =memset (vaddr + ofs,0 ,CACHELINE_BYTES );What guarantees that
hwsp_offsetis cacheline-aligned? From what I saw in patch 1, it's incremented by 8 so only every 8th one is actually CL-aligned.
Yeah the name of the #define is wrong here. It was originally cacheline aligned because
the page was originally shared between different contexts. This is no longer the case,
but the name was kept. I think TIMELINE_SEQNO_ALIGN would be a better fit, I will respin.
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +5
-3+clflush (vaddr + ofs); + +return 0 ; +} +static int intel_timeline_init (struct intel_timeline *timeline,struct intel_gt *gt,struct i915_vma *hwsp,unsigned int offset) { -void *vaddr; -u32 *seqno; -kref_init (&timeline->kref);atomic_set (&timeline->pin_count,0 );@@ -76,14 +91,8 @@ static int intel_timeline_init(struct intel_timeline *timeline, timeline->hwsp_ggtt = hwsp; }
Quoted 13 lines
drivers/gpu/drm/i915/gt/intel_timeline.c static int intel_timeline_init(struct intel_timeline *timeline, · line 95
Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +2
-8- vaddr =i915_gem_object_pin_map (hwsp->obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) -return PTR_ERR (vaddr); - - timeline->hwsp_map = vaddr; - seqno = vaddr + timeline->hwsp_offset; -WRITE_ONCE (*seqno,0 ); - timeline->hwsp_seqno = seqno; + timeline->hwsp_map =NULL ; + timeline->hwsp_seqno = (void *)(long )timeline->hwsp_offset;Maybe
uintptr_tinstead of long? I think they're always the same on Linux butuintptr_tseems like the more "correct" type for this sort of thing.
I did a non-scientific compare, void *)(uintptr_t vs void *)(long in the kernel, the latter was used 4x as often.
In general long is a pointer sized type for the kernel. I think for userspace it would be more correct, though.
Quoted 93 lines
Quoted 93 lines
drivers/gpu/drm/i915/gt/intel_timeline.c +8
-1GEM_BUG_ON (timeline->hwsp_offset >= hwsp->size);@@ -113,7 +122,8 @@ static void intel_timeline_fini(struct rcu_head *rcu)struct intel_timeline *timeline = container_of(rcu, struct intel_timeline, rcu); -i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj); +if (timeline->hwsp_map) +i915_gem_object_unpin_map (timeline->hwsp_ggtt->obj);i915_vma_put (timeline->hwsp_ggtt);i915_active_fini (&timeline->active);@@ -173,6 +183,12 @@ int intel_timeline_pin(struct intel_timeline *tl, struct i915_gem_ww_ctx *ww)if (atomic_add_unless (&tl->pin_count,1 ,0 ))return 0 ; +if (!tl->hwsp_map) { + err =intel_timeline_pin_map (tl); +if (err) +return err; + } + err =i915_ggtt_pin (tl->hwsp_ggtt, ww,0 ,PIN_HIGH );if (err)return err;drivers/gpu/drm/i915/gt/intel_timeline.h +2
-0@@ -98,4 +98,6 @@ intel_timeline_is_last(const struct intel_timeline *tl,return list_is_last_rcu (&rq->link, &tl->requests); } +I915_SELFTEST_DECLARE(int intel_timeline_pin_map(struct intel_timeline *tl)); +#endif drivers/gpu/drm/i915/gt/mock_engine.c +20
-2@@ -13,9 +13,20 @@#include "mock_engine.h" #include "selftests/mock_request.h" -static void mock_timeline_pin (struct intel_timeline *tl) +static int mock_timeline_pin (struct intel_timeline *tl) { +int err; + +if (WARN_ON (!i915_gem_object_trylock (tl->hwsp_ggtt->obj))) +return -EBUSY ; + + err =intel_timeline_pin_map (tl); +i915_gem_object_unlock (tl->hwsp_ggtt->obj); +if (err) +return err; +atomic_inc (&tl->pin_count); +return 0 ; }static void mock_timeline_unpin (struct intel_timeline *tl)@@ -133,6 +144,8 @@ static void mock_context_destroy(struct kref *ref)static int mock_context_alloc (struct intel_context *ce) { +int err; + ce->ring =mock_ring (ce->engine);if (!ce->ring)return -ENOMEM ;@@ -143,7 +156,12 @@ static int mock_context_alloc(struct intel_context *ce)return PTR_ERR (ce->timeline); } -mock_timeline_pin (ce->timeline); + err =mock_timeline_pin (ce->timeline); +if (err) { +intel_timeline_put (ce->timeline); + ce->timeline =NULL ; +return err; + }return 0 ; }drivers/gpu/drm/i915/gt/selftest_timeline.c +0
-0@@ -34,7 +34,7 @@ static unsigned long hwsp_cacheline(struct intel_timeline *tl) {unsigned long address = (unsigned long )page_address (hwsp_page (tl));
Quoted 5 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c static unsigned long hwsp_cacheline(struct intel_timeline *tl) · line 37
Quoted 2 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +1
-1-return (address + tl->hwsp_offset) /CACHELINE_BYTES ; +return (address +offset_in_page (tl->hwsp_offset)) /CACHELINE_BYTES ;Does this belong in the previous commit? I've got no clue what I'm talking about here but it looks like it goes with the
hwsp_offsetwrapping changes in 01/69.
Yeah likely. Will move.
Quoted 195 lines
--Jason
Quoted 192 lines
drivers/gpu/drm/i915/gt/selftest_timeline.c +31
-30}#define CACHELINES_PER_PAGE (PAGE_SIZE / CACHELINE_BYTES)@@ -58,6 +58,7 @@ static void __mock_hwsp_record(struct mock_hwsp_freelist *state, tl =xchg (&state->history[idx], tl);if (tl) {radix_tree_delete (&state->cachelines,hwsp_cacheline (tl)); +intel_timeline_unpin (tl);intel_timeline_put (tl); } }@@ -77,6 +78,12 @@ static int __mock_hwsp_timeline(struct mock_hwsp_freelist *state,if (IS_ERR (tl))return PTR_ERR (tl); + err =intel_timeline_pin (tl,NULL ); +if (err) { +intel_timeline_put (tl); +return err; + } + cacheline =hwsp_cacheline (tl); err =radix_tree_insert (&state->cachelines, cacheline, tl);if (err) {@@ -84,6 +91,7 @@ static int __mock_hwsp_timeline(struct mock_hwsp_freelist *state,pr_err ("HWSP cacheline %lu already used; duplicate allocation!\n" , cacheline); } +intel_timeline_unpin (tl);intel_timeline_put (tl);return err; }@@ -451,7 +459,7 @@ static int emit_ggtt_store_dw(struct i915_request *rq, u32 addr, u32 value) }static struct i915_request * -tl_write (struct intel_timeline *tl,struct intel_engine_cs *engine,u32 value) +checked_tl_write (struct intel_timeline *tl,struct intel_engine_cs *engine,u32 value) {struct i915_request *rq;int err;@@ -462,6 +470,13 @@ tl_write(struct intel_timeline *tl, struct intel_engine_cs *engine, u32 value) goto out; } +if (READ_ONCE (*tl->hwsp_seqno) != tl->seqno) { +pr_err ("Timeline created with incorrect breadcrumb, found %x, expected %x\n" , + *tl->hwsp_seqno, tl->seqno); +intel_timeline_unpin (tl); +return ERR_PTR (-EINVAL ); + } + rq =intel_engine_create_kernel_request (engine);if (IS_ERR (rq)) goto out_unpin;@@ -483,25 +498,6 @@ tl_write(struct intel_timeline *tl, struct intel_engine_cs *engine, u32 value)return rq; } -static struct intel_timeline * -checked_intel_timeline_create (struct intel_gt *gt) -{ -struct intel_timeline *tl; - - tl =intel_timeline_create (gt); -if (IS_ERR (tl)) -return tl; - -if (READ_ONCE (*tl->hwsp_seqno) != tl->seqno) { -pr_err ("Timeline created with incorrect breadcrumb, found %x, expected %x\n" , - *tl->hwsp_seqno, tl->seqno); -intel_timeline_put (tl); -return ERR_PTR (-EINVAL ); - } - -return tl; -} -static int live_hwsp_engine (void *arg) {#define NUM_TIMELINES 4096@@ -534,13 +530,13 @@ static int live_hwsp_engine(void *arg)struct intel_timeline *tl;struct i915_request *rq; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl);break ; } - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);if (IS_ERR (rq)) {intel_timeline_put (tl); err =PTR_ERR (rq);@@ -607,14 +603,14 @@ static int live_hwsp_alternate(void *arg)if (!intel_engine_can_store_dword (engine))continue ; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl); goto out; }intel_engine_pm_get (engine); - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);intel_engine_pm_put (engine);if (IS_ERR (rq)) {intel_timeline_put (tl);@@ -1257,6 +1253,10 @@ static int live_hwsp_rollover_user(void *arg)if (!tl->has_initial_breadcrumb) goto out; + err =intel_context_pin (ce); +if (err) + goto out; + tl->seqno =-4u ;WRITE_ONCE (*(u32 *)tl->hwsp_seqno, tl->seqno);@@ -1266,7 +1266,7 @@ static int live_hwsp_rollover_user(void *arg) this =intel_context_create_request (ce);if (IS_ERR (this)) { err =PTR_ERR (this); - goto out; + goto out_unpin; } pr_debug("%s: create fence.seqnp:%d\n",@@ -1285,17 +1285,18 @@ static int live_hwsp_rollover_user(void *arg)if (i915_request_wait (rq[2 ],0 ,HZ /5 ) <0 ) {pr_err ("Wait for timeline wrap timed out!\n" ); err = -EIO ; - goto out; + goto out_unpin; }for (i =0 ; i <ARRAY_SIZE (rq); i++) {if (!i915_request_completed (rq[i])) {pr_err ("Pre-wrap request not completed!\n" ); err = -EINVAL ; - goto out; + goto out_unpin; } } - +out_unpin: +intel_context_unpin (ce); out:for (i =0 ; i <ARRAY_SIZE (rq); i++)i915_request_put (rq[i]);@@ -1337,13 +1338,13 @@ static int live_hwsp_recycle(void *arg)struct intel_timeline *tl;struct i915_request *rq; - tl =checked_intel_timeline_create (gt); + tl =intel_timeline_create (gt);if (IS_ERR (tl)) { err =PTR_ERR (tl);break ; } - rq =tl_write (tl, engine, count); + rq =checked_tl_write (tl, engine, count);if (IS_ERR (rq)) {intel_timeline_put (tl); err =PTR_ERR (rq);drivers/gpu/drm/i915/i915_selftest.h +2
-0@@ -107,6 +107,7 @@ int __i915_subtests(const char *caller,#define I915_SELFTEST_DECLARE (x) x#define I915_SELFTEST_ONLY (x) unlikely(x) +#define I915_SELFTEST_EXPORT #else /* !IS_ENABLED(CONFIG_DRM_I915_SELFTEST) */ @@ -116,6 +117,7 @@ static inline int i915_perf_selftests(struct pci_dev *pdev) { return 0; }#define I915_SELFTEST_DECLARE (x)#define I915_SELFTEST_ONLY (x) 0 +#define I915_SELFTEST_EXPORT static#endif
Quoted 7 lines
Quoted 7 lines
--
2.30.1_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 3/69 drm/i915: Move cmd parser pinning to execbuffer
In reply to Maarten LankhorstWe need to get rid of allocations in the cmd parser, because it needs to be called from a signaling context, first move all pinning to execbuf, where we already hold all locks.
Allocate jump_whitelist in the execbuffer, and add annotations around intel_engine_cmd_parser(), to ensure we only call the command parser without allocating any memory, or taking any locks we're not supposed to.
Because i915_gem_object_get_page() may also allocate memory, add a path to i915_gem_object_get_sg() that prevents memory allocations, and walk the sg list manually. It should be similarly fast.
This has the added benefit of being able to catch all memory allocation errors before the point of no return, and return -ENOMEM safely to the execbuf submitter.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 74 ++++++++++++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 10 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 21 +++- drivers/gpu/drm/i915/gt/intel_ggtt.c | 2 +- drivers/gpu/drm/i915/i915_cmd_parser.c | 104 ++++++++---------- drivers/gpu/drm/i915/i915_drv.h | 7 +- drivers/gpu/drm/i915/i915_memcpy.c | 2 +- drivers/gpu/drm/i915/i915_memcpy.h | 2 +- 8 files changed, 142 insertions(+), 80 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +68 -6
@@ -28,6 +28,7 @@#include "i915_sw_fence_work.h" #include "i915_trace.h" #include "i915_user_extensions.h" +#include "i915_memcpy.h" struct eb_vma {struct i915_vma *vma;
@@ -2267,24 +2268,45 @@ struct eb_parse_work {struct i915_vma *trampoline;unsigned long batch_offset;unsigned long batch_length; +unsigned long *jump_whitelist; +const void *batch_map; +void *shadow_map; };static int __eb_parse (struct dma_fence_work *work) {struct eb_parse_work *pw =container_of (work,typeof (*pw), base); +int ret; +bool cookie; -return intel_engine_cmd_parser (pw->engine, - pw->batch, - pw->batch_offset, - pw->batch_length, - pw->shadow, - pw->trampoline); + cookie =dma_fence_begin_signalling (); + ret =intel_engine_cmd_parser (pw->engine, + pw->batch, + pw->batch_offset, + pw->batch_length, + pw->shadow, + pw->jump_whitelist, + pw->shadow_map, + pw->batch_map); +dma_fence_end_signalling (cookie); + +return ret; }static void __eb_parse_release (struct dma_fence_work *work) {struct eb_parse_work *pw =container_of (work,typeof (*pw), base); +if (!IS_ERR_OR_NULL (pw->jump_whitelist)) +kfree (pw->jump_whitelist); + +if (pw->batch_map) +i915_gem_object_unpin_map (pw->batch->obj); +else +i915_gem_object_unpin_pages (pw->batch->obj); + +i915_gem_object_unpin_map (pw->shadow->obj); +if (pw->trampoline)i915_active_release (&pw->trampoline->active);i915_active_release (&pw->shadow->active);
@@ -2334,6 +2356,8 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb, struct i915_vma *trampoline) {struct eb_parse_work *pw; +struct drm_i915_gem_object *batch = eb->batch->vma->obj; +bool needs_clflush;int err;GEM_BUG_ON (overflows_type (eb->batch_start_offset, pw->batch_offset));
@@ -2357,6 +2381,34 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb, goto err_shadow; } + pw->shadow_map =i915_gem_object_pin_map (shadow->obj,I915_MAP_WB ); +if (IS_ERR (pw->shadow_map)) { + err =PTR_ERR (pw->shadow_map); + goto err_trampoline; + } + + needs_clflush = + !(batch->cache_coherent &I915_BO_CACHE_COHERENT_FOR_READ ); + + pw->batch_map =ERR_PTR (-ENODEV ); +if (needs_clflush &&i915_has_memcpy_from_wc ()) + pw->batch_map =i915_gem_object_pin_map (batch,I915_MAP_WC ); + +if (IS_ERR (pw->batch_map)) { + err =i915_gem_object_pin_pages (batch); +if (err) + goto err_unmap_shadow; + pw->batch_map =NULL ; + } + + pw->jump_whitelist = +intel_engine_cmd_parser_alloc_jump_whitelist (eb->batch_len, + trampoline); +if (IS_ERR (pw->jump_whitelist)) { + err =PTR_ERR (pw->jump_whitelist); + goto err_unmap_batch; + } +dma_fence_work_init (&pw->base, &eb_parse_ops); pw->engine = eb->engine;
@@ -2396,6 +2448,16 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb,dma_fence_work_commit_imm (&pw->base);return err; +err_unmap_batch: +if (pw->batch_map) +i915_gem_object_unpin_map (batch); +else +i915_gem_object_unpin_pages (batch); +err_unmap_shadow: +i915_gem_object_unpin_map (shadow->obj); +err_trampoline: +if (trampoline) +i915_active_release (&trampoline->active); err_shadow:i915_active_release (&shadow->active); err_batch:
drivers/gpu/drm/i915/gem/i915_gem_object.h +5 -5
@@ -325,22 +325,22 @@ struct scatterlist * __i915_gem_object_get_sg(struct drm_i915_gem_object *obj, struct i915_gem_object_page_iter *iter, unsigned int n, - unsigned int *offset); + unsigned int *offset, bool allow_alloc);static inline struct scatterlist *i915_gem_object_get_sg (struct drm_i915_gem_object *obj,unsigned int n, -unsigned int *offset) +unsigned int *offset,bool allow_alloc) { -return __i915_gem_object_get_sg (obj, &obj->mm.get_page, n, offset); +return __i915_gem_object_get_sg (obj, &obj->mm.get_page, n, offset, allow_alloc); }static inline struct scatterlist *i915_gem_object_get_sg_dma (struct drm_i915_gem_object *obj,unsigned int n, -unsigned int *offset) +unsigned int *offset,bool allow_alloc) { -return __i915_gem_object_get_sg (obj, &obj->mm.get_dma_page, n, offset); +return __i915_gem_object_get_sg (obj, &obj->mm.get_dma_page, n, offset, allow_alloc); } struct page *
drivers/gpu/drm/i915/gem/i915_gem_pages.c +17 -4
@@ -448,7 +448,8 @@ struct scatterlist * __i915_gem_object_get_sg(struct drm_i915_gem_object *obj, struct i915_gem_object_page_iter *iter, unsigned int n, - unsigned int *offset) + unsigned int *offset, + bool allow_alloc) { const bool dma = iter == &obj->mm.get_dma_page;struct scatterlist *sg;
@@ -470,6 +471,9 @@ __i915_gem_object_get_sg(struct drm_i915_gem_object *obj,if (n <READ_ONCE (iter->sg_idx)) goto lookup; +if (!allow_alloc) + goto manual_lookup; +mutex_lock (&iter->lock);/* We prefer to reuse the last sg so that repeated lookup of this
@@ -519,7 +523,16 @@ __i915_gem_object_get_sg(struct drm_i915_gem_object *obj,if (unlikely (n < idx))/* insertion completed by another thread */ goto lookup; -/* In case we failed to insert the entry into the radixtree, we need + goto manual_walk; + +manual_lookup: + idx =0 ; + sg = obj->mm.pages->sgl; + count =__sg_page_count (sg); + +manual_walk: +/* +* In case we failed to insert the entry into the radixtree, we need * to look beyond the current sg. */ while (idx + count <= n) {
@@ -566,7 +579,7 @@ i915_gem_object_get_page(struct drm_i915_gem_object *obj, unsigned int n)GEM_BUG_ON (!i915_gem_object_has_struct_page (obj)); - sg =i915_gem_object_get_sg (obj, n, &offset); + sg =i915_gem_object_get_sg (obj, n, &offset, true);return nth_page (sg_page (sg), offset); }
@@ -592,7 +605,7 @@ i915_gem_object_get_dma_address_len(struct drm_i915_gem_object *obj,struct scatterlist *sg;unsigned int offset; - sg =i915_gem_object_get_sg_dma (obj, n, &offset); + sg =i915_gem_object_get_sg_dma (obj, n, &offset, true);if (len) *len =sg_dma_len (sg) - (offset <<PAGE_SHIFT );
drivers/gpu/drm/i915/gt/intel_ggtt.c +1 -1
@@ -1434,7 +1434,7 @@ intel_partial_pages(const struct i915_ggtt_view *view,if (ret) goto err_sg_alloc; - iter =i915_gem_object_get_sg_dma (obj, view->partial.offset, &offset); + iter =i915_gem_object_get_sg_dma (obj, view->partial.offset, &offset, true);GEM_BUG_ON (!iter); sg = st->sgl;
drivers/gpu/drm/i915/i915_cmd_parser.c +43 -61
162 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.h +6 -1
@@ -1950,12 +1950,17 @@ const char *i915_cache_level_str(struct drm_i915_private *i915, int type);int i915_cmd_parser_get_version (struct drm_i915_private *dev_priv);int intel_engine_init_cmd_parser (struct intel_engine_cs *engine);void intel_engine_cleanup_cmd_parser (struct intel_engine_cs *engine); +unsigned long *intel_engine_cmd_parser_alloc_jump_whitelist (u32 batch_length, +bool trampoline); +int intel_engine_cmd_parser (struct intel_engine_cs *engine,struct i915_vma *batch,unsigned long batch_offset,unsigned long batch_length,struct i915_vma *shadow, -bool trampoline); +unsigned long *jump_whitelist, +void *shadow_map, +const void *batch_map);#define I915_CMD_PARSER_TRAMPOLINE_SIZE 8/* intel_device_info.c */
drivers/gpu/drm/i915/i915_memcpy.c +1 -1
@@ -135,7 +135,7 @@ bool i915_memcpy_from_wc(void *dst, const void *src, unsigned long len)* accepts that its arguments may not be aligned, but are valid for the * potential 16-byte read past the end. */ -void i915_unaligned_memcpy_from_wc (void *dst,void *src,unsigned long len) +void i915_unaligned_memcpy_from_wc (void *dst,const void *src,unsigned long len) {unsigned long addr;
drivers/gpu/drm/i915/i915_memcpy.h +1 -1
@@ -13,7 +13,7 @@ struct drm_i915_private;void i915_memcpy_init_early (struct drm_i915_private *i915);bool i915_memcpy_from_wc (void *dst,const void *src,unsigned long len); -void i915_unaligned_memcpy_from_wc (void *dst,void *src,unsigned long len); +void i915_unaligned_memcpy_from_wc (void *dst,const void *src,unsigned long len);/* The movntdqa instructions used for memcpy-from-wc require 16-byte alignment, * as well as SSE4.1 support. i915_memcpy_from_wc() will report if it cannot
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 4/69 drm/i915: Add missing -EDEADLK handling to execbuf pinning, v2.
In reply to Maarten Lankhorsti915_vma_pin may fail with -EDEADLK when we start locking page tables, so ensure we handle this correctly.
Changes since v1:
- Drop -EDEADLK todo, this commit handles it.
- Change eb_pin_vma from sort-of-bool + -EDEADLK to a proper int. (Matt)
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +24 -11
@@ -420,13 +420,14 @@ static u64 eb_pin_flags(const struct drm_i915_gem_exec_object2 *entry,return pin_flags; } -static inline bool +static inline int eb_pin_vma (struct i915_execbuffer *eb,const struct drm_i915_gem_exec_object2 *entry,struct eb_vma *ev) {struct i915_vma *vma = ev->vma;u64 pin_flags; +int err;if (vma->node.size) pin_flags = vma->node.start;
@@ -438,24 +439,29 @@ eb_pin_vma(struct i915_execbuffer *eb, pin_flags |=PIN_GLOBAL ;/* Attempt to reuse the current location if available */ -/* TODO: Add -EDEADLK handling here */ -if (unlikely (i915_vma_pin_ww (vma, &eb->ww,0 ,0 , pin_flags))) { + err =i915_vma_pin_ww (vma, &eb->ww,0 ,0 , pin_flags); +if (err == -EDEADLK ) +return err; + +if (unlikely (err)) {if (entry->flags &EXEC_OBJECT_PINNED ) -return false; +return err;/* Failing that pick any _free_ space if suitable */ -if (unlikely (i915_vma_pin_ww (vma, &eb->ww, + err =i915_vma_pin_ww (vma, &eb->ww, entry->pad_to_size, entry->alignment,eb_pin_flags (entry, ev->flags) | -PIN_USER |PIN_NOEVICT ))) -return false; +PIN_USER |PIN_NOEVICT ); +if (unlikely (err)) +return err; }if (unlikely (ev->flags &EXEC_OBJECT_NEEDS_FENCE )) { -if (unlikely (i915_vma_pin_fence (vma))) { + err =i915_vma_pin_fence (vma); +if (unlikely (err)) {i915_vma_unpin (vma); -return false; +return err; }if (vma->fence)
@@ -463,7 +469,10 @@ eb_pin_vma(struct i915_execbuffer *eb, } ev->flags |= __EXEC_OBJECT_HAS_PIN; -return !eb_vma_misplaced (entry, vma, ev->flags); +if (eb_vma_misplaced (entry, vma, ev->flags)) +return -EBADSLT ; + +return 0 ; } static inline void
@@ -899,7 +908,11 @@ static int eb_validate_vmas(struct i915_execbuffer *eb)if (err)return err; -if (eb_pin_vma (eb, entry, ev)) { + err =eb_pin_vma (eb, entry, ev); +if (err == -EDEADLK ) +return err; + +if (!err) {if (entry->offset != vma->node.start) { entry->offset = vma->node.start |UPDATE ; eb->args->flags |= __EXEC_HAS_RELOC;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 5/69 drm/i915: Ensure we hold the object mutex in pin correctly.
In reply to Maarten LankhorstCurrently we have a lot of places where we hold the gem object lock, but haven't yet been converted to the ww dance. Complain loudly about those places.
i915_vma_pin shouldn't have the obj lock held, so we can do a ww dance, while i915_vma_pin_ww should.
--- drivers/gpu/drm/i915/gt/intel_renderstate.c | 2 +- drivers/gpu/drm/i915/i915_vma.c | 11 ++++++++++- drivers/gpu/drm/i915/i915_vma.h | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_renderstate.c +1 -1
@@ -176,7 +176,7 @@ int intel_renderstate_init(struct intel_renderstate *so,if (err) goto err_context; - err =i915_vma_pin (so->vma,0 ,0 ,PIN_GLOBAL |PIN_HIGH ); + err =i915_vma_pin_ww (so->vma, &so->ww,0 ,0 ,PIN_GLOBAL |PIN_HIGH );if (err) goto err_context;
drivers/gpu/drm/i915/i915_vma.c +10 -1
@@ -865,6 +865,8 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,#ifdef CONFIG_PROVE_LOCKING if (debug_locks &&lockdep_is_held (&vma->vm->i915->drm.struct_mutex))WARN_ON (!ww); +if (debug_locks && ww && vma->resv) +assert_vma_held (vma);#endif BUILD_BUG_ON (PIN_GLOBAL !=I915_VMA_GLOBAL_BIND );
@@ -1020,8 +1022,15 @@ 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 && vma->resv &&dma_resv_held (vma->resv)); +#endif + do { - err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL); + if (ww) + err = i915_vma_pin_ww(vma, ww, 0, align, flags | PIN_GLOBAL); + else + err = i915_vma_pin(vma, 0, align, flags | PIN_GLOBAL); if (err != -ENOSPC) { if (!err) { err = i915_vma_wait_for_bind(vma);
drivers/gpu/drm/i915/i915_vma.h +3 -0
@@ -243,6 +243,9 @@ i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,static inline int __must_check i915_vma_pin (struct i915_vma *vma,u64 size,u64 alignment,u64 flags) { +#ifdef CONFIG_LOCKDEP +WARN_ON_ONCE (vma->resv &&dma_resv_held (vma->resv)); +#endif return i915_vma_pin_ww (vma,NULL , size, alignment, flags); }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 6/69 drm/i915: Add gem object locking to madvise.
In reply to Maarten LankhorstDoesn't need the full ww lock, only checking if pages are bound.
--- drivers/gpu/drm/i915/i915_gem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gem.c +7 -1
@@ -941,10 +941,14 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; - err =mutex_lock_interruptible (&obj->mm.lock); + err =i915_gem_object_lock_interruptible (obj,NULL );if (err) goto out; + err =mutex_lock_interruptible (&obj->mm.lock); +if (err) + goto out_ww; +if (i915_gem_object_has_pages (obj) &&i915_gem_object_is_tiled (obj) && i915->quirks &QUIRK_PIN_SWIZZLED_PAGES ) {
@@ -989,6 +993,8 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data, args->retained = obj->mm.madv != __I915_MADV_PURGED;mutex_unlock (&obj->mm.lock); +out_ww: +i915_gem_object_unlock (obj); out:i915_gem_object_put (obj);return err;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 7/69 drm/i915: Move HAS_STRUCT_PAGE to obj->flags
In reply to Maarten LankhorstWe want to remove the changing of ops structure for attaching phys pages, so we need to kill off HAS_STRUCT_PAGE from ops->flags, and put it in the bo.
This will remove a potential race of dereferencing the wrong obj->ops without ww mutex held.
--- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 6 +++--- drivers/gpu/drm/i915/gem/i915_gem_lmem.c | 4 ++-- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 7 +++---- drivers/gpu/drm/i915/gem/i915_gem_object.c | 4 +++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 5 +++-- drivers/gpu/drm/i915/gem/i915_gem_object_types.h | 10 ++++++---- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 5 ++--- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 2 ++ drivers/gpu/drm/i915/gem/i915_gem_region.c | 4 +--- drivers/gpu/drm/i915/gem/i915_gem_region.h | 3 +-- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 8 ++++---- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 4 ++-- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 6 +++--- drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c | 4 ++-- drivers/gpu/drm/i915/gem/selftests/huge_pages.c | 10 +++++----- drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c | 11 ++++------- drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c | 12 ++++++++++++ drivers/gpu/drm/i915/gvt/dmabuf.c | 2 +- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +- drivers/gpu/drm/i915/selftests/mock_region.c | 4 ++-- 21 files changed, 63 insertions(+), 52 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +1 -1
@@ -261,7 +261,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, }drm_gem_private_object_init (dev, &obj->base, dma_buf->size); -i915_gem_object_init (obj, &i915_gem_object_dmabuf_ops, &lock_class); +i915_gem_object_init (obj, &i915_gem_object_dmabuf_ops, &lock_class,0 ); obj->base.import_attach = attach; obj->base.resv = dma_buf->resv;
drivers/gpu/drm/i915/gem/i915_gem_internal.c +3 -3
@@ -138,8 +138,7 @@ static void i915_gem_object_put_pages_internal(struct drm_i915_gem_object *obj,static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = { .name ="i915_gem_object_internal" , - .flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_IS_SHRINKABLE , + .flags =I915_GEM_OBJECT_IS_SHRINKABLE , .get_pages = i915_gem_object_get_pages_internal, .put_pages = i915_gem_object_put_pages_internal, };
@@ -178,7 +177,8 @@ 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); +i915_gem_object_init (obj, &i915_gem_object_internal_ops, &lock_class, +I915_BO_ALLOC_STRUCT_PAGE );/* * Mark the object as volatile, such that the pages are marked as
drivers/gpu/drm/i915/gem/i915_gem_lmem.c +2 -2
@@ -40,13 +40,13 @@ int __i915_gem_lmem_object_init(struct intel_memory_region *mem,struct drm_i915_private *i915 = mem->i915;drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &i915_gem_lmem_obj_ops, &lock_class); +i915_gem_object_init (obj, &i915_gem_lmem_obj_ops, &lock_class, flags); obj->read_domains =I915_GEM_DOMAIN_WC |I915_GEM_DOMAIN_GTT ;i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE ); -i915_gem_object_init_memory_region (obj, mem, flags); +i915_gem_object_init_memory_region (obj, mem);return 0 ; }
drivers/gpu/drm/i915/gem/i915_gem_mman.c +3 -4
@@ -251,7 +251,7 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf) goto out; iomap =-1 ; -if (!i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_STRUCT_PAGE )) { +if (!i915_gem_object_has_struct_page (obj)) { iomap = obj->mm.region->iomap.base; iomap -= obj->mm.region->region.start; }
@@ -653,9 +653,8 @@ __assign_mmap_offset(struct drm_file *file, }if (mmap_type !=I915_MMAP_TYPE_GTT && - !i915_gem_object_type_has (obj, -I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_HAS_IOMEM )) { + !i915_gem_object_has_struct_page (obj) && + !i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_IOMEM )) { err = -ENODEV ; goto out; }
drivers/gpu/drm/i915/gem/i915_gem_object.c +3 -1
@@ -60,7 +60,7 @@ void i915_gem_object_free(struct drm_i915_gem_object *obj)void i915_gem_object_init (struct drm_i915_gem_object *obj,const struct drm_i915_gem_object_ops *ops, -struct lock_class_key *key) +struct lock_class_key *key,unsigned flags) {__mutex_init (&obj->mm.lock, ops->name ?:"obj->mm.lock" , key);
@@ -78,6 +78,8 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,init_rcu_head (&obj->rcu); obj->ops = ops; +GEM_BUG_ON (flags & ~I915_BO_ALLOC_FLAGS ); + obj->flags = flags; obj->mm.madv =I915_MADV_WILLNEED ;INIT_RADIX_TREE (&obj->mm.get_page.radix,GFP_KERNEL | __GFP_NOWARN);
drivers/gpu/drm/i915/gem/i915_gem_object.h +3 -2
@@ -49,7 +49,8 @@ void i915_gem_object_free(struct drm_i915_gem_object *obj);void i915_gem_object_init (struct drm_i915_gem_object *obj,const struct drm_i915_gem_object_ops *ops, -struct lock_class_key *key); +struct lock_class_key *key, +unsigned alloc_flags);struct drm_i915_gem_object *i915_gem_object_create_shmem (struct drm_i915_private *i915,resource_size_t size);
@@ -241,7 +242,7 @@ i915_gem_object_type_has(const struct drm_i915_gem_object *obj,static inline bool i915_gem_object_has_struct_page (const struct drm_i915_gem_object *obj) { -return i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_STRUCT_PAGE ); +return obj->flags &I915_BO_ALLOC_STRUCT_PAGE ; } static inline bool
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6 -4
@@ -30,7 +30,6 @@ struct i915_lut_handle {struct drm_i915_gem_object_ops {unsigned int flags; -#define I915_GEM_OBJECT_HAS_STRUCT_PAGE BIT(0)#define I915_GEM_OBJECT_HAS_IOMEM BIT(1)#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(2)#define I915_GEM_OBJECT_IS_PROXY BIT(3)
@@ -171,9 +170,12 @@ struct drm_i915_gem_object {unsigned long flags;#define I915_BO_ALLOC_CONTIGUOUS BIT(0)#define I915_BO_ALLOC_VOLATILE BIT(1) -#define I915_BO_ALLOC_FLAGS (I915_BO_ALLOC_CONTIGUOUS | I915_BO_ALLOC_VOLATILE) -#define I915_BO_READONLY BIT(2) -#define I915_TILING_QUIRK_BIT 3/* unknown swizzling; do not release! */ +#define I915_BO_ALLOC_STRUCT_PAGE BIT(2) +#define I915_BO_ALLOC_FLAGS (I915_BO_ALLOC_CONTIGUOUS | \ + I915_BO_ALLOC_VOLATILE | \ + I915_BO_ALLOC_STRUCT_PAGE) +#define I915_BO_READONLY BIT(3) +#define I915_TILING_QUIRK_BIT 4/* unknown swizzling; do not release! */ /* * Is the object to be mapped as read-only to the GPU
drivers/gpu/drm/i915/gem/i915_gem_pages.c +2 -3
@@ -333,13 +333,12 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, enum i915_map_type type) {enum i915_map_type has_type; -unsigned int flags;bool pinned;void *ptr;int err; - flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE |I915_GEM_OBJECT_HAS_IOMEM ; -if (!i915_gem_object_type_has (obj, flags)) +if (!i915_gem_object_has_struct_page (obj) && + !i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_IOMEM ))return ERR_PTR (-ENXIO ); err =mutex_lock_interruptible_nested (&obj->mm.lock,I915_MM_GET_PAGES );
drivers/gpu/drm/i915/gem/i915_gem_phys.c +2 -0
@@ -240,6 +240,7 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) pages =__i915_gem_object_unset_pages (obj); obj->ops = &i915_gem_phys_ops; + obj->flags &= ~I915_BO_ALLOC_STRUCT_PAGE ; err =____i915_gem_object_get_pages (obj);if (err)
@@ -258,6 +259,7 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) err_xfer: obj->ops = &i915_gem_shmem_ops; + obj->flags |=I915_BO_ALLOC_STRUCT_PAGE ;if (!IS_ERR_OR_NULL (pages)) {unsigned int sg_page_sizes =i915_sg_page_sizes (pages->sgl);
drivers/gpu/drm/i915/gem/i915_gem_region.c +1 -3
@@ -106,13 +106,11 @@ i915_gem_object_get_pages_buddy(struct drm_i915_gem_object *obj) }void i915_gem_object_init_memory_region (struct drm_i915_gem_object *obj, -struct intel_memory_region *mem, -unsigned long flags) +struct intel_memory_region *mem) {INIT_LIST_HEAD (&obj->mm.blocks); obj->mm.region =intel_memory_region_get (mem); - obj->flags |= flags;if (obj->base.size <= mem->min_page_size) obj->flags |=I915_BO_ALLOC_CONTIGUOUS ;
drivers/gpu/drm/i915/gem/i915_gem_region.h +1 -2
@@ -17,8 +17,7 @@ void i915_gem_object_put_pages_buddy(struct drm_i915_gem_object *obj, struct sg_table *pages);void i915_gem_object_init_memory_region (struct drm_i915_gem_object *obj, -struct intel_memory_region *mem, -unsigned long flags); +struct intel_memory_region *mem);void i915_gem_object_release_memory_region (struct drm_i915_gem_object *obj); struct drm_i915_gem_object *
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +4 -4
@@ -430,8 +430,7 @@ static void shmem_release(struct drm_i915_gem_object *obj)const struct drm_i915_gem_object_ops i915_gem_shmem_ops = { .name ="i915_gem_object_shmem" , - .flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_IS_SHRINKABLE , + .flags =I915_GEM_OBJECT_IS_SHRINKABLE , .get_pages = shmem_get_pages, .put_pages = shmem_put_pages,
@@ -491,7 +490,8 @@ static int shmem_object_init(struct intel_memory_region *mem,mapping_set_gfp_mask (mapping, mask);GEM_BUG_ON (!(mapping_gfp_mask (mapping) & __GFP_RECLAIM)); -i915_gem_object_init (obj, &i915_gem_shmem_ops, &lock_class); +i915_gem_object_init (obj, &i915_gem_shmem_ops, &lock_class, +I915_BO_ALLOC_STRUCT_PAGE ); obj->write_domain =I915_GEM_DOMAIN_CPU ; obj->read_domains =I915_GEM_DOMAIN_CPU ;
@@ -515,7 +515,7 @@ static int shmem_object_init(struct intel_memory_region *mem,i915_gem_object_set_cache_coherency (obj, cache_level); -i915_gem_object_init_memory_region (obj, mem,0 ); +i915_gem_object_init_memory_region (obj, mem);return 0 ; }
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +2 -2
@@ -630,7 +630,7 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,int err;drm_gem_private_object_init (&mem->i915->drm, &obj->base, stolen->size); -i915_gem_object_init (obj, &i915_gem_object_stolen_ops, &lock_class); +i915_gem_object_init (obj, &i915_gem_object_stolen_ops, &lock_class,0 ); obj->stolen = stolen; obj->read_domains =I915_GEM_DOMAIN_CPU |I915_GEM_DOMAIN_GTT ;
@@ -641,7 +641,7 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem,if (err)return err; -i915_gem_object_init_memory_region (obj, mem,0 ); +i915_gem_object_init_memory_region (obj, mem);return 0 ; }
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +3 -3
@@ -702,8 +702,7 @@ i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj)static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .name ="i915_gem_object_userptr" , - .flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_IS_SHRINKABLE | + .flags =I915_GEM_OBJECT_IS_SHRINKABLE |I915_GEM_OBJECT_NO_MMAP |I915_GEM_OBJECT_ASYNC_CANCEL , .get_pages = i915_gem_userptr_get_pages,
@@ -796,7 +795,8 @@ i915_gem_userptr_ioctl(struct drm_device *dev,return -ENOMEM ;drm_gem_private_object_init (dev, &obj->base, args->user_size); -i915_gem_object_init (obj, &i915_gem_userptr_ops, &lock_class); +i915_gem_object_init (obj, &i915_gem_userptr_ops, &lock_class, +I915_BO_ALLOC_STRUCT_PAGE ); obj->read_domains =I915_GEM_DOMAIN_CPU ; obj->write_domain =I915_GEM_DOMAIN_CPU ;i915_gem_object_set_cache_coherency (obj,I915_CACHE_LLC );
drivers/gpu/drm/i915/gem/selftests/huge_gem_object.c +2 -2
@@ -89,7 +89,6 @@ static void huge_put_pages(struct drm_i915_gem_object *obj,static const struct drm_i915_gem_object_ops huge_ops = { .name ="huge-gem" , - .flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE , .get_pages = huge_get_pages, .put_pages = huge_put_pages, };
@@ -115,7 +114,8 @@ huge_gem_object(struct drm_i915_private *i915,return ERR_PTR (-ENOMEM );drm_gem_private_object_init (&i915->drm, &obj->base, dma_size); -i915_gem_object_init (obj, &huge_ops, &lock_class); +i915_gem_object_init (obj, &huge_ops, &lock_class, +I915_BO_ALLOC_STRUCT_PAGE ); obj->read_domains =I915_GEM_DOMAIN_CPU ; obj->write_domain =I915_GEM_DOMAIN_CPU ;
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +5 -5
@@ -140,8 +140,7 @@ static void put_huge_pages(struct drm_i915_gem_object *obj,static const struct drm_i915_gem_object_ops huge_page_ops = { .name ="huge-gem" , - .flags =I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_IS_SHRINKABLE , + .flags =I915_GEM_OBJECT_IS_SHRINKABLE , .get_pages = get_huge_pages, .put_pages = put_huge_pages, };
@@ -168,7 +167,8 @@ huge_pages_object(struct drm_i915_private *i915,return ERR_PTR (-ENOMEM );drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &huge_page_ops, &lock_class); +i915_gem_object_init (obj, &huge_page_ops, &lock_class, +I915_BO_ALLOC_STRUCT_PAGE );i915_gem_object_set_volatile (obj);i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE );
@@ -317,9 +317,9 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single)drm_gem_private_object_init (&i915->drm, &obj->base, size);if (single) -i915_gem_object_init (obj, &fake_ops_single, &lock_class); +i915_gem_object_init (obj, &fake_ops_single, &lock_class,0 );else -i915_gem_object_init (obj, &fake_ops, &lock_class); +i915_gem_object_init (obj, &fake_ops, &lock_class,0 );i915_gem_object_set_volatile (obj);i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE );
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +4 -7
@@ -819,9 +819,8 @@ static bool can_mmap(struct drm_i915_gem_object *obj, enum i915_mmap_type type)return false;if (type !=I915_MMAP_TYPE_GTT && - !i915_gem_object_type_has (obj, -I915_GEM_OBJECT_HAS_STRUCT_PAGE | -I915_GEM_OBJECT_HAS_IOMEM )) + !i915_gem_object_has_struct_page (obj) && + !i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_IOMEM ))return false;return true;
@@ -961,10 +960,8 @@ static const char *repr_mmap_type(enum i915_mmap_type type)static bool can_access (const struct drm_i915_gem_object *obj) { -unsigned int flags = -I915_GEM_OBJECT_HAS_STRUCT_PAGE |I915_GEM_OBJECT_HAS_IOMEM ; - -return i915_gem_object_type_has (obj, flags); +return i915_gem_object_has_struct_page (obj) || +i915_gem_object_type_has (obj,I915_GEM_OBJECT_HAS_IOMEM ); } static int __igt_mmap_access(struct drm_i915_private *i915,
drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c +12 -0
@@ -25,12 +25,24 @@ static int mock_phys_object(void *arg) goto out; } +if (!i915_gem_object_has_struct_page (obj)) { + err = -EINVAL ; +pr_err ("shmem has no struct page\n" ); + goto out_obj; + } + err =i915_gem_object_attach_phys (obj,PAGE_SIZE );if (err) {pr_err ("i915_gem_object_attach_phys failed, err=%d\n" , err); goto out_obj; } +if (i915_gem_object_has_struct_page (obj)) { + err = -EINVAL ; +pr_err ("shmem has a struct page\n" ); + goto out_obj; + } +if (obj->ops != &i915_gem_phys_ops) {pr_err ("i915_gem_object_attach_phys did not create a phys object\n" ); err = -EINVAL ;
drivers/gpu/drm/i915/gvt/dmabuf.c +1 -1
@@ -218,7 +218,7 @@ static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,drm_gem_private_object_init (dev, &obj->base,roundup (info->size,PAGE_SIZE )); -i915_gem_object_init (obj, &intel_vgpu_gem_ops, &lock_class); +i915_gem_object_init (obj, &intel_vgpu_gem_ops, &lock_class,0 );i915_gem_object_set_readonly (obj); obj->read_domains =I915_GEM_DOMAIN_GTT ;
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +1 -1
@@ -121,7 +121,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size) goto err;drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &fake_ops, &lock_class); +i915_gem_object_init (obj, &fake_ops, &lock_class,0 );i915_gem_object_set_volatile (obj);
drivers/gpu/drm/i915/selftests/mock_region.c +2 -2
@@ -27,13 +27,13 @@ static int mock_object_init(struct intel_memory_region *mem,return -E2BIG ;drm_gem_private_object_init (&i915->drm, &obj->base, size); -i915_gem_object_init (obj, &mock_region_obj_ops, &lock_class); +i915_gem_object_init (obj, &mock_region_obj_ops, &lock_class, flags); obj->read_domains =I915_GEM_DOMAIN_CPU |I915_GEM_DOMAIN_GTT ;i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE ); -i915_gem_object_init_memory_region (obj, mem, flags); +i915_gem_object_init_memory_region (obj, mem);return 0 ; }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 8/69 drm/i915: Rework struct phys attachment handling
In reply to Maarten LankhorstInstead of creating a separate object type, we make changes to the shmem type, to clear struct page backing. This will allow us to ensure we never run into a race when we exchange obj->ops with other function pointers.
--- drivers/gpu/drm/i915/gem/i915_gem_object.h | 8 ++ drivers/gpu/drm/i915/gem/i915_gem_phys.c | 102 +++++++++--------- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 22 +++- .../drm/i915/gem/selftests/i915_gem_phys.c | 6 -- 4 files changed, 78 insertions(+), 60 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +8 -0
@@ -63,7 +63,15 @@ void __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,struct sg_table *pages, bool needs_clflush); +int i915_gem_object_pwrite_phys (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *args); +int i915_gem_object_pread_phys (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pread *args); +int i915_gem_object_attach_phys (struct drm_i915_gem_object *obj,int align); +void i915_gem_object_put_pages_phys (struct drm_i915_gem_object *obj, +struct sg_table *pages); +void i915_gem_flush_free_objects (struct drm_i915_private *i915);
drivers/gpu/drm/i915/gem/i915_gem_phys.c +49 -53
166 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +21 -1
@@ -303,6 +303,11 @@ shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages)struct pagevec pvec;struct page *page; +if (unlikely (!i915_gem_object_has_struct_page (obj))) { +i915_gem_object_put_pages_phys (obj, pages); +return ; + } +__i915_gem_object_release_shmem (obj, pages, true);i915_gem_gtt_finish_pages (obj, pages);
@@ -343,6 +348,9 @@ shmem_pwrite(struct drm_i915_gem_object *obj,/* Caller already validated user args */ GEM_BUG_ON (!access_ok (user_data, arg->size)); +if (!i915_gem_object_has_struct_page (obj)) +return i915_gem_object_pwrite_phys (obj, arg); +/* * Before we instantiate/pin the backing store for our use, we * can prepopulate the shmemfs filp efficiently using a write into
@@ -421,9 +429,20 @@ shmem_pwrite(struct drm_i915_gem_object *obj,return 0 ; } +static int +shmem_pread (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pread *arg) +{ +if (!i915_gem_object_has_struct_page (obj)) +return i915_gem_object_pread_phys (obj, arg); + +return -ENODEV ; +} +static void shmem_release (struct drm_i915_gem_object *obj) { -i915_gem_object_release_memory_region (obj); +if (obj->flags &I915_BO_ALLOC_STRUCT_PAGE ) +i915_gem_object_release_memory_region (obj);fput (obj->base.filp); }
@@ -438,6 +457,7 @@ const struct drm_i915_gem_object_ops i915_gem_shmem_ops = { .writeback = shmem_writeback, .pwrite = shmem_pwrite, + .pread = shmem_pread, .release = shmem_release, };
drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c +0 -6
@@ -38,12 +38,6 @@ static int mock_phys_object(void *arg) }if (i915_gem_object_has_struct_page (obj)) { - err = -EINVAL ; -pr_err ("shmem has a struct page\n" ); - goto out_obj; - } - -if (obj->ops != &i915_gem_phys_ops) {pr_err ("i915_gem_object_attach_phys did not create a phys object\n" ); err = -EINVAL ; goto out_obj;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 9/69 drm/i915: Convert i915_gem_object_attach_phys() to ww locking, v2.
In reply to Maarten LankhorstSimple adding of i915_gem_object_lock, we may start to pass ww to get_pages() in the future, but that won't be the case here; We override shmem's get_pages() handling by calling i915_gem_object_get_pages_phys(), no ww is needed.
Changes since v1:
- Call shmem put pages directly, the callback would go down the phys free path.
--- drivers/gpu/drm/i915/gem/i915_gem_object.h | 3 ++- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 12 ++++++++++-- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 17 ++++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -1
@@ -69,10 +69,11 @@ int i915_gem_object_pread_phys(struct drm_i915_gem_object *obj, const struct drm_i915_gem_pread *args);int i915_gem_object_attach_phys (struct drm_i915_gem_object *obj,int align); +void i915_gem_object_put_pages_shmem (struct drm_i915_gem_object *obj, +struct sg_table *pages);void i915_gem_object_put_pages_phys (struct drm_i915_gem_object *obj,struct sg_table *pages); -void i915_gem_flush_free_objects (struct drm_i915_private *i915); struct sg_table *
drivers/gpu/drm/i915/gem/i915_gem_phys.c +10 -2
@@ -201,7 +201,7 @@ static int i915_gem_object_shmem_to_phys(struct drm_i915_gem_object *obj)__i915_gem_object_pin_pages (obj);if (!IS_ERR_OR_NULL (pages)) - i915_gem_shmem_ops.put_pages (obj, pages); +i915_gem_object_put_pages_shmem (obj, pages);i915_gem_object_release_memory_region (obj);return 0 ;
@@ -232,7 +232,13 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)if (err)return err; -mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + err =i915_gem_object_lock_interruptible (obj,NULL ); +if (err) +return err; + + err =mutex_lock_interruptible_nested (&obj->mm.lock,I915_MM_GET_PAGES ); +if (err) + goto err_unlock;if (unlikely (!i915_gem_object_has_struct_page (obj))) goto out;
@@ -263,6 +269,8 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) out:mutex_unlock (&obj->mm.lock); +err_unlock: +i915_gem_object_unlock (obj);return err; }
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +10 -7
@@ -296,18 +296,12 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,__start_cpu_write (obj); } -static void -shmem_put_pages (struct drm_i915_gem_object *obj,struct sg_table *pages) +void i915_gem_object_put_pages_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages) {struct sgt_iter sgt_iter;struct pagevec pvec;struct page *page; -if (unlikely (!i915_gem_object_has_struct_page (obj))) { -i915_gem_object_put_pages_phys (obj, pages); -return ; - } -__i915_gem_object_release_shmem (obj, pages, true);i915_gem_gtt_finish_pages (obj, pages);
@@ -336,6 +330,15 @@ shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages)kfree (pages); } +static void +shmem_put_pages (struct drm_i915_gem_object *obj,struct sg_table *pages) +{ +if (likely (i915_gem_object_has_struct_page (obj))) +i915_gem_object_put_pages_shmem (obj, pages); +else +i915_gem_object_put_pages_phys (obj, pages); +} +static int shmem_pwrite (struct drm_i915_gem_object *obj,const struct drm_i915_gem_pwrite *arg)
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 10/69 drm/i915: make lockdep slightly happier about execbuf.
In reply to Maarten LankhorstAs soon as we install fences, we should stop allocating memory in order to prevent any potential deadlocks.
This is required later on, when we start adding support for dma-fence annotations.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 24 ++++++++++++++----- drivers/gpu/drm/i915/i915_active.c | 20 ++++++++-------- drivers/gpu/drm/i915/i915_vma.c | 8 ++++--- drivers/gpu/drm/i915/i915_vma.h | 3 +++ 4 files changed, 36 insertions(+), 19 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +18 -6
@@ -50,11 +50,12 @@ enum {#define DBG_FORCE_RELOC 0/* choose one of the above! */ }; -#define __EXEC_OBJECT_HAS_PIN BIT(31) -#define __EXEC_OBJECT_HAS_FENCE BIT(30) -#define __EXEC_OBJECT_NEEDS_MAP BIT(29) -#define __EXEC_OBJECT_NEEDS_BIAS BIT(28) -#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 28)/* all of the above */ +/* __EXEC_OBJECT_NO_RESERVE is BIT(31), defined in i915_vma.h */ +#define __EXEC_OBJECT_HAS_PIN BIT(30) +#define __EXEC_OBJECT_HAS_FENCE BIT(29) +#define __EXEC_OBJECT_NEEDS_MAP BIT(28) +#define __EXEC_OBJECT_NEEDS_BIAS BIT(27) +#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 27)/* all of the above + */ #define __EXEC_OBJECT_RESERVED (__EXEC_OBJECT_HAS_PIN | __EXEC_OBJECT_HAS_FENCE)#define __EXEC_HAS_RELOC BIT(31)
@@ -928,6 +929,12 @@ static int eb_validate_vmas(struct i915_execbuffer *eb) } } +if (!(ev->flags &EXEC_OBJECT_WRITE )) { + err =dma_resv_reserve_shared (vma->resv,1 ); +if (err) +return err; + } +GEM_BUG_ON (drm_mm_node_allocated (&vma->node) &&eb_vma_misplaced (&eb->exec[i], vma, ev->flags)); }
@@ -2188,7 +2195,8 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) }if (err ==0 ) - err =i915_vma_move_to_active (vma, eb->request, flags); + err =i915_vma_move_to_active (vma, eb->request, + flags | __EXEC_OBJECT_NO_RESERVE); }if (unlikely (err))
@@ -2440,6 +2448,10 @@ static int eb_parse_pipeline(struct i915_execbuffer *eb,if (err) goto err_commit; + err =dma_resv_reserve_shared (shadow->resv,1 ); +if (err) + goto err_commit; +/* Wait for all writes (and relocs) into the batch to complete */ err = i915_sw_fence_await_reservation(&pw->base.chain, pw->batch->resv, NULL, false,
drivers/gpu/drm/i915/i915_active.c +10 -10
@@ -293,18 +293,13 @@ static struct active_node *__active_lookup(struct i915_active *ref, u64 idx)static struct i915_active_fence *active_instance (struct i915_active *ref,u64 idx) { -struct active_node *node, *prealloc; +struct active_node *node;struct rb_node **p, *parent; node =__active_lookup (ref, idx);if (likely (node))return &node->base; -/* Preallocate a replacement, just in case */ - prealloc =kmem_cache_alloc (global.slab_cache,GFP_KERNEL ); -if (!prealloc) -return NULL ; -spin_lock_irq (&ref->tree_lock);GEM_BUG_ON (i915_active_is_idle (ref));
@@ -314,10 +309,8 @@ active_instance(struct i915_active *ref, u64 idx) parent = *p; node = rb_entry(parent, struct active_node, node); -if (node->timeline == idx) { -kmem_cache_free (global.slab_cache, prealloc); +if (node->timeline == idx) goto out; - }if (node->timeline < idx) p = &parent->rb_right;
@@ -325,7 +318,14 @@ active_instance(struct i915_active *ref, u64 idx) p = &parent->rb_left; } - node = prealloc; +/* +* XXX: We should preallocate this before i915_active_ref() is ever +* called, but we cannot call into fs_reclaim() anyway, so use GFP_ATOMIC. +*/ + node =kmem_cache_alloc (global.slab_cache,GFP_ATOMIC ); +if (!node) + goto out; +__i915_active_fence_init (&node->base,NULL , node_retire); node->ref = ref; node->timeline = idx;
drivers/gpu/drm/i915/i915_vma.c +5 -3
@@ -1247,9 +1247,11 @@ int i915_vma_move_to_active(struct i915_vma *vma, obj->write_domain =I915_GEM_DOMAIN_RENDER ; obj->read_domains =0 ; }else { - err =dma_resv_reserve_shared (vma->resv,1 ); -if (unlikely (err)) -return err; +if (!(flags & __EXEC_OBJECT_NO_RESERVE)) { + err =dma_resv_reserve_shared (vma->resv,1 ); +if (unlikely (err)) +return err; + }dma_resv_add_shared_fence (vma->resv, &rq->fence); obj->write_domain =0 ;
drivers/gpu/drm/i915/i915_vma.h +3 -0
@@ -52,6 +52,9 @@ static inline bool i915_vma_is_active(const struct i915_vma *vma)return !i915_active_is_idle (&vma->active); } +/* 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,
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 11/69 drm/i915: Disable userptr pread/pwrite support.
In reply to Maarten LankhorstUserptr should not need the kernel for a userspace memcpy, userspace needs to call memcpy directly.
Specifically, disable i915_gem_pwrite_ioctl() and i915_gem_pread_ioctl().
-- Still needs an ack from relevant userspace that it won't break, but should be good.
--- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 20 ++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem.c | 5 +++++ 2 files changed, 25 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +20 -0
@@ -700,6 +700,24 @@ i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj)return i915_gem_userptr_init__mmu_notifier (obj,0 ); } +static int +i915_gem_userptr_pwrite (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pwrite *args) +{ +drm_dbg (obj->base.dev,"pwrite to userptr no longer allowed\n" ); + +return -EINVAL ; +} + +static int +i915_gem_userptr_pread (struct drm_i915_gem_object *obj, +const struct drm_i915_gem_pread *args) +{ +drm_dbg (obj->base.dev,"pread from userptr no longer allowed\n" ); + +return -EINVAL ; +} +static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .name ="i915_gem_object_userptr" , .flags = I915_GEM_OBJECT_IS_SHRINKABLE |
@@ -708,6 +726,8 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .get_pages = i915_gem_userptr_get_pages, .put_pages = i915_gem_userptr_put_pages, .dmabuf_export = i915_gem_userptr_dmabuf_export, + .pwrite = i915_gem_userptr_pwrite, + .pread = i915_gem_userptr_pread, .release = i915_gem_userptr_release, };
drivers/gpu/drm/i915/i915_gem.c +5 -0
@@ -396,6 +396,11 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, }trace_i915_gem_object_pread (obj, args->offset, args->size); + ret = -ENODEV ; +if (obj->ops->pread) + ret = obj->ops->pread (obj, args); +if (ret != -ENODEV ) + goto out; ret = -ENODEV ;if (obj->ops->pread)
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 12/69 drm/i915: No longer allow exporting userptr through dma-buf
In reply to Maarten LankhorstIt doesn't make sense to export a memory address, we will prevent allowing access this way to different address spaces when we rework userptr handling, so best to explicitly disable it.
--- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +2 -3
@@ -694,10 +694,9 @@ i915_gem_userptr_release(struct drm_i915_gem_object *obj)static int i915_gem_userptr_dmabuf_export (struct drm_i915_gem_object *obj) { -if (obj->userptr.mmu_object) -return 0 ; +drm_dbg (obj->base.dev,"Exporting userptr no longer allowed\n" ); -return i915_gem_userptr_init__mmu_notifier (obj,0 ); +return -EINVAL ; } static int
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 13/69 drm/i915: Reject more ioctls for userptr, v2.
In reply to Maarten LankhorstThere are a couple of ioctl's related to tiling and cache placement, that make no sense for userptr, reject those:
- i915_gem_set_tiling_ioctl()
Tiling should always be linear for userptr. Changing placement will fail with -ENXIO.
- i915_gem_set_caching_ioctl()
Userptr memory should always be cached. Changing caching mode will fail with -ENXIO.
- i915_gem_set_domain_ioctl()
Still temporarily allowed to work as intended, it's used to check userptr validity. With the reworked userptr code, it will keep working for this usecase.
This plus the previous changes have been tested against beignet by using its own unit tests, and intel-video-compute by using piglit's opencl tests.
Changes since v1:
- set_domain was apparently used in iris for checking userptr validity, keep it working as intended.
--- drivers/gpu/drm/i915/display/intel_display.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 12 ++++++++++-- drivers/gpu/drm/i915/gem/i915_gem_object.h | 6 ++++++ drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/display/intel_display.c +1 -1
@@ -11902,7 +11902,7 @@ static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,struct drm_i915_gem_object *obj =intel_fb_obj (fb);struct drm_i915_private *i915 =to_i915 (obj->base.dev); -if (obj->userptr.mm) { +if (i915_gem_object_is_userptr (obj)) {drm_dbg (&i915->drm,"attempting to use a userptr for a framebuffer, denied\n" );return -EINVAL ;
drivers/gpu/drm/i915/gem/i915_gem_domain.c +10 -2
@@ -287,7 +287,14 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,* not allowed to be changed by userspace. */ if (i915_gem_object_is_proxy (obj)) { - ret = -ENXIO ; +/* +* Silently allow cached for userptr; the vulkan driver +* sets all objects to cached +*/ +if (!i915_gem_object_is_userptr (obj) || + args->caching !=I915_CACHING_CACHED ) + ret = -ENXIO ; + goto out; }
@@ -467,7 +474,8 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,* tracking for that backing storage. The proxy object is always * considered to be outside of any cache domain. */ -if (i915_gem_object_is_proxy (obj)) { +if (i915_gem_object_is_proxy (obj) && + !i915_gem_object_is_userptr (obj)) { err = -ENXIO ; goto out; }
drivers/gpu/drm/i915/gem/i915_gem_object.h +6 -0
@@ -573,6 +573,12 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,void __i915_gem_object_invalidate_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin); +static inline bool +i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) +{ +return obj->userptr.mm; +} +static inline void i915_gem_object_flush_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +2 -1
@@ -721,7 +721,8 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .name = "i915_gem_object_userptr", .flags =I915_GEM_OBJECT_IS_SHRINKABLE |I915_GEM_OBJECT_NO_MMAP | - I915_GEM_OBJECT_ASYNC_CANCEL, +I915_GEM_OBJECT_ASYNC_CANCEL | + I915_GEM_OBJECT_IS_PROXY, .get_pages = i915_gem_userptr_get_pages, .put_pages = i915_gem_userptr_put_pages, .dmabuf_export = i915_gem_userptr_dmabuf_export,
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 14/69 drm/i915: Reject UNSYNCHRONIZED for userptr, v2.
In reply to Maarten LankhorstWe should not allow this any more, as it will break with the new userptr implementation, it could still be made to work, but there's no point in doing so.
Inspection of the beignet opencl driver shows that it's only used when normal userptr is not available, which means for new kernels you will need CONFIG_I915_USERPTR.
--- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +2 -8
@@ -224,7 +224,7 @@ i915_gem_userptr_init__mmu_notifier(struct drm_i915_gem_object *obj,struct i915_mmu_object *mo;if (flags &I915_USERPTR_UNSYNCHRONIZED ) -return capable (CAP_SYS_ADMIN ) ?0 : -EPERM ; +return -ENODEV ;if (GEM_WARN_ON (!obj->userptr.mm))return -EINVAL ;
@@ -274,13 +274,7 @@ static int i915_gem_userptr_init__mmu_notifier(struct drm_i915_gem_object *obj, unsigned flags) { -if ((flags &I915_USERPTR_UNSYNCHRONIZED ) ==0 ) -return -ENODEV ; - -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; - -return 0 ; +return -ENODEV ; } static void
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 15/69 drm/i915: Make compilation of userptr code depend on MMU_NOTIFIER.
In reply to Maarten LankhorstNow that unsynchronized mappings are removed, the only time userptr works is when the MMU notifier is enabled. Put all of the userptr code behind a mmu notifier ifdef.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 + drivers/gpu/drm/i915/gem/i915_gem_object.h | 4 ++ .../gpu/drm/i915/gem/i915_gem_object_types.h | 2 + drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 58 +++++++------------ drivers/gpu/drm/i915/i915_drv.h | 2 + 5 files changed, 31 insertions(+), 37 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -0
@@ -1964,8 +1964,10 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =0 ; } +#ifdef CONFIG_MMU_NOTIFIER if (!err)flush_workqueue (eb->i915->mm.userptr_wq); +#endif err_relock:i915_gem_ww_ctx_init (&eb->ww, true);
drivers/gpu/drm/i915/gem/i915_gem_object.h +4 -0
@@ -576,7 +576,11 @@ void __i915_gem_object_invalidate_frontbuffer(struct drm_i915_gem_object *obj,static inline bool i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) { +#ifdef CONFIG_MMU_NOTIFIER return obj->userptr.mm; +#else +return false; +#endif } static inline void
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +2 -0
@@ -296,6 +296,7 @@ struct drm_i915_gem_object {unsigned long *bit_17; union { +#ifdef CONFIG_MMU_NOTIFIER struct i915_gem_userptr { uintptr_t ptr;
@@ -303,6 +304,7 @@ struct drm_i915_gem_object {struct i915_mmu_object *mmu_object; struct work_struct *work; } userptr; +#endif struct drm_mm_node *stolen;
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +21 -37
139 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.h +2 -0
@@ -556,12 +556,14 @@ struct i915_gem_mm {struct notifier_block vmap_notifier;struct shrinker shrinker; +#ifdef CONFIG_MMU_NOTIFIER /** * Workqueue to fault in userptr pages, flushed by the execbuf * when required but otherwise left to userspace to try again * on EAGAIN. */ struct workqueue_struct *userptr_wq; +#endif /* shrinker accounting, also useful for userland debugging */ u64 shrink_memory;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 16/69 drm/i915: Fix userptr so we do not have to worry about obj->mm.lock, v7.
In reply to Maarten LankhorstInstead of doing what we do currently, which will never work with PROVE_LOCKING, do the same as AMD does, and something similar to relocation slowpath. When all locks are dropped, we acquire the pages for pinning. When the locks are taken, we transfer those pages in .get_pages() to the bo. As a final check before installing the fences, we ensure that the mmu notifier was not called; if it is, we return -EAGAIN to userspace to signal it has to start over.
Changes since v1:
- Unbinding is done in submit_init only. submit_begin() removed.
- MMU_NOTFIER -> MMU_NOTIFIER
Changes since v2:
- Make i915->mm.notifier a spinlock.
Changes since v3:
- Add WARN_ON if there are any page references left, should have been 0.
- Return 0 on success in submit_init(), bug from spinlock conversion.
- Release pvec outside of notifier_lock (Thomas).
Changes since v4:
- Mention why we're clearing eb->[i + 1].vma in the code. (Thomas)
- Actually check all invalidations in eb_move_to_gpu. (Thomas)
- Do not wait when process is exiting to fix gem_ctx_persistence.userptr. Changes since v5:
- Clarify why check on PF_EXITING is (temporarily) required. Changes since v6:
- Ensure userptr validity is checked in set_domain through a special path.
--- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 18 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 101 ++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 38 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 10 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 796 ++++++------------ drivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_gem.c | 5 +- 8 files changed, 395 insertions(+), 584 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_domain.c +16 -2
@@ -468,14 +468,28 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +if (i915_gem_object_is_userptr (obj)) { +/* +* Try to grab userptr pages, iris uses set_domain to check +* userptr validity +*/ + err =i915_gem_object_userptr_validate (obj); +if (!err) + err =i915_gem_object_wait (obj, +I915_WAIT_INTERRUPTIBLE | +I915_WAIT_PRIORITY | + (write_domain ?I915_WAIT_ALL :0 ), +MAX_SCHEDULE_TIMEOUT ); + goto out; + } +/* * Proxy objects do not control access to the backing storage, ergo * they cannot be used as a means to manipulate the cache domain * tracking for that backing storage. The proxy object is always * considered to be outside of any cache domain. */ -if (i915_gem_object_is_proxy (obj) && - !i915_gem_object_is_userptr (obj)) { +if (i915_gem_object_is_proxy (obj)) { err = -ENXIO ; goto out; }
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +88 -13
184 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_object.h +22 -16
@@ -59,6 +59,7 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915, const void *data, resource_size_t size);extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; +void __i915_gem_object_release_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages,bool needs_clflush);
@@ -278,12 +279,6 @@ i915_gem_object_never_mmap(const struct drm_i915_gem_object *obj)return i915_gem_object_type_has (obj,I915_GEM_OBJECT_NO_MMAP ); } -static inline bool -i915_gem_object_needs_async_cancel (const struct drm_i915_gem_object *obj) -{ -return i915_gem_object_type_has (obj,I915_GEM_OBJECT_ASYNC_CANCEL ); -} -static inline bool i915_gem_object_is_framebuffer (const struct drm_i915_gem_object *obj) {
@@ -573,16 +568,6 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,void __i915_gem_object_invalidate_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin); -static inline bool -i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) -{ -#ifdef CONFIG_MMU_NOTIFIER -return obj->userptr.mm; -#else -return false; -#endif -} -static inline void i915_gem_object_flush_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin)
@@ -603,4 +588,25 @@ int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +#ifdef CONFIG_MMU_NOTIFIER +static inline bool +i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) +{ +return obj->userptr.notifier.mm; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj); +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj); +#else +static inline bool i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) {return false; } + +static inline int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 ); } +static inline int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } + +#endif +#endif
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6 -4
@@ -7,6 +7,8 @@#ifndef __I915_GEM_OBJECT_TYPES_H__#define __I915_GEM_OBJECT_TYPES_H__ +#include <linux/mmu_notifier.h> +#include <drm/drm_gem.h> #include <uapi/drm/i915_drm.h>
@@ -34,7 +36,6 @@ struct drm_i915_gem_object_ops {#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(2)#define I915_GEM_OBJECT_IS_PROXY BIT(3)#define I915_GEM_OBJECT_NO_MMAP BIT(4) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(5)/* Interface between the GEM object and its backing storage. * get_pages() is called once prior to the use of the associated set
@@ -299,10 +300,11 @@ struct drm_i915_gem_object {#ifdef CONFIG_MMU_NOTIFIER struct i915_gem_userptr {uintptr_t ptr; +unsigned long notifier_seq; -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; +struct mmu_interval_notifier notifier; +struct page **pvec; +int page_ref; } userptr;#endif
drivers/gpu/drm/i915/gem/i915_gem_pages.c +1 -1
@@ -226,7 +226,7 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)* get_pages backends we should be better able to handle the * cancellation of the async task in a more uniform manner. */ -if (!pages && !i915_gem_object_needs_async_cancel (obj)) +if (!pages) pages =ERR_PTR (-EINVAL );if (!IS_ERR (pages))
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +258 -538
916 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.h +3 -6
@@ -558,11 +558,10 @@ struct i915_gem_mm {#ifdef CONFIG_MMU_NOTIFIER /** -* Workqueue to fault in userptr pages, flushed by the execbuf -* when required but otherwise left to userspace to try again -* on EAGAIN. +* notifier_lock for mmu notifiers, memory may not be allocated +* while holding this lock. */ -struct workqueue_struct *userptr_wq; +spinlock_t notifier_lock;#endif /* shrinker accounting, also useful for userland debugging */
@@ -942,8 +941,6 @@ struct drm_i915_private {struct i915_ggtt ggtt;/* VM representing the global address space */ struct i915_gem_mm mm; -DECLARE_HASHTABLE (mm_structs,7 ); -spinlock_t mm_lock;/* Kernel Modesetting */
drivers/gpu/drm/i915/i915_gem.c +1 -4
@@ -1053,10 +1053,8 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_unlock:i915_gem_drain_workqueue (dev_priv); -if (ret != -EIO ) { +if (ret != -EIO )intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv); - }if (ret == -EIO ) {/*
@@ -1113,7 +1111,6 @@ void i915_gem_driver_release(struct drm_i915_private *dev_priv)intel_wa_list_free (&dev_priv->gt_wa_list);intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv);i915_gem_drain_freed_objects (dev_priv);
Signature · 1 line
2.30.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 16/69] drm/i915: Fix userptr so we do not have to worry about obj->mm.lock, v7.
Hi, Maarten,
Quoted 26 lines · Maarten Lankhorst
Instead of doing what we do currently, which will never work with
PROVE_LOCKING, do the same as AMD does, and something similar to relocation slowpath. When all locks are dropped, we acquire the pages for pinning. When the locks are taken, we transfer those pages in .get_pages() to the bo. As a final check before installing the fences, we ensure that the mmu notifier was not called; if it is, we return-EAGAINto userspace to signal it has to start over.Changes since v1:
- Unbinding is done insubmit_initonly.submit_begin()removed.
-MMU_NOTFIER->MMU_NOTIFIER
Changes since v2:
- Makei915->mm.notifiera spinlock.
Changes since v3:
- AddWARN_ONif there are any page references left, should have been 0.
- Return 0 on success insubmit_init(), bug from spinlock conversion.
- Release pvec outside ofnotifier_lock(Thomas).
Changes since v4:
- Mention why we're clearing eb->[i + 1].vma in the code. (Thomas)
- Actually check all invalidations ineb_move_to_gpu. (Thomas)
- Do not wait when process is exiting to fix gem_ctx_persistence.userptr. Changes since v5:
- Clarify why check onPF_EXITINGis (temporarily) required. Changes since v6:
- Ensure userptr validity is checked inset_domainthrough a special path.
Quoted 2 lines
Signed-off-by Maarten Lankhorst <[email protected]>Acked-by Dave Airlie <[email protected]>
Mostly LGTM. Comments / suggestions below.
Quoted 572 lines
--- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 18 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 101 ++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 38 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 10 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 796 ++++++------------ drivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_gem.c | 5 +- 8 files changed, 395 insertions(+), 584 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_domain.c +16
-2@@ -468,14 +468,28 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +if (i915_gem_object_is_userptr (obj)) { +/* +* Try to grab userptr pages, iris uses set_domain to check +* userptr validity +*/ + err =i915_gem_object_userptr_validate (obj); +if (!err) + err =i915_gem_object_wait (obj, +I915_WAIT_INTERRUPTIBLE | +I915_WAIT_PRIORITY | + (write_domain ?I915_WAIT_ALL :0 ), +MAX_SCHEDULE_TIMEOUT ); + goto out; + } +/* * Proxy objects do not control access to the backing storage, ergo * they cannot be used as a means to manipulate the cache domain * tracking for that backing storage. The proxy object is always * considered to be outside of any cache domain. */ -if (i915_gem_object_is_proxy (obj) && - !i915_gem_object_is_userptr (obj)) { +if (i915_gem_object_is_proxy (obj)) { err = -ENXIO ; goto out; }drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +88
-13@@ -53,14 +53,16 @@ enum {/* __EXEC_OBJECT_NO_RESERVE is BIT(31), defined in i915_vma.h */ #define __EXEC_OBJECT_HAS_PIN BIT(30)#define __EXEC_OBJECT_HAS_FENCE BIT(29) -#define __EXEC_OBJECT_NEEDS_MAP BIT(28) -#define __EXEC_OBJECT_NEEDS_BIAS BIT(27) -#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 27)/* all of the above + */ +#define __EXEC_OBJECT_USERPTR_INIT BIT(28) +#define __EXEC_OBJECT_NEEDS_MAP BIT(27) +#define __EXEC_OBJECT_NEEDS_BIAS BIT(26) +#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 26)/* all of the above + */ #define __EXEC_OBJECT_RESERVED (__EXEC_OBJECT_HAS_PIN | __EXEC_OBJECT_HAS_FENCE)#define __EXEC_HAS_RELOC BIT(31)#define __EXEC_ENGINE_PINNED BIT(30) -#define __EXEC_INTERNAL_FLAGS (~0u << 30) +#define __EXEC_USERPTR_USED BIT(29) +#define __EXEC_INTERNAL_FLAGS (~0u << 29)#define UPDATE PIN_OFFSET_FIXED#define BATCH_OFFSET_BIAS (256*1024)@@ -864,6 +866,26 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb) }eb_add_vma (eb, i, batch, vma); + +if (i915_gem_object_is_userptr (vma->obj)) { + err =i915_gem_object_userptr_submit_init (vma->obj); +if (err) { +if (i +1 < eb->buffer_count) { +/* +* Execbuffer code expects last vma entry to be NULL, +* since we already initialized this entry, +* set the next value to NULL or we mess up +* cleanup handling. +*/ + eb->vma[i +1 ].vma =NULL ; + } + +return err; + } + + eb->vma[i].flags |= __EXEC_OBJECT_USERPTR_INIT; + eb->args->flags |= __EXEC_USERPTR_USED; + } }if (unlikely (eb->batch->flags &EXEC_OBJECT_WRITE )) {@@ -965,7 +987,7 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final,bool release_userptr) {const unsigned int count = eb->buffer_count;unsigned int i;@@ -979,6 +1001,11 @@ static void eb_release_vmas(struct i915_execbuffer *eb, bool final)eb_unreserve_vma (ev); +if (release_userptr && ev->flags & __EXEC_OBJECT_USERPTR_INIT) { + ev->flags &= ~__EXEC_OBJECT_USERPTR_INIT; +i915_gem_object_userptr_submit_fini (vma->obj); + } +if (final)i915_vma_put (vma); }@@ -1909,6 +1936,31 @@ static int eb_prefault_relocations(const struct i915_execbuffer *eb)return 0 ; } +static int eb_reinit_userptr (struct i915_execbuffer *eb) +{ +const unsigned int count = eb->buffer_count; +unsigned int i; +int ret; + +if (likely (!(eb->args->flags & __EXEC_USERPTR_USED))) +return 0 ; + +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; + +if (!i915_gem_object_is_userptr (ev->vma->obj)) +continue ; + + ret =i915_gem_object_userptr_submit_init (ev->vma->obj); +if (ret) +return ret; + + ev->flags |= __EXEC_OBJECT_USERPTR_INIT; + } + +return 0 ; +} + static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,struct i915_request *rq) {@@ -1923,7 +1975,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, true);i915_gem_ww_ctx_fini (&eb->ww);if (rq) {@@ -1964,10 +2016,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =0 ; } -#ifdef CONFIG_MMU_NOTIFIER if (!err) -flush_workqueue (eb->i915->mm.userptr_wq); -#endif + err =eb_reinit_userptr (eb); err_relock:i915_gem_ww_ctx_init (&eb->ww, true);@@ -2029,7 +2079,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto repeat_validate;@@ -2126,7 +2176,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto retry;@@ -2201,6 +2251,30 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) flags | __EXEC_OBJECT_NO_RESERVE); } +#ifdef CONFIG_MMU_NOTIFIER +if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { +spin_lock (&eb->i915->mm.notifier_lock); + +/* +* count is always at least 1, otherwise __EXEC_USERPTR_USED +* could not have been set +*/ +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; +struct drm_i915_gem_object *obj = ev->vma->obj; + +if (!i915_gem_object_is_userptr (obj)) +continue ; + + err =i915_gem_object_userptr_submit_done (obj); +if (err) +break ; + } + +spin_unlock (&eb->i915->mm.notifier_lock); + } +#endif +if (unlikely (err)) goto err_skip;@@ -3345,7 +3419,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, err =eb_lookup_vmas (&eb);if (err) { -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true); goto err_engine; }@@ -3417,6 +3491,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,trace_i915_request_queue (eb.request, eb.batch_flags); err =eb_submit (&eb, batch); + err_request:i915_request_get (eb.request); err =eb_request_add (&eb, err);@@ -3437,7 +3512,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK );drivers/gpu/drm/i915/gem/i915_gem_object.h +22
-16@@ -59,6 +59,7 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915, const void *data, resource_size_t size);extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; +void __i915_gem_object_release_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages,bool needs_clflush);@@ -278,12 +279,6 @@ i915_gem_object_never_mmap(const struct drm_i915_gem_object *obj)return i915_gem_object_type_has (obj,I915_GEM_OBJECT_NO_MMAP ); } -static inline bool -i915_gem_object_needs_async_cancel (const struct drm_i915_gem_object *obj) -{ -return i915_gem_object_type_has (obj,I915_GEM_OBJECT_ASYNC_CANCEL ); -} -static inline bool i915_gem_object_is_framebuffer (const struct drm_i915_gem_object *obj) {@@ -573,16 +568,6 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,void __i915_gem_object_invalidate_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin); -static inline bool -i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) -{ -#ifdef CONFIG_MMU_NOTIFIER -return obj->userptr.mm; -#else -return false; -#endif -} -static inline void i915_gem_object_flush_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin)@@ -603,4 +588,25 @@ int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +#ifdef CONFIG_MMU_NOTIFIER +static inline bool +i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) +{ +return obj->userptr.notifier.mm; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj); +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj); +#else +static inline bool i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) {return false; } + +static inline int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 ); } +static inline int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } + +#endif +#endif drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6
-4@@ -7,6 +7,8 @@#ifndef __I915_GEM_OBJECT_TYPES_H__#define __I915_GEM_OBJECT_TYPES_H__ +#include <linux/mmu_notifier.h> +#include <drm/drm_gem.h> #include <uapi/drm/i915_drm.h> @@ -34,7 +36,6 @@ struct drm_i915_gem_object_ops {#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(2)#define I915_GEM_OBJECT_IS_PROXY BIT(3)#define I915_GEM_OBJECT_NO_MMAP BIT(4) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(5)/* Interface between the GEM object and its backing storage. * get_pages() is called once prior to the use of the associated set @@ -299,10 +300,11 @@ struct drm_i915_gem_object {#ifdef CONFIG_MMU_NOTIFIER struct i915_gem_userptr {uintptr_t ptr; +unsigned long notifier_seq; -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; +struct mmu_interval_notifier notifier; +struct page **pvec; +int page_ref; } userptr;#endif drivers/gpu/drm/i915/gem/i915_gem_pages.c +1
-1@@ -226,7 +226,7 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)* get_pages backends we should be better able to handle the * cancellation of the async task in a more uniform manner. */ -if (!pages && !i915_gem_object_needs_async_cancel (obj)) +if (!pages) pages =ERR_PTR (-EINVAL );if (!IS_ERR (pages))drivers/gpu/drm/i915/gem/i915_gem_userptr.c +61
-120@@ -2,10 +2,39 @@* SPDX-License-Identifier: MIT * * Copyright © 2012-2014 Intel Corporation +* +* Based on amdgpu_mn, which bears the following notice: +* +* Copyright 2014 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +*/ +/* +* Authors: +* Christian König <[email protected]> */ #include <linux/mmu_context.h> -#include <linux/mmu_notifier.h> #include <linux/mempolicy.h> #include <linux/swap.h> #include <linux/sched/mm.h> @@ -15,373 +44,121 @@#include "i915_gem_object.h" #include "i915_scatterlist.h" -#if defined(CONFIG_MMU_NOTIFIER ) - -struct i915_mm_struct { -struct mm_struct *mm; -struct drm_i915_private *i915; -struct i915_mmu_notifier *mn; -struct hlist_node node; -struct kref kref; -struct rcu_work work; -}; - -#include <linux/interval_tree.h> - -struct i915_mmu_notifier { -spinlock_t lock; -struct hlist_node node; -struct mmu_notifier mn; -struct rb_root_cached objects; -struct i915_mm_struct *mm; -}; - -struct i915_mmu_object { -struct i915_mmu_notifier *mn; -struct drm_i915_gem_object *obj; -struct interval_tree_node it; -}; +#ifdef CONFIG_MMU_NOTIFIER -static void add_object (struct i915_mmu_object *mo) +/** +* i915_gem_userptr_invalidate - callback to notify about mm change +* +* @mni: the range (mm) is about to update +* @range: details on the invalidation +* @cur_seq: Value to pass to mmu_interval_set_seq() +* +* Block for operations on BOs to finish and mark pages as accessed and +* potentially dirty. +*/ +static bool i915_gem_userptr_invalidate (struct mmu_interval_notifier *mni, +const struct mmu_notifier_range *range, +unsigned long cur_seq) { -GEM_BUG_ON (!RB_EMPTY_NODE (&mo->it.rb)); -interval_tree_insert (&mo->it, &mo->mn->objects); -} + struct drm_i915_gem_object *obj = container_of(mni, struct drm_i915_gem_object, userptr.notifier); +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +long r; -static void del_object (struct i915_mmu_object *mo) -{ -if (RB_EMPTY_NODE (&mo->it.rb)) -return ; +if (!mmu_notifier_range_blockable (range)) +return false; -interval_tree_remove (&mo->it, &mo->mn->objects); -RB_CLEAR_NODE (&mo->it.rb); -} +spin_lock (&i915->mm.notifier_lock); -static void -__i915_gem_userptr_set_active (struct drm_i915_gem_object *obj,bool value) -{ -struct i915_mmu_object *mo = obj->userptr.mmu_object; +mmu_interval_set_seq (mni, cur_seq); + +spin_unlock (&i915->mm.notifier_lock);/* -* During mm_invalidate_range we need to cancel any userptr that -* overlaps the range being invalidated. Doing so requires the -* struct_mutex, and that risks recursion. In order to cause -* recursion, the user must alias the userptr address space with -* a GTT mmapping (possible with a MAP_FIXED) - then when we have -* to invalidate that mmaping, mm_invalidate_range is called with -* the userptr address *and* the struct_mutex held. To prevent that -* we set a flag under the i915_mmu_notifier spinlock to indicate -* whether this object is valid. +* We don't wait when the process is exiting. This is valid +* because the object will be cleaned up anyway. +* +* This is also temporarily required as a hack, because we +* cannot currently force non-consistent batch buffers to preempt +* and reschedule by waiting on it, hanging processes on exit. */ -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -if (value) -add_object (mo); -else -del_object (mo); -spin_unlock (&mo->mn->lock); -} - -static int -userptr_mn_invalidate_range_start (struct mmu_notifier *_mn, -const struct mmu_notifier_range *range) -{ -struct i915_mmu_notifier *mn = - container_of(_mn, struct i915_mmu_notifier, mn); -struct interval_tree_node *it; -unsigned long end; -int ret =0 ; - -if (RB_EMPTY_ROOT (&mn->objects.rb_root)) -return 0 ; - -/* interval ranges are inclusive, but invalidate range is exclusive */ - end = range->end -1 ; - -spin_lock (&mn->lock); - it =interval_tree_iter_first (&mn->objects, range->start, end); -while (it) { -struct drm_i915_gem_object *obj; - -if (!mmu_notifier_range_blockable (range)) { - ret = -EAGAIN ; -break ; - } - -/* -* The mmu_object is released late when destroying the -* GEM object so it is entirely possible to gain a -* reference on an object in the process of being freed -* since our serialisation is via the spinlock and not -* the struct_mutex - and consequently use it after it -* is freed and then double free it. To prevent that -* use-after-free we only acquire a reference on the -* object if it is not in the process of being destroyed. -*/ - obj = container_of(it, struct i915_mmu_object, it)->obj; -if (!kref_get_unless_zero (&obj->base.refcount)) { - it =interval_tree_iter_next (it, range->start, end); -continue ; - } -spin_unlock (&mn->lock); - - ret =i915_gem_object_unbind (obj, -I915_GEM_OBJECT_UNBIND_ACTIVE | -I915_GEM_OBJECT_UNBIND_BARRIER ); -if (ret ==0 ) - ret =__i915_gem_object_put_pages (obj); -i915_gem_object_put (obj); -if (ret) -return ret; +if (current->flags &PF_EXITING ) +return true; -spin_lock (&mn->lock); - -/* -* As we do not (yet) protect the mmu from concurrent insertion -* over this range, there is no guarantee that this search will -* terminate given a pathologic workload. -*/
drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 91
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +5
-5- it =interval_tree_iter_first (&mn->objects, range->start, end); - } -spin_unlock (&mn->lock); - -return ret; +/* we will unbind on next submission, still have userptr pins */ + r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, +MAX_SCHEDULE_TIMEOUT ); +if (r <=0 ) +drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);
I think, since linux 5.9 where a fork is no longer setting up COW on pinned pages, and we do in fact still pin pages, I think this fence wait should be removed, together with the PF_EXIT special case, as it does not improve on anything but creates hangs that only hangcheck / watchdog can resolve. If we, in future work no longer pin the pages, which is the direction we're moving towards, let's re-add it when needed.
Quoted 213 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +14
-184+return true; } -static const struct mmu_notifier_ops i915_gem_userptr_notifier = { - .invalidate_range_start = userptr_mn_invalidate_range_start, +static const struct mmu_interval_notifier_ops i915_gem_userptr_notifier_ops = { + .invalidate = i915_gem_userptr_invalidate, }; -static struct i915_mmu_notifier * -i915_mmu_notifier_create (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn; - - mn =kmalloc (sizeof (*mn),GFP_KERNEL ); -if (mn ==NULL ) -return ERR_PTR (-ENOMEM ); - -spin_lock_init (&mn->lock); - mn->mn.ops = &i915_gem_userptr_notifier; - mn->objects =RB_ROOT_CACHED ; - mn->mm = mm; - -return mn; -} - -static void -i915_gem_userptr_release__mmu_notifier (struct drm_i915_gem_object *obj) -{ -struct i915_mmu_object *mo; - - mo =fetch_and_zero (&obj->userptr.mmu_object); -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -del_object (mo); -spin_unlock (&mo->mn->lock); -kfree (mo); -} - -static struct i915_mmu_notifier * -i915_mmu_notifier_find (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn, *old; -int err; - - mn =READ_ONCE (mm->mn); -if (likely (mn)) -return mn; - - mn =i915_mmu_notifier_create (mm); -if (IS_ERR (mn)) -return mn; - - err =mmu_notifier_register (&mn->mn, mm->mm); -if (err) { -kfree (mn); -return ERR_PTR (err); - } - - old =cmpxchg (&mm->mn,NULL , mn); -if (old) { -mmu_notifier_unregister (&mn->mn, mm->mm); -kfree (mn); - mn = old; - } - -return mn; -} -static int i915_gem_userptr_init__mmu_notifier (struct drm_i915_gem_object *obj) { -struct i915_mmu_notifier *mn; -struct i915_mmu_object *mo; - -if (GEM_WARN_ON (!obj->userptr.mm)) -return -EINVAL ; - - mn =i915_mmu_notifier_find (obj->userptr.mm); -if (IS_ERR (mn)) -return PTR_ERR (mn); - - mo =kzalloc (sizeof (*mo),GFP_KERNEL ); -if (!mo) -return -ENOMEM ; - - mo->mn = mn; - mo->obj = obj; - mo->it.start = obj->userptr.ptr; - mo->it.last = obj->userptr.ptr + obj->base.size -1 ; -RB_CLEAR_NODE (&mo->it.rb); - - obj->userptr.mmu_object = mo; -return 0 ; -} - -static void -i915_mmu_notifier_free (struct i915_mmu_notifier *mn, -struct mm_struct *mm) -{ -if (mn ==NULL ) -return ; - -mmu_notifier_unregister (&mn->mn, mm); -kfree (mn); -} - - -static struct i915_mm_struct * -__i915_mm_struct_find (struct drm_i915_private *i915,struct mm_struct *real) -{ -struct i915_mm_struct *it, *mm =NULL ; - -rcu_read_lock (); -hash_for_each_possible_rcu (i915->mm_structs, - it, node, - (unsigned long )real) -if (it->mm == real &&kref_get_unless_zero (&it->kref)) { - mm = it; -break ; - } -rcu_read_unlock (); - -return mm; +return mmu_interval_notifier_insert (&obj->userptr.notifier, current->mm, + obj->userptr.ptr, obj->base.size, + &i915_gem_userptr_notifier_ops); } -static int -i915_gem_userptr_init__mm_struct (struct drm_i915_gem_object *obj) +static void i915_gem_object_userptr_drop_ref (struct drm_i915_gem_object *obj) {struct drm_i915_private *i915 =to_i915 (obj->base.dev); -struct i915_mm_struct *mm, *new; -int ret =0 ; - -/* During release of the GEM object we hold the struct_mutex. This -* precludes us from calling mmput() at that time as that may be -* the last reference and so call exit_mmap(). exit_mmap() will -* attempt to reap the vma, and if we were holding a GTT mmap -* would then call drm_gem_vm_close() and attempt to reacquire -* the struct mutex. So in order to avoid that recursion, we have -* to defer releasing the mm reference until after we drop the -* struct_mutex, i.e. we need to schedule a worker to do the clean -* up. -*/ - mm =__i915_mm_struct_find (i915, current->mm); -if (mm) - goto out; +struct page **pvec =NULL ; - new =kmalloc (sizeof (*mm),GFP_KERNEL ); -if (!new) -return -ENOMEM ; - -kref_init (&new->kref); - new->i915 =to_i915 (obj->base.dev); - new->mm = current->mm; - new->mn =NULL ; - -spin_lock (&i915->mm_lock); - mm =__i915_mm_struct_find (i915, current->mm); -if (!mm) { -hash_add_rcu (i915->mm_structs, - &new->node, - (unsigned long )new->mm); -mmgrab (current->mm); - mm = new; +spin_lock (&i915->mm.notifier_lock); +if (!--obj->userptr.page_ref) { + pvec = obj->userptr.pvec; + obj->userptr.pvec =NULL ; } -spin_unlock (&i915->mm_lock); -if (mm != new) -kfree (new); +GEM_BUG_ON (obj->userptr.page_ref <0 ); +spin_unlock (&i915->mm.notifier_lock); -out: - obj->userptr.mm = mm; -return ret; -} - -static void -__i915_mm_struct_free__worker (struct work_struct *work) -{ -struct i915_mm_struct *mm =container_of (work,typeof (*mm), work.work); - -i915_mmu_notifier_free (mm->mn, mm->mm); -mmdrop (mm->mm); -kfree (mm); -} - -static void -__i915_mm_struct_free (struct kref *kref) -{ -struct i915_mm_struct *mm =container_of (kref,typeof (*mm), kref); - -spin_lock (&mm->i915->mm_lock); -hash_del_rcu (&mm->node); -spin_unlock (&mm->i915->mm_lock); - -INIT_RCU_WORK (&mm->work, __i915_mm_struct_free__worker); -queue_rcu_work (system_wq, &mm->work); -} - -static void -i915_gem_userptr_release__mm_struct (struct drm_i915_gem_object *obj)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 125
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-5-{ -if (obj->userptr.mm ==NULL ) -return ; +if (pvec) { +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -kref_put (&obj->userptr.mm->kref, __i915_mm_struct_free); - obj->userptr.mm =NULL ; +unpin_user_pages (pvec, num_pages); +kfree (pvec);
IIRC, CQ spotted that we should have a kvfree here right?
Quoted 345 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +89
-206+ } } -struct get_pages_work { -struct work_struct work; -struct drm_i915_gem_object *obj; -struct task_struct *task; -}; - -static struct sg_table * -__i915_gem_userptr_alloc_pages (struct drm_i915_gem_object *obj, -struct page **pvec,unsigned long num_pages) +static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) { +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ;unsigned int max_segment =i915_sg_segment_size ();struct sg_table *st;unsigned int sg_page_sizes;struct scatterlist *sg; +struct page **pvec;int ret; st =kmalloc (sizeof (*st),GFP_KERNEL );if (!st) -return ERR_PTR (-ENOMEM ); +return -ENOMEM ; + +spin_lock (&i915->mm.notifier_lock); +if (GEM_WARN_ON (!obj->userptr.page_ref)) { +spin_unlock (&i915->mm.notifier_lock); + ret = -EFAULT ; + goto err_free; + } + + obj->userptr.page_ref++; + pvec = obj->userptr.pvec; +spin_unlock (&i915->mm.notifier_lock); alloc_table: sg =__sg_alloc_table_from_pages (st, pvec, num_pages,0 , num_pages <<PAGE_SHIFT , max_segment,NULL ,0 ,GFP_KERNEL );if (IS_ERR (sg)) { -kfree (st); -return ERR_CAST (sg); + ret =PTR_ERR (sg); + goto err; } ret =i915_gem_gtt_prepare_pages (obj, st);@@ -393,203 +170,20 @@ __i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj, goto alloc_table; } -kfree (st); -return ERR_PTR (ret); + goto err; } sg_page_sizes =i915_sg_page_sizes (st->sgl);__i915_gem_object_set_pages (obj, st, sg_page_sizes); -return st; -} - -static void -__i915_gem_userptr_get_pages_worker (struct work_struct *_work) -{ -struct get_pages_work *work =container_of (_work,typeof (*work), work); -struct drm_i915_gem_object *obj = work->obj; -const unsigned long npages = obj->base.size >>PAGE_SHIFT ; -unsigned long pinned; -struct page **pvec; -int ret; - - ret = -ENOMEM ; - pinned =0 ; - - pvec =kvmalloc_array (npages,sizeof (struct page *),GFP_KERNEL ); -if (pvec !=NULL ) { -struct mm_struct *mm = obj->userptr.mm->mm; -unsigned int flags =0 ; -int locked =0 ; - -if (!i915_gem_object_is_readonly (obj)) - flags |=FOLL_WRITE ; - - ret = -EFAULT ; -if (mmget_not_zero (mm)) { -while (pinned < npages) { -if (!locked) { -mmap_read_lock (mm); - locked =1 ; - } - ret =pin_user_pages_remote - (mm, - obj->userptr.ptr + pinned *PAGE_SIZE , - npages - pinned, - flags, - pvec + pinned,NULL , &locked); -if (ret <0 ) -break ; - - pinned += ret; - } -if (locked) -mmap_read_unlock (mm); -mmput (mm); - } - } - -mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); -if (obj->userptr.work == &work->work) { -struct sg_table *pages =ERR_PTR (ret); - -if (pinned == npages) { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, - npages); -if (!IS_ERR (pages)) { - pinned =0 ; - pages =NULL ; - } - } - - obj->userptr.work =ERR_CAST (pages); -if (IS_ERR (pages)) -__i915_gem_userptr_set_active (obj, false); - } -mutex_unlock (&obj->mm.lock); - -unpin_user_pages (pvec, pinned); -kvfree (pvec); - -i915_gem_object_put (obj); -put_task_struct (work->task); -kfree (work); -} - -static struct sg_table * -__i915_gem_userptr_get_pages_schedule (struct drm_i915_gem_object *obj) -{ -struct get_pages_work *work; - -/* Spawn a worker so that we can acquire the -* user pages without holding our mutex. Access -* to the user pages requires mmap_lock, and we have -* a strict lock ordering of mmap_lock, struct_mutex - -* we already hold struct_mutex here and so cannot -* call gup without encountering a lock inversion. -* -* Userspace will keep on repeating the operation -* (thanks to EAGAIN) until either we hit the fast -* path or the worker completes. If the worker is -* cancelled or superseded, the task is still run -* but the results ignored. (This leads to -* complications that we may have a stray object -* refcount that we need to be wary of when -* checking for existing objects during creation.) -* If the worker encounters an error, it reports -* that error back to this function through -* obj->userptr.work = ERR_PTR. -*/ - work =kmalloc (sizeof (*work),GFP_KERNEL ); -if (work ==NULL ) -return ERR_PTR (-ENOMEM ); - - obj->userptr.work = &work->work; - - work->obj =i915_gem_object_get (obj); - - work->task = current; -get_task_struct (work->task); - -INIT_WORK (&work->work, __i915_gem_userptr_get_pages_worker); -queue_work (to_i915 (obj->base.dev)->mm.userptr_wq, &work->work); - -return ERR_PTR (-EAGAIN ); -} - -static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) -{ -const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -struct mm_struct *mm = obj->userptr.mm->mm; -struct page **pvec; -struct sg_table *pages; -bool active; -int pinned; -unsigned int gup_flags =0 ; - -/* If userspace should engineer that these pages are replaced in -* the vma between us binding this page into the GTT and completion -* of rendering... Their loss. If they change the mapping of their -* pages they need to create a new bo to point to the new vma. -* -* However, that still leaves open the possibility of the vma -* being copied upon fork. Which falls under the same userspace -* synchronisation issue as a regular bo, except that this time -* the process may not be expecting that a particular piece of -* memory is tied to the GPU. -* -* Fortunately, we can hook into the mmu_notifier in order to -* discard the page references prior to anything nasty happening -* to the vma (discard or cloning) which should prevent the more -* egregious cases from causing harm. -*/ - -if (obj->userptr.work) { -/* active flag should still be held for the pending work */ -if (IS_ERR (obj->userptr.work)) -return PTR_ERR (obj->userptr.work); -else -return -EAGAIN ; - } - - pvec =NULL ; - pinned =0 ; - -if (mm == current->mm) { - pvec =kvmalloc_array (num_pages,sizeof (struct page *), -GFP_KERNEL | - __GFP_NORETRY | - __GFP_NOWARN); -if (pvec) { -/* defer to worker if malloc fails */ -if (!i915_gem_object_is_readonly (obj)) - gup_flags |=FOLL_WRITE ; - pinned =pin_user_pages_fast_only (obj->userptr.ptr, - num_pages, gup_flags, - pvec); - } - } - - active = false; -if (pinned <0 ) { - pages =ERR_PTR (pinned); - pinned =0 ; - }else if (pinned < num_pages) { - pages =__i915_gem_userptr_get_pages_schedule (obj); - active = pages ==ERR_PTR (-EAGAIN ); - }else { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, num_pages); - active = !IS_ERR (pages); - } -if (active) -__i915_gem_userptr_set_active (obj, true); - -if (IS_ERR (pages)) -unpin_user_pages (pvec, pinned); -kvfree (pvec); +return 0 ; -return PTR_ERR_OR_ZERO (pages); +err: +i915_gem_object_userptr_drop_ref (obj); +err_free: +kfree (st); +return ret; } static void@@ -599,9 +193,6 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,struct sgt_iter sgt_iter;struct page *page; -/* Cancel any inflight work and force them to restart their gup */ - obj->userptr.work =NULL ; -__i915_gem_userptr_set_active (obj, false);if (!pages)return ;@@ -641,19 +232,161 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, }mark_page_accessed (page); -unpin_user_page (page); } obj->mm.dirty = false;sg_free_table (pages);kfree (pages); + +i915_gem_object_userptr_drop_ref (obj); +} + +static int i915_gem_object_userptr_unbind (struct drm_i915_gem_object *obj,bool get_pages) +{ +struct sg_table *pages; +int err; + + err =i915_gem_object_unbind (obj,I915_GEM_OBJECT_UNBIND_ACTIVE ); +if (err) +return err; + +if (GEM_WARN_ON (i915_gem_object_has_pinned_pages (obj))) +return -EBUSY ; + +mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + + pages =__i915_gem_object_unset_pages (obj); +if (!IS_ERR_OR_NULL (pages)) +i915_gem_userptr_put_pages (obj, pages); + +if (get_pages) + err =____i915_gem_object_get_pages (obj); +mutex_unlock (&obj->mm.lock); + +return err; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) +{ +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; +struct page **pvec; +unsigned int gup_flags =0 ; +unsigned long notifier_seq; +int pinned, ret; + +if (obj->userptr.notifier.mm != current->mm) +return -EFAULT ; + + ret =i915_gem_object_lock_interruptible (obj,NULL ); +if (ret) +return ret; + +/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */ + ret =i915_gem_object_userptr_unbind (obj, false); +i915_gem_object_unlock (obj); +if (ret) +return ret; + + notifier_seq =mmu_interval_read_begin (&obj->userptr.notifier); + + pvec =kvmalloc_array (num_pages,sizeof (struct page *),GFP_KERNEL ); +if (!pvec) +return -ENOMEM ; + +if (!i915_gem_object_is_readonly (obj)) + gup_flags |=FOLL_WRITE ; + + pinned = ret =0 ; +while (pinned < num_pages) { + ret = pin_user_pages_fast(obj->userptr.ptr + pinned * PAGE_SIZE,
drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 312
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ num_pages - pinned, gup_flags, + &pvec[pinned]); +if (ret <0 ) + goto out; + + pinned += ret; + } + ret =0 ; + +spin_lock (&i915->mm.notifier_lock);
I think we can improve a lot on the locking here by having the object lock protect the object state and only take the driver-wide notifier lock in execbuf / userptr_invalidate. If we in addition use an rwlock as a notifier lock taken in read mode in execbuf, any potential global lock contention can be practically eliminated. But that's perhaps for a future improvement.
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-0+ +if (mmu_interval_read_retry (&obj->userptr.notifier, + !obj->userptr.page_ref ? notifier_seq : + obj->userptr.notifier_seq)) {
drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 326
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ ret = -EAGAIN ; + goto out_unlock; + } + +if (!obj->userptr.page_ref++) { + obj->userptr.pvec = pvec; + obj->userptr.notifier_seq = notifier_seq; + + pvec =NULL ; + }
In addition, if we can call get_pages() here to take the page_ref, we can eliminate one page_ref and the use of _userptr_submit_fini(). That would of course require the object lock, but we'd already hold that for the object state as above.
Quoted 173 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +61
-18+ +out_unlock: +spin_unlock (&i915->mm.notifier_lock); + +out: +if (pvec) { +unpin_user_pages (pvec, pinned); +kvfree (pvec); + } + +return ret; +} + +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) +{ +if (mmu_interval_read_retry (&obj->userptr.notifier, + obj->userptr.notifier_seq)) { +/* We collided with the mmu notifier, need to retry */ + +return -EAGAIN ; + } + +return 0 ; +} + +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) +{ +i915_gem_object_userptr_drop_ref (obj); +} + +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) +{ +int err; + + err =i915_gem_object_userptr_submit_init (obj); +if (err) +return err; + + err =i915_gem_object_lock_interruptible (obj,NULL ); +if (!err) { +/* +* Since we only check validity, not use the pages, +* it doesn't matter if we collide with the mmu notifier, +* and -EAGAIN handling is not required. +*/ + err =i915_gem_object_pin_pages (obj); +if (!err) +i915_gem_object_unpin_pages (obj); + +i915_gem_object_unlock (obj); + } + +i915_gem_object_userptr_submit_fini (obj); +return err; }static void i915_gem_userptr_release (struct drm_i915_gem_object *obj) { -i915_gem_userptr_release__mmu_notifier (obj); -i915_gem_userptr_release__mm_struct (obj); +GEM_WARN_ON (obj->userptr.page_ref); + +mmu_interval_notifier_remove (&obj->userptr.notifier); + obj->userptr.notifier.mm =NULL ; } static int@@ -686,7 +419,6 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .name = "i915_gem_object_userptr", .flags =I915_GEM_OBJECT_IS_SHRINKABLE |I915_GEM_OBJECT_NO_MMAP | -I915_GEM_OBJECT_ASYNC_CANCEL | I915_GEM_OBJECT_IS_PROXY, .get_pages = i915_gem_userptr_get_pages, .put_pages = i915_gem_userptr_put_pages,@@ -793,6 +525,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,i915_gem_object_set_cache_coherency (obj,I915_CACHE_LLC ); obj->userptr.ptr = args->user_ptr; + obj->userptr.notifier_seq =ULONG_MAX ;if (args->flags &I915_USERPTR_READ_ONLY )i915_gem_object_set_readonly (obj);@@ -800,9 +533,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,* at binding. This means that we need to hook into the mmu_notifier * in order to detect if the mmu is destroyed. */ - ret =i915_gem_userptr_init__mm_struct (obj); -if (ret ==0 ) - ret =i915_gem_userptr_init__mmu_notifier (obj); + ret =i915_gem_userptr_init__mmu_notifier (obj);if (ret ==0 ) ret =drm_gem_handle_create (file, &obj->base, &handle);@@ -821,15 +552,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,int i915_gem_init_userptr (struct drm_i915_private *dev_priv) {#ifdef CONFIG_MMU_NOTIFIER -spin_lock_init (&dev_priv->mm_lock); -hash_init (dev_priv->mm_structs); - - dev_priv->mm.userptr_wq = -alloc_workqueue ("i915-userptr-acquire" , -WQ_HIGHPRI |WQ_UNBOUND , -0 ); -if (!dev_priv->mm.userptr_wq) -return -ENOMEM ; +spin_lock_init (&dev_priv->mm.notifier_lock);#endif return 0 ;@@ -837,7 +560,4 @@ int i915_gem_init_userptr(struct drm_i915_private *dev_priv)void i915_gem_cleanup_userptr (struct drm_i915_private *dev_priv) { -#ifdef CONFIG_MMU_NOTIFIER -destroy_workqueue (dev_priv->mm.userptr_wq); -#endif }drivers/gpu/drm/i915/i915_drv.h +3
-6@@ -558,11 +558,10 @@ struct i915_gem_mm {#ifdef CONFIG_MMU_NOTIFIER /** -* Workqueue to fault in userptr pages, flushed by the execbuf -* when required but otherwise left to userspace to try again -* on EAGAIN. +* notifier_lock for mmu notifiers, memory may not be allocated +* while holding this lock. */ -struct workqueue_struct *userptr_wq; +spinlock_t notifier_lock;#endif /* shrinker accounting, also useful for userland debugging */ @@ -942,8 +941,6 @@ struct drm_i915_private {struct i915_ggtt ggtt;/* VM representing the global address space */ struct i915_gem_mm mm; -DECLARE_HASHTABLE (mm_structs,7 ); -spinlock_t mm_lock;/* Kernel Modesetting */ drivers/gpu/drm/i915/i915_gem.c +1
-4@@ -1053,10 +1053,8 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_unlock:i915_gem_drain_workqueue (dev_priv); -if (ret != -EIO ) { +if (ret != -EIO )intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv); - }if (ret == -EIO ) {/* @@ -1113,7 +1111,6 @@ void i915_gem_driver_release(struct drm_i915_private *dev_priv)intel_wa_list_free (&dev_priv->gt_wa_list);intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv);i915_gem_drain_freed_objects (dev_priv);
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 16/69] drm/i915: Fix userptr so we do not have to worry about obj->mm.lock, v7.
Op 2021-03-11 om 18:24 schreef Thomas Hellström (Intel):
Quoted 1,202 lines
Hi, Maarten,
Quoted 26 lines · Maarten Lankhorst
Instead of doing what we do currently, which will never work with
PROVE_LOCKING, do the same as AMD does, and something similar to relocation slowpath. When all locks are dropped, we acquire the pages for pinning. When the locks are taken, we transfer those pages in .get_pages() to the bo. As a final check before installing the fences, we ensure that the mmu notifier was not called; if it is, we return-EAGAINto userspace to signal it has to start over.Changes since v1:
- Unbinding is done insubmit_initonly.submit_begin()removed.
-MMU_NOTFIER->MMU_NOTIFIER
Changes since v2:
- Makei915->mm.notifiera spinlock.
Changes since v3:
- AddWARN_ONif there are any page references left, should have been 0.
- Return 0 on success insubmit_init(), bug from spinlock conversion.
- Release pvec outside ofnotifier_lock(Thomas).
Changes since v4:
- Mention why we're clearing eb->[i + 1].vma in the code. (Thomas)
- Actually check all invalidations ineb_move_to_gpu. (Thomas)
- Do not wait when process is exiting to fix gem_ctx_persistence.userptr. Changes since v5:
- Clarify why check onPF_EXITINGis (temporarily) required. Changes since v6:
- Ensure userptr validity is checked inset_domainthrough a special path.Quoted 2 lines
Signed-off-by Maarten Lankhorst <[email protected]>Acked-by Dave Airlie <[email protected]>Mostly LGTM. Comments / suggestions below.
Quoted 572 lines
--- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 18 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 101 ++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 38 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 10 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 796 ++++++------------ drivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_gem.c | 5 +- 8 files changed, 395 insertions(+), 584 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_domain.c +16
-2@@ -468,14 +468,28 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +if (i915_gem_object_is_userptr (obj)) { +/* +* Try to grab userptr pages, iris uses set_domain to check +* userptr validity +*/ + err =i915_gem_object_userptr_validate (obj); +if (!err) + err =i915_gem_object_wait (obj, +I915_WAIT_INTERRUPTIBLE | +I915_WAIT_PRIORITY | + (write_domain ?I915_WAIT_ALL :0 ), +MAX_SCHEDULE_TIMEOUT ); + goto out; + } +/* * Proxy objects do not control access to the backing storage, ergo * they cannot be used as a means to manipulate the cache domain * tracking for that backing storage. The proxy object is always * considered to be outside of any cache domain. */ -if (i915_gem_object_is_proxy (obj) && - !i915_gem_object_is_userptr (obj)) { +if (i915_gem_object_is_proxy (obj)) { err = -ENXIO ; goto out; }drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +88
-13@@ -53,14 +53,16 @@ enum {/* __EXEC_OBJECT_NO_RESERVE is BIT(31), defined in i915_vma.h */ #define __EXEC_OBJECT_HAS_PIN BIT(30)#define __EXEC_OBJECT_HAS_FENCE BIT(29) -#define __EXEC_OBJECT_NEEDS_MAP BIT(28) -#define __EXEC_OBJECT_NEEDS_BIAS BIT(27) -#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 27)/* all of the above + */ +#define __EXEC_OBJECT_USERPTR_INIT BIT(28) +#define __EXEC_OBJECT_NEEDS_MAP BIT(27) +#define __EXEC_OBJECT_NEEDS_BIAS BIT(26) +#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 26)/* all of the above + */ #define __EXEC_OBJECT_RESERVED (__EXEC_OBJECT_HAS_PIN | __EXEC_OBJECT_HAS_FENCE)#define __EXEC_HAS_RELOC BIT(31)#define __EXEC_ENGINE_PINNED BIT(30) -#define __EXEC_INTERNAL_FLAGS (~0u << 30) +#define __EXEC_USERPTR_USED BIT(29) +#define __EXEC_INTERNAL_FLAGS (~0u << 29)#define UPDATE PIN_OFFSET_FIXED#define BATCH_OFFSET_BIAS (256*1024)@@ -864,6 +866,26 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb) }eb_add_vma (eb, i, batch, vma); + +if (i915_gem_object_is_userptr (vma->obj)) { + err =i915_gem_object_userptr_submit_init (vma->obj); +if (err) { +if (i +1 < eb->buffer_count) { +/* +* Execbuffer code expects last vma entry to be NULL, +* since we already initialized this entry, +* set the next value to NULL or we mess up +* cleanup handling. +*/ + eb->vma[i +1 ].vma =NULL ; + } + +return err; + } + + eb->vma[i].flags |= __EXEC_OBJECT_USERPTR_INIT; + eb->args->flags |= __EXEC_USERPTR_USED; + } }if (unlikely (eb->batch->flags &EXEC_OBJECT_WRITE )) {@@ -965,7 +987,7 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final,bool release_userptr) {const unsigned int count = eb->buffer_count;unsigned int i;@@ -979,6 +1001,11 @@ static void eb_release_vmas(struct i915_execbuffer *eb, bool final)eb_unreserve_vma (ev); +if (release_userptr && ev->flags & __EXEC_OBJECT_USERPTR_INIT) { + ev->flags &= ~__EXEC_OBJECT_USERPTR_INIT; +i915_gem_object_userptr_submit_fini (vma->obj); + } +if (final)i915_vma_put (vma); }@@ -1909,6 +1936,31 @@ static int eb_prefault_relocations(const struct i915_execbuffer *eb)return 0 ; } +static int eb_reinit_userptr (struct i915_execbuffer *eb) +{ +const unsigned int count = eb->buffer_count; +unsigned int i; +int ret; + +if (likely (!(eb->args->flags & __EXEC_USERPTR_USED))) +return 0 ; + +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; + +if (!i915_gem_object_is_userptr (ev->vma->obj)) +continue ; + + ret =i915_gem_object_userptr_submit_init (ev->vma->obj); +if (ret) +return ret; + + ev->flags |= __EXEC_OBJECT_USERPTR_INIT; + } + +return 0 ; +} + static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,struct i915_request *rq) {@@ -1923,7 +1975,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, true);i915_gem_ww_ctx_fini (&eb->ww);if (rq) {@@ -1964,10 +2016,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =0 ; } -#ifdef CONFIG_MMU_NOTIFIER if (!err) -flush_workqueue (eb->i915->mm.userptr_wq); -#endif + err =eb_reinit_userptr (eb); err_relock:i915_gem_ww_ctx_init (&eb->ww, true);@@ -2029,7 +2079,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto repeat_validate;@@ -2126,7 +2176,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto retry;@@ -2201,6 +2251,30 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) flags | __EXEC_OBJECT_NO_RESERVE); } +#ifdef CONFIG_MMU_NOTIFIER +if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { +spin_lock (&eb->i915->mm.notifier_lock); + +/* +* count is always at least 1, otherwise __EXEC_USERPTR_USED +* could not have been set +*/ +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; +struct drm_i915_gem_object *obj = ev->vma->obj; + +if (!i915_gem_object_is_userptr (obj)) +continue ; + + err =i915_gem_object_userptr_submit_done (obj); +if (err) +break ; + } + +spin_unlock (&eb->i915->mm.notifier_lock); + } +#endif +if (unlikely (err)) goto err_skip;@@ -3345,7 +3419,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, err =eb_lookup_vmas (&eb);if (err) { -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true); goto err_engine; }@@ -3417,6 +3491,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,trace_i915_request_queue (eb.request, eb.batch_flags); err =eb_submit (&eb, batch); + err_request:i915_request_get (eb.request); err =eb_request_add (&eb, err);@@ -3437,7 +3512,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK );drivers/gpu/drm/i915/gem/i915_gem_object.h +22
-16@@ -59,6 +59,7 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915, const void *data, resource_size_t size);extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; +void __i915_gem_object_release_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages,bool needs_clflush);@@ -278,12 +279,6 @@ i915_gem_object_never_mmap(const struct drm_i915_gem_object *obj)return i915_gem_object_type_has (obj,I915_GEM_OBJECT_NO_MMAP ); } -static inline bool -i915_gem_object_needs_async_cancel (const struct drm_i915_gem_object *obj) -{ -return i915_gem_object_type_has (obj,I915_GEM_OBJECT_ASYNC_CANCEL ); -} -static inline bool i915_gem_object_is_framebuffer (const struct drm_i915_gem_object *obj) {@@ -573,16 +568,6 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,void __i915_gem_object_invalidate_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin); -static inline bool -i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) -{ -#ifdef CONFIG_MMU_NOTIFIER -return obj->userptr.mm; -#else -return false; -#endif -} -static inline void i915_gem_object_flush_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin)@@ -603,4 +588,25 @@ int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +#ifdef CONFIG_MMU_NOTIFIER +static inline bool +i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) +{ +return obj->userptr.notifier.mm; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj); +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj); +#else +static inline bool i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) {return false; } + +static inline int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 ); } +static inline int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } + +#endif +#endif drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6
-4@@ -7,6 +7,8 @@#ifndef __I915_GEM_OBJECT_TYPES_H__#define __I915_GEM_OBJECT_TYPES_H__ +#include <linux/mmu_notifier.h> +#include <drm/drm_gem.h> #include <uapi/drm/i915_drm.h> @@ -34,7 +36,6 @@ struct drm_i915_gem_object_ops {#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(2)#define I915_GEM_OBJECT_IS_PROXY BIT(3)#define I915_GEM_OBJECT_NO_MMAP BIT(4) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(5)/* Interface between the GEM object and its backing storage. * get_pages() is called once prior to the use of the associated set @@ -299,10 +300,11 @@ struct drm_i915_gem_object {#ifdef CONFIG_MMU_NOTIFIER struct i915_gem_userptr {uintptr_t ptr; +unsigned long notifier_seq; -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; +struct mmu_interval_notifier notifier; +struct page **pvec; +int page_ref; } userptr;#endif drivers/gpu/drm/i915/gem/i915_gem_pages.c +1
-1@@ -226,7 +226,7 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)* get_pages backends we should be better able to handle the * cancellation of the async task in a more uniform manner. */ -if (!pages && !i915_gem_object_needs_async_cancel (obj)) +if (!pages) pages =ERR_PTR (-EINVAL );if (!IS_ERR (pages))drivers/gpu/drm/i915/gem/i915_gem_userptr.c +61
-120@@ -2,10 +2,39 @@* SPDX-License-Identifier: MIT * * Copyright © 2012-2014 Intel Corporation +* +* Based on amdgpu_mn, which bears the following notice: +* +* Copyright 2014 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +*/ +/* +* Authors: +* Christian König <[email protected]> */ #include <linux/mmu_context.h> -#include <linux/mmu_notifier.h> #include <linux/mempolicy.h> #include <linux/swap.h> #include <linux/sched/mm.h> @@ -15,373 +44,121 @@#include "i915_gem_object.h" #include "i915_scatterlist.h" -#if defined(CONFIG_MMU_NOTIFIER ) - -struct i915_mm_struct { -struct mm_struct *mm; -struct drm_i915_private *i915; -struct i915_mmu_notifier *mn; -struct hlist_node node; -struct kref kref; -struct rcu_work work; -}; - -#include <linux/interval_tree.h> - -struct i915_mmu_notifier { -spinlock_t lock; -struct hlist_node node; -struct mmu_notifier mn; -struct rb_root_cached objects; -struct i915_mm_struct *mm; -}; - -struct i915_mmu_object { -struct i915_mmu_notifier *mn; -struct drm_i915_gem_object *obj; -struct interval_tree_node it; -}; +#ifdef CONFIG_MMU_NOTIFIER -static void add_object (struct i915_mmu_object *mo) +/** +* i915_gem_userptr_invalidate - callback to notify about mm change +* +* @mni: the range (mm) is about to update +* @range: details on the invalidation +* @cur_seq: Value to pass to mmu_interval_set_seq() +* +* Block for operations on BOs to finish and mark pages as accessed and +* potentially dirty. +*/ +static bool i915_gem_userptr_invalidate (struct mmu_interval_notifier *mni, +const struct mmu_notifier_range *range, +unsigned long cur_seq) { -GEM_BUG_ON (!RB_EMPTY_NODE (&mo->it.rb)); -interval_tree_insert (&mo->it, &mo->mn->objects); -} + struct drm_i915_gem_object *obj = container_of(mni, struct drm_i915_gem_object, userptr.notifier); +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +long r; -static void del_object (struct i915_mmu_object *mo) -{ -if (RB_EMPTY_NODE (&mo->it.rb)) -return ; +if (!mmu_notifier_range_blockable (range)) +return false; -interval_tree_remove (&mo->it, &mo->mn->objects); -RB_CLEAR_NODE (&mo->it.rb); -} +spin_lock (&i915->mm.notifier_lock); -static void -__i915_gem_userptr_set_active (struct drm_i915_gem_object *obj,bool value) -{ -struct i915_mmu_object *mo = obj->userptr.mmu_object; +mmu_interval_set_seq (mni, cur_seq); + +spin_unlock (&i915->mm.notifier_lock);/* -* During mm_invalidate_range we need to cancel any userptr that -* overlaps the range being invalidated. Doing so requires the -* struct_mutex, and that risks recursion. In order to cause -* recursion, the user must alias the userptr address space with -* a GTT mmapping (possible with a MAP_FIXED) - then when we have -* to invalidate that mmaping, mm_invalidate_range is called with -* the userptr address *and* the struct_mutex held. To prevent that -* we set a flag under the i915_mmu_notifier spinlock to indicate -* whether this object is valid. +* We don't wait when the process is exiting. This is valid +* because the object will be cleaned up anyway. +* +* This is also temporarily required as a hack, because we +* cannot currently force non-consistent batch buffers to preempt +* and reschedule by waiting on it, hanging processes on exit. */ -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -if (value) -add_object (mo); -else -del_object (mo); -spin_unlock (&mo->mn->lock); -} - -static int -userptr_mn_invalidate_range_start (struct mmu_notifier *_mn, -const struct mmu_notifier_range *range) -{ -struct i915_mmu_notifier *mn = - container_of(_mn, struct i915_mmu_notifier, mn); -struct interval_tree_node *it; -unsigned long end; -int ret =0 ; - -if (RB_EMPTY_ROOT (&mn->objects.rb_root)) -return 0 ; - -/* interval ranges are inclusive, but invalidate range is exclusive */ - end = range->end -1 ; - -spin_lock (&mn->lock); - it =interval_tree_iter_first (&mn->objects, range->start, end); -while (it) { -struct drm_i915_gem_object *obj; - -if (!mmu_notifier_range_blockable (range)) { - ret = -EAGAIN ; -break ; - } - -/* -* The mmu_object is released late when destroying the -* GEM object so it is entirely possible to gain a -* reference on an object in the process of being freed -* since our serialisation is via the spinlock and not -* the struct_mutex - and consequently use it after it -* is freed and then double free it. To prevent that -* use-after-free we only acquire a reference on the -* object if it is not in the process of being destroyed. -*/ - obj = container_of(it, struct i915_mmu_object, it)->obj; -if (!kref_get_unless_zero (&obj->base.refcount)) { - it =interval_tree_iter_next (it, range->start, end); -continue ; - } -spin_unlock (&mn->lock); - - ret =i915_gem_object_unbind (obj, -I915_GEM_OBJECT_UNBIND_ACTIVE | -I915_GEM_OBJECT_UNBIND_BARRIER ); -if (ret ==0 ) - ret =__i915_gem_object_put_pages (obj); -i915_gem_object_put (obj); -if (ret) -return ret; +if (current->flags &PF_EXITING ) +return true; -spin_lock (&mn->lock); - -/* -* As we do not (yet) protect the mmu from concurrent insertion -* over this range, there is no guarantee that this search will -* terminate given a pathologic workload. -*/ drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 91
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +5
-5- it =interval_tree_iter_first (&mn->objects, range->start, end); - } -spin_unlock (&mn->lock); - -return ret; +/* we will unbind on next submission, still have userptr pins */ + r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, +MAX_SCHEDULE_TIMEOUT ); +if (r <=0 ) +drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);I think, since linux 5.9 where a fork is no longer setting up COW on pinned pages, and we do in fact still pin pages, I think this fence wait should be removed, together with the
PF_EXITspecial case, as it does not improve on anything but creates hangs that only hangcheck / watchdog can resolve. If we, in future work no longer pin the pages, which is the direction we're moving towards, let's re-add it when needed.Quoted 213 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +14
-184+return true; } -static const struct mmu_notifier_ops i915_gem_userptr_notifier = { - .invalidate_range_start = userptr_mn_invalidate_range_start, +static const struct mmu_interval_notifier_ops i915_gem_userptr_notifier_ops = { + .invalidate = i915_gem_userptr_invalidate, }; -static struct i915_mmu_notifier * -i915_mmu_notifier_create (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn; - - mn =kmalloc (sizeof (*mn),GFP_KERNEL ); -if (mn ==NULL ) -return ERR_PTR (-ENOMEM ); - -spin_lock_init (&mn->lock); - mn->mn.ops = &i915_gem_userptr_notifier; - mn->objects =RB_ROOT_CACHED ; - mn->mm = mm; - -return mn; -} - -static void -i915_gem_userptr_release__mmu_notifier (struct drm_i915_gem_object *obj) -{ -struct i915_mmu_object *mo; - - mo =fetch_and_zero (&obj->userptr.mmu_object); -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -del_object (mo); -spin_unlock (&mo->mn->lock); -kfree (mo); -} - -static struct i915_mmu_notifier * -i915_mmu_notifier_find (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn, *old; -int err; - - mn =READ_ONCE (mm->mn); -if (likely (mn)) -return mn; - - mn =i915_mmu_notifier_create (mm); -if (IS_ERR (mn)) -return mn; - - err =mmu_notifier_register (&mn->mn, mm->mm); -if (err) { -kfree (mn); -return ERR_PTR (err); - } - - old =cmpxchg (&mm->mn,NULL , mn); -if (old) { -mmu_notifier_unregister (&mn->mn, mm->mm); -kfree (mn); - mn = old; - } - -return mn; -} -static int i915_gem_userptr_init__mmu_notifier (struct drm_i915_gem_object *obj) { -struct i915_mmu_notifier *mn; -struct i915_mmu_object *mo; - -if (GEM_WARN_ON (!obj->userptr.mm)) -return -EINVAL ; - - mn =i915_mmu_notifier_find (obj->userptr.mm); -if (IS_ERR (mn)) -return PTR_ERR (mn); - - mo =kzalloc (sizeof (*mo),GFP_KERNEL ); -if (!mo) -return -ENOMEM ; - - mo->mn = mn; - mo->obj = obj; - mo->it.start = obj->userptr.ptr; - mo->it.last = obj->userptr.ptr + obj->base.size -1 ; -RB_CLEAR_NODE (&mo->it.rb); - - obj->userptr.mmu_object = mo; -return 0 ; -} - -static void -i915_mmu_notifier_free (struct i915_mmu_notifier *mn, -struct mm_struct *mm) -{ -if (mn ==NULL ) -return ; - -mmu_notifier_unregister (&mn->mn, mm); -kfree (mn); -} - - -static struct i915_mm_struct * -__i915_mm_struct_find (struct drm_i915_private *i915,struct mm_struct *real) -{ -struct i915_mm_struct *it, *mm =NULL ; - -rcu_read_lock (); -hash_for_each_possible_rcu (i915->mm_structs, - it, node, - (unsigned long )real) -if (it->mm == real &&kref_get_unless_zero (&it->kref)) { - mm = it; -break ; - } -rcu_read_unlock (); - -return mm; +return mmu_interval_notifier_insert (&obj->userptr.notifier, current->mm, + obj->userptr.ptr, obj->base.size, + &i915_gem_userptr_notifier_ops); } -static int -i915_gem_userptr_init__mm_struct (struct drm_i915_gem_object *obj) +static void i915_gem_object_userptr_drop_ref (struct drm_i915_gem_object *obj) {struct drm_i915_private *i915 =to_i915 (obj->base.dev); -struct i915_mm_struct *mm, *new; -int ret =0 ; - -/* During release of the GEM object we hold the struct_mutex. This -* precludes us from calling mmput() at that time as that may be -* the last reference and so call exit_mmap(). exit_mmap() will -* attempt to reap the vma, and if we were holding a GTT mmap -* would then call drm_gem_vm_close() and attempt to reacquire -* the struct mutex. So in order to avoid that recursion, we have -* to defer releasing the mm reference until after we drop the -* struct_mutex, i.e. we need to schedule a worker to do the clean -* up. -*/ - mm =__i915_mm_struct_find (i915, current->mm); -if (mm) - goto out; +struct page **pvec =NULL ; - new =kmalloc (sizeof (*mm),GFP_KERNEL ); -if (!new) -return -ENOMEM ; - -kref_init (&new->kref); - new->i915 =to_i915 (obj->base.dev); - new->mm = current->mm; - new->mn =NULL ; - -spin_lock (&i915->mm_lock); - mm =__i915_mm_struct_find (i915, current->mm); -if (!mm) { -hash_add_rcu (i915->mm_structs, - &new->node, - (unsigned long )new->mm); -mmgrab (current->mm); - mm = new; +spin_lock (&i915->mm.notifier_lock); +if (!--obj->userptr.page_ref) { + pvec = obj->userptr.pvec; + obj->userptr.pvec =NULL ; } -spin_unlock (&i915->mm_lock); -if (mm != new) -kfree (new); +GEM_BUG_ON (obj->userptr.page_ref <0 ); +spin_unlock (&i915->mm.notifier_lock); -out: - obj->userptr.mm = mm; -return ret; -} - -static void -__i915_mm_struct_free__worker (struct work_struct *work) -{ -struct i915_mm_struct *mm =container_of (work,typeof (*mm), work.work); - -i915_mmu_notifier_free (mm->mn, mm->mm); -mmdrop (mm->mm); -kfree (mm); -} - -static void -__i915_mm_struct_free (struct kref *kref) -{ -struct i915_mm_struct *mm =container_of (kref,typeof (*mm), kref); - -spin_lock (&mm->i915->mm_lock); -hash_del_rcu (&mm->node); -spin_unlock (&mm->i915->mm_lock); - -INIT_RCU_WORK (&mm->work, __i915_mm_struct_free__worker); -queue_rcu_work (system_wq, &mm->work); -} - -static void -i915_gem_userptr_release__mm_struct (struct drm_i915_gem_object *obj)drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 125
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-5-{ -if (obj->userptr.mm ==NULL ) -return ; +if (pvec) { +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -kref_put (&obj->userptr.mm->kref, __i915_mm_struct_free); - obj->userptr.mm =NULL ; +unpin_user_pages (pvec, num_pages); +kfree (pvec);IIRC, CQ spotted that we should have a kvfree here right?
Quoted 345 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +89
-206+ } } -struct get_pages_work { -struct work_struct work; -struct drm_i915_gem_object *obj; -struct task_struct *task; -}; - -static struct sg_table * -__i915_gem_userptr_alloc_pages (struct drm_i915_gem_object *obj, -struct page **pvec,unsigned long num_pages) +static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) { +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ;unsigned int max_segment =i915_sg_segment_size ();struct sg_table *st;unsigned int sg_page_sizes;struct scatterlist *sg; +struct page **pvec;int ret; st =kmalloc (sizeof (*st),GFP_KERNEL );if (!st) -return ERR_PTR (-ENOMEM ); +return -ENOMEM ; + +spin_lock (&i915->mm.notifier_lock); +if (GEM_WARN_ON (!obj->userptr.page_ref)) { +spin_unlock (&i915->mm.notifier_lock); + ret = -EFAULT ; + goto err_free; + } + + obj->userptr.page_ref++; + pvec = obj->userptr.pvec; +spin_unlock (&i915->mm.notifier_lock); alloc_table: sg =__sg_alloc_table_from_pages (st, pvec, num_pages,0 , num_pages <<PAGE_SHIFT , max_segment,NULL ,0 ,GFP_KERNEL );if (IS_ERR (sg)) { -kfree (st); -return ERR_CAST (sg); + ret =PTR_ERR (sg); + goto err; } ret =i915_gem_gtt_prepare_pages (obj, st);@@ -393,203 +170,20 @@ __i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj, goto alloc_table; } -kfree (st); -return ERR_PTR (ret); + goto err; } sg_page_sizes =i915_sg_page_sizes (st->sgl);__i915_gem_object_set_pages (obj, st, sg_page_sizes); -return st; -} - -static void -__i915_gem_userptr_get_pages_worker (struct work_struct *_work) -{ -struct get_pages_work *work =container_of (_work,typeof (*work), work); -struct drm_i915_gem_object *obj = work->obj; -const unsigned long npages = obj->base.size >>PAGE_SHIFT ; -unsigned long pinned; -struct page **pvec; -int ret; - - ret = -ENOMEM ; - pinned =0 ; - - pvec =kvmalloc_array (npages,sizeof (struct page *),GFP_KERNEL ); -if (pvec !=NULL ) { -struct mm_struct *mm = obj->userptr.mm->mm; -unsigned int flags =0 ; -int locked =0 ; - -if (!i915_gem_object_is_readonly (obj)) - flags |=FOLL_WRITE ; - - ret = -EFAULT ; -if (mmget_not_zero (mm)) { -while (pinned < npages) { -if (!locked) { -mmap_read_lock (mm); - locked =1 ; - } - ret =pin_user_pages_remote - (mm, - obj->userptr.ptr + pinned *PAGE_SIZE , - npages - pinned, - flags, - pvec + pinned,NULL , &locked); -if (ret <0 ) -break ; - - pinned += ret; - } -if (locked) -mmap_read_unlock (mm); -mmput (mm); - } - } - -mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); -if (obj->userptr.work == &work->work) { -struct sg_table *pages =ERR_PTR (ret); - -if (pinned == npages) { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, - npages); -if (!IS_ERR (pages)) { - pinned =0 ; - pages =NULL ; - } - } - - obj->userptr.work =ERR_CAST (pages); -if (IS_ERR (pages)) -__i915_gem_userptr_set_active (obj, false); - } -mutex_unlock (&obj->mm.lock); - -unpin_user_pages (pvec, pinned); -kvfree (pvec); - -i915_gem_object_put (obj); -put_task_struct (work->task); -kfree (work); -} - -static struct sg_table * -__i915_gem_userptr_get_pages_schedule (struct drm_i915_gem_object *obj) -{ -struct get_pages_work *work; - -/* Spawn a worker so that we can acquire the -* user pages without holding our mutex. Access -* to the user pages requires mmap_lock, and we have -* a strict lock ordering of mmap_lock, struct_mutex - -* we already hold struct_mutex here and so cannot -* call gup without encountering a lock inversion. -* -* Userspace will keep on repeating the operation -* (thanks to EAGAIN) until either we hit the fast -* path or the worker completes. If the worker is -* cancelled or superseded, the task is still run -* but the results ignored. (This leads to -* complications that we may have a stray object -* refcount that we need to be wary of when -* checking for existing objects during creation.) -* If the worker encounters an error, it reports -* that error back to this function through -* obj->userptr.work = ERR_PTR. -*/ - work =kmalloc (sizeof (*work),GFP_KERNEL ); -if (work ==NULL ) -return ERR_PTR (-ENOMEM ); - - obj->userptr.work = &work->work; - - work->obj =i915_gem_object_get (obj); - - work->task = current; -get_task_struct (work->task); - -INIT_WORK (&work->work, __i915_gem_userptr_get_pages_worker); -queue_work (to_i915 (obj->base.dev)->mm.userptr_wq, &work->work); - -return ERR_PTR (-EAGAIN ); -} - -static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) -{ -const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -struct mm_struct *mm = obj->userptr.mm->mm; -struct page **pvec; -struct sg_table *pages; -bool active; -int pinned; -unsigned int gup_flags =0 ; - -/* If userspace should engineer that these pages are replaced in -* the vma between us binding this page into the GTT and completion -* of rendering... Their loss. If they change the mapping of their -* pages they need to create a new bo to point to the new vma. -* -* However, that still leaves open the possibility of the vma -* being copied upon fork. Which falls under the same userspace -* synchronisation issue as a regular bo, except that this time -* the process may not be expecting that a particular piece of -* memory is tied to the GPU. -* -* Fortunately, we can hook into the mmu_notifier in order to -* discard the page references prior to anything nasty happening -* to the vma (discard or cloning) which should prevent the more -* egregious cases from causing harm. -*/ - -if (obj->userptr.work) { -/* active flag should still be held for the pending work */ -if (IS_ERR (obj->userptr.work)) -return PTR_ERR (obj->userptr.work); -else -return -EAGAIN ; - } - - pvec =NULL ; - pinned =0 ; - -if (mm == current->mm) { - pvec =kvmalloc_array (num_pages,sizeof (struct page *), -GFP_KERNEL | - __GFP_NORETRY | - __GFP_NOWARN); -if (pvec) { -/* defer to worker if malloc fails */ -if (!i915_gem_object_is_readonly (obj)) - gup_flags |=FOLL_WRITE ; - pinned =pin_user_pages_fast_only (obj->userptr.ptr, - num_pages, gup_flags, - pvec); - } - } - - active = false; -if (pinned <0 ) { - pages =ERR_PTR (pinned); - pinned =0 ; - }else if (pinned < num_pages) { - pages =__i915_gem_userptr_get_pages_schedule (obj); - active = pages ==ERR_PTR (-EAGAIN ); - }else { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, num_pages); - active = !IS_ERR (pages); - } -if (active) -__i915_gem_userptr_set_active (obj, true); - -if (IS_ERR (pages)) -unpin_user_pages (pvec, pinned); -kvfree (pvec); +return 0 ; -return PTR_ERR_OR_ZERO (pages); +err: +i915_gem_object_userptr_drop_ref (obj); +err_free: +kfree (st); +return ret; } static void@@ -599,9 +193,6 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,struct sgt_iter sgt_iter;struct page *page; -/* Cancel any inflight work and force them to restart their gup */ - obj->userptr.work =NULL ; -__i915_gem_userptr_set_active (obj, false);if (!pages)return ;@@ -641,19 +232,161 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, }mark_page_accessed (page); -unpin_user_page (page); } obj->mm.dirty = false;sg_free_table (pages);kfree (pages); + +i915_gem_object_userptr_drop_ref (obj); +} + +static int i915_gem_object_userptr_unbind (struct drm_i915_gem_object *obj,bool get_pages) +{ +struct sg_table *pages; +int err; + + err =i915_gem_object_unbind (obj,I915_GEM_OBJECT_UNBIND_ACTIVE ); +if (err) +return err; + +if (GEM_WARN_ON (i915_gem_object_has_pinned_pages (obj))) +return -EBUSY ; + +mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + + pages =__i915_gem_object_unset_pages (obj); +if (!IS_ERR_OR_NULL (pages)) +i915_gem_userptr_put_pages (obj, pages); + +if (get_pages) + err =____i915_gem_object_get_pages (obj); +mutex_unlock (&obj->mm.lock); + +return err; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) +{ +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; +struct page **pvec; +unsigned int gup_flags =0 ; +unsigned long notifier_seq; +int pinned, ret; + +if (obj->userptr.notifier.mm != current->mm) +return -EFAULT ; + + ret =i915_gem_object_lock_interruptible (obj,NULL ); +if (ret) +return ret; + +/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */ + ret =i915_gem_object_userptr_unbind (obj, false); +i915_gem_object_unlock (obj); +if (ret) +return ret; + + notifier_seq =mmu_interval_read_begin (&obj->userptr.notifier); + + pvec =kvmalloc_array (num_pages,sizeof (struct page *),GFP_KERNEL ); +if (!pvec) +return -ENOMEM ; + +if (!i915_gem_object_is_readonly (obj)) + gup_flags |=FOLL_WRITE ; + + pinned = ret =0 ; +while (pinned < num_pages) { + ret = pin_user_pages_fast(obj->userptr.ptr + pinned * PAGE_SIZE,drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 312
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ num_pages - pinned, gup_flags, + &pvec[pinned]); +if (ret <0 ) + goto out; + + pinned += ret; + } + ret =0 ; + +spin_lock (&i915->mm.notifier_lock);I think we can improve a lot on the locking here by having the object lock protect the object state and only take the driver-wide notifier lock in execbuf /
userptr_invalidate. If we in addition use an rwlock as a notifier lock taken in read mode in execbuf, any potential global lock contention can be practically eliminated. But that's perhaps for a future improvement.
Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-0+ +if (mmu_interval_read_retry (&obj->userptr.notifier, + !obj->userptr.page_ref ? notifier_seq : + obj->userptr.notifier_seq)) {drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 326
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ ret = -EAGAIN ; + goto out_unlock; + } + +if (!obj->userptr.page_ref++) { + obj->userptr.pvec = pvec; + obj->userptr.notifier_seq = notifier_seq; + + pvec =NULL ; + }In addition, if we can call
get_pages()here to take thepage_ref, we can eliminate onepage_refand the use of_userptr_submit_fini(). That would of course require the object lock, but we'd already hold that for the object state as above.
I guess it could be optimized by not doing this dance..
Perhaps this?
i915_gem_object_set_pages(pvec, seq)
{i915_gem_object_lock_interruptible();
Directly run the set_pages() function body with pvec and seqno as argument. It will check for collisions, and return -EAGAIN if needed, 0 if notifier seqno was already set to same. gem_object_unlock()
}
Quoted 170 lines
Quoted 170 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +61
-18+ +out_unlock: +spin_unlock (&i915->mm.notifier_lock); + +out: +if (pvec) { +unpin_user_pages (pvec, pinned); +kvfree (pvec); + } + +return ret; +} + +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) +{ +if (mmu_interval_read_retry (&obj->userptr.notifier, + obj->userptr.notifier_seq)) { +/* We collided with the mmu notifier, need to retry */ + +return -EAGAIN ; + } + +return 0 ; +} + +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) +{ +i915_gem_object_userptr_drop_ref (obj); +} + +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) +{ +int err; + + err =i915_gem_object_userptr_submit_init (obj); +if (err) +return err; + + err =i915_gem_object_lock_interruptible (obj,NULL ); +if (!err) { +/* +* Since we only check validity, not use the pages, +* it doesn't matter if we collide with the mmu notifier, +* and -EAGAIN handling is not required. +*/ + err =i915_gem_object_pin_pages (obj); +if (!err) +i915_gem_object_unpin_pages (obj); + +i915_gem_object_unlock (obj); + } + +i915_gem_object_userptr_submit_fini (obj); +return err; }static void i915_gem_userptr_release (struct drm_i915_gem_object *obj) { -i915_gem_userptr_release__mmu_notifier (obj); -i915_gem_userptr_release__mm_struct (obj); +GEM_WARN_ON (obj->userptr.page_ref); + +mmu_interval_notifier_remove (&obj->userptr.notifier); + obj->userptr.notifier.mm =NULL ; } static int@@ -686,7 +419,6 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = { .name = "i915_gem_object_userptr", .flags =I915_GEM_OBJECT_IS_SHRINKABLE |I915_GEM_OBJECT_NO_MMAP | -I915_GEM_OBJECT_ASYNC_CANCEL | I915_GEM_OBJECT_IS_PROXY, .get_pages = i915_gem_userptr_get_pages, .put_pages = i915_gem_userptr_put_pages,@@ -793,6 +525,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,i915_gem_object_set_cache_coherency (obj,I915_CACHE_LLC ); obj->userptr.ptr = args->user_ptr; + obj->userptr.notifier_seq =ULONG_MAX ;if (args->flags &I915_USERPTR_READ_ONLY )i915_gem_object_set_readonly (obj);@@ -800,9 +533,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,* at binding. This means that we need to hook into the mmu_notifier * in order to detect if the mmu is destroyed. */ - ret =i915_gem_userptr_init__mm_struct (obj); -if (ret ==0 ) - ret =i915_gem_userptr_init__mmu_notifier (obj); + ret =i915_gem_userptr_init__mmu_notifier (obj);if (ret ==0 ) ret =drm_gem_handle_create (file, &obj->base, &handle);@@ -821,15 +552,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,int i915_gem_init_userptr (struct drm_i915_private *dev_priv) {#ifdef CONFIG_MMU_NOTIFIER -spin_lock_init (&dev_priv->mm_lock); -hash_init (dev_priv->mm_structs); - - dev_priv->mm.userptr_wq = -alloc_workqueue ("i915-userptr-acquire" , -WQ_HIGHPRI |WQ_UNBOUND , -0 ); -if (!dev_priv->mm.userptr_wq) -return -ENOMEM ; +spin_lock_init (&dev_priv->mm.notifier_lock);#endif return 0 ;@@ -837,7 +560,4 @@ int i915_gem_init_userptr(struct drm_i915_private *dev_priv)void i915_gem_cleanup_userptr (struct drm_i915_private *dev_priv) { -#ifdef CONFIG_MMU_NOTIFIER -destroy_workqueue (dev_priv->mm.userptr_wq); -#endif }drivers/gpu/drm/i915/i915_drv.h +3
-6@@ -558,11 +558,10 @@ struct i915_gem_mm {#ifdef CONFIG_MMU_NOTIFIER /** -* Workqueue to fault in userptr pages, flushed by the execbuf -* when required but otherwise left to userspace to try again -* on EAGAIN. +* notifier_lock for mmu notifiers, memory may not be allocated +* while holding this lock. */ -struct workqueue_struct *userptr_wq; +spinlock_t notifier_lock;#endif /* shrinker accounting, also useful for userland debugging */ @@ -942,8 +941,6 @@ struct drm_i915_private {struct i915_ggtt ggtt;/* VM representing the global address space */ struct i915_gem_mm mm; -DECLARE_HASHTABLE (mm_structs,7 ); -spinlock_t mm_lock;/* Kernel Modesetting */ drivers/gpu/drm/i915/i915_gem.c +1
-4@@ -1053,10 +1053,8 @@ int i915_gem_init(struct drm_i915_private *dev_priv) err_unlock:i915_gem_drain_workqueue (dev_priv); -if (ret != -EIO ) { +if (ret != -EIO )intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv); - }if (ret == -EIO ) {/* @@ -1113,7 +1111,6 @@ void i915_gem_driver_release(struct drm_i915_private *dev_priv)intel_wa_list_free (&dev_priv->gt_wa_list);intel_uc_cleanup_firmwares (&dev_priv->gt.uc); -i915_gem_cleanup_userptr (dev_priv);
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_gem.c +0
-0i915_gem_drain_freed_objects (dev_priv);_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [PATCH v8 16/69] drm/i915: Fix userptr so we do not have to worry about obj->mm.lock, v7.
Quoted 1,219 lines · Maarten Lankhorst
Op 2021-03-11 om 18:24 schreef Thomas Hellström (Intel):
Quoted 1,198 lines
Hi, Maarten,
Quoted 26 lines · Maarten Lankhorst
Instead of doing what we do currently, which will never work with
PROVE_LOCKING, do the same as AMD does, and something similar to relocation slowpath. When all locks are dropped, we acquire the pages for pinning. When the locks are taken, we transfer those pages in .get_pages() to the bo. As a final check before installing the fences, we ensure that the mmu notifier was not called; if it is, we return-EAGAINto userspace to signal it has to start over.Changes since v1:
- Unbinding is done insubmit_initonly.submit_begin()removed.
-MMU_NOTFIER->MMU_NOTIFIER
Changes since v2:
- Makei915->mm.notifiera spinlock.
Changes since v3:
- AddWARN_ONif there are any page references left, should have been 0.
- Return 0 on success insubmit_init(), bug from spinlock conversion.
- Release pvec outside ofnotifier_lock(Thomas).
Changes since v4:
- Mention why we're clearing eb->[i + 1].vma in the code. (Thomas)
- Actually check all invalidations ineb_move_to_gpu. (Thomas)
- Do not wait when process is exiting to fix gem_ctx_persistence.userptr. Changes since v5:
- Clarify why check onPF_EXITINGis (temporarily) required. Changes since v6:
- Ensure userptr validity is checked inset_domainthrough a special path.Quoted 2 lines
Signed-off-by Maarten Lankhorst <[email protected]>Acked-by Dave Airlie <[email protected]>Mostly LGTM. Comments / suggestions below.
Quoted 572 lines
--- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 18 +- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 101 ++- drivers/gpu/drm/i915/gem/i915_gem_object.h | 38 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 10 +- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 796 ++++++------------ drivers/gpu/drm/i915/i915_drv.h | 9 +- drivers/gpu/drm/i915/i915_gem.c | 5 +- 8 files changed, 395 insertions(+), 584 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_domain.c +16
-2@@ -468,14 +468,28 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,if (!obj)return -ENOENT ; +if (i915_gem_object_is_userptr (obj)) { +/* +* Try to grab userptr pages, iris uses set_domain to check +* userptr validity +*/ + err =i915_gem_object_userptr_validate (obj); +if (!err) + err =i915_gem_object_wait (obj, +I915_WAIT_INTERRUPTIBLE | +I915_WAIT_PRIORITY | + (write_domain ?I915_WAIT_ALL :0 ), +MAX_SCHEDULE_TIMEOUT ); + goto out; + } +/* * Proxy objects do not control access to the backing storage, ergo * they cannot be used as a means to manipulate the cache domain * tracking for that backing storage. The proxy object is always * considered to be outside of any cache domain. */ -if (i915_gem_object_is_proxy (obj) && - !i915_gem_object_is_userptr (obj)) { +if (i915_gem_object_is_proxy (obj)) { err = -ENXIO ; goto out; }drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +88
-13@@ -53,14 +53,16 @@ enum {/* __EXEC_OBJECT_NO_RESERVE is BIT(31), defined in i915_vma.h */ #define __EXEC_OBJECT_HAS_PIN BIT(30)#define __EXEC_OBJECT_HAS_FENCE BIT(29) -#define __EXEC_OBJECT_NEEDS_MAP BIT(28) -#define __EXEC_OBJECT_NEEDS_BIAS BIT(27) -#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 27)/* all of the above + */ +#define __EXEC_OBJECT_USERPTR_INIT BIT(28) +#define __EXEC_OBJECT_NEEDS_MAP BIT(27) +#define __EXEC_OBJECT_NEEDS_BIAS BIT(26) +#define __EXEC_OBJECT_INTERNAL_FLAGS (~0u << 26)/* all of the above + */ #define __EXEC_OBJECT_RESERVED (__EXEC_OBJECT_HAS_PIN | __EXEC_OBJECT_HAS_FENCE)#define __EXEC_HAS_RELOC BIT(31)#define __EXEC_ENGINE_PINNED BIT(30) -#define __EXEC_INTERNAL_FLAGS (~0u << 30) +#define __EXEC_USERPTR_USED BIT(29) +#define __EXEC_INTERNAL_FLAGS (~0u << 29)#define UPDATE PIN_OFFSET_FIXED#define BATCH_OFFSET_BIAS (256*1024)@@ -864,6 +866,26 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb) }eb_add_vma (eb, i, batch, vma); + +if (i915_gem_object_is_userptr (vma->obj)) { + err =i915_gem_object_userptr_submit_init (vma->obj); +if (err) { +if (i +1 < eb->buffer_count) { +/* +* Execbuffer code expects last vma entry to be NULL, +* since we already initialized this entry, +* set the next value to NULL or we mess up +* cleanup handling. +*/ + eb->vma[i +1 ].vma =NULL ; + } + +return err; + } + + eb->vma[i].flags |= __EXEC_OBJECT_USERPTR_INIT; + eb->args->flags |= __EXEC_USERPTR_USED; + } }if (unlikely (eb->batch->flags &EXEC_OBJECT_WRITE )) {@@ -965,7 +987,7 @@ eb_get_vma(const struct i915_execbuffer *eb, unsigned long handle) } } -static void eb_release_vmas (struct i915_execbuffer *eb,bool final) +static void eb_release_vmas (struct i915_execbuffer *eb,bool final,bool release_userptr) {const unsigned int count = eb->buffer_count;unsigned int i;@@ -979,6 +1001,11 @@ static void eb_release_vmas(struct i915_execbuffer *eb, bool final)eb_unreserve_vma (ev); +if (release_userptr && ev->flags & __EXEC_OBJECT_USERPTR_INIT) { + ev->flags &= ~__EXEC_OBJECT_USERPTR_INIT; +i915_gem_object_userptr_submit_fini (vma->obj); + } +if (final)i915_vma_put (vma); }@@ -1909,6 +1936,31 @@ static int eb_prefault_relocations(const struct i915_execbuffer *eb)return 0 ; } +static int eb_reinit_userptr (struct i915_execbuffer *eb) +{ +const unsigned int count = eb->buffer_count; +unsigned int i; +int ret; + +if (likely (!(eb->args->flags & __EXEC_USERPTR_USED))) +return 0 ; + +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; + +if (!i915_gem_object_is_userptr (ev->vma->obj)) +continue ; + + ret =i915_gem_object_userptr_submit_init (ev->vma->obj); +if (ret) +return ret; + + ev->flags |= __EXEC_OBJECT_USERPTR_INIT; + } + +return 0 ; +} + static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb,struct i915_request *rq) {@@ -1923,7 +1975,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, }/* We may process another execbuffer during the unlock... */ -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, true);i915_gem_ww_ctx_fini (&eb->ww);if (rq) {@@ -1964,10 +2016,8 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err =0 ; } -#ifdef CONFIG_MMU_NOTIFIER if (!err) -flush_workqueue (eb->i915->mm.userptr_wq); -#endif + err =eb_reinit_userptr (eb); err_relock:i915_gem_ww_ctx_init (&eb->ww, true);@@ -2029,7 +2079,7 @@ static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb, err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto repeat_validate;@@ -2126,7 +2176,7 @@ static int eb_relocate_parse(struct i915_execbuffer *eb) err:if (err == -EDEADLK ) { -eb_release_vmas (eb, false); +eb_release_vmas (eb, false, false); err =i915_gem_ww_ctx_backoff (&eb->ww);if (!err) goto retry;@@ -2201,6 +2251,30 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) flags | __EXEC_OBJECT_NO_RESERVE); } +#ifdef CONFIG_MMU_NOTIFIER +if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { +spin_lock (&eb->i915->mm.notifier_lock); + +/* +* count is always at least 1, otherwise __EXEC_USERPTR_USED +* could not have been set +*/ +for (i =0 ; i < count; i++) { +struct eb_vma *ev = &eb->vma[i]; +struct drm_i915_gem_object *obj = ev->vma->obj; + +if (!i915_gem_object_is_userptr (obj)) +continue ; + + err =i915_gem_object_userptr_submit_done (obj); +if (err) +break ; + } + +spin_unlock (&eb->i915->mm.notifier_lock); + } +#endif +if (unlikely (err)) goto err_skip;@@ -3345,7 +3419,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, err =eb_lookup_vmas (&eb);if (err) { -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true); goto err_engine; }@@ -3417,6 +3491,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,trace_i915_request_queue (eb.request, eb.batch_flags); err =eb_submit (&eb, batch); + err_request:i915_request_get (eb.request); err =eb_request_add (&eb, err);@@ -3437,7 +3512,7 @@ i915_gem_do_execbuffer(struct drm_device *dev,i915_request_put (eb.request); err_vma: -eb_release_vmas (&eb, true); +eb_release_vmas (&eb, true, true);if (eb.trampoline)i915_vma_unpin (eb.trampoline);WARN_ON (err == -EDEADLK );drivers/gpu/drm/i915/gem/i915_gem_object.h +22
-16@@ -59,6 +59,7 @@ i915_gem_object_create_shmem_from_data(struct drm_i915_private *i915, const void *data, resource_size_t size);extern const struct drm_i915_gem_object_ops i915_gem_shmem_ops; +void __i915_gem_object_release_shmem (struct drm_i915_gem_object *obj,struct sg_table *pages,bool needs_clflush);@@ -278,12 +279,6 @@ i915_gem_object_never_mmap(const struct drm_i915_gem_object *obj)return i915_gem_object_type_has (obj,I915_GEM_OBJECT_NO_MMAP ); } -static inline bool -i915_gem_object_needs_async_cancel (const struct drm_i915_gem_object *obj) -{ -return i915_gem_object_type_has (obj,I915_GEM_OBJECT_ASYNC_CANCEL ); -} -static inline bool i915_gem_object_is_framebuffer (const struct drm_i915_gem_object *obj) {@@ -573,16 +568,6 @@ void __i915_gem_object_flush_frontbuffer(struct drm_i915_gem_object *obj,void __i915_gem_object_invalidate_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin); -static inline bool -i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) -{ -#ifdef CONFIG_MMU_NOTIFIER -return obj->userptr.mm; -#else -return false; -#endif -} -static inline void i915_gem_object_flush_frontbuffer (struct drm_i915_gem_object *obj,enum fb_op_origin origin)@@ -603,4 +588,25 @@ int i915_gem_object_read_from_page(struct drm_i915_gem_object *obj, u64 offset,bool i915_gem_object_is_shmem (const struct drm_i915_gem_object *obj); +#ifdef CONFIG_MMU_NOTIFIER +static inline bool +i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) +{ +return obj->userptr.notifier.mm; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj); +void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj); +int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj); +#else +static inline bool i915_gem_object_is_userptr (struct drm_i915_gem_object *obj) {return false; } + +static inline int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline int i915_gem_object_userptr_submit_done (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } +static inline void i915_gem_object_userptr_submit_fini (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 ); } +static inline int i915_gem_object_userptr_validate (struct drm_i915_gem_object *obj) {GEM_BUG_ON (1 );return -ENODEV ; } + +#endif +#endif drivers/gpu/drm/i915/gem/i915_gem_object_types.h +6
-4@@ -7,6 +7,8 @@#ifndef __I915_GEM_OBJECT_TYPES_H__#define __I915_GEM_OBJECT_TYPES_H__ +#include <linux/mmu_notifier.h> +#include <drm/drm_gem.h> #include <uapi/drm/i915_drm.h> @@ -34,7 +36,6 @@ struct drm_i915_gem_object_ops {#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(2)#define I915_GEM_OBJECT_IS_PROXY BIT(3)#define I915_GEM_OBJECT_NO_MMAP BIT(4) -#define I915_GEM_OBJECT_ASYNC_CANCEL BIT(5)/* Interface between the GEM object and its backing storage. * get_pages() is called once prior to the use of the associated set @@ -299,10 +300,11 @@ struct drm_i915_gem_object {#ifdef CONFIG_MMU_NOTIFIER struct i915_gem_userptr {uintptr_t ptr; +unsigned long notifier_seq; -struct i915_mm_struct *mm; -struct i915_mmu_object *mmu_object; -struct work_struct *work; +struct mmu_interval_notifier notifier; +struct page **pvec; +int page_ref; } userptr;#endif drivers/gpu/drm/i915/gem/i915_gem_pages.c +1
-1@@ -226,7 +226,7 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)* get_pages backends we should be better able to handle the * cancellation of the async task in a more uniform manner. */ -if (!pages && !i915_gem_object_needs_async_cancel (obj)) +if (!pages) pages =ERR_PTR (-EINVAL );if (!IS_ERR (pages))drivers/gpu/drm/i915/gem/i915_gem_userptr.c +61
-120@@ -2,10 +2,39 @@* SPDX-License-Identifier: MIT * * Copyright © 2012-2014 Intel Corporation +* +* Based on amdgpu_mn, which bears the following notice: +* +* Copyright 2014 Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +* +*/ +/* +* Authors: +* Christian König <[email protected]> */ #include <linux/mmu_context.h> -#include <linux/mmu_notifier.h> #include <linux/mempolicy.h> #include <linux/swap.h> #include <linux/sched/mm.h> @@ -15,373 +44,121 @@#include "i915_gem_object.h" #include "i915_scatterlist.h" -#if defined(CONFIG_MMU_NOTIFIER ) - -struct i915_mm_struct { -struct mm_struct *mm; -struct drm_i915_private *i915; -struct i915_mmu_notifier *mn; -struct hlist_node node; -struct kref kref; -struct rcu_work work; -}; - -#include <linux/interval_tree.h> - -struct i915_mmu_notifier { -spinlock_t lock; -struct hlist_node node; -struct mmu_notifier mn; -struct rb_root_cached objects; -struct i915_mm_struct *mm; -}; - -struct i915_mmu_object { -struct i915_mmu_notifier *mn; -struct drm_i915_gem_object *obj; -struct interval_tree_node it; -}; +#ifdef CONFIG_MMU_NOTIFIER -static void add_object (struct i915_mmu_object *mo) +/** +* i915_gem_userptr_invalidate - callback to notify about mm change +* +* @mni: the range (mm) is about to update +* @range: details on the invalidation +* @cur_seq: Value to pass to mmu_interval_set_seq() +* +* Block for operations on BOs to finish and mark pages as accessed and +* potentially dirty. +*/ +static bool i915_gem_userptr_invalidate (struct mmu_interval_notifier *mni, +const struct mmu_notifier_range *range, +unsigned long cur_seq) { -GEM_BUG_ON (!RB_EMPTY_NODE (&mo->it.rb)); -interval_tree_insert (&mo->it, &mo->mn->objects); -} + struct drm_i915_gem_object *obj = container_of(mni, struct drm_i915_gem_object, userptr.notifier); +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +long r; -static void del_object (struct i915_mmu_object *mo) -{ -if (RB_EMPTY_NODE (&mo->it.rb)) -return ; +if (!mmu_notifier_range_blockable (range)) +return false; -interval_tree_remove (&mo->it, &mo->mn->objects); -RB_CLEAR_NODE (&mo->it.rb); -} +spin_lock (&i915->mm.notifier_lock); -static void -__i915_gem_userptr_set_active (struct drm_i915_gem_object *obj,bool value) -{ -struct i915_mmu_object *mo = obj->userptr.mmu_object; +mmu_interval_set_seq (mni, cur_seq); + +spin_unlock (&i915->mm.notifier_lock);/* -* During mm_invalidate_range we need to cancel any userptr that -* overlaps the range being invalidated. Doing so requires the -* struct_mutex, and that risks recursion. In order to cause -* recursion, the user must alias the userptr address space with -* a GTT mmapping (possible with a MAP_FIXED) - then when we have -* to invalidate that mmaping, mm_invalidate_range is called with -* the userptr address *and* the struct_mutex held. To prevent that -* we set a flag under the i915_mmu_notifier spinlock to indicate -* whether this object is valid. +* We don't wait when the process is exiting. This is valid +* because the object will be cleaned up anyway. +* +* This is also temporarily required as a hack, because we +* cannot currently force non-consistent batch buffers to preempt +* and reschedule by waiting on it, hanging processes on exit. */ -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -if (value) -add_object (mo); -else -del_object (mo); -spin_unlock (&mo->mn->lock); -} - -static int -userptr_mn_invalidate_range_start (struct mmu_notifier *_mn, -const struct mmu_notifier_range *range) -{ -struct i915_mmu_notifier *mn = - container_of(_mn, struct i915_mmu_notifier, mn); -struct interval_tree_node *it; -unsigned long end; -int ret =0 ; - -if (RB_EMPTY_ROOT (&mn->objects.rb_root)) -return 0 ; - -/* interval ranges are inclusive, but invalidate range is exclusive */ - end = range->end -1 ; - -spin_lock (&mn->lock); - it =interval_tree_iter_first (&mn->objects, range->start, end); -while (it) { -struct drm_i915_gem_object *obj; - -if (!mmu_notifier_range_blockable (range)) { - ret = -EAGAIN ; -break ; - } - -/* -* The mmu_object is released late when destroying the -* GEM object so it is entirely possible to gain a -* reference on an object in the process of being freed -* since our serialisation is via the spinlock and not -* the struct_mutex - and consequently use it after it -* is freed and then double free it. To prevent that -* use-after-free we only acquire a reference on the -* object if it is not in the process of being destroyed. -*/ - obj = container_of(it, struct i915_mmu_object, it)->obj; -if (!kref_get_unless_zero (&obj->base.refcount)) { - it =interval_tree_iter_next (it, range->start, end); -continue ; - } -spin_unlock (&mn->lock); - - ret =i915_gem_object_unbind (obj, -I915_GEM_OBJECT_UNBIND_ACTIVE | -I915_GEM_OBJECT_UNBIND_BARRIER ); -if (ret ==0 ) - ret =__i915_gem_object_put_pages (obj); -i915_gem_object_put (obj); -if (ret) -return ret; +if (current->flags &PF_EXITING ) +return true; -spin_lock (&mn->lock); - -/* -* As we do not (yet) protect the mmu from concurrent insertion -* over this range, there is no guarantee that this search will -* terminate given a pathologic workload. -*/ drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 91
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +5
-5- it =interval_tree_iter_first (&mn->objects, range->start, end); - } -spin_unlock (&mn->lock); - -return ret; +/* we will unbind on next submission, still have userptr pins */ + r =dma_resv_wait_timeout_rcu (obj->base.resv, true, false, +MAX_SCHEDULE_TIMEOUT ); +if (r <=0 ) +drm_err (&i915->drm,"(%ld) failed to wait for idle\n" , r);I think, since linux 5.9 where a fork is no longer setting up COW on pinned pages, and we do in fact still pin pages, I think this fence wait should be removed, together with the
PF_EXITspecial case, as it does not improve on anything but creates hangs that only hangcheck / watchdog can resolve. If we, in future work no longer pin the pages, which is the direction we're moving towards, let's re-add it when needed.Quoted 213 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +14
-184+return true; } -static const struct mmu_notifier_ops i915_gem_userptr_notifier = { - .invalidate_range_start = userptr_mn_invalidate_range_start, +static const struct mmu_interval_notifier_ops i915_gem_userptr_notifier_ops = { + .invalidate = i915_gem_userptr_invalidate, }; -static struct i915_mmu_notifier * -i915_mmu_notifier_create (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn; - - mn =kmalloc (sizeof (*mn),GFP_KERNEL ); -if (mn ==NULL ) -return ERR_PTR (-ENOMEM ); - -spin_lock_init (&mn->lock); - mn->mn.ops = &i915_gem_userptr_notifier; - mn->objects =RB_ROOT_CACHED ; - mn->mm = mm; - -return mn; -} - -static void -i915_gem_userptr_release__mmu_notifier (struct drm_i915_gem_object *obj) -{ -struct i915_mmu_object *mo; - - mo =fetch_and_zero (&obj->userptr.mmu_object); -if (!mo) -return ; - -spin_lock (&mo->mn->lock); -del_object (mo); -spin_unlock (&mo->mn->lock); -kfree (mo); -} - -static struct i915_mmu_notifier * -i915_mmu_notifier_find (struct i915_mm_struct *mm) -{ -struct i915_mmu_notifier *mn, *old; -int err; - - mn =READ_ONCE (mm->mn); -if (likely (mn)) -return mn; - - mn =i915_mmu_notifier_create (mm); -if (IS_ERR (mn)) -return mn; - - err =mmu_notifier_register (&mn->mn, mm->mm); -if (err) { -kfree (mn); -return ERR_PTR (err); - } - - old =cmpxchg (&mm->mn,NULL , mn); -if (old) { -mmu_notifier_unregister (&mn->mn, mm->mm); -kfree (mn); - mn = old; - } - -return mn; -} -static int i915_gem_userptr_init__mmu_notifier (struct drm_i915_gem_object *obj) { -struct i915_mmu_notifier *mn; -struct i915_mmu_object *mo; - -if (GEM_WARN_ON (!obj->userptr.mm)) -return -EINVAL ; - - mn =i915_mmu_notifier_find (obj->userptr.mm); -if (IS_ERR (mn)) -return PTR_ERR (mn); - - mo =kzalloc (sizeof (*mo),GFP_KERNEL ); -if (!mo) -return -ENOMEM ; - - mo->mn = mn; - mo->obj = obj; - mo->it.start = obj->userptr.ptr; - mo->it.last = obj->userptr.ptr + obj->base.size -1 ; -RB_CLEAR_NODE (&mo->it.rb); - - obj->userptr.mmu_object = mo; -return 0 ; -} - -static void -i915_mmu_notifier_free (struct i915_mmu_notifier *mn, -struct mm_struct *mm) -{ -if (mn ==NULL ) -return ; - -mmu_notifier_unregister (&mn->mn, mm); -kfree (mn); -} - - -static struct i915_mm_struct * -__i915_mm_struct_find (struct drm_i915_private *i915,struct mm_struct *real) -{ -struct i915_mm_struct *it, *mm =NULL ; - -rcu_read_lock (); -hash_for_each_possible_rcu (i915->mm_structs, - it, node, - (unsigned long )real) -if (it->mm == real &&kref_get_unless_zero (&it->kref)) { - mm = it; -break ; - } -rcu_read_unlock (); - -return mm; +return mmu_interval_notifier_insert (&obj->userptr.notifier, current->mm, + obj->userptr.ptr, obj->base.size, + &i915_gem_userptr_notifier_ops); } -static int -i915_gem_userptr_init__mm_struct (struct drm_i915_gem_object *obj) +static void i915_gem_object_userptr_drop_ref (struct drm_i915_gem_object *obj) {struct drm_i915_private *i915 =to_i915 (obj->base.dev); -struct i915_mm_struct *mm, *new; -int ret =0 ; - -/* During release of the GEM object we hold the struct_mutex. This -* precludes us from calling mmput() at that time as that may be -* the last reference and so call exit_mmap(). exit_mmap() will -* attempt to reap the vma, and if we were holding a GTT mmap -* would then call drm_gem_vm_close() and attempt to reacquire -* the struct mutex. So in order to avoid that recursion, we have -* to defer releasing the mm reference until after we drop the -* struct_mutex, i.e. we need to schedule a worker to do the clean -* up. -*/ - mm =__i915_mm_struct_find (i915, current->mm); -if (mm) - goto out; +struct page **pvec =NULL ; - new =kmalloc (sizeof (*mm),GFP_KERNEL ); -if (!new) -return -ENOMEM ; - -kref_init (&new->kref); - new->i915 =to_i915 (obj->base.dev); - new->mm = current->mm; - new->mn =NULL ; - -spin_lock (&i915->mm_lock); - mm =__i915_mm_struct_find (i915, current->mm); -if (!mm) { -hash_add_rcu (i915->mm_structs, - &new->node, - (unsigned long )new->mm); -mmgrab (current->mm); - mm = new; +spin_lock (&i915->mm.notifier_lock); +if (!--obj->userptr.page_ref) { + pvec = obj->userptr.pvec; + obj->userptr.pvec =NULL ; } -spin_unlock (&i915->mm_lock); -if (mm != new) -kfree (new); +GEM_BUG_ON (obj->userptr.page_ref <0 ); +spin_unlock (&i915->mm.notifier_lock); -out: - obj->userptr.mm = mm; -return ret; -} - -static void -__i915_mm_struct_free__worker (struct work_struct *work) -{ -struct i915_mm_struct *mm =container_of (work,typeof (*mm), work.work); - -i915_mmu_notifier_free (mm->mn, mm->mm); -mmdrop (mm->mm); -kfree (mm); -} - -static void -__i915_mm_struct_free (struct kref *kref) -{ -struct i915_mm_struct *mm =container_of (kref,typeof (*mm), kref); - -spin_lock (&mm->i915->mm_lock); -hash_del_rcu (&mm->node); -spin_unlock (&mm->i915->mm_lock); - -INIT_RCU_WORK (&mm->work, __i915_mm_struct_free__worker); -queue_rcu_work (system_wq, &mm->work); -} - -static void -i915_gem_userptr_release__mm_struct (struct drm_i915_gem_object *obj)drivers/gpu/drm/i915/gem/i915_gem_userptr.c line 124
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-5-{ -if (obj->userptr.mm ==NULL ) -return ; +if (pvec) { +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -kref_put (&obj->userptr.mm->kref, __i915_mm_struct_free); - obj->userptr.mm =NULL ; +unpin_user_pages (pvec, num_pages); +kfree (pvec);IIRC, CQ spotted that we should have a kvfree here right?
Quoted 345 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +89
-206+ } } -struct get_pages_work { -struct work_struct work; -struct drm_i915_gem_object *obj; -struct task_struct *task; -}; - -static struct sg_table * -__i915_gem_userptr_alloc_pages (struct drm_i915_gem_object *obj, -struct page **pvec,unsigned long num_pages) +static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) { +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ;unsigned int max_segment =i915_sg_segment_size ();struct sg_table *st;unsigned int sg_page_sizes;struct scatterlist *sg; +struct page **pvec;int ret; st =kmalloc (sizeof (*st),GFP_KERNEL );if (!st) -return ERR_PTR (-ENOMEM ); +return -ENOMEM ; + +spin_lock (&i915->mm.notifier_lock); +if (GEM_WARN_ON (!obj->userptr.page_ref)) { +spin_unlock (&i915->mm.notifier_lock); + ret = -EFAULT ; + goto err_free; + } + + obj->userptr.page_ref++; + pvec = obj->userptr.pvec; +spin_unlock (&i915->mm.notifier_lock); alloc_table: sg =__sg_alloc_table_from_pages (st, pvec, num_pages,0 , num_pages <<PAGE_SHIFT , max_segment,NULL ,0 ,GFP_KERNEL );if (IS_ERR (sg)) { -kfree (st); -return ERR_CAST (sg); + ret =PTR_ERR (sg); + goto err; } ret =i915_gem_gtt_prepare_pages (obj, st);@@ -393,203 +170,20 @@ __i915_gem_userptr_alloc_pages(struct drm_i915_gem_object *obj, goto alloc_table; } -kfree (st); -return ERR_PTR (ret); + goto err; } sg_page_sizes =i915_sg_page_sizes (st->sgl);__i915_gem_object_set_pages (obj, st, sg_page_sizes); -return st; -} - -static void -__i915_gem_userptr_get_pages_worker (struct work_struct *_work) -{ -struct get_pages_work *work =container_of (_work,typeof (*work), work); -struct drm_i915_gem_object *obj = work->obj; -const unsigned long npages = obj->base.size >>PAGE_SHIFT ; -unsigned long pinned; -struct page **pvec; -int ret; - - ret = -ENOMEM ; - pinned =0 ; - - pvec =kvmalloc_array (npages,sizeof (struct page *),GFP_KERNEL ); -if (pvec !=NULL ) { -struct mm_struct *mm = obj->userptr.mm->mm; -unsigned int flags =0 ; -int locked =0 ; - -if (!i915_gem_object_is_readonly (obj)) - flags |=FOLL_WRITE ; - - ret = -EFAULT ; -if (mmget_not_zero (mm)) { -while (pinned < npages) { -if (!locked) { -mmap_read_lock (mm); - locked =1 ; - } - ret =pin_user_pages_remote - (mm, - obj->userptr.ptr + pinned *PAGE_SIZE , - npages - pinned, - flags, - pvec + pinned,NULL , &locked); -if (ret <0 ) -break ; - - pinned += ret; - } -if (locked) -mmap_read_unlock (mm); -mmput (mm); - } - } - -mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); -if (obj->userptr.work == &work->work) { -struct sg_table *pages =ERR_PTR (ret); - -if (pinned == npages) { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, - npages); -if (!IS_ERR (pages)) { - pinned =0 ; - pages =NULL ; - } - } - - obj->userptr.work =ERR_CAST (pages); -if (IS_ERR (pages)) -__i915_gem_userptr_set_active (obj, false); - } -mutex_unlock (&obj->mm.lock); - -unpin_user_pages (pvec, pinned); -kvfree (pvec); - -i915_gem_object_put (obj); -put_task_struct (work->task); -kfree (work); -} - -static struct sg_table * -__i915_gem_userptr_get_pages_schedule (struct drm_i915_gem_object *obj) -{ -struct get_pages_work *work; - -/* Spawn a worker so that we can acquire the -* user pages without holding our mutex. Access -* to the user pages requires mmap_lock, and we have -* a strict lock ordering of mmap_lock, struct_mutex - -* we already hold struct_mutex here and so cannot -* call gup without encountering a lock inversion. -* -* Userspace will keep on repeating the operation -* (thanks to EAGAIN) until either we hit the fast -* path or the worker completes. If the worker is -* cancelled or superseded, the task is still run -* but the results ignored. (This leads to -* complications that we may have a stray object -* refcount that we need to be wary of when -* checking for existing objects during creation.) -* If the worker encounters an error, it reports -* that error back to this function through -* obj->userptr.work = ERR_PTR. -*/ - work =kmalloc (sizeof (*work),GFP_KERNEL ); -if (work ==NULL ) -return ERR_PTR (-ENOMEM ); - - obj->userptr.work = &work->work; - - work->obj =i915_gem_object_get (obj); - - work->task = current; -get_task_struct (work->task); - -INIT_WORK (&work->work, __i915_gem_userptr_get_pages_worker); -queue_work (to_i915 (obj->base.dev)->mm.userptr_wq, &work->work); - -return ERR_PTR (-EAGAIN ); -} - -static int i915_gem_userptr_get_pages (struct drm_i915_gem_object *obj) -{ -const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; -struct mm_struct *mm = obj->userptr.mm->mm; -struct page **pvec; -struct sg_table *pages; -bool active; -int pinned; -unsigned int gup_flags =0 ; - -/* If userspace should engineer that these pages are replaced in -* the vma between us binding this page into the GTT and completion -* of rendering... Their loss. If they change the mapping of their -* pages they need to create a new bo to point to the new vma. -* -* However, that still leaves open the possibility of the vma -* being copied upon fork. Which falls under the same userspace -* synchronisation issue as a regular bo, except that this time -* the process may not be expecting that a particular piece of -* memory is tied to the GPU. -* -* Fortunately, we can hook into the mmu_notifier in order to -* discard the page references prior to anything nasty happening -* to the vma (discard or cloning) which should prevent the more -* egregious cases from causing harm. -*/ - -if (obj->userptr.work) { -/* active flag should still be held for the pending work */ -if (IS_ERR (obj->userptr.work)) -return PTR_ERR (obj->userptr.work); -else -return -EAGAIN ; - } - - pvec =NULL ; - pinned =0 ; - -if (mm == current->mm) { - pvec =kvmalloc_array (num_pages,sizeof (struct page *), -GFP_KERNEL | - __GFP_NORETRY | - __GFP_NOWARN); -if (pvec) { -/* defer to worker if malloc fails */ -if (!i915_gem_object_is_readonly (obj)) - gup_flags |=FOLL_WRITE ; - pinned =pin_user_pages_fast_only (obj->userptr.ptr, - num_pages, gup_flags, - pvec); - } - } - - active = false; -if (pinned <0 ) { - pages =ERR_PTR (pinned); - pinned =0 ; - }else if (pinned < num_pages) { - pages =__i915_gem_userptr_get_pages_schedule (obj); - active = pages ==ERR_PTR (-EAGAIN ); - }else { - pages =__i915_gem_userptr_alloc_pages (obj, pvec, num_pages); - active = !IS_ERR (pages); - } -if (active) -__i915_gem_userptr_set_active (obj, true); - -if (IS_ERR (pages)) -unpin_user_pages (pvec, pinned); -kvfree (pvec); +return 0 ; -return PTR_ERR_OR_ZERO (pages); +err: +i915_gem_object_userptr_drop_ref (obj); +err_free: +kfree (st); +return ret; } static void@@ -599,9 +193,6 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,struct sgt_iter sgt_iter;struct page *page; -/* Cancel any inflight work and force them to restart their gup */ - obj->userptr.work =NULL ; -__i915_gem_userptr_set_active (obj, false);if (!pages)return ;@@ -641,19 +232,161 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, }mark_page_accessed (page); -unpin_user_page (page); } obj->mm.dirty = false;sg_free_table (pages);kfree (pages); + +i915_gem_object_userptr_drop_ref (obj); +} + +static int i915_gem_object_userptr_unbind (struct drm_i915_gem_object *obj,bool get_pages) +{ +struct sg_table *pages; +int err; + + err =i915_gem_object_unbind (obj,I915_GEM_OBJECT_UNBIND_ACTIVE ); +if (err) +return err; + +if (GEM_WARN_ON (i915_gem_object_has_pinned_pages (obj))) +return -EBUSY ; + +mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + + pages =__i915_gem_object_unset_pages (obj); +if (!IS_ERR_OR_NULL (pages)) +i915_gem_userptr_put_pages (obj, pages); + +if (get_pages) + err =____i915_gem_object_get_pages (obj); +mutex_unlock (&obj->mm.lock); + +return err; +} + +int i915_gem_object_userptr_submit_init (struct drm_i915_gem_object *obj) +{ +struct drm_i915_private *i915 =to_i915 (obj->base.dev); +const unsigned long num_pages = obj->base.size >>PAGE_SHIFT ; +struct page **pvec; +unsigned int gup_flags =0 ; +unsigned long notifier_seq; +int pinned, ret; + +if (obj->userptr.notifier.mm != current->mm) +return -EFAULT ; + + ret =i915_gem_object_lock_interruptible (obj,NULL ); +if (ret) +return ret; + +/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */ + ret =i915_gem_object_userptr_unbind (obj, false); +i915_gem_object_unlock (obj); +if (ret) +return ret; + + notifier_seq =mmu_interval_read_begin (&obj->userptr.notifier); + + pvec =kvmalloc_array (num_pages,sizeof (struct page *),GFP_KERNEL ); +if (!pvec) +return -ENOMEM ; + +if (!i915_gem_object_is_readonly (obj)) + gup_flags |=FOLL_WRITE ; + + pinned = ret =0 ; +while (pinned < num_pages) { + ret = pin_user_pages_fast(obj->userptr.ptr + pinned * PAGE_SIZE,drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 312
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ num_pages - pinned, gup_flags, + &pvec[pinned]); +if (ret <0 ) + goto out; + + pinned += ret; + } + ret =0 ; + +spin_lock (&i915->mm.notifier_lock);I think we can improve a lot on the locking here by having the object lock protect the object state and only take the driver-wide notifier lock in execbuf /
userptr_invalidate. If we in addition use an rwlock as a notifier lock taken in read mode in execbuf, any potential global lock contention can be practically eliminated. But that's perhaps for a future improvement.Quoted 16 lines
Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +4
-0+ +if (mmu_interval_read_retry (&obj->userptr.notifier, + !obj->userptr.page_ref ? notifier_seq : + obj->userptr.notifier_seq)) {drivers/gpu/drm/i915/gem/i915_gem_userptr.c i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj, · line 326
Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +10
-0+ ret = -EAGAIN ; + goto out_unlock; + } + +if (!obj->userptr.page_ref++) { + obj->userptr.pvec = pvec; + obj->userptr.notifier_seq = notifier_seq; + + pvec =NULL ; + }In addition, if we can call
get_pages()here to take thepage_ref, we can eliminate onepage_refand the use of_userptr_submit_fini(). That would of course require the object lock, but we'd already hold that for the object state as above.I guess it could be optimized by not doing this dance..
Perhaps this?
Quoted 7 lines
i915_gem_object_set_pages(pvec, seq)
{i915_gem_object_lock_interruptible();Directly run the
set_pages()function body with pvec and seqno as argument. It will check for collisions, and return-EAGAINif needed, 0 if notifier seqno was already set to same.gem_object_unlock()
}
Yeah, I had something like the attached in mind. I think getting rid of submit_fini() would be helpful moving forward.
/Thomas
From de14ad02b8c5100cc0834711f254dbb15561c60b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= <[email protected]>
Date: Mon, 8 Feb 2021 17:45:41 +0100
Subject: [PATCH] drm/i915: Simplify userptr locking
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Use an rwlock instead of spinlock for the global notifier lock to reduce risk of contention in execbuf.
Protect object state with the object lock whenever possible rather than with the global notifier lock
Don't take an explicit page_ref in userptr_submit_init() but rather call get_pages() after obtaining the page list so that get_pages() holds the page_ref. This means we don't need to call userptr_submit_fini().
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 67 ++++++------------- drivers/gpu/drm/i915/i915_drv.h | 2 +- 3 files changed, 25 insertions(+), 48 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -2
@@ -2261,7 +2261,7 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb)#ifdef CONFIG_MMU_NOTIFIER if (!err && (eb->args->flags & __EXEC_USERPTR_USED)) { -spin_lock (&eb->i915->mm.notifier_lock); +read_lock (&eb->i915->mm.notifier_lock);/* * count is always at least 1, otherwise __EXEC_USERPTR_USED
@@ -2279,7 +2279,7 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) break; } -spin_unlock (&eb->i915->mm.notifier_lock); +read_unlock (&eb->i915->mm.notifier_lock); }#endif
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +22 -45
166 lines not on this page · raw message
drivers/gpu/drm/i915/i915_drv.h +1 -1
@@ -595,7 +595,7 @@ struct i915_gem_mm {* notifier_lock for mmu notifiers, memory may not be allocated * while holding this lock. */ -spinlock_t notifier_lock; +rwlock_t notifier_lock;#endif /* shrinker accounting, also useful for userland debugging */
Signature · 1 line
2.25.1
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 17/69 drm/i915: Flatten obj->mm.lock
In reply to Maarten LankhorstWith userptr fixed, there is no need for all separate lockdep classes now, and we can remove all lockdep tricks used. A trylock in the shrinker is all we need now to flatten the locking hierarchy.
--- drivers/gpu/drm/i915/gem/i915_gem_object.c | 5 +-- drivers/gpu/drm/i915/gem/i915_gem_object.h | 20 ++---------- drivers/gpu/drm/i915/gem/i915_gem_pages.c | 34 ++++++++++---------- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 10 +++--- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 2 +- 6 files changed, 27 insertions(+), 46 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.c +1 -4
@@ -62,7 +62,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,const struct drm_i915_gem_object_ops *ops, struct lock_class_key *key, unsigned flags) { - __mutex_init(&obj->mm.lock, ops->name ?: "obj->mm.lock", key); + mutex_init(&obj->mm.lock);spin_lock_init (&obj->vma.lock);INIT_LIST_HEAD (&obj->vma.list);
@@ -86,9 +86,6 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,mutex_init (&obj->mm.get_page.lock);INIT_RADIX_TREE (&obj->mm.get_dma_page.radix,GFP_KERNEL | __GFP_NOWARN);mutex_init (&obj->mm.get_dma_page.lock); - -if (IS_ENABLED (CONFIG_LOCKDEP ) &&i915_gem_object_is_shrinkable (obj)) -fs_reclaim_taints_mutex (&obj->mm.lock); }/**
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -18
@@ -372,27 +372,10 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,int ____i915_gem_object_get_pages (struct drm_i915_gem_object *obj);int __i915_gem_object_get_pages (struct drm_i915_gem_object *obj); -enum i915_mm_subclass {/* lockdep subclass for obj->mm.lock/struct_mutex */ -I915_MM_NORMAL =0 , -/* -* Only used by struct_mutex, when called "recursively" from -* direct-reclaim-esque. Safe because there is only every one -* struct_mutex in the entire system. -*/ -I915_MM_SHRINKER =1 , -/* -* Used for obj->mm.lock when allocating pages. Safe because the object -* isn't yet on any LRU, and therefore the shrinker can't deadlock on -* it. As soon as the object has pages, obj->mm.lock nests within -* fs_reclaim. -*/ -I915_MM_GET_PAGES =1 , -}; -static inline int __must_check i915_gem_object_pin_pages (struct drm_i915_gem_object *obj) { -might_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); +might_lock (&obj->mm.lock);if (atomic_inc_not_zero (&obj->mm.pages_pin_count))return 0 ;
@@ -436,6 +419,7 @@ i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj) }int __i915_gem_object_put_pages (struct drm_i915_gem_object *obj); +int __i915_gem_object_put_pages_locked (struct drm_i915_gem_object *obj);void i915_gem_object_truncate (struct drm_i915_gem_object *obj);void i915_gem_object_writeback (struct drm_i915_gem_object *obj);
drivers/gpu/drm/i915/gem/i915_gem_pages.c +17 -17
@@ -114,7 +114,7 @@ int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj) {int err; - err =mutex_lock_interruptible_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + err =mutex_lock_interruptible (&obj->mm.lock);if (err)return err;
@@ -196,21 +196,13 @@ __i915_gem_object_unset_pages(struct drm_i915_gem_object *obj)return pages; } -int __i915_gem_object_put_pages (struct drm_i915_gem_object *obj) +int __i915_gem_object_put_pages_locked (struct drm_i915_gem_object *obj) {struct sg_table *pages; -int err;if (i915_gem_object_has_pinned_pages (obj))return -EBUSY ; -/* May be called by shrinker from within get_pages() (on another bo) */ -mutex_lock (&obj->mm.lock); -if (unlikely (atomic_read (&obj->mm.pages_pin_count))) { - err = -EBUSY ; - goto unlock; - } -i915_gem_object_release_mmap_offset (obj);/*
@@ -226,14 +218,22 @@ int __i915_gem_object_put_pages(struct drm_i915_gem_object *obj)* get_pages backends we should be better able to handle the * cancellation of the async task in a more uniform manner. */ -if (!pages) - pages =ERR_PTR (-EINVAL ); - -if (!IS_ERR (pages)) +if (!IS_ERR_OR_NULL (pages)) obj->ops->put_pages (obj, pages); - err =0 ; -unlock: +return 0 ; +} + +int __i915_gem_object_put_pages (struct drm_i915_gem_object *obj) +{ +int err; + +if (i915_gem_object_has_pinned_pages (obj)) +return -EBUSY ; + +/* May be called by shrinker from within get_pages() (on another bo) */ +mutex_lock (&obj->mm.lock); + err =__i915_gem_object_put_pages_locked (obj);mutex_unlock (&obj->mm.lock);return err;
@@ -341,7 +341,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, !i915_gem_object_type_has(obj, I915_GEM_OBJECT_HAS_IOMEM))return ERR_PTR (-ENXIO ); - err =mutex_lock_interruptible_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + err =mutex_lock_interruptible (&obj->mm.lock);if (err)return ERR_PTR (err);
drivers/gpu/drm/i915/gem/i915_gem_phys.c +1 -1
@@ -236,7 +236,7 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)if (err)return err; - err =mutex_lock_interruptible_nested (&obj->mm.lock,I915_MM_GET_PAGES ); + err =mutex_lock_interruptible (&obj->mm.lock);if (err) goto err_unlock;
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +5 -5
@@ -49,9 +49,9 @@ static bool unsafe_drop_pages(struct drm_i915_gem_object *obj, flags =I915_GEM_OBJECT_UNBIND_TEST ;if (i915_gem_object_unbind (obj, flags) ==0 ) -__i915_gem_object_put_pages (obj); +return true; -return !i915_gem_object_has_pages (obj); +return false; } static void try_to_writeback(struct drm_i915_gem_object *obj,
@@ -200,10 +200,10 @@ i915_gem_shrink(struct drm_i915_private *i915,spin_unlock_irqrestore (&i915->mm.obj_lock, flags); -if (unsafe_drop_pages (obj, shrink)) { +if (unsafe_drop_pages (obj, shrink) && +mutex_trylock (&obj->mm.lock)) {/* May arrive from get_pages on another bo */ -mutex_lock (&obj->mm.lock); -if (!i915_gem_object_has_pages (obj)) { +if (!__i915_gem_object_put_pages_locked (obj)) {try_to_writeback (obj, shrink); count += obj->base.size >>PAGE_SHIFT ; }
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -1
@@ -253,7 +253,7 @@ static int i915_gem_object_userptr_unbind(struct drm_i915_gem_object *obj, boolif (GEM_WARN_ON (i915_gem_object_has_pinned_pages (obj)))return -EBUSY ; -mutex_lock_nested (&obj->mm.lock,I915_MM_GET_PAGES ); +mutex_lock (&obj->mm.lock); pages =__i915_gem_object_unset_pages (obj);if (!IS_ERR_OR_NULL (pages))
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 18/69 drm/i915: Populate logical context during first pin.
In reply to Maarten LankhorstThis allows us to remove pin_map from state allocation, which saves us a few retry loops. We won't need this until first pin, anyway.
--- .../drm/i915/gt/intel_execlists_submission.c | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_execlists_submission.c +23 -3
@@ -2206,11 +2206,31 @@ static void execlists_preempt(struct timer_list *timer)execlists_kick (timer, preempt); } +static int +__execlists_context_pre_pin (struct intel_context *ce, +struct intel_engine_cs *engine, +struct i915_gem_ww_ctx *ww,void **vaddr) +{ +int err; + + err =lrc_pre_pin (ce, engine, ww, vaddr); +if (err) +return err; + +if (!__test_and_set_bit (CONTEXT_INIT_BIT , &ce->flags)) { +lrc_init_state (ce, engine, *vaddr); + +__i915_gem_object_flush_map (ce->state->obj,0 , engine->context_size); + } + +return 0 ; +} +static int execlists_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww,void **vaddr) { -return lrc_pre_pin (ce, ce->engine, ww, vaddr); +return __execlists_context_pre_pin (ce, ce->engine, ww, vaddr); }static int execlists_context_pin (struct intel_context *ce,void *vaddr)
@@ -3088,8 +3108,8 @@ static int virtual_context_pre_pin(struct intel_context *ce, {struct virtual_engine *ve =container_of (ce,typeof (*ve), context); -/* Note: we must use a real engine class for setting up reg state */ -return lrc_pre_pin (ce, ve->siblings[0 ], ww, vaddr); +/* Note: we must use a real engine class for setting up reg state */ +return __execlists_context_pre_pin (ce, ve->siblings[0 ], ww, vaddr); }static int virtual_context_pin (struct intel_context *ce,void *vaddr)
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 19/69 drm/i915: Make ring submission compatible with obj->mm.lock removal, v2.
In reply to Maarten LankhorstWe map the initial context during first pin.
This allows us to remove pin_map from state allocation, which saves us a few retry loops. We won't need this until first pin anyway.
intel_ring_submission_setup() is also reworked slightly to do all pinning in a single ww loop.
Changes since v1:
- Handle -EDEADLK backoff in intel_ring_submission_setup() better.
- Handle smatch errors reported by Dan and testbot.
--- .../gpu/drm/i915/gt/intel_ring_submission.c | 184 +++++++++++------- 1 file changed, 118 insertions(+), 66 deletions(-)
drivers/gpu/drm/i915/gt/intel_ring_submission.c +118 -66
@@ -436,6 +436,26 @@ static void ring_context_destroy(struct kref *ref)intel_context_free (ce); } +static int ring_context_init_default_state (struct intel_context *ce, +struct i915_gem_ww_ctx *ww) +{ +struct drm_i915_gem_object *obj = ce->state->obj; +void *vaddr; + + vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + +shmem_read (ce->engine->default_state,0 , + vaddr, ce->engine->context_size); + +i915_gem_object_flush_map (obj); +__i915_gem_object_release_map (obj); + +__set_bit (CONTEXT_VALID_BIT , &ce->flags); +return 0 ; +} +static int ring_context_pre_pin (struct intel_context *ce,struct i915_gem_ww_ctx *ww,void **unused)
@@ -443,6 +463,13 @@ static int ring_context_pre_pin(struct intel_context *ce,struct i915_address_space *vm;int err =0 ; +if (ce->engine->default_state && + !test_bit (CONTEXT_VALID_BIT , &ce->flags)) { + err =ring_context_init_default_state (ce, ww); +if (err) +return err; + } + vm =vm_alias (ce->vm);if (vm) err =gen6_ppgtt_pin (i915_vm_to_ppgtt ((vm)), ww);
@@ -498,22 +525,6 @@ alloc_context_vma(struct intel_engine_cs *engine)if (IS_IVYBRIDGE (i915))i915_gem_object_set_cache_coherency (obj,I915_CACHE_L3_LLC ); -if (engine->default_state) { -void *vaddr; - - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); -if (IS_ERR (vaddr)) { - err =PTR_ERR (vaddr); - goto err_obj; - } - -shmem_read (engine->default_state,0 , - vaddr, engine->context_size); - -i915_gem_object_flush_map (obj); -__i915_gem_object_release_map (obj); - } - vma =i915_vma_instance (obj, &engine->gt->ggtt->vm,NULL );if (IS_ERR (vma)) { err =PTR_ERR (vma);
@@ -545,8 +556,6 @@ static int ring_context_alloc(struct intel_context *ce)return PTR_ERR (vma); ce->state = vma; -if (engine->default_state) -__set_bit (CONTEXT_VALID_BIT , &ce->flags); }return 0 ;
@@ -1151,37 +1160,15 @@ static int gen7_ctx_switch_bb_setup(struct intel_engine_cs * const engine,return gen7_setup_clear_gpr_bb (engine, vma); } -static int gen7_ctx_switch_bb_init (struct intel_engine_cs *engine) +static int gen7_ctx_switch_bb_init (struct intel_engine_cs *engine, +struct i915_gem_ww_ctx *ww, +struct i915_vma *vma) { -struct drm_i915_gem_object *obj; -struct i915_vma *vma; -int size;int err; - size =gen7_ctx_switch_bb_setup (engine,NULL /* probe size */ ); -if (size <=0 ) -return size; - - size =ALIGN (size,PAGE_SIZE ); - obj =i915_gem_object_create_internal (engine->i915, size); -if (IS_ERR (obj)) -return PTR_ERR (obj); - - vma =i915_vma_instance (obj, engine->gt->vm,NULL ); -if (IS_ERR (vma)) { - err =PTR_ERR (vma); - goto err_obj; - } - - vma->private =intel_context_create (engine);/* dummy residuals */ -if (IS_ERR (vma->private)) { - err =PTR_ERR (vma->private); - goto err_obj; - } - - err =i915_vma_pin (vma,0 ,0 ,PIN_USER |PIN_HIGH ); + err =i915_vma_pin_ww (vma, ww,0 ,0 ,PIN_USER |PIN_HIGH );if (err) - goto err_private; +return err; err =i915_vma_sync (vma);if (err)
@@ -1196,17 +1183,53 @@ static int gen7_ctx_switch_bb_init(struct intel_engine_cs *engine) err_unpin:i915_vma_unpin (vma); -err_private: -intel_context_put (vma->private); -err_obj: -i915_gem_object_put (obj);return err; } +static struct i915_vma *gen7_ctx_vma (struct intel_engine_cs *engine) +{ +struct drm_i915_gem_object *obj; +struct i915_vma *vma; +int size, err; + +if (!IS_GEN (engine->i915,7 ) || engine->class !=RENDER_CLASS ) +return 0 ; + + err =gen7_ctx_switch_bb_setup (engine,NULL /* probe size */ ); +if (err <0 ) +return ERR_PTR (err); +if (!err) +return NULL ; + + size =ALIGN (err,PAGE_SIZE ); + + obj =i915_gem_object_create_internal (engine->i915, size); +if (IS_ERR (obj)) +return ERR_CAST (obj); + + vma =i915_vma_instance (obj, engine->gt->vm,NULL ); +if (IS_ERR (vma)) { +i915_gem_object_put (obj); +return ERR_CAST (vma); + } + + vma->private =intel_context_create (engine);/* dummy residuals */ +if (IS_ERR (vma->private)) { + err =PTR_ERR (vma->private); + vma->private =NULL ; +i915_gem_object_put (obj); +return ERR_PTR (err); + } + +return vma; +} +int intel_ring_submission_setup (struct intel_engine_cs *engine) { +struct i915_gem_ww_ctx ww;struct intel_timeline *timeline;struct intel_ring *ring; +struct i915_vma *gen7_wa_vma;int err;setup_common (engine);
@@ -1237,43 +1260,72 @@ int intel_ring_submission_setup(struct intel_engine_cs *engine) }GEM_BUG_ON (timeline->has_initial_breadcrumb); - err =intel_timeline_pin (timeline,NULL ); -if (err) - goto err_timeline; - ring =intel_engine_create_ring (engine,SZ_16K );if (IS_ERR (ring)) { err =PTR_ERR (ring); - goto err_timeline_unpin; + goto err_timeline; } - err =intel_ring_pin (ring,NULL ); -if (err) - goto err_ring; -GEM_BUG_ON (engine->legacy.ring); engine->legacy.ring = ring; engine->legacy.timeline = timeline; -GEM_BUG_ON (timeline->hwsp_ggtt != engine->status_page.vma); + gen7_wa_vma =gen7_ctx_vma (engine); +if (IS_ERR (gen7_wa_vma)) { + err =PTR_ERR (gen7_wa_vma); + goto err_ring; + } -if (IS_GEN (engine->i915,7 ) && engine->class ==RENDER_CLASS ) { - err =gen7_ctx_switch_bb_init (engine); +i915_gem_ww_ctx_init (&ww, false); + +retry: + 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) + err =i915_gem_object_lock (engine->legacy.ring->vma->obj, &ww); +if (!err) + err =intel_timeline_pin (timeline, &ww); +if (!err) { + err =intel_ring_pin (ring, &ww);if (err) - goto err_ring_unpin; +intel_timeline_unpin (timeline); + } +if (err) + goto out; + +GEM_BUG_ON (timeline->hwsp_ggtt != engine->status_page.vma); + +if (gen7_wa_vma) { + err =gen7_ctx_switch_bb_init (engine, &ww, gen7_wa_vma); +if (err) { +intel_ring_unpin (ring); +intel_timeline_unpin (timeline); + } } +out: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +if (err) + goto err_gen7_put; +/* Finally, take ownership and responsibility for cleanup! */ engine->release = ring_release;return 0 ; -err_ring_unpin: -intel_ring_unpin (ring); +err_gen7_put: +if (gen7_wa_vma) { +intel_context_put (gen7_wa_vma->private); +i915_gem_object_put (gen7_wa_vma->obj); + } err_ring:intel_ring_put (ring); -err_timeline_unpin: -intel_timeline_unpin (timeline); err_timeline:intel_timeline_put (timeline); err:
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 20/69 drm/i915: Handle ww locking in init_status_page
In reply to Maarten LankhorstTry to pin to ggtt first, and use a full ww loop to handle eviction correctly.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 37 +++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +24 -13
@@ -602,6 +602,7 @@ static void cleanup_status_page(struct intel_engine_cs *engine) }static int pin_ggtt_status_page (struct intel_engine_cs *engine, +struct i915_gem_ww_ctx *ww,struct i915_vma *vma) {unsigned int flags;
@@ -622,12 +623,13 @@ static int pin_ggtt_status_page(struct intel_engine_cs *engine,else flags =PIN_HIGH ; -return i915_ggtt_pin (vma,NULL ,0 , flags); +return i915_ggtt_pin (vma, ww,0 , flags); }static int init_status_page (struct intel_engine_cs *engine) {struct drm_i915_gem_object *obj; +struct i915_gem_ww_ctx ww;struct i915_vma *vma;void *vaddr;int ret;
@@ -653,30 +655,39 @@ static int init_status_page(struct intel_engine_cs *engine) vma =i915_vma_instance (obj, &engine->gt->ggtt->vm,NULL );if (IS_ERR (vma)) { ret =PTR_ERR (vma); - goto err; + goto err_put; } +i915_gem_ww_ctx_init (&ww, true); +retry: + ret =i915_gem_object_lock (obj, &ww); +if (!ret && !HWS_NEEDS_PHYSICAL (engine->i915)) + ret =pin_ggtt_status_page (engine, &ww, vma); +if (ret) + goto err; + vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB );if (IS_ERR (vaddr)) { ret =PTR_ERR (vaddr); - goto err; + goto err_unpin; } engine->status_page.addr =memset (vaddr,0 ,PAGE_SIZE ); engine->status_page.vma = vma; -if (!HWS_NEEDS_PHYSICAL (engine->i915)) { - ret =pin_ggtt_status_page (engine, vma); -if (ret) - goto err_unpin; - } - -return 0 ; - err_unpin: -i915_gem_object_unpin_map (obj); +if (ret) +i915_vma_unpin (vma); err: -i915_gem_object_put (obj); +if (ret == -EDEADLK ) { + ret =i915_gem_ww_ctx_backoff (&ww); +if (!ret) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +err_put: +if (ret) +i915_gem_object_put (obj);return ret; }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 21/69 drm/i915: Rework clflush to work correctly without obj->mm.lock.
In reply to Maarten LankhorstPin in the caller, not in the work itself. This should also work better for dma-fence annotations.
--- drivers/gpu/drm/i915/gem/i915_gem_clflush.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_clflush.c +7 -8
@@ -27,15 +27,8 @@ static void __do_clflush(struct drm_i915_gem_object *obj)static int clflush_work (struct dma_fence_work *base) {struct clflush *clflush =container_of (base,typeof (*clflush), base); -struct drm_i915_gem_object *obj = clflush->obj; -int err; - err =i915_gem_object_pin_pages (obj); -if (err) -return err; - -__do_clflush (obj); -i915_gem_object_unpin_pages (obj); +__do_clflush (clflush->obj);return 0 ; }
@@ -44,6 +37,7 @@ static void clflush_release(struct dma_fence_work *base) {struct clflush *clflush =container_of (base,typeof (*clflush), base); +i915_gem_object_unpin_pages (clflush->obj);i915_gem_object_put (clflush->obj); }
@@ -61,6 +55,11 @@ static struct clflush *clflush_work_create(struct drm_i915_gem_object *obj)if (!clflush)return NULL ; +if (__i915_gem_object_get_pages (obj) <0 ) { +kfree (clflush); +return NULL ; + } +dma_fence_work_init (&clflush->base, &clflush_ops); clflush->obj =i915_gem_object_get (obj);/* obj <-> clflush cycle */
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 22/69 drm/i915: Pass ww ctx to intel_pin_to_display_plane
In reply to Maarten LankhorstInstead of multiple lockings, lock the object once, and perform the ww dance around attach_phys and pin_pages.
--- drivers/gpu/drm/i915/display/intel_display.c | 69 ++++++++++++------- drivers/gpu/drm/i915/display/intel_display.h | 2 +- drivers/gpu/drm/i915/display/intel_fbdev.c | 2 +- drivers/gpu/drm/i915/display/intel_overlay.c | 34 +++++++-- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 30 ++------ drivers/gpu/drm/i915/gem/i915_gem_object.h | 1 + drivers/gpu/drm/i915/gem/i915_gem_phys.c | 10 +-- .../drm/i915/gem/selftests/i915_gem_phys.c | 2 + 8 files changed, 86 insertions(+), 64 deletions(-)
drivers/gpu/drm/i915/display/intel_display.c +43 -26
@@ -1091,6 +1091,7 @@ static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)struct i915_vma *intel_pin_and_fence_fb_obj (struct drm_framebuffer *fb, +bool phys_cursor,const struct i915_ggtt_view *view,bool uses_fence,unsigned long *out_flags)
@@ -1099,14 +1100,19 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,struct drm_i915_private *dev_priv =to_i915 (dev);struct drm_i915_gem_object *obj =intel_fb_obj (fb);intel_wakeref_t wakeref; +struct i915_gem_ww_ctx ww;struct i915_vma *vma;unsigned int pinctl;u32 alignment; +int ret;if (drm_WARN_ON (dev, !i915_gem_object_is_framebuffer (obj)))return ERR_PTR (-EINVAL ); - alignment =intel_surf_alignment (fb,0 ); +if (phys_cursor) + alignment =intel_cursor_alignment (dev_priv); +else + alignment =intel_surf_alignment (fb,0 );if (drm_WARN_ON (dev, alignment && !is_power_of_2 (alignment)))return ERR_PTR (-EINVAL );
@@ -1141,14 +1147,26 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,if (HAS_GMCH (dev_priv)) pinctl |=PIN_MAPPABLE ; - vma =i915_gem_object_pin_to_display_plane (obj, - alignment, view, pinctl); -if (IS_ERR (vma)) +i915_gem_ww_ctx_init (&ww, true); +retry: + ret =i915_gem_object_lock (obj, &ww); +if (!ret && phys_cursor) + ret =i915_gem_object_attach_phys (obj, alignment); +if (!ret) + ret =i915_gem_object_pin_pages (obj); +if (ret) goto err; -if (uses_fence &&i915_vma_is_map_and_fenceable (vma)) { -int ret; +if (!ret) { + vma =i915_gem_object_pin_to_display_plane (obj, &ww, alignment, + view, pinctl); +if (IS_ERR (vma)) { + ret =PTR_ERR (vma); + goto err_unpin; + } + } +if (uses_fence &&i915_vma_is_map_and_fenceable (vma)) {/* * Install a fence for tiled scan-out. Pre-i965 always needs a * fence, whereas 965+ only requires a fence if using
@@ -1169,16 +1187,28 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, ret =i915_vma_pin_fence (vma);if (ret !=0 &&INTEL_GEN (dev_priv) <4 ) {i915_vma_unpin (vma); - vma =ERR_PTR (ret); - goto err; + goto err_unpin; } + ret =0 ; -if (ret ==0 && vma->fence) +if (vma->fence) *out_flags |=PLANE_HAS_FENCE ; }i915_vma_get (vma); + +err_unpin: +i915_gem_object_unpin_pages (obj); err: +if (ret == -EDEADLK ) { + ret =i915_gem_ww_ctx_backoff (&ww); +if (!ret) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +if (ret) + vma =ERR_PTR (ret); +atomic_dec (&dev_priv->gpu_error.pending_fb_pin);intel_runtime_pm_put (&dev_priv->runtime_pm, wakeref);return vma;
@@ -11333,19 +11363,11 @@ int intel_plane_pin_fb(struct intel_plane_state *plane_state)struct drm_i915_private *dev_priv =to_i915 (plane->base.dev);struct drm_framebuffer *fb = plane_state->hw.fb;struct i915_vma *vma; +bool phys_cursor = + plane->id ==PLANE_CURSOR && +INTEL_INFO (dev_priv)->display.cursor_needs_physical; -if (plane->id ==PLANE_CURSOR && -INTEL_INFO (dev_priv)->display.cursor_needs_physical) { -struct drm_i915_gem_object *obj =intel_fb_obj (fb); -const int align =intel_cursor_alignment (dev_priv); -int err; - - err =i915_gem_object_attach_phys (obj, align); -if (err) -return err; - } - - vma =intel_pin_and_fence_fb_obj (fb, + vma =intel_pin_and_fence_fb_obj (fb, phys_cursor, &plane_state->view,intel_plane_uses_fence (plane_state), &plane_state->flags);
@@ -11434,13 +11456,8 @@ intel_prepare_plane_fb(struct drm_plane *_plane,if (!obj)return 0 ; - ret =i915_gem_object_pin_pages (obj); -if (ret) -return ret; ret =intel_plane_pin_fb (new_plane_state); - -i915_gem_object_unpin_pages (obj);if (ret)return ret;
drivers/gpu/drm/i915/display/intel_display.h +1 -1
@@ -573,7 +573,7 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,struct intel_load_detect_pipe *old, struct drm_modeset_acquire_ctx *ctx);struct i915_vma * -intel_pin_and_fence_fb_obj (struct drm_framebuffer *fb, +intel_pin_and_fence_fb_obj (struct drm_framebuffer *fb,bool phys_cursor,const struct i915_ggtt_view *view,bool uses_fence,unsigned long *out_flags);
drivers/gpu/drm/i915/display/intel_fbdev.c +1 -1
@@ -211,7 +211,7 @@ static int intelfb_create(struct drm_fb_helper *helper,* This also validates that any existing fb inherited from the * BIOS is suitable for own access. */ - vma =intel_pin_and_fence_fb_obj (&ifbdev->fb->base, + vma =intel_pin_and_fence_fb_obj (&ifbdev->fb->base, false, &view, false, &flags);if (IS_ERR (vma)) { ret =PTR_ERR (vma);
drivers/gpu/drm/i915/display/intel_overlay.c +29 -5
@@ -755,6 +755,32 @@ static u32 overlay_cmd_reg(struct drm_intel_overlay_put_image *params)return cmd; } +static struct i915_vma *intel_overlay_pin_fb (struct drm_i915_gem_object *new_bo) +{ +struct i915_gem_ww_ctx ww; +struct i915_vma *vma; +int ret; + +i915_gem_ww_ctx_init (&ww, true); +retry: + ret =i915_gem_object_lock (new_bo, &ww); +if (!ret) { + vma =i915_gem_object_pin_to_display_plane (new_bo, &ww,0 , +NULL ,PIN_MAPPABLE ); + ret =PTR_ERR_OR_ZERO (vma); + } +if (ret == -EDEADLK ) { + ret =i915_gem_ww_ctx_backoff (&ww); +if (!ret) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +if (ret) +return ERR_PTR (ret); + +return vma; +} +static int intel_overlay_do_put_image (struct intel_overlay *overlay,struct drm_i915_gem_object *new_bo,struct drm_intel_overlay_put_image *params)
@@ -776,12 +802,10 @@ static int intel_overlay_do_put_image(struct intel_overlay *overlay,atomic_inc (&dev_priv->gpu_error.pending_fb_pin); - vma =i915_gem_object_pin_to_display_plane (new_bo, -0 ,NULL ,PIN_MAPPABLE ); -if (IS_ERR (vma)) { - ret =PTR_ERR (vma); + vma =intel_overlay_pin_fb (new_bo); +if (IS_ERR (vma)) goto out_pin_section; - } +i915_gem_object_flush_frontbuffer (new_bo,ORIGIN_DIRTYFB );if (!overlay->active) {
drivers/gpu/drm/i915/gem/i915_gem_domain.c +6 -24
@@ -318,12 +318,12 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,*/ struct i915_vma *i915_gem_object_pin_to_display_plane (struct drm_i915_gem_object *obj, +struct i915_gem_ww_ctx *ww,u32 alignment,const struct i915_ggtt_view *view,unsigned int flags) {struct drm_i915_private *i915 =to_i915 (obj->base.dev); -struct i915_gem_ww_ctx ww;struct i915_vma *vma;int ret;
@@ -331,11 +331,6 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,if (HAS_LMEM (i915) && !i915_gem_object_is_lmem (obj))return ERR_PTR (-EINVAL ); -i915_gem_ww_ctx_init (&ww, true); -retry: - ret =i915_gem_object_lock (obj, &ww); -if (ret) - goto err;/* * The display engine is not coherent with the LLC cache on gen6. As * a result, we make sure that the pinning that is about to occur is
@@ -350,7 +345,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,HAS_WT (i915) ? I915_CACHE_WT : I915_CACHE_NONE);if (ret) - goto err; +return ERR_PTR (ret);/* * As the user may map the buffer once pinned in the display plane
@@ -363,33 +358,20 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, vma =ERR_PTR (-ENOSPC );if ((flags &PIN_MAPPABLE ) ==0 && (!view || view->type ==I915_GGTT_VIEW_NORMAL )) - vma =i915_gem_object_ggtt_pin_ww (obj, &ww, view,0 , alignment, + vma =i915_gem_object_ggtt_pin_ww (obj, ww, view,0 , alignment, flags |PIN_MAPPABLE |PIN_NONBLOCK );if (IS_ERR (vma) && vma !=ERR_PTR (-EDEADLK )) - vma =i915_gem_object_ggtt_pin_ww (obj, &ww, view,0 , + vma =i915_gem_object_ggtt_pin_ww (obj, ww, view,0 , alignment, flags); -if (IS_ERR (vma)) { - ret =PTR_ERR (vma); - goto err; - } +if (IS_ERR (vma)) +return vma; vma->display_alignment =max_t (u64, vma->display_alignment, alignment);i915_vma_mark_scanout (vma);i915_gem_object_flush_if_display_locked (obj); -err: -if (ret == -EDEADLK ) { - ret =i915_gem_ww_ctx_backoff (&ww); -if (!ret) - goto retry; - } -i915_gem_ww_ctx_fini (&ww); - -if (ret) -return ERR_PTR (ret); -return vma; }
drivers/gpu/drm/i915/gem/i915_gem_object.h +1 -0
@@ -510,6 +510,7 @@ void i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);struct i915_vma *__must_check i915_gem_object_pin_to_display_plane (struct drm_i915_gem_object *obj, +struct i915_gem_ww_ctx *ww,u32 alignment,const struct i915_ggtt_view *view,unsigned int flags);
drivers/gpu/drm/i915/gem/i915_gem_phys.c +3 -7
@@ -219,6 +219,8 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) {int err; +assert_object_held (obj); +if (align > obj->base.size)return -EINVAL ;
@@ -232,13 +234,9 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)if (err)return err; - err =i915_gem_object_lock_interruptible (obj,NULL ); -if (err) -return err; - err =mutex_lock_interruptible (&obj->mm.lock);if (err) - goto err_unlock; +return err;if (unlikely (!i915_gem_object_has_struct_page (obj))) goto out;
@@ -269,8 +267,6 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) out:mutex_unlock (&obj->mm.lock); -err_unlock: -i915_gem_object_unlock (obj);return err; }
drivers/gpu/drm/i915/gem/selftests/i915_gem_phys.c +2 -0
@@ -31,7 +31,9 @@ static int mock_phys_object(void *arg) goto out_obj; } +i915_gem_object_lock (obj,NULL ); err =i915_gem_object_attach_phys (obj,PAGE_SIZE ); +i915_gem_object_unlock (obj);if (err) {pr_err ("i915_gem_object_attach_phys failed, err=%d\n" , err); goto out_obj;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 23/69 drm/i915: Add object locking to vm_fault_cpu
In reply to Maarten LankhorstTake a simple lock so we hold ww around (un)pin_pages as needed.
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +4 -0
@@ -246,6 +246,9 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf) area->vm_flags & VM_WRITE))return VM_FAULT_SIGBUS ; +if (i915_gem_object_lock_interruptible (obj,NULL )) +return VM_FAULT_NOPAGE ; + err =i915_gem_object_pin_pages (obj);if (err) goto out;
@@ -269,6 +272,7 @@ static vm_fault_t vm_fault_cpu(struct vm_fault *vmf)i915_gem_object_unpin_pages (obj); out: +i915_gem_object_unlock (obj);return i915_error_to_vmf_fault (err); }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 24/69 drm/i915: Move pinning to inside engine_wa_list_verify()
In reply to Maarten LankhorstThis should be done as part of the ww loop, in order to remove a i915_vma_pin that needs ww held.
Now only i915_ggtt_pin() callers remaining.
--- drivers/gpu/drm/i915/gt/intel_gtt.c | 14 +++++++++++++- drivers/gpu/drm/i915/gt/intel_gtt.h | 3 +++ drivers/gpu/drm/i915/gt/intel_workarounds.c | 10 ++++++++-- drivers/gpu/drm/i915/gt/selftest_execlists.c | 5 +++-- drivers/gpu/drm/i915/gt/selftest_lrc.c | 2 +- drivers/gpu/drm/i915/gt/selftest_mocs.c | 3 ++- drivers/gpu/drm/i915/gt/selftest_workarounds.c | 6 +++--- 7 files changed, 33 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/intel_gtt.c +13 -1
@@ -427,7 +427,6 @@ __vm_create_scratch_for_read(struct i915_address_space *vm, unsigned long size) {struct drm_i915_gem_object *obj;struct i915_vma *vma; -int err; obj =i915_gem_object_create_internal (vm->i915,PAGE_ALIGN (size));if (IS_ERR (obj))
@@ -441,6 +440,19 @@ __vm_create_scratch_for_read(struct i915_address_space *vm, unsigned long size)return vma; } +return vma; +} + +struct i915_vma * +__vm_create_scratch_for_read_pinned (struct i915_address_space *vm,unsigned long size) +{ +struct i915_vma *vma; +int err; + + vma =__vm_create_scratch_for_read (vm, size); +if (IS_ERR (vma)) +return vma; + err =i915_vma_pin (vma,0 ,0 ,i915_vma_is_ggtt (vma) ?PIN_GLOBAL :PIN_USER );if (err) {
drivers/gpu/drm/i915/gt/intel_gtt.h +3 -0
@@ -581,6 +581,9 @@ void i915_vm_free_pt_stash(struct i915_address_space *vm,struct i915_vma *__vm_create_scratch_for_read (struct i915_address_space *vm,unsigned long size); +struct i915_vma * +__vm_create_scratch_for_read_pinned (struct i915_address_space *vm,unsigned long size); + static inline struct sgt_dma { struct scatterlist *sg; dma_addr_t dma, max;
drivers/gpu/drm/i915/gt/intel_workarounds.c +8 -2
@@ -2211,10 +2211,15 @@ static int engine_wa_list_verify(struct intel_context *ce,if (err) goto err_pm; + err =i915_vma_pin_ww (vma, &ww,0 ,0 , +i915_vma_is_ggtt (vma) ?PIN_GLOBAL :PIN_USER ); +if (err) + goto err_unpin; + rq =i915_request_create (ce);if (IS_ERR (rq)) { err =PTR_ERR (rq); - goto err_unpin; + goto err_vma; } err =i915_request_await_object (rq, vma->obj, true);
@@ -2255,6 +2260,8 @@ static int engine_wa_list_verify(struct intel_context *ce, err_rq:i915_request_put (rq); +err_vma: +i915_vma_unpin (vma); err_unpin:intel_context_unpin (ce); err_pm:
@@ -2265,7 +2272,6 @@ static int engine_wa_list_verify(struct intel_context *ce, }i915_gem_ww_ctx_fini (&ww);intel_engine_pm_put (ce->engine); -i915_vma_unpin (vma);i915_vma_put (vma);return err; }
drivers/gpu/drm/i915/gt/selftest_execlists.c +3 -2
@@ -4165,8 +4165,9 @@ static int preserved_virtual_engine(struct intel_gt *gt,int err =0 ;u32 *cs; - scratch =__vm_create_scratch_for_read (&siblings[0 ]->gt->ggtt->vm, -PAGE_SIZE ); + scratch = +__vm_create_scratch_for_read_pinned (&siblings[0 ]->gt->ggtt->vm, +PAGE_SIZE );if (IS_ERR (scratch))return PTR_ERR (scratch);
drivers/gpu/drm/i915/gt/selftest_lrc.c +1 -1
@@ -27,7 +27,7 @@static struct i915_vma *create_scratch (struct intel_gt *gt) { -return __vm_create_scratch_for_read (>->ggtt->vm,PAGE_SIZE ); +return __vm_create_scratch_for_read_pinned (>->ggtt->vm,PAGE_SIZE ); }static bool is_active (struct i915_request *rq)
drivers/gpu/drm/i915/gt/selftest_mocs.c +2 -1
@@ -74,7 +74,8 @@ static int live_mocs_init(struct live_mocs *arg, struct intel_gt *gt)if (flags & (HAS_GLOBAL_MOCS |HAS_ENGINE_MOCS )) arg->mocs = &arg->table; - arg->scratch =__vm_create_scratch_for_read (>->ggtt->vm,PAGE_SIZE ); + arg->scratch = +__vm_create_scratch_for_read_pinned (>->ggtt->vm,PAGE_SIZE );if (IS_ERR (arg->scratch))return PTR_ERR (arg->scratch);
drivers/gpu/drm/i915/gt/selftest_workarounds.c +3 -3
@@ -463,7 +463,7 @@ static int check_dirty_whitelist(struct intel_context *ce)u32 *cs, *results; sz = (2 *ARRAY_SIZE (values) +1 ) *sizeof (u32); - scratch =__vm_create_scratch_for_read (ce->vm, sz); + scratch =__vm_create_scratch_for_read_pinned (ce->vm, sz);if (IS_ERR (scratch))return PTR_ERR (scratch);
@@ -1003,14 +1003,14 @@ static int live_isolated_whitelist(void *arg)for (i =0 ; i <ARRAY_SIZE (client); i++) { client[i].scratch[0 ] = -__vm_create_scratch_for_read (gt->vm,4096 ); +__vm_create_scratch_for_read_pinned (gt->vm,4096 );if (IS_ERR (client[i].scratch[0 ])) { err =PTR_ERR (client[i].scratch[0 ]); goto err; } client[i].scratch[1 ] = -__vm_create_scratch_for_read (gt->vm,4096 ); +__vm_create_scratch_for_read_pinned (gt->vm,4096 );if (IS_ERR (client[i].scratch[1 ])) { err =PTR_ERR (client[i].scratch[1 ]);i915_vma_unpin_and_release (&client[i].scratch[0 ],0 );
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 25/69 drm/i915: Take reservation lock around i915_vma_pin.
In reply to Maarten LankhorstWe previously complained when ww == NULL.
This function is now only used in selftests to pin an object, and ww locking is now fixed.
--- .../i915/gem/selftests/i915_gem_coherency.c | 12 ++++------- drivers/gpu/drm/i915/i915_gem.c | 6 +++++- drivers/gpu/drm/i915/i915_vma.c | 4 +--- drivers/gpu/drm/i915/i915_vma.h | 20 +++++++++++++++---- 4 files changed, 26 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +4 -8
@@ -218,15 +218,13 @@ static int gpu_set(struct context *ctx, unsigned long offset, u32 v)u32 *cs;int err; + vma =i915_gem_object_ggtt_pin (ctx->obj,NULL ,0 ,0 ,0 ); +if (IS_ERR (vma)) +return PTR_ERR (vma); +i915_gem_object_lock (ctx->obj,NULL );i915_gem_object_set_to_gtt_domain (ctx->obj, false); - vma =i915_gem_object_ggtt_pin (ctx->obj,NULL ,0 ,0 ,0 ); -if (IS_ERR (vma)) { - err =PTR_ERR (vma); - goto out_unlock; - } - rq =intel_engine_create_kernel_request (ctx->engine);if (IS_ERR (rq)) { err =PTR_ERR (rq);
@@ -265,9 +263,7 @@ static int gpu_set(struct context *ctx, unsigned long offset, u32 v)i915_request_add (rq); out_unpin:i915_vma_unpin (vma); -out_unlock:i915_gem_object_unlock (ctx->obj); -return err; }
drivers/gpu/drm/i915/i915_gem.c +5 -1
@@ -906,7 +906,11 @@ i915_gem_object_ggtt_pin_ww(struct drm_i915_gem_object *obj,return ERR_PTR (ret); } - ret =i915_vma_pin_ww (vma, ww, size, alignment, flags |PIN_GLOBAL ); +if (ww) + ret =i915_vma_pin_ww (vma, ww, size, alignment, flags |PIN_GLOBAL ); +else + ret =i915_vma_pin (vma, size, alignment, flags |PIN_GLOBAL ); +if (ret)return ERR_PTR (ret);
drivers/gpu/drm/i915/i915_vma.c +1 -3
@@ -863,9 +863,7 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,int err;#ifdef CONFIG_PROVE_LOCKING -if (debug_locks &&lockdep_is_held (&vma->vm->i915->drm.struct_mutex)) -WARN_ON (!ww); -if (debug_locks && ww && vma->resv) +if (debug_locks && !WARN_ON (!ww) && vma->resv)assert_vma_held (vma);#endif
drivers/gpu/drm/i915/i915_vma.h +16 -4
@@ -246,10 +246,22 @@ i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,static inline int __must_check i915_vma_pin (struct i915_vma *vma,u64 size,u64 alignment,u64 flags) { -#ifdef CONFIG_LOCKDEP -WARN_ON_ONCE (vma->resv &&dma_resv_held (vma->resv)); -#endif -return i915_vma_pin_ww (vma,NULL , size, alignment, flags); +struct i915_gem_ww_ctx ww; +int err; + +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (vma->obj, &ww); +if (!err) + err =i915_vma_pin_ww (vma, &ww, size, alignment, flags); +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); + +return err; } int i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 26/69 drm/i915: Make lrc_init_wa_ctx compatible with ww locking, v3.
In reply to Maarten LankhorstMake creation separate from pinning, in order to take the lock only once, and pin the mapping with the lock held.
Changes since v1:
- Rebase on top of upstream changes.
Changes since v2:
- Fully clear wa_ctx on error.
--- drivers/gpu/drm/i915/gt/intel_lrc.c | 49 ++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/gt/intel_lrc.c +38 -11
@@ -1421,7 +1421,7 @@ gen10_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)#define CTX_WA_BB_SIZE (PAGE_SIZE) -static int lrc_setup_wa_ctx (struct intel_engine_cs *engine) +static int lrc_create_wa_ctx (struct intel_engine_cs *engine) {struct drm_i915_gem_object *obj;struct i915_vma *vma;
@@ -1437,10 +1437,6 @@ static int lrc_setup_wa_ctx(struct intel_engine_cs *engine) goto err; } - err =i915_ggtt_pin (vma,NULL ,0 ,PIN_HIGH ); -if (err) - goto err; - engine->wa_ctx.vma = vma;return 0 ;
@@ -1452,9 +1448,6 @@ static int lrc_setup_wa_ctx(struct intel_engine_cs *engine)void lrc_fini_wa_ctx (struct intel_engine_cs *engine) {i915_vma_unpin_and_release (&engine->wa_ctx.vma,0 ); - -/* Called on error unwind, clear all flags to prevent further use */ -memset (&engine->wa_ctx,0 ,sizeof (engine->wa_ctx)); }typedef u32 *(*wa_bb_func_t )(struct intel_engine_cs *engine,u32 *batch);
@@ -1466,6 +1459,7 @@ void lrc_init_wa_ctx(struct intel_engine_cs *engine) &wa_ctx->indirect_ctx, &wa_ctx->per_ctx };wa_bb_func_t wa_bb_fn[ARRAY_SIZE (wa_bb)]; +struct i915_gem_ww_ctx ww;void *batch, *batch_ptr;unsigned int i;int err;
@@ -1494,7 +1488,7 @@ void lrc_init_wa_ctx(struct intel_engine_cs *engine)return ; } - err =lrc_setup_wa_ctx (engine); + err =lrc_create_wa_ctx (engine);if (err) {/* * We continue even if we fail to initialize WA batch
@@ -1507,7 +1501,22 @@ void lrc_init_wa_ctx(struct intel_engine_cs *engine)return ; } +if (!engine->wa_ctx.vma) +return ; + +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (wa_ctx->vma->obj, &ww); +if (!err) + err =i915_ggtt_pin (wa_ctx->vma, &ww,0 ,PIN_HIGH ); +if (err) + goto err; + batch =i915_gem_object_pin_map (wa_ctx->vma->obj,I915_MAP_WB ); +if (IS_ERR (batch)) { + err =PTR_ERR (batch); + goto err_unpin; + }/* * Emit the two workaround batch buffers, recording the offset from the
@@ -1532,8 +1541,26 @@ void lrc_init_wa_ctx(struct intel_engine_cs *engine)__i915_gem_object_release_map (wa_ctx->vma->obj);/* Verify that we can handle failure to setup the wa_ctx */ -if (err ||i915_inject_probe_error (engine->i915, -ENODEV )) -lrc_fini_wa_ctx (engine); +if (!err) + err =i915_inject_probe_error (engine->i915, -ENODEV ); + +err_unpin: +if (err) +i915_vma_unpin (wa_ctx->vma); +err: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); + +if (err) { +i915_vma_put (engine->wa_ctx.vma); + +/* Clear all flags to prevent further use */ +memset (wa_ctx,0 ,sizeof (*wa_ctx)); + } }static void st_runtime_underflow (struct intel_context_stats *stats,s32 dt)
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 27/69 drm/i915: Make __engine_unpark() compatible with ww locking.
In reply to Maarten LankhorstTake the ww lock around engine_unpark. Because of the many many places where rpm is used, I chose the safest option and used a trylock to opportunistically take this lock for __engine_unpark.
--- drivers/gpu/drm/i915/gt/intel_engine_pm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/i915/gt/intel_engine_pm.c +4 -0
@@ -27,12 +27,16 @@ static void dbg_poison_ce(struct intel_context *ce)int type =i915_coherent_map_type (ce->engine->i915);void *map; +if (!i915_gem_object_trylock (obj)) +return ; + map =i915_gem_object_pin_map (obj, type);if (!IS_ERR (map)) {memset (map,CONTEXT_REDZONE , obj->base.size);i915_gem_object_flush_map (obj);i915_gem_object_unpin_map (obj); } +i915_gem_object_unlock (obj); } }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 28/69 drm/i915: Take obj lock around set_domain ioctl
In reply to Maarten LankhorstWe need to lock the object to move it to the correct domain, add the missing lock.
--- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 41 ++++++++++------------ 1 file changed, 19 insertions(+), 22 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_domain.c +19 -22
@@ -456,13 +456,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,* userptr validity */ err =i915_gem_object_userptr_validate (obj); -if (!err) - err =i915_gem_object_wait (obj, -I915_WAIT_INTERRUPTIBLE | -I915_WAIT_PRIORITY | - (write_domain ?I915_WAIT_ALL :0 ), -MAX_SCHEDULE_TIMEOUT ); - goto out; + goto out_wait; }/*
@@ -476,6 +470,10 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, goto out; } + err =i915_gem_object_lock_interruptible (obj,NULL ); +if (err) + goto out; +/* * Flush and acquire obj->pages so that we are coherent through * direct access in memory with previous cached writes through
@@ -487,7 +485,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,*/ err =i915_gem_object_pin_pages (obj);if (err) - goto out; + goto out_unlock;/* * Already in the desired write domain? Nothing for us to do!
@@ -500,10 +498,6 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,* without having to further check the requested write_domain. */ if (READ_ONCE (obj->write_domain) == read_domains) - goto out_wait; - - err =i915_gem_object_lock_interruptible (obj,NULL ); -if (err) goto out_unpin;if (read_domains &I915_GEM_DOMAIN_WC )
@@ -513,19 +507,22 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,else i915_gem_object_set_to_cpu_domain (obj, write_domain); -i915_gem_object_unlock (obj); +out_unpin: +i915_gem_object_unpin_pages (obj); +out_unlock: +i915_gem_object_unlock (obj); out_wait: - err =i915_gem_object_wait (obj, -I915_WAIT_INTERRUPTIBLE | -I915_WAIT_PRIORITY | - (write_domain ?I915_WAIT_ALL :0 ), -MAX_SCHEDULE_TIMEOUT ); -if (write_domain) -i915_gem_object_invalidate_frontbuffer (obj,ORIGIN_CPU ); +if (!err) { + err =i915_gem_object_wait (obj, +I915_WAIT_INTERRUPTIBLE | +I915_WAIT_PRIORITY | + (write_domain ?I915_WAIT_ALL :0 ), +MAX_SCHEDULE_TIMEOUT ); +if (write_domain) +i915_gem_object_invalidate_frontbuffer (obj,ORIGIN_CPU ); + } -out_unpin: -i915_gem_object_unpin_pages (obj); out:i915_gem_object_put (obj);return err;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 29/69 drm/i915: Defer pin calls in buffer pool until first use by caller.
In reply to Maarten LankhorstWe need to take the obj lock to pin pages, so wait until the callers have done so, before making the object unshrinkable.
--- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 + .../gpu/drm/i915/gem/i915_gem_object_blt.c | 6 +++ .../gpu/drm/i915/gt/intel_gt_buffer_pool.c | 47 +++++++++---------- .../gpu/drm/i915/gt/intel_gt_buffer_pool.h | 5 ++ .../drm/i915/gt/intel_gt_buffer_pool_types.h | 1 + 5 files changed, 35 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -0
@@ -1335,6 +1335,7 @@ static int __reloc_gpu_alloc(struct i915_execbuffer *eb, err =PTR_ERR (cmd); goto err_pool; } +intel_gt_buffer_pool_mark_used (pool);memset32 (cmd,0 , pool->obj->base.size /sizeof (u32));
@@ -2630,6 +2631,7 @@ static int eb_parse(struct i915_execbuffer *eb) err =PTR_ERR (shadow); goto err; } +intel_gt_buffer_pool_mark_used (pool);i915_gem_object_set_readonly (shadow->obj); shadow->private = pool;
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +6 -0
@@ -55,6 +55,9 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,if (unlikely (err)) goto out_put; +/* we pinned the pool, mark it as such */ +intel_gt_buffer_pool_mark_used (pool); + cmd =i915_gem_object_pin_map (pool->obj, pool->type);if (IS_ERR (cmd)) { err =PTR_ERR (cmd);
@@ -277,6 +280,9 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,if (unlikely (err)) goto out_put; +/* we pinned the pool, mark it as such */ +intel_gt_buffer_pool_mark_used (pool); + cmd =i915_gem_object_pin_map (pool->obj, pool->type);if (IS_ERR (cmd)) { err =PTR_ERR (cmd);
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c +21 -26
72 lines not on this page · raw message
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.h +5 -0
@@ -18,10 +18,15 @@ struct intel_gt_buffer_pool_node * intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size, enum i915_map_type type); +void intel_gt_buffer_pool_mark_used (struct intel_gt_buffer_pool_node *node); +static inline int intel_gt_buffer_pool_mark_active (struct intel_gt_buffer_pool_node *node,struct i915_request *rq) { +/* did we call mark_used? */ +GEM_WARN_ON (!node->pinned); +return i915_active_add_request (&node->active, rq); }
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool_types.h +1 -0
@@ -30,6 +30,7 @@ struct intel_gt_buffer_pool_node { };unsigned long age;enum i915_map_type type; +u32 pinned; };#endif /* INTEL_GT_BUFFER_POOL_TYPES_H */
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 30/69 drm/i915: Fix pread/pwrite to work with new locking rules.
In reply to Maarten LankhorstWe are removing obj->mm.lock, and need to take the reservation lock before we can pin pages. Move the pinning pages into the helper, and merge gtt pwrite/pread preparation and cleanup paths.
The fence lock is also removed; it will conflict with fence annotations, because of memory allocations done when pagefaulting inside copy_*_user.
--- drivers/gpu/drm/i915/Makefile | 1 - drivers/gpu/drm/i915/gem/i915_gem_fence.c | 95 --------- drivers/gpu/drm/i915/gem/i915_gem_object.h | 5 - drivers/gpu/drm/i915/i915_gem.c | 215 +++++++++++---------- 4 files changed, 112 insertions(+), 204 deletions(-) delete mode 100644 drivers/gpu/drm/i915/gem/i915_gem_fence.c
drivers/gpu/drm/i915/Makefile +0 -1
@@ -140,7 +140,6 @@ gem-y += \ gem/i915_gem_dmabuf.o \ gem/i915_gem_domain.o \ gem/i915_gem_execbuffer.o \ - gem/i915_gem_fence.o \ gem/i915_gem_internal.o \ gem/i915_gem_object.o \ gem/i915_gem_object_blt.o \
drivers/gpu/drm/i915/gem/i915_gem_fence.c deleted +0 -95
95 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_object.h +0 -5
@@ -189,11 +189,6 @@ static inline void i915_gem_object_unlock(struct drm_i915_gem_object *obj)dma_resv_unlock (obj->base.resv); } -struct dma_fence * -i915_gem_object_lock_fence (struct drm_i915_gem_object *obj); -void i915_gem_object_unlock_fence (struct drm_i915_gem_object *obj, -struct dma_fence *fence); -static inline void i915_gem_object_set_readonly (struct drm_i915_gem_object *obj) {
drivers/gpu/drm/i915/i915_gem.c +112 -103
331 lines not on this page · raw message
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 31/69 drm/i915: Fix workarounds selftest, part 1
In reply to Maarten Lankhorstpin_map needs the ww lock, so ensure we pin both before submission.
--- drivers/gpu/drm/i915/gem/i915_gem_object.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_pages.c | 12 +++ .../gpu/drm/i915/gt/selftest_workarounds.c | 95 +++++++++++++------ 3 files changed, 80 insertions(+), 30 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +3 -0
@@ -437,6 +437,9 @@ void i915_gem_object_writeback(struct drm_i915_gem_object *obj);void *__must_check i915_gem_object_pin_map (struct drm_i915_gem_object *obj,enum i915_map_type type); +void *__must_check i915_gem_object_pin_map_unlocked (struct drm_i915_gem_object *obj, +enum i915_map_type type); +void __i915_gem_object_flush_map (struct drm_i915_gem_object *obj,unsigned long offset,unsigned long size);
drivers/gpu/drm/i915/gem/i915_gem_pages.c +12 -0
@@ -400,6 +400,18 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, goto out_unlock; } +void *i915_gem_object_pin_map_unlocked (struct drm_i915_gem_object *obj, +enum i915_map_type type) +{ +void *ret; + +i915_gem_object_lock (obj,NULL ); + ret =i915_gem_object_pin_map (obj, type); +i915_gem_object_unlock (obj); + +return ret; +} +void __i915_gem_object_flush_map (struct drm_i915_gem_object *obj,unsigned long offset,unsigned long size)
drivers/gpu/drm/i915/gt/selftest_workarounds.c +65 -30
226 lines not on this page · raw message
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 32/69 drm/i915: Prepare for obj->mm.lock removal, v2.
In reply to Maarten LankhorstFrom: Thomas Hellström <[email protected]>
Stolen objects need to lock, and we may call put_pages when refcount drops to 0, ensure all calls are handled correctly.
Changes since v1:
- Rebase on top of upstream changes.
Idea-from: Thomas Hellström <[email protected]>
--- drivers/gpu/drm/i915/gem/i915_gem_object.h | 14 ++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_pages.c | 14 ++++++++++++-- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 12 +++++++----- 3 files changed, 33 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +14 -0
@@ -144,6 +144,20 @@ i915_gem_object_put(struct drm_i915_gem_object *obj)#define assert_object_held (obj) dma_resv_assert_held((obj)->base.resv) +/* +* If more than one potential simultaneous locker, assert held. +*/ +static inline void assert_object_held_shared (struct drm_i915_gem_object *obj) +{ +/* +* Note mm list lookup is protected by +* kref_get_unless_zero(). +*/ +if (IS_ENABLED (CONFIG_LOCKDEP ) && +kref_read (&obj->base.refcount) >0 ) +lockdep_assert_held (&obj->mm.lock); +} +static inline int __i915_gem_object_lock (struct drm_i915_gem_object *obj,struct i915_gem_ww_ctx *ww,bool intr)
drivers/gpu/drm/i915/gem/i915_gem_pages.c +12 -2
@@ -19,7 +19,7 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,bool shrinkable;int i; -lockdep_assert_held (&obj->mm.lock); +assert_object_held_shared (obj);if (i915_gem_object_is_volatile (obj)) obj->mm.madv =I915_MADV_DONTNEED ;
@@ -70,6 +70,7 @@ void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,struct list_head *list;unsigned long flags; +lockdep_assert_held (&obj->mm.lock);spin_lock_irqsave (&i915->mm.obj_lock, flags); i915->mm.shrink_count++;
@@ -91,6 +92,8 @@ int ____i915_gem_object_get_pages(struct drm_i915_gem_object *obj)struct drm_i915_private *i915 =to_i915 (obj->base.dev);int err; +assert_object_held_shared (obj); +if (unlikely (obj->mm.madv !=I915_MADV_WILLNEED )) {drm_dbg (&i915->drm,"Attempting to obtain a purgeable object\n" );
@@ -118,6 +121,8 @@ int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj)if (err)return err; +assert_object_held_shared (obj); +if (unlikely (!i915_gem_object_has_pages (obj))) {GEM_BUG_ON (i915_gem_object_has_pinned_pages (obj));
@@ -145,7 +150,7 @@ void i915_gem_object_truncate(struct drm_i915_gem_object *obj)/* Try to discard unwanted pages */ void i915_gem_object_writeback (struct drm_i915_gem_object *obj) { -lockdep_assert_held (&obj->mm.lock); +assert_object_held_shared (obj);GEM_BUG_ON (i915_gem_object_has_pages (obj));if (obj->ops->writeback)
@@ -176,6 +181,8 @@ __i915_gem_object_unset_pages(struct drm_i915_gem_object *obj) {struct sg_table *pages; +assert_object_held_shared (obj); + pages =fetch_and_zero (&obj->mm.pages);if (IS_ERR_OR_NULL (pages))return pages;
@@ -203,6 +210,9 @@ int __i915_gem_object_put_pages_locked(struct drm_i915_gem_object *obj)if (i915_gem_object_has_pinned_pages (obj))return -EBUSY ; +/* May be called by shrinker from within get_pages() (on another bo) */ +assert_object_held_shared (obj); +i915_gem_object_release_mmap_offset (obj);/*
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +7 -5
@@ -637,13 +637,15 @@ static int __i915_gem_object_create_stolen(struct intel_memory_region *mem, cache_level =HAS_LLC (mem->i915) ?I915_CACHE_LLC :I915_CACHE_NONE ;i915_gem_object_set_cache_coherency (obj, cache_level); - err =i915_gem_object_pin_pages (obj); -if (err) -return err; +if (WARN_ON (!i915_gem_object_trylock (obj))) +return -EBUSY ; -i915_gem_object_init_memory_region (obj, mem); + err =i915_gem_object_pin_pages (obj); +if (!err) +i915_gem_object_init_memory_region (obj, mem); +i915_gem_object_unlock (obj); -return 0 ; +return err; } static int _i915_gem_object_stolen_init(struct intel_memory_region *mem,
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 33/69 drm/i915: Add igt_spinner_pin() to allow for ww locking around spinner.
In reply to Maarten LankhorstBy default, we assume that it's called inside igt_create_request to keep existing selftests working, but allow for manual pinning when passing a ww context.
--- drivers/gpu/drm/i915/selftests/igt_spinner.c | 136 ++++++++++++------- drivers/gpu/drm/i915/selftests/igt_spinner.h | 5 + 2 files changed, 95 insertions(+), 46 deletions(-)
drivers/gpu/drm/i915/selftests/igt_spinner.c +90 -46
@@ -12,8 +12,6 @@int igt_spinner_init (struct igt_spinner *spin,struct intel_gt *gt) { -unsigned int mode; -void *vaddr;int err;memset (spin,0 ,sizeof (*spin));
@@ -24,6 +22,7 @@ int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt) err =PTR_ERR (spin->hws); goto err; } +i915_gem_object_set_cache_coherency (spin->hws,I915_CACHE_LLC ); spin->obj =i915_gem_object_create_internal (gt->i915,PAGE_SIZE );if (IS_ERR (spin->obj)) {
@@ -31,34 +30,83 @@ int igt_spinner_init(struct igt_spinner *spin, struct intel_gt *gt) goto err_hws; } -i915_gem_object_set_cache_coherency (spin->hws,I915_CACHE_LLC ); - vaddr =i915_gem_object_pin_map (spin->hws,I915_MAP_WB ); -if (IS_ERR (vaddr)) { - err =PTR_ERR (vaddr); - goto err_obj; - } - spin->seqno =memset (vaddr,0xff ,PAGE_SIZE ); - - mode =i915_coherent_map_type (gt->i915); - vaddr =i915_gem_object_pin_map (spin->obj, mode); -if (IS_ERR (vaddr)) { - err =PTR_ERR (vaddr); - goto err_unpin_hws; - } - spin->batch = vaddr; -return 0 ; -err_unpin_hws: -i915_gem_object_unpin_map (spin->hws); -err_obj: -i915_gem_object_put (spin->obj); err_hws:i915_gem_object_put (spin->hws); err:return err; } +static void *igt_spinner_pin_obj (struct intel_context *ce, +struct i915_gem_ww_ctx *ww, +struct drm_i915_gem_object *obj, +unsigned int mode,struct i915_vma **vma) +{ +void *vaddr; +int ret; + + *vma =i915_vma_instance (obj, ce->vm,NULL ); +if (IS_ERR (*vma)) +return ERR_CAST (*vma); + + ret =i915_gem_object_lock (obj, ww); +if (ret) +return ERR_PTR (ret); + + vaddr =i915_gem_object_pin_map (obj, mode); + +if (!ww) +i915_gem_object_unlock (obj); + +if (IS_ERR (vaddr)) +return vaddr; + +if (ww) + ret =i915_vma_pin_ww (*vma, ww,0 ,0 ,PIN_USER ); +else + ret =i915_vma_pin (*vma,0 ,0 ,PIN_USER ); + +if (ret) { +i915_gem_object_unpin_map (obj); +return ERR_PTR (ret); + } + +return vaddr; +} + +int igt_spinner_pin (struct igt_spinner *spin, +struct intel_context *ce, +struct i915_gem_ww_ctx *ww) +{ +void *vaddr; + +if (spin->ce &&WARN_ON (spin->ce != ce)) +return -ENODEV ; + spin->ce = ce; + +if (!spin->seqno) { + vaddr =igt_spinner_pin_obj (ce, ww, spin->hws,I915_MAP_WB , &spin->hws_vma); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + spin->seqno =memset (vaddr,0xff ,PAGE_SIZE ); + } + +if (!spin->batch) { +unsigned int mode = +i915_coherent_map_type (spin->gt->i915); + + vaddr =igt_spinner_pin_obj (ce, ww, spin->obj, mode, &spin->batch_vma); +if (IS_ERR (vaddr)) +return PTR_ERR (vaddr); + + spin->batch = vaddr; + } + +return 0 ; +} +static unsigned int seqno_offset (u64 fence) {return offset_in_page (sizeof (u32) * fence);
@@ -103,27 +151,18 @@ igt_spinner_create_request(struct igt_spinner *spin,if (!intel_engine_can_store_dword (ce->engine))return ERR_PTR (-ENODEV ); - vma =i915_vma_instance (spin->obj, ce->vm,NULL ); -if (IS_ERR (vma)) -return ERR_CAST (vma); - - hws =i915_vma_instance (spin->hws, ce->vm,NULL ); -if (IS_ERR (hws)) -return ERR_CAST (hws); +if (!spin->batch) { + err =igt_spinner_pin (spin, ce,NULL ); +if (err) +return ERR_PTR (err); + } - err =i915_vma_pin (vma,0 ,0 ,PIN_USER ); -if (err) -return ERR_PTR (err); - - err =i915_vma_pin (hws,0 ,0 ,PIN_USER ); -if (err) - goto unpin_vma; + hws = spin->hws_vma; + vma = spin->batch_vma; rq =intel_context_create_request (ce); -if (IS_ERR (rq)) { - err =PTR_ERR (rq); - goto unpin_hws; - } +if (IS_ERR (rq)) +return ERR_CAST (rq); err =move_to_active (vma, rq,0 );if (err)
@@ -186,10 +225,6 @@ igt_spinner_create_request(struct igt_spinner *spin,i915_request_set_error_once (rq, err);i915_request_add (rq); } -unpin_hws: -i915_vma_unpin (hws); -unpin_vma: -i915_vma_unpin (vma);return err ?ERR_PTR (err) : rq; }
@@ -203,6 +238,9 @@ hws_seqno(const struct igt_spinner *spin, const struct i915_request *rq)void igt_spinner_end (struct igt_spinner *spin) { +if (!spin->batch) +return ; + *spin->batch =MI_BATCH_BUFFER_END ;intel_gt_chipset_flush (spin->gt); }
@@ -211,10 +249,16 @@ void igt_spinner_fini(struct igt_spinner *spin) {igt_spinner_end (spin); -i915_gem_object_unpin_map (spin->obj); +if (spin->batch) { +i915_vma_unpin (spin->batch_vma); +i915_gem_object_unpin_map (spin->obj); + }i915_gem_object_put (spin->obj); -i915_gem_object_unpin_map (spin->hws); +if (spin->seqno) { +i915_vma_unpin (spin->hws_vma); +i915_gem_object_unpin_map (spin->hws); + }i915_gem_object_put (spin->hws); }
drivers/gpu/drm/i915/selftests/igt_spinner.h +5 -0
@@ -20,11 +20,16 @@ struct igt_spinner {struct intel_gt *gt;struct drm_i915_gem_object *hws;struct drm_i915_gem_object *obj; +struct intel_context *ce; +struct i915_vma *hws_vma, *batch_vma;u32 *batch;void *seqno; };int igt_spinner_init (struct igt_spinner *spin,struct intel_gt *gt); +int igt_spinner_pin (struct igt_spinner *spin, +struct intel_context *ce, +struct i915_gem_ww_ctx *ww);void igt_spinner_fini (struct igt_spinner *spin); struct i915_request *
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 34/69 drm/i915: Add ww locking around vm_access()
In reply to Maarten Lankhorsti915_gem_object_pin_map potentially needs a ww context, so ensure we have one we can revoke.
--- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_mman.c +22 -2
@@ -421,7 +421,9 @@ vm_access(struct vm_area_struct *area, unsigned long addr, {struct i915_mmap_offset *mmo = area->vm_private_data;struct drm_i915_gem_object *obj = mmo->obj; +struct i915_gem_ww_ctx ww;void *vaddr; +int err =0 ;if (i915_gem_object_is_readonly (obj) && write)return -EACCES ;
@@ -430,10 +432,18 @@ vm_access(struct vm_area_struct *area, unsigned long addr,if (addr >= obj->base.size)return -EINVAL ; +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (obj, &ww); +if (err) + goto out; +/* As this is primarily for debugging, let's focus on simplicity */ vaddr =i915_gem_object_pin_map (obj,I915_MAP_FORCE_WC ); -if (IS_ERR (vaddr)) -return PTR_ERR (vaddr); +if (IS_ERR (vaddr)) { + err =PTR_ERR (vaddr); + goto out; + }if (write) {memcpy (vaddr + addr, buf, len);
@@ -443,6 +453,16 @@ vm_access(struct vm_area_struct *area, unsigned long addr, }i915_gem_object_unpin_map (obj); +out: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); + +if (err) +return err;return len; }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 35/69 drm/i915: Increase ww locking for perf.
In reply to Maarten LankhorstWe need to lock a few more objects, some temporarily, add ww lock where needed.
--- drivers/gpu/drm/i915/i915_perf.c | 56 ++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_perf.c +43 -13
@@ -1576,7 +1576,7 @@ static int alloc_oa_buffer(struct i915_perf_stream *stream) stream->oa_buffer.vma = vma; stream->oa_buffer.vaddr = -i915_gem_object_pin_map (bo,I915_MAP_WB ); +i915_gem_object_pin_map_unlocked (bo,I915_MAP_WB );if (IS_ERR (stream->oa_buffer.vaddr)) { ret =PTR_ERR (stream->oa_buffer.vaddr); goto err_unpin;
@@ -1630,6 +1630,7 @@ static int alloc_noa_wait(struct i915_perf_stream *stream)const u32 base = stream->engine->mmio_base;#define CS_GPR (x) GEN8_RING_CS_GPR(base, x)u32 *batch, *ts0, *cs, *jump; +struct i915_gem_ww_ctx ww;int ret, i;enum {START_TS ,
@@ -1647,15 +1648,21 @@ static int alloc_noa_wait(struct i915_perf_stream *stream)return PTR_ERR (bo); } +i915_gem_ww_ctx_init (&ww, true); +retry: + ret =i915_gem_object_lock (bo, &ww); +if (ret) + goto out_ww; +/* * We pin in GGTT because we jump into this buffer now because * multiple OA config BOs will have a jump to this address and it * needs to be fixed during the lifetime of the i915/perf stream. */ - vma =i915_gem_object_ggtt_pin (bo,NULL ,0 ,0 ,PIN_HIGH ); + vma =i915_gem_object_ggtt_pin_ww (bo, &ww,NULL ,0 ,0 ,PIN_HIGH );if (IS_ERR (vma)) { ret =PTR_ERR (vma); - goto err_unref; + goto out_ww; } batch = cs =i915_gem_object_pin_map (bo,I915_MAP_WB );
@@ -1789,12 +1796,19 @@ static int alloc_noa_wait(struct i915_perf_stream *stream)__i915_gem_object_release_map (bo); stream->noa_wait = vma; -return 0 ; + goto out_ww; err_unpin:i915_vma_unpin_and_release (&vma,0 ); -err_unref: -i915_gem_object_put (bo); +out_ww: +if (ret == -EDEADLK ) { + ret =i915_gem_ww_ctx_backoff (&ww); +if (!ret) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +if (ret) +i915_gem_object_put (bo);return ret; }
@@ -1837,6 +1851,7 @@ alloc_oa_config_buffer(struct i915_perf_stream *stream, {struct drm_i915_gem_object *obj;struct i915_oa_config_bo *oa_bo; +struct i915_gem_ww_ctx ww;size_t config_length =0 ;u32 *cs;int err;
@@ -1857,10 +1872,16 @@ alloc_oa_config_buffer(struct i915_perf_stream *stream, goto err_free; } +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (obj, &ww); +if (err) + goto out_ww; + cs =i915_gem_object_pin_map (obj,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); - goto err_oa_bo; + goto out_ww; } cs = write_cs_mi_lri(cs,
@@ -1888,19 +1909,28 @@ alloc_oa_config_buffer(struct i915_perf_stream *stream, NULL);if (IS_ERR (oa_bo->vma)) { err =PTR_ERR (oa_bo->vma); - goto err_oa_bo; + goto out_ww; } oa_bo->oa_config =i915_oa_config_get (oa_config);llist_add (&oa_bo->node, &stream->oa_config_bos); -return oa_bo; +out_ww: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); -err_oa_bo: -i915_gem_object_put (obj); +if (err) +i915_gem_object_put (obj); err_free: -kfree (oa_bo); -return ERR_PTR (err); +if (err) { +kfree (oa_bo); +return ERR_PTR (err); + } +return oa_bo; } static struct i915_vma *
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 36/69 drm/i915: Lock ww in ucode objects correctly
In reply to Maarten LankhorstIn the ucode functions, the calls are done before userspace runs, when debugging using debugfs, or when creating semi-permanent mappings; we can safely use the unlocked versions that does the ww dance for us.
Because there is no pin_pages_unlocked yet, add it as convenience function.
This removes possible lockdep splats about missing resv lock for ucode.
--- drivers/gpu/drm/i915/gem/i915_gem_object.h | 2 ++ drivers/gpu/drm/i915/gem/i915_gem_pages.c | 20 ++++++++++++++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_guc_log.c | 4 ++-- drivers/gpu/drm/i915/gt/uc/intel_huc.c | 2 +- drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c | 2 +- 6 files changed, 27 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -0
@@ -392,6 +392,8 @@ i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)return __i915_gem_object_get_pages (obj); } +int i915_gem_object_pin_pages_unlocked (struct drm_i915_gem_object *obj); +static inline bool i915_gem_object_has_pages (struct drm_i915_gem_object *obj) {
drivers/gpu/drm/i915/gem/i915_gem_pages.c +20 -0
@@ -139,6 +139,26 @@ int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj)return err; } +int i915_gem_object_pin_pages_unlocked (struct drm_i915_gem_object *obj) +{ +struct i915_gem_ww_ctx ww; +int err; + +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (obj, &ww); +if (!err) + err =i915_gem_object_pin_pages (obj); + +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +return err; +} +/* Immediately discard the backing storage */ void i915_gem_object_truncate (struct drm_i915_gem_object *obj) {
drivers/gpu/drm/i915/gt/uc/intel_guc.c +1 -1
@@ -682,7 +682,7 @@ int intel_guc_allocate_and_map_vma(struct intel_guc *guc, u32 size,if (IS_ERR (vma))return PTR_ERR (vma); - vaddr =i915_gem_object_pin_map (vma->obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (vma->obj,I915_MAP_WB );if (IS_ERR (vaddr)) {i915_vma_unpin_and_release (&vma,0 );return PTR_ERR (vaddr);
drivers/gpu/drm/i915/gt/uc/intel_guc_log.c +2 -2
@@ -335,7 +335,7 @@ static int guc_log_map(struct intel_guc_log *log)* buffer pages, so that we can directly get the data * (up-to-date) from memory. */ - vaddr =i915_gem_object_pin_map (log->vma->obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (log->vma->obj,I915_MAP_WC );if (IS_ERR (vaddr))return PTR_ERR (vaddr);
@@ -744,7 +744,7 @@ int intel_guc_log_dump(struct intel_guc_log *log, struct drm_printer *p,if (!obj)return 0 ; - map =i915_gem_object_pin_map (obj,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (map)) {DRM_DEBUG ("Failed to pin object\n" );drm_puts (p,"(log data unaccessible)\n" );
drivers/gpu/drm/i915/gt/uc/intel_huc.c +1 -1
@@ -82,7 +82,7 @@ static int intel_huc_rsa_data_create(struct intel_huc *huc)if (IS_ERR (vma))return PTR_ERR (vma); - vaddr =i915_gem_object_pin_map (vma->obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (vma->obj,I915_MAP_WB );if (IS_ERR (vaddr)) {i915_vma_unpin_and_release (&vma,0 );return PTR_ERR (vaddr);
drivers/gpu/drm/i915/gt/uc/intel_uc_fw.c +1 -1
@@ -539,7 +539,7 @@ int intel_uc_fw_init(struct intel_uc_fw *uc_fw)if (!intel_uc_fw_is_available (uc_fw))return -ENOEXEC ; - err =i915_gem_object_pin_pages (uc_fw->obj); + err =i915_gem_object_pin_pages_unlocked (uc_fw->obj);if (err) {DRM_DEBUG_DRIVER ("%s fw pin-pages err=%d\n" ,intel_uc_fw_type_repr (uc_fw->type), err);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 37/69 drm/i915: Add ww locking to dma-buf ops.
In reply to Maarten Lankhorstvmap is using pin_pages, but needs to use ww locking, add pin_pages_unlocked to correctly lock the mapping.
Also add ww locking to begin/end cpu access.
--- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 60 ++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +33 -27
@@ -82,7 +82,7 @@ static int i915_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map *mapstruct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);void *vaddr; - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (vaddr))return PTR_ERR (vaddr);
@@ -123,42 +123,48 @@ static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, enum dma_data_dire {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf);bool write = (direction ==DMA_BIDIRECTIONAL || direction ==DMA_TO_DEVICE ); +struct i915_gem_ww_ctx ww;int err; - err =i915_gem_object_pin_pages (obj); -if (err) -return err; - - err =i915_gem_object_lock_interruptible (obj,NULL ); -if (err) - goto out; - -i915_gem_object_set_to_cpu_domain (obj, write); -i915_gem_object_unlock (obj); - -out: -i915_gem_object_unpin_pages (obj); +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (obj, &ww); +if (!err) + err =i915_gem_object_pin_pages (obj); +if (!err) { +i915_gem_object_set_to_cpu_domain (obj, write); +i915_gem_object_unpin_pages (obj); + } +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww);return err; }static int i915_gem_end_cpu_access (struct dma_buf *dma_buf,enum dma_data_direction direction) {struct drm_i915_gem_object *obj =dma_buf_to_obj (dma_buf); +struct i915_gem_ww_ctx ww;int err; - err =i915_gem_object_pin_pages (obj); -if (err) -return err; - - err =i915_gem_object_lock_interruptible (obj,NULL ); -if (err) - goto out; - -i915_gem_object_set_to_gtt_domain (obj, false); -i915_gem_object_unlock (obj); - -out: -i915_gem_object_unpin_pages (obj); +i915_gem_ww_ctx_init (&ww, true); +retry: + err =i915_gem_object_lock (obj, &ww); +if (!err) + err =i915_gem_object_pin_pages (obj); +if (!err) { +i915_gem_object_set_to_gtt_domain (obj, false); +i915_gem_object_unpin_pages (obj); + } +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww);return err; }
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 38/69 drm/i915: Add missing ww lock in intel_dsb_prepare.
In reply to Maarten LankhorstBecause of the long lifetime of the mapping, we cannot wrap this in a simple limited ww lock. Just use the unlocked version of pin_map, because we'll likely release the mapping a lot later, in a different thread.
--- drivers/gpu/drm/i915/display/intel_dsb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_dsb.c +1 -1
@@ -293,7 +293,7 @@ void intel_dsb_prepare(struct intel_crtc_state *crtc_state) goto out; } - buf =i915_gem_object_pin_map (vma->obj,I915_MAP_WC ); + buf =i915_gem_object_pin_map_unlocked (vma->obj,I915_MAP_WC );if (IS_ERR (buf)) {drm_err (&i915->drm,"Command buffer creation failed\n" );i915_vma_unpin_and_release (&vma,I915_VMA_RELEASE_MAP );
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 39/69 drm/i915: Fix ww locking in shmem_create_from_object
In reply to Maarten LankhorstQuick fix, just use the unlocked version.
--- drivers/gpu/drm/i915/gt/shmem_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/shmem_utils.c +1 -1
@@ -39,7 +39,7 @@ struct file *shmem_create_from_object(struct drm_i915_gem_object *obj)return file; } - ptr =i915_gem_object_pin_map (obj,I915_MAP_WB ); + ptr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (ptr))return ERR_CAST (ptr);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 40/69 drm/i915: Use a single page table lock for each gtt.
In reply to Maarten LankhorstWe may create page table objects on the fly, but we may need to wait with the ww lock held. Instead of waiting on a freed obj lock, ensure we have the same lock for each object to keep -EDEADLK working. This ensures that i915_vma_pin_ww can lock the page tables when required.
--- drivers/gpu/drm/i915/gt/intel_ggtt.c | 8 +++++- drivers/gpu/drm/i915/gt/intel_gtt.c | 38 ++++++++++++++++++++++++++- drivers/gpu/drm/i915/gt/intel_gtt.h | 5 ++++ drivers/gpu/drm/i915/gt/intel_ppgtt.c | 3 ++- drivers/gpu/drm/i915/i915_vma.c | 5 ++++ 5 files changed, 56 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/intel_ggtt.c +7 -1
@@ -656,7 +656,9 @@ static int init_aliasing_ppgtt(struct i915_ggtt *ggtt)if (err) goto err_ppgtt; +i915_gem_object_lock (ppgtt->vm.scratch[0 ],NULL ); err =i915_vm_pin_pt_stash (&ppgtt->vm, &stash); +i915_gem_object_unlock (ppgtt->vm.scratch[0 ]);if (err) goto err_stash;
@@ -743,6 +745,7 @@ static void ggtt_cleanup_hw(struct i915_ggtt *ggtt)mutex_unlock (&ggtt->vm.mutex);i915_address_space_fini (&ggtt->vm); +dma_resv_fini (&ggtt->vm.resv);arch_phys_wc_del (ggtt->mtrr);
@@ -1129,6 +1132,7 @@ static int ggtt_probe_hw(struct i915_ggtt *ggtt, struct intel_gt *gt) ggtt->vm.gt = gt; ggtt->vm.i915 = i915; ggtt->vm.dma = i915->drm.dev; +dma_resv_init (&ggtt->vm.resv);if (INTEL_GEN (i915) <=5 ) ret =i915_gmch_probe (ggtt);
@@ -1136,8 +1140,10 @@ static int ggtt_probe_hw(struct i915_ggtt *ggtt, struct intel_gt *gt) ret =gen6_gmch_probe (ggtt); else ret =gen8_gmch_probe (ggtt); -if (ret) +if (ret) { +dma_resv_fini (&ggtt->vm.resv);return ret; + }if ((ggtt->vm.total -1 ) >>32 ) { drm_err(&i915->drm,
drivers/gpu/drm/i915/gt/intel_gtt.c +37 -1
@@ -13,16 +13,36 @@struct drm_i915_gem_object *alloc_pt_dma (struct i915_address_space *vm,int sz) { +struct drm_i915_gem_object *obj; +if (I915_SELFTEST_ONLY (should_fail (&vm->fault_attr,1 )))i915_gem_shrink_all (vm->i915); -return i915_gem_object_create_internal (vm->i915, sz); + obj =i915_gem_object_create_internal (vm->i915, sz); +/* ensure all dma objects have the same reservation class */ +if (!IS_ERR (obj)) + obj->base.resv = &vm->resv; +return obj; }int pin_pt_dma (struct i915_address_space *vm,struct drm_i915_gem_object *obj) {int err; +i915_gem_object_lock (obj,NULL ); + err =i915_gem_object_pin_pages (obj); +i915_gem_object_unlock (obj); +if (err) +return err; + +i915_gem_object_make_unshrinkable (obj); +return 0 ; +} + +int pin_pt_dma_locked (struct i915_address_space *vm,struct drm_i915_gem_object *obj) +{ +int err; + err =i915_gem_object_pin_pages (obj);if (err)return err;
@@ -56,6 +76,20 @@ void __i915_vm_close(struct i915_address_space *vm)mutex_unlock (&vm->mutex); } +/* lock the vm into the current ww, if we lock one, we lock all */ +int i915_vm_lock_objects (struct i915_address_space *vm, +struct i915_gem_ww_ctx *ww) +{ +if (vm->scratch[0 ]->base.resv == &vm->resv) { +return i915_gem_object_lock (vm->scratch[0 ], ww); + }else { +struct i915_ppgtt *ppgtt =i915_vm_to_ppgtt (vm); + +/* We borrowed the scratch page from ggtt, take the top level object */ +return i915_gem_object_lock (ppgtt->pd->pt.base, ww); + } +} +void i915_address_space_fini (struct i915_address_space *vm) {drm_mm_takedown (&vm->mm);
@@ -69,6 +103,7 @@ static void __i915_vm_release(struct work_struct *work) vm->cleanup (vm);i915_address_space_fini (vm); +dma_resv_fini (&vm->resv);kfree (vm); }
@@ -98,6 +133,7 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass)mutex_init (&vm->mutex);lockdep_set_subclass (&vm->mutex, subclass);fs_reclaim_taints_mutex (&vm->mutex); +dma_resv_init (&vm->resv);GEM_BUG_ON (!vm->total);drm_mm_init (&vm->mm,0 , vm->total);
drivers/gpu/drm/i915/gt/intel_gtt.h +5 -0
@@ -242,6 +242,7 @@ struct i915_address_space {atomic_t open;struct mutex mutex;/* protects vma and our lists */ +struct dma_resv resv;/* reservation lock for all pd objects, and buffer pool */ #define VM_CLASS_GGTT 0#define VM_CLASS_PPGTT 1
@@ -351,6 +352,9 @@ struct i915_ppgtt {#define i915_is_ggtt (vm) ((vm)->is_ggtt) +int __must_check +i915_vm_lock_objects (struct i915_address_space *vm,struct i915_gem_ww_ctx *ww); +static inline bool i915_vm_is_4lvl (const struct i915_address_space *vm) {
@@ -527,6 +531,7 @@ struct i915_page_directory *alloc_pd(struct i915_address_space *vm);struct i915_page_directory *__alloc_pd (int npde);int pin_pt_dma (struct i915_address_space *vm,struct drm_i915_gem_object *obj); +int pin_pt_dma_locked (struct i915_address_space *vm,struct drm_i915_gem_object *obj);void free_px (struct i915_address_space *vm,struct i915_page_table *pt,int lvl);
drivers/gpu/drm/i915/gt/intel_ppgtt.c +2 -1
@@ -266,7 +266,7 @@ int i915_vm_pin_pt_stash(struct i915_address_space *vm,for (n =0 ; n <ARRAY_SIZE (stash->pt); n++) {for (pt = stash->pt[n]; pt; pt = pt->stash) { - err =pin_pt_dma (vm, pt->base); + err =pin_pt_dma_locked (vm, pt->base);if (err)return err; }
@@ -308,6 +308,7 @@ void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt) ppgtt->vm.dma = i915->drm.dev; ppgtt->vm.total =BIT_ULL (INTEL_INFO (i915)->ppgtt_size); +dma_resv_init (&ppgtt->vm.resv);i915_address_space_init (&ppgtt->vm,VM_CLASS_PPGTT ); ppgtt->vm.vma_ops.bind_vma = ppgtt_bind_vma;
drivers/gpu/drm/i915/i915_vma.c +5 -0
@@ -884,6 +884,11 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww, wakeref =intel_runtime_pm_get (&vma->vm->i915->runtime_pm);if (flags & vma->vm->bind_async_flags) { +/* lock VM */ + err =i915_vm_lock_objects (vma->vm, ww); +if (err) + goto err_rpm; + work =i915_vma_work ();if (!work) { err = -ENOMEM ;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 41/69 drm/i915/selftests: Prepare huge_pages testcases for obj->mm.lock removal.
In reply to Maarten LankhorstStraightforward conversion, just convert a bunch of calls to unlocked versions.
--- .../gpu/drm/i915/gem/selftests/huge_pages.c | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/gem/selftests/huge_pages.c +21 -7
@@ -585,7 +585,7 @@ static int igt_mock_ppgtt_misaligned_dma(void *arg) goto out_put; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto out_put;
@@ -649,15 +649,19 @@ static int igt_mock_ppgtt_misaligned_dma(void *arg)break ; } +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);i915_gem_object_put (obj); }return 0 ; out_unpin: +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj); +i915_gem_object_unlock (obj); out_put:i915_gem_object_put (obj);
@@ -671,8 +675,10 @@ static void close_object_list(struct list_head *objects,list_for_each_entry_safe (obj, on, objects, st_link) {list_del (&obj->st_link); +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);i915_gem_object_put (obj); } }
@@ -709,7 +715,7 @@ static int igt_mock_ppgtt_huge_fill(void *arg)break ; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj);break ;
@@ -885,7 +891,7 @@ static int igt_mock_ppgtt_64K(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto out_object_put;
@@ -939,8 +945,10 @@ static int igt_mock_ppgtt_64K(void *arg) }i915_vma_unpin (vma); +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);i915_gem_object_put (obj); } }
@@ -950,7 +958,9 @@ static int igt_mock_ppgtt_64K(void *arg) out_vma_unpin:i915_vma_unpin (vma); out_object_unpin: +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj); +i915_gem_object_unlock (obj); out_object_put:i915_gem_object_put (obj);
@@ -1012,7 +1022,7 @@ static int __cpu_check_vmap(struct drm_i915_gem_object *obj, u32 dword, u32 val)if (err)return err; - ptr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + ptr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (ptr))return PTR_ERR (ptr);
@@ -1292,7 +1302,7 @@ static int igt_ppgtt_smoke_huge(void *arg)return err; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {if (err == -ENXIO || err == -E2BIG ) {i915_gem_object_put (obj);
@@ -1315,8 +1325,10 @@ static int igt_ppgtt_smoke_huge(void *arg) __func__, size, i); } out_unpin: +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj); out_put:i915_gem_object_put (obj);
@@ -1390,7 +1402,7 @@ static int igt_ppgtt_sanity_check(void *arg)return err; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj); goto out;
@@ -1404,8 +1416,10 @@ static int igt_ppgtt_sanity_check(void *arg) err =igt_write_huge (ctx, obj); +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);i915_gem_object_put (obj);if (err) {
@@ -1450,7 +1464,7 @@ static int igt_tmpfs_fallback(void *arg) goto out_restore; } - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto out_put;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 42/69 drm/i915/selftests: Prepare client blit for obj->mm.lock removal.
In reply to Maarten LankhorstStraightforward conversion, just convert a bunch of calls to unlocked versions.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c +4 -4
@@ -52,7 +52,7 @@ static int __igt_client_fill(struct intel_engine_cs *engine) goto err_flush; } - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_put;
@@ -171,7 +171,7 @@ static int prepare_blit(const struct tiled_blits *t,u32 src_pitch, dst_pitch;u32 cmd, *cs; - cs =i915_gem_object_pin_map (batch,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (batch,I915_MAP_WC );if (IS_ERR (cs))return PTR_ERR (cs);
@@ -391,7 +391,7 @@ static int verify_buffer(const struct tiled_blits *t, y =i915_prandom_u32_max_state (t->height, prng); p = y * t->width + x; - vaddr =i915_gem_object_pin_map (buf->vma->obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (buf->vma->obj,I915_MAP_WC );if (IS_ERR (vaddr))return PTR_ERR (vaddr);
@@ -578,7 +578,7 @@ static int tiled_blits_prepare(struct tiled_blits *t,int err;int i; - map =i915_gem_object_pin_map (t->scratch.vma->obj,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (t->scratch.vma->obj,I915_MAP_WC );if (IS_ERR (map))return PTR_ERR (map);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 43/69 drm/i915/selftests: Prepare coherency tests for obj->mm.lock removal.
In reply to Maarten LankhorstStraightforward conversion, just convert a bunch of calls to unlocked versions.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c +2 -2
@@ -174,7 +174,7 @@ static int wc_set(struct context *ctx, unsigned long offset, u32 v)if (err)return err; - map =i915_gem_object_pin_map (ctx->obj,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (ctx->obj,I915_MAP_WC );if (IS_ERR (map))return PTR_ERR (map);
@@ -201,7 +201,7 @@ static int wc_get(struct context *ctx, unsigned long offset, u32 *v)if (err)return err; - map =i915_gem_object_pin_map (ctx->obj,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (ctx->obj,I915_MAP_WC );if (IS_ERR (map))return PTR_ERR (map);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 44/69 drm/i915/selftests: Prepare context tests for obj->mm.lock removal.
In reply to Maarten LankhorstStraightforward conversion, just convert a bunch of calls to unlocked versions.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c +5 -5
@@ -1092,7 +1092,7 @@ __read_slice_count(struct intel_context *ce,if (ret <0 )return ret; - buf =i915_gem_object_pin_map (obj,I915_MAP_WB ); + buf =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (buf)) { ret =PTR_ERR (buf);return ret;
@@ -1509,7 +1509,7 @@ static int write_to_scratch(struct i915_gem_context *ctx,if (IS_ERR (obj))return PTR_ERR (obj); - cmd =i915_gem_object_pin_map (obj,I915_MAP_WB ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto out;
@@ -1620,7 +1620,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,if (err) goto out_vm; - cmd =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto out;
@@ -1656,7 +1656,7 @@ static int read_from_scratch(struct i915_gem_context *ctx,if (err) goto out_vm; - cmd =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto out;
@@ -1715,7 +1715,7 @@ static int read_from_scratch(struct i915_gem_context *ctx, }i915_request_put (rq); - cmd =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto out_vm;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 45/69 drm/i915/selftests: Prepare dma-buf tests for obj->mm.lock removal.
In reply to Maarten LankhorstUse pin_pages_unlocked() where we don't have a lock.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_dmabuf.c +1 -1
@@ -194,7 +194,7 @@ static int igt_dmabuf_import_ownership(void *arg)dma_buf_put (dmabuf); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {pr_err ("i915_gem_object_pin_pages failed with err=%d\n" , err); goto out_obj;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 46/69 drm/i915/selftests: Prepare execbuf tests for obj->mm.lock removal.
In reply to Maarten LankhorstAlso quite simple, a single call needs to use the unlocked version.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_execbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_execbuffer.c +1 -1
@@ -116,7 +116,7 @@ static int igt_gpu_reloc(void *arg)if (IS_ERR (scratch))return PTR_ERR (scratch); - map =i915_gem_object_pin_map (scratch,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (scratch,I915_MAP_WC );if (IS_ERR (map)) { err =PTR_ERR (map); goto err_scratch;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 47/69 drm/i915/selftests: Prepare mman testcases for obj->mm.lock removal.
In reply to Maarten LankhorstEnsure we hold the lock around put_pages, and use the unlocked wrappers for pinning pages and mappings.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +6 -4
@@ -306,7 +306,7 @@ static int igt_partial_tiling(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {pr_err ("Failed to allocate %u pages (%lu total), err=%d\n" , nreal, obj->base.size /PAGE_SIZE , err);
@@ -443,7 +443,7 @@ static int igt_smoke_tiling(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {pr_err ("Failed to allocate %u pages (%lu total), err=%d\n" , nreal, obj->base.size /PAGE_SIZE , err);
@@ -782,7 +782,7 @@ static int wc_set(struct drm_i915_gem_object *obj) {void *vaddr; - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (vaddr))return PTR_ERR (vaddr);
@@ -798,7 +798,7 @@ static int wc_check(struct drm_i915_gem_object *obj)void *vaddr;int err =0 ; - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (vaddr))return PTR_ERR (vaddr);
@@ -1300,7 +1300,9 @@ static int __igt_mmap_revoke(struct drm_i915_private *i915, }if (type !=I915_MMAP_TYPE_GTT ) { +i915_gem_object_lock (obj,NULL );__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);if (i915_gem_object_has_pages (obj)) {pr_err ("Failed to put-pages object!\n" ); err = -EINVAL ;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 48/69 drm/i915/selftests: Prepare object tests for obj->mm.lock removal.
In reply to Maarten LankhorstConvert a single pin_pages call to use the unlocked version.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_object.c +1 -1
@@ -47,7 +47,7 @@ static int igt_gem_huge(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {pr_err ("Failed to allocate %u pages (%lu total), err=%d\n" , nreal, obj->base.size /PAGE_SIZE , err);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 49/69 drm/i915/selftests: Prepare object blit tests for obj->mm.lock removal.
In reply to Maarten LankhorstUse some unlocked versions where we're not holding the ww lock.
--- drivers/gpu/drm/i915/gem/selftests/i915_gem_object_blt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/selftests/i915_gem_object_blt.c +3 -3
@@ -262,7 +262,7 @@ static int igt_fill_blt_thread(void *arg) goto err_flush; } - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_put;
@@ -380,7 +380,7 @@ static int igt_copy_blt_thread(void *arg) goto err_flush; } - vaddr =i915_gem_object_pin_map (src,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (src,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_put_src;
@@ -400,7 +400,7 @@ static int igt_copy_blt_thread(void *arg) goto err_put_src; } - vaddr =i915_gem_object_pin_map (dst,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (dst,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_put_dst;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 50/69 drm/i915/selftests: Prepare igt_gem_utils for obj->mm.lock removal
In reply to Maarten Lankhorstigt_emit_store_dw needs to use the unlocked version, as it's not holding a lock. This fixes igt_gpu_fill_dw() which is used by some other selftests.
--- drivers/gpu/drm/i915/gem/selftests/igt_gem_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/selftests/igt_gem_utils.c +1 -1
@@ -56,7 +56,7 @@ igt_emit_store_dw(struct i915_vma *vma,if (IS_ERR (obj))return ERR_CAST (obj); - cmd =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto err;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 51/69 drm/i915/selftests: Prepare context selftest for obj->mm.lock removal
In reply to Maarten LankhorstOnly needs to convert a single call to the unlocked version.
--- drivers/gpu/drm/i915/gt/selftest_context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/selftest_context.c +2 -2
@@ -87,8 +87,8 @@ static int __live_context_size(struct intel_engine_cs *engine)if (err) goto err; - vaddr =i915_gem_object_pin_map (ce->state->obj, -i915_coherent_map_type (engine->i915)); + vaddr =i915_gem_object_pin_map_unlocked (ce->state->obj, +i915_coherent_map_type (engine->i915));if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr);intel_context_unpin (ce);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 52/69 drm/i915/selftests: Prepare hangcheck for obj->mm.lock removal
In reply to Maarten LankhorstConvert a few calls to use the unlocked versions.
--- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/gt/selftest_hangcheck.c +4 -4
@@ -61,15 +61,15 @@ static int hang_init(struct hang *h, struct intel_gt *gt) }i915_gem_object_set_cache_coherency (h->hws,I915_CACHE_LLC ); - vaddr =i915_gem_object_pin_map (h->hws,I915_MAP_WB ); + vaddr =i915_gem_object_pin_map_unlocked (h->hws,I915_MAP_WB );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_obj; } h->seqno =memset (vaddr,0xff ,PAGE_SIZE ); - vaddr =i915_gem_object_pin_map (h->obj, -i915_coherent_map_type (gt->i915)); + vaddr =i915_gem_object_pin_map_unlocked (h->obj, +i915_coherent_map_type (gt->i915));if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_unpin_hws;
@@ -130,7 +130,7 @@ hang_create_request(struct hang *h, struct intel_engine_cs *engine)return ERR_CAST (obj); } - vaddr =i915_gem_object_pin_map (obj,i915_coherent_map_type (gt->i915)); + vaddr =i915_gem_object_pin_map_unlocked (obj,i915_coherent_map_type (gt->i915));if (IS_ERR (vaddr)) {i915_gem_object_put (obj);i915_vm_put (vm);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 53/69 drm/i915/selftests: Prepare execlists and lrc selftests for obj->mm.lock removal
In reply to Maarten LankhorstConvert normal functions to unlocked versions where needed.
--- drivers/gpu/drm/i915/gt/selftest_execlists.c | 18 +++++++++--------- drivers/gpu/drm/i915/gt/selftest_lrc.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/gt/selftest_execlists.c +9 -9
@@ -982,7 +982,7 @@ static int live_timeslice_preempt(void *arg) goto err_obj; } - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_obj;
@@ -1289,7 +1289,7 @@ static int live_timeslice_queue(void *arg) goto err_obj; } - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto err_obj;
@@ -1531,7 +1531,7 @@ static int live_busywait_preempt(void *arg) goto err_ctx_lo; } - map =i915_gem_object_pin_map (obj,I915_MAP_WC ); + map =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (map)) { err =PTR_ERR (map); goto err_obj;
@@ -2691,7 +2691,7 @@ static int create_gang(struct intel_engine_cs *engine,if (err) goto err_obj; - cs =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto err_obj;
@@ -2970,7 +2970,7 @@ static int live_preempt_gang(void *arg)* it will terminate the next lowest spinner until there * are no more spinners and the gang is complete. */ - cs =i915_gem_object_pin_map (rq->batch->obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (rq->batch->obj,I915_MAP_WC );if (!IS_ERR (cs)) { *cs =0 ;i915_gem_object_unpin_map (rq->batch->obj);
@@ -3035,7 +3035,7 @@ create_gpr_user(struct intel_engine_cs *engine,return ERR_PTR (err); } - cs =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cs)) {i915_vma_put (vma);return ERR_CAST (cs);
@@ -3239,7 +3239,7 @@ static int live_preempt_user(void *arg)if (IS_ERR (global))return PTR_ERR (global); - result =i915_gem_object_pin_map (global->obj,I915_MAP_WC ); + result =i915_gem_object_pin_map_unlocked (global->obj,I915_MAP_WC );if (IS_ERR (result)) {i915_vma_unpin_and_release (&global,0 );return PTR_ERR (result);
@@ -3626,7 +3626,7 @@ static int live_preempt_smoke(void *arg) goto err_free; } - cs =i915_gem_object_pin_map (smoke.batch,I915_MAP_WB ); + cs =i915_gem_object_pin_map_unlocked (smoke.batch,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto err_batch;
@@ -4231,7 +4231,7 @@ static int preserved_virtual_engine(struct intel_gt *gt, goto out_end; } - cs =i915_gem_object_pin_map (scratch->obj,I915_MAP_WB ); + cs =i915_gem_object_pin_map_unlocked (scratch->obj,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto out_end;
drivers/gpu/drm/i915/gt/selftest_lrc.c +8 -8
@@ -627,7 +627,7 @@ static int __live_lrc_gpr(struct intel_engine_cs *engine, goto err_rq; } - cs =i915_gem_object_pin_map (scratch->obj,I915_MAP_WB ); + cs =i915_gem_object_pin_map_unlocked (scratch->obj,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto err_rq;
@@ -923,7 +923,7 @@ store_context(struct intel_context *ce,if (IS_ERR (batch))return batch; - cs =i915_gem_object_pin_map (batch->obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (batch->obj,I915_MAP_WC );if (IS_ERR (cs)) {i915_vma_put (batch);return ERR_CAST (cs);
@@ -1138,7 +1138,7 @@ load_context(struct intel_context *ce,if (IS_ERR (batch))return batch; - cs =i915_gem_object_pin_map (batch->obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (batch->obj,I915_MAP_WC );if (IS_ERR (cs)) {i915_vma_put (batch);return ERR_CAST (cs);
@@ -1277,29 +1277,29 @@ static int compare_isolation(struct intel_engine_cs *engine,u32 *defaults;int err =0 ; -A [0 ] =i915_gem_object_pin_map (ref[0 ]->obj,I915_MAP_WC ); +A [0 ] =i915_gem_object_pin_map_unlocked (ref[0 ]->obj,I915_MAP_WC );if (IS_ERR (A [0 ]))return PTR_ERR (A [0 ]); -A [1 ] =i915_gem_object_pin_map (ref[1 ]->obj,I915_MAP_WC ); +A [1 ] =i915_gem_object_pin_map_unlocked (ref[1 ]->obj,I915_MAP_WC );if (IS_ERR (A [1 ])) { err =PTR_ERR (A [1 ]); goto err_A0; } -B [0 ] =i915_gem_object_pin_map (result[0 ]->obj,I915_MAP_WC ); +B [0 ] =i915_gem_object_pin_map_unlocked (result[0 ]->obj,I915_MAP_WC );if (IS_ERR (B [0 ])) { err =PTR_ERR (B [0 ]); goto err_A1; } -B [1 ] =i915_gem_object_pin_map (result[1 ]->obj,I915_MAP_WC ); +B [1 ] =i915_gem_object_pin_map_unlocked (result[1 ]->obj,I915_MAP_WC );if (IS_ERR (B [1 ])) { err =PTR_ERR (B [1 ]); goto err_B0; } - lrc =i915_gem_object_pin_map (ce->state->obj, + lrc =i915_gem_object_pin_map_unlocked (ce->state->obj,i915_coherent_map_type (engine->i915));if (IS_ERR (lrc)) { err =PTR_ERR (lrc);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 54/69 drm/i915/selftests: Prepare mocs tests for obj->mm.lock removal
In reply to Maarten LankhorstUse pin_map_unlocked when we're not holding locks.
--- drivers/gpu/drm/i915/gt/selftest_mocs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gt/selftest_mocs.c +1 -1
@@ -79,7 +79,7 @@ static int live_mocs_init(struct live_mocs *arg, struct intel_gt *gt)if (IS_ERR (arg->scratch))return PTR_ERR (arg->scratch); - arg->vaddr =i915_gem_object_pin_map (arg->scratch->obj,I915_MAP_WB ); + arg->vaddr =i915_gem_object_pin_map_unlocked (arg->scratch->obj,I915_MAP_WB );if (IS_ERR (arg->vaddr)) { err =PTR_ERR (arg->vaddr); goto err_scratch;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 55/69 drm/i915/selftests: Prepare ring submission for obj->mm.lock removal
In reply to Maarten LankhorstUse unlocked versions when the ww lock is not held.
--- drivers/gpu/drm/i915/gt/selftest_ring_submission.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/selftest_ring_submission.c +2 -2
@@ -35,7 +35,7 @@ static struct i915_vma *create_wally(struct intel_engine_cs *engine)return ERR_PTR (err); } - cs =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cs =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cs)) {i915_gem_object_put (obj);return ERR_CAST (cs);
@@ -212,7 +212,7 @@ static int __live_ctx_switch_wa(struct intel_engine_cs *engine)if (IS_ERR (bb))return PTR_ERR (bb); - result =i915_gem_object_pin_map (bb->obj,I915_MAP_WC ); + result =i915_gem_object_pin_map_unlocked (bb->obj,I915_MAP_WC );if (IS_ERR (result)) {intel_context_put (bb->private);i915_vma_unpin_and_release (&bb,0 );
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 56/69 drm/i915/selftests: Prepare timeline tests for obj->mm.lock removal
In reply to Maarten LankhorstWe can no longer call intel_timeline_pin with a null argument, so add a ww loop that locks the backing object.
--- drivers/gpu/drm/i915/gt/selftest_timeline.c | 30 +++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/gt/selftest_timeline.c +25 -5
@@ -37,6 +37,26 @@ static unsigned long hwsp_cacheline(struct intel_timeline *tl)return (address +offset_in_page (tl->hwsp_offset)) /CACHELINE_BYTES ; } +static int selftest_tl_pin (struct intel_timeline *tl) +{ +struct i915_gem_ww_ctx ww; +int err; + +i915_gem_ww_ctx_init (&ww, false); +retry: + err =i915_gem_object_lock (tl->hwsp_ggtt->obj, &ww); +if (!err) + err =intel_timeline_pin (tl, &ww); + +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +return err; +} +#define CACHELINES_PER_PAGE (PAGE_SIZE / CACHELINE_BYTES)struct mock_hwsp_freelist {
@@ -78,7 +98,7 @@ static int __mock_hwsp_timeline(struct mock_hwsp_freelist *state,if (IS_ERR (tl))return PTR_ERR (tl); - err =intel_timeline_pin (tl,NULL ); + err =selftest_tl_pin (tl);if (err) {intel_timeline_put (tl);return err;
@@ -464,7 +484,7 @@ checked_tl_write(struct intel_timeline *tl, struct intel_engine_cs *engine, u32struct i915_request *rq;int err; - err =intel_timeline_pin (tl,NULL ); + err =selftest_tl_pin (tl);if (err) { rq =ERR_PTR (err); goto out;
@@ -664,7 +684,7 @@ static int live_hwsp_wrap(void *arg)if (!tl->has_initial_breadcrumb) goto out_free; - err =intel_timeline_pin (tl,NULL ); + err =selftest_tl_pin (tl);if (err) goto out_free;
@@ -811,13 +831,13 @@ static int setup_watcher(struct hwsp_watcher *w, struct intel_gt *gt)if (IS_ERR (obj))return PTR_ERR (obj); - w->map =i915_gem_object_pin_map (obj,I915_MAP_WB ); + w->map =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (w->map)) {i915_gem_object_put (obj);return PTR_ERR (w->map); } - vma =i915_gem_object_ggtt_pin_ww (obj,NULL ,NULL ,0 ,0 ,0 ); + vma =i915_gem_object_ggtt_pin (obj,NULL ,0 ,0 ,0 );if (IS_ERR (vma)) {i915_gem_object_put (obj);return PTR_ERR (vma);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 57/69 drm/i915/selftests: Prepare i915_request tests for obj->mm.lock removal
In reply to Maarten LankhorstStraightforward conversion by using unlocked versions.
--- drivers/gpu/drm/i915/selftests/i915_request.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/selftests/i915_request.c +5 -5
@@ -619,7 +619,7 @@ static struct i915_vma *empty_batch(struct drm_i915_private *i915)if (IS_ERR (obj))return ERR_CAST (obj); - cmd =i915_gem_object_pin_map (obj,I915_MAP_WB ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto err;
@@ -781,7 +781,7 @@ static struct i915_vma *recursive_batch(struct drm_i915_private *i915)if (err) goto err; - cmd =i915_gem_object_pin_map (obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (cmd)) { err =PTR_ERR (cmd); goto err;
@@ -816,7 +816,7 @@ static int recursive_batch_resolve(struct i915_vma *batch) {u32 *cmd; - cmd =i915_gem_object_pin_map (batch->obj,I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (batch->obj,I915_MAP_WC );if (IS_ERR (cmd))return PTR_ERR (cmd);
@@ -1069,8 +1069,8 @@ static int live_sequential_engines(void *arg)if (!request[idx])break ; - cmd =i915_gem_object_pin_map (request[idx]->batch->obj, -I915_MAP_WC ); + cmd =i915_gem_object_pin_map_unlocked (request[idx]->batch->obj, +I915_MAP_WC );if (!IS_ERR (cmd)) { *cmd =MI_BATCH_BUFFER_END ;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 58/69 drm/i915/selftests: Prepare memory region tests for obj->mm.lock removal
In reply to Maarten LankhorstUse the unlocked variants for pin_map and pin_pages, and add lock around unpinning/putting pages.
--- .../drm/i915/selftests/intel_memory_region.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/i915/selftests/intel_memory_region.c +11 -7
@@ -31,10 +31,12 @@ static void close_objects(struct intel_memory_region *mem,struct drm_i915_gem_object *obj, *on;list_for_each_entry_safe (obj, on, objects, st_link) { +i915_gem_object_lock (obj,NULL );if (i915_gem_object_has_pinned_pages (obj))i915_gem_object_unpin_pages (obj);/* No polluting the memory region between tests */ __i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);list_del (&obj->st_link);i915_gem_object_put (obj); }
@@ -69,7 +71,7 @@ static int igt_mock_fill(void *arg)break ; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj);break ;
@@ -109,7 +111,7 @@ igt_object_create(struct intel_memory_region *mem,if (IS_ERR (obj))return obj; - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto put;
@@ -123,8 +125,10 @@ igt_object_create(struct intel_memory_region *mem,static void igt_object_release (struct drm_i915_gem_object *obj) { +i915_gem_object_lock (obj,NULL );i915_gem_object_unpin_pages (obj);__i915_gem_object_put_pages (obj); +i915_gem_object_unlock (obj);list_del (&obj->st_link);i915_gem_object_put (obj); }
@@ -509,7 +513,7 @@ static int igt_cpu_check(struct drm_i915_gem_object *obj, u32 dword, u32 val)if (err)return err; - ptr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + ptr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (ptr))return PTR_ERR (ptr);
@@ -614,7 +618,7 @@ static int igt_lmem_create(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto out_put;
@@ -653,7 +657,7 @@ static int igt_lmem_write_gpu(void *arg) goto out_file; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto out_put;
@@ -725,7 +729,7 @@ static int igt_lmem_write_cpu(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - vaddr =i915_gem_object_pin_map (obj,I915_MAP_WC ); + vaddr =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (vaddr)) { err =PTR_ERR (vaddr); goto out_put;
@@ -828,7 +832,7 @@ create_region_for_mapping(struct intel_memory_region *mr, u64 size, u32 type,return obj; } - addr =i915_gem_object_pin_map (obj, type); + addr =i915_gem_object_pin_map_unlocked (obj, type);if (IS_ERR (addr)) {i915_gem_object_put (obj);if (PTR_ERR (addr) == -ENXIO )
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 59/69 drm/i915/selftests: Prepare cs engine tests for obj->mm.lock removal
In reply to Maarten LankhorstSame as other tests, use pin_map_unlocked.
--- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/selftest_engine_cs.c +2 -2
@@ -75,7 +75,7 @@ static struct i915_vma *create_empty_batch(struct intel_context *ce)if (IS_ERR (obj))return ERR_CAST (obj); - cs =i915_gem_object_pin_map (obj,I915_MAP_WB ); + cs =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto err_put;
@@ -211,7 +211,7 @@ static struct i915_vma *create_nop_batch(struct intel_context *ce)if (IS_ERR (obj))return ERR_CAST (obj); - cs =i915_gem_object_pin_map (obj,I915_MAP_WB ); + cs =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WB );if (IS_ERR (cs)) { err =PTR_ERR (cs); goto err_put;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 60/69 drm/i915/selftests: Prepare gtt tests for obj->mm.lock removal
In reply to Maarten LankhorstWe 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.
--- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 92 ++++++++++++++----- 1 file changed, 67 insertions(+), 25 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +67 -25
@@ -130,7 +130,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size) obj->cache_level =I915_CACHE_NONE ;/* Preallocate the "backing storage" */ -if (i915_gem_object_pin_pages (obj)) +if (i915_gem_object_pin_pages_unlocked (obj)) goto err_obj;i915_gem_object_unpin_pages (obj);
@@ -146,6 +146,7 @@ static int igt_ppgtt_alloc(void *arg) {struct drm_i915_private *dev_priv = arg;struct i915_ppgtt *ppgtt; +struct i915_gem_ww_ctx ww;u64 size, last, limit;int err =0 ;
@@ -171,6 +172,12 @@ static int igt_ppgtt_alloc(void *arg) limit =totalram_pages () <<PAGE_SHIFT ; limit =min (ppgtt->vm.total, limit); +i915_gem_ww_ctx_init (&ww, false); +retry: + err =i915_vm_lock_objects (&ppgtt->vm, &ww); +if (err) + goto err_ppgtt_cleanup; +/* Check we can allocate the entire range */ for (size =4096 ; size <= limit; size <<=2 ) {struct i915_vm_pt_stash stash = {};
@@ -215,6 +222,13 @@ static int igt_ppgtt_alloc(void *arg) } err_ppgtt_cleanup: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +i915_vm_put (&ppgtt->vm);return err; }
@@ -276,7 +290,7 @@ static int lowlevel_hole(struct i915_address_space *vm,GEM_BUG_ON (obj->base.size !=BIT_ULL (size)); -if (i915_gem_object_pin_pages (obj)) { +if (i915_gem_object_pin_pages_unlocked (obj)) {i915_gem_object_put (obj);kfree (order);break ;
@@ -297,20 +311,36 @@ static int lowlevel_hole(struct i915_address_space *vm,if (vm->allocate_va_range) {struct i915_vm_pt_stash stash = {}; +struct i915_gem_ww_ctx ww; +int err; + +i915_gem_ww_ctx_init (&ww, false); +retry: + err =i915_vm_lock_objects (vm, &ww); +if (err) + goto alloc_vm_end; + err = -ENOMEM ;if (i915_vm_alloc_pt_stash (vm, &stash,BIT_ULL (size))) -break ; - -if (i915_vm_pin_pt_stash (vm, &stash)) { -i915_vm_free_pt_stash (vm, &stash); -break ; - } + goto alloc_vm_end; - vm->allocate_va_range (vm, &stash, - addr,BIT_ULL (size)); + err =i915_vm_pin_pt_stash (vm, &stash); +if (!err) + vm->allocate_va_range (vm, &stash, + addr,BIT_ULL (size));i915_vm_free_pt_stash (vm, &stash); +alloc_vm_end: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); + +if (err) +break ; } mock_vma->pages = obj->mm.pages;
@@ -1166,7 +1196,7 @@ static int igt_ggtt_page(void *arg)if (IS_ERR (obj))return PTR_ERR (obj); - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) goto out_free;
@@ -1333,7 +1363,7 @@ static int igt_gtt_reserve(void *arg) goto out; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj); goto out;
@@ -1385,7 +1415,7 @@ static int igt_gtt_reserve(void *arg) goto out; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj); goto out;
@@ -1549,7 +1579,7 @@ static int igt_gtt_insert(void *arg) goto out; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj); goto out;
@@ -1658,7 +1688,7 @@ static int igt_gtt_insert(void *arg) goto out; } - err =i915_gem_object_pin_pages (obj); + err =i915_gem_object_pin_pages_unlocked (obj);if (err) {i915_gem_object_put (obj); goto out;
@@ -1829,7 +1859,7 @@ static int igt_cs_tlb(void *arg) goto out_vm; } - batch =i915_gem_object_pin_map (bbe,I915_MAP_WC ); + batch =i915_gem_object_pin_map_unlocked (bbe,I915_MAP_WC );if (IS_ERR (batch)) { err =PTR_ERR (batch); goto out_put_bbe;
@@ -1845,7 +1875,7 @@ static int igt_cs_tlb(void *arg) }/* Track the execution of each request by writing into different slot */ - batch =i915_gem_object_pin_map (act,I915_MAP_WC ); + batch =i915_gem_object_pin_map_unlocked (act,I915_MAP_WC );if (IS_ERR (batch)) { err =PTR_ERR (batch); goto out_put_act;
@@ -1892,7 +1922,7 @@ static int igt_cs_tlb(void *arg) goto out_put_out;GEM_BUG_ON (vma->node.start != vm->total -PAGE_SIZE ); - result =i915_gem_object_pin_map (out,I915_MAP_WB ); + result =i915_gem_object_pin_map_unlocked (out,I915_MAP_WB );if (IS_ERR (result)) { err =PTR_ERR (result); goto out_put_out;
@@ -1908,6 +1938,7 @@ static int igt_cs_tlb(void *arg)while (!__igt_timeout (end_time,NULL )) {struct i915_vm_pt_stash stash = {};struct i915_request *rq; +struct i915_gem_ww_ctx ww;u64 offset; offset = igt_random_offset(&prng,
@@ -1926,19 +1957,30 @@ static int igt_cs_tlb(void *arg)if (err) goto end; +i915_gem_ww_ctx_init (&ww, false); +retry: + err =i915_vm_lock_objects (vm, &ww); +if (err) + goto end_ww; + err =i915_vm_alloc_pt_stash (vm, &stash, chunk_size);if (err) - goto end; + goto end_ww; err =i915_vm_pin_pt_stash (vm, &stash); -if (err) { -i915_vm_free_pt_stash (vm, &stash); - goto end; - } - - vm->allocate_va_range (vm, &stash, offset, chunk_size); +if (!err) + vm->allocate_va_range (vm, &stash, offset, chunk_size);i915_vm_free_pt_stash (vm, &stash); +end_ww: +if (err == -EDEADLK ) { + err =i915_gem_ww_ctx_backoff (&ww); +if (!err) + goto retry; + } +i915_gem_ww_ctx_fini (&ww); +if (err) + goto end;/* Prime the TLB with the dummy pages */ for (i =0 ; i < count; i++) {
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 61/69 drm/i915: Finally remove obj->mm.lock.
In reply to Maarten LankhorstWith all callers and selftests fixed to use ww locking, we can now finally remove this lock.
--- drivers/gpu/drm/i915/gem/i915_gem_object.c | 2 - drivers/gpu/drm/i915/gem/i915_gem_object.h | 5 +-- .../gpu/drm/i915/gem/i915_gem_object_types.h | 1 - drivers/gpu/drm/i915/gem/i915_gem_pages.c | 43 ++++--------------- drivers/gpu/drm/i915/gem/i915_gem_phys.c | 34 ++++----------- drivers/gpu/drm/i915/gem/i915_gem_pm.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 37 +++++++++++----- drivers/gpu/drm/i915/gem/i915_gem_shrinker.h | 4 +- drivers/gpu/drm/i915/gem/i915_gem_tiling.c | 2 - drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 3 +- drivers/gpu/drm/i915/i915_debugfs.c | 4 +- drivers/gpu/drm/i915/i915_gem.c | 6 --- drivers/gpu/drm/i915/i915_gem_gtt.c | 2 +- 14 files changed, 55 insertions(+), 92 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object.c +0 -2
@@ -62,8 +62,6 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,const struct drm_i915_gem_object_ops *ops, struct lock_class_key *key, unsigned flags) { - mutex_init(&obj->mm.lock); - spin_lock_init(&obj->vma.lock);INIT_LIST_HEAD (&obj->vma.list);
drivers/gpu/drm/i915/gem/i915_gem_object.h +2 -3
@@ -155,7 +155,7 @@ static inline void assert_object_held_shared(struct drm_i915_gem_object *obj)*/ if (IS_ENABLED (CONFIG_LOCKDEP ) &&kref_read (&obj->base.refcount) >0 ) -lockdep_assert_held (&obj->mm.lock); +assert_object_held (obj); } static inline int __i915_gem_object_lock(struct drm_i915_gem_object *obj,
@@ -384,7 +384,7 @@ int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);static inline int __must_check i915_gem_object_pin_pages (struct drm_i915_gem_object *obj) { -might_lock (&obj->mm.lock); +assert_object_held (obj);if (atomic_inc_not_zero (&obj->mm.pages_pin_count))return 0 ;
@@ -430,7 +430,6 @@ i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj) }int __i915_gem_object_put_pages (struct drm_i915_gem_object *obj); -int __i915_gem_object_put_pages_locked (struct drm_i915_gem_object *obj);void i915_gem_object_truncate (struct drm_i915_gem_object *obj);void i915_gem_object_writeback (struct drm_i915_gem_object *obj);
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +0 -1
@@ -222,7 +222,6 @@ struct drm_i915_gem_object {* Protects the pages and their use. Do not use directly, but * instead go through the pin/unpin interfaces. */ -struct mutex lock;atomic_t pages_pin_count;atomic_t shrink_pin;
drivers/gpu/drm/i915/gem/i915_gem_pages.c +9 -34
100 lines not on this page · raw message
drivers/gpu/drm/i915/gem/i915_gem_phys.c +8 -26
@@ -234,40 +234,22 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)if (err)return err; - err =mutex_lock_interruptible (&obj->mm.lock); -if (err) -return err; - -if (unlikely (!i915_gem_object_has_struct_page (obj))) - goto out; - -if (obj->mm.madv !=I915_MADV_WILLNEED ) { - err = -EFAULT ; - goto out; - } +if (obj->mm.madv !=I915_MADV_WILLNEED ) +return -EFAULT ; -if (i915_gem_object_has_tiling_quirk (obj)) { - err = -EFAULT ; - goto out; - } +if (i915_gem_object_has_tiling_quirk (obj)) +return -EFAULT ; -if (obj->mm.mapping ||i915_gem_object_has_pinned_pages (obj)) { - err = -EBUSY ; - goto out; - } +if (obj->mm.mapping ||i915_gem_object_has_pinned_pages (obj)) +return -EBUSY ;if (unlikely (obj->mm.madv !=I915_MADV_WILLNEED )) {drm_dbg (obj->base.dev,"Attempting to obtain a purgeable object\n" ); - err = -EFAULT ; - goto out; +return -EFAULT ; } - err =i915_gem_object_shmem_to_phys (obj); - -out: -mutex_unlock (&obj->mm.lock); -return err; +return i915_gem_object_shmem_to_phys (obj); }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )
drivers/gpu/drm/i915/gem/i915_gem_pm.c +1 -1
@@ -116,7 +116,7 @@ int i915_gem_freeze_late(struct drm_i915_private *i915)*/ with_intel_runtime_pm(&i915->runtime_pm, wakeref) -i915_gem_shrink (i915,-1UL ,NULL , ~0 ); +i915_gem_shrink (NULL , i915,-1UL ,NULL , ~0 );i915_gem_drain_freed_objects (i915);wbinvd_on_all_cpus ();
drivers/gpu/drm/i915/gem/i915_gem_shmem.c +1 -1
@@ -99,7 +99,7 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj) goto err_sg; } -i915_gem_shrink (i915,2 * page_count,NULL , *s++); +i915_gem_shrink (NULL , i915,2 * page_count,NULL , *s++);/* * We've tried hard to allocate the memory by reaping
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +27 -10
@@ -94,7 +94,8 @@ static void try_to_writeback(struct drm_i915_gem_object *obj,* The number of pages of backing storage actually released. */ unsigned long -i915_gem_shrink (struct drm_i915_private *i915, +i915_gem_shrink (struct i915_gem_ww_ctx *ww, +struct drm_i915_private *i915,unsigned long target,unsigned long *nr_scanned,unsigned int shrink)
@@ -113,6 +114,7 @@ i915_gem_shrink(struct drm_i915_private *i915,intel_wakeref_t wakeref =0 ;unsigned long count =0 ;unsigned long scanned =0 ; +int err;trace_i915_gem_shrink (i915, target, shrink);
@@ -200,25 +202,40 @@ i915_gem_shrink(struct drm_i915_private *i915,spin_unlock_irqrestore (&i915->mm.obj_lock, flags); -if (unsafe_drop_pages (obj, shrink) && -mutex_trylock (&obj->mm.lock)) { + err =0 ; +if (unsafe_drop_pages (obj, shrink)) {/* May arrive from get_pages on another bo */ -if (!__i915_gem_object_put_pages_locked (obj)) { +if (!ww) { +if (!i915_gem_object_trylock (obj)) + goto skip; + }else { + err =i915_gem_object_lock (obj, ww); +if (err) + goto skip; + } + +if (!__i915_gem_object_put_pages (obj)) {try_to_writeback (obj, shrink); count += obj->base.size >>PAGE_SHIFT ; } -mutex_unlock (&obj->mm.lock); +if (!ww) +i915_gem_object_unlock (obj); }dma_resv_prune (obj->base.resv); scanned += obj->base.size >>PAGE_SHIFT ; +skip:i915_gem_object_put (obj);spin_lock_irqsave (&i915->mm.obj_lock, flags); +if (err) +break ; }list_splice_tail (&still_in_list, phase->list);spin_unlock_irqrestore (&i915->mm.obj_lock, flags); +if (err) +return err; }if (shrink &I915_SHRINK_BOUND )
@@ -249,7 +266,7 @@ unsigned long i915_gem_shrink_all(struct drm_i915_private *i915)unsigned long freed =0 ; with_intel_runtime_pm(&i915->runtime_pm, wakeref) { - freed =i915_gem_shrink (i915,-1UL ,NULL , + freed =i915_gem_shrink (NULL , i915,-1UL ,NULL ,I915_SHRINK_BOUND |I915_SHRINK_UNBOUND ); }
@@ -295,7 +312,7 @@ i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) sc->nr_scanned =0 ; - freed = i915_gem_shrink(i915, + freed = i915_gem_shrink(NULL, i915, sc->nr_to_scan, &sc->nr_scanned, I915_SHRINK_BOUND |
@@ -304,7 +321,7 @@ i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)intel_wakeref_t wakeref; with_intel_runtime_pm(&i915->runtime_pm, wakeref) { - freed += i915_gem_shrink(i915, + freed += i915_gem_shrink(NULL, i915, sc->nr_to_scan - sc->nr_scanned, &sc->nr_scanned, I915_SHRINK_ACTIVE |
@@ -329,7 +346,7 @@ i915_gem_shrinker_oom(struct notifier_block *nb, unsigned long event, void *ptr) freed_pages =0 ; with_intel_runtime_pm(&i915->runtime_pm, wakeref) - freed_pages +=i915_gem_shrink (i915,-1UL ,NULL , + freed_pages +=i915_gem_shrink (NULL , i915,-1UL ,NULL ,I915_SHRINK_BOUND |I915_SHRINK_UNBOUND |I915_SHRINK_WRITEBACK );
@@ -367,7 +384,7 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptrintel_wakeref_t wakeref; with_intel_runtime_pm(&i915->runtime_pm, wakeref) - freed_pages +=i915_gem_shrink (i915,-1UL ,NULL , + freed_pages +=i915_gem_shrink (NULL , i915,-1UL ,NULL ,I915_SHRINK_BOUND |I915_SHRINK_UNBOUND |I915_SHRINK_VMAPS );
drivers/gpu/drm/i915/gem/i915_gem_shrinker.h +3 -1
@@ -9,10 +9,12 @@#include <linux/bits.h> struct drm_i915_private ; +struct i915_gem_ww_ctx ;struct mutex ;/* i915_gem_shrinker.c */ -unsigned long i915_gem_shrink (struct drm_i915_private *i915, +unsigned long i915_gem_shrink (struct i915_gem_ww_ctx *ww, +struct drm_i915_private *i915,unsigned long target,unsigned long *nr_scanned,unsigned flags);
drivers/gpu/drm/i915/gem/i915_gem_tiling.c +0 -2
@@ -265,7 +265,6 @@ i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,* pages to prevent them being swapped out and causing corruption * due to the change in swizzling. */ -mutex_lock (&obj->mm.lock);if (i915_gem_object_has_pages (obj) && obj->mm.madv ==I915_MADV_WILLNEED && i915->quirks &QUIRK_PIN_SWIZZLED_PAGES ) {
@@ -280,7 +279,6 @@ i915_gem_object_set_tiling(struct drm_i915_gem_object *obj,i915_gem_object_set_tiling_quirk (obj); } } -mutex_unlock (&obj->mm.lock);spin_lock (&obj->vma.lock);for_each_ggtt_vma (vma, obj) {
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +1 -2
@@ -253,7 +253,7 @@ static int i915_gem_object_userptr_unbind(struct drm_i915_gem_object *obj, boolif (GEM_WARN_ON (i915_gem_object_has_pinned_pages (obj)))return -EBUSY ; -mutex_lock (&obj->mm.lock); +assert_object_held (obj); pages =__i915_gem_object_unset_pages (obj);if (!IS_ERR_OR_NULL (pages))
@@ -261,7 +261,6 @@ static int i915_gem_object_userptr_unbind(struct drm_i915_gem_object *obj, boolif (get_pages) err =____i915_gem_object_get_pages (obj); -mutex_unlock (&obj->mm.lock);return err; }
drivers/gpu/drm/i915/i915_debugfs.c +2 -2
@@ -904,10 +904,10 @@ i915_drop_caches_set(void *data, u64 val)fs_reclaim_acquire (GFP_KERNEL );if (val &DROP_BOUND ) -i915_gem_shrink (i915,LONG_MAX ,NULL ,I915_SHRINK_BOUND ); +i915_gem_shrink (NULL , i915,LONG_MAX ,NULL ,I915_SHRINK_BOUND );if (val &DROP_UNBOUND ) -i915_gem_shrink (i915,LONG_MAX ,NULL ,I915_SHRINK_UNBOUND ); +i915_gem_shrink (NULL , i915,LONG_MAX ,NULL ,I915_SHRINK_UNBOUND );if (val &DROP_SHRINK_ALL )i915_gem_shrink_all (i915);
drivers/gpu/drm/i915/i915_gem.c +0 -6
@@ -963,10 +963,6 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,if (err) goto out; - err =mutex_lock_interruptible (&obj->mm.lock); -if (err) - goto out_ww; -if (i915_gem_object_has_pages (obj) &&i915_gem_object_is_tiled (obj) && i915->quirks &QUIRK_PIN_SWIZZLED_PAGES ) {
@@ -1009,9 +1005,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,i915_gem_object_truncate (obj); args->retained = obj->mm.madv != __I915_MADV_PURGED; -mutex_unlock (&obj->mm.lock); -out_ww:i915_gem_object_unlock (obj); out:i915_gem_object_put (obj);
drivers/gpu/drm/i915/i915_gem_gtt.c +1 -1
@@ -44,7 +44,7 @@ int i915_gem_gtt_prepare_pages(struct drm_i915_gem_object *obj,* the DMA remapper, i915_gem_shrink will return 0. */ GEM_BUG_ON (obj->mm.pages == pages); - }while (i915_gem_shrink (to_i915 (obj->base.dev), + }while (i915_gem_shrink (NULL ,to_i915 (obj->base.dev), obj->base.size >>PAGE_SHIFT ,NULL ,I915_SHRINK_BOUND |I915_SHRINK_UNBOUND ));
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 62/69 drm/i915: Keep userpointer bindings if seqcount is unchanged, v2.
In reply to Maarten LankhorstInstead of force unbinding and rebinding every time, we try to check if our notifier seqcount is still correct when pages are bound. This way we only rebind userptr when we need to, and prevent stalls.
Changes since v1:
- Missing mutex_unlock, reported by kbuild.
--- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 27 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_userptr.c +24 -3
@@ -281,12 +281,33 @@ int i915_gem_object_userptr_submit_init(struct drm_i915_gem_object *obj)if (ret)return ret; -/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */ - ret =i915_gem_object_userptr_unbind (obj, false); +/* optimistically try to preserve current pages while unlocked */ +if (i915_gem_object_has_pages (obj) && + !mmu_interval_check_retry (&obj->userptr.notifier, + obj->userptr.notifier_seq)) { +spin_lock (&i915->mm.notifier_lock); +if (obj->userptr.pvec && + !mmu_interval_read_retry (&obj->userptr.notifier, + obj->userptr.notifier_seq)) { + obj->userptr.page_ref++; + +/* We can keep using the current binding, this is the fastpath */ + ret =1 ; + } +spin_unlock (&i915->mm.notifier_lock); + } + +if (!ret) { +/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */ + ret =i915_gem_object_userptr_unbind (obj, false); + }i915_gem_object_unlock (obj); -if (ret) +if (ret <0 )return ret; +if (ret >0 ) +return 0 ; + notifier_seq =mmu_interval_read_begin (&obj->userptr.notifier); pvec =kvmalloc_array (num_pages,sizeof (struct page *),GFP_KERNEL );
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 63/69 drm/i915: Move gt_revoke() slightly
In reply to Maarten LankhorstWe get a lockdep splat when the reset mutex is held, because it can be taken from fence_wait. This conflicts with the mmu notifier we have, because we recurse between reset mutex and mmap lock -> mmu notifier.
Remove this recursion by calling revoke_mmaps before taking the lock.
The reset code still needs fixing, as taking mmap locks during reset is not allowed.
--- drivers/gpu/drm/i915/gt/intel_reset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/intel_reset.c +3 -2
@@ -970,8 +970,6 @@ static int do_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask) {int err, i; -gt_revoke (gt); - err =__intel_gt_reset (gt,ALL_ENGINES );for (i =0 ; err && i <RESET_MAX_RETRIES ; i++) {msleep (10 * (i +1 ));
@@ -1026,6 +1024,9 @@ void intel_gt_reset(struct intel_gt *gt,might_sleep ();GEM_BUG_ON (!test_bit (I915_RESET_BACKOFF , >->reset.flags)); + +gt_revoke (gt); +mutex_lock (>->reset.mutex);/* Clear any previous failed attempts at recovery. Time to try again. */
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 64/69 drm/i915: Add missing -EDEADLK path in execbuffer ggtt pinning.
In reply to Maarten LankhorstIn reloc_iomap we swallow the -EDEADLK error, but this needs to be returned for -EDEADLK handling. Add the missing check to make bsw pass again.
Testcase: gem_exec_fence.basic-await
--- drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +2 -0
@@ -1209,6 +1209,8 @@ static void *reloc_iomap(struct drm_i915_gem_object *obj,PIN_MAPPABLE |PIN_NONBLOCK /* NOWARN */ | PIN_NOEVICT); +if (vma ==ERR_PTR (-EDEADLK )) +return vma;if (IS_ERR (vma)) {memset (&cache->node,0 ,sizeof (cache->node));mutex_lock (&ggtt->vm.mutex);
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v8 65/69 drm/i915: Fix pin_map in scheduler selftests
In reply to Maarten Lankhorst--- drivers/gpu/drm/i915/selftests/i915_scheduler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/selftests/i915_scheduler.c +1 -1
@@ -645,7 +645,7 @@ static int __igt_schedule_cycle(struct drm_i915_private *i915,if (IS_ERR (obj))return PTR_ERR (obj); - time =i915_gem_object_pin_map (obj,I915_MAP_WC ); + time =i915_gem_object_pin_map_unlocked (obj,I915_MAP_WC );if (IS_ERR (time)) { err =PTR_ERR (time); goto out_obj;
Signature · 6 lines
2.30.1 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx